コード例 #1
0
        public ActionResult Add(BeltTransfer model, string name)
        {
            if (!((model.LotQuantity != null) && ((float)model.LotQuantity > 0)))
            {
                ModelState.AddModelError("LotQuantity", "Некорректный вес - должен быть больше нуля");
            }

            if (ModelState.IsValid)
            {
                var lastTransfer = _cdb.InternalTransfers.Where(x => x.EquipID == model.EquipID).Where(x => x.IsValid)
                                   .OrderByDescending(x => x.TransferTimeStamp).Take(1).FirstOrDefault();
                if (lastTransfer != null)
                {
                    model.TotalQuantity = lastTransfer.TotalQuantity - lastTransfer.LotQuantity + model.LotQuantity;
                }
                else
                {
                    model.TotalQuantity = model.LotQuantity;
                }

                model.LasEditDateTime = DateTime.Now;
                model.IsValid         = false;
                model.Status          = 1;
                model.OperatorName    = User.Identity.Name;
                _cdb.InternalTransfers.Add(model);
                _cdb.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.Name   = name;
            @ViewBag.Title = "Ввод данных конвейерных весов";
            return(View("Add", model));
        }
コード例 #2
0
        public ActionResult Add(int?scaleId, string name)
        {
            if (scaleId == null)
            {
                return(HttpNotFound());
            }
            string userName = User.Identity.Name ?? "";
            var    model    = new BeltTransfer();

            model.EquipID           = scaleId;
            model.LasEditDateTime   = DateTime.Now;
            model.TransferTimeStamp = System.DateTime.Now;
            if (model.Equip != null)
            {
                model.LotName = model.Equip.Name.ToString() + "-" + DateTime.Now.ToString("yyMMddHHmmss");
            }
            model.ID = "B" + scaleId + (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

            ViewBag.Name   = name;
            @ViewBag.Title = "Ввод данных конвейерных весов";
            return(View("Add", model));
        }
コード例 #3
0
        public ActionResult Edit(BeltTransfer model)
        {
            if (!((model.LotQuantity != null) && ((float)model.LotQuantity > 0)))
            {
                ModelState.AddModelError("LotQuantity", "Некорректный вес - должен быть больше нуля");
            }

            if (ModelState.IsValid)
            {
                BeltTransfer transfer = _cdb.InternalTransfers.Find(model.ID);
                if (transfer == null)
                {
                    transfer = _cdb.InternalTransfers.Find(model.ID);
                }
                transfer.IsValid           = true;
                transfer.Status            = 3;
                transfer.LasEditDateTime   = DateTime.Now;
                transfer.OperatorName      = User.Identity.Name;
                _cdb.Entry(transfer).State = EntityState.Modified;
                _cdb.SaveChanges();

                model.InheritedFrom = model.ID;
                model.ID            = "B" + model.EquipID + (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                model.OperatorName  = User.Identity.Name;
                string name = Request.UserHostName;
                model.LasEditDateTime = DateTime.Now;
                model.IsValid         = false;
                model.Status          = 2;
                model.TotalQuantity   = transfer.TotalQuantity - transfer.LotQuantity + model.LotQuantity;
                _cdb.InternalTransfers.Add(model);
                _cdb.SaveChanges();

                return(RedirectToAction("Index"));
            }

            @ViewBag.Title = "Редактирование данных конвейерных весов";
            return(View("Edit", model));
        }
コード例 #4
0
ファイル: Emulator.cs プロジェクト: princess555/CTS_Github
        public static void beltTransfersEmul(int qntFrom, int qntTo)
        {
            try
            {
                BeltTransfer transfer = new BeltTransfer();

                transfer.EquipID = ldb.BeltScales.ToList()[rnd.Next(1, ldb.BeltScales.Count())].ID;

                transfer.ID = "B" + transfer.EquipID + (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                var scale = ldb.BeltScales.Where(x => x.ID == transfer.EquipID).ToList();
                transfer.LotName           = scale[0].Name + "-" + DateTime.Now.ToString("yyMMddHHmmss");
                transfer.LotQuantity       = rnd.Next(qntFrom, qntTo);
                transfer.TransferTimeStamp = DateTime.Now;
                transfer.LasEditDateTime   = DateTime.Now;
                transfer.IsValid           = true;
                transfer.OperatorName      = "emulator";

                ldb.BeltTransfers.Add(transfer);
                ldb.SaveChanges();
            }
            catch (Exception ex)
            {
            }
        }