Ejemplo n.º 1
0
        public void Allot(string connectionId, Model.ProgressState ps, System.Threading.CancellationToken cancellationToken, string billNo, string[] areaCodes)
        {
            Locker.LockKey = billNo;
            ConnectionId = connectionId;
            ps.State = StateType.Start;
            NotifyConnection(ps.Clone());

            IQueryable<OutBillMaster> outBillMasterQuery = OutBillMasterRepository.GetQueryable();
            IQueryable<Cell> cellQuery = CellRepository.GetQueryable();
            IQueryable<Storage> storageQuery = StorageRepository.GetQueryable();

            OutBillMaster billMaster = outBillMasterQuery.Single(b => b.BillNo == billNo);

            if (!CheckAndLock(billMaster, ps)) { return; }

            //选择未分配的细单;
            var billDetails = billMaster.OutBillDetails.Where(b => (b.BillQuantity - b.AllotQuantity) > 0).ToArray();
            //选择当前订单操作目标仓库;
            var storages = storageQuery.Where(s => s.Cell.WarehouseCode == billMaster.WarehouseCode);
            if (areaCodes.Length > 0)
            {
                //选择指定库区;
                storages = storages.Where(s => areaCodes.Any(a => a == s.Cell.AreaCode));
            }
            else
            {
                storages = storages.Where(s => s.Cell.Area.AllotOutOrder > 0);
            }
            storages = storages.Where(s => string.IsNullOrEmpty(s.LockTag) && s.Cell.IsActive == "1"
                                            && s.Quantity - s.OutFrozenQuantity > 0);

            foreach (var billDetail in billDetails)
            {
                //1:主库区 1;2:件烟区 2;
                //3;条烟区 3;4:暂存区 4;
                //5:备货区 0;6:残烟区 0;
                //7:罚烟区 0;8:虚拟区 0;
                //9:其他区 0;

                //分配整盘;排除 件烟区 条烟区
                string[] areaTypes = new string[] { "2", "3","5" };
                var ss = storages.Where(s=>areaTypes.All(a => a != s.Cell.Area.AreaType)
                                            && s.ProductCode == billDetail.ProductCode)
                                 .OrderBy(s => new { s.Cell.Area.AllotOutOrder, s.StorageTime });
                AllotPallet(billMaster, billDetail, ss, cancellationToken, ps);

                //分配件烟;件烟区 
                areaTypes = new string[] { "2" };
                ss = storages.Where(s => areaTypes.Any(a => a == s.Cell.Area.AreaType)
                                            && s.ProductCode == billDetail.ProductCode)
                                 .OrderBy(s => new { s.Cell.Area.AllotOutOrder, s.StorageTime });
                AllotPiece(billMaster, billDetail, ss, cancellationToken, ps);

                //分配件烟 (下层储位);排除 件烟区 条烟区 
                areaTypes = new string[] { "2", "3","5" };
                ss = storages.Where(s => areaTypes.All(a => a != s.Cell.Area.AreaType)
                                            && s.ProductCode == billDetail.ProductCode
                                            && s.Cell.Layer == 1)
                                 .OrderBy(s => new {s.Cell.Area.AllotOutOrder, s.StorageTime });
                AllotPiece(billMaster, billDetail, ss, cancellationToken, ps);

                //分配件烟 (非下层储位);排除 件烟区 条烟区 
                areaTypes = new string[] { "2", "3","5" };
                ss = storages.Where(s => areaTypes.All(a => a != s.Cell.Area.AreaType)
                                            && s.ProductCode == billDetail.ProductCode
                                            && s.Cell.Layer != 1)
                                .OrderBy(s => new { s.Cell.Area.AllotOutOrder, s.StorageTime });
                AllotPiece(billMaster, billDetail, ss, cancellationToken, ps);

                //分配条烟;条烟区
                areaTypes = new string[] { "3" };
                ss = storages.Where(s => areaTypes.Any(a => a == s.Cell.Area.AreaType)
                                            && s.ProductCode == billDetail.ProductCode)
                                 .OrderBy(s => new { s.Cell.Area.AllotOutOrder, s.StorageTime });
                AllotBar(billMaster, billDetail, ss, cancellationToken, ps);

                //分配条烟;件烟区
                areaTypes = new string[] { "2" };
                ss = storages.Where(s => areaTypes.Any(a => a == s.Cell.Area.AreaType)
                                            && s.ProductCode == billDetail.ProductCode)
                                .OrderBy(s => new { s.Cell.Area.AllotOutOrder, s.StorageTime });
                AllotBar(billMaster, billDetail, ss, cancellationToken, ps);

                //分配条烟 (主库区下层);
                areaTypes = new string[] { "1" };
                ss = storages.Where(s => areaTypes.All(a => a == s.Cell.Area.AreaType)
                                            && s.ProductCode == billDetail.ProductCode
                                            && s.Cell.Layer == 1)
                                 .OrderBy(s => new { s.Cell.Area.AllotOutOrder, s.StorageTime });
                AllotBar(billMaster, billDetail, ss, cancellationToken, ps);

                //分配条烟 (主库区)
                areaTypes = new string[] { "1" };
                ss = storages.Where(s => areaTypes.All(a => a == s.Cell.Area.AreaType)
                                            && s.ProductCode == billDetail.ProductCode
                                            && s.Cell.Layer != 1)
                                 .OrderBy(s => new { s.Cell.Area.AllotOutOrder, s.StorageTime });
                AllotBar(billMaster, billDetail, ss, cancellationToken, ps);

                //分配条烟 (暂存区)
                areaTypes = new string[] { "4" };
                ss = storages.Where(s => areaTypes.All(a => a == s.Cell.Area.AreaType)
                                            && s.ProductCode == billDetail.ProductCode)
                                 .OrderBy(s => s.StorageTime)
                                 .OrderBy(s => s.Cell.Area.AllotOutOrder);
                AllotBar(billMaster, billDetail, ss, cancellationToken, ps);

                if (billDetail.BillQuantity > billDetail.AllotQuantity)
                {
                    ps.State = StateType.Warning;
                    ps.Errors.Add(billDetail.ProductCode + " " + billDetail.Product.ProductName + ",库存不足!" + "订单量:" + billDetail.BillQuantity / billDetail.Product.Unit.Count + "(件)," + "未分配量:" + (billDetail.BillQuantity - billDetail.RealQuantity) / billDetail.Product.Unit.Count + "(件)");
                }
            }

            string billno = billMaster.BillNo;
            if (billMaster.OutBillDetails.Any(i => i.BillQuantity - i.AllotQuantity > 0))
            {
                ps.State = StateType.Warning;
                ps.Errors.Add("分配未全部完成,没有储位可分配!");
                NotifyConnection(ps.Clone());

                OutBillMasterRepository.GetObjectSet()
                    .UpdateEntity(i => i.BillNo == billno,
                    i => new OutBillMaster() { LockTag = "" });
            }
            else
            {
                ps.State = StateType.Info;
                ps.Messages.Add("分配完成,开始保存请稍候!");
                NotifyConnection(ps.Clone());

                billMaster.Status = "3";
                try
                {
                    if (!cancellationToken.IsCancellationRequested)
                    {
                        billMaster.LockTag = string.Empty;
                        CellRepository.SaveChanges();
                        ps.State = StateType.Info;
                        ps.Messages.Clear();
                        ps.Messages.Add("分配成功!");
                        NotifyConnection(ps.Clone());
                    }
                }
                catch (Exception e)
                {
                    ps.State = StateType.Error;
                    ps.Messages.Add("保存失败,详情:" + e.Message);
                    NotifyConnection(ps.Clone());
                }
                finally
                {
                    OutBillMasterRepository.GetObjectSet()
                        .UpdateEntity(i => i.BillNo == billno,
                        i => new OutBillMaster() { LockTag = "" });
                }
            }
        }
        public void IsUpdatingSelectedCell()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_Update_Cell_database")
                          .Options;
            var appDbContext = new AppDbContext(options);
            var user         = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "abcd"),
            }));

            appDbContext.UserPermissions.Add(new UserPermission
            {
                Id       = 1,
                UserName = "******",
                IdPrison = 1,
                Prison   = new Prison
                {
                    Id         = 1,
                    PrisonName = "prison_test"
                }
            });
            appDbContext.SaveChanges();
            var loggerRepository = new LoggerRepository(appDbContext);
            var loggerService    = new LoggerService(loggerRepository);

            var cellRepository = new CellRepository(appDbContext);
            var cellService    = new CellService(cellRepository);

            var cellController = new PCellsController(
                cellService,
                _mapper,
                loggerService)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = new DefaultHttpContext {
                        User = user
                    }
                }
            };

            appDbContext.CellTypes.Add(new CellType
            {
                Id       = 1,
                CellName = "abcd"
            });
            cellController.AddCell(new CellDTO
            {
                Beds       = 1,
                IdCellType = 1,
            });

            var cellToUpdate = new CellDTO
            {
                Beds       = 5,
                IdCellType = 1
            };


            Assert.AreEqual(appDbContext.Cells.Count(), 1);
            cellController.UpdateCell(1, cellToUpdate);
            Assert.AreEqual(appDbContext.Cells.Count(), 1, "Cell has not deleted or added, instead of updating");
            Assert.AreEqual(appDbContext.Cells.FirstOrDefault(x => x.Id == 1).Beds, 5, "The cell updated wrong value");
        }
Ejemplo n.º 3
0
        public bool AllotEdit(string billNo, long id, string cellCode, int allotQuantity, out string strResult)
        {
            bool result = false;
            var  ibm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "3");
            var  cell   = CellRepository.GetQueryable().Single(c => c.CellCode == cellCode);

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    var allotDetail = ibm.OutBillAllots.Single(a => a.ID == (int)id);
                    if (string.IsNullOrEmpty(allotDetail.Storage.LockTag))
                    {
                        Storage storage;
                        if (allotDetail.CellCode == cellCode)
                        {
                            storage = allotDetail.Storage;
                            storage.OutFrozenQuantity -= allotDetail.AllotQuantity;
                        }
                        else
                        {
                            storage = Locker.LockNoEmpty(cell, allotDetail.Product);
                            allotDetail.Storage.OutFrozenQuantity -= allotDetail.AllotQuantity;
                        }
                        if (storage != null)
                        {
                            decimal q1 = allotDetail.OutBillDetail.BillQuantity - allotDetail.OutBillDetail.AllotQuantity;
                            decimal q2 = allotQuantity * allotDetail.Unit.Count;
                            decimal q3 = storage.Quantity - storage.OutFrozenQuantity;
                            if (q1 >= q2 && q2 <= q3)
                            {
                                try
                                {
                                    allotDetail.OutBillDetail.AllotQuantity -= allotDetail.AllotQuantity;
                                    allotDetail.OutBillDetail.AllotQuantity += q2;
                                    storage.OutFrozenQuantity += q2;
                                    storage.LockTag            = string.Empty;
                                    allotDetail.CellCode       = storage.Cell.CellCode;
                                    allotDetail.StorageCode    = storage.StorageCode;
                                    allotDetail.AllotQuantity  = q2;
                                    OutBillAllotRepository.SaveChanges();
                                    strResult = "保存修改成功!";
                                    result    = true;
                                }
                                catch (Exception)
                                {
                                    strResult = "保存修改失败,订单或储位其他人正在操作!";
                                }
                            }
                            else
                            {
                                strResult = "分配数量超过订单数量,或者当前储位库存量不足!";
                            }
                        }
                        else
                        {
                            strResult = "当前选择的储位不可用,其他人正在操作或没有库存!";
                        }
                    }
                    else
                    {
                        strResult = "当前储位其他人正在操作,请稍候重试!";
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
Ejemplo n.º 4
0
        private IEnumerable <Cell> GetGroupEditCells(IEnumerable <Guid> rowsIds)
        {
            var recordsCells = CellRepository.GetCellsByRecords(MetaData.Sheet, MetaData.PeriodIds, rowsIds);

            return(FilterCellsByGroupEditColumns(recordsCells));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 修改移库细单
        /// </summary>
        /// <param name="moveBillDetail"></param>
        /// <returns></returns>
        public bool Save(MoveBillDetail moveBillDetail, out string strResult)
        {
            bool    result            = false;
            decimal inFrozenQuantity  = 0;
            decimal outFrozenQuantity = 0;

            if (moveBillDetail.OutCellCode == moveBillDetail.InCellCode)
            {
                strResult = "移入和移出货位不能一样!";
                return(false);
            }
            IQueryable <MoveBillDetail> moveBillDetailQuery = MoveBillDetailRepository.GetQueryable();
            var     mbd     = moveBillDetailQuery.FirstOrDefault(i => i.ID == moveBillDetail.ID && i.BillNo == moveBillDetail.BillNo);
            var     unit    = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == moveBillDetail.UnitCode);
            Product product = null;

            if (mbd.ProductCode == moveBillDetail.ProductCode)//判断用户选择的移库卷烟编码和之前保存的移库卷烟编码是否相等
            {
                product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == mbd.ProductCode);
            }
            else
            {
                product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == moveBillDetail.ProductCode);
            }
            var     outCell       = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.OutCellCode);
            var     inCell        = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.InCellCode);
            Storage outStorage    = null;
            Storage oldOutStorage = null;

            if (mbd.OutStorageCode == moveBillDetail.OutStorageCode)//判断用户选择的移出库存和之前保存的移出库存是否相等
            {
                outStorage        = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.OutStorageCode);
                outFrozenQuantity = outStorage.OutFrozenQuantity - mbd.RealQuantity;
            }
            else
            {
                oldOutStorage     = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.OutStorageCode);
                outStorage        = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == moveBillDetail.OutStorageCode);
                outFrozenQuantity = outStorage.OutFrozenQuantity;
            }
            Storage inStorage    = null;
            Storage oldInStorage = null;

            if (mbd.InCellCode == moveBillDetail.InCellCode)//判断用户选择的移入货位和之前保存的移入货位是否相等
            {
                inStorage        = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.InStorageCode);
                inFrozenQuantity = inStorage.InFrozenQuantity - mbd.RealQuantity;
            }
            else
            {
                oldInStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.InStorageCode);
                inStorage    = Locker.LockStorage(inCell);
                if (inStorage == null)
                {
                    strResult = "移入库存加锁失败!";
                    return(false);
                }
                inFrozenQuantity = inStorage.InFrozenQuantity;
            }
            if (inCell.IsSingle == "1")
            {
                if (inStorage.Product != null && inStorage.Product.ProductCode != moveBillDetail.ProductCode)
                {
                    strResult = "货位:<" + inCell.CellName + ">是非货位管理货位不能移入不同品牌的卷烟!";
                    return(false);
                }
            }
            //判断移出数量是否合理
            bool isOutQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity * unit.Count, outStorage.InFrozenQuantity, outFrozenQuantity, outCell.MaxQuantity * product.Unit.Count, outStorage.Quantity, "out");

            if (Locker.LockStorage(outStorage, product) != null)
            {
                //if (Locker.LockStorage(inStorage, product) != null)
                //{
                //判断移入数量是否合理
                bool isInQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity * unit.Count, inFrozenQuantity, inStorage.OutFrozenQuantity, inCell.MaxQuantity * product.Unit.Count, inStorage.Quantity, "in");
                if (isOutQuantityRight && isInQuantityRight)
                {
                    if (mbd.OutStorageCode == moveBillDetail.OutStorageCode)
                    {
                        outStorage.OutFrozenQuantity -= mbd.RealQuantity;
                        outStorage.OutFrozenQuantity += moveBillDetail.RealQuantity * unit.Count;
                    }
                    else
                    {
                        oldOutStorage.OutFrozenQuantity -= mbd.RealQuantity;
                        outStorage.OutFrozenQuantity    += moveBillDetail.RealQuantity * unit.Count;
                    }
                    if (mbd.InCellCode == moveBillDetail.InCellCode)
                    {
                        inStorage.InFrozenQuantity -= mbd.RealQuantity;
                        inStorage.InFrozenQuantity += moveBillDetail.RealQuantity * unit.Count;
                    }
                    else
                    {
                        oldInStorage.InFrozenQuantity -= mbd.RealQuantity;
                        inStorage.InFrozenQuantity    += moveBillDetail.RealQuantity * unit.Count;
                    }
                    mbd.ProductCode       = moveBillDetail.ProductCode;
                    mbd.OutCellCode       = moveBillDetail.OutCellCode;
                    mbd.OutStorageCode    = moveBillDetail.OutStorageCode;
                    mbd.InCellCode        = moveBillDetail.InCellCode;
                    mbd.InStorageCode     = inStorage.StorageCode;
                    mbd.UnitCode          = moveBillDetail.UnitCode;
                    mbd.RealQuantity      = moveBillDetail.RealQuantity * unit.Count;
                    mbd.Status            = "0";
                    outStorage.LockTag    = string.Empty;
                    inStorage.LockTag     = string.Empty;
                    inStorage.ProductCode = product.ProductCode;
                    MoveBillDetailRepository.SaveChanges();
                    result = true;
                }
                //}
                //else
                //{
                //    resultStr = "加锁移入库存失败,当前库存已有人在操作!";
                //}
            }
            else
            {
                resultStr = "加锁移出库存失败,当前库存已有人在操作!";
            }
            strResult = resultStr;
            return(result);
        }
Ejemplo n.º 6
0
        public bool AllotAdd(string billNo, long id, string productCode, string cellCode, int allotQuantity, out string strResult)
        {
            bool result = false;
            var  ibm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var  cell   = CellRepository.GetQueryable().Single(c => c.CellCode == cellCode);
            var  obm    = OutBillDetailRepository.GetQueryable().FirstOrDefault(o => o.ID == id);

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    Storage storage = Locker.LockNoEmpty(cell, obm.Product);
                    if (storage != null && allotQuantity > 0)
                    {
                        OutBillAllot billAllot = null;
                        decimal      q1        = obm.BillQuantity - obm.AllotQuantity;
                        decimal      q2        = allotQuantity * obm.Unit.Count;
                        decimal      q3        = storage.Quantity - storage.OutFrozenQuantity;
                        if (q1 >= q2 && q2 <= q3)
                        {
                            try
                            {
                                billAllot = new OutBillAllot()
                                {
                                    BillNo          = billNo,
                                    OutBillDetailId = obm.ID,
                                    ProductCode     = obm.ProductCode,
                                    CellCode        = storage.CellCode,
                                    StorageCode     = storage.StorageCode,
                                    UnitCode        = obm.UnitCode,
                                    AllotQuantity   = q2,
                                    RealQuantity    = 0,
                                    Status          = "0"
                                };
                                obm.AllotQuantity         += q2;
                                storage.OutFrozenQuantity += q2;
                                ibm.OutBillAllots.Add(billAllot);
                                ibm.Status      = "3";
                                storage.LockTag = string.Empty;
                                StorageRepository.SaveChanges();
                                strResult = "保存修改成功!";
                                result    = true;
                            }
                            catch (Exception)
                            {
                                strResult = "保存添加失败,订单或储位其他人正在操作!";
                            }
                        }
                        else
                        {
                            strResult = "分配数量超过订单数量,或者当前储位库存量不足!";
                        }
                    }
                    else
                    {
                        strResult = "当前选择的储位不可用,其他人正在操作或没有库存!";
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
Ejemplo n.º 7
0
        public bool AllotAdd(string billNo, long id, string cellCode, string productname, out string strResult, out decimal allotQuantity)
        {
            bool    result   = false;
            decimal quantity = 0;

            allotQuantity = 0;
            var ibm          = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var cell         = CellRepository.GetQueryable().Single(c => c.CellCode == cellCode);
            var cell0        = CellRepository.GetQueryable();
            var storages0    = StorageRepository.GetQueryable();
            var cellstorage  = cell0.Join(storages0, c => c.CellCode, s => s.CellCode, (c, s) => new { cell0 = c, storages0 = s });
            var cellstorages = cellstorage.Where(c => c.cell0.CellCode == cellCode).Select(c => new { product = c.storages0.Product.ProductName }).ToArray();
            var storages     = StorageRepository.GetQueryable().FirstOrDefault(s => s.CellCode == cellCode);

            if (storages != null)
            {
                quantity = storages.Quantity;
            }
            var ibd = InBillDetailRepository.GetQueryable().FirstOrDefault(i => i.ID == id);

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    Storage storage = Locker.LockStorage(cell);
                    if (storage != null)
                    {
                        if (productname == cellstorages[0].product || quantity == 0)
                        {
                            decimal q2 = ibd.BillQuantity - ibd.AllotQuantity;
                            if (q2 > 0)
                            {
                                InBillAllot billAllot = null;
                                decimal     q1        = ibd.Product.CellMaxProductQuantity * ibd.Product.Unit.Count - (storage.Quantity + storage.InFrozenQuantity);
                                if (q2 <= q1)
                                {
                                    try
                                    {
                                        billAllot = new InBillAllot()
                                        {
                                            BillNo         = billNo,
                                            InBillDetailId = ibd.ID,
                                            ProductCode    = ibd.ProductCode,
                                            CellCode       = storage.CellCode,
                                            StorageCode    = storage.StorageCode,
                                            UnitCode       = ibd.UnitCode,
                                            AllotQuantity  = q2,
                                            RealQuantity   = 0,
                                            Status         = "0"
                                        };
                                        allotQuantity             = q2 / ibd.Unit.Count;
                                        ibd.AllotQuantity        += q2;
                                        storage.InFrozenQuantity += q2;
                                        storage.ProductCode       = ibd.ProductCode;
                                        ibm.InBillAllots.Add(billAllot);
                                        ibm.Status      = "3";
                                        storage.LockTag = string.Empty;
                                        StorageRepository.SaveChanges();
                                        strResult = "";
                                        result    = true;
                                    }
                                    catch (Exception)
                                    {
                                        strResult     = "保存添加失败,订单或储位其他人正在操作!";
                                        allotQuantity = 0;
                                    }
                                }
                                else
                                {
                                    try
                                    {
                                        billAllot = new InBillAllot()
                                        {
                                            BillNo         = billNo,
                                            InBillDetailId = ibd.ID,
                                            ProductCode    = ibd.ProductCode,
                                            CellCode       = storage.CellCode,
                                            StorageCode    = storage.StorageCode,
                                            UnitCode       = ibd.UnitCode,
                                            AllotQuantity  = q1,
                                            RealQuantity   = 0,
                                            Status         = "0"
                                        };
                                        allotQuantity             = q1 / ibd.Unit.Count;
                                        ibd.AllotQuantity        += q1;
                                        storage.InFrozenQuantity += q1;
                                        storage.ProductCode       = ibd.ProductCode;
                                        ibm.InBillAllots.Add(billAllot);
                                        ibm.Status      = "3";
                                        storage.LockTag = string.Empty;
                                        StorageRepository.SaveChanges();
                                        strResult = "";
                                        result    = true;
                                    }
                                    catch (Exception)
                                    {
                                        strResult = "保存添加失败,订单或储位其他人正在操作!";
                                    }
                                }
                            }
                            else
                            {
                                strResult = "分配数量必须大于0!";
                            }
                        }
                        else
                        {
                            strResult = "该货位已存在其他产品,不能放入该产品!";
                        }
                    }
                    else
                    {
                        strResult = "当前选择的储位不可用,或者分配数量超过最大托盘数,其他人正在操作!";
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 新增移库细单
        /// </summary>
        /// <param name="moveBillDetail"></param>
        /// <returns></returns>
        public bool Add(MoveBillDetail moveBillDetail, out string strResult)
        {
            bool result = false;

            try
            {
                IQueryable <MoveBillDetail> moveBillDetailQuery = MoveBillDetailRepository.GetQueryable();
                var     product    = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == moveBillDetail.ProductCode);
                var     unit       = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == moveBillDetail.UnitCode);
                var     storage    = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == moveBillDetail.InStorageCode);
                var     outStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == moveBillDetail.OutStorageCode);
                var     outCell    = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.OutCellCode);
                var     inCell     = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.InCellCode);
                Storage inStorage  = null;
                if (storage != null)
                {
                    inStorage = Locker.LockStorage(storage, product);
                }
                else
                {
                    inStorage = Locker.LockStorage(inCell);
                }
                //判断移出数量是否合理
                bool isOutQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity * unit.Count, outStorage.InFrozenQuantity, outStorage.OutFrozenQuantity, outCell.MaxQuantity * product.Unit.Count, outStorage.Quantity, "out");
                if (Locker.LockStorage(outStorage, product) != null)
                {
                    if (inStorage != null)
                    {
                        //判断移入数量是否合理
                        bool isInQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity * unit.Count, inStorage.InFrozenQuantity, inStorage.OutFrozenQuantity, inCell.MaxQuantity * product.Unit.Count, inStorage.Quantity, "in");
                        if (isInQuantityRight && isOutQuantityRight)
                        {
                            var mbd = new MoveBillDetail();
                            mbd.BillNo                    = moveBillDetail.BillNo;
                            mbd.ProductCode               = moveBillDetail.ProductCode;
                            mbd.OutCellCode               = moveBillDetail.OutCellCode;
                            mbd.OutStorageCode            = moveBillDetail.OutStorageCode;
                            mbd.InCellCode                = moveBillDetail.InCellCode;
                            mbd.InStorageCode             = inStorage.StorageCode;
                            mbd.UnitCode                  = moveBillDetail.UnitCode;
                            mbd.RealQuantity              = moveBillDetail.RealQuantity * unit.Count;
                            outStorage.OutFrozenQuantity += moveBillDetail.RealQuantity * unit.Count;
                            inStorage.ProductCode         = moveBillDetail.ProductCode;
                            inStorage.InFrozenQuantity   += moveBillDetail.RealQuantity * unit.Count;
                            mbd.Status                    = "0";
                            inStorage.LockTag             = string.Empty;
                            outStorage.LockTag            = string.Empty;
                            MoveBillDetailRepository.Add(mbd);
                            MoveBillDetailRepository.SaveChanges();
                            result = true;
                        }
                        else
                        {
                            result = false;
                        }
                    }
                    else
                    {
                        resultStr = "移入库存加锁失败";
                    }
                }
                else
                {
                    resultStr = "移出库存加锁失败";
                }
            }
            catch (Exception ex)
            {
                resultStr = ex.ToString();
            }
            strResult = resultStr;
            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 手工分配入库单
        /// </summary>
        /// <param name="billNo"></param>
        /// <param name="id"></param>
        /// <param name="cellCode"></param>
        /// <param name="allotQuantity"></param>
        /// <param name="strResult"></param>
        /// <returns></returns>
        public bool AllotAdd(string billNo, long id, string cellCode, decimal allotQuantity, out string strResult)
        {
            bool result = false;
            var  ibm    = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var  cell   = CellRepository.GetQueryable().Single(c => c.CellCode == cellCode);
            var  ibd    = InBillDetailRepository.GetQueryable().FirstOrDefault(i => i.ID == id);

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    Storage storage = Locker.LockStorage(cell);
                    if (storage != null)
                    {
                        if (allotQuantity > 0)
                        {
                            InBillAllot billAllot = null;
                            decimal     q1        = ibd.BillQuantity - ibd.AllotQuantity;
                            decimal     q2        = allotQuantity * ibd.Unit.Count;
                            if (q2 <= q1 && q2 <= (cell.MaxQuantity * ibd.Unit.Count - (storage.Quantity + storage.InFrozenQuantity)))
                            {
                                try
                                {
                                    billAllot = new InBillAllot()
                                    {
                                        BillNo         = billNo,
                                        InBillDetailId = ibd.ID,
                                        ProductCode    = ibd.ProductCode,
                                        CellCode       = storage.CellCode,
                                        StorageCode    = storage.StorageCode,
                                        UnitCode       = ibd.UnitCode,
                                        AllotQuantity  = q2,
                                        RealQuantity   = 0,
                                        Status         = "0"
                                    };
                                    ibd.AllotQuantity        += q2;
                                    storage.InFrozenQuantity += q2;
                                    storage.ProductCode       = ibd.ProductCode;
                                    ibm.InBillAllots.Add(billAllot);
                                    ibm.Status      = "3";
                                    storage.LockTag = string.Empty;
                                    StorageRepository.SaveChanges();
                                    strResult = "手工分配成功!";
                                    result    = true;
                                }
                                catch (Exception)
                                {
                                    strResult = "保存添加失败,订单或储位其他人正在操作!";
                                }
                            }
                            else
                            {
                                strResult = "分配数量超过订单数量,或者大于储位的最大数量!";
                            }
                        }
                        else
                        {
                            strResult = "分配数量必须大于0!";
                        }
                    }
                    else
                    {
                        strResult = "当前选择的储位不可用,或者分配数量超过最大托盘数,其他人正在操作!";
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
        public void CreateSyncMoveBillDetail(MoveBillMaster moveBillMaster)
        {
            Locker.LockKey = moveBillMaster.BillNo;

            IQueryable <Storage> storageQuery = StorageRepository.GetQueryable();
            IQueryable <Cell>    cellQuery    = CellRepository.GetQueryableIncludeStorages();

            var storages = storageQuery.Where(s => s.Cell.WarehouseCode == moveBillMaster.WarehouseCode &&
                                              s.Cell.IsActive == "1" &&
                                              s.Quantity - s.OutFrozenQuantity > 0 &&
                                              s.OutFrozenQuantity > 0);

            var cells = cellQuery.Where(c => c.WarehouseCode == moveBillMaster.WarehouseCode &&
                                        c.IsActive == "1");

            //1:主库区 1;2:件烟区 2;
            //3;条烟区 3;4:暂存区 4;
            //5:备货区 0;6:残烟区 0;
            //7:罚烟区 0;8:虚拟区 0;
            //9:其他区 0;

            //主库区未满盘件烟移到件烟区
            string[] areaTypes = new string[] { "1" };
            var      ss        = storages.Where(s => areaTypes.Any(a => a == s.Cell.Area.AreaType) &&
                                                ((s.Quantity - s.OutFrozenQuantity) / s.Product.Unit.Count) > 1)
                                 .ToArray();

            if (Locker.Lock(ss))
            {
                //件烟区 货位是单一存储的空货位;
                areaTypes = new string[] { "2" };
                var cc = cells.Where(c => areaTypes.Any(a => a == c.Area.AreaType) &&
                                     c.IsSingle == "1")
                         .ToArray();

                ss.AsParallel().ForAll(
                    (Action <Storage>) delegate(Storage s)
                {
                    MoveToPieceArea(moveBillMaster, s, cc);
                }
                    );

                Locker.UnLock(ss);
            }
            else
            {
                return;
            }

            MoveBillDetailRepository.SaveChanges();

            //主库区件烟库区条烟移到条烟区
            areaTypes = new string[] { "1", "2" };
            ss        = storages.Where(s => areaTypes.Any(a => a == s.Cell.Area.AreaType) &&
                                       (s.Quantity - s.OutFrozenQuantity) % s.Product.Unit.Count > 0)
                        .ToArray();

            if (Locker.Lock(ss))
            {
                areaTypes = new string[] { "3" };
                var cc = cells.Where(c => areaTypes.Any(a => a == c.Area.AreaType) &&
                                     c.IsSingle == "1")
                         .ToArray();

                ss.AsParallel().ForAll(
                    (Action <Storage>) delegate(Storage s)
                {
                    MoveToBarArea(moveBillMaster, s, cc);
                }
                    );

                Locker.UnLock(ss);
            }
            else
            {
                return;
            }

            MoveBillDetailRepository.SaveChanges();
        }
Ejemplo n.º 12
0
        public void Allot(string connectionId, ProgressState ps, CancellationToken cancellationToken, string billNo, string[] areaCodes)
        {
            Locker.LockKey = billNo;
            ConnectionId   = connectionId;
            ps.State       = StateType.Start;
            ps.Messages.Add("开始分配!");
            NotifyConnection(ps.Clone());
            IQueryable <THOK.Authority.DbModel.SystemParameter> systemParQuery = SystemParameterRepository.GetQueryable();
            IQueryable <InBillMaster> inBillMasterQuery = InBillMasterRepository.GetQueryable();
            IQueryable <Cell>         cellQuery         = CellRepository.GetObjectSet()
                                                          .Include("Warehouse").Include("Area").Include("Storages");

            InBillMaster billMaster = inBillMasterQuery.Single(b => b.BillNo == billNo);

            if (!CheckAndLock(billMaster, ps))
            {
                return;
            }

            var isDefaultProduct  = systemParQuery.FirstOrDefault(s => s.ParameterName == "IsDefaultProduct");  //查询预设的卷烟其他卷烟是否可入 0 否 1是
            var InMantissaIsPiece = systemParQuery.FirstOrDefault(s => s.ParameterName == "InMantissaIsPiece"); //查询入库的尾数是否放入件烟区  0 否 1是

            //选择未分配的细单数组;
            var billDetails = billMaster.InBillDetails
                              .Where(b => (b.BillQuantity - b.AllotQuantity) > 0)
                              .ToArray();


            //选择当前订单操作目标仓库;
            var cells = cellQuery.Where(c => c.WarehouseCode == billMaster.WarehouseCode &&
                                        c.Warehouse.IsActive == "1" &&
                                        c.Area.IsActive == "1" &&
                                        c.IsActive == "1" &&
                                        (areaCodes.Any(a => a == c.AreaCode) ||
                                         (!areaCodes.Any() && c.Area.AllotInOrder > 0)))
                        .ToArray();

            //1:主库区;2:件烟区;
            //3;条烟区;4:暂存区;
            //5:备货区;6:残烟区;
            //7:罚烟区;8:虚拟区;
            //9:其他区;

            //排除 件烟区,条烟区 货位是单一存储的空货位;
            string [] areaTypes = new string [] { "2", "3" };
            var       cells1    = cells.Where(c => c.Area.AreaType != "2" && c.Area.AreaType != "3"
                                              //areaTypes.All(a => a != c.Area.AreaType)
                                              && c.IsSingle == "1" &&
                                              (c.Storages.Count == 0 ||
                                               c.Storages.Any(s => string.IsNullOrEmpty(s.LockTag) &&
                                                              s.Quantity == 0 &&
                                                              s.InFrozenQuantity == 0)));

            //条烟区 货位是单一存储的货位(不必是空货位,因为条烟会多次存储到同一个货位);
            areaTypes = new string[] { "3" };
            var cell2 = cells.Where(c => areaTypes.Any(a => a == c.Area.AreaType) &&
                                    c.IsSingle == "1");

            //件烟区 货位是单一存储的空货位;
            areaTypes = new string[] { "2", "4" };
            var cell3 = cells.Where(c => areaTypes.Any(a => a == c.Area.AreaType) &&
                                    c.IsSingle == "1" &&
                                    c.Storages.Any(s => string.IsNullOrEmpty(s.LockTag) &&
                                                   s.Product != null &&
                                                   (s.Quantity > 0 || s.InFrozenQuantity > 0) &&
                                                   (c.MaxQuantity >= s.Product.CellMaxProductQuantity ? s.Product.CellMaxProductQuantity : c.MaxQuantity) * s.Product.Unit.Count > s.Quantity + s.InFrozenQuantity));

            //件烟区 货位是单一存储的空货位;
            areaTypes = new string[] { "2" };
            var cell4 = cells.Where(c => areaTypes.Any(a => a == c.Area.AreaType) &&
                                    c.IsSingle == "1" &&
                                    (c.Storages.Count == 0 ||
                                     c.Storages.Any(s => string.IsNullOrEmpty(s.LockTag) &&
                                                    s.Quantity == 0 &&
                                                    s.InFrozenQuantity == 0
                                                    )
                                    )
                                    );

            //非货位管理区
            var cell5 = cells.Where(c => c.IsSingle == "0");


            //排除 件烟区,条烟区
            var cellQueryFromList1 = cells1.Where(c => c.Storages.Count == 0 ||
                                                  c.Storages.Any(s => string.IsNullOrEmpty(s.LockTag) &&
                                                                 s.Quantity == 0 &&
                                                                 s.InFrozenQuantity == 0))
                                     .OrderBy(c => c.Area.AllotInOrder);
            //条烟区
            var cellQueryFromList2 = cell2.OrderBy(c => c.Area.AllotInOrder);

            //件烟区 --入库尾数可以放入件烟区
            var cellQueryFromList3 = cell3.OrderBy(c => c.Area.AllotInOrder);

            if (InMantissaIsPiece.ParameterValue != "0")
            {
                cellQueryFromList3 = cell3.Where(c => c.Storages.Any(s => (c.MaxQuantity >= s.Product.CellMaxProductQuantity ? s.Product.CellMaxProductQuantity : c.MaxQuantity) * s.Product.Unit.Count > s.Quantity + s.InFrozenQuantity))
                                     .OrderBy(c => c.Area.AllotInOrder);
            }
            //件烟区 --入库尾数不放入件烟区
            var cellQueryFromList4 = cell4.Where(c => c.Storages.Count == 0 ||
                                                 c.Storages.Any(s => string.IsNullOrEmpty(s.LockTag) &&
                                                                s.Quantity == 0 &&
                                                                s.InFrozenQuantity == 0))
                                     .OrderBy(c => c.Area.AllotInOrder);

            //非货位管理区
            var cellQueryFromList5 = cell5.OrderBy(c => c.Area.AllotInOrder % 10000);

            foreach (var billDetail in billDetails)
            {
                //分配预设当前卷烟的货位;
                var cs = cellQueryFromList1.Where(c => c.DefaultProductCode == billDetail.ProductCode);
                AllotPallet(billMaster, billDetail, cs, cancellationToken, ps);

                //分配没预设卷烟的货位;
                cs = cellQueryFromList1.Where(c => string.IsNullOrEmpty(c.DefaultProductCode) &&
                                              (string.IsNullOrEmpty(billDetail.Product.PointAreaCodes) || billDetail.Product.PointAreaCodes.Contains(c.AreaCode)));
                AllotPallet(billMaster, billDetail, cs, cancellationToken, ps);

                if (isDefaultProduct.ParameterValue != "0")//判断预设卷烟后不能放入其他烟
                {
                    //分配预设其他卷烟的货位;
                    cs = cellQueryFromList1.Where(c => c.DefaultProductCode != billDetail.ProductCode &&
                                                  !string.IsNullOrEmpty(c.DefaultProductCode) &&
                                                  (string.IsNullOrEmpty(billDetail.Product.PointAreaCodes) || billDetail.Product.PointAreaCodes.Contains(c.AreaCode)));
                    AllotPallet(billMaster, billDetail, cs, cancellationToken, ps);
                }

                //分配条烟到条烟区;
                cs = cellQueryFromList2.Where(c => c.DefaultProductCode == billDetail.ProductCode ||
                                              (c.Storages.Count == 1 &&
                                               c.Storages.First().ProductCode == billDetail.ProductCode)
                                              );
                AllotBar(billMaster, billDetail, cs, cancellationToken, ps);
                //分配条烟到条烟区;
                if (!cs.Any())
                {
                    cs = cellQueryFromList2.Where(c => (isDefaultProduct.ParameterValue == "0" ? string.IsNullOrEmpty(c.DefaultProductCode) : true));
                    AllotBar(billMaster, billDetail, cs, cancellationToken, ps);
                }

                //分配未满一托盘的卷烟到件烟区;
                cs = cellQueryFromList3.Where(c => (isDefaultProduct.ParameterValue == "0" ? string.IsNullOrEmpty(c.DefaultProductCode) : true) || c.DefaultProductCode == billDetail.ProductCode);
                if (cellQueryFromList2.Any())
                {
                    if (InMantissaIsPiece.ParameterValue != "0")
                    {
                        AllotPiece(billMaster, billDetail, cs, cancellationToken, ps);
                    }
                    cs = cellQueryFromList4.Where(c => (isDefaultProduct.ParameterValue == "0" ? string.IsNullOrEmpty(c.DefaultProductCode) : true));
                    AllotPiece(billMaster, billDetail, cs, cancellationToken, ps);
                }
                else
                {
                    if (InMantissaIsPiece.ParameterValue != "0")
                    {
                        AllotPieceAndBar(billMaster, billDetail, cs, cancellationToken, ps);
                    }
                    cs = cellQueryFromList4.Where(c => (isDefaultProduct.ParameterValue == "0" ? string.IsNullOrEmpty(c.DefaultProductCode) : true));
                    AllotPieceAndBar(billMaster, billDetail, cs, cancellationToken, ps);
                }

                //分配未满一托盘的卷烟到下层货架;
                cs = cellQueryFromList1.Where(c => c.Layer == 1 && (isDefaultProduct.ParameterValue == "0" ? string.IsNullOrEmpty(c.DefaultProductCode) : true) &&
                                              (string.IsNullOrEmpty(billDetail.Product.PointAreaCodes) || billDetail.Product.PointAreaCodes.Contains(c.AreaCode)));
                if (cellQueryFromList2.Count() > 0)
                {
                    AllotPiece(billMaster, billDetail, cs, cancellationToken, ps);
                }
                else
                {
                    AllotPieceAndBar(billMaster, billDetail, cs, cancellationToken, ps);
                }

                //分配未分配卷烟到其他库区;
                cs = cellQueryFromList1.Where(c => (isDefaultProduct.ParameterValue == "0" ? string.IsNullOrEmpty(c.DefaultProductCode) : true) &&
                                              (string.IsNullOrEmpty(billDetail.Product.PointAreaCodes) || billDetail.Product.PointAreaCodes.Contains(c.AreaCode)));
                AllotPiece(billMaster, billDetail, cs, cancellationToken, ps);

                //分配未分配卷烟到其他非货位管理货位;
                while (!cancellationToken.IsCancellationRequested && (billDetail.BillQuantity - billDetail.AllotQuantity) > 0)
                {
                    var c = cellQueryFromList5.Where(i => !i.Storages.Any() ||
                                                     i.Storages.Count() < i.MaxPalletQuantity ||
                                                     i.Storages.Any(s => string.IsNullOrEmpty(s.LockTag) &&
                                                                    s.Quantity == 0 &&
                                                                    s.InFrozenQuantity == 0))
                            .Where(i => string.IsNullOrEmpty(billDetail.Product.PointAreaCodes) || billDetail.Product.PointAreaCodes.Contains(i.AreaCode))
                            .FirstOrDefault();

                    if (c != null)
                    {
                        lock (c)
                        {
                            decimal allotQuantity = (c.MaxQuantity >= billDetail.Product.CellMaxProductQuantity ? billDetail.Product.CellMaxProductQuantity : c.MaxQuantity) * billDetail.Product.Unit.Count;
                            decimal billQuantity  = billDetail.BillQuantity - billDetail.AllotQuantity;
                            allotQuantity = allotQuantity < billQuantity ? allotQuantity : billQuantity;
                            var targetStorage = Locker.LockStorage(c);
                            if (targetStorage != null &&
                                targetStorage.Quantity == 0 &&
                                targetStorage.InFrozenQuantity == 0)
                            {
                                Allot(billMaster, billDetail, c, targetStorage, allotQuantity, ps);
                                Locker.UnLockStorage(targetStorage);
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            string billno = billMaster.BillNo;

            if (billMaster.InBillDetails.Any(i => i.BillQuantity - i.AllotQuantity > 0))
            {
                ps.State = StateType.Warning;
                ps.Errors.Add("分配未全部完成,没有储位可分配!");
                NotifyConnection(ps.Clone());

                InBillMasterRepository.GetObjectSet()
                .UpdateEntity(i => i.BillNo == billno,
                              i => new InBillMaster()
                {
                    LockTag = ""
                });
            }
            else
            {
                ps.State = StateType.Info;
                ps.Messages.Add("分配完成,开始保存请稍候!");
                NotifyConnection(ps.Clone());

                billMaster.Status = "3";
                try
                {
                    if (!cancellationToken.IsCancellationRequested)
                    {
                        billMaster.LockTag = string.Empty;
                        CellRepository.SaveChanges();
                        ps.State = StateType.Info;
                        ps.Messages.Clear();
                        ps.Messages.Add("分配成功!");
                        NotifyConnection(ps.Clone());
                    }
                }
                catch (Exception e)
                {
                    ps.State = StateType.Error;
                    ps.Messages.Add("保存失败,详情:" + e.Message);
                    NotifyConnection(ps.Clone());
                }
                finally
                {
                    InBillMasterRepository.GetObjectSet()
                    .UpdateEntity(i => i.BillNo == billno,
                                  i => new InBillMaster()
                    {
                        LockTag = ""
                    });
                }
            }
        }
Ejemplo n.º 13
0
        public bool CreateNewTaskForEmptyPalletStack(int positionID)
        {
            string palletCode  = "";
            int    palletCount = 10;
            var    position    = PositionRepository.GetQueryable()
                                 .Where(i => i.ID == positionID).FirstOrDefault();

            if (position != null)
            {
                var positionQuery = PositionRepository.GetQueryable()
                                    .Where(i => i.SRMName == position.SRMName &&
                                           i.AbleStockInPallet && i.ID != positionID);
                var cellPositionQuery = CellPositionRepository.GetQueryable()
                                        .Where(i => i.StockOutPositionID != positionID &&
                                               positionQuery.Contains(i.StockInPosition));
                var cellQuery = CellRepository.GetQueryable()
                                .Where(i => i.IsSingle == "1" &&
                                       cellPositionQuery.Any(p => p.CellCode == i.CellCode) &&
                                       (i.Storages.Count == 0 ||
                                        i.Storages.Any(s => string.IsNullOrEmpty(s.LockTag) &&
                                                       s.Quantity == 0 &&
                                                       s.InFrozenQuantity == 0) ||
                                        i.Storages.Any(s => s.ProductCode == palletCode &&
                                                       s.Quantity + s.InFrozenQuantity < palletCount)));

                var cell = cellQuery.FirstOrDefault();
                if (cell != null)
                {
                    var cellPosition = CellPositionRepository.GetQueryable()
                                       .Where(cp => cp.CellCode == cell.CellCode).FirstOrDefault();
                    if (!cell.Storages.Any())
                    {
                        var storage = new Storage()
                        {
                            Cell        = cell,
                            StorageCode = Guid.NewGuid().ToString(),
                            CellCode    = cell.CellCode,
                            IsLock      = "0",
                            IsActive    = "0",
                            StorageTime = DateTime.Now,
                            UpdateTime  = DateTime.Now
                        };
                        lock (cell.Storages)
                        {
                            cell.Storages.Add(storage);
                        }
                    }
                    var targetStorage = cell.Storages.FirstOrDefault();
                    if (targetStorage != null && cellPosition != null)
                    {
                        targetStorage.InFrozenQuantity += 1;
                        var newTask = new Task();
                        newTask.TaskType  = "01";
                        newTask.TaskLevel = 0;
                        //newTask.PathID = path.ID;
                        newTask.ProductCode = palletCode;
                        newTask.ProductName = "空托盘";
                        //newTask.OriginStorageCode = inItem.CellCode;
                        newTask.TargetStorageCode    = cell.CellCode;
                        newTask.OriginPositionID     = positionID;
                        newTask.TargetPositionID     = cellPosition.StockInPositionID;
                        newTask.CurrentPositionID    = positionID;
                        newTask.CurrentPositionState = "02";
                        newTask.State           = "01";
                        newTask.TagState        = "01";//拟不使用
                        newTask.Quantity        = 1;
                        newTask.TaskQuantity    = 1;
                        newTask.OperateQuantity = 0;
                        //newTask.OrderID = inItem.BillNo;
                        //newTask.OrderType = "01";
                        //newTask.AllotID = inItem.ID;
                        newTask.DownloadState = "1";
                        TaskRepository.Add(newTask);
                        TaskRepository.SaveChanges();
                        return(true);
                    }
                }
            }
            return(false);
        }