private void btn_go_Click(object sender, EventArgs e) { using (DataClasses1DataContext db = new DataClasses1DataContext()) { AccountPurchase1 accnt = new AccountPurchase1(); string items = Convert.ToString(comb_items.SelectedItem); DateTime date = date_picker.Value; int quant = Convert.ToInt16(num_txt.Text); int custid = Convert.ToInt16(txt_cust.ToString()); Customer1 customer = db.Customer1s.Single(u => u.customerID == custid); accnt.customerID = custid; accnt.purchaseDate = date; accnt.quantity = quant; accnt.prodDescription = items; var price = from p in db.Stores where p.prodDescription == items select p.productPrice; decimal totalPrice = Convert.ToDecimal(price) * quant; customer.customerBalance = customer.customerBalance + totalPrice; db.AccountPurchase1s.InsertOnSubmit(accnt); db.SubmitChanges(); MessageBox.Show("Action Completed"); this.Hide(); customerPage pg = new customerPage(); pg.ShowDialog(); } }
private void btn_submit_Click(object sender, EventArgs e) { using (DataClasses1DataContext db = new DataClasses1DataContext()) { var totalBal = from b in db.Customer1s where b.customerID == custID select b.customerBalance; var credit = from c in db.Customer1s where c.customerID == custID select c.credit; Customer1 uCust = db.Customer1s.Single(u => u.customerID == custID); if (chk_total.Checked) { uCust.customerBalance = 0.0M; } else if (chk_custom.Checked) { decimal bal = Convert.ToDecimal(txt_custom.Text.ToString()); decimal leftOver = Convert.ToDecimal(totalBal) - bal; if (leftOver == 0) { uCust.customerBalance = 0.0M; } else if (leftOver > 0) { decimal cred = Convert.ToDecimal(totalBal) - leftOver; uCust.customerBalance = uCust.customerBalance - cred; uCust.credit = cred; } else { decimal left = Math.Abs(Convert.ToDecimal(totalBal) - leftOver); uCust.customerBalance = 0.0M; uCust.credit = Convert.ToDecimal(credit) + left; } } } }
partial void DeleteCustomer1(Customer1 instance);
partial void UpdateCustomer1(Customer1 instance);
partial void InsertCustomer1(Customer1 instance);