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.
// <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)