Esempio n. 1
0
        private void dgvOrders_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowindex = dgvOrders.CurrentCell.RowIndex;

            Globals.Salespassing = dgvOrders.Rows[rowindex].Cells[0].Value;

            int            orderNo = Globals.Salespassing;
            Customer_Order ordeR   = db.Customer_Order.FirstOrDefault(c => c.Order_ID == orderNo);

            txtDate.Enabled       = false;
            txtOrderTotal.Enabled = false;
            txtOrdNum.Enabled     = false;
            txtStatus.Enabled     = false;
            txtVat.Enabled        = false;
            rbxNotes.Enabled      = false;

            txtDate.Text       = ordeR.Order_Date.ToString();
            txtOrderTotal.Text = ordeR.OrderTotal.ToString();
            txtOrdNum.Text     = ordeR.Order_ID.ToString();
            txtStatus.Text     = ordeR.Order_Status.ToString();
            txtVat.Text        = ordeR.Sale_Vat_Amount.ToString();
            rbxNotes.Text      = ordeR.OrderNotes.ToString();

            var combos = from obj in db.Customer_Order_Line
                         where (obj.Customer_Order_ID == orderNo) && (obj.Combo_ID != null)
                         select new
            {
                itemId       = obj.Combo_ID,
                itemQuantity = obj.Combo_Quantity
            };

            foreach (var item in combos)
            {
                Globals it    = new Globals();
                dynamic num   = item.itemId;
                int     id    = num;
                dynamic num2  = item.itemQuantity;
                int     quant = num2;
                Combo   comb  = db.Comboes.FirstOrDefault(c => c.Combo_ID == id);
                it.OrderItemName  = comb.Combo_Name;
                it.OrderQuantity  = num2;
                it.OrderItemPrice = comb.Combo_Price;

                list.Add(it);
            }



            var menus = from obj in db.Customer_Order_Line
                        where (obj.Customer_Order_ID == orderNo) && (obj.Menu_Item_ID != null)
                        select new
            {
                itemId       = obj.Menu_Item_ID,
                itemQuantity = obj.Menu_Item_Quantity
            };

            foreach (var item in menus)
            {
                Globals   it    = new Globals();
                dynamic   num   = item.itemId;
                int       id    = num;
                dynamic   num2  = item.itemQuantity;
                int       quant = num2;
                Menu_Item comb  = db.Menu_Item.FirstOrDefault(c => c.Menu_Item_ID == id);
                it.OrderItemName  = comb.Menu_Item_Name;
                it.OrderQuantity  = num2;
                it.OrderItemPrice = comb.Menu_Item_Price;

                list.Add(it);
            }

            var stocks = from obj in db.Customer_Order_Line
                         where (obj.Customer_Order_ID == orderNo) && (obj.Stock_ID != null)
                         select new
            {
                itemId       = obj.Stock_ID,
                itemQuantity = obj.Stock_Item_Quantity
            };

            foreach (var item in stocks)
            {
                Globals    it    = new Globals();
                dynamic    num   = item.itemId;
                int        id    = num;
                dynamic    num2  = item.itemQuantity;
                int        quant = num2;
                Stock_Item comb  = db.Stock_Item.FirstOrDefault(c => c.Stock_ID == id);
                it.OrderItemName = comb.Stock_Item_Name;
                it.OrderQuantity = num2;
                dynamic     num3 = comb.Stock_ID;
                int         id5  = num3;
                Stock_Price pric = db.Stock_Price.FirstOrDefault(c => c.Stock_Price_ID == id5);
                it.OrderItemPrice = pric.Stock_Price1;

                list.Add(it);
            }



            var products = from obj in list
                           select new
            {
                ItemName     = obj.OrderItemName,
                ItemQuantity = obj.OrderQuantity,
                ItemPrice    = obj.OrderItemPrice
            };


            dataGridView1.DataSource = products.ToList();
            list.Clear();
        }
        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;
        }
Esempio n. 3
0
        private void frmViewOrder_Load(object sender, EventArgs e)
        {
            int            orderNo = Globals.Salespassing;
            Customer_Order ordeR   = db.Customer_Order.FirstOrDefault(c => c.Order_ID == orderNo);

            if (ordeR != null)
            {
                txtDate.Enabled       = false;
                txtOrderTotal.Enabled = false;
                txtOrdNum.Enabled     = false;
                txtStatus.Enabled     = false;
                txtVat.Enabled        = false;
                rbxNotes.Enabled      = false;

                txtDate.Text       = ordeR.Order_Date.ToString();
                txtOrderTotal.Text = ordeR.OrderTotal.ToString();
                txtOrdNum.Text     = ordeR.Order_ID.ToString();
                txtStatus.Text     = ordeR.Order_Status.ToString();
                txtVat.Text        = ordeR.Sale_Vat_Amount.ToString();
                rbxNotes.Text      = ordeR.OrderNotes.ToString();

                var combos = from obj in db.Customer_Order_Line
                             where (obj.Customer_Order_ID == orderNo) && (obj.Combo_ID != null)
                             select new
                {
                    itemId       = obj.Combo_ID,
                    itemQuantity = obj.Combo_Quantity
                };

                foreach (var item in combos)
                {
                    Globals it    = new Globals();
                    dynamic num   = item.itemId;
                    int     id    = num;
                    dynamic num2  = item.itemQuantity;
                    int     quant = num2;
                    Combo   comb  = db.Comboes.FirstOrDefault(c => c.Combo_ID == id);
                    it.OrderItemName  = comb.Combo_Name;
                    it.OrderQuantity  = num2;
                    it.OrderItemPrice = comb.Combo_Price;

                    list.Add(it);
                }



                var menus = from obj in db.Customer_Order_Line
                            where (obj.Customer_Order_ID == orderNo) && (obj.Menu_Item_ID != null)
                            select new
                {
                    itemId       = obj.Menu_Item_ID,
                    itemQuantity = obj.Menu_Item_Quantity
                };

                foreach (var item in menus)
                {
                    Globals   it    = new Globals();
                    dynamic   num   = item.itemId;
                    int       id    = num;
                    dynamic   num2  = item.itemQuantity;
                    int       quant = num2;
                    Menu_Item comb  = db.Menu_Item.FirstOrDefault(c => c.Menu_Item_ID == id);
                    it.OrderItemName  = comb.Menu_Item_Name;
                    it.OrderQuantity  = num2;
                    it.OrderItemPrice = comb.Menu_Item_Price;

                    list.Add(it);
                }

                var stocks = from obj in db.Customer_Order_Line
                             where (obj.Customer_Order_ID == orderNo) && (obj.Stock_ID != null)
                             select new
                {
                    itemId       = obj.Stock_ID,
                    itemQuantity = obj.Stock_Item_Quantity
                };

                foreach (var item in stocks)
                {
                    Globals    it    = new Globals();
                    dynamic    num   = item.itemId;
                    int        id    = num;
                    dynamic    num2  = item.itemQuantity;
                    int        quant = num2;
                    Stock_Item comb  = db.Stock_Item.FirstOrDefault(c => c.Stock_ID == id);
                    it.OrderItemName = comb.Stock_Item_Name;
                    it.OrderQuantity = num2;
                    dynamic     num3 = comb.Stock_ID;
                    int         id5  = num3;
                    Stock_Price pric = db.Stock_Price.FirstOrDefault(c => c.Stock_Price_ID == id5);
                    it.OrderItemPrice = pric.Stock_Price1;

                    list.Add(it);
                }



                var products = from obj in list
                               select new
                {
                    ItemName     = obj.OrderItemName,
                    ItemQuantity = obj.OrderQuantity,
                    ItemPrice    = obj.OrderItemPrice
                };


                dgvOrders.DataSource = products.ToList();
            }
            else
            {
                this.Close();
                MessageBox.Show("No Order selected,Select order to view");
            }
        }
        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");
            }
        }