private void UpdateReturn() { var totalItems = 0; var totalCost = 0; m_products = new List <Product>(); foreach (DataGridViewRow row in listOfProducts.Rows) { var quantity = Int32.Parse(row.Cells[3].Value.ToString()); var product = m_register.Products.SingleOrDefault (p => p.SN.IntValue == Int32.Parse(row.Cells[0].Value.ToString())); if (product != null) { product = new Product(product.ItemName, product.SN.IntValue, quantity, product.Cost.Value, product.Price.Value, product.Discontinued); m_products.Add(product); } totalItems += quantity; totalCost += quantity * (int)((CashValue)row.Cells[2].Value).Value; } var totalCashValueCost = new CashValue(totalCost); costLbl.Text = totalCashValueCost.ToString(); countLbl.Text = totalItems.ToString(); }
/// <summary> /// Handles the Click event of the updateButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void updateButton_Click(object sender, EventArgs e) { if (AcceptButton != null) { return; } CashValue cost; CashValue price; if (!CashValue.TryParse((double)costNum.Value, out cost)) { MessageBox.Show("Failed to parse Cash Value for cost!", "Notice!"); return; } if (!CashValue.TryParse((double)priceNum.Value, out price)) { MessageBox.Show("Failed to parse Price Value for cost!", "Notice!"); return; } m_product.Cost = cost; m_product.Price = price; m_product.ItemName = itemNameBox.Text; m_product.Quantity = (int)quantityNum.Value; m_inventory.UpdateInventory(); m_register.Save(); AcceptButton = updateButton; AcceptButton.DialogResult = DialogResult.OK; AcceptButton.PerformClick(); }
/// <summary> /// Initializes a new instance of the <see cref="MoneySelectorUI"/> class. /// </summary> /// <param name="goal">The goal.</param> public MoneySelectorUI(ref Register register, CashValue goal, bool exact, bool fromRegister) { InitializeComponent(); if (fromRegister) { foreach (ICurrency cur in register.Cash.GetListOfCash()) { if (cur is TwentyDollarBills) { m_numTwenty.Maximum = cur.GetCount(); } else if (cur is TenDollarBills) { m_numTen.Maximum = cur.GetCount(); } else if (cur is FiveDollarBills) { m_numFive.Maximum = cur.GetCount(); } else if (cur is OneDollarBills) { m_numOne.Maximum = cur.GetCount(); } else if (cur is Quarters) { m_numQuarters.Maximum = cur.GetCount(); } else if (cur is Dimes) { m_numDimes.Maximum = cur.GetCount(); } else if (cur is Nickels) { m_numNickels.Maximum = cur.GetCount(); } else if (cur is Pennies) { m_numPennies.Maximum = cur.GetCount(); } else { throw new ArgumentException("lol, good job Numnuts"); } } } this.goalLbl.Text = "Goal: " + goal; this.m_goal = goal; this.m_cash = new Money(); this.m_exact = exact; this.AcceptButton = this.acceptButton; this.AcceptButton.DialogResult = DialogResult.OK; this.acceptButton.Enabled = false; if (!exact) { this.exactLbl.Visible = false; } }
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 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(); }
public CashValueWithCount(CashValue cashValue, int count) { CashValue = cashValue; Value = CashValue.GetValue(); Count = count; }