private void CuttingItemReturn(int materialid, string name, int orderid, decimal QTY, decimal height, decimal width, string store) { var st = db.Stores.Where(x => x.StoreName == store).FirstOrDefault(); int storeid = st.ID; decimal oldstock, newstock; var custlist = db.CuttingListsMaterials.Where(x => x.MaterialID == materialid && x.StoreID == storeid && x.Height == height && x.Width == width).FirstOrDefault(); if (custlist != null) { oldstock = Convert.ToDecimal(custlist.Quantity); newstock = oldstock + QTY; custlist.Quantity = newstock; db.SaveChanges(); Logger log = new Logger(); log.Action = "Return of Cutting List of Material ( " + name + " ) In store ( " + store + " ) from Order ( " + orderid + " )"; log.ActionDate = DateTime.Now; log.UserName = User.Identity.Name; log.ActionType = "CuttingList Return"; db.Loggers.Add(log); db.SaveChanges(); MaterialHistory MH = new MaterialHistory(); MH.ActionDate = DateTime.Now; MH.MaterialID = materialid; MH.StoreID = storeid; MH.TransactionName = "Return CuttingList"; MH.UserName = User.Identity.Name; MH.NewStock = newstock; MH.OldStock = oldstock; MH.Note = "CuttingListMaterial ( " + name + " ) is now returned in Store ( " + storeid.ToString() + " ) From order ( " + orderid + " ) With Height " + height.ToString() + " and Width " + width.ToString(); db.MaterialHistories.Add(MH); db.SaveChanges(); } else { CuttingListsMaterial cs = new CuttingListsMaterial(); cs.Quantity = QTY; cs.StoreID = storeid; cs.MaterialID = materialid; cs.IsActive = true; cs.Height = height; cs.Width = width; cs.UserName = User.Identity.Name; cs.Notes = "Return of Cutting List of Material ( " + name + " ) In store ( " + store + " ) from Order ( " + orderid + " )"; cs.ActionDate = DateTime.Now; db.CuttingListsMaterials.Add(cs); db.SaveChanges(); MaterialHistory MH = new MaterialHistory(); MH.ActionDate = DateTime.Now; MH.MaterialID = materialid; MH.StoreID = storeid; MH.TransactionName = "Return CuttingList"; MH.UserName = User.Identity.Name; MH.NewStock = Convert.ToDecimal(QTY); MH.OldStock = 0; MH.Note = "CuttingListMaterial ( " + name + " ) is now returned in Store ( " + storeid.ToString() + " ) From order ( " + orderid + " ) With Height " + height.ToString() + " and Width " + width.ToString(); db.MaterialHistories.Add(MH); db.SaveChanges(); } }
private void CuttingItemStock() { var MaterialID = Convert.ToInt32(txtMaterialID.Value); var MaterialStore = Convert.ToInt32(FromStore.SelectedValue); var Materialheight = Convert.ToDecimal(txtitemHieght.Value); var MaterialWidth = Convert.ToDecimal(txtItemWidth.Value); var MaterialNotes = txtItemNotes.Value.ToString(); var MaterialStock = Convert.ToDecimal(txtCurrentStock.Value); var storeto = Convert.ToInt32(ToStore.SelectedValue); var newstock = MaterialStock - Convert.ToDecimal(txtRequestedStock.Value); var fromitem = db.CuttingListsMaterials.Where(x => x.MaterialID == MaterialID && x.StoreID == MaterialStore && x.Height == Materialheight && x.Width == MaterialWidth && x.Notes == MaterialNotes.ToString()).FirstOrDefault(); var toitem = db.CuttingListsMaterials.Where(x => x.MaterialID == MaterialID && x.StoreID == storeto && x.Height == Materialheight && x.Width == MaterialWidth && x.Notes == MaterialNotes.ToString()).FirstOrDefault(); if (fromitem != null) { fromitem.Quantity -= Convert.ToDecimal(txtRequestedStock.Value); db.SaveChanges(); } CuttingListsMaterial CS = new CuttingListsMaterial(); CS.StoreID = Convert.ToInt32(ToStore.SelectedValue); CS.MaterialID = MaterialID; CS.Height = Materialheight; CS.Width = MaterialWidth; CS.Quantity = Convert.ToDecimal(txtRequestedStock.Value); CS.UserName = User.Identity.Name; CS.ActionDate = DateTime.Now; CS.Notes = "Transferred From Store " + MaterialStore.ToString() + " At " + DateTime.Now.ToString() + " Transfer Number " + LblTransferID.Text; CS.IsActive = true; db.CuttingListsMaterials.Add(CS); db.SaveChanges(); Logger log = new Logger(); log.Action = "Transfer Number ( " + LblTransferID.Text + " ) CuttingList Material (" + fromitem.Material.MaterialName.ToString() + " ) , " + "The Stock changed from " + MaterialStock.ToString() + " to " + newstock.ToString() + " From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )"; log.ActionDate = DateTime.Now; log.ActionType = "CuttingList Transfer"; log.UserName = User.Identity.Name; db.Loggers.Add(log); db.SaveChanges(); MaterialHistory MH = new MaterialHistory(); MH.MaterialID = MaterialID; MH.StoreID = MaterialStore; MH.OldStock = MaterialStock; MH.NewStock = newstock; MH.ActionDate = DateTime.Now; MH.UserName = User.Identity.Name; MH.Note = " Cutting List Transfer No " + LblTransferID.Text.ToString() + " With Height " + Materialheight.ToString() + " and Width " + MaterialWidth.ToString(); MH.TransactionName = "CuttingList Transfer"; db.MaterialHistories.Add(MH); db.SaveChanges(); MaterialHistory MH2 = new MaterialHistory(); MH2.MaterialID = MaterialID; MH2.StoreID = Convert.ToInt32(ToStore.SelectedValue); MH2.OldStock = 0; MH2.NewStock = Convert.ToDecimal(txtRequestedStock.Value); MH2.ActionDate = DateTime.Now; MH2.UserName = User.Identity.Name; MH2.Note = " Cutting List Transfer No " + LblTransferID.Text.ToString() + " With Height " + Materialheight.ToString() + " and Width " + MaterialWidth.ToString(); MH2.TransactionName = "CuttingList Transfer"; db.MaterialHistories.Add(MH2); db.SaveChanges(); }
private void AddNewCuttingList() { decimal QTY; decimal Height; decimal Width; CuttingListsMaterial DM = new CuttingListsMaterial(); DM.StoreID = Convert.ToInt32(SelectStores.SelectedValue); DM.MaterialID = Convert.ToInt32(selectitem.SelectedValue); DM.Notes = DefectiveNote.Value; //Get Quantity Value if (Quantity.Value == null || Quantity.Value == string.Empty) { QTY = 0; } else { QTY = Convert.ToDecimal(Quantity.Value); } DM.Quantity = QTY; //Get Height Value if (Sheight.Value == null || Sheight.Value == String.Empty) { Height = 0; } else { Height = Convert.ToDecimal(Sheight.Value); } DM.Height = Height; //Get Width Value if (SWidth.Value == null || SWidth.Value == String.Empty) { Width = 0; } else { Width = Convert.ToDecimal(SWidth.Value); } DM.Width = Width; DM.IsActive = true; DM.UnitID = Convert.ToInt32(itemunit.SelectedValue); DM.UserName = User.Identity.Name.ToString(); DM.ActionDate = DateTime.Now; DM.ReservedQTY = 0; db.CuttingListsMaterials.Add(DM); db.SaveChanges(); Logger log = new Logger(); log.UserName = User.Identity.Name; log.Action = @"New Cutting List of ( " + selectitem.SelectedItem.ToString() + " ) is added successfully to " + "store( " + SelectStores.SelectedItem.ToString() + " ) With Height " + Sheight.Value.ToString() + " and Width " + SWidth.Value.ToString(); log.ActionType = "New CuttingList"; log.ActionDate = DateTime.Now; db.Loggers.Add(log); db.SaveChanges(); LblError.Text = "New Cutting List Material is added Successfully"; LblError.Visible = true; LblError.ForeColor = System.Drawing.Color.Green; MaterialHistory MH = new MaterialHistory(); MH.ActionDate = DateTime.Now; MH.UserName = User.Identity.Name; MH.TransactionName = "New CuttingList"; MH.OldStock = 0; //Get Height Value if (Sheight.Value == null || Sheight.Value == String.Empty) { Height = 0; } else { Height = Convert.ToDecimal(Sheight.Value); } DM.Height = Height; //Get Width Value if (SWidth.Value == null || SWidth.Value == String.Empty) { Width = 0; } else { Width = Convert.ToDecimal(SWidth.Value); } DM.Width = Width; MH.Note = "New Cutting List With Height " + Height.ToString() + " And Width " + Width.ToString(); MH.NewStock = Convert.ToDecimal(Quantity.Value); MH.MaterialID = Convert.ToInt32(selectitem.SelectedValue); MH.StoreID = Convert.ToInt32(SelectStores.SelectedValue); db.MaterialHistories.Add(MH); db.SaveChanges(); Quantity.Value = ""; Sheight.Value = ""; SWidth.Value = ""; DefectiveNote.Value = ""; //STORES.DataBind(); //SelectStores.SelectedIndex = 0; //selectitem.SelectedIndex = 0; }