private void completeReturnButton_click(object sender, EventArgs e) { if (AcceptButton != null) { return; } var cashValue = 0; foreach (Product p in m_products) { cashValue += p.Quantity * p.Price.Value; } CashValue total = new CashValue(cashValue); if (m_register.Cash.GetCashValue().Value < total.Value) { MessageBox.Show("You need more money to pay for all this than you have", "Notice!"); return; } MoneySelectorUI moneySelector = new MoneySelectorUI(ref m_register, total, true, true); DialogResult tempDR = moneySelector.ShowDialog(); if (tempDR != DialogResult.OK) { return; } var payment = moneySelector.Cash; m_register.Cash.Debit(payment.GetCashValue()); foreach (Product p in m_register.Products) { var product = m_products.SingleOrDefault(pro => pro.SN.Equals(p.SN)); if (product == null) { continue; } p.Quantity += product.Quantity; } m_register.Save(); m_inventory.UpdateInventory(); m_report.UpdateReport(); AcceptButton = completeReturn; AcceptButton.DialogResult = DialogResult.OK; AcceptButton.PerformClick(); }
private void disconButton_Click(object sender, EventArgs e) { if (AcceptButton != null) { return; } try { m_product = listOfProducts.Items[listOfProducts.SelectedIndex] as Product; } catch { return; } DialogResult tempDR; tempDR = MessageBox.Show("Are you sure you want to discontinue " + m_product + ".", "Confirm", MessageBoxButtons.YesNo); if (tempDR == DialogResult.Yes) { if (m_product.Quantity > 0) { CashValue returnCash = new CashValue(m_product.Cost.Value * m_product.Quantity); MessageBox.Show("Please chose how you will get your money back.", "Notice"); MoneySelectorUI selector = new MoneySelectorUI(ref m_register, returnCash, true, false); tempDR = selector.ShowDialog(); if (tempDR != DialogResult.OK) { return; } m_register.Cash.Credit(selector.Cash); MessageBox.Show(selector.Cash.GetCashValue() + " was added to your register", "Notice"); } m_product.Discontinued = true; m_product.Quantity = 0; m_report.UpdateReport(); m_inventory.UpdateInventory(); } m_register.Save(); AcceptButton = disconButton; AcceptButton.DialogResult = DialogResult.OK; AcceptButton.PerformClick(); }
private void completeSale_Click(object sender, EventArgs e) { if (m_sale.Products.Count == 0) { return; } MoneySelectorUI moneySelector = new MoneySelectorUI(ref m_register, m_sale.GetTotal(), false, false); DialogResult tempDR = moneySelector.ShowDialog(); Money payment; if (tempDR == DialogResult.OK) { payment = moneySelector.Cash; } else { return; } Receipt receipt; try { receipt = m_sale.Complete(payment); } catch (Exception exc) { MessageBox.Show(exc.Message); return; } ChangeForm changeForm = new ChangeForm(receipt.Change); changeForm.ShowDialog(); m_report.Receipts.Add(receipt); m_register.Save(); m_button.Enabled = false; this.Clear(); }
private void completeShipmentButton_Click(object sender, EventArgs e) { if (AcceptButton != null) { return; } var cashValue = 0; foreach (Product p in m_products) { cashValue += p.Quantity * p.Cost.Value; } CashValue total = new CashValue(cashValue); if (m_register.Cash.GetCashValue().Value < total.Value) { MessageBox.Show("You need more money to pay for all this than you have", "Notice!"); return; } Money unlim = new Money(new TwentyDollarBills(100), new TenDollarBills(100), new FiveDollarBills(100), new OneDollarBills(100), new Quarters(100), new Dimes(100), new Nickels(100), new Pennies(100)); MoneySelectorUI moneySelector = new MoneySelectorUI(ref m_register, total, false, true); DialogResult tempDR = moneySelector.ShowDialog(); if (tempDR != DialogResult.OK) { return; } var payment = moneySelector.Cash; var change = unlim.Credit(total, payment); m_register.Cash.Debit(payment); if (change.GetCashValue().Value != 0) { ChangeForm cf = new ChangeForm(change); cf.ShowDialog(); } m_register.Cash.Credit(change); foreach (Product p in m_register.Products) { var product = m_products.SingleOrDefault(pro => pro.SN.Equals(p.SN)); if (product == null) { continue; } p.Quantity += product.Quantity; } m_register.Save(); m_inventory.UpdateInventory(); m_report.UpdateReport(); AcceptButton = completeShipmentButton; AcceptButton.DialogResult = DialogResult.OK; AcceptButton.PerformClick(); }