Depuis la version 11.0, ce code est obsolète. Il est possible de réaliser ce paramétrage sans code. La requête peut être modifiée via la propriété StringUpdater de l'objet StockInterro. Ensuite, il faut mettre à OUI la propriété AutoAddCustomColumnsGrid.
La programmation décrite ici montre comment ajouter une colonne mentionnant la date d'échéance dans la première grille de l'interrogation commerciale articles (StockInterro). Ce customizer SigStock se fait via l'implémentation de 3 interfaces :
Le code s'entend comme suit :
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorUi;
using System.Windows.Forms;
using System.Linq;
namespace SigStock
{
public class Customizer : MercatorUi.ICustomizers.IStringUpdater, MercatorUi.ICustomizers.IFormLoadCustomizer, MercatorUi.ICustomizers.IFormClosedCustomizer
{
public string StringUpdate(string stringToModify)
{
string id = Api.StrExtract(stringToModify, "<ID>", "</ID>");
if (id != "STOCK_INTERRO1") // Il ne faut agir que sur la requête de la grille 1 de StockInterro. Or, StringUpdate va voir passer toutes les requêtes de tous les objets et grille du signalétiques articles.
return stringToModify; // Cette requête n'est pas celle de la grille 1 se StockInterro -> on ne la modifie pas
else // attention : la requête varie en fonction des cases à cocher sélectionnée.
return stringToModify.Replace(",pieds_v.date,", ",pieds_v.date,pieds_v.echeance,").Replace(",pieds_a.date,", ",pieds_a.date,pieds_a.echeance,").Replace(",lignes_d.date,", ",lignes_d.date,cast('01/01/1900' as datetime) as echeance,");
}
public void FormLoadCustomize(Form form)
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
MercatorUi.Forms.Sig.SigObjects.StockInterro stockInterro = sigForm.MovableControls.Values.OfType<MercatorUi.Forms.Sig.SigObjects.StockInterro>().FirstOrDefault();
if (stockInterro != null)
stockInterro.AfterColumnsCreated += stockInterro_AfterColumnsCreated;
}
public void FormClosedCustomize(Form form)
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
MercatorUi.Forms.Sig.SigObjects.StockInterro stockInterro = sigForm.MovableControls.Values.OfType<MercatorUi.Forms.Sig.SigObjects.StockInterro>().FirstOrDefault();
if (stockInterro != null)
stockInterro.AfterColumnsCreated -= stockInterro_AfterColumnsCreated;
}
private void stockInterro_AfterColumnsCreated(object sender, EventArgs e)
{
MercatorUi.GridPro.DataGridViewXPro grid = (MercatorUi.GridPro.DataGridViewXPro)sender;
if (grid.Name == "grid1") // attention : StockInterro contient 2 grilles. Ici, on veut agir uniquement sur la grille 1. Ce même évènement va aussi voir passer la grille 2 (mais on ne la modifie pas)
{
grid.Columns.Add("echeance", _Divers.Iif_langue(Globals.Langue, "Due Date", "Vervald.", "Echéance"));
grid.Columns["echeance"].Width = 68;
grid.Columns["echeance"].DataPropertyName = "echeance";
grid.Columns["echeance"].DefaultCellStyle.Format = Api.Iif(Globals.DateMDY, "MM/dd/yyyy", "dd/MM/yyyy");
}
}
}
}