private void btnDeliverySubmit_Click(object sender, EventArgs e) { Company_Information inf = db.Company_Information.FirstOrDefault(c => c.Company_Info_ID == 1); string phrase = txtContact.Text; double number; bool isNumeric = double.TryParse(phrase, out number); if ((phrase.Length == 10) && (isNumeric == true)) { if (Convert.ToInt32(txtContact.Text) > -1) { double VatAmount = 0; DeliveryTable order = new DeliveryTable(); order.ItemName = ""; order.orderTotal = Globals.AmountDue; int contact = Convert.ToInt32(txtContact.Text); if (Globals.ComboItems.Count != 0) { foreach (var item in Globals.ComboItems) { VatAmount = VatAmount + item.OrderItemPrice * inf.VAT_Percentage; } } if (Globals.ComboItems.Count != 0) { foreach (var item in Globals.MenuItems) { VatAmount = VatAmount + item.OrderItemPrice * inf.VAT_Percentage; } } if (Globals.StockItems.Count != 0) { foreach (var item in Globals.StockItems) { VatAmount = VatAmount + item.OrderItemPrice * inf.VAT_Percentage; } } VatAmount = Math.Round(VatAmount, 2); order.orderDatef = DateTime.Now; order.vatTot = VatAmount; order.orderNotesf = richTextBox1.Text; order.orderTotal = Globals.AmountDue; order.totalItemsf = Globals.ComboItems.Count + Globals.MenuItems.Count + Globals.StockItems.Count; Customer cust = db.Customers.FirstOrDefault(c => ((c.Customer_Name == txtCustName.Text) && (c.Customer_Contact_Number == contact))); if (cust == null) { MessageBox.Show("Customer does not exist,Add customer"); using (frmAddCustomer frm = new frmAddCustomer() { }) { if ((frm.ShowDialog() == DialogResult.OK) && (Globals.addCustomer == true)) { var some = db.Customers.ToList(); cust = some.LastOrDefault(); order.customerName = cust.Customer_Name; order.customerContact = cust.Customer_Contact_Number; } else { MessageBox.Show("Something went wrong"); return; } } } else { order.customerName = txtCustName.Text; order.customerContact = Convert.ToInt32(txtContact.Text); } db.DeliveryTables.Add(order); db.SaveChanges(); for (int i = 0; i < Globals.ComboItems.Count; i++) { DeliveryLine item = new DeliveryLine(); item.comboItemId = Globals.ComboItems[i].OrderItemId; item.orderId = order.OrderId; item.comboItemQuantity = Globals.ComboItems[i].OrderQuantity; db.DeliveryLines.Add(item); } for (int i = 0; i < Globals.StockItems.Count; i++) { DeliveryLine item = new DeliveryLine(); item.stockItemId = Globals.StockItems[i].OrderItemId; item.orderId = order.OrderId; item.stockItemQuantity = Globals.StockItems[i].OrderQuantity; db.DeliveryLines.Add(item); } for (int i = 0; i < Globals.MenuItems.Count; i++) { DeliveryLine item = new DeliveryLine(); item.menuItemId = Globals.MenuItems[i].OrderItemId; item.orderId = order.OrderId; item.menuItemQuantity = Globals.MenuItems[i].OrderQuantity; db.DeliveryLines.Add(item); } db.SaveChanges(); this.Close(); Globals.ComboItems.Clear(); Globals.MenuItems.Clear(); Globals.StockItems.Clear(); int id2 = Globals.LogedUser; Employee emp = db.Employees.FirstOrDefault(c => c.Employee_ID == id2); Audit ad = new Audit(); ad.Audit_Name = emp.Employee_Name; ad.Audit_Table = "DeliveryTable"; ad.Audit_Description = "Order Saving"; ad.User_ID = Globals.LogedUser; ad.transactionNumber = order.OrderId; ad.auditDate = DateTime.Now; db.Audits.Add(ad); db.SaveChanges(); MessageBox.Show("Order saved successfully with order number: " + order.OrderId.ToString() + ",customer Address: " + cust.Customer_Address.ToString()); string username = "******"; string password = "******"; string msgsender = "4700000000"; string destinationaddr = "27" + txtContact.Text.Substring(1, 9); string message = "Dear customer,thank you for ordering food with us,your order is being prepared for delivery,your order number is: " + order.OrderId.ToString(); // Create ViaNettSMS object with username and password ViaNettSMS s = new ViaNettSMS(username, password); // Declare Result object returned by the SendSMS function ViaNettSMS.Result result; try { // Send SMS through HTTP API result = s.sendSMS(msgsender, destinationaddr, message); // Show Send SMS response if (result.Success) { MessageBox.Show("Order confirmation message successfully sent to customer"); } else { MessageBox.Show("Error:Network connection not strong enough to send and receive messages:" + result.ErrorCode + " " + result.ErrorMessage); } } catch (System.Net.WebException ex) { //Catch error occurred while connecting to server. MessageBox.Show(ex.Message); } } else { MessageBox.Show("Error: Contact number can't be a negative number"); } } else { MessageBox.Show("Error: Contact number not numeric/valid,please anter a valid number(integer)"); } }
private void btnRetrieve_Click(object sender, EventArgs e) { string phrase = txtOrderNo.Text; double number; bool isNumeric = double.TryParse(phrase, out number); if ((phrase.Length < 9) && (isNumeric == true)) { if (Convert.ToInt32(txtOrderNo.Text) > -1) { listBox1.Items.Clear(); int orderNo = Convert.ToInt32(txtOrderNo.Text); Company_Information inf = db.Company_Information.FirstOrDefault(c => c.Company_Info_ID == 1); var combos = from obj in db.DeliveryLines where (obj.orderId == orderNo) && (obj.comboItemId != null) select new { itemId = obj.comboItemId, itemQuantity = obj.comboItemQuantity }; foreach (var item in combos) { var comboId = item.itemId; Combo comb = db.Comboes.FirstOrDefault(c => c.Combo_ID == comboId); string itemAdd = "ItemName:: " + comb.Combo_Name + " Price: " + comb.Combo_Price + " Quantity: " + Convert.ToString(item.itemQuantity); Globals.vatAmountDelivery = Globals.vatAmountDelivery + comb.Combo_Price * inf.VAT_Percentage; listBox1.Items.Add(itemAdd); } var menus = from obj in db.DeliveryLines where (obj.orderId == orderNo) && (obj.menuItemId != null) select new { itemId = obj.menuItemId, itemQuantity = obj.menuItemQuantity }; foreach (var item in menus) { var Menu_Item_ID = item.itemId; Menu_Item comb = db.Menu_Item.FirstOrDefault(c => c.Menu_Item_ID == Menu_Item_ID); string itemAdd = "ItemName:: " + comb.Menu_Item_Name + " Price:: " + comb.Menu_Item_Price + " Quantity: " + Convert.ToString(item.itemQuantity); Globals.vatAmountDelivery = Globals.vatAmountDelivery + comb.Menu_Item_Price * inf.VAT_Percentage; listBox1.Items.Add(itemAdd); } var stocks = from obj in db.DeliveryLines where (obj.orderId == orderNo) && (obj.stockItemId != null) select new { itemId = obj.stockItemId, itemQuantity = obj.stockItemQuantity }; foreach (var item in stocks) { var Stock_ID = item.itemId; Stock_Item comb = db.Stock_Item.FirstOrDefault(c => c.Stock_ID == Stock_ID); string itemAdd = "ItemName:: " + comb.Stock_Item_Name + " Price: " + comb.Stock_Price + " Quantity: " + Convert.ToString(item.itemQuantity); Stock_Price pric = db.Stock_Price.FirstOrDefault(c => c.Stock_Price_ID == Stock_ID); Globals.vatAmountDelivery = Globals.vatAmountDelivery + pric.Stock_Price1 * inf.VAT_Percentage; listBox1.Items.Add(itemAdd); } if (listBox1.Items.Count != 0) { btnPay.Visible = true; } } else { MessageBox.Show("Error: Item 'ID' can't be less than one"); } } else { MessageBox.Show("Error: Item 'ID' not numeric,please anter a numeric value(integer)"); } }
private void button7_Click(object sender, EventArgs e) { //string phrase = txtCash.Text; //double number; //bool isNumeric = double.TryParse(phrase, out number); //if ((phrase.Length < 9) && (isNumeric == true)) //{ // if (Convert.ToInt32(txtCash.Text) > -1) // { //int contact = Convert.ToInt32(txtContact.Text); Customer_Order order = new Customer_Order(); //Object Declaration---------------------------------// try { Company_Information inf = db.Company_Information.FirstOrDefault(c => c.Company_Info_ID == 1); double VatAmount = 0; if (Globals.ComboItems.Count != 0) { foreach (var item in Globals.ComboItems) { VatAmount = VatAmount + item.OrderItemPrice * inf.VAT_Percentage; } } if (Globals.ComboItems.Count != 0) { foreach (var item in Globals.MenuItems) { VatAmount = VatAmount + item.OrderItemPrice * inf.VAT_Percentage; } } if (Globals.StockItems.Count != 0) { foreach (var item in Globals.StockItems) { VatAmount = VatAmount + item.OrderItemPrice * inf.VAT_Percentage; } } //-----------------------------------------------------// VatAmount = Math.Round(VatAmount, 2); //Order Details insert------------------------------------// order.Order_Status = "N"; order.Order_Date = DateTime.Now; order.Sale_Vat_Amount = VatAmount; order.Payment_ID = Globals.SalesPaymentID; order.Delivery_Status_ID = 2; order.OrderNotes = richTextBox1.Text; order.OrderTotal = Globals.AmountDue; order.TotalItems = Globals.ComboItems.Count + Globals.MenuItems.Count + Globals.StockItems.Count; order.Cash = Convert.ToDouble(txtCash.Text); order.Change = Convert.ToDouble(txtCash.Text) - Globals.AmountDue; //order.Customer_ID = cust.Customer_ID; //---------------------------------------------------------// db.Customer_Order.Add(order); db.SaveChanges(); } catch (Exception i) { MessageBox.Show(Convert.ToString(i)); } for (int i = 0; i < Globals.ComboItems.Count; i++) { Customer_Order_Line orderLine = new Customer_Order_Line(); orderLine.Customer_Order_ID = order.Order_ID; orderLine.Combo_Quantity = Globals.ComboItems[i].OrderQuantity; orderLine.Combo_ID = Globals.ComboItems[i].OrderItemId; db.Customer_Order_Line.Add(orderLine); db.SaveChanges(); } for (int i = 0; i < Globals.StockItems.Count; i++) { Customer_Order_Line orderLine = new Customer_Order_Line(); orderLine.Customer_Order_ID = order.Order_ID; orderLine.Stock_Item_Quantity = Globals.StockItems[i].OrderQuantity; orderLine.Stock_ID = Globals.StockItems[i].OrderItemId; int id = Globals.StockItems[i].OrderItemId; Stock_Item stc = db.Stock_Item.FirstOrDefault(c => c.Stock_ID == id); stc.Stock_Item_Quantity = stc.Stock_Item_Quantity - Globals.StockItems[i].OrderQuantity; db.Customer_Order_Line.Add(orderLine); db.SaveChanges(); } for (int i = 0; i < Globals.MenuItems.Count; i++) { Customer_Order_Line orderLine = new Customer_Order_Line(); orderLine.Customer_Order_ID = order.Order_ID; orderLine.Menu_Item_Quantity = Globals.MenuItems[i].OrderQuantity; orderLine.Menu_Item_ID = Globals.MenuItems[i].OrderItemId; db.Customer_Order_Line.Add(orderLine); db.SaveChanges(); } Globals.ComboItems.Clear(); Globals.MenuItems.Clear(); Globals.StockItems.Clear(); Globals.refresher = true; Globals.AmountDue = 0; this.Close(); int id2 = Globals.LogedUser; Employee emp = db.Employees.FirstOrDefault(c => c.Employee_ID == id2); Audit ad = new Audit(); ad.Audit_Name = emp.Employee_Name; ad.Audit_Table = "Customer_Order"; ad.Audit_Description = "Order Processing"; ad.User_ID = Globals.LogedUser; ad.transactionNumber = order.Order_ID; ad.auditDate = DateTime.Now; db.Audits.Add(ad); db.SaveChanges(); MessageBox.Show("Order created successfully with order number: " + order.Order_ID.ToString()); btnEatIn.Visible = false; }
private void button1_Click(object sender, EventArgs e) { string phrase = txtOrderNo.Text; double number; bool isNumeric = double.TryParse(phrase, out number); if ((phrase.Length < 9) && (isNumeric == true)) { if (Convert.ToInt32(txtOrderNo.Text) > -1) { int id = Convert.ToInt32(txtOrderNo.Text); DeliveryTable orderD = db.DeliveryTables.FirstOrDefault(c => c.OrderId == id); if (orderD == null) { MessageBox.Show("Order not found"); return; } Payment pay = new Payment(); Payment_Type type = db.Payment_Type.FirstOrDefault(c => c.Payment_Description == "Cash"); pay.Payment_Amount = Convert.ToDouble(Globals.AmountDue); pay.Payment_Date = DateTime.Today; db.Payments.Add(pay); db.SaveChanges(); Globals.SalesPaymentID = pay.Payment_ID; Customer_Order order = new Customer_Order(); string name = orderD.customerName; dynamic num = orderD.customerContact; int contact = num; Customer custom = db.Customers.FirstOrDefault(c => (c.Customer_Name == name) && (c.Customer_Contact_Number == contact)); //Object Declaration---------------------------------// try { Company_Information inf = db.Company_Information.FirstOrDefault(c => c.Company_Info_ID == 1); //-----------------------------------------------------// //Order Details insert------------------------------------// order.Order_Status = "D"; order.Order_Date = DateTime.Now; order.Payment_ID = 2;// db.Payments.LastOrDefault().Payment_ID; order.Delivery_Status_ID = 1; order.OrderNotes = orderD.orderNotesf; order.OrderTotal = orderD.orderTotal; order.TotalItems = orderD.totalItemsf; order.Sale_Vat_Amount = Globals.vatAmountDelivery; order.Customer_ID = custom.Customer_ID; //---------------------------------------------------------// db.Customer_Order.Add(order); db.SaveChanges(); } catch (Exception i) { MessageBox.Show(Convert.ToString(i)); } int orderNo = orderD.OrderId; var combos = from obj in db.DeliveryLines where (obj.orderId == orderNo) && (obj.comboItemId != null) select new { itemId = obj.comboItemId, itemQuantity = obj.comboItemQuantity }; foreach (var item in combos) { //MessageBox.Show(Convert.ToString(order.Order_ID)+ " " + Convert.ToString(order.Order_ID)); Customer_Order_Line orderLine = new Customer_Order_Line(); orderLine.Customer_Order_ID = order.Order_ID; orderLine.Combo_Quantity = item.itemQuantity; orderLine.Combo_ID = item.itemId; db.Customer_Order_Line.Add(orderLine); } var menus = from obj2 in db.DeliveryLines where (obj2.orderId == orderNo) && (obj2.menuItemId != null) select new { itemId = obj2.menuItemId, itemQuantity = obj2.menuItemQuantity }; foreach (var item2 in menus) { //MessageBox.Show(Convert.ToString( item.itemQuantity) + Convert.ToString(item.itemId)); Customer_Order_Line orderLine = new Customer_Order_Line(); orderLine.Customer_Order_ID = order.Order_ID; orderLine.Menu_Item_Quantity = item2.itemQuantity; orderLine.Menu_Item_ID = item2.itemId; db.Customer_Order_Line.Add(orderLine); } var stocks = from obj3 in db.DeliveryLines where (obj3.orderId == orderNo) && (obj3.stockItemId != null) select new { itemId = obj3.stockItemId, itemQuantity = obj3.stockItemQuantity }; foreach (var item3 in stocks) { Customer_Order_Line orderLine = new Customer_Order_Line(); orderLine.Customer_Order_ID = order.Order_ID; orderLine.Menu_Item_Quantity = item3.itemQuantity; orderLine.Menu_Item_ID = item3.itemId; db.Customer_Order_Line.Add(orderLine); } db.SaveChanges(); Globals.ComboItems.Clear(); Globals.MenuItems.Clear(); Globals.StockItems.Clear(); Globals.refresher = true; Globals.AmountDue = 0; this.Close(); int id2 = Globals.LogedUser; Employee emp = db.Employees.FirstOrDefault(c => c.Employee_ID == id2); Audit ad = new Audit(); ad.Audit_Name = emp.Employee_Name; ad.Audit_Table = "Customer_Order"; ad.Audit_Description = "Order Processing"; ad.User_ID = Globals.LogedUser; ad.transactionNumber = order.Order_ID; ad.auditDate = DateTime.Now; db.Audits.Add(ad); db.SaveChanges(); MessageBox.Show("Order created successfully"); } else { MessageBox.Show("Error: Order number can't be less than one"); } } else { MessageBox.Show("Error: Order number should be numerical"); } }