Le module illustré ici permet d'ajouter un bouton dans le ruban inférieur de l'écran des rappels. Ce bouton permet de déclencher n'importe quelle action, dont notamment effectuer des modifications sur le DataSet qui se trouve derrière les deux grilles principales de l'écran. Dans notre exemple, nous nous limitons à l'affichage du DataSet.
Comme la fenêtre des rappels ne dispose pas d'un customizer qui lui est propre, il faut l'atteindre via un customizer Main qui va exploiter l'évènement BaseFormCreating. Le bouton qui va être ajouté est de type MercatorUi.BoutonsPro.ButtonXPro, çàd un bouton doté des enrichissements graphiques de Mercator. (Il est possible d'utiliser à la place le simple bouton System.Windows.Forms.Button). Le bouton sera doté d'une image libre 32x32 pixels (reprise dans le zip ci-joint).
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;
using System.Drawing;
namespace Main
{
public class Customizer : MercatorUi.ICustomizers.IExec
{
public void Main(MercatorUi.ICustomizers.ExecAction Action)
{
if (Action == MercatorUi.ICustomizers.ExecAction.DossierOpen)
{
Globals.Main.BaseFormCreating += Main_BaseFormCreating;
}
else if (Action == MercatorUi.ICustomizers.ExecAction.DossierClose)
{
Globals.Main.BaseFormCreating -= Main_BaseFormCreating;
}
}
void Main_BaseFormCreating(object sender, MercatorUi.Main.BaseFormCreatingEventArgs e)
{
if (e.Form.GetType() == typeof(MercatorUi.Forms.Accounting.AccountingRemindersForm))
e.Form.Shown += AccountingRemindersForm_Shown;
}
void AccountingRemindersForm_Shown(object sender, EventArgs e)
{
MercatorUi.Forms.Accounting.AccountingRemindersForm accountingRemindersForm = (MercatorUi.Forms.Accounting.AccountingRemindersForm)sender;
accountingRemindersForm.Shown -= AccountingRemindersForm_Shown;
MercatorUi.BoutonsPro.BleuPro bleuPro1 = (MercatorUi.BoutonsPro.BleuPro)accountingRemindersForm.Controls["bleuPro1"];
MercatorUi.BoutonsPro.ButtonXPro buttonCustom = new MercatorUi.BoutonsPro.ButtonXPro
{
AccessibleRole = AccessibleRole.PushButton,
Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, 0),
Image = Image.FromFile("window_edit.png"),
Location = new Point(250, 5),
Name = "buttonCustom",
Size = new Size(120, 48),
SubItemsExpandWidth = 16,
Text = "Custom Action"
};
buttonCustom.Click += buttonCustom_Click;
buttonCustom.Disposed += ButtonCustom_Disposed;
bleuPro1.Controls.Add(buttonCustom);
}
private void ButtonCustom_Disposed(object sender, EventArgs e)
{
MercatorUi.BoutonsPro.ButtonXPro buttonCustom = (MercatorUi.BoutonsPro.ButtonXPro)sender;
buttonCustom.Click -= buttonCustom_Click;
buttonCustom.Disposed -= ButtonCustom_Disposed;
}
void buttonCustom_Click(object sender, EventArgs e)
{
MercatorUi.BoutonsPro.ButtonXPro buttonCustom = (MercatorUi.BoutonsPro.ButtonXPro)sender;
MercatorUi.Forms.Accounting.AccountingRemindersForm accountingRemindersForm = (MercatorUi.Forms.Accounting.AccountingRemindersForm)buttonCustom.FindForm();
_Divers.ViewData(accountingRemindersForm.DataSet, true);
}
}
}
Notez qu'il est possible d'utiliser ce code dans d'autres écrans :
- Les domiciliations : le type de form à prendre en compte est MercatorUi.Forms.Accounting.AccountingBankDomForm au lieu de MercatorUi.Forms.Accounting.AccountingRemindersForm
- Les paiements : le type de form à prendre en compte est MercatorUi.Forms.Accounting.AccountingBankPayForm au lieu de MercatorUi.Forms.Accounting.AccountingRemindersForm
A télécharger :
0000002293.zip (1 Kb - 12/02/2014)