Exemple #1
0
        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();
        }