private void btnPurchase_Click(object sender, EventArgs e)
        {
            using (StoreDataDataContext context = new StoreDataDataContext())
            {
                if (c.CreditLimit >= c.Balance + Decimal.Parse(txtTotPrice.Text))
                {
                    //create Invoice (1 product per purchase)
                    Invoice i = new Invoice();
                    i.CustID    = c.CustID;
                    i.ProdID    = p.ProdID;
                    i.Qty       = (int)numQty.Value;
                    i.orderDate = DateTime.Today;
                    i.TotalBal  = Decimal.Parse(txtTotPrice.Text);

                    context.Invoices.InsertOnSubmit(i);

                    var cstmr = context.Customers.Where(c => c.CustID == this.c.CustID).First();

                    Customer customer = (Customer)cstmr;
                    //bill customer
                    customer.Balance += i.TotalBal;


                    var prdct = context.Products.Where(p => p.ProdID == this.p.ProdID).First();

                    Product product = (Product)prdct;

                    // reduce number in stock
                    product.totAvail -= (int)numQty.Value;


                    context.SubmitChanges();
                    this.Hide();
                    MessageBox.Show("Order successfully Placed.", "Purchase Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.Close();
                }
                else
                {
                    MessageBox.Show("Insufficient credit balance to allow for this purchase.", "Purchase Canceled", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#2
0
        private void btnPay_Click(object sender, EventArgs e)
        {
            if (txtAmt.Text == "")
            {
                MessageBox.Show("Dollar Amount Must Be Entered.", "No Amount Specified", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                decimal amt = decimal.Parse(txtAmt.Text);
                using (StoreDataDataContext context = new StoreDataDataContext())
                {
                    Customer cstmr = context.Customers.Where(c => c.CustID == customerID).First();

                    cstmr.Balance -= amt;


                    context.SubmitChanges();

                    setFields(cstmr);
                }
            }
        }