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 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");
            }
        }