Пример #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();
            }
        }