private void CreditCardPay_Click(object sender, EventArgs e) { if (this.ItemListInCart.Rows.Count > 0) { //add all food object List <Receipt_Food> foodlist = new List <Receipt_Food>(); foreach (DataGridViewRow row in this.ItemListInCart.Rows) { int foodid = (int)row.Cells[1].Value; int quantity = (int)row.Cells[3].Value; FoodStock foodObj = FoodStock.FindById(foodid); foodlist.Add(new Receipt_Food(foodid, foodObj.Name, foodObj.Price, quantity)); } //make the receipt decimal totalPrice = 0; foreach (DataGridViewRow row in this.ItemListInCart.Rows) { totalPrice += (decimal)row.Cells[5].Value; } decimal tax = (totalPrice * 6 / 100); decimal servTax = this.orderType == "Dine-In" ? totalPrice * 10 / 100 : 0; decimal finaltotal = totalPrice + tax + servTax; Receipt newReceipt = new Receipt(tax, servTax, finaltotal, foodlist); newReceipt.Save(); /*Minus the stock from database*/ foreach (Receipt_Food currFood in newReceipt.FoodOrdered) { //food stock quantity minus ordered quantity FoodStock foodObj = FoodStock.FindById(currFood.FoodId); foodObj.Quantity -= currFood.QuantityOrdered; foodObj.Save(); if (foodObj.Quantity <= 0) { Account myAcc = Model.Account.GetSupplierAcc(); EmailSupplierForm emailSupplier = new EmailSupplierForm(myAcc.Email, foodObj.Id, foodObj.Name); emailSupplier.Show(); } } this.Hide(); ReceiptPage showReceipt = new ReceiptPage(newReceipt, finaltotal); showReceipt.Show(); this.Close(); } else { MessageBox.Show("You must have at least one item to checkout!"); } }
private void CashPayButton_Click(object sender, EventArgs e) { try { decimal cashPayed = Convert.ToDecimal(this.cashAmount.Text); if (this.ItemListInCart.Rows.Count > 0) { //add all food object List <Receipt_Food> foodlist = new List <Receipt_Food>(); foreach (DataGridViewRow row in this.ItemListInCart.Rows) { int foodid = (int)row.Cells[1].Value; int quantity = (int)row.Cells[3].Value; FoodStock foodObj = FoodStock.FindById(foodid); foodlist.Add(new Receipt_Food(foodid, foodObj.Name, foodObj.Price, quantity)); } //make the receipt decimal totalPrice = 0; foreach (DataGridViewRow row in this.ItemListInCart.Rows) { totalPrice += (decimal)row.Cells[5].Value; } decimal tax = (totalPrice * 6 / 100); decimal servTax = this.orderType == "Dine-In" ? totalPrice * 10 / 100 : 0; decimal finaltotal = totalPrice + tax + servTax; if (cashPayed >= finaltotal) { Receipt newReceipt = new Receipt(tax, servTax, finaltotal, foodlist); newReceipt.Save(); /*Minus the stock from database*/ foreach (Receipt_Food currFood in newReceipt.FoodOrdered) { Account myAcc = Model.Account.GetSupplierAcc(); //food stock quantity minus ordered quantity FoodStock foodObj = FoodStock.FindById(currFood.FoodId); foodObj.Quantity -= currFood.QuantityOrdered; foodObj.Save(); if (foodObj.Quantity <= 0) { EmailSupplierForm emailSupplier = new EmailSupplierForm(myAcc.Email, foodObj.Id, foodObj.Name); emailSupplier.Show(); } } this.Hide(); ReceiptPage showReceipt = new ReceiptPage(newReceipt, cashPayed); showReceipt.Show(); this.Close(); } else { MessageBox.Show("The cash amount cannot be lower than Total Price!"); } } else { MessageBox.Show("You must have at least one item to checkout!"); } } catch (Exception ex) { if (ex is FormatException) { MessageBox.Show("Cash Amount must be decimal number!"); } else { MessageBox.Show("Error saving receipt!"); } } }