Grijp in op het niveau van de LinesEditor voor Mercator de waarde gebruikt

0000003032     -      21-12-2021

Volgende programmering maakt het mogelijk om in te grijpen op het niveau van de LinesEditor bij de verkopen, aankopen, transfer tussen depots of bij de inventarissen voor dat Mercator de waarde gebruikt.

Dit kan gebruikt worden voor bv. gegevens die door een handscanner gestuurd worden te manipuleren voordat deze verwerkt worden.
In het onderstaande voorbeeld stuurt de handscanner een '1*' bij elke scan voordat de belangrijke informatie gestuurd word. Deze '1*' wordt dan verwijderd uit de sleutel.

Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using MercatorApi;
using MercatorUi;
using MercatorExtensions;
using MercatorDatabase;

namespace Billing
{
    public class Customizer : MercatorUi.ICustomizers.IFormLoadCustomizer, MercatorUi.ICustomizers.IFormClosedCustomizer
    {
        public void FormLoadCustomize(System.Windows.Forms.Form WindowsForm)
        {
            MercatorUi.Forms.Billing.BillingForm billingForm = (MercatorUi.Forms.Billing.BillingForm)WindowsForm;
            if (billingForm.LinesEditor != null)
                billingForm.LinesEditor.BeforeCellValidated += billingFormLinesEditor_BeforeCellValidated;
        }

        public void FormClosedCustomize(System.Windows.Forms.Form WindowsForm)
        {
            MercatorUi.Forms.Billing.BillingForm billingForm = (MercatorUi.Forms.Billing.BillingForm)WindowsForm;
            if (billingForm.LinesEditor != null)
                billingForm.LinesEditor.BeforeCellValidated -= billingFormLinesEditor_BeforeCellValidated;
        }

        void billingFormLinesEditor_BeforeCellValidated(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            MercatorUi.Forms.Billing.BillingObjects.LinesEditor linesEditor = (MercatorUi.Forms.Billing.BillingObjects.LinesEditor)sender;
            MercatorUi.Forms.Billing.BillingForm billingForm = (MercatorUi.Forms.Billing.BillingForm)linesEditor.Form;
            if ((e.RowIndex > -1) && (e.ColumnIndex > -1) && (linesEditor.Grid.Columns[e.ColumnIndex].Name == "id_article"))
            {
                string id_article = linesEditor.Grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().TrimEnd();
                if (id_article.EndsWith("%") && id_article.StartsWith("1*"))
                    linesEditor.Grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = id_article.Substring(2);
            }
        }
    }
}