In this post, I am going to share some .Net POS code samples to get you going with Retail POS coding.
Though you can use any .Net data access technology but POS provides helper classes to make things simpler.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using LSRetailPosis.DataAccess;
using LSRetailPosis.DataAccess.DataUtil;
namespace Rahul.Dynamics.Retail.DataAccess
{
public class PosIsButtonGrid : DataLayer
{
public PosIsButtonGrid(SqlConnection connection, string DATAAREAID)
: base(connection, DATAAREAID)
{
}
public DataTable GetPosIsButtonGridById(string BUTTONGRIDID)
{
SqlSelect sqlUtilSelect = new SqlSelect("POSISBUTTONGRID");
sqlUtilSelect.Select("BUTTONGRIDID");
sqlUtilSelect.Select("NAME");
sqlUtilSelect.Where("DATAAREAID", base.dataAreaId, true);
sqlUtilSelect.Where("BUTTONGRIDID", BUTTONGRIDID, false);
return base.dbUtil.GetTable(sqlUtilSelect);
}
public DataTable GetPosIsButtonGridButtonsByGridId(string BUTTONGRIDID)
{
SqlSelect sqlUtilSelect = new SqlSelect("POSISBUTTONGRIDBUTTONS");
sqlUtilSelect.Select("DISPLAYTEXT");
sqlUtilSelect.Select("ACTIONPROPERTY");
sqlUtilSelect.Where("DATAAREAID", base.dataAreaId, true);
sqlUtilSelect.Where("BUTTONGRIDID", BUTTONGRIDID, false);
sqlUtilSelect.OrderBy("ROWNUMBER", true);
return base.dbUtil.GetTable(sqlUtilSelect);
}
}
}
//Sale item. Add it to retail transaction
public static void ItemSale(ref PosTransaction posTransaction, string itemID, decimal quantity)
{
// If the transaction object is not of the type RetailTransaction, it has to be converted to one before an item can be added
if (posTransaction.GetType() != typeof(RetailTransaction))
{
posTransaction = new RetailTransaction(LSRetailPosis.Settings.ApplicationSettings.Terminal.StoreId, LSRetailPosis.Settings.ApplicationSettings.Terminal.StoreCurrency, LSRetailPosis.Settings.ApplicationSettings.Terminal.TaxIncludedInPrice, LSRetailPosis.ApplicationServices.IRounding);
TransactionSystem transSystem = new TransactionSystem(posTransaction);
transSystem.LoadTransactionStatus();
}
try
{
string selectedItemId = itemID;
//if (ApplicationServices.IItem.ItemSearch(ref selectedItemId, 500))
{
ItemSystem system = new ItemSystem((RetailTransaction)posTransaction);
string selectedBarcodeId = "";
DataTable barcodesForItem = system.GetBarcodesForItem(selectedItemId);
if (barcodesForItem == null)
{
selectedBarcodeId = "";
}
else if (barcodesForItem.Rows.Count == 0)
{
selectedBarcodeId = "";
}
else if (barcodesForItem.Rows.Count == 1)
{
selectedBarcodeId = barcodesForItem.Rows[0][0].ToString();
}
if (selectedBarcodeId.Length != 0)
{
OperationInfo o = new OperationInfo();
o.NumpadQuantity = 1;
o.NumpadValue = selectedBarcodeId;
o.ReturnItems = false;
new ItemSale { OperationID = PosisOperations.ItemSale, OperationInfo = o, Barcode = selectedBarcodeId, POSTransaction = posTransaction }.RunOperation();
}
else
{
OperationInfo o = new OperationInfo();
o.NumpadQuantity = 1;
o.NumpadValue = selectedItemId;
o.ReturnItems = false;
new ItemSale { OperationID = PosisOperations.ItemSale, OperationInfo = o, Barcode = selectedItemId, POSTransaction = posTransaction }.RunOperation();
}
}
}
catch (PosisException exception)
{
using (LSRetailPosis.POSProcesses.frmMessage dialog = new LSRetailPosis.POSProcesses.frmMessage(exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error))
{
LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog);
}
ApplicationExceptionHandler.HandleException("BlankOperation.ItemSale", exception);
throw;
}
catch (Exception exception2)
{
using (LSRetailPosis.POSProcesses.frmMessage dialog = new LSRetailPosis.POSProcesses.frmMessage(exception2.Message, MessageBoxButtons.OK, MessageBoxIcon.Error))
{
LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog);
}
ApplicationExceptionHandler.HandleException("BlankOperation.ItemSale", exception2);
throw;
}
}