Beispiel #1
0
 public ActionResult CellCreate(Cell cell)
 {
     string errorInfo = string.Empty;
     bool bResult = CellService.Add(cell, out errorInfo);
     string msg = bResult ? "新增成功" : "新增失败";
     return Json(JsonMessageHelper.getJsonMessage(bResult, msg, errorInfo), "text", JsonRequestBehavior.AllowGet);
 }
Beispiel #2
0
 public Storage LockBar(Cell cell, Product product)
 {
     Storage storage = null;
     if (Lock(cell))
     {
         try
         {
             if (cell.Storages.Count == 1)
             {
                 storage = cell.Storages.Where(s => s.ProductCode == product.ProductCode
                                                 || string.IsNullOrEmpty(s.ProductCode))
                                        .FirstOrDefault();
                 if (storage != null)
                 {
                     if (string.IsNullOrEmpty(storage.LockTag)) { storage.LockTag = this.LockKey; }
                     else storage = null;
                 }
             }
             else if (cell.Storages.Count == 0)
             {
                 storage = new Storage()
                 {
                     Cell = cell,
                     StorageCode = Guid.NewGuid().ToString(),
                     CellCode = cell.CellCode,
                     IsLock = "0",
                     LockTag = this.LockKey,
                     IsActive = "0",
                     StorageTime = DateTime.Now,
                     UpdateTime = DateTime.Now
                 };
                 cell.Storages.Add(storage);
             }
             StorageRepository.SaveChanges();
         }
         catch (Exception)
         {
             if (storage != null) { StorageRepository.Detach(storage); }
             storage = null;
         }
     }
     UnLock(cell);
     return storage;
 }
Beispiel #3
0
 public bool Lock(Cell[] cells)
 {
     if (cells.All(c => string.IsNullOrEmpty(c.LockTag)))
     {
         try
         {
             cells.AsParallel().ForAll(c => c.LockTag = this.LockKey);
             StorageRepository.SaveChanges();
             return true;
         }
         catch (Exception)
         {
             return false;
         }
     }
     else
     {
         return false;
     }
 }
Beispiel #4
0
        private void MoveToPieceArea(MoveBillMaster moveBillMaster, Storage sourceStorage, Cell[] cc)
        {
            var cells = cc.Where(c => c.DefaultProductCode == sourceStorage.ProductCode
                                      || (c.Storages.Any()
                                         && c.Storages.FirstOrDefault().ProductCode == sourceStorage.ProductCode));
            foreach (var c in cells)
            {
                lock (c)
                {
                    var targetStorage = Locker.LockStorage(c);
                    if (sourceStorage != null && targetStorage != null
                        && (string.IsNullOrEmpty(targetStorage.ProductCode)
                            || targetStorage.ProductCode == sourceStorage.ProductCode
                            || (targetStorage.Quantity == 0
                                && targetStorage.InFrozenQuantity == 0)))
                    {
                        decimal moveQuantity = Math.Floor((sourceStorage.Quantity - sourceStorage.OutFrozenQuantity)
                                                    / sourceStorage.Product.Unit.Count)
                                                   * sourceStorage.Product.Unit.Count;
                        moveQuantity = moveQuantity % (targetStorage.Cell.MaxQuantity * sourceStorage.Product.Unit.Count);
                        decimal targetAbleQuantity = Math.Floor((targetStorage.Cell.MaxQuantity
                                                        * sourceStorage.Product.Unit.Count
                                                        - targetStorage.Quantity
                                                        - targetStorage.InFrozenQuantity
                                                        + targetStorage.OutFrozenQuantity) / sourceStorage.Product.Unit.Count)
                                                        * sourceStorage.Product.Unit.Count;
                        moveQuantity = moveQuantity <= targetAbleQuantity ? moveQuantity : targetAbleQuantity;
                        AddToMoveBillDetail(moveBillMaster, sourceStorage, targetStorage, moveQuantity,"1");
                    }

                    if (targetStorage != null)
                    {
                        targetStorage.LockTag = string.Empty;
                    }
                }
            }

            cells = cc.Where(c => string.IsNullOrEmpty(c.DefaultProductCode));

            foreach (var c in cells)
            {
                lock (c)
                {
                    var targetStorage = Locker.LockStorage(c);
                    if (sourceStorage != null && targetStorage != null
                        && (string.IsNullOrEmpty(targetStorage.ProductCode)
                            || targetStorage.ProductCode == sourceStorage.ProductCode
                            || (targetStorage.Quantity == 0
                                && targetStorage.InFrozenQuantity == 0)))
                    {
                        decimal moveQuantity = Math.Floor((sourceStorage.Quantity - sourceStorage.OutFrozenQuantity)
                                                    / sourceStorage.Product.Unit.Count)
                                                   * sourceStorage.Product.Unit.Count;
                        moveQuantity = moveQuantity % (targetStorage.Cell.MaxQuantity * sourceStorage.Product.Unit.Count);
                        decimal targetAbleQuantity = Math.Floor((c.MaxQuantity
                                                        * sourceStorage.Product.Unit.Count
                                                        - targetStorage.Quantity
                                                        - targetStorage.InFrozenQuantity
                                                        + targetStorage.OutFrozenQuantity)/sourceStorage.Product.Unit.Count)
                                                        * sourceStorage.Product.Unit.Count;
                        moveQuantity = moveQuantity <= targetAbleQuantity ? moveQuantity : targetAbleQuantity;
                        AddToMoveBillDetail(moveBillMaster, sourceStorage, targetStorage, moveQuantity,"1");
                    }
                    if (targetStorage != null)
                    {
                        targetStorage.LockTag = string.Empty;
                    }
                }
            }
        }
Beispiel #5
0
        private void MoveToBarArea(MoveBillMaster moveBillMaster, Storage sourceStorage, Cell[] cc)
        {
            var cells = cc.Where(c => c.DefaultProductCode == sourceStorage.ProductCode
                                      || (c.Storages.Any()
                                         && c.Storages.FirstOrDefault().ProductCode == sourceStorage.ProductCode));
            foreach (var c in cells)
            {
                lock (c)
                {
                    var targetStorage = Locker.LockStorage(c);
                    if (sourceStorage != null && targetStorage != null
                        && (string.IsNullOrEmpty(targetStorage.ProductCode)
                            || targetStorage.ProductCode == sourceStorage.ProductCode
                            || (targetStorage.Quantity == 0
                                && targetStorage.InFrozenQuantity == 0)))
                    {
                        decimal moveQuantity = (sourceStorage.Quantity - sourceStorage.OutFrozenQuantity) % sourceStorage.Product.Unit.Count;
                        AddToMoveBillDetail(moveBillMaster, sourceStorage, targetStorage, moveQuantity,"1");
                    }

                    if (targetStorage != null)
                    {
                        targetStorage.LockTag = string.Empty;
                    }
                }
            }

            cells = cc.Where(c => string.IsNullOrEmpty(c.DefaultProductCode));

            foreach (var c in cells)
            {
                lock (c)
                {
                    var targetStorage = Locker.LockStorage(c);
                    if (sourceStorage != null && targetStorage != null
                        && (string.IsNullOrEmpty(targetStorage.ProductCode)
                            || targetStorage.ProductCode == sourceStorage.ProductCode
                            || (targetStorage.Quantity == 0
                                && targetStorage.InFrozenQuantity == 0)))
                    {
                        decimal moveQuantity = (sourceStorage.Quantity - sourceStorage.OutFrozenQuantity) % sourceStorage.Product.Unit.Count;
                        AddToMoveBillDetail(moveBillMaster, sourceStorage, targetStorage, moveQuantity,"1");
                    }
                    if (targetStorage != null)
                    {
                        targetStorage.LockTag = string.Empty;
                    }
                }
            }
        }
Beispiel #6
0
 private void UnLock(Cell cell)
 {
     try
     {
         cell.LockTag = string.Empty;
         CellRepository.SaveChanges();
     }
     catch (Exception)
     {
         CellRepository.Detach(cell);
     }
 }
Beispiel #7
0
        private bool Lock(Cell cell)
        {
            try
            {
                if (string.IsNullOrEmpty(cell.LockTag))
                {
                    cell.LockTag = this.LockKey;
                    CellRepository.SaveChanges();
                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception)
            {
                CellRepository.Detach(cell);
                return false;
            }
        }
Beispiel #8
0
 public void UnLock(Cell[] cells)
 {
     try
     {
         cells.AsParallel().ForAll(c => c.LockTag = string.Empty);
         CellRepository.SaveChanges();
     }
     catch (Exception)
     {
         return;
     }
 }
Beispiel #9
0
        /// <summary>
        /// 用于选择可入库目标库存记录
        /// </summary>
        /// <param name="cell">目标储位</param>
        /// <returns>目标储位上可入库的库存记录</returns>
        public Storage LockStorage(Cell cell)
        {
            try
            {
                if (string.IsNullOrEmpty(cell.LockTag))
                {
                    Storage storage = null;
                    if (cell.Storages.Any())
                    {
                        if (cell.IsSingle == "1")
                        {
                            storage = cell.Storages.Single();
                            if (string.IsNullOrEmpty(storage.LockTag))
                            {
                                return storage;
                            }
                            else
                                return null;
                        }
                        else
                        {
                            storage = cell.Storages.FirstOrDefault(s=>string.IsNullOrEmpty(s.LockTag)
                                                                      && s.Quantity == 0
                                                                      && s.InFrozenQuantity == 0);

                            if (storage != null)
                            {
                                return storage;
                            }
                            else if (cell.Storages.Count < cell.MaxPalletQuantity)
                            {
                                storage = new Storage()
                                {
                                    Cell = cell,
                                    StorageCode = Guid.NewGuid().ToString(),
                                    CellCode = cell.CellCode,
                                    IsLock = "0",
                                    IsActive = "0",
                                    StorageTime = DateTime.Now,
                                    UpdateTime = DateTime.Now
                                };
                                lock (cell.Storages)
                                {
                                    cell.Storages.Add(storage);
                                }
                                return storage;
                            }
                            else
                                return null;
                        }
                    }
                    else
                    {
                        storage = new Storage()
                        {
                            Cell = cell,
                            StorageCode = Guid.NewGuid().ToString(),
                            CellCode = cell.CellCode,
                            IsLock = "0",
                            IsActive = "0",
                            StorageTime = DateTime.Now,
                            UpdateTime = DateTime.Now
                        };
                        lock (cell.Storages)
                        {
                            cell.Storages.Add(storage);
                        }
                        return storage;
                    }
                }
                else
                    return null;
            }
            catch (Exception)
            {
                return null;
            }
        }
Beispiel #10
0
 public Storage LockNoEmpty(Cell cell,Product product)
 {
     Storage storage = null;
     if (Lock(cell))
     {
         try
         {
             storage = cell.Storages.Where(s => s.ProductCode == product.ProductCode
                                           && s.Quantity - s.OutFrozenQuantity > 0)
                                    .FirstOrDefault();
             if (storage != null)
             {
                 storage.LockTag = this.LockKey;
                 StorageRepository.SaveChanges();
             }
         }
         catch (Exception)
         {
             if (storage != null) { StorageRepository.Detach(storage); }
             storage = null;
         }
     }
     UnLock(cell);
     return storage;
 }
Beispiel #11
0
 public Storage LockEmpty(Cell cell)
 {
     Storage storage = null;
     if (Lock(cell))
     {
         try
         {
             if (cell.IsSingle == "1")
             {
                 if (cell.Storages.Count == 0)
                 {
                     storage = new Storage()
                     {
                         Cell = cell,
                         StorageCode = Guid.NewGuid().ToString(),
                         CellCode = cell.CellCode,
                         IsLock = "0",
                         LockTag = this.LockKey,
                         IsActive = "0",
                         StorageTime = DateTime.Now,
                         UpdateTime = DateTime.Now
                     };
                     cell.Storages.Add(storage);
                 }
                 else if (cell.Storages.Count == 1)
                 {
                     storage = cell.Storages.Where(s => string.IsNullOrEmpty(s.LockTag)
                                                   && s.Quantity == 0
                                                   && s.InFrozenQuantity == 0)
                                            .FirstOrDefault();
                     if (storage!=null) { storage.LockTag = this.LockKey; }
                 }
             }
             else
             {
                 storage = cell.Storages.Where(s => string.IsNullOrEmpty(s.LockTag)
                                             && s.Quantity == 0
                                             && s.InFrozenQuantity == 0)
                                        .FirstOrDefault();
                 if (storage != null)
                 {
                     storage.LockTag = this.LockKey;
                 }
                 else
                 {
                     storage = new Storage()
                     {
                         StorageCode = Guid.NewGuid().ToString(),
                         CellCode = cell.CellCode,
                         IsLock = "0",
                         LockTag = this.LockKey,
                         IsActive = "0",
                         StorageTime = DateTime.Now,
                         UpdateTime = DateTime.Now
                     };
                     cell.Storages.Add(storage);
                 }
             }
             StorageRepository.SaveChanges();
         }
         catch (Exception)
         {
             if (storage != null) { StorageRepository.Detach(storage); }
             storage = null;
         }
     }
     UnLock(cell);
     return storage;
 }
Beispiel #12
0
 //编辑货位表
 // GET: /Cell/Edit/
 public ActionResult Edit(Cell cell)
 {
     bool bResult = CellService.Save(cell);
     string msg = bResult ? "修改成功" : "修改失败";
     return Json(JsonMessageHelper.getJsonMessage(bResult, msg, null), "text", JsonRequestBehavior.AllowGet);
 }
Beispiel #13
0
 public Storage LockPiece(Cell cell, Product product)
 {
     Storage storage = null;
     if (Lock(cell))
     {
         try
         {
             if (cell.Storages.Count == 1)
             {
                 storage = cell.Storages.Where(s => (s.ProductCode == product.ProductCode
                                                     && (s.Cell.MaxQuantity * product.Unit.Count
                                                         - s.Quantity - s.InFrozenQuantity
                                                         + s.OutFrozenQuantity) > 0)
                                                 || string.IsNullOrEmpty(s.ProductCode)
                                                 || (s.Quantity == 0 && s.InFrozenQuantity == 0))
                                        .FirstOrDefault();
                 if (storage != null) {
                     if (string.IsNullOrEmpty(storage.LockTag)){storage.LockTag = this.LockKey;}
                     else storage = null;
                 }
             }
             else if (cell.Storages.Count == 0)
             {
                 storage = new Storage()
                 {
                     Cell=cell,
                     StorageCode = Guid.NewGuid().ToString(),
                     CellCode = cell.CellCode,
                     IsLock = "0",
                     LockTag = this.LockKey,
                     IsActive = "1",
                     StorageTime = DateTime.Now,
                     UpdateTime = DateTime.Now
                 };
                 cell.Storages.Add(storage);
             }
             StorageRepository.SaveChanges();
         }
         catch (Exception)
         {
             if (storage != null) { StorageRepository.Detach(storage); }
             storage = null;
         }
     }
     UnLock(cell);
     return storage;
 }
Beispiel #14
0
 public ActionResult CellCreate(Cell cell)
 {
     bool bResult = CellService.Add(cell);
     string msg = bResult ? "新增成功" : "新增失败";
     return Json(JsonMessageHelper.getJsonMessage(bResult, msg, null), "text", JsonRequestBehavior.AllowGet);
 }