Ajouter la valorisation au DPA dans la troisième grille de l'interrogation commerciale articles

0000003179     -      25/09/2023

La programmation décrite ici montre comment ajouter une colonne affichant la valorisation au DPA (dernier prix d'achat actuel) dans la troisième grille de l'interrogation commerciale articles (StockInterro). Ce customizer SigStock se fait via l'implémentation de 2 interfaces :

Le code s'entend comme suit :

Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorUi;
using System.Windows.Forms;
using System.Linq;
 
// <CompileWithRoslyn />

namespace SigStock
{
    public class Customizer : MercatorUi.ICustomizers.IFormLoadCustomizer, MercatorUi.ICustomizers.IFormClosedCustomizer
    {
        public void FormLoadCustomize(Form form)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
            MercatorUi.Forms.Sig.SigObjects.StockInterro stockInterro = sigForm.MovableControls.Values.OfType< MercatorUi.Forms.Sig.SigObjects.StockInterro>().FirstOrDefault();
            if (stockInterro != null)
                stockInterro.AfterColumnsCreated += stockInterro_AfterColumnsCreated;
        }
        public void FormClosedCustomize(Form form)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
            MercatorUi.Forms.Sig.SigObjects.StockInterro stockInterro = sigForm.MovableControls.Values.OfType<MercatorUi.Forms.Sig.SigObjects.StockInterro>().FirstOrDefault();
            if (stockInterro != null)
                stockInterro.AfterColumnsCreated -= stockInterro_AfterColumnsCreated;
        }
        private void stockInterro_AfterColumnsCreated(object sender, EventArgs e)
        {
            MercatorUi.GridPro.DataGridViewXPro grid = (MercatorUi.GridPro.DataGridViewXPro)sender;
            if ((grid.Name == "grid3") && (grid.DataSource is DataTable dt))
            {
                MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)grid.FindForm();
                double s_dpa = Convert.ToDouble(sigForm.DataSourceRow["s_dpa"]);

                dt.Columns.Add("valorisation", typeof(double));

                foreach (DataRow dr in dt.Rows)
                {
                    dr["valorisation"] = Math.Round(s_dpa * Convert.ToDouble(dr["dispo"]), MercatorUi.Globals.DEC_DEV_B_PU);
                }

                grid.Columns.Add("valorisation", "Valor. DPA");
                grid.Columns["valorisation"].Width = 90;
                grid.Columns["valorisation"].DataPropertyName = "valorisation";
                grid.Columns["valorisation"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                grid.Columns["valorisation"].DefaultCellStyle.Format = Globals.PictBasePu;
                grid.Columns["valorisation"].SortMode = DataGridViewColumnSortMode.NotSortable;
            }
        }
    }
}

 

Si nécessaire, ce customizer peut implémenter IStringUpdater ou IStringUpdaterWithContextInfo pour modifier la requête SQL. L'id de cette requête est

<ID>STOCK_INTERRO3</ID>