private void LogSalesReservation(decimal?oldstock, decimal?newstock, int iD, bool reserve)
        {
            try
            {
                var             material = db.MaterialInStocks.Where(x => x.ID == iD).FirstOrDefault();
                MaterialHistory MH       = new MaterialHistory();
                MH.ActionDate = DateTime.Now;
                MH.MaterialID = material.MaterialID;
                MH.StoreID    = material.StoreID;
                MH.OldStock   = oldstock;
                MH.NewStock   = newstock;
                if (reserve)
                {
                    MH.Note            = " Sales Reservation Of Material ( " + material.Material.MaterialName.ToString() + " ) in Store ( " + material.Store.StoreName.ToString() + " ) By " + User.Identity.Name.ToString();
                    MH.TransactionName = "Sales Reservation";
                }
                else
                {
                    MH.Note            = " Sales Reservation of Material ( " + material.Material.MaterialName.ToString() + " ) in Store ( " + material.Store.StoreName.ToString() + " ) Cancelled By " + User.Identity.Name.ToString();
                    MH.TransactionName = "Cancel Reservation";
                }

                MH.UserName = User.Identity.Name.ToString();

                db.MaterialHistories.Add(MH);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                lblError.Text      = "Error in Log History of Reservation , Error is " + ex.InnerException.Message;
                lblError.Visible   = true;
                lblError.ForeColor = System.Drawing.Color.Red;
            }
        }
Пример #2
0
        private void AddNewStock(int storeid, int materialid, decimal QTY)
        {
            try
            {
                var     MS = db.MaterialInStocks.Where(x => x.MaterialID == materialid && x.StoreID == storeid).FirstOrDefault();
                decimal oldstock, newstock;
                oldstock       = Convert.ToDecimal(MS.StockOnHand);
                newstock       = oldstock + QTY;
                MS.StockOnHand = newstock;
                db.SaveChanges();

                Logger log = new Logger();
                log.UserName   = User.Identity.Name;
                log.Action     = "Material " + MS.Material.MaterialName.ToString() + " Stock is now increased From " + oldstock.ToString() + " To " + newstock.ToString();
                log.ActionType = "Item Addition";
                log.ActionDate = DateTime.Now;
                db.Loggers.Add(log);
                db.SaveChanges();

                StockLogger stLog = new StockLogger();
                stLog.ActionDate      = DateTime.Now;
                stLog.MaterialInStock = MS.ID;
                stLog.NewStock        = newstock;
                stLog.OldStock        = oldstock;
                stLog.UserName        = User.Identity.Name;
                stLog.Notes           = "Material " + MS.Material.MaterialName.ToString() + " stock increased in Container " + txtContainerNumber.Value.ToString();
                db.StockLoggers.Add(stLog);
                db.SaveChanges();

                MaterialHistory MH = new MaterialHistory();
                MH.MaterialID      = materialid;
                MH.StoreID         = storeid;
                MH.NewStock        = newstock;
                MH.OldStock        = oldstock;
                MH.TransactionName = "Addition";
                MH.UserName        = User.Identity.Name;
                MH.ActionDate      = DateTime.Now;
                MH.Note            = "Material " + MS.Material.MaterialName.ToString() + " stock increased in Container " + txtContainerNumber.Value.ToString();
                db.MaterialHistories.Add(MH);
                db.SaveChanges();

                lblAddItemErr.Text      = "Item Entered Successfully";
                lblAddItemErr.Visible   = true;
                lblAddItemErr.ForeColor = Color.Green;
            }
            catch (Exception ex)
            {
                lblAddItemErr.Text      = "Error in new stock addition " + ex.InnerException.Message;
                lblAddItemErr.Visible   = true;
                lblAddItemErr.ForeColor = Color.Green;
            }
        }
        private void MaterialStock()
        {
            var MaterialID    = Convert.ToInt32(txtMaterialID.Value);
            var MaterialStore = Convert.ToInt32(txtStore.Value);
            var MaterialStock = Convert.ToDecimal(txtCurrentStock.Value);
            var newstock      = MaterialStock - Convert.ToDecimal(txtRequestedStock.Value);
            var item          = db.MaterialInStocks.Where(x => x.MaterialID == MaterialID && x.StoreID == MaterialStore).FirstOrDefault();

            item.StockOnHand -= Convert.ToDecimal(txtRequestedStock.Value);
            db.SaveChanges();

            var ss = db.MaterialInStocks.Where(x => x.MaterialID == MaterialID && x.StoreID == MaterialStore).FirstOrDefault();

            StockLogger stlog = new StockLogger();

            stlog.MaterialInStock = ss.ID;
            stlog.OldStock        = MaterialStock;
            stlog.ActionDate      = DateTime.Now;
            stlog.UserName        = User.Identity.Name;
            stlog.NewStock        = MaterialStock - Convert.ToDecimal(txtRequestedStock.Value);
            stlog.Notes           = "Order Number " + LblOrderID.Text.ToString() + "   For Customer " + Customer.SelectedItem.ToString();

            db.StockLoggers.Add(stlog);
            db.SaveChanges();

            Logger log = new Logger();

            log.Action     = " Material Order (" + item.Material.MaterialName.ToString() + " ) , The Stock changed from " + MaterialStock.ToString() + " to " + newstock.ToString() + " For Customer " + Customer.SelectedItem.ToString();
            log.ActionDate = DateTime.Now;
            log.ActionType = "Material Order";
            log.UserName   = User.Identity.Name;

            db.Loggers.Add(log);
            db.SaveChanges();

            MaterialHistory MH = new MaterialHistory();

            MH.ActionDate      = DateTime.Now;
            MH.MaterialID      = MaterialID;
            MH.StoreID         = MaterialStore;
            MH.TransactionName = "Sales Material";
            MH.UserName        = User.Identity.Name;
            MH.NewStock        = newstock;
            MH.OldStock        = MaterialStock;
            MH.Note            = "Material " + item.Material.MaterialName.ToString() + " is now invoiced in Store " + MaterialStore.ToString() + " In order ID " + LblOrderID.Text.ToString();
            db.MaterialHistories.Add(MH);
            db.SaveChanges();
        }
        private void MaterialReturn(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;
            var mat     = db.MaterialInStocks.Where(x => x.MaterialID == materialid && x.StoreID == storeid).FirstOrDefault();

            if (mat != null)
            {
                decimal oldstock = decimal.Parse(mat.StockOnHand.ToString());
                decimal newstock = oldstock + QTY;

                mat.StockOnHand = newstock;
                db.SaveChanges();

                StockLogger stlog = new StockLogger();
                stlog.ActionDate      = DateTime.Now;
                stlog.UserName        = User.Identity.Name;
                stlog.MaterialInStock = mat.ID;
                stlog.NewStock        = newstock;
                stlog.OldStock        = oldstock;
                stlog.Notes           = "Return of Good Material ( " + name + " ) In store ( " + store + " ) from Order  ( " + orderid + " )";

                db.StockLoggers.Add(stlog);
                db.SaveChanges();

                Logger log = new Logger();
                log.ActionType = "Material Return";
                log.ActionDate = DateTime.Now;
                log.UserName   = User.Identity.Name;
                log.Action     = "Return of Good List of Material ( " + name + " ) In store ( " + store + " ) from Order  ( " + orderid + " )";

                db.Loggers.Add(log);
                db.SaveChanges();

                MaterialHistory MH = new MaterialHistory();
                MH.ActionDate      = DateTime.Now;
                MH.MaterialID      = materialid;
                MH.StoreID         = storeid;
                MH.TransactionName = "Return Material";
                MH.UserName        = User.Identity.Name;
                MH.NewStock        = newstock;
                MH.OldStock        = oldstock;
                MH.Note            = "Material ( " + name + " ) is now returned in Store ( " + storeid.ToString() + " ) From order ( " + orderid + " ) ";
                db.MaterialHistories.Add(MH);
                db.SaveChanges();
            }
        }
        private void DeadMaterialStock()
        {
            var MaterialID     = Convert.ToInt32(txtMaterialID.Value);
            var MaterialStore  = Convert.ToInt32(txtStore.Value);
            var Materialheight = Convert.ToDecimal(txtitemHieght.Value);
            var MaterialWidth  = Convert.ToDecimal(txtItemWidth.Value);
            var MaterialNotes  = txtItemNotes.Value.ToString();
            var MaterialStock  = Convert.ToDecimal(txtCurrentStock.Value);

            var newstock = MaterialStock - Convert.ToDecimal(txtRequestedStock.Value);

            var item = db.DeadMaterials.Where(x => x.MaterialID == MaterialID && x.StoreID == MaterialStore && x.Height == Materialheight && x.Width == MaterialWidth && x.Notes == MaterialNotes.ToString()).FirstOrDefault();

            item.Quantity = item.Quantity - Convert.ToDecimal(txtRequestedStock.Value);
            db.SaveChanges();

            Logger log = new Logger();

            log.Action = "Dead Material (" + item.Material.MaterialName.ToString() + " ) , The Stock changed from "
                         + MaterialStock.ToString() + " to " + newstock.ToString();
            log.ActionDate = DateTime.Now;
            log.ActionType = "DeadMaterial Order";
            log.UserName   = User.Identity.Name;

            db.Loggers.Add(log);
            db.SaveChanges();

            MaterialHistory MH = new MaterialHistory();

            MH.ActionDate      = DateTime.Now;
            MH.MaterialID      = MaterialID;
            MH.StoreID         = MaterialStore;
            MH.TransactionName = "Sales DeadList";
            MH.UserName        = User.Identity.Name;
            MH.NewStock        = newstock;
            MH.OldStock        = MaterialStock;
            MH.Note            = "DeadMaterial " + item.Material.MaterialName.ToString() + " is now invoiced in Store "
                                 + MaterialStore.ToString() + "With Height " + Materialheight.ToString() + " and Width "
                                 + MaterialWidth.ToString() + " In Order ID " + LblOrderID.Text.ToString() + " In Order ID " + LblOrderID.Text.ToString();
            db.MaterialHistories.Add(MH);
            db.SaveChanges();
        }
Пример #6
0
 private void AddHistory(int materialID, int storeID, decimal newstock, Material m)
 {
     try
     {
         MaterialHistory MH = new MaterialHistory();
         MH.ActionDate      = DateTime.Now;
         MH.MaterialID      = materialID;
         MH.StoreID         = storeID;
         MH.TransactionName = "Initial Stock";
         MH.UserName        = User.Identity.Name;
         MH.NewStock        = newstock;
         MH.OldStock        = 0;
         MH.Note            = "Material " + m.MaterialName + " is now created in Store " + storeID.ToString();
         db.MaterialHistories.Add(MH);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         LblAddItemToStore.Text      = ex.InnerException.InnerException.Message;
         LblAddItemToStore.Visible   = true;
         LblAddItemToStore.ForeColor = System.Drawing.Color.Red;
     }
 }
        protected void btnUpdateMaterial_Click(object sender, EventArgs e)
        {
            var materialid = Convert.ToInt32(dsMaterials.SelectedValue);
            var storeid    = Convert.ToInt32(dsStores.SelectedValue);

            var     Ms             = db.MaterialInStocks.Where(x => x.MaterialID == materialid && x.StoreID == storeid).FirstOrDefault();
            decimal OldStock       = Convert.ToDecimal(Ms.StockOnHand.ToString());
            var     oldsafetystock = Ms.SafetyStock.ToString();
            var     oldreserved    = Ms.ReservedStock.ToString();
            decimal newstock       = Convert.ToDecimal(txtstock.Value);
            string  oldname        = Ms.Material.MaterialName.ToString();
            string  newname        = itemname.Value.ToString();
            int     oldtype        = Convert.ToInt32(Ms.Material.TypeID);
            string  oldtypename    = Ms.Material.SubCategory.SubCategoryName.ToString();
            int     newtype        = Convert.ToInt32(materialcategory.SelectedValue);

            try
            {
                Ms.ReservedStock = Convert.ToDecimal(txtReservedStock.Value);
                Ms.StockOnHand   = Convert.ToDecimal(txtstock.Value);
                Ms.SafetyStock   = Convert.ToDecimal(SafetyStock.Value);
                if (oldname != newname)
                {
                    Ms.Material.MaterialName = newname;
                }

                if (oldtype != newtype)
                {
                    Ms.Material.TypeID = newtype;
                }

                db.SaveChanges();
                dsMaterials.DataBind();
                lblError.Text      = "The Material Data Updated Successfully";
                lblError.Visible   = true;
                lblError.ForeColor = System.Drawing.Color.Green;

                StockLogger stLog = new StockLogger();
                stLog.OldStock = OldStock;
                stLog.NewStock = Convert.ToDecimal(txtstock.Value);

                stLog.OldSafetyStock = Convert.ToDecimal(oldsafetystock);
                stLog.newSafetyStock = Convert.ToDecimal(SafetyStock.Value);

                stLog.OldReservedStock = Convert.ToDecimal(oldreserved);
                stLog.NewReservedStock = Convert.ToDecimal(txtReservedStock.Value);

                stLog.UserName   = User.Identity.Name;
                stLog.ActionDate = DateTime.Now;

                stLog.MaterialInStock = Ms.ID;
                db.StockLoggers.Add(stLog);
                db.SaveChanges();


                Logger Log = new Logger();
                Log.ActionType = "Update Material";
                string Action = "Material ( " + Ms.Material.MaterialName + " ) Stock in Store ( " + Ms.Store.StoreName + " ) is ( " + txtstock.Value.ToString() + " ) And Safety Stock is ( " + SafetyStock.Value.ToString() + " ) ";
                if (oldname == newname)
                {
                    Log.Action = Action;
                }
                else
                {
                    Log.Action = Action + " and Material Name Changed From ( '" + oldname + "' ) To ( '" + newname + "' ) ";
                }

                if (oldtype != newtype)
                {
                    Log.Action += " and Category changed from ( '" + oldtypename + "' ) To ('" + materialcategory.SelectedItem.ToString() + "') )";
                }


                Log.UserName   = User.Identity.Name;
                Log.ActionDate = DateTime.Now;
                db.Loggers.Add(Log);
                db.SaveChanges();

                if (OldStock != newstock)
                {
                    MaterialHistory MH = new MaterialHistory();
                    MH.ActionDate      = DateTime.Now;
                    MH.MaterialID      = materialid;
                    MH.StoreID         = storeid;
                    MH.TransactionName = "Update Stock";
                    MH.UserName        = User.Identity.Name;
                    MH.NewStock        = Convert.ToDecimal(txtstock.Value);
                    MH.OldStock        = Convert.ToDecimal(OldStock);
                    MH.Note            = "Material ( " + Ms.Material.MaterialName + " ) Stock is now updated in Store " + Ms.Store.StoreName.ToString();
                    db.MaterialHistories.Add(MH);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                lblError.Text      = "Error in Update Material Data " + ex.Message;
                lblError.Visible   = true;
                lblError.ForeColor = System.Drawing.Color.Red;
            }
        }
Пример #8
0
        private void AddNewDeadMaterial()
        {
            decimal      QTY;
            decimal      Height;
            decimal      Width;
            DeadMaterial DM = new DeadMaterial();

            DM.StoreID    = Convert.ToInt32(SelectStores.SelectedValue);
            DM.MaterialID = Convert.ToInt32(selectitem.SelectedValue);
            DM.Notes      = DeadNote.Value;

            //Get Quantity Value
            if (Quantity.Value == "")
            {
                QTY = 0;
            }
            else
            {
                QTY = Convert.ToDecimal(Quantity.Value);
            }
            DM.Quantity = QTY;

            //Get Height Value
            if (Sheight.Value == "")
            {
                Height = 0;
            }
            else
            {
                Height = Convert.ToDecimal(Sheight.Value);
            }
            DM.Height = Height;

            //Get Width Value
            if (SWidth.Value == "")
            {
                Width = 0;
            }
            else
            {
                Width = Convert.ToDecimal(SWidth.Value);
            }
            DM.Width = Width;

            DM.UnitID     = Convert.ToInt32(itemunit.SelectedValue);
            DM.UserName   = User.Identity.Name.ToString();
            DM.ActionDate = DateTime.Now;
            DM.IsActive   = true;

            db.DeadMaterials.Add(DM);
            db.SaveChanges();

            MaterialHistory MH = new MaterialHistory();

            MH.ActionDate      = DateTime.Now;
            MH.UserName        = User.Identity.Name;
            MH.TransactionName = "New DeadMaterial";
            MH.OldStock        = 0;
            MH.NewStock        = Convert.ToDecimal(Quantity.Value);
            MH.Note            = "New Dead Material With Height " + Height.ToString() + " And Width " + Width.ToString();
            MH.MaterialID      = Convert.ToInt32(selectitem.SelectedValue);
            MH.StoreID         = Convert.ToInt32(SelectStores.SelectedValue);
            db.MaterialHistories.Add(MH);
            db.SaveChanges();

            Logger log = new Logger();

            log.UserName = User.Identity.Name;
            log.Action   = @"New Dead Material 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 DeadMaterial";
            log.ActionDate = DateTime.Now;
            db.Loggers.Add(log);
            db.SaveChanges();

            LblError.Text      = "New Dead Material is added Successfully";
            LblError.Visible   = true;
            LblError.ForeColor = System.Drawing.Color.Green;

            Quantity.Value = "";
            Sheight.Value  = "";
            SWidth.Value   = "";
            DeadNote.Value = "";
            //selectitem.SelectedIndex = 0;
            //SelectStores.SelectedIndex = 0;
            //itemunit.SelectedIndex = 0;
        }
Пример #9
0
        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();
        }
Пример #10
0
        private void MaterialStock()
        {
            var MaterialID    = Convert.ToInt32(txtMaterialID.Value);
            var StoreFrom     = Convert.ToInt32(FromStore.SelectedValue);
            var MaterialStock = Convert.ToDecimal(txtCurrentStock.Value);
            var store2        = Convert.ToInt32(ToStore.SelectedValue);
            //Update Current Stock Of From Store
            var item      = db.MaterialInStocks.Where(x => x.MaterialID == MaterialID && x.StoreID == StoreFrom).FirstOrDefault();
            var stock1    = item.StockOnHand;
            var newstock1 = item.StockOnHand - Convert.ToDecimal(txtRequestedStock.Value);

            item.StockOnHand -= Convert.ToDecimal(txtRequestedStock.Value);
            db.SaveChanges();

            StockLogger stlog = new StockLogger();

            stlog.MaterialInStock = item.ID;
            stlog.OldStock        = stock1;
            stlog.NewStock        = newstock1;
            stlog.UserName        = User.Identity.Name;
            stlog.ActionDate      = DateTime.Now;
            stlog.Notes           = "Transfer Number " + LblTransferID.Text.ToString() + " From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            db.StockLoggers.Add(stlog);

            Logger log2 = new Logger();

            log2.Action = "Transfer Number ( " + LblTransferID.Text + " ) of  Material (" + item.Material.MaterialName.ToString() + " ) , The Stock changed from ( "
                          + stock1.ToString() + " ) to ( " + newstock1.ToString() + " ) From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            log2.ActionDate = DateTime.Now;
            log2.ActionType = "Material Transfer";
            log2.UserName   = User.Identity.Name;

            db.Loggers.Add(log2);
            db.SaveChanges();

            MaterialHistory MH = new MaterialHistory();

            MH.MaterialID      = MaterialID;
            MH.StoreID         = Convert.ToInt32(FromStore.SelectedValue);
            MH.OldStock        = stock1;
            MH.NewStock        = newstock1;
            MH.ActionDate      = DateTime.Now;
            MH.UserName        = User.Identity.Name;
            MH.Note            = " Material Transfer No ( " + LblTransferID.Text.ToString() + " ) From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            MH.TransactionName = "Material Transfer";
            db.MaterialHistories.Add(MH);
            db.SaveChanges();

            //To Store Actions

            var itemstore2  = db.MaterialInStocks.Where(x => x.MaterialID == MaterialID && x.StoreID == store2).FirstOrDefault();
            var storestock  = itemstore2.StockOnHand;
            var storestock2 = storestock + Convert.ToDecimal(txtRequestedStock.Value);

            itemstore2.StockOnHand = storestock2;
            db.SaveChanges();

            //stockLogger
            StockLogger stlog2 = new StockLogger();

            stlog2.MaterialInStock = itemstore2.ID;
            stlog2.OldStock        = storestock;
            stlog2.NewStock        = storestock2;
            stlog2.UserName        = User.Identity.Name;
            stlog2.ActionDate      = DateTime.Now;
            stlog2.Notes           = "Transfer Number " + LblTransferID.Text.ToString() + " From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            db.StockLoggers.Add(stlog2);
            db.SaveChanges();


            //Insert Logger
            Logger log = new Logger();

            log.Action = "Transfer Number ( " + LblTransferID.Text + " ) of  Material (" + item.Material.MaterialName.ToString() + " ) , The Stock changed from "
                         + storestock.ToString() + " to " + storestock2.ToString() + " From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            log.ActionDate = DateTime.Now;
            log.ActionType = "Material Transfer";
            log.UserName   = User.Identity.Name;

            db.Loggers.Add(log);
            db.SaveChanges();


            MaterialHistory MH2 = new MaterialHistory();

            MH2.MaterialID      = MaterialID;
            MH2.StoreID         = Convert.ToInt32(ToStore.SelectedValue);
            MH2.OldStock        = storestock;
            MH2.NewStock        = storestock2;
            MH2.ActionDate      = DateTime.Now;
            MH2.UserName        = User.Identity.Name;
            MH2.Note            = " Material Transfer No ( " + LblTransferID.Text.ToString() + " ) From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            MH2.TransactionName = "Material Transfer";
            db.MaterialHistories.Add(MH2);
            db.SaveChanges();
        }
        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();
            }
        }