Esempio n. 1
0
        private void Allot(InBillMaster billMaster, InBillDetail billDetail, Cell cell, Storage storage, decimal allotQuantity, ProgressState ps)
        {
            if (storage != null && allotQuantity > 0)
            {
                InBillAllot billAllot = null;
                billDetail.AllotQuantity += allotQuantity;
                storage.ProductCode       = billDetail.ProductCode;
                storage.LockTag           = billDetail.BillNo;
                storage.InFrozenQuantity += allotQuantity;

                billAllot = new InBillAllot()
                {
                    BillNo         = billMaster.BillNo,
                    InBillDetailId = billDetail.ID,
                    ProductCode    = billDetail.ProductCode,
                    CellCode       = cell.CellCode,
                    StorageCode    = storage.StorageCode,
                    UnitCode       = billDetail.UnitCode,
                    AllotQuantity  = allotQuantity,
                    RealQuantity   = 0,
                    Status         = "0"
                };
                billMaster.InBillAllots.Add(billAllot);

                decimal sumBillQuantity  = billMaster.InBillDetails.Sum(d => d.BillQuantity);
                decimal sumAllotQuantity = billMaster.InBillDetails.Sum(d => d.AllotQuantity);

                decimal sumBillProductQuantity = billMaster.InBillDetails.Where(d => d.ProductCode == billDetail.ProductCode)
                                                 .Sum(d => d.BillQuantity);
                decimal sumAllotProductQuantity = billMaster.InBillDetails.Where(d => d.ProductCode == billDetail.ProductCode)
                                                  .Sum(d => d.AllotQuantity);

                ps.State                = StateType.Processing;
                ps.TotalProgressName    = "分配入库单:" + billMaster.BillNo;
                ps.TotalProgressValue   = (int)(sumAllotQuantity / sumBillQuantity * 100);
                ps.CurrentProgressName  = "分配卷烟:" + billDetail.Product.ProductName;
                ps.CurrentProgressValue = (int)(sumAllotProductQuantity / sumBillProductQuantity * 100);
                NotifyConnection(ps.Clone());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 入库分配
        /// </summary>
        /// <param name="inBillMaster">入库主单</param>
        /// <returns></returns>
        public bool InAllot(InBillMaster inBillMaster, Guid employeeId)
        {
            try
            {
                var inBillDetails = inBillMaster.InBillDetails.ToArray();
                var cell          = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == inBillMaster.TargetCellCode);
                //入库单入库
                inBillMaster.InBillDetails.AsParallel().ForAll(
                    (Action <InBillDetail>) delegate(InBillDetail i)
                {
                    if (i.BillQuantity - i.AllotQuantity > 0)
                    {
                        Storage inStorage = null;
                        lock (cell)
                        {
                            inStorage = Locker.LockStorage(cell);
                            if (inStorage == null)
                            {
                                throw new Exception("锁定储位失败,储位其他人正在操作,无法分配请稍候重试!");
                            }
                            inStorage.LockTag = inBillMaster.BillNo;
                        }
                        if (inStorage.Quantity == 0 &&
                            inStorage.InFrozenQuantity == 0)
                        {
                            decimal allotQuantity = i.BillQuantity;
                            i.AllotQuantity      += allotQuantity;
                            i.RealQuantity       += allotQuantity;
                            inStorage.ProductCode = i.ProductCode;
                            inStorage.Quantity   += allotQuantity;
                            inStorage.LockTag     = string.Empty;

                            var billAllot = new InBillAllot()
                            {
                                BillNo         = inBillMaster.BillNo,
                                InBillDetailId = i.ID,
                                ProductCode    = i.ProductCode,
                                CellCode       = inStorage.CellCode,
                                StorageCode    = inStorage.StorageCode,
                                UnitCode       = i.UnitCode,
                                AllotQuantity  = allotQuantity,
                                RealQuantity   = allotQuantity,
                                Status         = "2"
                            };

                            lock (inBillMaster.InBillAllots)
                            {
                                inBillMaster.InBillAllots.Add(billAllot);
                            }
                        }
                        else
                        {
                            throw new Exception("储位数量不等于0,无法分配请稍候重试!");
                        }
                    }
                });
                //入库结单
                inBillMaster.Status         = "6";
                inBillMaster.VerifyDate     = DateTime.Now;
                inBillMaster.VerifyPersonID = employeeId;
                inBillMaster.UpdateTime     = DateTime.Now;
                InBillMasterRepository.SaveChanges();
                return(true);
            }
            catch (AggregateException ex)
            {
                resultStr = "审核失败,详情:" + ex.InnerExceptions.Select(i => i.Message).Aggregate((m, n) => m + n);
                return(false);
            }
        }