Cet exemple montre comment empêcher de dupliquer les données de l’onglet "Fournisseurs" de la fiche article lors de la duplication de la fiche.
Il suffira d’implémenter l’interface MercatorUi.ICustomizers.IFormLoadCustomizer pour utiliser l’évènement AfterRecordDuplicate.
Sources du code :
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using MercatorApi;
using MercatorUi;
namespace SigStock
{
public class Customizer : MercatorUi.ICustomizers.IFormLoadCustomizer, MercatorUi.ICustomizers.IFormClosedCustomizer
{
public void FormLoadCustomize(Form form)
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
sigForm.Sig.AfterRecordDuplicate += new MercatorUi.Sig.Sig.AfterRecordDuplicateEventHandler(sigStock_AfterRecordDuplicate);
}
public void FormClosedCustomize(Form form)
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
sigForm.Sig.AfterRecordDuplicate -= new MercatorUi.Sig.Sig.AfterRecordDuplicateEventHandler(sigStock_AfterRecordDuplicate);
}
void sigStock_AfterRecordDuplicate(object sender, MercatorUi.Sig.Sig.AfterRecordDuplicateEventArgs e)
{
List<Control> l = e.SigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigGrids.ArtFou));
if (l.Count == 0)
return;
MercatorUi.Forms.Sig.SigGrids.ArtFou artFou = (MercatorUi.Forms.Sig.SigGrids.ArtFou)l[0];
artFou.Grid.CurrentCell = null;
DataTable dt = (DataTable)artFou.Grid.DataSource;
dt.Rows.Clear();
}
}
}