示例#1
0
 private void UnLock(Cell cell)
 {
     try
     {
         cell.LockTag = string.Empty;
         CellRepository.SaveChanges();
     }
     catch (Exception)
     {
         CellRepository.Detach(cell);
     }
 }
示例#2
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);
     }
 }
示例#3
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);
        }