Le module illustré ici permet de compléter automatiquement le champ optionnel ID_FOU_COM de LIGNES_V avec le fournisseur par défaut défini au niveau de l'article. Cette fonctionnalité peut être couplée avec la fixation du fournisseur dans la commande client pour la contremarque.
Le code exploite de façon très simple l'évènement AfterInsertItem du BillingEngine. Il s'établit comme suit :
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using MercatorApi;
using MercatorUi;
namespace Billing
{
public class Customizer : MercatorUi.ICustomizers.IBillingEngineCreated, MercatorUi.ICustomizers.IBillingEngineClosed
{
public void BillingEngineCreated(MercatorUi.Engine.Gescom.BillingEngine billingEngine)
{
billingEngine.AfterInsertItem += BillingEngine_AfterInsertItem;
}
public void BillingEngineClosed(MercatorUi.Engine.Gescom.BillingEngine billingEngine)
{
billingEngine.AfterInsertItem -= BillingEngine_AfterInsertItem;
}
void BillingEngine_AfterInsertItem(object sender, MercatorUi.Engine.Gescom.BillingEngine.AfterInsertItemEventArgs e)
{
DataSet ds = Api.Zselect(MercatorUi.Globals.RepData, "select fou.f_id,fou.f_nom from ARTFOU inner join FOU on (artfou.id_fou=fou.f_id) where (id_art=@s_id) and (principal=1)", new MercatorSqlParam("@s_id", e.StockRecord.S_ID, SqlDbType.Char));
if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
{
e.LignesVRecord.ID_FOU_COM = ds.Tables[0].Rows[0]["f_id"].ToString().TrimEnd();
e.DataRowLignes["NOM_FOU_COM"] = ds.Tables[0].Rows[0]["f_nom"].ToString().TrimEnd();
}
}
}
}