From 69cb7d8bce08fc678e3a9ec1487b59dbee0326a9 Mon Sep 17 00:00:00 2001 From: tanshu Date: Thu, 31 Mar 2016 14:13:26 +0530 Subject: [PATCH] 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. --- Tanshu.Accounts.Helpers/SelectorEvent.cs | 38 ----- .../Tanshu.Accounts.Helpers.csproj | 1 - .../Controllers/BillController.cs | 27 +--- .../Controllers/ISaleForm.cs | 17 --- .../Sales/SalesForm.Designer.cs | 2 +- .../Sales/SalesForm.cs | 140 +++++++++--------- .../Tanshu.Accounts.PointOfSale.csproj | 1 - 7 files changed, 75 insertions(+), 151 deletions(-) delete mode 100644 Tanshu.Accounts.Helpers/SelectorEvent.cs delete mode 100644 Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs diff --git a/Tanshu.Accounts.Helpers/SelectorEvent.cs b/Tanshu.Accounts.Helpers/SelectorEvent.cs deleted file mode 100644 index 02b638f..0000000 --- a/Tanshu.Accounts.Helpers/SelectorEvent.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; - -namespace Tanshu.Accounts.Helpers -{ - public enum SelectorAction - { - Insert = 1, - Update = 2, - Delete = 3 - } - public class SelectorEventArgs : 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; - } - } -} diff --git a/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj b/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj index 7fb1e4e..371a643 100644 --- a/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj +++ b/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj @@ -66,7 +66,6 @@ Code - Form diff --git a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs index be11b61..eb0bd65 100644 --- a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs +++ b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs @@ -15,8 +15,7 @@ namespace Tanshu.Accounts.PointOfSale { public readonly BillDict _bill; public Voucher _voucher; - private Guid? _editVoucherID; - private ISaleForm _saleForm; + public 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)); } - public void InitGui(ISaleForm saleForm) - { - this._saleForm = saleForm; - this._saleForm.SetUserName(Session.User.Name); - } public void AddProduct(Product product) { var newKey = new BillItemKey(product.ProductID, Guid.Empty); @@ -148,7 +142,6 @@ namespace Tanshu.Accounts.PointOfSale using (var bi = new VoucherBI()) { _voucher = bi.Get(x => x.VoucherID == voucherID); - _bill.Clear(); _bill.Load(_voucher); var newKotKey = new BillItemKey(Guid.Empty); var newKotItem = new BillItemValue(); @@ -184,7 +177,7 @@ namespace Tanshu.Accounts.PointOfSale ClearBill(); return true; } - public void ClearBill() + private void ClearBill() { using (var bi = new CustomerBI()) _voucher = new Voucher(Session.User, bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER)); @@ -195,18 +188,15 @@ namespace Tanshu.Accounts.PointOfSale } public SaleFormState FormLoad() { + ClearBill(); if (_editVoucherID.HasValue) { FoodTable ft = new FoodTableBI().Get(x => x.VoucherID == _editVoucherID.Value); if (ft == null) - { - LoadBill(_editVoucherID.Value); - } - else { _editVoucherID = null; - LoadBill(ft.Name); } + LoadBill(_editVoucherID.Value); return SaleFormState.Billing; } return SaleFormState.Waiting; @@ -387,12 +377,7 @@ namespace Tanshu.Accounts.PointOfSale Thermal.PrintKot(_voucher.VoucherID, saved.Value); //Cleanup - if (_editVoucherID.HasValue) - _saleForm.CloseWindow(); - else - { - ClearBill(); - } + ClearBill(); return true; } public bool SaveAndPrintBill() @@ -440,8 +425,6 @@ namespace Tanshu.Accounts.PointOfSale UpdateVoucher(true, !_editVoucherID.HasValue); } Thermal.PrintBill(_voucher.VoucherID); - if (_editVoucherID.HasValue) - _saleForm.CloseWindow(); ClearBill(); return true; } diff --git a/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs b/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs deleted file mode 100644 index fa09bbb..0000000 --- a/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs +++ /dev/null @@ -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); - } -} diff --git a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.Designer.cs index 69c61a6..637d2fb 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.Designer.cs @@ -672,7 +672,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales private System.Windows.Forms.DataGridViewTextBoxColumn quantityColumn; private System.Windows.Forms.Button btnMore; private System.Windows.Forms.Button btnMoveKot; - private readonly BillController _billController; + private readonly BillController _controller; private System.Windows.Forms.Button btnSplitBill; private System.Windows.Forms.Label label10; private System.Windows.Forms.TextBox txtPax; diff --git a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs index df20d88..333431c 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs @@ -11,20 +11,14 @@ using Tanshu.Accounts.Repository; namespace Tanshu.Accounts.PointOfSale.Sales { - public partial class SalesForm : Form, ISaleForm + public partial class SalesForm : Form { private ProductGroup _currentProductGroup; public SalesForm(BillController billController) { InitializeComponent(); - _billController = billController; - billController.InitGui(this); - } - - #region ISaleForm Members - public void SetUserName(string name) - { - Text = name; + _controller = billController; + this.Text = Session.User.Name; } private void ShowInfo(Voucher voucher, BillDict bill) @@ -65,7 +59,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales { if (bindingSource.Position == -1) 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; } } @@ -76,7 +70,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales { if (bindingSource.Position == -1) return null; - var item = _billController._bill.ElementAt(bindingSource.Position); + var item = _controller._bill.ElementAt(bindingSource.Position); return item.Key; } } @@ -87,18 +81,11 @@ namespace Tanshu.Accounts.PointOfSale.Sales { if (bindingSource.Position == -1) 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; } } - public void CloseWindow() - { - Close(); - } - - #endregion - private void SalesForm_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) @@ -117,15 +104,15 @@ namespace Tanshu.Accounts.PointOfSale.Sales { if (!e.Alt) { - _billController.ShowCustomers(); - ShowInfo(_billController._voucher, _billController._bill); + _controller.ShowCustomers(); + ShowInfo(_controller._voucher, _controller._bill); } break; } case Keys.F8: { - _billController.LoadBill(null); - ShowInfo(_billController._voucher, _billController._bill); + _controller.LoadBill(null); + ShowInfo(_controller._voucher, _controller._bill); FormState = SaleFormState.Billing; break; } @@ -141,20 +128,20 @@ namespace Tanshu.Accounts.PointOfSale.Sales } case Keys.Delete: { - _billController.SetQuantity(CurrentKey, CurrentProduct, -1, false); - ShowInfo(_billController._voucher, _billController._bill); + _controller.SetQuantity(CurrentKey, CurrentProduct, -1, false); + ShowInfo(_controller._voucher, _controller._bill); break; } case Keys.Add: { - _billController.SetQuantity(CurrentKey, CurrentProduct, 1, false); - ShowInfo(_billController._voucher, _billController._bill); + _controller.SetQuantity(CurrentKey, CurrentProduct, 1, false); + ShowInfo(_controller._voucher, _controller._bill); break; } case Keys.Subtract: { - _billController.SetQuantity(CurrentKey, CurrentProduct, -1, false); - ShowInfo(_billController._voucher, _billController._bill); + _controller.SetQuantity(CurrentKey, CurrentProduct, -1, false); + ShowInfo(_controller._voucher, _controller._bill); break; } case Keys.Up: @@ -171,8 +158,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales } case Keys.Escape: { - var canceled = _billController.CancelBillChanges(); - ShowInfo(_billController._voucher, _billController._bill); + var canceled = _controller.CancelBillChanges(); + ShowInfo(_controller._voucher, _controller._bill); if (canceled) FormState = SaleFormState.Waiting; break; @@ -188,22 +175,21 @@ namespace Tanshu.Accounts.PointOfSale.Sales txtServiceCharge.Visible = showSC; lblServiceCharge.Visible = showSC; } - _billController.ClearBill(); - var state = _billController.FormLoad(); - ShowInfo(_billController._voucher, _billController._bill); + var state = _controller.FormLoad(); + ShowInfo(_controller._voucher, _controller._bill); FormState = state; } private void btnCustomer_Click(object sender, EventArgs e) { - _billController.ShowCustomers(); - ShowInfo(_billController._voucher, _billController._bill); + _controller.ShowCustomers(); + ShowInfo(_controller._voucher, _controller._bill); } private void btnVoid_Click(object sender, EventArgs e) { - var voided = _billController.VoidBill(); - ShowInfo(_billController._voucher, _billController._bill); + var voided = _controller.VoidBill(); + ShowInfo(_controller._voucher, _controller._bill); if (voided) FormState = SaleFormState.Waiting; } @@ -213,14 +199,14 @@ namespace Tanshu.Accounts.PointOfSale.Sales var item = CurrentProduct; if (item == null) return; - _billController.SetPrice(CurrentProduct); - ShowInfo(_billController._voucher, _billController._bill); + _controller.SetPrice(CurrentProduct); + ShowInfo(_controller._voucher, _controller._bill); } private void btnClear_Click(object sender, EventArgs e) { - var canceled = _billController.CancelBillChanges(); - ShowInfo(_billController._voucher, _billController._bill); + var canceled = _controller.CancelBillChanges(); + ShowInfo(_controller._voucher, _controller._bill); if (canceled) FormState = SaleFormState.Waiting; } @@ -258,8 +244,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales private void btnSettle_Click(object sender, EventArgs e) { - var settled = _billController.SettleBill(); - ShowInfo(_billController._voucher, _billController._bill); + var settled = _controller.SettleBill(); + ShowInfo(_controller._voucher, _controller._bill); if (settled) FormState = SaleFormState.Waiting; } @@ -270,20 +256,20 @@ namespace Tanshu.Accounts.PointOfSale.Sales if (item == null || CurrentKey.KotID != Guid.Empty) return; // No Product or Old Product - _billController.ShowModifiers(item); - ShowInfo(_billController._voucher, _billController._bill); + _controller.ShowModifiers(item); + ShowInfo(_controller._voucher, _controller._bill); } private void btnDelete_Click(object sender, EventArgs e) { - _billController.SetQuantity(CurrentKey, CurrentProduct, -1, false); - ShowInfo(_billController._voucher, _billController._bill); + _controller.SetQuantity(CurrentKey, CurrentProduct, -1, false); + ShowInfo(_controller._voucher, _controller._bill); } private void btnMoveTable_Click(object sender, EventArgs e) { - _billController.MoveTable(); - ShowInfo(_billController._voucher, _billController._bill); + _controller.MoveTable(); + ShowInfo(_controller._voucher, _controller._bill); } 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) { - _billController.MoveKot(CurrentKot); - ShowInfo(_billController._voucher, _billController._bill); + _controller.MoveKot(CurrentKot); + ShowInfo(_controller._voucher, _controller._bill); } #region Helper Functions @@ -367,16 +353,16 @@ namespace Tanshu.Accounts.PointOfSale.Sales var item = button.Tag as Product; if (item.IsNotAvailable) return; - _billController.AddProduct(item); - bindingSource.DataSource = _billController._bill.ToList(); - bindingSource.CurrencyManager.Position = _billController._bill.IndexOfKey(new BillItemKey(item.ProductID, Guid.Empty)); + _controller.AddProduct(item); + bindingSource.DataSource = _controller._bill.ToList(); + bindingSource.CurrencyManager.Position = _controller._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); + _controller.ShowModifiers(CurrentProduct); + ShowInfo(_controller._voucher, _controller._bill); } private void productPage_Click(object sender, EventArgs e) @@ -398,8 +384,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales return; var item = button.Tag as FoodTable; var tableName = item.Name; - _billController.LoadBill(tableName); - ShowInfo(_billController._voucher, _billController._bill); + _controller.LoadBill(tableName); + ShowInfo(_controller._voucher, _controller._bill); FormState = SaleFormState.Billing; } @@ -416,38 +402,50 @@ namespace Tanshu.Accounts.PointOfSale.Sales } private void btnPrintBill_Click(object sender, EventArgs e) { - var printed = _billController.SaveAndPrintBill(); - ShowInfo(_billController._voucher, _billController._bill); - if (printed) + var printed = _controller.SaveAndPrintBill(); + if (!printed) + return; + if (_controller._editVoucherID.HasValue) + this.Close(); + else + { + ShowInfo(_controller._voucher, _controller._bill); FormState = SaleFormState.Waiting; + } } private void btnPrintKot_Click(object sender, EventArgs e) { - var printed = _billController.SaveAndPrintKot(); - ShowInfo(_billController._voucher, _billController._bill); - if (printed) + var printed = _controller.SaveAndPrintKot(); + if (!printed) + return; + if (_controller._editVoucherID.HasValue) + this.Close(); + else + { + ShowInfo(_controller._voucher, _controller._bill); FormState = SaleFormState.Waiting; + } } private void btnQuantity_Click(object sender, EventArgs e) { - _billController.SetQuantity(CurrentKey, CurrentProduct, 0, true); - ShowInfo(_billController._voucher, _billController._bill); + _controller.SetQuantity(CurrentKey, CurrentProduct, 0, true); + ShowInfo(_controller._voucher, _controller._bill); } private void btnDiscount_Click(object sender, EventArgs e) { - _billController.SetDiscount(); - ShowInfo(_billController._voucher, _billController._bill); + _controller.SetDiscount(); + ShowInfo(_controller._voucher, _controller._bill); } #endregion private void btnSplitBill_Click(object sender, EventArgs e) { - _billController.SplitBill(); - ShowInfo(_billController._voucher, _billController._bill); + _controller.SplitBill(); + ShowInfo(_controller._voucher, _controller._bill); } } } \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj index 1bf9403..fd02057 100644 --- a/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj +++ b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj @@ -99,7 +99,6 @@ - Form