L’exemple donné ici permet de mettre par défaut une valeur dans une colonne de la grille de tarification des clients.
Dans notre cas, il s'agit du champ "date_fin".
Ce système est disponible dans toutes les grilles avec boutons "Ajouter / Supprimer" des signalétiques.
Le code s’établit comme suit :
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Linq;
using MercatorApi;
using MercatorExtensions;
using MercatorUi;
using MercatorDatabase;
using System.Windows.Forms;
namespace SigCli
{
public class Customizer :
MercatorUi.ICustomizers.IFormLoadCustomizer,
MercatorUi.ICustomizers.IFormClosedCustomizer
{
public void FormLoadCustomize(Form WindowsForm)
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;
List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigGrids.TarCli));
foreach (Control cTarCli in l)
{
MercatorUi.Forms.Sig.SigGrids.TarCli tarCli = (MercatorUi.Forms.Sig.SigGrids.TarCli)cTarCli;
tarCli.AssociatedPanelCreated += TarCli_AssociatedPanelCreated;
}
}
public void FormClosedCustomize(Form WindowsForm)
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;
List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigGrids.TarCli));
foreach (Control cTarCli in l)
{
MercatorUi.Forms.Sig.SigGrids.TarCli tarCli = (MercatorUi.Forms.Sig.SigGrids.TarCli)cTarCli;
tarCli.AssociatedPanelCreated -= TarCli_AssociatedPanelCreated;
}
}
private void TarCli_AssociatedPanelCreated(object sender, MercatorUi.MovableControls.MovableGrid.AssociatedPanelCreatedEventArgs e)
{
MercatorUi.MovableControls.Tools.GridButtons buttons = (MercatorUi.MovableControls.Tools.GridButtons)e.AssociatedPanel;
buttons.BeforeClickInGridButtons += new MercatorUi.MovableControls.Tools.GridButtons.BeforeClickInGridButtonsHandler(buttons_BeforeClickInGridButtons);
buttons.AfterClickInGridButtons += Buttons_AfterClickInGridButtons;
buttons.Disposed += Buttons_Disposed;
}
private void Buttons_Disposed(object sender, EventArgs e)
{
MercatorUi.MovableControls.Tools.GridButtons buttons = (MercatorUi.MovableControls.Tools.GridButtons)sender;
buttons.AfterClickInGridButtons -= Buttons_AfterClickInGridButtons;
buttons.Disposed -= Buttons_Disposed;
}
private void Buttons_AfterClickInGridButtons(object sender, MercatorUi.MovableControls.Tools.AfterClickInGridButtonsEventArgs e)
{
MercatorUi.MovableControls.Tools.GridButtons buttons = (MercatorUi.MovableControls.Tools.GridButtons)sender;
if ((e.ClickedButtonX == MercatorUi.MovableControls.Tools.ButtonsForGrid.Add) || (e.ClickedButtonX == MercatorUi.MovableControls.Tools.ButtonsForGrid.Insert))
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)buttons.FindForm();
List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigGrids.TarCli));
foreach (Control cTarCli in l)
{
MercatorUi.Forms.Sig.SigGrids.TarCli tarCli = (MercatorUi.Forms.Sig.SigGrids.TarCli)cTarCli;
tarCli.Grid.CurrentRow.Cells["date_fin"].Value = new DateTime(2999, 12, 31);
}
}
}
}
}