Beispiel #1
0
 public bool Lock(Storage[] storages)
 {
     if (storages.All(s => string.IsNullOrEmpty(s.LockTag) || s.LockTag == this.LockKey))
     {
         storages.AsParallel().ForAll(s => s.LockTag = this.LockKey);
         StorageRepository.SaveChanges();
         return true;
     }
     else
     {
         return false;
     }
 }
 public void AddToMoveBillDetail(MoveBillMaster moveBillMaster, Storage sourceStorage, Storage targetStorage, decimal moveQuantity)
 {
     if (moveQuantity > 0)
     {
         Locker.LockKey = moveBillMaster.BillNo;
         MoveBillDetail detail = new MoveBillDetail();
         detail.BillNo = moveBillMaster.BillNo;
         detail.ProductCode = sourceStorage.ProductCode;
         detail.OutCellCode = sourceStorage.CellCode;
         detail.OutStorageCode = sourceStorage.StorageCode;
         detail.InCellCode = targetStorage.CellCode;
         detail.InStorageCode = targetStorage.StorageCode;
         detail.UnitCode = sourceStorage.Product.UnitCode;
         detail.RealQuantity = moveQuantity;
         detail.Status = "0";
         moveBillMaster.MoveBillDetails.Add(detail);
         sourceStorage.OutFrozenQuantity += moveQuantity;
         targetStorage.ProductCode = sourceStorage.ProductCode;
         targetStorage.InFrozenQuantity += moveQuantity;
     }
 }
Beispiel #3
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 #4
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 #5
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 #6
0
 /// <summary>
 /// 解锁当前锁锁定的库存记录
 /// </summary>
 /// <param name="storage"></param>
 public void UnLockStorage(Storage storage)
 {
     if (storage.LockTag == this.LockKey)
     {
         storage.LockTag = string.Empty;
     }
 }
Beispiel #7
0
 public void UnLock(Storage[] storages)
 {
     try
     {
         storages.AsParallel().ForAll(s => s.LockTag = string.Empty);
         StorageRepository.SaveChanges();
     }
     catch (Exception)
     {
         return;
     }
 }
Beispiel #8
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 #9
0
 public Storage LockStorage(Storage storage, Product product)
 {
     var cell = storage.Cell;
     if (Lock(cell))
     {
         if (string.IsNullOrEmpty(storage.LockTag) && storage.ProductCode == product.ProductCode)
         {
             try
             {
                 storage.LockTag = this.LockKey;
                 StorageRepository.SaveChanges();
             }
             catch (Exception)
             {
                 if (storage != null) { StorageRepository.Detach(storage); }
                 storage = null;
             }
         }
         else
         {
             storage = null;
         }
     }
     else
     {
         storage = null;
     }
     UnLock(cell);
     return storage;
 }
Beispiel #10
0
 /// <summary>
 /// 用于选择可出库目标库存记录
 /// </summary>
 /// <param name="storage">目标库存记录</param>
 /// <param name="product">要出库的产品</param>
 /// <returns>可出库的库存记录</returns>
 public Storage LockNoEmptyStorage(Storage storage, Product product)
 {
     try
     {
         if (storage != null
             && string.IsNullOrEmpty(storage.LockTag)
             && storage.ProductCode == product.ProductCode
             && storage.Quantity - storage.OutFrozenQuantity > 0)
         {
             return storage;
         }
         else
             return null;
     }
     catch (Exception)
     {
         return null;
     }
 }
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
        public bool CreateNewTaskForEmptyPalletStack(int positionID)
        {
            string palletCode = "";
            int palletCount = 10;
            var position = PositionRepository.GetQueryable()
                .Where(i=>i.ID == positionID).FirstOrDefault();

            if (position != null)
            {
                var positionQuery = PositionRepository.GetQueryable()
                    .Where(i => i.SRMName == position.SRMName
                        && i.AbleStockInPallet && i.ID != positionID);
                var cellPositionQuery = CellPositionRepository.GetQueryable()
                    .Where(i => i.StockOutPositionID != positionID
                        && positionQuery.Contains(i.StockInPosition));
                var cellQuery = CellRepository.GetQueryable()
                    .Where(i => i.IsSingle == "1"
                        && cellPositionQuery.Any(p => p.CellCode == i.CellCode)
                        && (i.Storages.Count == 0
                            || i.Storages.Any(s => string.IsNullOrEmpty(s.LockTag)
                                && s.Quantity == 0
                                && s.InFrozenQuantity == 0)
                            || i.Storages.Any(s => s.ProductCode == palletCode
                                && s.Quantity + s.InFrozenQuantity < palletCount)));

                var cell = cellQuery.FirstOrDefault();
                if (cell != null)
                {
                    var cellPosition = CellPositionRepository.GetQueryable()
                        .Where(cp => cp.CellCode == cell.CellCode).FirstOrDefault();
                    if (!cell.Storages.Any())
                    {
                        var 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);
                        }
                    }
                    var targetStorage = cell.Storages.FirstOrDefault();
                    if (targetStorage != null && cellPosition != null)
                    {
                        targetStorage.InFrozenQuantity += 1;
                        var newTask = new Task();
                        newTask.TaskType = "01";
                        newTask.TaskLevel = 0;
                        //newTask.PathID = path.ID;
                        newTask.ProductCode = palletCode;
                        newTask.ProductName = "空托盘";
                        //newTask.OriginStorageCode = inItem.CellCode;
                        newTask.TargetStorageCode = cell.CellCode;
                        newTask.OriginPositionID = positionID;
                        newTask.TargetPositionID = cellPosition.StockInPositionID;
                        newTask.CurrentPositionID = positionID;
                        newTask.CurrentPositionState = "02";
                        newTask.State = "01";
                        newTask.TagState = "01";//拟不使用
                        newTask.Quantity = 1;
                        newTask.TaskQuantity = 1;
                        newTask.OperateQuantity = 0;
                        //newTask.OrderID = inItem.BillNo;
                        //newTask.OrderType = "01";
                        //newTask.AllotID = inItem.ID;
                        newTask.DownloadState = "1";
                        TaskRepository.Add(newTask);
                        TaskRepository.SaveChanges();
                        return true;
                    }
                }
            }
            return false;
        }
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;
 }