예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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    = "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);
        }
예제 #4
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    = "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);
        }
예제 #5
0
        /// <summary>
        /// 库存加锁
        /// </summary>
        /// <param name="billNo">订单号</param>
        /// <param name="cell">货位</param>
        /// <returns></returns>
        private Storage LockStorage(string billNo, Cell cell)
        {
            try
            {
                cell.LockTag = billNo;
                CellRepository.SaveChanges();
            }
            catch (Exception)
            {
                CellRepository.Detach(cell);
                return(null);
            }

            Storage storage = null;

            try
            {
                if (cell.IsSingle == "1")
                {
                    if (cell.Storages.Count == 0)
                    {
                        storage = new Storage()
                        {
                            StorageCode = Guid.NewGuid().ToString(),
                            CellCode    = cell.CellCode,
                            IsLock      = "0",
                            LockTag     = billNo,
                            IsActive    = "0",
                            StorageTime = DateTime.Now,
                            UpdateTime  = DateTime.Now
                        };
                        cell.Storages.Add(storage);
                    }
                    else if (cell.Storages.Count == 1)
                    {
                        storage         = cell.Storages.Single();
                        storage.LockTag = billNo;
                    }
                }
                else
                {
                    storage = cell.Storages.Where(s => s.LockTag == null || s.LockTag == string.Empty &&
                                                  s.Quantity == 0 &&
                                                  s.InFrozenQuantity == 0)
                              .FirstOrDefault();
                    if (storage != null)
                    {
                        storage.LockTag = billNo;
                    }
                    else
                    {
                        storage = new Storage()
                        {
                            StorageCode = Guid.NewGuid().ToString(),
                            CellCode    = cell.CellCode,
                            IsLock      = "0",
                            LockTag     = billNo,
                            IsActive    = "0",
                            StorageTime = DateTime.Now,
                            UpdateTime  = DateTime.Now
                        };
                        cell.Storages.Add(storage);
                    }
                }
                StorageRepository.SaveChanges();
            }
            catch (Exception)
            {
                StorageRepository.Detach(storage);
                cell.Storages.Remove(storage);
                storage = null;
            }

            cell.LockTag = string.Empty;
            CellRepository.SaveChanges();

            return(storage);
        }
예제 #6
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()
                            {
                                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);
        }