private void btnCheckIn_Click(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); Check_In checkitem = new Check_In(); Check_In_Line checkitemline = new Check_In_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); checkitem.Stock_Item_Name = itemEdited.Stock_Item_Name; checkitem.Check_In_Date = DateTime.Today; checkitemline.Check_In_ID = checkitem.Check_In_ID; checkitemline.Stock_ID = itemEdited.Stock_ID; checkitemline.Quantity = Convert.ToInt32(txtStockQuantity.Text); checkitemline.Stock_Item_Name = itemEdited.Stock_Item_Name; db.Check_In_Line.Add(checkitemline); db.Check_In.Add(checkitem); 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_Item"; ad.Audit_Description = "Item_CheckIn"; ad.User_ID = Globals.LogedUser; ad.transactionNumber = checkitem.Check_In_ID; ad.auditDate = DateTime.Now; db.Audits.Add(ad); db.SaveChanges(); MessageBox.Show("Stock item checked in successfully,quantity: -" + txtStockQuantity.Text); Globals.refresher = true; this.Close(); } else { MessageBox.Show("Error:Quantity exceeds stock items available/Quantity less than 1 or too large"); } } else { MessageBox.Show("Error: Value entered is not in correct format(not numeric)"); } }
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); } } }