private void button1_Click_1(object sender, EventArgs e)
        {
            string phrase = txtStockQuantity.Text;

            double number;
            bool   isNumeric = double.TryParse(phrase, out number);

            if (isNumeric == true)
            {
                if ((phrase.Length < 9) && Convert.ToInt32(txtStockQuantity.Text) > 0)
                {
                    int            id         = Globals.MStockpassing;
                    Stock_Item     itemEdited = db.Stock_Item.FirstOrDefault(c => c.Stock_ID == id);
                    Check_Out      itemout    = new Check_Out();
                    Check_Out_Line outline    = new Check_Out_Line();

                    itemout.Stock_Item_Name = itemEdited.Stock_Item_Name;
                    itemout.Check_Out_Date  = DateTime.Today;

                    outline.Stock_ID        = itemEdited.Stock_ID;
                    outline.Check_Out_ID    = itemout.Check_Out_ID;
                    outline.Quaantity       = Convert.ToInt32(txtStockQuantity.Text);
                    outline.Stock_Item_Name = itemEdited.Stock_Item_Name;

                    itemEdited.Stock_Item_Quantity = itemEdited.Stock_Item_Quantity + Convert.ToInt32(txtStockQuantity.Text);
                    db.Check_Out.Add(itemout);
                    db.Check_Out_Line.Add(outline);
                    db.SaveChanges();

                    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       = "Check_Out";
                    ad.Audit_Description = "Item_CheckOut";
                    ad.User_ID           = Globals.LogedUser;
                    ad.transactionNumber = itemout.Check_Out_ID;
                    ad.auditDate         = DateTime.Now;
                    db.Audits.Add(ad);
                    db.SaveChanges();

                    MessageBox.Show("Stock item checked out successfully,quantity: +" + txtStockQuantity.Text);
                    Globals.refresher = true;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Error:Quantity less than 1 or too large");
                }
            }
            else
            {
                MessageBox.Show("Error: Value entered is not in correct format(not numeric)");
            }
        }
Exemple #2
0
        private void dgvAuditList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            dgvAuditDetails.DataSource = null;
            dgvAuditDetails.Rows.Clear();
            int     rowindex = dgvAuditList.CurrentCell.RowIndex;
            dynamic value    = dgvAuditList.Rows[rowindex].Cells[0].Value;

            if (value != null)
            {
                int   v = value;
                Audit t = db.Audits.FirstOrDefault(c => c.Audit_ID == v);
                if (t.Audit_Description == "Order Processing")
                {
                    var Menus = from obj in db.Customer_Order_Line
                                join obj2 in db.Customer_Order
                                on obj.Customer_Order_ID equals obj2.Order_ID
                                where (obj.Menu_Item_ID != null && obj2.Order_ID == t.transactionNumber)
                                select new
                    {
                        Id        = obj.Menu_Item_ID,
                        Quantity1 = obj.Menu_Item_Quantity
                    };

                    var Combos = from obj in db.Customer_Order_Line
                                 join obj2 in db.Customer_Order
                                 on obj.Customer_Order_ID equals obj2.Order_ID
                                 where (obj.Combo_ID != null && obj2.Order_ID == t.transactionNumber)
                                 select new
                    {
                        Id        = obj.Combo_ID,
                        Quantity1 = obj.Combo_Quantity
                    };

                    var Stocks = from obj in db.Customer_Order_Line
                                 join obj2 in db.Customer_Order
                                 on obj.Customer_Order_ID equals obj2.Order_ID
                                 where (obj.Stock_ID != null && obj2.Order_ID == t.transactionNumber)
                                 select new
                    {
                        Id        = obj.Stock_ID,
                        Quantity1 = obj.Stock_Item_Quantity
                    };



                    foreach (var i in Menus)
                    {
                        Menu_Item m = db.Menu_Item.FirstOrDefault(c => c.Menu_Item_ID == i.Id);
                        this.dgvAuditDetails.Rows.Add(m.Menu_Item_Name, i.Quantity1);
                    }

                    foreach (var i in Combos)
                    {
                        Combo m = db.Comboes.FirstOrDefault(c => c.Combo_ID == i.Id);
                        this.dgvAuditDetails.Rows.Add(m.Combo_Name, i.Quantity1);
                    }

                    foreach (var i in Stocks)
                    {
                        Stock_Item m = db.Stock_Item.FirstOrDefault(c => c.Stock_ID == i.Id);
                        this.dgvAuditDetails.Rows.Add(m.Stock_Item_Name, i.Quantity1);
                    }
                }

                else if (t.Audit_Description == "Order Saving")
                {
                    var Menus = from obj in db.DeliveryLines
                                join obj2 in db.DeliveryTables
                                on obj.orderId equals obj2.OrderId
                                where (obj.menuItemId != null && obj2.OrderId == t.transactionNumber)
                                select new
                    {
                        Id        = obj.menuItemId,
                        Quantity1 = obj.menuItemQuantity
                    };

                    var Combos = from obj in db.DeliveryLines
                                 join obj2 in db.DeliveryTables
                                 on obj.orderId equals obj2.OrderId
                                 where (obj.comboItemId != null && obj2.OrderId == t.transactionNumber)
                                 select new
                    {
                        Id        = obj.comboItemId,
                        Quantity1 = obj.comboItemQuantity
                    };

                    var Stocks = from obj in db.DeliveryLines
                                 join obj2 in db.DeliveryTables
                                 on obj.orderId equals obj2.OrderId
                                 where (obj.stockItemId != null && obj2.OrderId == t.transactionNumber)
                                 select new
                    {
                        Id        = obj.stockItemId,
                        Quantity1 = obj.stockItemQuantity
                    };



                    foreach (var i in Menus)
                    {
                        Menu_Item m = db.Menu_Item.FirstOrDefault(c => c.Menu_Item_ID == i.Id);
                        this.dgvAuditDetails.Rows.Add(m.Menu_Item_Name, i.Quantity1);
                    }

                    foreach (var i in Combos)
                    {
                        Combo m = db.Comboes.FirstOrDefault(c => c.Combo_ID == i.Id);
                        this.dgvAuditDetails.Rows.Add(m.Combo_Name, i.Quantity1);
                    }

                    foreach (var i in Stocks)
                    {
                        Stock_Item m = db.Stock_Item.FirstOrDefault(c => c.Stock_ID == i.Id);
                        this.dgvAuditDetails.Rows.Add(m.Stock_Item_Name, i.Quantity1);
                    }
                }

                else if (t.Audit_Description == "Stock_Item_Write_Off")
                {
                    Stock_WriteOff_Line w = db.Stock_WriteOff_Line.FirstOrDefault(c => c.Stock_WriteOff_LineID == t.transactionNumber);
                    Stock_Item          s = db.Stock_Item.FirstOrDefault(c => c.Stock_ID == w.Stock_ID);
                    this.dgvAuditDetails.Rows.Add(s.Stock_Item_Name, w.Quantity);
                }
                else if (t.Audit_Description == "Item_CheckIn")
                {
                    Check_In_Line w = db.Check_In_Line.FirstOrDefault(c => c.Check_In_Line_ID == t.transactionNumber);
                    Stock_Item    s = db.Stock_Item.FirstOrDefault(c => c.Stock_ID == w.Stock_ID);
                    this.dgvAuditDetails.Rows.Add(s.Stock_Item_Name, w.Quantity);
                }

                else if (t.Audit_Description == "Item_CheckOut")
                {
                    Check_Out_Line w = db.Check_Out_Line.FirstOrDefault(c => c.Check_Out_ID == t.transactionNumber);
                    Stock_Item     s = db.Stock_Item.FirstOrDefault(c => c.Stock_ID == w.Stock_ID);
                    this.dgvAuditDetails.Rows.Add(s.Stock_Item_Name, w.Quaantity);
                }
            }
        }