Beispiel #1
0
        public void DeleteMoveBillDetail(MoveBillMaster moveBillMaster)
        {
            if (moveBillMaster != null)
            {
                var sourceStorages = moveBillMaster.MoveBillDetails.Select(m => m.OutStorage).ToArray();
                var targetStorages = moveBillMaster.MoveBillDetails.Select(m => m.InStorage).ToArray();

                if (Locker.Lock(sourceStorages) && Locker.Lock(targetStorages))
                {
                    moveBillMaster.MoveBillDetails.AsParallel().ForAll(
                        (Action <MoveBillDetail>) delegate(MoveBillDetail m)
                    {
                        if (m.InStorage.ProductCode == m.ProductCode &&
                            m.OutStorage.ProductCode == m.ProductCode &&
                            m.InStorage.InFrozenQuantity >= m.RealQuantity &&
                            m.OutStorage.OutFrozenQuantity >= m.RealQuantity)
                        {
                            m.InStorage.InFrozenQuantity   -= m.RealQuantity;
                            m.OutStorage.OutFrozenQuantity -= m.RealQuantity;
                            m.InStorage.LockTag             = string.Empty;
                            m.OutStorage.LockTag            = string.Empty;
                        }
                        else
                        {
                            throw new Exception("储位的卷烟或入库冻结量与当前分配不符,信息可能被异常修改,不能删除移库单!");
                        }
                    }
                        );

                    Locker.UnLock(sourceStorages);
                    Locker.UnLock(targetStorages);
                }
                else
                {
                    throw new Exception("锁定储位失败,其他人可能正在操作,请稍候重试!");
                }

                MoveBillDetailRepository.Delete(moveBillMaster.MoveBillDetails.ToArray());
                //MoveBillDetailRepository.GetObjectSet()
                //    .DeleteEntity(m => m.BillNo == moveBillMaster.BillNo);

                MoveBillDetailRepository.SaveChanges();
            }
        }
        /// <summary>
        /// 删除移库细单
        /// </summary>
        /// <param name="ID">移库细单ID</param>
        /// <returns></returns>
        public bool Delete(string ID, out string strResult)
        {
            bool result = false;
            IQueryable <MoveBillDetail> moveBillDetailQuery = MoveBillDetailRepository.GetQueryable();
            int intID      = Convert.ToInt32(ID);
            var mbd        = moveBillDetailQuery.FirstOrDefault(i => i.ID == intID);
            var outStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.OutStorageCode);
            var inStorage  = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.InStorageCode);
            var product    = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == mbd.ProductCode);
            var unit       = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == mbd.UnitCode);

            try
            {
                if (Locker.LockStorage(outStorage, product) != null)
                {
                    if (Locker.LockStorage(inStorage, product) != null)
                    {
                        outStorage.OutFrozenQuantity -= mbd.RealQuantity;
                        inStorage.InFrozenQuantity   -= mbd.RealQuantity;
                        MoveBillDetailRepository.Delete(mbd);
                        MoveBillDetailRepository.SaveChanges();
                        result = true;
                    }
                    else
                    {
                        resultStr = "加锁移入库存失败,当前库存已有人在操作!";
                    }
                }
                else
                {
                    resultStr = "加锁移出库存失败,当前库存已有人在操作!";
                }
            }
            catch (Exception ex)
            {
                resultStr = ex.ToString();
            }
            strResult = resultStr;
            return(result);
        }