Chore: Rename _billController to _controller as it is shorter

Removed: Unused SelectorEvent Helper
Refactor: Removed references to SaleForm from BillController as it is not needed.
This commit is contained in:
tanshu
2016-03-31 14:13:26 +05:30
parent 51d518d2a0
commit 69cb7d8bce
7 changed files with 75 additions and 151 deletions

View File

@ -1,38 +0,0 @@
using System;
namespace Tanshu.Accounts.Helpers
{
public enum SelectorAction
{
Insert = 1,
Update = 2,
Delete = 3
}
public class SelectorEventArgs<T> : EventArgs
{
public SelectorEventArgs(T item, SelectorAction action)
{
Item = item;
Action = action;
Handled = false;
}
public T Item
{
get;
private set;
}
public SelectorAction Action
{
get;
private set;
}
public bool Handled
{
get;
set;
}
}
}

View File

@ -66,7 +66,6 @@
<Compile Include="CustomStructs.cs"> <Compile Include="CustomStructs.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="SelectorEvent.cs" />
<Compile Include="SelectVoidReason.cs"> <Compile Include="SelectVoidReason.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

View File

@ -15,8 +15,7 @@ namespace Tanshu.Accounts.PointOfSale
{ {
public readonly BillDict _bill; public readonly BillDict _bill;
public Voucher _voucher; public Voucher _voucher;
private Guid? _editVoucherID; public Guid? _editVoucherID;
private ISaleForm _saleForm;
public BillController(Guid? editVoucherID) public BillController(Guid? editVoucherID)
{ {
@ -26,11 +25,6 @@ namespace Tanshu.Accounts.PointOfSale
_voucher = new Voucher(Session.User, bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER)); _voucher = new Voucher(Session.User, bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER));
} }
public void InitGui(ISaleForm saleForm)
{
this._saleForm = saleForm;
this._saleForm.SetUserName(Session.User.Name);
}
public void AddProduct(Product product) public void AddProduct(Product product)
{ {
var newKey = new BillItemKey(product.ProductID, Guid.Empty); var newKey = new BillItemKey(product.ProductID, Guid.Empty);
@ -148,7 +142,6 @@ namespace Tanshu.Accounts.PointOfSale
using (var bi = new VoucherBI()) using (var bi = new VoucherBI())
{ {
_voucher = bi.Get(x => x.VoucherID == voucherID); _voucher = bi.Get(x => x.VoucherID == voucherID);
_bill.Clear();
_bill.Load(_voucher); _bill.Load(_voucher);
var newKotKey = new BillItemKey(Guid.Empty); var newKotKey = new BillItemKey(Guid.Empty);
var newKotItem = new BillItemValue(); var newKotItem = new BillItemValue();
@ -184,7 +177,7 @@ namespace Tanshu.Accounts.PointOfSale
ClearBill(); ClearBill();
return true; return true;
} }
public void ClearBill() private void ClearBill()
{ {
using (var bi = new CustomerBI()) using (var bi = new CustomerBI())
_voucher = new Voucher(Session.User, bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER)); _voucher = new Voucher(Session.User, bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER));
@ -195,18 +188,15 @@ namespace Tanshu.Accounts.PointOfSale
} }
public SaleFormState FormLoad() public SaleFormState FormLoad()
{ {
ClearBill();
if (_editVoucherID.HasValue) if (_editVoucherID.HasValue)
{ {
FoodTable ft = new FoodTableBI().Get(x => x.VoucherID == _editVoucherID.Value); FoodTable ft = new FoodTableBI().Get(x => x.VoucherID == _editVoucherID.Value);
if (ft == null) if (ft == null)
{
LoadBill(_editVoucherID.Value);
}
else
{ {
_editVoucherID = null; _editVoucherID = null;
LoadBill(ft.Name);
} }
LoadBill(_editVoucherID.Value);
return SaleFormState.Billing; return SaleFormState.Billing;
} }
return SaleFormState.Waiting; return SaleFormState.Waiting;
@ -387,12 +377,7 @@ namespace Tanshu.Accounts.PointOfSale
Thermal.PrintKot(_voucher.VoucherID, saved.Value); Thermal.PrintKot(_voucher.VoucherID, saved.Value);
//Cleanup //Cleanup
if (_editVoucherID.HasValue) ClearBill();
_saleForm.CloseWindow();
else
{
ClearBill();
}
return true; return true;
} }
public bool SaveAndPrintBill() public bool SaveAndPrintBill()
@ -440,8 +425,6 @@ namespace Tanshu.Accounts.PointOfSale
UpdateVoucher(true, !_editVoucherID.HasValue); UpdateVoucher(true, !_editVoucherID.HasValue);
} }
Thermal.PrintBill(_voucher.VoucherID); Thermal.PrintBill(_voucher.VoucherID);
if (_editVoucherID.HasValue)
_saleForm.CloseWindow();
ClearBill(); ClearBill();
return true; return true;
} }

View File

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanshu.Accounts.Contracts;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Common;
namespace Tanshu.Accounts.PointOfSale
{
public interface ISaleForm
{
void CloseWindow();
void SetUserName(string name);
}
}

View File

@ -672,7 +672,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
private System.Windows.Forms.DataGridViewTextBoxColumn quantityColumn; private System.Windows.Forms.DataGridViewTextBoxColumn quantityColumn;
private System.Windows.Forms.Button btnMore; private System.Windows.Forms.Button btnMore;
private System.Windows.Forms.Button btnMoveKot; private System.Windows.Forms.Button btnMoveKot;
private readonly BillController _billController; private readonly BillController _controller;
private System.Windows.Forms.Button btnSplitBill; private System.Windows.Forms.Button btnSplitBill;
private System.Windows.Forms.Label label10; private System.Windows.Forms.Label label10;
private System.Windows.Forms.TextBox txtPax; private System.Windows.Forms.TextBox txtPax;

View File

@ -11,20 +11,14 @@ using Tanshu.Accounts.Repository;
namespace Tanshu.Accounts.PointOfSale.Sales namespace Tanshu.Accounts.PointOfSale.Sales
{ {
public partial class SalesForm : Form, ISaleForm public partial class SalesForm : Form
{ {
private ProductGroup _currentProductGroup; private ProductGroup _currentProductGroup;
public SalesForm(BillController billController) public SalesForm(BillController billController)
{ {
InitializeComponent(); InitializeComponent();
_billController = billController; _controller = billController;
billController.InitGui(this); this.Text = Session.User.Name;
}
#region ISaleForm Members
public void SetUserName(string name)
{
Text = name;
} }
private void ShowInfo(Voucher voucher, BillDict bill) private void ShowInfo(Voucher voucher, BillDict bill)
@ -65,7 +59,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
{ {
if (bindingSource.Position == -1) if (bindingSource.Position == -1)
return null; return null;
var item = _billController._bill.ElementAt(bindingSource.Position); var item = _controller._bill.ElementAt(bindingSource.Position);
return item.Key.BillItemType != BillItemType.Kot ? item.Value : null; return item.Key.BillItemType != BillItemType.Kot ? item.Value : null;
} }
} }
@ -76,7 +70,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
{ {
if (bindingSource.Position == -1) if (bindingSource.Position == -1)
return null; return null;
var item = _billController._bill.ElementAt(bindingSource.Position); var item = _controller._bill.ElementAt(bindingSource.Position);
return item.Key; return item.Key;
} }
} }
@ -87,18 +81,11 @@ namespace Tanshu.Accounts.PointOfSale.Sales
{ {
if (bindingSource.Position == -1) if (bindingSource.Position == -1)
return null; return null;
var item = _billController._bill.ElementAt(bindingSource.Position); var item = _controller._bill.ElementAt(bindingSource.Position);
return item.Key.BillItemType == BillItemType.Kot ? item.Key : null; return item.Key.BillItemType == BillItemType.Kot ? item.Key : null;
} }
} }
public void CloseWindow()
{
Close();
}
#endregion
private void SalesForm_KeyDown(object sender, KeyEventArgs e) private void SalesForm_KeyDown(object sender, KeyEventArgs e)
{ {
switch (e.KeyCode) switch (e.KeyCode)
@ -117,15 +104,15 @@ namespace Tanshu.Accounts.PointOfSale.Sales
{ {
if (!e.Alt) if (!e.Alt)
{ {
_billController.ShowCustomers(); _controller.ShowCustomers();
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
} }
break; break;
} }
case Keys.F8: case Keys.F8:
{ {
_billController.LoadBill(null); _controller.LoadBill(null);
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
FormState = SaleFormState.Billing; FormState = SaleFormState.Billing;
break; break;
} }
@ -141,20 +128,20 @@ namespace Tanshu.Accounts.PointOfSale.Sales
} }
case Keys.Delete: case Keys.Delete:
{ {
_billController.SetQuantity(CurrentKey, CurrentProduct, -1, false); _controller.SetQuantity(CurrentKey, CurrentProduct, -1, false);
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
break; break;
} }
case Keys.Add: case Keys.Add:
{ {
_billController.SetQuantity(CurrentKey, CurrentProduct, 1, false); _controller.SetQuantity(CurrentKey, CurrentProduct, 1, false);
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
break; break;
} }
case Keys.Subtract: case Keys.Subtract:
{ {
_billController.SetQuantity(CurrentKey, CurrentProduct, -1, false); _controller.SetQuantity(CurrentKey, CurrentProduct, -1, false);
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
break; break;
} }
case Keys.Up: case Keys.Up:
@ -171,8 +158,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales
} }
case Keys.Escape: case Keys.Escape:
{ {
var canceled = _billController.CancelBillChanges(); var canceled = _controller.CancelBillChanges();
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
if (canceled) if (canceled)
FormState = SaleFormState.Waiting; FormState = SaleFormState.Waiting;
break; break;
@ -188,22 +175,21 @@ namespace Tanshu.Accounts.PointOfSale.Sales
txtServiceCharge.Visible = showSC; txtServiceCharge.Visible = showSC;
lblServiceCharge.Visible = showSC; lblServiceCharge.Visible = showSC;
} }
_billController.ClearBill(); var state = _controller.FormLoad();
var state = _billController.FormLoad(); ShowInfo(_controller._voucher, _controller._bill);
ShowInfo(_billController._voucher, _billController._bill);
FormState = state; FormState = state;
} }
private void btnCustomer_Click(object sender, EventArgs e) private void btnCustomer_Click(object sender, EventArgs e)
{ {
_billController.ShowCustomers(); _controller.ShowCustomers();
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
} }
private void btnVoid_Click(object sender, EventArgs e) private void btnVoid_Click(object sender, EventArgs e)
{ {
var voided = _billController.VoidBill(); var voided = _controller.VoidBill();
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
if (voided) if (voided)
FormState = SaleFormState.Waiting; FormState = SaleFormState.Waiting;
} }
@ -213,14 +199,14 @@ namespace Tanshu.Accounts.PointOfSale.Sales
var item = CurrentProduct; var item = CurrentProduct;
if (item == null) if (item == null)
return; return;
_billController.SetPrice(CurrentProduct); _controller.SetPrice(CurrentProduct);
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
} }
private void btnClear_Click(object sender, EventArgs e) private void btnClear_Click(object sender, EventArgs e)
{ {
var canceled = _billController.CancelBillChanges(); var canceled = _controller.CancelBillChanges();
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
if (canceled) if (canceled)
FormState = SaleFormState.Waiting; FormState = SaleFormState.Waiting;
} }
@ -258,8 +244,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales
private void btnSettle_Click(object sender, EventArgs e) private void btnSettle_Click(object sender, EventArgs e)
{ {
var settled = _billController.SettleBill(); var settled = _controller.SettleBill();
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
if (settled) if (settled)
FormState = SaleFormState.Waiting; FormState = SaleFormState.Waiting;
} }
@ -270,20 +256,20 @@ namespace Tanshu.Accounts.PointOfSale.Sales
if (item == null || CurrentKey.KotID != Guid.Empty) if (item == null || CurrentKey.KotID != Guid.Empty)
return; // No Product or Old Product return; // No Product or Old Product
_billController.ShowModifiers(item); _controller.ShowModifiers(item);
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
} }
private void btnDelete_Click(object sender, EventArgs e) private void btnDelete_Click(object sender, EventArgs e)
{ {
_billController.SetQuantity(CurrentKey, CurrentProduct, -1, false); _controller.SetQuantity(CurrentKey, CurrentProduct, -1, false);
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
} }
private void btnMoveTable_Click(object sender, EventArgs e) private void btnMoveTable_Click(object sender, EventArgs e)
{ {
_billController.MoveTable(); _controller.MoveTable();
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
} }
private void btnMore_Click(object sender, EventArgs e) private void btnMore_Click(object sender, EventArgs e)
@ -315,8 +301,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales
private void btnMoveKot_Click(object sender, EventArgs e) private void btnMoveKot_Click(object sender, EventArgs e)
{ {
_billController.MoveKot(CurrentKot); _controller.MoveKot(CurrentKot);
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
} }
#region Helper Functions #region Helper Functions
@ -367,16 +353,16 @@ namespace Tanshu.Accounts.PointOfSale.Sales
var item = button.Tag as Product; var item = button.Tag as Product;
if (item.IsNotAvailable) if (item.IsNotAvailable)
return; return;
_billController.AddProduct(item); _controller.AddProduct(item);
bindingSource.DataSource = _billController._bill.ToList(); bindingSource.DataSource = _controller._bill.ToList();
bindingSource.CurrencyManager.Position = _billController._bill.IndexOfKey(new BillItemKey(item.ProductID, Guid.Empty)); bindingSource.CurrencyManager.Position = _controller._bill.IndexOfKey(new BillItemKey(item.ProductID, Guid.Empty));
var showModifier = false; var showModifier = false;
using (var bi = new ProductGroupModifierBI()) using (var bi = new ProductGroupModifierBI())
showModifier = bi.HasCompulsoryModifier(CurrentProduct.inventory.Product.ProductGroup.ProductGroupID); showModifier = bi.HasCompulsoryModifier(CurrentProduct.inventory.Product.ProductGroup.ProductGroupID);
if (showModifier) if (showModifier)
_billController.ShowModifiers(CurrentProduct); _controller.ShowModifiers(CurrentProduct);
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
} }
private void productPage_Click(object sender, EventArgs e) private void productPage_Click(object sender, EventArgs e)
@ -398,8 +384,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales
return; return;
var item = button.Tag as FoodTable; var item = button.Tag as FoodTable;
var tableName = item.Name; var tableName = item.Name;
_billController.LoadBill(tableName); _controller.LoadBill(tableName);
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
FormState = SaleFormState.Billing; FormState = SaleFormState.Billing;
} }
@ -416,38 +402,50 @@ namespace Tanshu.Accounts.PointOfSale.Sales
} }
private void btnPrintBill_Click(object sender, EventArgs e) private void btnPrintBill_Click(object sender, EventArgs e)
{ {
var printed = _billController.SaveAndPrintBill(); var printed = _controller.SaveAndPrintBill();
ShowInfo(_billController._voucher, _billController._bill); if (!printed)
if (printed) return;
if (_controller._editVoucherID.HasValue)
this.Close();
else
{
ShowInfo(_controller._voucher, _controller._bill);
FormState = SaleFormState.Waiting; FormState = SaleFormState.Waiting;
}
} }
private void btnPrintKot_Click(object sender, EventArgs e) private void btnPrintKot_Click(object sender, EventArgs e)
{ {
var printed = _billController.SaveAndPrintKot(); var printed = _controller.SaveAndPrintKot();
ShowInfo(_billController._voucher, _billController._bill); if (!printed)
if (printed) return;
if (_controller._editVoucherID.HasValue)
this.Close();
else
{
ShowInfo(_controller._voucher, _controller._bill);
FormState = SaleFormState.Waiting; FormState = SaleFormState.Waiting;
}
} }
private void btnQuantity_Click(object sender, EventArgs e) private void btnQuantity_Click(object sender, EventArgs e)
{ {
_billController.SetQuantity(CurrentKey, CurrentProduct, 0, true); _controller.SetQuantity(CurrentKey, CurrentProduct, 0, true);
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
} }
private void btnDiscount_Click(object sender, EventArgs e) private void btnDiscount_Click(object sender, EventArgs e)
{ {
_billController.SetDiscount(); _controller.SetDiscount();
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
} }
#endregion #endregion
private void btnSplitBill_Click(object sender, EventArgs e) private void btnSplitBill_Click(object sender, EventArgs e)
{ {
_billController.SplitBill(); _controller.SplitBill();
ShowInfo(_billController._voucher, _billController._bill); ShowInfo(_controller._voucher, _controller._bill);
} }
} }
} }

View File

@ -99,7 +99,6 @@
<Compile Include="Authentication\ILogin.cs" /> <Compile Include="Authentication\ILogin.cs" />
<Compile Include="Controllers\BillController.cs" /> <Compile Include="Controllers\BillController.cs" />
<Compile Include="Controllers\BillDict.cs" /> <Compile Include="Controllers\BillDict.cs" />
<Compile Include="Controllers\ISaleForm.cs" />
<Compile Include="CurrencyCounter.cs"> <Compile Include="CurrencyCounter.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>