using System; using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.Linq; using System.Threading; using System.Windows.Forms; using Tanshu.Accounts.BI; using Tanshu.Accounts.Contracts; using Tanshu.Accounts.Helpers; using Tanshu.Common; namespace Tanshu.Accounts.PointOfSale { public partial class SalesForm : Form { private static readonly Logging.SqlLogger Log = new Logging.SqlLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #region Waiting private List selectedBills = new List(); private List pendingBills = new List(); private PendingType pendingList = PendingType.Today; #endregion private SaleFormState _formState = SaleFormState.Waiting; #region Billing private Dictionary bill = new Dictionary(); private CustomerBO customer = new CustomerBI().GetCustomer(new Guid("F016CBAD-206C-42C0-BB1D-6006CE57BAB5")); private Guid? _advanceID; #endregion private SaleVoucherBO _billInfo; object lockObject = new object(); Guid? _newBillID; readonly int _floor; public SalesForm() { InitializeComponent(); btnCustomer.Text = customer.Name; lblUser.Text = CurrentUser.user.Name; var floorString = System.Configuration.ConfigurationManager.AppSettings["floor"]; _floor = !string.IsNullOrEmpty(floorString) ? Convert.ToInt32(floorString.Trim()) : 0; } public SalesForm(Guid voucherID) : this() { _newBillID = voucherID; } private void SalesForm_KeyDown(object sender, KeyEventArgs e) { if (_formState == SaleFormState.Billing) { #region Billing KeyDown switch (e.KeyCode) { case Keys.F2: { if (dgvProducts.Rows.Count > 0) SetQuantity(CurrentProduct, 0, false, true); break; } case Keys.F3: { btnDiscount_Click(sender, new EventArgs()); break; } case Keys.F4: { if (!e.Alt) ShowCustomerList(false); break; } case Keys.F5: { btnWaiter_Click(sender, new EventArgs()); break; } case Keys.F7: { using (SelectProduct selectProduct = new SelectProduct(new ProductBI().GetFilteredProducts, true)) { selectProduct.ShowDialog(); if (selectProduct.SelectedItem != null) AddProductToGrid(selectProduct.SelectedItem.ProductID); } break; } case Keys.F8: { LoadBillFromTable(); break; } case Keys.F9: { if (dgvProducts.Rows.Count > 0) SetAmount(CurrentProduct, -1); break; } case Keys.F10: { if (dgvProducts.Rows.Count > 0) SetAmount(CurrentProduct, -1); break; } case Keys.F11: { btnPrintBill_Click(sender, e); break; } case Keys.F12: { btnPrintKot_Click(sender, e); break; } case Keys.Delete: { if (dgvProducts.Rows.Count > 0) ProductRemove(CurrentProduct); break; } case Keys.Add: { if (dgvProducts.Rows.Count > 0) SetQuantity(CurrentProduct, 1, false, false); break; } case Keys.Subtract: { if (dgvProducts.Rows.Count > 0) SetQuantity(CurrentProduct, -1, false, false); break; } case Keys.Up: { if ((bindingSource.Position >= 1) && (!dgvProducts.Focused)) bindingSource.Position -= 1; break; } case Keys.Down: { if ((bindingSource.Position < bindingSource.Count - 1) && (!dgvProducts.Focused)) bindingSource.Position += 1; break; } case Keys.Escape: { if (bill.Count != 0) if (MessageBox.Show("Cancel current bill?", "Cancel bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) return; ClearBill(); break; } } #endregion } else { #region Waiting KeyDown switch (e.KeyCode) { case Keys.F6: { ChangeFormState(SaleFormState.Billing); break; } case Keys.F8: { LoadBillFromTable(); break; } } #endregion } } #region Helper Functions private void ClearBill() { ShowCustomerList(true); this._billInfo = null; this.txtBillID.Text = ""; this.txtKotID.Text = ""; this.txtCreationDate.Text = ""; this.txtDate.Text = ""; this.txtLastEditDate.Text = ""; this.txtNarration.Text = ""; this.txtUserID.Text = ""; this.txtTableID.Text = ""; this.btnWaiter.Text = "Waiter - F5"; this.btnWaiter.Tag = null; txtGrossTax.Text = "0.00"; txtDiscount.Text = "0.00"; txtGrossAmount.Text = "0.00"; txtAmount.Text = "0.00"; bill.Clear(); _advanceID = null; bindingSource.DataSource = bill.Values; ChangeFormState(SaleFormState.Waiting); } private void AddProductToGrid(Guid productID) { BillHelperFunctions.AddProductToGrid(productID, bindingSource, bill); CalculateAmount(); } private void SetQuantity(SalesBillItemBO product, decimal quantity, bool absolute, bool prompt) { if (product == null) return; BillHelperFunctions.SetQuantity(product, quantity, absolute, prompt, bindingSource, bill); CalculateAmount(); } private void SetAmount(SalesBillItemBO product, decimal amount) { if (product == null) return; BillHelperFunctions.SetAmount(product, amount, bindingSource, bill); CalculateAmount(); } private void SetDiscount(SalesBillItemBO product, decimal discount) { if (product == null) return; BillHelperFunctions.SetDiscount(product.productID, discount, customer, bill); CalculateAmount(); return; } private bool ProductRemove(SalesBillItemBO product) { if (product == null) return false; if (product.Printed > 0) { if (!Thread.CurrentPrincipal.IsInRole("Sales/EditPrintedProduct")) { MessageBox.Show("You are not allowed to delete already printed products"); return false; } if (MessageBox.Show(string.Format("Already {0} items have been printed.\n\rAre you sure you want to delete this item?", product.Printed), "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return false; //If BillList(Location).Printed <> 0 Then ItemsDeleted.Add("Deleted " & BillList(Location).Printed & " " & BillList(Location).Name & " from Bill No " & mBillNo) } bill.Remove(new BillItemKey(product.productID, product.Printed == 0)); CalculateAmount(); return true; } private void InputBox_Validating(object sender, InputBoxValidatingArgs e) { } private void button_Click(object sender, EventArgs e) { var button = sender as Button; if (button == null) return; var tag = (Guid)button.Tag; AddProductToGrid(tag); } private void CalculateAmount() { txtGrossTax.Text = string.Format("{0:#0.00}", bill.Values.Sum(b => b.TaxAmount)); txtDiscount.Text = string.Format("{0:#0.00}", bill.Values.Sum(b => b.DiscountAmount)); txtGrossAmount.Text = string.Format("{0:#0.00}", bill.Values.Sum(b => b.GrossAmount)); txtAmount.Text = string.Format("{0:#0.00}", Math.Round(bill.Values.Sum(b => b.Value))); bindingSource.DataSource = bill.Values.ToList(); dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells); } private void btnPrintBill_Click(object sender, EventArgs e) { var val = Save(true); if (!val.HasValue) return; PrintBill(val.Value); ClearBill(); } private void btnPrintKot_Click(object sender, EventArgs e) { var val = Save(false); if (!val.HasValue) return; PrintKOT(val.Value); ClearBill(); } private void btnCancel_Click(object sender, EventArgs e) { if (bill.Count != 0) if (MessageBox.Show("Cancel current bill?", "Cancel bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) return; ClearBill(); } private SalesBillItemBO CurrentProduct { get { if (dgvProducts.Rows.Count == 0) return null; SalesBillItemBO product = bill.ElementAt(dgvProducts.CurrentRow.Index).Value; return product; } } private void btnQuantity_Click(object sender, EventArgs e) { if (dgvProducts.Rows.Count > 0) SetQuantity(CurrentProduct, 0, false, true); } private void btnDiscount_Click(object sender, EventArgs e) { if (dgvProducts.Rows.Count > 0) SetDiscount(CurrentProduct, -1); } #endregion private void SalesForm_Load(object sender, EventArgs e) { ChangeFormState(SaleFormState.Waiting); if (_newBillID.HasValue) { LoadBill(_newBillID.Value); ChangeFormState(SaleFormState.Billing); } ControlFactory.GenerateButtons(ref pnlBilling, new Rectangle(489, 94, 481, 385), 6, 6, 2, new ProductBI().GetUnFilteredProducts(), new ButtonClickDelegate(button_Click)); } private void ChangeFormState(SaleFormState state) { _formState = state; if (state == SaleFormState.Billing) { pnlWaiting.Visible = false; pnlBilling.Visible = true; } else { pnlWaiting.Visible = true; pnlBilling.Visible = false; ListUnpaidBills(); } } #region Save Bill private Guid? Save(bool finalBill) { decimal? amount = null; if (_billInfo != null && new SaleVoucherBI().IsBillPrinted(_billInfo.VoucherID)) { if (!Thread.CurrentPrincipal.IsInRole("Sales/EditBill")) { MessageBox.Show("You are not authorized to access"); return null; } amount = new SaleVoucherBI().Amount(_billInfo.VoucherID); } if (bill.Count == 0) return null; // if (_advanceID.HasValue) { var billAmount = Math.Round(bill.Values.Sum(b => b.Value)); var advanceAmount = new AdvanceBI().Get(_advanceID.Value).Amount; if (advanceAmount > billAmount) { if (MessageBox.Show("Advance adjusted amount more than bill amount, advance will not be adjusted.\n\rContinue will bill print?", "Advace adjustment error", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return null; else _advanceID = null; } } var saved = _billInfo == null ? AddNewSale(finalBill) : UpdateSale(finalBill); if (saved.HasValue && _advanceID.HasValue) new AdvanceBI().Adjust(_advanceID.Value, CurrentUser.user.UserID); if (amount != null) Log.Warn(string.Format("{4} modified bill no {0}/{1} from (Rs. {2:#,00}) to (Rs. {3:#,00})", _billInfo.BillID, _billInfo.TableID, amount.Value, new SaleVoucherBI().Amount(saved.Value), Thread.CurrentPrincipal.Identity.Name)); if (_newBillID.HasValue) this.Close(); return saved; } private void PrintBill(Guid voucherID) { if (!Thread.CurrentPrincipal.IsInRole("Sales/PrintBill")) MessageBox.Show("You are not authorized to access"); else { Print.Thermal.PrintBill(voucherID); Print.Thermal.PrintCustomerKot("KOT", voucherID, bill.Values.ToList()); } } private void PrintKOT(Guid voucherID) { if (!Thread.CurrentPrincipal.IsInRole("Sales/PrintKOT")) MessageBox.Show("You are not authorized to access"); else Print.Thermal.PrintWaiterKot("KOT", voucherID, bill.Values.ToList()); } #region Save / Update private Guid? AddNewSale(bool finalBill) { if (_billInfo != null) { MessageBox.Show("Error in AddNewSale, there is a previous sale in memory", "Error"); return null; } if (btnWaiter.Tag == null) btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID; #region SaleVoucher var user = CurrentUser.user; var saleVoucher = new SaleVoucherBO { CustomerID = customer.CustomerID, PaidStatus = PaidStatus.Pending, //Paid = finalBill, TableID = txtTableID.Text, WaiterID = (Guid)btnWaiter.Tag, Printed = finalBill, Date = DateTime.Now, Narration = txtNarration.Text, Ref = "", Type = 'S', UserID = user.UserID, Floor = _floor, AdvanceID = _advanceID }; #endregion #region Inventories List iList = new SaleVoucherBI().SaleInventory(bill.Values, null); #endregion new SaleVoucherBI().Insert(saleVoucher, iList); return saleVoucher.VoucherID; } private Guid? UpdateSale(bool finalBill) { if (btnWaiter.Tag == null) btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID; var user = CurrentUser.user; #region Voucher and SaleVoucher var saleVoucher = new SaleVoucherBO { VoucherID = _billInfo.VoucherID, timestamp = _billInfo.timestamp, UserID = _billInfo.UserID, Date = _billInfo.Date, CreationDate = DateTime.Now, LastEditDate = DateTime.Now, Narration = _billInfo.Narration, Ref = "", Type = 'S', Alarm = _billInfo.Alarm, BillID = _billInfo.BillID, CustomerID = customer.CustomerID, KotID = _billInfo.KotID, PaidStatus = _billInfo.PaidStatus, Printed = _billInfo.Printed || finalBill, TableID = txtTableID.Text, VoidReason = _billInfo.VoidReason, WaiterID = (Guid)btnWaiter.Tag, SaleTimestamp = _billInfo.SaleTimestamp, Floor = _floor, AdvanceID = _advanceID }; if ((!_billInfo.Printed) && finalBill) saleVoucher.Date = null; #endregion #region Inventory List iList = new SaleVoucherBI().SaleInventory(bill.Values, _billInfo.VoucherID); #endregion new SaleVoucherBI().Update(saleVoucher, iList); return saleVoucher.VoucherID; } #endregion #endregion private void LoadBillFromTable() { InputBoxResult result = InputBox.Show("Enter Table Number", "Table", "0", InputBox_Validating); if (result.OK) { txtTableID.Text = result.Text.Trim(); if ((txtTableID.Text != "C") && (txtTableID.Text != "") && (!txtTableID.Text.Contains("."))) { Guid? tID = new SaleVoucherBI().GetPendingVoucherID(txtTableID.Text, _floor); if (tID.HasValue) { LoadBill(tID.Value); ChangeFormState(SaleFormState.Billing); } } else ClearBill(); } } private void LoadBill(Guid voucherID) { ClearBill(); var iList = new List(); new SaleVoucherBI().GetSaleVoucher(voucherID, ref _billInfo, ref iList); this.txtBillID.Text = _billInfo.BillID; this.txtKotID.Text = _billInfo.KotID; this.txtCreationDate.Text = _billInfo.CreationDate.ToString("HH:mm dd-MMM-yyyy"); this.txtDate.Text = _billInfo.Date.Value.ToString("HH:mm dd-MMM-yyyy"); this.txtLastEditDate.Text = _billInfo.LastEditDate.ToString("HH:mm dd-MMM-yyyy"); this.txtNarration.Text = _billInfo.Narration; this.txtUserID.Text = new UserBI().GetUser(_billInfo.UserID).Name; this.customer = new CustomerBI().GetCustomer(_billInfo.CustomerID); this.btnCustomer.Text = this.customer.Name; this.txtTableID.Text = _billInfo.TableID; this.btnWaiter.Tag = _billInfo.WaiterID; this._advanceID = _billInfo.AdvanceID; this.btnWaiter.Text = string.Format("{0} - F5", new WaiterBI().GetWaiter(_billInfo.WaiterID).Name); foreach (var inventory in iList) { var key = new BillItemKey(inventory.ProductID, inventory.Quantity == 0); bill.Add(key, new SalesBillItemBO { productID = inventory.ProductID, Discount = inventory.Discount, Name = inventory.ProductName, Price = inventory.Rate, Printed = inventory.Quantity, Quantity = inventory.Quantity, Tax = inventory.Tax, }); } CalculateAmount(); } #region Waiting private void btnStartBill_Click(object sender, EventArgs e) { ChangeFormState(SaleFormState.Billing); } private void btnSelectBill_Click(object sender, EventArgs e) { if (bsPending.Current != null) { LoadBill(((PendingBillsBO)bsPending.Current).voucherID); ChangeFormState(SaleFormState.Billing); } } private void tmrPending_Tick(object sender, EventArgs e) { if (chkRefresh.Checked) ListUnpaidBills(); } private void ListUnpaidBills() { lock (lockObject) { pendingBills = new SaleVoucherBI().GetPendingBills(pendingList, _floor); bsPending.DataSource = pendingBills; var alarmBills = new SaleVoucherBI().GetPendingBills(PendingType.Alarms, _floor).OrderBy(b => b.AlarmTime).ToList(); if (alarmBills.Count > 0) { var al = alarmBills.First(); var seconds = al.AlarmTime.Value.Subtract(DateTime.Now).TotalSeconds; lblUser.Text = seconds <= 0 ? string.Format("Alarm {0:hh:MM}", al.AlarmTime) : CurrentUser.user.Name; } else { lblUser.Text = CurrentUser.user.Name; } } } private void dgvPending_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { try { DataGridView dgv = sender as DataGridView; PendingBillsBO data = dgv.Rows[e.RowIndex].DataBoundItem as PendingBillsBO; if (data.Printed) e.CellStyle.BackColor = Color.LightSlateGray; } catch { // Catch and swallow exception when DataGridView attemps to get values for removed rows. } } private void tcPending_SelectedIndexChanged(object sender, EventArgs e) { switch (tcPending.SelectedTab.Text) { case "Today": pendingList = PendingType.Today; break; case "Week": pendingList = PendingType.Week; break; case "All": pendingList = PendingType.All; break; case "Alarms": pendingList = PendingType.Alarms; break; } ListUnpaidBills(); } private void dgvPending_CellValuePushed(object sender, DataGridViewCellValueEventArgs e) { if (e.ColumnIndex != 0) return; if ((bool)e.Value) selectedBills.Add(pendingBills[e.RowIndex].voucherID); else selectedBills.Remove(pendingBills[e.RowIndex].voucherID); } private void dgvPending_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) { if (e.ColumnIndex != 0) return; if (e.RowIndex > pendingBills.Count - 1) return; e.Value = selectedBills.Contains(pendingBills.ElementAt(e.RowIndex).voucherID); } #endregion #region Billing private void btnCustomer_Click(object sender, EventArgs e) { ShowCustomerList(false); } private void ShowCustomerList(bool reset) { if ((customer.CustomerID == new Guid("F016CBAD-206C-42C0-BB1D-6006CE57BAB5")) && (!reset)) { using (SelectCustomer selectCustomer = new SelectCustomer(new CustomerBI().GetFilteredCustomers, true)) { selectCustomer.customerEvent += new CustomerEventHandler(selectCustomer_customerEvent); selectCustomer.ShowDialog(); if (selectCustomer.SelectedItem != null) { customer = selectCustomer.SelectedItem; btnCustomer.Text = customer.Name; } else { customer = new CustomerBI().GetCustomer(new Guid("F016CBAD-206C-42C0-BB1D-6006CE57BAB5")); } } } else if (!reset) { using (CustomersForm form = new CustomersForm(customer.CustomerID, customer.Phone)) { form.ShowDialog(); } } else { customer = new CustomerBI().GetCustomer(new Guid("F016CBAD-206C-42C0-BB1D-6006CE57BAB5")); btnCustomer.Text = customer.Name; } } CustomerBO selectCustomer_customerEvent(object sender, CustomerEventArgs e) { using (CustomersForm form = new CustomersForm(e.CustomerID, e.Phone)) { form.ShowDialog(); return form.Customer; } } #endregion private void dgvPending_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if ((dgvProducts.Rows.Count > 0) && (dgvPending.CurrentRow != null)) { LoadBill(((PendingBillsBO)bsPending.Current).voucherID); ChangeFormState(SaleFormState.Billing); } } private void btnRefresh_Click(object sender, EventArgs e) { ListUnpaidBills(); } private void btnVoid_Click(object sender, EventArgs e) { if (_billInfo != null) { if ((_billInfo.Printed) && (!Thread.CurrentPrincipal.IsInRole("Sales/VoidPrintedBill"))) MessageBox.Show("Cannot void a paid bill"); else if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { SelectVoidReason voidReason = new SelectVoidReason(GetVoidReason, true); voidReason.ShowDialog(); if (voidReason.SelectedItem != null) { new SaleVoucherBI().VoidBill(_billInfo.VoucherID, voidReason.SelectedItem.Description); ClearBill(); } else { MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } } private List GetVoidReason(Dictionary filter) { List list = new List(); list.Add(new StringType("Discount")); list.Add(new StringType("Printing Fault")); list.Add(new StringType("Item Changed")); list.Add(new StringType("Quantity Reduced")); list.Add(new StringType("Costing Bill for Party")); list.Add(new StringType("Cashier Mistake")); list.Add(new StringType("Management Freesale")); list.Add(new StringType("Other")); return list.Where(i => i.Description.ToLower().Contains(filter["Name"].ToLower().Trim())).ToList(); } private void btnRate_Click(object sender, EventArgs e) { if (!Thread.CurrentPrincipal.IsInRole("Sales/ChangeRate")) MessageBox.Show("You are not authorized to access"); else { if (dgvProducts.Rows.Count > 0) { SalesBillItemBO product = bill.ElementAt(dgvProducts.CurrentRow.Index).Value; decimal rate = 0; InputBoxResult result = InputBox.Show("Enter Rate", "Rate", product.Price.ToString(), InputBox_Validating); if (result.OK) rate = Convert.ToDecimal(result.Text); if (rate != 0) { BillHelperFunctions.SetRate(product.productID, rate, bill); CalculateAmount(); } } } } private void btnClear_Click(object sender, EventArgs e) { ClearBill(); } private void btnPaidCash_Click(object sender, EventArgs e) { var user = CurrentUser.user; new SaleVoucherBI().DeclareBillsPaid(user.UserID, selectedBills, PaidStatus.Cash); ListUnpaidBills(); } private void btnPaidCC_Click(object sender, EventArgs e) { var user = CurrentUser.user; new SaleVoucherBI().DeclareBillsPaid(user.UserID, selectedBills, PaidStatus.CreditCard); ListUnpaidBills(); } private void btnAlarm_Click(object sender, EventArgs e) { if (bsPending.Current != null) { PendingBillsBO billAlarm = (PendingBillsBO)bsPending.Current; InputBoxResult result = InputBox.Show( string.Format("Alarm for Bill {0} Rs. {1}", billAlarm.BillNo, billAlarm.Amount), "Alarm", string.Format("{0:dd-MMM-yyy HH:mm}", billAlarm.LastEdited), InputBox_Validating); if (result.OK) { DateTime alarmTime; if (result.Text == string.Empty) { new SaleVoucherBI().SetAlarm(billAlarm.voucherID, null); MessageBox.Show("Alarm Cleared", "Alarm Cleared", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (DateTime.TryParseExact(result.Text, "dd-MMM-yyyy HH:mm", new CultureInfo("en-US"), DateTimeStyles.None, out alarmTime)) { new SaleVoucherBI().SetAlarm(billAlarm.voucherID, alarmTime); MessageBox.Show("Alarm set", "Alarm Set", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Alarm NOT set, please try again", "Alarm NOT Set", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } private void btnBillList_Click(object sender, EventArgs e) { if (!Thread.CurrentPrincipal.IsInRole("Security/CreateUser")) return; var result = InputBox.Show("Bill No", "Bill No", "", InputBox_Validating); if (result.OK) { var saleVoucher = new SaleVoucherBO(); var list = new List(); new SaleVoucherBI().GetSaleVoucher(result.Text,ref saleVoucher, ref list); if (saleVoucher == null) return; LoadBill(saleVoucher.VoucherID); ChangeFormState(SaleFormState.Billing); } //#region Filters //decimal? minValue = 0, maxValue = 0; //decimal valTemp; //DateTime? fromDate = DateTime.Now, toDate = DateTime.Now; // used in filters //DateTime dateTemp; //bool? showVoided; //InputBoxResult result = InputBox.Show("Start Date", "Start Date", string.Format("{0:dd-MMM-yyy}", fromDate), InputBox_Validating); //if ((result.OK) && (DateTime.TryParseExact(result.Text, "dd-MMM-yyyy", new CultureInfo("en-US"), DateTimeStyles.None, out dateTemp))) //{ // fromDate = dateTemp; //} //result = InputBox.Show("Finish Date", "Finish Date", string.Format("{0:dd-MMM-yyy}", toDate), InputBox_Validating); //if ((result.OK) && (DateTime.TryParseExact(result.Text, "dd-MMM-yyyy", new CultureInfo("en-US"), DateTimeStyles.None, out dateTemp))) //{ // toDate = dateTemp; //} //result = InputBox.Show("Minimum Value", "Minimum Value", "0", InputBox_Validating); //if ((result.OK) && (decimal.TryParse(result.Text, out valTemp))) //{ // minValue = valTemp; //} //result = InputBox.Show("Maximum Value", "Maximum Value", "0", InputBox_Validating); //if ((result.OK) && (decimal.TryParse(result.Text, out valTemp))) //{ // maxValue = valTemp; //} //DialogResult dResult = MessageBox.Show("Show Un-Voided Bills only", "Un-Voided", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); //if (dResult == DialogResult.Yes) // showVoided = false; //else if (dResult == DialogResult.No) // showVoided = true; //else // showVoided = null; //#endregion //List billList = ManagementBI.GetBillList(fromDate, toDate, minValue, maxValue, showVoided); //using (SelectBill selectBill = new SelectBill(billList, true)) //{ // selectBill.ShowDialog(); // if (selectBill.SelectedItem != null) // { // LoadBill(selectBill.SelectedItem.voucherID); // ChangeFormState(SaleFormState.Billing); // } //} } private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { DataGridView dgv = sender as DataGridView; SalesBillItemBO data = dgv.Rows[e.RowIndex].DataBoundItem as SalesBillItemBO; if (data.Printed > 0) { e.CellStyle.SelectionBackColor = Color.HotPink; e.CellStyle.BackColor = Color.LightPink; } else { e.CellStyle.SelectionBackColor = Color.Green; e.CellStyle.BackColor = Color.LightGreen; } } private void btnWaiter_Click(object sender, EventArgs e) { using (SelectWaiter selectWaiter = new SelectWaiter(new WaiterBI().GetFilteredWaiters, true)) { selectWaiter.waiterEvent += new WaiterEventHandler(selectWaiter_waiterEvent); selectWaiter.ShowDialog(); if (selectWaiter.SelectedItem != null) { btnWaiter.Text = string.Format("{0} - F5", selectWaiter.SelectedItem.Name); btnWaiter.Tag = selectWaiter.SelectedItem.WaiterID; } else { btnWaiter.Text = "Select Waiter - F5"; btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID; } } } WaiterBO selectWaiter_waiterEvent(object sender, WaiterEventArgs e) { WaiterBO waiter = e.Waiter; if (!Thread.CurrentPrincipal.IsInRole("Waiter/Master")) return waiter; switch (e.Action) { case 1: // Add new WaiterBI().Insert(waiter); e.Handled = true; return waiter; case 2: // Edit new WaiterBI().Update(waiter); e.Handled = true; return waiter; case 3: // Delete e.Handled = new WaiterBI().Delete(waiter.WaiterID); return new WaiterBI().GetWaiter(1); default: throw new ArgumentException(); } } private void btnResetCustomer_Click(object sender, EventArgs e) { ShowCustomerList(true); } private void btnPaidStaff_Click(object sender, EventArgs e) { var user = CurrentUser.user; new SaleVoucherBI().DeclareBillsPaid(user.UserID, selectedBills, PaidStatus.Staff); ListUnpaidBills(); } private void btnPaidCredit_Click(object sender, EventArgs e) { var user = CurrentUser.user; new SaleVoucherBI().DeclareBillsPaid(user.UserID, selectedBills, PaidStatus.Credit); ListUnpaidBills(); } private void btnAdvance_Click(object sender, EventArgs e) { if (_billInfo != null && _billInfo.AdvanceID.HasValue) return; using (var frm = new AdjustAdvanceForm(true)) { frm.ShowDialog(); _advanceID = frm.AdvanceID; } } } }