How to Implement a Trigger Project

The Triggers are empty interfaces that do not have any code. LS Retail will never add any code into them between versions. The only change that would be done is adding a new function or a change in the trigger parameters.

Because LS Retail does not provide any code in the Triggers they can be implemented as any other interface. It is not necessary to have the original trigger projects from LS Retail, although they can be used too.

The text below will go through the implementation of the TransactionTrigger interface step-by-step.

Open the Visual Studio solution provided in the development pack.

    • Source Ø Solution.sln

Configure the solution for the current machine:

    • Right-click on the POSStartProject project and select Properties.
    • Click on the Debug tab.
    • Check the Start external program option. And click the button.

    • Navigate to the location you put the development pack in. In the development pack navigate to the POS Build path and select LS One POS.exe.
      Source Ø POS Ø Build Ø LS One POS.exe
    • Right-click on the POSStartProject and click Set as StartUp Project.

Navigate to the TransactionTrigger project in the solution explorer

    • POS Ø Triggers Ø TransactionTriggers
    • Building the customized TransactionTrigger.dll
    • The project now needs to know where the dll should go so the LS One POS will pick it up when it runs. We also need to tell the VS environment which exe we want to run when we are testing and debugging our customized dll.
    • Right-click on the TransactionTriggers project and select Properties.
    • The Application tab has system information about the dll that will be built using this project. The Assembly name is the name of the dll output and the Assembly information button allows you to change information that will be visible when right-clicking on the actual dll.

    • Click Assembly Information button and add any text you want to the Title information.

    • Click on OK
    • If at this point you get build errors saying Unable to copy file and Access to path then you need to run the Visual Studio as an administrator or make sure that you have write access to the folder where the LS One POS is installed.

    • Go to the build output folder for the solution and find the Triggers folder. (DevPack Ø Source Ø POS Ø Build Ø Triggers).
      Find the LSOne.Triggers.Transaction.dll, right-click it, select Properties, select tab Details. In File description you should see the text you added to the Assembly information previously.

Running customized dll using LS One POS.

    • Open the TransactionTriggers.cs file.
      POS Ø Triggers Ø Triggers Ø TransactionTriggers.cs
    • Find function PostEndTransaction and set a breakpoint on the open curly brackets. Breakpoints can either be added by setting the cursor in the line and pressing F9 or clicking where the red circle is in the picture below.
          
            public void PostEndTransaction(IConnectionManager entry, IPosTransaction posTransaction)
            {
                try
                {
                    entry.ErrorLogger.LogMessage(LogMessageType.Trace, "When concluding the transaction, after printing and saving", "TransactionTriggers.PostEndTransaction");
                }
                catch (Exception x)
                {
                    entry.ErrorLogger.LogMessage(LogMessageType.Error, this.ToString(), x);
                    throw x;
                }
            }
          
        
    • To run the project you can either use the Play button or hit F5.

    • The LS One POS will start.
    • Log on to the LS One POS
    • Sell an item and pay for it.
    • Because a breakpoint was set in PostEndTransaction, the running will stop after the payment has been calculated and all information will be saved to the database.
    • To let the LS One POS continue, hit either the F5 or the Play button again.
    • To stop the running of the LS One POS program through the development environment either exit the LS One POS as usual or you can set the focus on the Visual Studio and hit Shift + F5.

Adding code to the PostEndTransaction trigger.

    • Find the PostEndTransaction function in the TransactionTriggers.cs again.
    • Add the code below to the function.

    • All code in C# is case sensitive

          
            public void PostEndTransaction(ref PosTransaction posTransaction)
            {
               try
               {
                  LSRetailPosis.ApplicationLog.Log(@"TransactionTriggers.PostEndTransaction",
                     @"When concluding the transaction, after printing and
                      saving", LSRetailPosis.LogTraceLevel.Trace);
                  if (posTransaction is RetailTransaction)
                  {
                    foreach (SaleLineItem currentItem in((RetailTransaction)posTransaction).SaleItems)
                    {
                      ISettings settings =
            		(Isettings)entry.Settings.GetApplicationSettings("POSApplication");
                      string message = currentItem.Description + "\n";
                      message += "Terminal: ";
                      message += settings.Terminal.ID + "\n";
                      message += "Store: ";
                      message += settings.Terminal.StoreID + "\n";
                      message += "Pos User: ";
                      message += settings.POSUser.NameOnReceipt;
                      Services.DialogService(entry).ShowMessage(message, MessageBoxButtons.OK, 			MessageBoxIcon.Information);
                    }
                  }
               }
               catch (Exception x)
               {
                  LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), x);
                  throw x;
               }
            }

          
        
    • In the code above you will notice that MessageBoxButtons and MessageBoxIcon are in red (they might be underlined with a red line in your code). This means that there is either a reference missing or a using statement. Both are windows API enums and the TransactionTriggers project needs a reference to System.Windows.Forms to resolve them. This is done by right-clicking on References in the TransactionTriggers project and clicking on Add reference. Then click on the .NET tab and find it in the list
    • Right-click on MessageBoxButtons and select ResolveØ using System.Windows.Forms;

    • Make sure the project builds without errors. You might need to add a reference to get it to build at this point. Hint: it is to an interface (see error message).
    • Make sure the breakpoint is where it was set before and run the project by pressing F5 or the Play button.
    • Log on to the LS One POS and sell a few items.
    • Pay for the items.
    • Once you have clicked on the payment button, the control should be given over to the TransactionTriggers project.
    • Use F10 (Step over) and F11 (Step into) to debug the code.
    • First we make sure that we are looking at the right type of transaction.

      if (posTransaction is RetailTransaction)

    • If the transaction is anything other than RetailTransaction then the remaining code will not be run.
    • Then we loop through all the sale items on the transaction and get information about Barcode, ItemId and Description. Then we use the Dialog service to display the message with an OK button and the information icon.

    • Take the breakpoint out of the code (select the line and press F9 again), run the LS One POS and sell different items in a couple of different sales. Every time a payment is made, the dialog will pop up for each item you sold.

Exception logging and handling

    • The LS One POS framework provides support for trace and error logging.
    • The ErrorLogger in the database entry provides functionality for logging trace and error messages. The type of logging is controlled by a type enum showed in the code example below.
          
		public void PreVoidTransaction(IConnectionManager entry
					   				   PreTriggerResults results,
					   				   PosTransaction posTransaction)
		{
			try
			{
				entry.ErrorLogger.LogMessage(LogMessageType.Trace, 
											"Before voiding the transaction...",
											"TransactionTriggers.PreVoidTransaction");
			}
			catch (Exception x)
			{
				entry.ErrorLogger.LogMessage(LogMessageType.Error, this.ToString(), x);
				throw x;
			}
		}