L'exemple ici montre comment gérer un mémo dans les lignes d'un document de vente ou d'achat de la gestion commerciale. Il se fait par l'ajout d'une colonne de boutons dans le LinesEditor. Le texte de ce bouton sera :
- Mémo si le mémo n'est pas vide
- mémo si le mémo est vide
Cette programmation est constuite sur base d'un customizer Billing qui implémente les interface suivantes :
Le code 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.BillingFormLoaded += new EventHandler(BillingEngine_BillingFormLoaded);
}
public void BillingEngineClosed(MercatorUi.Engine.Gescom.BillingEngine BillingEngine)
{
BillingEngine.BillingFormLoaded -= new EventHandler(BillingEngine_BillingFormLoaded);
}
void BillingEngine_BillingFormLoaded(object sender, EventArgs e)
{
MercatorUi.Engine.Gescom.BillingEngine billingEngine = (MercatorUi.Engine.Gescom.BillingEngine)sender;
if (billingEngine.BillingForm.LinesEditor != null)
{
MercatorUi.GridPro.DataGridViewHidableButtonXColumn colButtonMemo = new MercatorUi.GridPro.DataGridViewHidableButtonXColumn();
colButtonMemo.Name = "ButtonMemo";
colButtonMemo.HeaderText = "";
colButtonMemo.Width = 50;
colButtonMemo.BeforeCellPaint += new EventHandler<DevComponents.DotNetBar.Controls.BeforeCellPaintEventArgs>(colButtonMemo_BeforeCellPaint);
billingEngine.BillingForm.LinesEditor.Grid.Columns.Add(colButtonMemo);
billingEngine.BillingForm.LinesEditor.Grid.CellSuperClick += new MercatorUi.GridPro.CellSuperClickHandler(Grid_CellSuperClick);
}
}
void colButtonMemo_BeforeCellPaint(object sender, DevComponents.DotNetBar.Controls.BeforeCellPaintEventArgs e)
{
if ((e.ColumnIndex > -1) && (e.RowIndex > -1))
{
MercatorUi.GridPro.DataGridViewHidableButtonXColumn colButtonMemo = (MercatorUi.GridPro.DataGridViewHidableButtonXColumn)sender;
DataTable dt = (DataTable)colButtonMemo.DataGridView.DataSource;
if (dt.Rows[Api.DataGridViewRowToDataTableRowIndex(colButtonMemo.DataGridView.Rows[e.RowIndex])]["memo"].ToString() != "")
colButtonMemo.DataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Api.Iif_langue(Globals.Langue, "Merkz.", "Memo", "Memo", "Mémo");
else
colButtonMemo.DataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Api.Iif_langue(Globals.Langue, "merkz.", "memo", "memo", "mémo");
}
}
void Grid_CellSuperClick(object sender, DataGridViewCellEventArgs e)
{
MercatorUi.GridPro.DataGridViewXPro grid = (MercatorUi.GridPro.DataGridViewXPro)sender;
if ((e.ColumnIndex < 0 || e.RowIndex < 0) || (grid.Columns[e.ColumnIndex].Name != "ButtonMemo"))
return;
DataTable dt = (DataTable)grid.DataSource;
DataRow currentRow = dt.Rows[Api.DataGridViewRowToDataTableRowIndex(grid.Rows[e.RowIndex])];
string memo = Dialogs.AskMemo(string.Format("Memo ligne {0} ?", e.RowIndex + 1), currentRow["memo"].ToString(), grid.FindForm());
if (!dt.Columns["memo"].ReadOnly && (memo != null)) // on n'a pas cliqué sur "Annuler"
currentRow["memo"] = memo.Trim();
}
}
}
Si on souhaite effectuer la saisie d'un contenu HTML plutôt qu'un simple mémo, il suffit de remplacer cette ligne
string memo = Dialogs.AskMemo(string.Format("Memo ligne {0} ?", e.RowIndex + 1), dt.Rows[e.RowIndex]["memo"].ToString(), grid.FindForm());
par
string memo = Dialogs.AskHtml(string.Format("Memo ligne {0} ?", e.RowIndex + 1), dt.Rows[e.RowIndex]["memo"].ToString(), grid.FindForm());