Le paramétrage décrit ici permet de filtrer les mouvements journaliers sur ventes en fonction du représentant. Une boîte de dialogue permettant la sélection du représentant ou de tous les représentants est présentée à l'utilisateur. Ce paramétrage modifie aussi le titre de la fenêtre en ajoutant le nom du représentant.
Cette programmation est construite sur base d'un customizer Gescom qui implémente ces interfaces :
La méthode StringUpdate doit être utilisée deux fois :
Le code s'établit comme suit :
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorUi;
using System.Windows.Forms;
namespace Gescom
{
public class Customizer : MercatorUi.ICustomizers.IStringUpdater, MercatorUi.ICustomizers.IFormLoadCustomizer
{
public string StringUpdate(string StringToModify)
{
string id = Api.StrExtract(StringToModify, "<ID>", "</ID>");
if (id.StartsWith("DASHBOARD_V"))
{
MercatorUi._Dialogs.DialogAskComboRet rep = Dialogs.AskRep("Quel représentant ?", true);
if ((rep != null) && (rep.Id != "")) // Tous : rep.Id=""
{
StringToModify = StringToModify.Replace(" from lignes_v", string.Format(",'{0}' as id_rep,'{1}' as nom_rep from lignes_v", Api.UnquoteSql(rep.Id), Api.UnquoteSql(rep.Lib)))
.Replace("rayons.id) where ", string.Format("rayons.id) where (pieds_v.id_rep='{0}') and ", Api.UnquoteSql(rep.Id)));
}
}
else if (id == "DASHBOARD_NODE")
{
Form f = Globals.Main.WonTopForm();
if ((f != null) && (f is MercatorUi.Forms.Gescom.GescomDashboardForm))
{
MercatorUi.Forms.Gescom.GescomDashboardForm gescomDashboardForm = (MercatorUi.Forms.Gescom.GescomDashboardForm)f;
if (gescomDashboardForm.Dt.Columns.Contains("id_rep"))
{
string id_rep = gescomDashboardForm.Dt.Rows[0]["id_rep"].ToString();
StringToModify = StringToModify.Replace("(pieds_v.date>=@date_1)", string.Format("(pieds_v.id_rep='{0}') and (pieds_v.date>=@date_1)", Api.UnquoteSql(id_rep)));
}
}
}
return StringToModify;
}
public void FormLoadCustomize(System.Windows.Forms.Form WindowsForm)
{
if (WindowsForm is MercatorUi.Forms.Gescom.GescomDashboardForm)
{
MercatorUi.Forms.Gescom.GescomDashboardForm gescomDashboardForm = (MercatorUi.Forms.Gescom.GescomDashboardForm)WindowsForm;
if (gescomDashboardForm.Dt.Columns.Contains("nom_rep"))
gescomDashboardForm.Text += " - Représentant : " + gescomDashboardForm.Dt.Rows[0]["nom_rep"].ToString();
}
}
}
}