Refactor: Refactored the bill inventory in the hope of making it less
error prone and more understandable.
Refactor: Also upgrade path to moving from Price/FullPrice to HasHappyHour/
IsHappyHour
Must have a few errors.
This commit is contained in:
@ -30,25 +30,24 @@
|
||||
{
|
||||
this.flpModifier = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.btnClose = new System.Windows.Forms.Button();
|
||||
this.flpModifier.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// flpModifier
|
||||
//
|
||||
this.flpModifier.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
|
||||
this.flpModifier.Controls.Add(this.btnClose);
|
||||
this.flpModifier.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.flpModifier.Location = new System.Drawing.Point(0, 0);
|
||||
this.flpModifier.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.flpModifier.Location = new System.Drawing.Point(0, 84);
|
||||
this.flpModifier.Name = "flpModifier";
|
||||
this.flpModifier.Size = new System.Drawing.Size(486, 408);
|
||||
this.flpModifier.Size = new System.Drawing.Size(486, 324);
|
||||
this.flpModifier.TabIndex = 6;
|
||||
//
|
||||
// btnClose
|
||||
//
|
||||
this.btnClose.Location = new System.Drawing.Point(3, 3);
|
||||
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);
|
||||
this.btnClose.Name = "btnClose";
|
||||
this.btnClose.Size = new System.Drawing.Size(480, 75);
|
||||
this.btnClose.TabIndex = 6;
|
||||
this.btnClose.TabIndex = 7;
|
||||
this.btnClose.Text = "Close";
|
||||
this.btnClose.UseVisualStyleBackColor = true;
|
||||
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
|
||||
@ -59,16 +58,14 @@
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(486, 408);
|
||||
this.ControlBox = false;
|
||||
this.Controls.Add(this.btnClose);
|
||||
this.Controls.Add(this.flpModifier);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "ModifierForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "Modifier";
|
||||
this.Load += new System.EventHandler(this.ModifierForm_Load);
|
||||
this.flpModifier.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -14,10 +14,10 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
public partial class ModifierForm : Form
|
||||
{
|
||||
private IList<Modifier> selection;
|
||||
private IList<InventoryModifier> selection;
|
||||
private IList<Modifier> source;
|
||||
private IList<CheckBox> list;
|
||||
public ModifierForm(IList<Modifier> source, IList<Modifier> selection)
|
||||
public ModifierForm(IList<Modifier> source, IList<InventoryModifier> selection)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.selection = selection;
|
||||
@ -28,18 +28,41 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
private void button_Click(object sender, EventArgs e)
|
||||
{
|
||||
CheckBox button = sender as CheckBox;
|
||||
if (button == null)
|
||||
return;
|
||||
if (button.CheckState == CheckState.Checked)
|
||||
selection.Add((Modifier)button.Tag);
|
||||
selection.Add(new InventoryModifier() { Modifier = (Modifier)button.Tag });
|
||||
else
|
||||
selection.Remove((Modifier)button.Tag);
|
||||
selection.Remove(selection.First(x => x.Modifier.ModifierID == ((Modifier)button.Tag).ModifierID));
|
||||
}
|
||||
public IList<Modifier> Selection
|
||||
private void ModifierForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
get
|
||||
var size = new Point(75, 75);
|
||||
int count = 30;
|
||||
ButtonClickDelegate bcDelegate = new ButtonClickDelegate(button_Click);
|
||||
if (list.Count != 0)
|
||||
{
|
||||
return selection;
|
||||
for (int i = list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
list[i].Dispose();
|
||||
}
|
||||
list = new List<CheckBox>();
|
||||
}
|
||||
if (count > source.Count)
|
||||
count = source.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var control = new CheckBox()
|
||||
{
|
||||
Name = i.ToString(),
|
||||
Text = source[i].Name,
|
||||
Width = size.X,
|
||||
Height = size.Y,
|
||||
Tag = source[i],
|
||||
Appearance = Appearance.Button,
|
||||
Checked = selection.Count(x => x.Modifier.ModifierID == source[i].ModifierID) > 0
|
||||
};
|
||||
control.Click += new EventHandler(bcDelegate);
|
||||
flpModifier.Controls.Add(control);
|
||||
list.Add(control);
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,10 +71,5 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void ModifierForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
ControlFactory.GenerateModifiers(ref flpModifier, ref list, selection, new Point(75, 75), 30, source, new ButtonClickDelegate(button_Click));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,8 +32,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
System.Windows.Forms.DataGridViewCellStyle dgvCellStyleDisplay = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
System.Windows.Forms.DataGridViewCellStyle dgvCellStyleQuantity = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
this.label7 = new System.Windows.Forms.Label();
|
||||
this.txtDiscount = new System.Windows.Forms.TextBox();
|
||||
this.Label12 = new System.Windows.Forms.Label();
|
||||
@ -43,8 +43,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.txtGrossTax = new System.Windows.Forms.TextBox();
|
||||
this.dgvProducts = new System.Windows.Forms.DataGridView();
|
||||
this.Display = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.printedDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.displayColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.bindingSource = new System.Windows.Forms.BindingSource(this.components);
|
||||
this.pnlBilling = new System.Windows.Forms.Panel();
|
||||
this.label10 = new System.Windows.Forms.Label();
|
||||
@ -53,7 +52,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
this.flpGroup = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.flpActions = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.btnQuantity = new System.Windows.Forms.Button();
|
||||
this.btnRate = new System.Windows.Forms.Button();
|
||||
this.btnPrice = new System.Windows.Forms.Button();
|
||||
this.btnDelete = new System.Windows.Forms.Button();
|
||||
this.btnDiscount = new System.Windows.Forms.Button();
|
||||
this.btnModifier = new System.Windows.Forms.Button();
|
||||
@ -81,6 +80,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
this.txtBillID = new System.Windows.Forms.TextBox();
|
||||
this.txtKotID = new System.Windows.Forms.TextBox();
|
||||
this.btnCustomer = new System.Windows.Forms.Button();
|
||||
this.quantityColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvProducts)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.bindingSource)).BeginInit();
|
||||
this.pnlBilling.SuspendLayout();
|
||||
@ -190,8 +190,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
this.dgvProducts.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
|
||||
this.dgvProducts.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dgvProducts.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.Display,
|
||||
this.printedDataGridViewTextBoxColumn});
|
||||
this.displayColumn,
|
||||
this.quantityColumn});
|
||||
this.dgvProducts.DataSource = this.bindingSource;
|
||||
this.dgvProducts.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically;
|
||||
this.dgvProducts.Location = new System.Drawing.Point(12, 90);
|
||||
@ -206,31 +206,31 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
//
|
||||
// Display
|
||||
//
|
||||
this.Display.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
|
||||
this.Display.DataPropertyName = "Display";
|
||||
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
||||
this.Display.DefaultCellStyle = dataGridViewCellStyle1;
|
||||
this.Display.HeaderText = "Display";
|
||||
this.Display.MinimumWidth = 250;
|
||||
this.Display.Name = "Display";
|
||||
this.Display.ReadOnly = true;
|
||||
this.Display.Width = 250;
|
||||
this.displayColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
|
||||
this.displayColumn.DataPropertyName = "Display";
|
||||
dgvCellStyleDisplay.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
||||
this.displayColumn.DefaultCellStyle = dgvCellStyleDisplay;
|
||||
this.displayColumn.HeaderText = "Display";
|
||||
this.displayColumn.MinimumWidth = 250;
|
||||
this.displayColumn.Name = "DisplayColumn";
|
||||
this.displayColumn.ReadOnly = true;
|
||||
this.displayColumn.Width = 250;
|
||||
//
|
||||
// printedDataGridViewTextBoxColumn
|
||||
// quantityColumn
|
||||
//
|
||||
this.printedDataGridViewTextBoxColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
|
||||
this.printedDataGridViewTextBoxColumn.DataPropertyName = "Quantity";
|
||||
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
|
||||
dataGridViewCellStyle2.Format = "N2";
|
||||
this.printedDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle2;
|
||||
this.printedDataGridViewTextBoxColumn.HeaderText = "Printed";
|
||||
this.printedDataGridViewTextBoxColumn.Name = "printedDataGridViewTextBoxColumn";
|
||||
this.printedDataGridViewTextBoxColumn.ReadOnly = true;
|
||||
this.printedDataGridViewTextBoxColumn.Width = 65;
|
||||
this.quantityColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
|
||||
this.quantityColumn.DataPropertyName = "Quantity";
|
||||
dgvCellStyleQuantity.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
|
||||
dgvCellStyleQuantity.Format = "N2";
|
||||
this.quantityColumn.DefaultCellStyle = dgvCellStyleQuantity;
|
||||
this.quantityColumn.HeaderText = "Quantity";
|
||||
this.quantityColumn.Name = "QuantityColumn";
|
||||
this.quantityColumn.ReadOnly = true;
|
||||
this.quantityColumn.Width = 65;
|
||||
//
|
||||
// bindingSource
|
||||
//
|
||||
this.bindingSource.DataSource = typeof(Tanshu.Accounts.Contracts.BillItemValue);
|
||||
this.bindingSource.DataSource = typeof(System.Collections.Generic.KeyValuePair<Tanshu.Accounts.Contracts.BillItemKey, Tanshu.Accounts.Contracts.BillItemValue>);
|
||||
//
|
||||
// pnlBilling
|
||||
//
|
||||
@ -309,7 +309,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
// flpActions
|
||||
//
|
||||
this.flpActions.Controls.Add(this.btnQuantity);
|
||||
this.flpActions.Controls.Add(this.btnRate);
|
||||
this.flpActions.Controls.Add(this.btnPrice);
|
||||
this.flpActions.Controls.Add(this.btnDelete);
|
||||
this.flpActions.Controls.Add(this.btnDiscount);
|
||||
this.flpActions.Controls.Add(this.btnModifier);
|
||||
@ -338,15 +338,15 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
this.btnQuantity.UseVisualStyleBackColor = true;
|
||||
this.btnQuantity.Click += new System.EventHandler(this.btnQuantity_Click);
|
||||
//
|
||||
// btnRate
|
||||
// btnPrice
|
||||
//
|
||||
this.btnRate.Location = new System.Drawing.Point(84, 3);
|
||||
this.btnRate.Name = "btnRate";
|
||||
this.btnRate.Size = new System.Drawing.Size(75, 75);
|
||||
this.btnRate.TabIndex = 146;
|
||||
this.btnRate.Text = "&Rate";
|
||||
this.btnRate.UseVisualStyleBackColor = true;
|
||||
this.btnRate.Click += new System.EventHandler(this.btnRate_Click);
|
||||
this.btnPrice.Location = new System.Drawing.Point(84, 3);
|
||||
this.btnPrice.Name = "btnPrice";
|
||||
this.btnPrice.Size = new System.Drawing.Size(75, 75);
|
||||
this.btnPrice.TabIndex = 146;
|
||||
this.btnPrice.Text = "btnPrice";
|
||||
this.btnPrice.UseVisualStyleBackColor = true;
|
||||
this.btnPrice.Click += new System.EventHandler(this.btnPrice_Click);
|
||||
//
|
||||
// btnDelete
|
||||
//
|
||||
@ -657,7 +657,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
private System.Windows.Forms.Button btnPrintKot;
|
||||
private System.Windows.Forms.Button btnPrintBill;
|
||||
private System.Windows.Forms.Button btnVoid;
|
||||
private System.Windows.Forms.Button btnRate;
|
||||
private System.Windows.Forms.Button btnPrice;
|
||||
private System.Windows.Forms.Button btnClear;
|
||||
internal System.Windows.Forms.Label lblServiceCharge;
|
||||
internal System.Windows.Forms.TextBox txtServiceCharge;
|
||||
@ -668,8 +668,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
private System.Windows.Forms.FlowLayoutPanel flpMain;
|
||||
private System.Windows.Forms.Button btnDelete;
|
||||
private System.Windows.Forms.Button btnMoveTable;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn Display;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn printedDataGridViewTextBoxColumn;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn displayColumn;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn quantityColumn;
|
||||
private System.Windows.Forms.Button btnMore;
|
||||
private System.Windows.Forms.Button btnMoveKot;
|
||||
private readonly BillController _billController;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
@ -173,11 +174,11 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
}
|
||||
}
|
||||
|
||||
private void btnRate_Click(object sender, EventArgs e)
|
||||
private void btnPrice_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_billController.SetRate();
|
||||
_billController.SetPrice();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -194,14 +195,14 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
||||
{
|
||||
var dgv = sender as DataGridView;
|
||||
var data = dgv.Rows[e.RowIndex].DataBoundItem as BillItemValue;
|
||||
var data = (KeyValuePair<BillItemKey, BillItemValue>)dgv.Rows[e.RowIndex].DataBoundItem;
|
||||
|
||||
if (data.IsKot)
|
||||
if (data.Key.BillItemType == BillItemType.Kot)
|
||||
{
|
||||
e.CellStyle.SelectionBackColor = Color.Blue;
|
||||
e.CellStyle.BackColor = Color.LightBlue;
|
||||
}
|
||||
else if (data.Printed)
|
||||
else if (data.Value.inventory.Kot != null)
|
||||
{
|
||||
e.CellStyle.SelectionBackColor = Color.HotPink;
|
||||
e.CellStyle.BackColor = Color.LightPink;
|
||||
@ -211,6 +212,15 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
e.CellStyle.SelectionBackColor = Color.Green;
|
||||
e.CellStyle.BackColor = Color.LightGreen;
|
||||
}
|
||||
if (dgv.Columns[e.ColumnIndex].Name.Equals("DisplayColumn"))
|
||||
e.Value = data.Value.Display;
|
||||
else if (dgv.Columns[e.ColumnIndex].Name.Equals("QuantityColumn"))
|
||||
{
|
||||
if (data.Key.BillItemType != BillItemType.Kot)
|
||||
e.Value = data.Value.inventory.Quantity;
|
||||
else
|
||||
e.Value = "";
|
||||
}
|
||||
}
|
||||
|
||||
private void btnSettle_Click(object sender, EventArgs e)
|
||||
@ -220,11 +230,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
|
||||
private void btnModifier_Click(object sender, EventArgs e)
|
||||
{
|
||||
var item = _billController.CurrentProduct;
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
_billController.ShowModifiers(item);
|
||||
_billController.ShowModifiers();
|
||||
}
|
||||
|
||||
private void btnDelete_Click(object sender, EventArgs e)
|
||||
@ -254,7 +260,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
{
|
||||
btnMore.Text = more ? "Less" : "More";
|
||||
btnQuantity.Visible = !more;
|
||||
btnRate.Visible = more;
|
||||
btnPrice.Visible = more;
|
||||
btnDelete.Visible = !more;
|
||||
btnDiscount.Visible = !more;
|
||||
btnModifier.Visible = !more;
|
||||
@ -271,7 +277,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
|
||||
#region Helper Functions
|
||||
|
||||
public void ClearBill(List<BillItemValue> bill)
|
||||
public void ClearBill(BillDict bill)
|
||||
{
|
||||
txtBillID.Text = "";
|
||||
txtKotID.Text = "";
|
||||
@ -292,14 +298,14 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
}
|
||||
|
||||
public void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount,
|
||||
decimal taxAmount, decimal valueAmount, List<BillItemValue> bill)
|
||||
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;
|
||||
bindingSource.DataSource = bill.ToList();
|
||||
dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user