Пример #1
0
        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");
            }
        }