Ce paramétrage montre comment il est possible d'afficher une petite fenêtre contenant quelques détails d'un document, alors que la souris survole simplement la grille de l'historique clients du menu "Fenêtres". Pour des raisons d'ergonomie, le processus ne se déclenche que si la souris se déplace au-dessus des 6 premières colonnes.
Pour recompiler ce module, il suffit de créer un projet dont le nom est HistCli, qui contient une seule classe Customizer et qui a comme référence ajoutée MercatorUi.dll ou stocker dans la base de données un customizer HistCli à partir d'un onglet C# de l'éditeur de commande. (Cette seconde option est recommandée).
Cette programmation repose sur l'interface MercatorUi.ICustomizers.IFormLoadCustomizer. Comme un nouvel évènement est créé dans une fenêtre d'historique, à partir d'un objet (le customizer) dont la durée de vie est plus longue que celle de la fenêtre de signalétique, nous sommes obligés d'implémenter MercatorUi.ICustomizers.IFormClosedCustomizer pour y supprimer la souscription aux évènements CellMove, Move et FormClosing.
using System;
using System.Collections.Generic;
using System.Text;
using MercatorApi;
using MercatorExtensions;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
using System.Runtime.InteropServices;
// <CompileWithRoslyn />
namespace HistCli
{
public class Customizer : MercatorUi.ICustomizers.IFormLoadCustomizer, MercatorUi.ICustomizers.IFormClosedCustomizer
{
public void FormLoadCustomize(Form form)
{
MercatorUi.Forms.Hist.HistForm histForm = (MercatorUi.Forms.Hist.HistForm)form;
histForm.dataGridView.CellMouseMove += DataGridView_CellMouseMove;
histForm.Move += HistForm_Move;
histForm.FormClosing += HistForm_FormClosing;
}
public void FormClosedCustomize(Form form)
{
MercatorUi.Forms.Hist.HistForm histForm = (MercatorUi.Forms.Hist.HistForm)form;
histForm.dataGridView.CellMouseMove -= DataGridView_CellMouseMove;
histForm.Move -= HistForm_Move;
histForm.FormClosing -= HistForm_FormClosing;
}
void DataGridView_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
{
MercatorUi.GridPro.DataGridViewXPro grid = (MercatorUi.GridPro.DataGridViewXPro)sender;
MercatorUi.Forms.Hist.HistForm histForm = (MercatorUi.Forms.Hist.HistForm)grid.FindForm();
IntPtr activeHandle = MercatorWM.WMdll.GetActiveWindow();
if ((activeHandle == histForm.Handle) || (activeHandle == MercatorUi.Wait.WaitStatic.CurrentHandle))
{
if ((e.RowIndex > -1) && (e.ColumnIndex <= 5) && (grid.Rows[e.RowIndex].Cells["piece"].Value != DBNull.Value))
{
string id = grid.Rows[e.RowIndex].Cells["id"].Value.ToString();
string journal = grid.Rows[e.RowIndex].Cells["journal"].Value.ToString();
Int64 piece = Convert.ToInt64(grid.Rows[e.RowIndex].Cells["piece"].Value);
if (histForm.Tag?.ToString() != id + journal + piece)
{
Point p = new Point();
GetCursorPos(ref p);
StringBuilder sb = new StringBuilder("<p><strong>" + journal.TrimEnd() + " " + piece + "</strong></p>");
DataSet ds = Api.Zselect(MercatorUi.Globals.RepData, "select top 5 q,designatio from lignes_v (NOLOCK) where (id=@id) and (journal=@journal) and (piece=@piece) and (designatio<>'') order by recno \r\n select count(*) as nbre from lignes_v (NOLOCK) where (id=@id) and (journal=@journal) and (piece=@piece) and (designatio<>'')",
new MercatorSqlParam("@id", id, SqlDbType.Char),
new MercatorSqlParam("@journal", journal, SqlDbType.Char),
new MercatorSqlParam("@piece", piece));
if (ds != null)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr.Value<double>("q").CompareTo(0d, MercatorUi.Globals.N_DEC_Q) == 0)
sb.Append(dr["designatio"].ToString().TrimEnd() + "<br />");
else
sb.Append(dr.Value<double>("q").ToString("### ##0.00").TrimStart() + " " + dr["designatio"].ToString().TrimEnd() + "<br />");
}
if (ds.Tables[1].Rows[0].Value<int>("nbre") > 5)
sb.Append("...");
}
if (sb.EndsWith("<br />"))
sb.Length -= 6;
MercatorUi.Wait.WaitStatic.WaitWindowBaseThread(sb.ToString(), p, 3);
histForm.Tag = id + journal + piece;
}
}
}
}
[DllImport("user32.dll")]
static extern bool GetCursorPos(ref Point lpPoint);
void HistForm_Move(object sender, EventArgs e)
{
MercatorUi.Wait.WaitStatic.WaitClearBaseThread();
}
void HistForm_FormClosing(object sender, FormClosingEventArgs e)
{
MercatorUi.Wait.WaitStatic.WaitClearBaseThread();
}
}
}