Exemple #1
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);
                }
            }
        }
        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)
            {
                int                 id         = Globals.MStockpassing;
                Stock_Item          itemEdited = db.Stock_Item.FirstOrDefault(c => c.Stock_ID == id);
                Stock_Write_Off     writeoff   = new Stock_Write_Off();
                Stock_WriteOff_Line writeline  = new Stock_WriteOff_Line();

                if ((phrase.Length < 9) && (Convert.ToInt32(txtStockQuantity.Text) <= itemEdited.Stock_Item_Quantity) && Convert.ToInt32(txtStockQuantity.Text) > 0)
                {
                    itemEdited.Stock_Item_Quantity = itemEdited.Stock_Item_Quantity - Convert.ToInt32(txtStockQuantity.Text);

                    writeoff.WriteOff_Stock_Name     = itemEdited.Stock_Item_Name;
                    writeoff.WriteOff_Reason         = txtReason.Text;
                    writeoff.Stock_WriteOff_Quantity = Convert.ToInt32(txtStockQuantity.Text);
                    writeoff.WriteOffDate            = DateTime.Now;

                    writeline.Stock_ID        = itemEdited.Stock_ID;
                    writeline.Write_Off_ID    = writeoff.Write_Off_ID;
                    writeline.Quantity        = Convert.ToInt32(txtStockQuantity.Text);
                    writeline.Stock_Item_Name = itemEdited.Stock_Item_Name;

                    db.Stock_Write_Off.Add(writeoff);
                    db.Stock_WriteOff_Line.Add(writeline);

                    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       = "Stock_Write_Off";
                    ad.Audit_Description = "Stock_Item_Write_Off";
                    ad.User_ID           = Globals.LogedUser;
                    ad.transactionNumber = writeoff.Write_Off_ID;
                    ad.auditDate         = DateTime.Now;
                    db.Audits.Add(ad);
                    db.SaveChanges();

                    MessageBox.Show("Stock item writen off successfully,quantity: -" + txtStockQuantity.Text);
                    Globals.refresher = true;
                    this.Close();
                }


                else
                {
                    MessageBox.Show("Error:Quantity exceeds available stock items/Quantity less than 1 or too large");
                }
            }
            else
            {
                MessageBox.Show("Error: Value entered is not in correct format(not numeric)");
            }
        }