Ejemplo n.º 1
0
        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();

            if (item != null)
            {
                item.Quantity -= Convert.ToDecimal(txtRequestedStock.Value);
                db.SaveChanges();
            }

            DeadMaterial CS = new DeadMaterial();

            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.DeadMaterials.Add(CS);
            db.SaveChanges();


            Logger log = new Logger();

            log.Action = "Transfer Number ( " + LblTransferID.Text + " ) of Dead Material (" + item.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 = "DeadMaterial Transfer";
            log.UserName   = User.Identity.Name;


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

            MaterialHistory MH = new MaterialHistory();

            MH.ActionDate      = DateTime.Now;
            MH.MaterialID      = MaterialID;
            MH.StoreID         = Convert.ToInt32(ToStore.SelectedValue);
            MH.TransactionName = "DeadMaterial Transfer";
            MH.UserName        = User.Identity.Name;
            MH.NewStock        = Convert.ToDecimal(txtRequestedStock.Value);
            MH.OldStock        = 0;
            MH.Note            = "DeadMaterial Transfer No " + LblTransferID.Text.ToString() + " With Height " + Materialheight.ToString() + " and Width " + MaterialWidth.ToString() + " From Store " + FromStore.SelectedItem.ToString() + " To Store " + ToStore.SelectedItem.ToString();
            db.MaterialHistories.Add(MH);
            db.SaveChanges();


            MaterialHistory MH2 = new MaterialHistory();

            MH2.ActionDate      = DateTime.Now;
            MH2.MaterialID      = MaterialID;
            MH2.StoreID         = MaterialStore;
            MH2.TransactionName = "DeadMaterial Transfer";
            MH2.UserName        = User.Identity.Name;
            MH2.NewStock        = newstock;
            MH2.OldStock        = MaterialStock;
            MH2.Note            = "DeadMaterial Transfer No " + LblTransferID.Text.ToString() + " With Height " + Materialheight.ToString() + " and Width " + MaterialWidth.ToString() + " From Store " + FromStore.SelectedItem.ToString() + " To Store " + ToStore.SelectedItem.ToString();
            db.MaterialHistories.Add(MH2);
            db.SaveChanges();
        }
Ejemplo n.º 2
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;
        }
        private void DeadMaterialReturn(int materialid, string name, int orderid, decimal QTY, decimal height, decimal width, string store)
        {
            decimal oldstock, newstock;
            var     st       = db.Stores.Where(x => x.StoreName == store).FirstOrDefault();
            int     storeid  = st.ID;
            var     deaditem = db.DeadMaterials.Where(x => x.MaterialID == materialid && x.StoreID == storeid && x.Height == height && x.Width == width).FirstOrDefault();

            if (deaditem != null)
            {
                oldstock          = Convert.ToDecimal(deaditem.Quantity);
                newstock          = Convert.ToDecimal(deaditem.Quantity) + QTY;
                deaditem.Quantity = newstock;
                db.SaveChanges();

                Logger log = new Logger();
                log.Action     = "Return of Dead 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 DeadList";
                MH.UserName        = User.Identity.Name;
                MH.NewStock        = newstock;
                MH.OldStock        = oldstock;
                MH.Note            = "DeadMaterial " + name + " is now returned in Store " + storeid.ToString() + " With Height "
                                     + height.ToString() + " and Width " + width.ToString() + " from Order  ( " + orderid + " )";;
                db.MaterialHistories.Add(MH);
                db.SaveChanges();
            }
            else
            {
                DeadMaterial cs = new DeadMaterial();
                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 Dead Material ( " + name + " ) In store ( " + store + " ) from Order  ( " + orderid + " )";
                cs.ActionDate = DateTime.Now;

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

                MaterialHistory MH = new MaterialHistory();
                MH.ActionDate      = DateTime.Now;
                MH.MaterialID      = materialid;
                MH.StoreID         = storeid;
                MH.TransactionName = "Return DeadList";
                MH.UserName        = User.Identity.Name;
                MH.NewStock        = Convert.ToDecimal(QTY);
                MH.OldStock        = 0;
                MH.Note            = "DeadMaterial " + name + " is now returned in Store " + storeid.ToString() + " With Height "
                                     + height.ToString() + " and Width " + width.ToString() + " from Order  ( " + orderid + " )";;
                db.MaterialHistories.Add(MH);
                db.SaveChanges();
            }
        }