Exemple de gestion des libellés et images des boutons (caisse tactile)

0000002756     -      31/07/2025

L'exemple illustré ici montre comment gérer l'image et le texte des boutons utilisés dans la version de démonstration caisse tactile.

Le code doit être placé dans un customizer Billing créé à partir de la séquence correspondante. Il implémente l'interface MercatorUi.ICustomizers.IBillingEngineCreated

Le code est le suivant :

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

// <ReferenceInclude>"WidgetPosTouch.dll"</ReferenceInclude>

namespace Billing
{
    public class Customizer : MercatorUi.ICustomizers.IBillingEngineCreated
    {
        public void BillingEngineCreated(MercatorUi.Engine.Gescom.BillingEngine billingEngine)
        {
            billingEngine.BillingFormLoaded += BillingEngine_BillingFormLoaded;
        }

        void BillingEngine_BillingFormLoaded(object sender, EventArgs e)
        {
            MercatorUi.Engine.Gescom.BillingEngine billingEngine = (MercatorUi.Engine.Gescom.BillingEngine)sender;
            billingEngine.BillingFormLoaded -= BillingEngine_BillingFormLoaded;
            foreach (Control c in billingEngine.BillingForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Billing.BillingObjects.TouchSelector)))
            {
                MercatorUi.Forms.Billing.BillingObjects.TouchSelector touchSelector = (MercatorUi.Forms.Billing.BillingObjects.TouchSelector)c;
                touchSelector.AddingButtons += TouchSelector_AddingButtons;
                touchSelector.ButtonTouchAdded += TouchSelectorOrList_ButtonTouchAdded;
            }
            foreach (Control c in billingEngine.BillingForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Billing.BillingObjects.TouchList)))
            {
                MercatorUi.Forms.Billing.BillingObjects.TouchList touchList = (MercatorUi.Forms.Billing.BillingObjects.TouchList)c;
                touchList.ButtonTouchAdded += TouchSelectorOrList_ButtonTouchAdded;
                touchList.AfterItemButtonClick += TouchList_AfterItemButtonClick;
            }
            billingEngine.BillingForm.FormClosed += BillingForm_FormClosed;

            foreach (MercatorUi.Widgets.WidgetBaseControl widget in MercatorUi.Globals.ListWidgets)
            {
                if (widget is WidgetPosTouch.UserControlPosTouch)
                {
                    ((WidgetPosTouch.UserControlPosTouch)widget).RegisterBilling(billingEngine.BillingForm);
                    break;
                }
            }
        }

        void BillingForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            MercatorUi.Forms.Billing.BillingForm billingForm = (MercatorUi.Forms.Billing.BillingForm)sender;
            foreach (Control c in billingForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Billing.BillingObjects.TouchSelector)))
            {
                MercatorUi.Forms.Billing.BillingObjects.TouchSelector touchSelector = (MercatorUi.Forms.Billing.BillingObjects.TouchSelector)c;
                touchSelector.AddingButtons -= TouchSelector_AddingButtons;
                touchSelector.ButtonTouchAdded -= TouchSelectorOrList_ButtonTouchAdded;
            }
            foreach (Control c in billingForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Billing.BillingObjects.TouchList)))
            {
                MercatorUi.Forms.Billing.BillingObjects.TouchList touchList = (MercatorUi.Forms.Billing.BillingObjects.TouchList)c;
                touchList.ButtonTouchAdded -= TouchSelectorOrList_ButtonTouchAdded;
                touchList.AfterItemButtonClick -= TouchList_AfterItemButtonClick;
            }
            billingForm.FormClosed -= BillingForm_FormClosed;
        }

        void TouchSelector_AddingButtons(object sender, MercatorUi.Forms.Billing.BillingObjects.TouchSelector.AddingButtonsEventArgs e)
        {
            //Dialogs.Stop(e.ReqSql.ToString());
            e.ReqSql = e.ReqSql.Replace("s_id as id,", "s_id as id,s_prix_ti,s_cle4,s_cle1,s_qv_3,s_qdispo,")
                        .Replace("order by dbo.XDESIGN_F(s_id)", "order by s_cle1");
        }

        void TouchSelectorOrList_ButtonTouchAdded(object sender, MercatorUi.Forms.Billing.BillingObjects.TouchSelector.ButtonTouchAddedEventArgs e)
        {
            if (e.ButtonTouch.Niveau == MercatorUi.Forms.Billing.BillingObjects.TouchSelector.TouchSelectorNiveau.ART)
            {
                DataSet ds = Api.Zselect(MercatorUi.Globals.RepData, string.Format("select dbo.XDESIGN_{0}(s_id) as design,s_prix_ti from STOCK (NOLOCK) where s_id=@s_id", MercatorUi.Globals.Langue), new MercatorSqlParam("@s_id", e.ButtonTouch.Name, SqlDbType.Char, 10));
                if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
                {
                    Label labelDesign = new Label();
                    labelDesign.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    labelDesign.Text = ds.Tables[0].Rows[0]["design"].ToString().TrimEnd();
                    labelDesign.AutoSize = true;
                    labelDesign.BackColor = System.Drawing.Color.Transparent;
                    labelDesign.Location = new System.Drawing.Point(5, 3);
                    e.ButtonTouch.Controls.Add(labelDesign);

                    Label labelPrix = new Label();
                    labelPrix.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    labelPrix.Text = Api.Transform(Convert.ToDouble(ds.Tables[0].Rows[0]["s_prix_ti"]), "### ##0.00") + " €";
                    labelPrix.AutoSize = false;
                    labelPrix.Size = new System.Drawing.Size(100, 14);
                    labelPrix.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                    labelPrix.BackColor = System.Drawing.Color.Transparent;
                    labelPrix.Location = new System.Drawing.Point(5, 95);
                    e.ButtonTouch.Controls.Add(labelPrix);
                }
            }
            else if (e.ButtonTouch.Text != "") // sur Rayons / Familles -> on regarde si l'image existe dans les fichiers SQL / Autres
            {
                Label labelNom = null;
                byte[] bytes = Api.SqlFileToBytes("<Other\\" + e.ButtonTouch.Text + ".png");
                if ((bytes != null) && (bytes.Length > 0))
                {
                    e.ButtonTouch.Image = Api.BytesToImage(bytes);
                    labelNom = new Label();
                    labelNom.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    labelNom.Text = e.ButtonTouch.Text;
                    labelNom.AutoSize = true;
                    labelNom.BackColor = System.Drawing.Color.Transparent;
                    labelNom.Location = new System.Drawing.Point(5, 2);
                    e.ButtonTouch.Controls.Add(labelNom);
                    e.ButtonTouch.Text = "";
                }

                if (e.ButtonTouch.Niveau == MercatorUi.Forms.Billing.BillingObjects.TouchSelector.TouchSelectorNiveau.FAMILLE)
                {
                    e.ButtonTouch.BackColor = System.Drawing.Color.IndianRed;
                    e.ButtonTouch.ColorTable = DevComponents.DotNetBar.eButtonColor.Flat;
                    if (labelNom != null)
                        labelNom.ForeColor = System.Drawing.Color.White;
                }
                else if (e.ButtonTouch.Niveau == MercatorUi.Forms.Billing.BillingObjects.TouchSelector.TouchSelectorNiveau.SSFAMILLE)
                {
                    e.ButtonTouch.BackColor = System.Drawing.Color.DarkOrange;
                    e.ButtonTouch.ColorTable = DevComponents.DotNetBar.eButtonColor.Flat;
                    if (labelNom != null)
                        labelNom.ForeColor = System.Drawing.Color.White;
                }
            }
        }

        void touchList_AfterItemButtonClick(object sender, MercatorUi.Forms.Billing.BillingObjects.TouchList.AfterItemButtonClickEventArgs e)
        {
            // on vient d'ajouter un article dans l'onglet qui contient l'objet de modes de paiements -> le mettre à jour
            MercatorUi.Forms.Billing.BillingObjects.TouchList touchList = (MercatorUi.Forms.Billing.BillingObjects.TouchList)sender;
            MercatorUi.Forms.Billing.BillingForm billingForm = (MercatorUi.Forms.Billing.BillingForm)touchList.Form;
            billingForm.UpdatePayments();
        }
    }
}

 

 



Cookies fonctionnels : Cookies nécessaires à l'utilisation du site et cookies de préférence. Ils ne contiennent aucune donnée à caractère personnel. (En savoir plus)

Cookies statistiques : Captation de statistiques liées aux comportements des internautes. (En savoir plus)

Cookies marketing : Pour effectuer le suivi des visiteurs au travers des sites web, à des fins publicitaires. (En savoir plus)