Vous consultez une page technique concernant le logiciel de gestion Mercator. Celle-ci contient des informations spécifiques destinées aux professionnels de Mercator. Souhaitez-vous être redirigés vers des informations plus générales ?


   Ne plus poser cette question

Ouvrir un tiroir-caisse avec la bibliothèque OPOS

0000002641     -      29/06/2016

L'exemple de code fourni ici montre comment ouvrir un tiroir-caisse en utilisant les outils OPOS. Il exploite l'évènement BeforeOpenCashDrawer disponible dans l'objet Payment de la BillingForm. Il permet d'intervenir juste avant l'ouverture du tiroir-caisse.

Auapravant, il faut installer le driver OPOS.

Dans cette programmation, nous utilisons la version standard de Windows OPOS fournie par Microsoft.
Il faut donc reprendre les dll fournies dans le fichier zip ci-dessous et les copier dans le répertoire principal de Mercator.

Zoom
// <ReferenceInclude>"POS.Devices.Opos_Constants.dll"</ReferenceInclude>
// <ReferenceInclude>"POS.Devices.OPOSCashDrawer.dll"</ReferenceInclude>
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorUi;
using System.Reflection;
using System.Windows.Forms;
using POS.Devices;
using POS;

namespace Main
{
    public class Customizer : MercatorUi.ICustomizers.IExec
    {
        public void Main(MercatorUi.ICustomizers.ExecAction Action)
        {
            if (Action == MercatorUi.ICustomizers.ExecAction.DossierOpen)
            {
                MercatorUi.Forms.Billing.BillingObjects.Payments.BeforeOpenCashDrawer += new MercatorUi.Forms.Billing.BillingObjects.Payments.BeforeOpenCashDrawerEventHandler(MercatorUiFormsBillingBillingObjectsPayments_BeforeOpenCashDrawer);
            }
            if (Action == MercatorUi.ICustomizers.ExecAction.DossierClose)
            {
                MercatorUi.Forms.Billing.BillingObjects.Payments.BeforeOpenCashDrawer -= new MercatorUi.Forms.Billing.BillingObjects.Payments.BeforeOpenCashDrawerEventHandler(MercatorUiFormsBillingBillingObjectsPayments_BeforeOpenCashDrawer);
            }
        }
        void MercatorUiFormsBillingBillingObjectsPayments_BeforeOpenCashDrawer(MercatorUi.Forms.Billing.BillingObjects.Payments.BeforeOpenCashDrawerEventArgs e)
        {
            POS.Devices.OPOSCashDrawer tiroir = new POS.Devices.OPOSCashDrawer();
            int rc = 0;
            rc = tiroir.Open(Globals.ParamPos["PORT_TIR"]);
            if (rc != (int)OPOS_Constants.OPOS_SUCCESS)
            {
                Dialogs.Stop(((OPOS_Constants)Enum.ToObject(typeof(OPOS_Constants), rc)).ToString());
                e.Result = MercatorUi.Forms.Billing.BillingObjects.Payments.BeforeOpenCashDrawerResultEnum.Failed;
                return;
            }
            rc = tiroir.ClaimDevice(200);
            tiroir.DeviceEnabled = true;
            if (rc != (int)OPOS_Constants.OPOS_SUCCESS)
            {
                Dialogs.Stop(((OPOS_Constants)Enum.ToObject(typeof(OPOS_Constants), rc)).ToString());
                e.Result = MercatorUi.Forms.Billing.BillingObjects.Payments.BeforeOpenCashDrawerResultEnum.Failed;
                return;
            }
            rc = tiroir.OpenDrawer();
            if (rc != (int)OPOS_Constants.OPOS_SUCCESS)
            {
                Dialogs.Stop(((OPOS_Constants)Enum.ToObject(typeof(OPOS_Constants), rc)).ToString());
                e.Result = MercatorUi.Forms.Billing.BillingObjects.Payments.BeforeOpenCashDrawerResultEnum.Failed;
                return;
            }
            e.Result = MercatorUi.Forms.Billing.BillingObjects.Payments.BeforeOpenCashDrawerResultEnum.Done;
            tiroir.DeviceEnabled = false;
            tiroir.ReleaseDevice();
            tiroir.Close();
        }
    }
}


A télécharger : 0000002641.zip (43 Kb - 28/04/2016)