Major refactor of the Sales Form and Bill controller to make code more readable and less error prone.

The functions now only do one thing.
This commit is contained in:
tanshu
2016-03-31 12:27:39 +05:30
parent bb2db24837
commit 51d518d2a0
17 changed files with 615 additions and 396 deletions

View File

@ -1,6 +1,6 @@
 namespace Tanshu.Accounts.PointOfSale
{
partial class CustomersForm
partial class CustomerForm
{
/// <summary>
/// Required designer variable.
@ -180,7 +180,7 @@
this.txtUniqueID.Text = "UniqueID";
this.txtUniqueID.WordWrap = false;
//
// CustomersForm
// CustomerForm
//
this.AcceptButton = this.btnSave;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -204,10 +204,10 @@
this.Controls.Add(this.txtName);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CustomersForm";
this.Name = "CustomerForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Customers";
this.Load += new System.EventHandler(this.CustomersForm_Load);
this.Text = "Customer";
this.Load += new System.EventHandler(this.CustomerForm_Load);
this.ResumeLayout(false);
this.PerformLayout();

View File

@ -7,19 +7,24 @@ using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.PointOfSale
{
public partial class CustomersForm : Form
public partial class CustomerForm : Form
{
private Guid? _customerID;
private Customer _customer;
private readonly string phone;
#region Form Load
public CustomersForm(Guid? customerID, string phone)
public CustomerForm(Guid? customerID)
{
InitializeComponent();
this._customerID = customerID;
}
public CustomerForm(Guid? customerID, string phone)
{
InitializeComponent();
this._customerID = customerID;
this.phone = phone;
}
private void CustomersForm_Load(object sender, EventArgs e)
private void CustomerForm_Load(object sender, EventArgs e)
{
if (_customerID.HasValue)
{

View File

@ -0,0 +1,167 @@
namespace Tanshu.Accounts.PointOfSale
{
partial class CustomerListForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.btnAdd = new System.Windows.Forms.Button();
this.btnEdit = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.dgvCustomers = new System.Windows.Forms.DataGridView();
this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.phone = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.address = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.bsList = new System.Windows.Forms.BindingSource(this.components);
((System.ComponentModel.ISupportInitialize)(this.dgvCustomers)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsList)).BeginInit();
this.SuspendLayout();
//
// btnAdd
//
this.btnAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnAdd.Location = new System.Drawing.Point(12, 255);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(75, 75);
this.btnAdd.TabIndex = 68;
this.btnAdd.Text = "&Add";
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// btnEdit
//
this.btnEdit.AccessibleName = "Done";
this.btnEdit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnEdit.Location = new System.Drawing.Point(93, 255);
this.btnEdit.Name = "btnEdit";
this.btnEdit.Size = new System.Drawing.Size(75, 75);
this.btnEdit.TabIndex = 62;
this.btnEdit.Text = "&Edit";
this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click);
//
// btnExit
//
this.btnExit.AccessibleName = "Done";
this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnExit.Location = new System.Drawing.Point(575, 255);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(75, 75);
this.btnExit.TabIndex = 61;
this.btnExit.Text = "E&xit";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// dgvCustomers
//
this.dgvCustomers.AllowUserToAddRows = false;
this.dgvCustomers.AllowUserToDeleteRows = false;
this.dgvCustomers.AllowUserToResizeRows = false;
this.dgvCustomers.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dgvCustomers.AutoGenerateColumns = false;
this.dgvCustomers.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;
this.dgvCustomers.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvCustomers.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.nameDataGridViewTextBoxColumn,
this.phone,
this.address});
this.dgvCustomers.DataSource = this.bsList;
this.dgvCustomers.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically;
this.dgvCustomers.Location = new System.Drawing.Point(12, 12);
this.dgvCustomers.MultiSelect = false;
this.dgvCustomers.Name = "dgvCustomers";
this.dgvCustomers.ReadOnly = true;
this.dgvCustomers.RowHeadersVisible = false;
this.dgvCustomers.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
this.dgvCustomers.RowTemplate.Height = 24;
this.dgvCustomers.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dgvCustomers.Size = new System.Drawing.Size(638, 237);
this.dgvCustomers.TabIndex = 74;
this.dgvCustomers.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvCustomers_CellDoubleClick);
//
// nameDataGridViewTextBoxColumn
//
this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name";
this.nameDataGridViewTextBoxColumn.HeaderText = "Name";
this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn";
this.nameDataGridViewTextBoxColumn.ReadOnly = true;
this.nameDataGridViewTextBoxColumn.Width = 60;
//
// phone
//
this.phone.DataPropertyName = "Phone";
this.phone.HeaderText = "Phone";
this.phone.Name = "phone";
this.phone.ReadOnly = true;
this.phone.Width = 63;
//
// address
//
this.address.DataPropertyName = "Address";
this.address.HeaderText = "Address";
this.address.Name = "address";
this.address.ReadOnly = true;
this.address.Width = 70;
//
// bsList
//
this.bsList.DataSource = typeof(Tanshu.Accounts.Entities.Customer);
//
// CustomerListForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(662, 342);
this.Controls.Add(this.dgvCustomers);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.btnEdit);
this.Controls.Add(this.btnExit);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CustomerListForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Customers";
this.Load += new System.EventHandler(this.CustomerListForm_Load);
((System.ComponentModel.ISupportInitialize)(this.dgvCustomers)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bsList)).EndInit();
this.ResumeLayout(false);
}
#endregion
internal System.Windows.Forms.Button btnAdd;
internal System.Windows.Forms.Button btnEdit;
internal System.Windows.Forms.Button btnExit;
private System.Windows.Forms.DataGridView dgvCustomers;
private System.Windows.Forms.BindingSource bsList;
private System.Windows.Forms.DataGridViewTextBoxColumn Password;
private System.Windows.Forms.DataGridViewTextBoxColumn CustomerGroups;
private System.Windows.Forms.DataGridViewTextBoxColumn nameDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn phone;
private System.Windows.Forms.DataGridViewTextBoxColumn address;
}
}

View File

@ -0,0 +1,74 @@
using System;
using System.Linq;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Repository;
using System.Collections.Generic;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.PointOfSale
{
public partial class CustomerListForm : Form
{
private IList<Customer> _list;
public CustomerListForm()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
using (var frm = new CustomerForm(null))
frm.ShowDialog();
using (var bi = new CustomerBI())
_list = bi.List();
bsList.DataSource = _list;
}
private void CustomerListForm_Load(object sender, EventArgs e)
{
ShowGrid();
}
private void ShowGrid()
{
using (var bi = new CustomerBI())
_list = bi.List();
bsList.DataSource = _list;
}
private void btnEdit_Click(object sender, EventArgs e)
{
var id = ((Customer)bsList.Current).CustomerID;
using (var frm = new CustomerForm(id))
frm.ShowDialog();
using (var bi = new CustomerBI())
_list = bi.List();
bsList.DataSource = _list;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
public Customer SelectedItem
{
get
{
if (bsList.Position >= 0)
{
var item = _list[bsList.Position];
if (item != null)
return item;
}
return _list.First(x => x.CustomerID == Constants.CASH_CUSTOMER);
}
}
private void dgvCustomers_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
this.Close();
}
}
}

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="phone.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="address.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="bsList.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -44,7 +44,8 @@
// btnClose
//
this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); this.btnClose.Location = new System.Drawing.Point(3, 3);
| System.Windows.Forms.AnchorStyles.Right)));
this.btnClose.Location = new System.Drawing.Point(3, 3);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(480, 75);
this.btnClose.TabIndex = 7;
@ -66,6 +67,7 @@
this.Text = "Modifier";
this.Load += new System.EventHandler(this.ModifierForm_Load);
this.ResumeLayout(false);
}
#endregion

View File

@ -27,17 +27,15 @@ namespace Tanshu.Accounts.PointOfSale.Sales
Text = name;
}
public void SetCustomerDisplay(string name)
{
btnCustomer.Text = name;
}
public void ShowInfo(Voucher voucher)
private void ShowInfo(Voucher voucher, BillDict bill)
{
if (voucher.VoucherID == Guid.Empty)
{
txtTableID.Text = voucher.Table.Name;
txtPax.Text = voucher.Pax.ToString();
txtBillID.Text = "";
txtKotID.Text = "";
txtCreationDate.Text = "";
txtDate.Text = "";
txtLastEditDate.Text = "";
}
else
{
@ -46,15 +44,52 @@ namespace Tanshu.Accounts.PointOfSale.Sales
txtCreationDate.Text = voucher.CreationDate.ToString("HH:mm dd-MMM-yyyy");
txtDate.Text = voucher.Date.ToString("HH:mm dd-MMM-yyyy");
txtLastEditDate.Text = voucher.LastEditDate.ToString("HH:mm dd-MMM-yyyy");
btnCustomer.Text = voucher.Customer.Name;
txtTableID.Text = voucher.Table.Name;
txtPax.Text = voucher.Pax.ToString();
}
btnCustomer.Text = voucher.Customer.Name;
txtTableID.Text = voucher.Table == null ? "" : voucher.Table.Name;
txtPax.Text = voucher.Pax.ToString();
bindingSource.CurrencyManager.Position = Math.Min(bindingSource.CurrencyManager.Position, bill.Count - 1);
txtGrossTax.Text = string.Format("{0:#0.00}", bill.Tax);
txtDiscount.Text = string.Format("{0:#0.00}", bill.Discount);
txtServiceCharge.Text = string.Format("{0:#0.00}", bill.ServiceCharge);
txtGrossAmount.Text = string.Format("{0:#0.00}", bill.NetAmount);
txtAmount.Text = string.Format("{0:#0.00}", bill.Amount);
bindingSource.DataSource = bill.ToList();
dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
MoreButton(false);
}
public BillItemValue CurrentProduct
{
get
{
if (bindingSource.Position == -1)
return null;
var item = _billController._bill.ElementAt(bindingSource.Position);
return item.Key.BillItemType != BillItemType.Kot ? item.Value : null;
}
}
public BindingSource BindingSource
public BillItemKey CurrentKey
{
get { return bindingSource; }
get
{
if (bindingSource.Position == -1)
return null;
var item = _billController._bill.ElementAt(bindingSource.Position);
return item.Key;
}
}
public BillItemKey CurrentKot
{
get
{
if (bindingSource.Position == -1)
return null;
var item = _billController._bill.ElementAt(bindingSource.Position);
return item.Key.BillItemType == BillItemType.Kot ? item.Key : null;
}
}
public void CloseWindow()
@ -81,22 +116,17 @@ namespace Tanshu.Accounts.PointOfSale.Sales
case Keys.F4:
{
if (!e.Alt)
_billController.ShowCustomers(false);
break;
}
case Keys.F7:
{
//using (var selectProduct = new SelectProduct(ProductBI.GetFilteredProducts, true))
//{
// selectProduct.ShowDialog();
// if (selectProduct.SelectedItem != null)
// _billController.AddProduct(selectProduct.SelectedItem.ProductID);
//}
{
_billController.ShowCustomers();
ShowInfo(_billController._voucher, _billController._bill);
}
break;
}
case Keys.F8:
{
_billController.LoadBill(null);
ShowInfo(_billController._voucher, _billController._bill);
FormState = SaleFormState.Billing;
break;
}
case Keys.F11:
@ -111,18 +141,20 @@ namespace Tanshu.Accounts.PointOfSale.Sales
}
case Keys.Delete:
{
_billController.SetQuantity(-1, false);
//_billController.ProductRemove();
_billController.SetQuantity(CurrentKey, CurrentProduct, -1, false);
ShowInfo(_billController._voucher, _billController._bill);
break;
}
case Keys.Add:
{
_billController.SetQuantity(1, false);
_billController.SetQuantity(CurrentKey, CurrentProduct, 1, false);
ShowInfo(_billController._voucher, _billController._bill);
break;
}
case Keys.Subtract:
{
_billController.SetQuantity(-1, false);
_billController.SetQuantity(CurrentKey, CurrentProduct, -1, false);
ShowInfo(_billController._voucher, _billController._bill);
break;
}
case Keys.Up:
@ -139,7 +171,10 @@ namespace Tanshu.Accounts.PointOfSale.Sales
}
case Keys.Escape:
{
_billController.CancelBillChanges();
var canceled = _billController.CancelBillChanges();
ShowInfo(_billController._voucher, _billController._bill);
if (canceled)
FormState = SaleFormState.Waiting;
break;
}
}
@ -153,43 +188,41 @@ namespace Tanshu.Accounts.PointOfSale.Sales
txtServiceCharge.Visible = showSC;
lblServiceCharge.Visible = showSC;
}
_billController.FormLoad();
FormState = SaleFormState.Waiting;
_billController.ClearBill();
var state = _billController.FormLoad();
ShowInfo(_billController._voucher, _billController._bill);
FormState = state;
}
private void btnCustomer_Click(object sender, EventArgs e)
{
_billController.ShowCustomers(false);
_billController.ShowCustomers();
ShowInfo(_billController._voucher, _billController._bill);
}
private void btnVoid_Click(object sender, EventArgs e)
{
try
{
_billController.VoidBill();
}
catch (PermissionException ex)
{
MessageBox.Show(ex.Message);
}
var voided = _billController.VoidBill();
ShowInfo(_billController._voucher, _billController._bill);
if (voided)
FormState = SaleFormState.Waiting;
}
private void btnPrice_Click(object sender, EventArgs e)
{
try
{
_billController.SetPrice();
}
catch (Exception ex)
{
if (!(ex is ValidationException) && !(ex is PermissionException))
throw;
}
var item = CurrentProduct;
if (item == null)
return;
_billController.SetPrice(CurrentProduct);
ShowInfo(_billController._voucher, _billController._bill);
}
private void btnClear_Click(object sender, EventArgs e)
{
_billController.CancelBillChanges();
var canceled = _billController.CancelBillChanges();
ShowInfo(_billController._voucher, _billController._bill);
if (canceled)
FormState = SaleFormState.Waiting;
}
private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
@ -225,22 +258,32 @@ namespace Tanshu.Accounts.PointOfSale.Sales
private void btnSettle_Click(object sender, EventArgs e)
{
_billController.SettleBill();
var settled = _billController.SettleBill();
ShowInfo(_billController._voucher, _billController._bill);
if (settled)
FormState = SaleFormState.Waiting;
}
private void btnModifier_Click(object sender, EventArgs e)
{
_billController.ShowModifiers();
var item = CurrentProduct;
if (item == null || CurrentKey.KotID != Guid.Empty)
return; // No Product or Old Product
_billController.ShowModifiers(item);
ShowInfo(_billController._voucher, _billController._bill);
}
private void btnDelete_Click(object sender, EventArgs e)
{
_billController.SetQuantity(-1, false);
_billController.SetQuantity(CurrentKey, CurrentProduct, -1, false);
ShowInfo(_billController._voucher, _billController._bill);
}
private void btnMoveTable_Click(object sender, EventArgs e)
{
_billController.MoveTable();
ShowInfo(_billController._voucher, _billController._bill);
}
private void btnMore_Click(object sender, EventArgs e)
@ -272,44 +315,13 @@ namespace Tanshu.Accounts.PointOfSale.Sales
private void btnMoveKot_Click(object sender, EventArgs e)
{
_billController.MoveKot();
_billController.MoveKot(CurrentKot);
ShowInfo(_billController._voucher, _billController._bill);
}
#region Helper Functions
public void ClearBill(BillDict bill)
{
txtBillID.Text = "";
txtKotID.Text = "";
txtCreationDate.Text = "";
txtDate.Text = "";
txtLastEditDate.Text = "";
txtTableID.Text = "";
txtPax.Text = "";
txtGrossTax.Text = "0.00";
txtDiscount.Text = "0.00";
txtServiceCharge.Text = "0.00";
txtGrossAmount.Text = "0.00";
txtAmount.Text = "0.00";
bindingSource.CurrencyManager.Position = 0; //Hack for Mono
bindingSource.DataSource = bill;
MoreButton(false);
FormState = SaleFormState.Waiting;
}
public void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount,
decimal taxAmount, decimal valueAmount, BillDict bill)
{
txtGrossTax.Text = string.Format("{0:#0.00}", taxAmount);
txtDiscount.Text = string.Format("{0:#0.00}", discountAmount);
txtServiceCharge.Text = string.Format("{0:#0.00}", serviceChargeAmount);
txtGrossAmount.Text = string.Format("{0:#0.00}", grossAmount);
txtAmount.Text = string.Format("{0:#0.00}", Math.Round(valueAmount));
bindingSource.DataSource = bill.ToList();
dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
}
public SaleFormState FormState
private SaleFormState FormState
{
set
{
@ -356,6 +368,15 @@ namespace Tanshu.Accounts.PointOfSale.Sales
if (item.IsNotAvailable)
return;
_billController.AddProduct(item);
bindingSource.DataSource = _billController._bill.ToList();
bindingSource.CurrencyManager.Position = _billController._bill.IndexOfKey(new BillItemKey(item.ProductID, Guid.Empty));
var showModifier = false;
using (var bi = new ProductGroupModifierBI())
showModifier = bi.HasCompulsoryModifier(CurrentProduct.inventory.Product.ProductGroup.ProductGroupID);
if (showModifier)
_billController.ShowModifiers(CurrentProduct);
ShowInfo(_billController._voucher, _billController._bill);
}
private void productPage_Click(object sender, EventArgs e)
@ -378,6 +399,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
var item = button.Tag as FoodTable;
var tableName = item.Name;
_billController.LoadBill(tableName);
ShowInfo(_billController._voucher, _billController._bill);
FormState = SaleFormState.Billing;
}
@ -394,30 +416,30 @@ namespace Tanshu.Accounts.PointOfSale.Sales
}
private void btnPrintBill_Click(object sender, EventArgs e)
{
_billController.SaveBill();
var printed = _billController.SaveAndPrintBill();
ShowInfo(_billController._voucher, _billController._bill);
if (printed)
FormState = SaleFormState.Waiting;
}
private void btnPrintKot_Click(object sender, EventArgs e)
{
_billController.SaveKot();
var printed = _billController.SaveAndPrintKot();
ShowInfo(_billController._voucher, _billController._bill);
if (printed)
FormState = SaleFormState.Waiting;
}
private void btnQuantity_Click(object sender, EventArgs e)
{
_billController.SetQuantity(0, true);
_billController.SetQuantity(CurrentKey, CurrentProduct, 0, true);
ShowInfo(_billController._voucher, _billController._bill);
}
private void btnDiscount_Click(object sender, EventArgs e)
{
try
{
_billController.SetDiscount();
}
catch (Exception ex)
{
if (!(ex is ValidationException) && !(ex is PermissionException))
throw;
}
_billController.SetDiscount();
ShowInfo(_billController._voucher, _billController._bill);
}
#endregion
@ -425,6 +447,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
private void btnSplitBill_Click(object sender, EventArgs e)
{
_billController.SplitBill();
ShowInfo(_billController._voucher, _billController._bill);
}
}
}