コード例 #1
0
        public object SearchMoveBillDetail(string billNo, int page, int rows)
        {
            var allotQuery = MoveBillDetailRepository.GetQueryable();
            var query      = allotQuery.Where(a => a.BillNo == billNo && a.Status != "2")
                             .OrderByDescending(a => a.Status == "1").Select(i => i);
            int total = query.Count();

            query = query.Skip((page - 1) * rows).Take(rows);

            var temp = query.ToArray().Select(a => new
            {
                a.ID,
                a.BillNo,
                a.ProductCode,
                a.Product.ProductName,
                a.InCellCode,
                InCellName = a.InCell.CellName,
                a.OutCellCode,
                OutCellName = a.OutCell.CellName,
                CellType    = "移库",
                a.InStorageCode,
                a.UnitCode,
                a.Unit.UnitName,
                a.RealQuantity,
                PieceQuantity = Math.Floor(a.RealQuantity / a.Product.UnitList.Unit01.Count),
                RopeQuantity  = Math.Floor(a.RealQuantity % a.Product.UnitList.Unit01.Count / a.Product.UnitList.Unit02.Count),
                Status        = SwitchStatus(a.Status),
                a.Operator
            });

            return(new { total, rows = temp.ToArray() });
        }
コード例 #2
0
        /// <summary>
        /// 查询移库细单
        /// </summary>
        /// <param name="page">页码</param>
        /// <param name="rows">行数</param>
        /// <param name="BillNo">移库单号</param>
        /// <returns></returns>
        public object GetDetails(int page, int rows, string BillNo)
        {
            if (BillNo != "" && BillNo != null)
            {
                IQueryable <MoveBillDetail> MoveBillDetailQuery = MoveBillDetailRepository.GetQueryable();
                var moveBillDetail = MoveBillDetailQuery.Where(i => i.BillNo.Contains(BillNo)).OrderBy(i => i.BillNo).Select(i => i);
                int total          = moveBillDetail.Count();
                moveBillDetail = moveBillDetail.Skip((page - 1) * rows).Take(rows);

                var temp = moveBillDetail.ToArray().AsEnumerable().Select(i => new
                {
                    i.ID,
                    i.BillNo,
                    i.ProductCode,
                    i.Product.ProductName,
                    i.OutCellCode,
                    OutCellName = i.OutCell.CellName,
                    i.OutStorageCode,
                    i.InCellCode,
                    InCellName = i.InCell.CellName,
                    i.InStorageCode,
                    i.UnitCode,
                    i.Unit.UnitName,
                    RealQuantity    = i.RealQuantity / i.Unit.Count,
                    OperatePersonID = i.OperatePersonID == null ? string.Empty : i.OperatePersonID.ToString(),
                    EmployeeName    = i.OperatePerson == null ? string.Empty : i.OperatePerson.EmployeeName,
                    StartTime       = i.StartTime == null ? null : ((DateTime)i.StartTime).ToString("yyyy-MM-dd HH:mm:ss"),
                    FinishTime      = i.FinishTime == null ? null : ((DateTime)i.FinishTime).ToString("yyyy-MM-dd HH:mm:ss"),
                    Status          = WhatStatus(i.Status)
                });
                return(new { total, rows = temp.ToArray() });
            }
            return("");
        }
コード例 #3
0
        /// <summary>
        /// 移库结单
        /// </summary>
        /// <param name="BillNo">单据号</param>
        /// <param name="strResult">提示信息</param>
        /// <returns></returns>
        public bool Settle(string BillNo, out string strResult)
        {
            bool result = false;

            strResult = string.Empty;
            var mbm = MoveBillMasterRepository.GetQueryable().FirstOrDefault(m => m.BillNo == BillNo);

            if (mbm != null && mbm.Status == "3")
            {
                using (var scope = new TransactionScope())
                {
                    try
                    {
                        //结单移库单,修改冻结量
                        var moveDetail = MoveBillDetailRepository.GetQueryable()
                                         .Where(m => m.BillNo == BillNo &&
                                                m.Status != "2");
                        var sourceStorages = moveDetail.Select(m => m.OutStorage).ToArray();
                        var targetStorages = moveDetail.Select(m => m.InStorage).ToArray();
                        if (!Locker.Lock(sourceStorages) || !Locker.Lock(targetStorages))
                        {
                            strResult = "锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!";
                            return(false);
                        }
                        moveDetail.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("储位的卷烟或入库冻结量与当前分配不符,信息可能被异常修改,不能结单!");
                            }
                        }
                            );
                        MoveBillDetailRepository.SaveChanges();
                        mbm.Status     = "4";
                        mbm.UpdateTime = DateTime.Now;
                        MoveBillMasterRepository.SaveChanges();
                        result = true;
                        scope.Complete();
                    }
                    catch (Exception e)
                    {
                        strResult = "移库单结单出错!原因:" + e.Message;
                        return(false);
                    }
                }
            }
            return(result);
        }
コード例 #4
0
ファイル: TaskService.cs プロジェクト: radtek/HNXC_WMS
        /// <summary>
        /// 移库但觉作业
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <param name="errInfo">错误消息</param>
        /// <returns></returns>
        public bool MoveBIllTask(string billNo, out string errInfo)
        {
            bool result = true;

            errInfo = string.Empty;
            var moveQuery = MoveBillDetailRepository.GetQueryable().Where(i => i.BillNo == billNo);

            try
            {
                if (moveQuery.Any())
                {
                    foreach (var moveItem in moveQuery.ToArray())
                    {
                        //根据移出货位查找起始位置信息
                        var originCellPosition = CellPositionRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveItem.OutCellCode);
                        //根据移入货位查找目标位置信息
                        var targetCellPosition = CellPositionRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveItem.InCellCode);
                        //根据移出位置ID去找起始区域ID信息
                        var originPosition = PositionRepository.GetQueryable().FirstOrDefault(p => p.ID == originCellPosition.StockOutPositionID);
                        //根据移入位置ID去找目标区域ID信息
                        var targetPosition = PositionRepository.GetQueryable().FirstOrDefault(p => p.ID == targetCellPosition.StockInPositionID);
                        //根据入库的目标区域和起始位置区域去找路径信息
                        var path     = PathRepository.GetQueryable().FirstOrDefault(p => p.OriginRegionID == originPosition.RegionID && p.TargetRegionID == targetPosition.RegionID);
                        var moveTask = new Task();
                        moveTask.TaskType             = "01";
                        moveTask.TaskLevel            = 0;
                        moveTask.PathID               = path.ID;
                        moveTask.ProductCode          = moveItem.Product.ProductCode;
                        moveTask.ProductName          = moveItem.Product.ProductName;
                        moveTask.OriginStorageCode    = moveItem.OutCellCode;
                        moveTask.TargetStorageCode    = moveItem.InCellCode;
                        moveTask.OriginPositionID     = originPosition.ID;
                        moveTask.TargetPositionID     = targetPosition.ID;
                        moveTask.CurrentPositionID    = originPosition.ID;
                        moveTask.CurrentPositionState = "01";
                        moveTask.State           = "01";
                        moveTask.TagState        = "01";
                        moveTask.Quantity        = Convert.ToInt32(moveItem.RealQuantity);
                        moveTask.TaskQuantity    = Convert.ToInt32(moveItem.RealQuantity);
                        moveTask.OperateQuantity = Convert.ToInt32(moveItem.RealQuantity);
                        moveTask.OrderID         = moveItem.BillNo;
                        moveTask.OrderType       = "02";
                        moveTask.AllotID         = moveItem.ID;
                        TaskRepository.Add(moveTask);
                    }
                    TaskRepository.SaveChanges();
                }
                else
                {
                    errInfo = "当前选择订单没有移库细表数据,请重新选择!";
                }
            }
            catch (Exception e)
            {
                result  = false;
                errInfo = e.Message;
            }
            return(result);
        }
コード例 #5
0
        /// <summary>获得移库细单信息</summary>
        public System.Data.DataTable GetMoveBillDetail(int page, int rows, string BillNo)
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            if (BillNo != "" && BillNo != null)
            {
                IQueryable <MoveBillDetail> MoveBillDetailQuery = MoveBillDetailRepository.GetQueryable();
                var moveBillDetail = MoveBillDetailQuery.Where(i => i.BillNo.Contains(BillNo)).OrderBy(i => i.BillNo).Select(i => new
                {
                    OutCellName       = i.OutCell.CellName,
                    OutStorageCode    = i.OutStorageCode,
                    InCellName        = i.InCell.CellName,
                    InStorageCode     = i.InStorageCode,
                    ProductCode       = i.ProductCode,
                    ProductName       = i.Product.ProductName,
                    UnitCode          = i.UnitCode,
                    UnitName          = i.Unit.UnitName,
                    RealQuantity      = i.RealQuantity / i.Unit.Count,
                    OperatePersonName = i.OperatePerson == null ? string.Empty : i.OperatePerson.EmployeeName,
                    Status            = i.Status == "0" ? "未开始" : i.Status == "1" ? "已申请" : i.Status == "2" ? "已完成" : "空",
                });
                dt.Columns.Add("移出储位名称", typeof(string));
                //dt.Columns.Add("移出存储编码", typeof(string));
                dt.Columns.Add("移入储位名称", typeof(string));
                //dt.Columns.Add("移入存储编码", typeof(string));
                dt.Columns.Add("产品代码", typeof(string));
                dt.Columns.Add("产品名称", typeof(string));
                dt.Columns.Add("单位编码", typeof(string));
                dt.Columns.Add("单位名称", typeof(string));
                dt.Columns.Add("数量", typeof(string));
                dt.Columns.Add("作业人员", typeof(string));
                dt.Columns.Add("作业状态", typeof(string));

                //dt.Columns.Add("Description", typeof(string));
                foreach (var m in moveBillDetail)
                {
                    dt.Rows.Add
                    (
                        m.OutCellName
                        //, m.OutStorageCode
                        , m.InCellName
                        //, m.InStorageCode
                        , m.ProductCode
                        , m.ProductName
                        , m.UnitCode
                        , m.UnitName
                        , m.RealQuantity
                        , m.OperatePersonName
                        , m.Status
                    );
                }
            }
            return(dt);
        }
コード例 #6
0
        public bool EditAllot(string id, string status, string operater, out string strResult)
        {
            strResult = string.Empty;
            bool result = false;

            string[]       ids    = id.Split(',');
            string         strId  = "";
            MoveBillDetail detail = null;

            var employee = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.UserName == operater);

            for (int i = 0; i < ids.Length; i++)
            {
                strId  = ids[i].ToString();
                detail = MoveBillDetailRepository.GetQueryable().AsEnumerable().FirstOrDefault(a => strId == a.ID.ToString());
                if (detail != null)
                {
                    if (detail.Status == "0" && status == "1" ||
                        detail.Status == "1" && status == "0" ||
                        detail.Status == "1" && status == "2")
                    {
                        try
                        {
                            detail.Status = status;
                            if (operater != "")
                            {
                                detail.Operator = employee.EmployeeName;
                            }
                            else
                            {
                                detail.Operator = "";
                            }
                            MoveBillDetailRepository.SaveChanges();
                            result = true;
                        }
                        catch (Exception ex)
                        {
                            strResult = "原因:" + ex.Message;
                        }
                    }
                    else
                    {
                        strResult = "原因:操作错误!";
                    }
                }
                else
                {
                    strResult = "原因:未找到该记录!";
                }
            }
            return(result);
        }
コード例 #7
0
        /// <summary>
        /// 修改移库细单
        /// </summary>
        /// <param name="moveBillDetail"></param>
        /// <returns></returns>
        public bool Save(MoveBillDetail moveBillDetail, out string strResult)
        {
            bool result = 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);
            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 outCell    = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.OutCellCode);
            var inCell     = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.InCellCode);
            //判断移出数量是否合理
            bool isOutQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity, outStorage.InFrozenQuantity, outStorage.OutFrozenQuantity - mbd.RealQuantity, outCell.MaxQuantity, outStorage.Quantity, "out");
            //判断移入数量是否合理
            bool isInQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity, inStorage.InFrozenQuantity - mbd.RealQuantity, inStorage.OutFrozenQuantity, inCell.MaxQuantity, inStorage.Quantity, "in");

            if (Locker.LockStorage(outStorage, product) != null)
            {
                if (Locker.LockStorage(inStorage, product) != null)
                {
                    if (isOutQuantityRight && isInQuantityRight)
                    {
                        mbd.ProductCode               = moveBillDetail.ProductCode;
                        mbd.OutCellCode               = moveBillDetail.OutCellCode;
                        mbd.OutStorageCode            = moveBillDetail.OutStorageCode;
                        mbd.InCellCode                = moveBillDetail.InCellCode;
                        mbd.InStorageCode             = moveBillDetail.InStorageCode;
                        mbd.UnitCode                  = moveBillDetail.UnitCode;
                        mbd.RealQuantity              = moveBillDetail.RealQuantity * unit.Count;
                        outStorage.OutFrozenQuantity += moveBillDetail.RealQuantity * unit.Count;
                        inStorage.InFrozenQuantity   += moveBillDetail.RealQuantity * unit.Count;
                        mbd.Status = "0";
                        MoveBillDetailRepository.SaveChanges();
                        result = true;
                    }
                }
                else
                {
                    resultStr = "加锁移入库存失败,当前库存已有人在操作!";
                }
            }
            else
            {
                resultStr = "加锁移出库存失败,当前库存已有人在操作!";
            }
            strResult = resultStr;
            return(result);
        }
コード例 #8
0
        /// <summary>
        /// 根据参数查询要生成的盘点数据  --异动查询预览
        /// </summary>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <param name="beginDate">开始时间</param>
        /// <param name="endDate">结束时间</param>
        /// <returns></returns>
        public object GetChangedCellDetails(int page, int rows, string beginDate, string endDate)
        {
            IQueryable <Storage>        storageQuery  = StorageRepository.GetQueryable();
            IQueryable <InBillAllot>    inAllotQuery  = InBillAllotRepository.GetQueryable();
            IQueryable <OutBillAllot>   outAllotQuery = OutBillAllotRepository.GetQueryable();
            IQueryable <MoveBillDetail> moveBillQuery = MoveBillDetailRepository.GetQueryable();

            if (beginDate == string.Empty || beginDate == null)
            {
                beginDate = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd");
            }
            if (endDate == string.Empty || endDate == null)
            {
                endDate = DateTime.Now.ToString("yyyy-MM-dd");
            }
            DateTime begin = Convert.ToDateTime(beginDate);
            DateTime end   = Convert.ToDateTime(endDate);

            var inCells      = inAllotQuery.Where(i => i.FinishTime >= begin && i.FinishTime <= end).OrderBy(i => i.CellCode).Select(i => i.CellCode);
            var outCells     = outAllotQuery.Where(o => o.FinishTime >= begin && o.FinishTime <= end).OrderBy(o => o.CellCode).Select(o => o.CellCode);
            var moveInCells  = moveBillQuery.Where(m => m.FinishTime >= begin && m.FinishTime <= end).OrderBy(m => m.InCell.CellCode).Select(m => m.InCell.CellCode);
            var moveOutCells = moveBillQuery.Where(m => m.FinishTime >= begin && m.FinishTime <= end).OrderBy(m => m.OutCell.CellCode).Select(m => m.OutCell.CellCode);
            var storages     = storageQuery.Where(s => s.Quantity > 0 && s.IsLock == "0" && (inCells.Any(i => i == s.CellCode) || outCells.Any(o => o == s.CellCode) || moveInCells.Any(mi => mi == s.CellCode) || moveOutCells.Any(mo => mo == s.CellCode)))
                               .OrderBy(s => s.ProductCode)
                               .Select(s => s);
            int total = storages.Count();

            storages = storages.Skip((page - 1) * rows).Take(rows);

            var temp = storages.ToArray().Select(s => new
            {
                s.StorageCode,
                s.Cell.CellCode,
                s.Cell.CellName,
                s.Product.ProductCode,
                s.Product.ProductName,
                s.Product.Unit.UnitCode,
                s.Product.Unit.UnitName,
                Quantity    = s.Quantity / s.Product.Unit.Count,
                IsActive    = s.IsActive == "1" ? "可用" : "不可用",
                StorageTime = s.StorageTime.ToString("yyyy-MM-dd"),
                UpdateTime  = s.UpdateTime.ToString("yyyy-MM-dd")
            });

            return(new { total, rows = temp.ToArray() });
        }
コード例 #9
0
        public object GetMoveBillMaster()
        {
            string str            = "";
            var    moveBillDetail = MoveBillDetailRepository.GetQueryable().Where(i => i.Status != "2").Select(b => b.BillNo).ToArray();

            for (int i = 0; i < moveBillDetail.Length; i++)
            {
                str += moveBillDetail[i];
            }
            var moveBillMaster = MoveBillMasterRepository.GetQueryable().ToArray().Where(i => str.Contains(i.BillNo) && i.Status != "6")
                                 .Distinct()
                                 .OrderByDescending(t => t.BillDate)
                                 .Select(i => new
            {
                BillNo = i.BillNo
            });

            return(moveBillMaster);
        }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
ファイル: TaskService.cs プロジェクト: radtek/wms_rfid_mdj
        private bool FinishMoveBillTask(Task task)
        {
            var moveDetail = MoveBillDetailRepository.GetQueryable()
                             .Where(i => i.BillNo == task.OrderID &&
                                    i.ID == task.AllotID &&
                                    i.Status == "1")
                             .FirstOrDefault();

            if (moveDetail != null &&
                (moveDetail.MoveBillMaster.Status == "2" ||
                 moveDetail.MoveBillMaster.Status == "3"
                ))
            {
                if (string.IsNullOrEmpty(moveDetail.InStorage.LockTag) &&
                    string.IsNullOrEmpty(moveDetail.OutStorage.LockTag) &&
                    moveDetail.InStorage.InFrozenQuantity >= moveDetail.RealQuantity &&
                    moveDetail.OutStorage.OutFrozenQuantity >= moveDetail.RealQuantity)
                {
                    moveDetail.Status                        = "2";
                    moveDetail.InStorage.Quantity           += moveDetail.RealQuantity;
                    moveDetail.InStorage.InFrozenQuantity   -= moveDetail.RealQuantity;
                    moveDetail.InStorage.Rfid                = "";
                    moveDetail.OutStorage.Quantity          -= moveDetail.RealQuantity;
                    moveDetail.OutStorage.OutFrozenQuantity -= moveDetail.RealQuantity;
                    moveDetail.OutStorage.Rfid               = "";
                    //判断移入的时间是否小于移出的时间
                    if (DateTime.Compare(moveDetail.InStorage.StorageTime, moveDetail.OutStorage.StorageTime) == 1)
                    {
                        moveDetail.InStorage.StorageTime = moveDetail.OutStorage.StorageTime;
                    }
                    moveDetail.MoveBillMaster.Status = "3";
                    moveDetail.FinishTime            = DateTime.Now;
                    var sortwork = SortWorkDispatchRepository.GetQueryable()
                                   .Where(s => s.MoveBillMaster.BillNo == moveDetail.MoveBillMaster.BillNo &&
                                          s.DispatchStatus == "2")
                                   .FirstOrDefault();
                    //修改分拣调度作业状态
                    if (sortwork != null)
                    {
                        sortwork.DispatchStatus = "3";
                    }
                    if (moveDetail.MoveBillMaster.MoveBillDetails.All(c => c.Status == "2"))
                    {
                        moveDetail.MoveBillMaster.Status = "4";
                    }

                    MoveBillDetailRepository.SaveChanges();
                    return(true);
                }
                else
                {
                    //"需确认移库的数据别人在操作或者完成的数量不对,完成出错!";
                    return(false);
                }
            }
            else
            {
                //"需确认移库的数据查询为空或者主单状态不对,完成出错!";
                return(false);
            }
        }
コード例 #12
0
        public bool Settle(string id, ref string errorInfo)
        {
            try
            {
                Guid ID       = new Guid(id);
                var  sortWork = SortWorkDispatchRepository.GetQueryable().FirstOrDefault(s => s.ID == ID);

                if (sortWork == null)
                {
                    errorInfo = "当前选择的调度记录不存在,未能结单!";
                    return(false);
                }
                if (sortWork.DispatchStatus == "1")
                {
                    errorInfo = "当前选择的调度记录不是执行中,未能结单!";
                    return(false);
                }
                if (sortWork.MoveBillMaster.Status == "1")
                {
                    errorInfo = "当前选择的调度记录移库单不是执行中,未能结单!";
                    return(false);
                }
                using (var scope = new TransactionScope())
                {
                    //移库细单解锁冻结量
                    var moveDetail = MoveBillDetailRepository.GetQueryable()
                                     .Where(m => m.BillNo == sortWork.MoveBillNo && m.Status != "2");

                    if (moveDetail.Any())
                    {
                        var sourceStorages = moveDetail.Select(m => m.OutStorage).ToArray();
                        var targetStorages = moveDetail.Select(m => m.InStorage).ToArray();

                        if (!Locker.Lock(sourceStorages) ||
                            !Locker.Lock(targetStorages))
                        {
                            errorInfo = "锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!";
                            return(false);
                        }

                        moveDetail.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("储位的卷烟或移库冻结量与当前分配不符,信息可能被异常修改,不能结单!");
                            }
                        }
                            );
                        //解锁分拣线路调度的状态,以便重新做作业调度;
                        foreach (var sortDisp in sortWork.SortOrderDispatchs)
                        {
                            sortDisp.SortWorkDispatchID = null;
                            sortDisp.WorkStatus         = "1";
                        }
                    }
                    else
                    {
                        //出库单作自动出库
                        var storages = StorageRepository.GetQueryable().Where(s => s.CellCode == sortWork.SortingLine.CellCode &&
                                                                              s.Quantity - s.OutFrozenQuantity > 0).ToArray();

                        if (!Locker.Lock(storages))
                        {
                            errorInfo = "锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!";
                            return(false);
                        }
                        var outAllots  = sortWork.OutBillMaster.OutBillAllots;
                        var outDetails = OutBillDetailRepository.GetQueryableIncludeProduct()
                                         .Where(o => o.BillNo == sortWork.OutBillMaster.BillNo);
                        outDetails.ToArray().AsParallel().ForAll(
                            (Action <OutBillDetail>) delegate(OutBillDetail o)
                        {
                            var ss = storages.Where(s => s.ProductCode == o.ProductCode).ToArray();
                            foreach (var s in ss)
                            {
                                lock (s)
                                {
                                    if (o.BillQuantity - o.AllotQuantity > 0)
                                    {
                                        decimal allotQuantity = s.Quantity;
                                        decimal billQuantity  = o.BillQuantity - o.AllotQuantity;
                                        allotQuantity         = allotQuantity < billQuantity ? allotQuantity : billQuantity;
                                        o.AllotQuantity      += allotQuantity;
                                        o.RealQuantity       += allotQuantity;
                                        s.Quantity           -= allotQuantity;

                                        var billAllot = new OutBillAllot()
                                        {
                                            BillNo          = sortWork.OutBillMaster.BillNo,
                                            OutBillDetailId = o.ID,
                                            ProductCode     = o.ProductCode,
                                            CellCode        = s.CellCode,
                                            StorageCode     = s.StorageCode,
                                            UnitCode        = o.UnitCode,
                                            AllotQuantity   = allotQuantity,
                                            RealQuantity    = allotQuantity,
                                            FinishTime      = DateTime.Now,
                                            Status          = "2"
                                        };
                                        lock (sortWork.OutBillMaster.OutBillAllots)
                                        {
                                            sortWork.OutBillMaster.OutBillAllots.Add(billAllot);
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }

                            if (o.BillQuantity - o.AllotQuantity > 0)
                            {
                                throw new Exception(sortWork.SortingLine.SortingLineName + " " + o.ProductCode + " " + o.Product.ProductName + "分拣备货区库存不足,未能结单!");
                            }
                        }
                            );

                        storages.AsParallel().ForAll(s => s.LockTag = string.Empty);
                    }

                    //出库结单
                    var outMaster = OutBillMasterRepository.GetQueryable()
                                    .FirstOrDefault(o => o.BillNo == sortWork.OutBillNo);
                    outMaster.Status     = "6";
                    outMaster.UpdateTime = DateTime.Now;
                    //移库结单
                    var moveMater = MoveBillMasterRepository.GetQueryable()
                                    .FirstOrDefault(m => m.BillNo == sortWork.MoveBillNo);
                    moveMater.Status     = "4";
                    moveMater.UpdateTime = DateTime.Now;
                    //分拣作业结单
                    sortWork.DispatchStatus = "4";
                    sortWork.UpdateTime     = DateTime.Now;
                    SortWorkDispatchRepository.SaveChanges();
                    scope.Complete();
                    return(true);
                }
            }
            catch (AggregateException ex)
            {
                errorInfo = "结单失败,详情:" + ex.InnerExceptions.Select(i => i.Message).Aggregate((m, n) => m + n);
                return(false);
            }
            catch (Exception e)
            {
                errorInfo = "结单失败,详情:" + e.Message;
                return(false);
            }
        }
コード例 #13
0
        /// <summary>获得移库细单信息</summary>
        public System.Data.DataTable GetMoveBillDetail(int page, int rows, string BillNo, bool isAbnormity, bool isGroup, out string sortingName)
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            IQueryable <THOK.Authority.DbModel.SystemParameter> systemParQuery = SystemParameterRepository.GetQueryable();

            BillNo = BillNo.Substring(0, BillNo.Length - 1);
            string[] BillNos = BillNo.Split(',');
            sortingName = "合单";
            isGroup     = true;
            if (BillNos.Count() > 0)
            {
                IQueryable <MoveBillDetail> MoveBillDetailQuery = MoveBillDetailRepository.GetQueryable();
                if (BillNos.Count() == 1)
                {
                    string billnoStr = BillNos[0].ToString();
                    var    sortWork  = SortWorkDispatchRepository.GetQueryable().FirstOrDefault(i => i.MoveBillNo == billnoStr);
                    if (sortWork != null)
                    {
                        sortingName = sortWork.SortingLine.SortingLineName;
                    }
                    else
                    {
                        sortingName = "";
                    }
                }
                var IsSummary = systemParQuery.FirstOrDefault(s => s.ParameterName == "IsSummary");//打印是否合单汇总0:不汇总;1:汇总
                if (IsSummary != null && IsSummary.ParameterValue == "0")
                {
                    isGroup = false;
                }
                var moves = MoveBillDetailQuery.Where(i => BillNos.Any(b => b == i.BillNo));
                if (isAbnormity == false)
                {
                    moves = moves.Where(i => i.Product.IsAbnormity != "1");
                }
                if (isGroup)
                {
                    var moveBillDetail = moves.Where(s => s.OutCell.Area.AreaType != "5" && s.Product.IsAbnormity == "1" && s.InCell.Area.AreaType == "5")
                                         .GroupBy(m => new { m.ProductCode, m.Product.ProductName, m.Product })
                                         .Select(r => new { r.Key.ProductCode, r.Key.ProductName, r.Key.Product, RealQuantity = r.Sum(p => p.RealQuantity) }).AsEnumerable()
                                         .Select(r => new { r.Product, isAbnormity = r.Product.IsAbnormity == "1" ? "*" : " ", r.ProductCode, r.ProductName, RealQuantity = r.RealQuantity / r.Product.Unit.Count, strRealQuantity = r.RealQuantity / r.Product.UnitList.Unit02.Count })
                                         .OrderBy(r => r.RealQuantity).ThenBy(s => s.Product.BelongRegion);

                    var moveBillDetail1 = moves.Where(s => s.OutCell.Area.AreaType != "5" && s.Product.IsAbnormity != "1" && s.InCell.Area.AreaType == "5")
                                          .GroupBy(m => new { m.ProductCode, m.Product.ProductName, m.Product })
                                          .Select(r => new { r.Key.ProductCode, r.Key.ProductName, r.Key.Product, RealQuantity = r.Sum(p => p.RealQuantity) }).AsEnumerable()
                                          .Select(r => new { r.Product, isAbnormity = r.Product.IsAbnormity == "1" ? "*" : " ", r.ProductCode, r.ProductName, RealQuantity = r.RealQuantity / r.Product.Unit.Count, strRealQuantity = r.RealQuantity / r.Product.UnitList.Unit02.Count })
                                          .OrderBy(r => r.RealQuantity).ThenBy(s => s.Product.BelongRegion);

                    var moveBillDetail2 = moves.Where(s => s.OutCell.Area.AreaType == "5" && s.InCell.Area.AreaType == "5").AsEnumerable()
                                          .Select(r => new { OutCellName = r.OutCell.CellName, InCellName = r.InCell.CellName, r.Product, isAbnormity = r.Product.IsAbnormity == "1" ? "*" : " ", r.ProductCode, r.Product.ProductName, RealQuantity = r.RealQuantity / r.Product.Unit.Count, strRealQuantity = r.RealQuantity / r.Product.UnitList.Unit02.Count })
                                          .OrderBy(r => r.RealQuantity).ThenBy(s => s.Product.BelongRegion);

                    dt.Columns.Add("产品代码", typeof(string));
                    dt.Columns.Add("产品名称", typeof(string));
                    dt.Columns.Add("数量(件)", typeof(string));
                    dt.Columns.Add("数量(条)", typeof(string));
                    dt.Columns.Add("异形烟(*)", typeof(string));
                    dt.Columns.Add("分拣互移", typeof(string));
                    dt.Columns.Add("01线签字", typeof(string));
                    dt.Columns.Add("02线签字", typeof(string));
                    foreach (var m in moveBillDetail)//异形烟
                    {
                        dt.Rows.Add
                        (
                            m.ProductCode
                            , m.ProductName
                            , m.RealQuantity
                            , m.strRealQuantity
                            , m.isAbnormity
                        );
                    }

                    foreach (var m in moveBillDetail1)//不是整托的烟和整托的烟排序
                    {
                        dt.Rows.Add
                        (
                            m.ProductCode
                            , m.ProductName
                            , m.RealQuantity
                            , m.strRealQuantity
                            , m.isAbnormity
                        );
                    }

                    foreach (var m in moveBillDetail2)//分拣线互移的烟
                    {
                        dt.Rows.Add
                        (
                            m.ProductCode
                            , m.ProductName
                            , Convert.ToDecimal(m.RealQuantity)
                            , Convert.ToDecimal(m.strRealQuantity)
                            , m.isAbnormity
                            , m.OutCellName + "移入" + m.InCellName
                        );
                    }
                    if (moveBillDetail.Count() > 0 || moveBillDetail1.Count() > 0 || moveBillDetail2.Count() > 0)
                    {
                        dt.Rows.Add(null, "总数:", moveBillDetail.Sum(m => m.RealQuantity) + moveBillDetail1.Sum(s => s.RealQuantity) + moveBillDetail2.Sum(b => b.RealQuantity));
                        dt.Rows.Add("出库:", null, "验收:", null);
                    }
                }
                else
                {
                    var moveBillDetail = moves.AsEnumerable().Select(i => new
                    {
                        OutCellName       = i.OutCell.CellName,
                        OutStorageCode    = i.OutStorageCode,
                        InCellName        = i.InCell.CellName,
                        InStorageCode     = i.InStorageCode,
                        ProductCode       = i.ProductCode,
                        ProductName       = i.Product.ProductName,
                        UnitCode          = i.UnitCode,
                        UnitName          = i.Unit.UnitName,
                        RealQuantity      = i.RealQuantity / i.Unit.Count,
                        strRealQuantity   = i.RealQuantity / i.Product.UnitList.Unit02.Count,
                        OperatePersonName = i.OperatePerson == null ? string.Empty : i.OperatePerson.EmployeeName,
                        Status            = i.Status == "0" ? "未开始" : i.Status == "1" ? "已申请" : i.Status == "2" ? "已完成" : "空",
                        isAbnormity       = i.Product.IsAbnormity == "1" ? "*" : "",
                    }).OrderBy(i => i.OutCellName).ThenBy(i => i.ProductCode);

                    dt.Columns.Add("移出储位名称", typeof(string));
                    dt.Columns.Add("移入储位名称", typeof(string));
                    dt.Columns.Add("产品代码", typeof(string));
                    dt.Columns.Add("产品名称", typeof(string));
                    //dt.Columns.Add("单位编码", typeof(string));
                    //dt.Columns.Add("单位名称", typeof(string));
                    dt.Columns.Add("数量(件)", typeof(string));
                    dt.Columns.Add("数量(条)", typeof(string));
                    dt.Columns.Add("异形烟(*)", typeof(string));
                    foreach (var m in moveBillDetail)
                    {
                        dt.Rows.Add
                        (
                            m.OutCellName
                            , m.InCellName
                            , m.ProductCode
                            , m.ProductName
                            //, m.UnitCode
                            //, m.UnitName
                            , m.RealQuantity
                            , m.strRealQuantity
                            , m.isAbnormity
                        );
                    }
                    if (moveBillDetail.Count() > 0)
                    {
                        dt.Rows.Add(null, null, null, null, "总数:", moveBillDetail.Sum(m => m.RealQuantity));
                    }
                }
            }
            return(dt);
        }
コード例 #14
0
        public bool Add(DateTime datetime, out string strResult)
        {
            bool result = false;

            strResult = string.Empty;

            var moveBillMaster = MoveBillMasterRepository.GetQueryable().Where(i => i.BillDate <= datetime);
            var moveBillDetail = MoveBillDetailRepository.GetQueryable().Where(i => i.MoveBillMaster.BillDate <= datetime);

            if (moveBillMaster.Any())
            {
                #region 主表移入历史表
                try
                {
                    foreach (var item in moveBillMaster.ToArray())
                    {
                        MoveBillMasterHistory history = new MoveBillMasterHistory();
                        history.BillNo          = item.BillNo;
                        history.BillDate        = item.BillDate;
                        history.BillTypeCode    = item.BillTypeCode;
                        history.WarehouseCode   = item.WarehouseCode;
                        history.OperatePersonID = item.OperatePersonID;
                        history.Status          = item.Status;
                        history.VerifyPersonID  = item.VerifyPersonID;
                        history.VerifyDate      = item.VerifyDate;
                        history.Description     = item.Description;
                        history.IsActive        = item.IsActive;
                        history.UpdateTime      = item.UpdateTime;
                        history.Origin          = item.Origin;
                        MoveBillMasterHistoryRepository.Add(history);
                    }
                    result = true;
                }
                catch (Exception e)
                {
                    strResult = "主库单:" + e.InnerException.ToString();
                    result    = false;
                }
                #endregion

                if (moveBillDetail.Any())
                {
                    #region 细表移入历史表
                    try
                    {
                        foreach (var item in moveBillDetail.ToArray())
                        {
                            MoveBillDetailHistory history = new MoveBillDetailHistory();
                            history.BillNo          = item.BillNo;
                            history.ProductCode     = item.ProductCode;
                            history.OutCellCode     = item.OutCellCode;
                            history.OutStorageCode  = item.OutStorageCode;
                            history.InCellCode      = item.InCellCode;
                            history.InStorageCode   = item.InStorageCode;
                            history.UnitCode        = item.UnitCode;
                            history.RealQuantity    = item.RealQuantity;
                            history.OperatePersonID = item.OperatePersonID;
                            history.StartTime       = item.StartTime;
                            history.FinishTime      = item.FinishTime;
                            history.Status          = item.Status;
                            history.Operator        = item.Operator;
                            history.CanRealOperate  = item.CanRealOperate;
                            history.PalletTag       = item.PalletTag;
                            MoveBillDetailHistoryRepository.Add(history);
                        }
                        result = true;
                    }
                    catch (Exception e)
                    {
                        strResult = "细库单:" + e.InnerException.ToString();;
                    }
                    #endregion
                }
                if (result == true)
                {
                    #region  除主细分配表
                    try
                    {
                        foreach (var item in moveBillMaster.ToList())
                        {
                            Del(MoveBillDetailRepository, item.MoveBillDetails);
                            MoveBillMasterRepository.Delete(item);
                            result = true;
                        }
                    }
                    catch (Exception e)
                    {
                        strResult = "删除情况" + e.InnerException.ToString();
                    }
                    MoveBillMasterHistoryRepository.SaveChanges();
                    #endregion
                }
            }
            else
            {
                strResult = "数据不存在!";
            }
            return(result);
        }
コード例 #15
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);
        }
コード例 #16
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);
        }
コード例 #17
0
        public bool Delete(string id, ref string errorInfo)
        {
            try
            {
                Guid ID = new Guid(id);
                var  sortOrderDispatch = SortWorkDispatchRepository.GetQueryable().FirstOrDefault(s => s.ID == ID);
                if (sortOrderDispatch == null)
                {
                    errorInfo = "当前选择的调度记录不存在,未能删除!";
                    return(false);
                }
                if (sortOrderDispatch.DispatchStatus != "1")
                {
                    errorInfo = "当前选择的调度记录不是已调度,未能删除!";
                    return(false);
                }
                if (sortOrderDispatch.OutBillMaster.Status != "1")
                {
                    errorInfo = "当前选择的调度记录出库单不是已录入,未能删除!";
                    return(false);
                }
                if (sortOrderDispatch.MoveBillMaster.Status != "1")
                {
                    errorInfo = "当前选择的调度记录移库单不是已录入,未能删除!";
                    return(false);
                }

                using (var scope = new TransactionScope())
                {
                    //解锁移库冻结量
                    var moveDetail = MoveBillDetailRepository.GetQueryable()
                                     .Where(m => m.BillNo
                                            == sortOrderDispatch.MoveBillNo);

                    var sourceStorages = moveDetail.Select(m => m.OutStorage).ToArray();
                    var targetStorages = moveDetail.Select(m => m.InStorage).ToArray();

                    if (!Locker.Lock(sourceStorages) ||
                        !Locker.Lock(targetStorages))
                    {
                        errorInfo = "锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!";
                        return(false);
                    }

                    moveDetail.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("储位的卷烟或移库冻结量与当前分配不符,信息可能被异常修改,不能删除!");
                        }
                    }
                        );

                    Del(MoveBillDetailRepository, sortOrderDispatch.MoveBillMaster.MoveBillDetails); //删除移库细单
                    MoveBillMasterRepository.Delete(sortOrderDispatch.MoveBillMaster);               //删除移库主单

                    Del(OutBillDetailRepository, sortOrderDispatch.OutBillMaster.OutBillDetails);    //删除出库细单
                    OutBillMasterRepository.Delete(sortOrderDispatch.OutBillMaster);                 //删除出库主单

                    //修改线路调度表中作业状态
                    var sortDisp = SortOrderDispatchRepository.GetQueryable()
                                   .Where(s => s.SortWorkDispatchID
                                          == sortOrderDispatch.ID);
                    foreach (var item in sortDisp.ToArray())
                    {
                        item.WorkStatus         = "1";
                        item.SortWorkDispatchID = null;
                    }
                    SortWorkDispatchRepository.Delete(sortOrderDispatch);
                    SortWorkDispatchRepository.SaveChanges();
                    scope.Complete();
                    return(true);
                }
            }
            catch (Exception e)
            {
                errorInfo = "删除失败,详情:" + e.Message;
                return(false);
            }
        }
コード例 #18
0
        /// <summary>
        /// 根据参数生成并保存盘点数据  --异动生成
        /// </summary>
        /// <param name="beginDate">开始时间</param>
        /// <param name="endDate">结束时间</param>
        /// <param name="UserName">登陆用户</param>
        /// <returns></returns>
        public bool ChangedAdd(string beginDate, string endDate, string UserName, string billType, out string info)
        {
            bool result = false;

            info = string.Empty;
            IQueryable <Warehouse>      wareQuery     = WarehouseRepository.GetQueryable();
            IQueryable <Storage>        storageQuery  = StorageRepository.GetQueryable();
            IQueryable <InBillAllot>    inAllotQuery  = InBillAllotRepository.GetQueryable();
            IQueryable <OutBillAllot>   outAllotQuery = OutBillAllotRepository.GetQueryable();
            IQueryable <MoveBillDetail> moveBillQuery = MoveBillDetailRepository.GetQueryable();
            var employee = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.UserName == UserName);

            if (employee != null)
            {
                if (beginDate == string.Empty || beginDate == null)
                {
                    beginDate = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd");
                }
                if (endDate == string.Empty || endDate == null)
                {
                    endDate = DateTime.Now.ToString("yyyy-MM-dd");
                }
                DateTime begin = Convert.ToDateTime(beginDate);
                DateTime end   = Convert.ToDateTime(endDate);
                try
                {
                    using (var scope = new TransactionScope())
                    {
                        Console.WriteLine("start");
                        var sw = new Stopwatch();
                        sw.Start();

                        #region 循环所有仓库的订单,一个仓库一个盘点单据
                        var warehouses = wareQuery.OrderBy(w => w.WarehouseCode);
                        foreach (var item in warehouses.ToArray())
                        {
                            var inCells      = inAllotQuery.Where(i => i.FinishTime >= begin && i.FinishTime <= end && i.Cell.WarehouseCode == item.WarehouseCode).OrderBy(i => i.CellCode).Select(i => i.CellCode);
                            var outCells     = outAllotQuery.Where(o => o.FinishTime >= begin && o.FinishTime <= end && o.Cell.WarehouseCode == item.WarehouseCode).OrderBy(o => o.CellCode).Select(o => o.CellCode);
                            var moveInCells  = moveBillQuery.Where(m => m.FinishTime >= begin && m.FinishTime <= end && m.InCell.WarehouseCode == item.WarehouseCode).OrderBy(m => m.InCell.CellCode).Select(m => m.InCell.CellCode);
                            var moveOutCells = moveBillQuery.Where(m => m.FinishTime >= begin && m.FinishTime <= end && m.OutCell.WarehouseCode == item.WarehouseCode).OrderBy(m => m.OutCell.CellCode).Select(m => m.OutCell.CellCode);
                            var storages     = storageQuery.Where(s => s.Quantity > 0 && s.IsLock == "0" && (inCells.Any(i => i == s.CellCode) || outCells.Any(o => o == s.CellCode) || moveInCells.Any(mi => mi == s.CellCode) || moveOutCells.Any(mo => mo == s.CellCode)))
                                               .OrderBy(s => s.ProductCode)
                                               .Select(s => s).ToArray();
                            if (storages.Any())
                            {
                                string billNo = GetCheckBillNo().ToString();
                                var    check  = new CheckBillMaster();
                                check.BillNo          = billNo;
                                check.BillDate        = DateTime.Now;
                                check.BillTypeCode    = billType;
                                check.WarehouseCode   = item.WarehouseCode;
                                check.OperatePersonID = employee.ID;
                                check.Status          = "1";
                                check.IsActive        = "1";
                                check.UpdateTime      = DateTime.Now;

                                CheckBillMasterRepository.Add(check);
                                storages.AsParallel().ForAll(stor =>
                                {
                                    var checkDetail             = new CheckBillDetail();
                                    checkDetail.CellCode        = stor.CellCode;
                                    checkDetail.StorageCode     = stor.StorageCode;
                                    checkDetail.ProductCode     = stor.ProductCode;
                                    checkDetail.UnitCode        = stor.Product.UnitCode;
                                    checkDetail.Quantity        = stor.Quantity;
                                    checkDetail.RealProductCode = stor.ProductCode;
                                    checkDetail.RealUnitCode    = stor.Product.UnitCode;
                                    checkDetail.RealQuantity    = stor.Quantity;
                                    checkDetail.Status          = "0";
                                    lock (check.CheckBillDetails)
                                    {
                                        check.CheckBillDetails.Add(checkDetail);
                                    }
                                    stor.IsLock = "1";
                                });
                                result = true;
                            }
                            else
                            {
                                info = "所选择查询的时间无数据!";
                            }
                        }

                        CheckBillMasterRepository.SaveChanges();
                        #endregion

                        sw.Stop();
                        Console.WriteLine(sw.ElapsedMilliseconds);

                        sw.Restart();
                        CheckBillMasterRepository.SaveChanges();
                        sw.Stop();
                        Console.WriteLine(sw.ElapsedMilliseconds);
                        scope.Complete();
                    }
                }
                catch (Exception e)
                {
                    result = false;
                    info   = e.Message;
                }
            }
            return(result);
        }
コード例 #19
0
        public void Dispatch(string connectionId, Model.ProgressState ps, CancellationToken cancellationToken, string workDispatchId, string userName)
        {
            Locker.LockKey = workDispatchId;
            ConnectionId   = connectionId;
            ps.State       = StateType.Start;
            NotifyConnection(ps.Clone());

            IQueryable <SortOrderDispatch> sortOrderDispatchQuery = SortOrderDispatchRepository.GetQueryable();
            IQueryable <SortOrder>         sortOrderQuery         = SortOrderRepository.GetQueryable();
            IQueryable <SortOrderDetail>   sortOrderDetailQuery   = SortOrderDetailRepository.GetQueryable();

            IQueryable <OutBillMaster>  outBillMasterQuery  = OutBillMasterRepository.GetQueryable();
            IQueryable <OutBillDetail>  outBillDetailQuery  = OutBillDetailRepository.GetQueryable();
            IQueryable <MoveBillMaster> moveBillMasterQuery = MoveBillMasterRepository.GetQueryable();
            IQueryable <MoveBillDetail> moveBillDetailQuery = MoveBillDetailRepository.GetQueryable();

            IQueryable <SortingLowerlimit> sortingLowerlimitQuery = SortingLowerlimitRepository.GetQueryable();
            IQueryable <SortingLine>       sortingLineQuery       = SortingLineRepository.GetQueryable();
            IQueryable <Storage>           storageQuery           = StorageRepository.GetQueryable();

            IQueryable <SortWorkDispatch> sortWorkDispatchQuery = SortWorkDispatchRepository.GetQueryable();

            workDispatchId = workDispatchId.Substring(0, workDispatchId.Length - 1);
            int[] work = workDispatchId.Split(',').Select(s => Convert.ToInt32(s)).ToArray();

            //调度表未作业的数据
            var temp = sortOrderDispatchQuery.Where(s => work.Any(w => w == s.ID) && s.WorkStatus == "1")
                       .Join(sortOrderQuery,
                             dp => new { dp.OrderDate, dp.DeliverLineCode },
                             om => new { om.OrderDate, om.DeliverLineCode },
                             (dp, om) => new { dp.OrderDate, dp.SortingLine, dp.DeliverLineCode, om.OrderID }
                             ).Join(sortOrderDetailQuery,
                                    dm => new { dm.OrderID },
                                    od => new { od.OrderID },
                                    (dm, od) => new { dm.OrderDate, dm.SortingLine, od.Product, od.UnitCode, od.Price, od.RealQuantity }
                                    ).GroupBy(r => new { r.OrderDate, r.SortingLine, r.Product, r.UnitCode, r.Price })
                       .Select(r => new { r.Key.OrderDate, r.Key.SortingLine, r.Key.Product, r.Key.UnitCode, r.Key.Price, SumQuantity = r.Sum(p => p.RealQuantity * r.Key.Product.UnitList.Unit02.Count) })
                       .GroupBy(r => new { r.OrderDate, r.SortingLine })
                       .Select(r => new { r.Key.OrderDate, r.Key.SortingLine, Products = r })
                       .ToArray();

            var    employee        = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);
            string operatePersonID = employee != null?employee.ID.ToString() : "";

            if (employee == null)
            {
                ps.State = StateType.Error;
                ps.Errors.Add("未找到当前用户,或当前用户不可用!");
                NotifyConnection(ps.Clone());
                return;
            }

            decimal sumAllotQuantity     = 0;
            decimal sumAllotLineQuantity = 0;

            MoveBillMaster lastMoveBillMaster = null;

            foreach (var item in temp)
            {
                try
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    bool hasError = false;
                    ps.State = StateType.Info;
                    ps.Messages.Add("开始调度" + item.SortingLine.SortingLineName);
                    NotifyConnection(ps.Clone());

                    using (var scope = new TransactionScope())
                    {
                        if (item.Products.Count() > 0)
                        {
                            if (cancellationToken.IsCancellationRequested)
                            {
                                return;
                            }

                            if (lastMoveBillMaster != null && lastMoveBillMaster.WarehouseCode != item.SortingLine.Cell.WarehouseCode)
                            {
                                if (MoveBillCreater.CheckIsNeedSyncMoveBill(lastMoveBillMaster.WarehouseCode))
                                {
                                    MoveBillCreater.CreateSyncMoveBillDetail(lastMoveBillMaster);
                                }
                            }

                            sumAllotLineQuantity = 0;

                            if (cancellationToken.IsCancellationRequested)
                            {
                                return;
                            }
                            MoveBillMaster moveBillMaster = MoveBillCreater.CreateMoveBillMaster(item.SortingLine.Cell.WarehouseCode,
                                                                                                 item.SortingLine.MoveBillTypeCode,
                                                                                                 operatePersonID);
                            moveBillMaster.Origin      = "2";
                            moveBillMaster.Description = "分拣调度生成!";
                            lastMoveBillMaster         = moveBillMaster;
                            foreach (var product in item.Products.ToArray())
                            {
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }

                                decimal sumBillQuantity = temp.Sum(t => t.Products.Sum(p => p.SumQuantity));
                                sumAllotQuantity += product.SumQuantity;

                                decimal sumBillProductQuantity = item.Products.Sum(p => p.SumQuantity);
                                sumAllotLineQuantity += product.SumQuantity;

                                ps.State                = StateType.Processing;
                                ps.TotalProgressName    = "分拣作业调度";
                                ps.TotalProgressValue   = (int)(sumAllotQuantity / sumBillQuantity * 100);
                                ps.CurrentProgressName  = "正在调度:" + item.SortingLine.SortingLineName;
                                ps.CurrentProgressValue = (int)(sumAllotLineQuantity / sumBillProductQuantity * 100);
                                NotifyConnection(ps.Clone());

                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }
                                //获取分拣线下限数据
                                var sortingLowerlimitQuantity = sortingLowerlimitQuery.Where(s => s.ProductCode == product.Product.ProductCode &&
                                                                                             s.SortingLineCode == product.SortingLine.SortingLineCode);
                                decimal lowerlimitQuantity = 0;
                                if (sortingLowerlimitQuantity.Count() > 0)
                                {
                                    lowerlimitQuantity = sortingLowerlimitQuantity.Sum(s => s.Quantity);
                                }

                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }
                                //获取分拣备货区库存
                                var storageQuantity = storageQuery.Where(s => s.ProductCode == product.Product.ProductCode)
                                                      .Join(sortingLineQuery,
                                                            s => s.Cell,
                                                            l => l.Cell,
                                                            (s, l) => new { l.SortingLineCode, s.Quantity }
                                                            )
                                                      .Where(r => r.SortingLineCode == product.SortingLine.SortingLineCode);
                                decimal storQuantity = 0;
                                if (storageQuantity.Count() > 0)
                                {
                                    storQuantity = storageQuantity.Sum(s => s.Quantity);
                                }
                                //获取当前这个卷烟库存数量
                                string[] areaTypes        = new string[] { "1", "2", "4" };
                                var      areaSumQuantitys = storageQuery.Where(s => areaTypes.Any(t => t == s.Cell.Area.AreaType) &&
                                                                               s.ProductCode == product.Product.ProductCode).ToArray();
                                decimal areaQuantiy = 0;
                                if (areaSumQuantitys.Count() > 0)
                                {
                                    areaQuantiy = areaSumQuantitys.Sum(s => s.Quantity - s.OutFrozenQuantity);
                                }

                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }

                                //获取移库量(按整件计)出库量加上下限量减去备货区库存量取整
                                decimal quantity = 0;

                                quantity = Math.Ceiling((product.SumQuantity + lowerlimitQuantity - storQuantity) / product.Product.Unit.Count)
                                           * product.Product.Unit.Count;

                                if (areaQuantiy < quantity)//判断当前这个卷烟库存是否小于移库量
                                {
                                    //出库量减去备货区库存量取整
                                    quantity = Math.Ceiling((product.SumQuantity - storQuantity) / product.Product.Unit.Count)
                                               * product.Product.Unit.Count;

                                    if (areaQuantiy < quantity)
                                    {
                                        //出库量减去备货区库存量
                                        quantity = product.SumQuantity - storQuantity;
                                    }
                                }

                                if (quantity > 0)
                                {
                                    if (cancellationToken.IsCancellationRequested)
                                    {
                                        return;
                                    }
                                    AlltoMoveBill(moveBillMaster, product.Product, item.SortingLine.Cell, ref quantity, cancellationToken, ps, item.SortingLine.Cell.CellCode);
                                }

                                if (quantity > 0)
                                {
                                    //生成移库不完整,可能是库存不足;
                                    hasError = true;
                                    ps.State = StateType.Error;
                                    ps.Errors.Add(product.Product.ProductCode + " " + product.Product.ProductName + " 库存不足!");
                                    NotifyConnection(ps.Clone());
                                }
                            }

                            if (!hasError)
                            {
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }

                                OutBillMaster outBillMaster = OutBillCreater.CreateOutBillMaster(item.SortingLine.Cell.WarehouseCode,
                                                                                                 item.SortingLine.OutBillTypeCode,
                                                                                                 operatePersonID);
                                outBillMaster.Origin      = "2";
                                outBillMaster.Description = "分拣调度生成!";
                                //添加出库单细单
                                foreach (var product in item.Products.ToArray())
                                {
                                    if (cancellationToken.IsCancellationRequested)
                                    {
                                        return;
                                    }
                                    OutBillCreater.AddToOutBillDetail(outBillMaster, product.Product, product.Price, product.SumQuantity);
                                }

                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }
                                //添加出库、移库主单和作业调度表
                                SortWorkDispatch sortWorkDisp = AddSortWorkDispMaster(moveBillMaster, outBillMaster, item.SortingLine.SortingLineCode, item.OrderDate);

                                //修改线路调度作业状态和作业ID
                                var sortDispTemp = sortOrderDispatchQuery.Where(s => work.Any(w => w == s.ID) &&
                                                                                s.OrderDate == item.OrderDate &&
                                                                                s.SortingLineCode == item.SortingLine.SortingLineCode);

                                foreach (var sortDisp in sortDispTemp.ToArray())
                                {
                                    if (cancellationToken.IsCancellationRequested)
                                    {
                                        return;
                                    }
                                    sortDisp.SortWorkDispatchID = sortWorkDisp.ID;
                                    sortDisp.WorkStatus         = "2";
                                }
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }
                                SortWorkDispatchRepository.SaveChanges();
                                scope.Complete();
                                ps.Messages.Add(item.SortingLine.SortingLineName + " 调度成功!");
                            }
                            else
                            {
                                ps.State = StateType.Info;
                                ps.Messages.Add(item.SortingLine.SortingLineName + " 调度失败!");
                                NotifyConnection(ps.Clone());
                                return;
                            }
                        }
                    }
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }
                    if (MoveBillCreater.CheckIsNeedSyncMoveBill(lastMoveBillMaster.WarehouseCode))
                    {
                        MoveBillCreater.CreateSyncMoveBillDetail(lastMoveBillMaster);
                    }
                    MoveBillMasterRepository.SaveChanges();
                }
                catch (Exception e)
                {
                    ps.State = StateType.Info;
                    ps.Errors.Add(item.SortingLine.SortingLineName + "作业调度失败! 详情:" + e.Message);
                    NotifyConnection(ps.Clone());
                    return;
                }
            }

            ps.State = StateType.Info;
            ps.Messages.Add("调度完成!");
            NotifyConnection(ps.Clone());
        }
コード例 #20
0
        public void Dispatch(string connectionId, Model.ProgressState ps, CancellationToken cancellationToken, string workDispatchId, string userName)
        {
            Locker.LockKey = workDispatchId;
            ConnectionId   = connectionId;
            ps.State       = StateType.Start;
            NotifyConnection(ps.Clone());

            IQueryable <SortOrderDispatch> sortOrderDispatchQuery = SortOrderDispatchRepository.GetQueryable();
            IQueryable <SortOrder>         sortOrderQuery         = SortOrderRepository.GetQueryable();
            IQueryable <SortOrderDetail>   sortOrderDetailQuery   = SortOrderDetailRepository.GetQueryable();

            IQueryable <OutBillMaster>  outBillMasterQuery  = OutBillMasterRepository.GetQueryable();
            IQueryable <OutBillDetail>  outBillDetailQuery  = OutBillDetailRepository.GetQueryable();
            IQueryable <MoveBillMaster> moveBillMasterQuery = MoveBillMasterRepository.GetQueryable();
            IQueryable <MoveBillDetail> moveBillDetailQuery = MoveBillDetailRepository.GetQueryable();

            IQueryable <SortingLowerlimit> sortingLowerlimitQuery = SortingLowerlimitRepository.GetQueryable();
            IQueryable <SortingLine>       sortingLineQuery       = SortingLineRepository.GetQueryable();
            IQueryable <Storage>           storageQuery           = StorageRepository.GetQueryable();

            IQueryable <SortWorkDispatch> sortWorkDispatchQuery = SortWorkDispatchRepository.GetQueryable();

            IQueryable <THOK.Authority.DbModel.SystemParameter> systemParQuery = SystemParameterRepository.GetQueryable();


            var IsUselowerlimit = systemParQuery.FirstOrDefault(s => s.ParameterName == "IsUselowerlimit"); //查询调度是否使用下限 0 否 1是
            var isRoundingTray  = systemParQuery.FirstOrDefault(s => s.ParameterName == "isRoundingTray");  //查询立式机总量大于20件的是否取整托盘 0表示不取整托盘。其它任意数字表示大于的总数

            workDispatchId = workDispatchId.Substring(0, workDispatchId.Length - 1);
            int[] work = workDispatchId.Split(',').Select(s => Convert.ToInt32(s)).ToArray();

            //调度表未作业的数据
            var temp = sortOrderDispatchQuery.Join(sortOrderQuery,
                                                   dp => new { dp.OrderDate, dp.DeliverLineCode },
                                                   om => new { om.OrderDate, om.DeliverLineCode },
                                                   (dp, om) => new { dp.ID, dp.WorkStatus, dp.OrderDate, dp.SortingLine, dp.DeliverLineCode, om.OrderID }
                                                   ).Join(sortOrderDetailQuery,
                                                          dm => new { dm.OrderID },
                                                          od => new { od.OrderID },
                                                          (dm, od) => new { dm.ID, dm.WorkStatus, dm.OrderDate, dm.SortingLine, od.Product, od.UnitCode, od.Price, od.RealQuantity }
                                                          ).WhereIn(s => s.ID, work)
                       .Where(s => s.WorkStatus == "1")
                       .GroupBy(r => new { r.OrderDate, r.SortingLine, r.Product, r.UnitCode, r.Price })
                       .Select(r => new { r.Key.OrderDate, r.Key.SortingLine, r.Key.Product, r.Key.UnitCode, r.Key.Price, SumQuantity = r.Sum(p => p.RealQuantity * r.Key.Product.UnitList.Unit02.Count) })
                       .AsParallel()
                       .GroupBy(r => new { r.OrderDate, r.SortingLine })
                       .Select(r => new { r.Key.OrderDate, r.Key.SortingLine, Products = r })
                       .OrderBy(s => s.SortingLine.SortingLineCode)                      //如果取整托盘多余的量是1号线就倒序排序,目前多余的量放入2号线,所以先调度一号线
                       .ToArray();

            var temp1 = sortingLowerlimitQuery.GroupBy(r => new { r.Product, r.SortType })
                        .Select(s => new { s.Key.Product, s.Key.SortType }).ToArray();

            var temp2 = sortOrderDispatchQuery.Join(sortOrderQuery,
                                                    dp => new { dp.OrderDate, dp.DeliverLineCode },
                                                    om => new { om.OrderDate, om.DeliverLineCode },
                                                    (dp, om) => new { dp.ID, dp.WorkStatus, dp.OrderDate, om.OrderID }
                                                    ).Join(sortOrderDetailQuery,
                                                           dm => new { dm.OrderID },
                                                           od => new { od.OrderID },
                                                           (dm, od) => new { dm.ID, dm.WorkStatus, od.Product, od.RealQuantity }
                                                           ).WhereIn(s => s.ID, work)
                        .GroupBy(r => new { r.Product })
                        .Select(s => new { s.Key.Product, Quantity = s.Sum(p => p.RealQuantity * s.Key.Product.UnitList.Unit02.Count) })
                        .ToArray();

            Dictionary <string, decimal> proQuan = new Dictionary <string, decimal>();

            var    employee        = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);
            string operatePersonID = employee != null?employee.ID.ToString() : "";

            if (employee == null)
            {
                ps.State = StateType.Error;
                ps.Errors.Add("未找到当前用户,或当前用户不可用!");
                NotifyConnection(ps.Clone());
                return;
            }

            decimal sumAllotQuantity     = 0;
            decimal sumAllotLineQuantity = 0;

            MoveBillMaster lastMoveBillMaster = null;

            foreach (var item in temp)
            {
                try
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    bool hasError = false;
                    ps.State = StateType.Info;
                    ps.Messages.Add("开始调度" + item.SortingLine.SortingLineName);
                    NotifyConnection(ps.Clone());

                    //using (var scope = new TransactionScope())
                    //{
                    if (item.Products.Count() > 0)
                    {
                        if (cancellationToken.IsCancellationRequested)
                        {
                            return;
                        }

                        if (lastMoveBillMaster != null && lastMoveBillMaster.WarehouseCode != item.SortingLine.Cell.WarehouseCode)
                        {
                            if (MoveBillCreater.CheckIsNeedSyncMoveBill(lastMoveBillMaster.WarehouseCode))
                            {
                                MoveBillCreater.CreateSyncMoveBillDetail(lastMoveBillMaster);
                            }
                        }

                        sumAllotLineQuantity = 0;

                        if (cancellationToken.IsCancellationRequested)
                        {
                            return;
                        }
                        MoveBillMaster moveBillMaster = MoveBillCreater.CreateMoveBillMaster(item.SortingLine.Cell.WarehouseCode,
                                                                                             item.SortingLine.MoveBillTypeCode,
                                                                                             operatePersonID);
                        moveBillMaster.Origin      = "2";
                        moveBillMaster.Description = item.SortingLine.SortingLineCode + " 分拣调度生成!";
                        lastMoveBillMaster         = moveBillMaster;
                        foreach (var product in item.Products.ToArray())
                        {
                            if (product.SumQuantity > 0)
                            {
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }

                                decimal sumBillQuantity = temp.Sum(t => t.Products.Sum(p => p.SumQuantity));
                                sumAllotQuantity += product.SumQuantity;

                                decimal sumBillProductQuantity = item.Products.Sum(p => p.SumQuantity);
                                sumAllotLineQuantity += product.SumQuantity;

                                ps.State                = StateType.Processing;
                                ps.TotalProgressName    = "分拣作业调度";
                                ps.TotalProgressValue   = (int)(sumAllotQuantity / sumBillQuantity * 100);
                                ps.CurrentProgressName  = "正在调度:" + item.SortingLine.SortingLineName;
                                ps.CurrentProgressValue = (int)(sumAllotLineQuantity / sumBillProductQuantity * 100);
                                NotifyConnection(ps.Clone());

                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }
                                //获取分拣线下限数据
                                var sortingLowerlimitQuantity = sortingLowerlimitQuery.Where(s => s.ProductCode == product.Product.ProductCode &&
                                                                                             s.SortingLineCode == product.SortingLine.SortingLineCode);
                                decimal lowerlimitQuantity = 0;
                                if (sortingLowerlimitQuantity.Count() > 0)
                                {
                                    lowerlimitQuantity = sortingLowerlimitQuantity.Sum(s => s.Quantity);
                                }

                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }
                                //获取分拣备货区库存
                                var storageQuantity = storageQuery.Where(s => s.ProductCode == product.Product.ProductCode)
                                                      .Join(sortingLineQuery,
                                                            s => s.Cell,
                                                            l => l.Cell,
                                                            (s, l) => new { l.SortingLineCode, s.Quantity }
                                                            )
                                                      .Where(r => r.SortingLineCode == product.SortingLine.SortingLineCode);
                                decimal storQuantity = 0;
                                if (storageQuantity.Count() > 0)
                                {
                                    storQuantity = storageQuantity.Sum(s => s.Quantity);
                                }
                                //获取当前这个卷烟库存数量
                                string[] areaTypes        = new string[] { "1", "2", "4" };
                                var      areaSumQuantitys = storageQuery.Where(s => areaTypes.Any(t => t == s.Cell.Area.AreaType) &&
                                                                               s.ProductCode == product.Product.ProductCode).ToArray();
                                decimal areaQuantiy = 0;
                                if (areaSumQuantitys.Count() > 0)
                                {
                                    areaQuantiy = areaSumQuantitys.Sum(s => s.Quantity - s.OutFrozenQuantity);
                                }

                                //是否使用下限
                                if (IsUselowerlimit != null && IsUselowerlimit.ParameterValue == "0")
                                {
                                    lowerlimitQuantity = 0;
                                }

                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }

                                //获取移库量(按整件计)出库量加上下限量减去备货区库存量取整
                                decimal quantity = 0;

                                quantity = Math.Ceiling((product.SumQuantity + lowerlimitQuantity - storQuantity) / product.Product.Unit.Count)
                                           * product.Product.Unit.Count;

                                //立式机大于20件的取整托盘
                                //查询这个卷烟是否是立式机的卷烟
                                if (isRoundingTray != null && Convert.ToInt32(isRoundingTray.ParameterValue) > 0)
                                {
                                    var temp3 = temp1.FirstOrDefault(s => s.Product.ProductCode == product.Product.ProductCode && s.SortType == "1");
                                    if (temp3 != null && temp.Count() >= 2 && quantity > 0)
                                    {
                                        //查询这个订单在分拣当中是否存在.大于20件取整托盘,
                                        var SumlowerlimitQuantity = temp2.FirstOrDefault(s => s.Product.ProductCode == temp3.Product.ProductCode);
                                        if (SumlowerlimitQuantity != null && SumlowerlimitQuantity.Quantity > (Convert.ToInt32(isRoundingTray.ParameterValue) * product.Product.Unit.Count))
                                        {
                                            decimal WholeCare          = 0; //托盘数
                                            decimal SumSortingQuantity = 0; //整托盘的数量
                                            decimal Quantity1          = 0;
                                            decimal Quantity2          = 0;
                                            //取2条线数量总和取整托盘
                                            WholeCare          = Math.Ceiling(SumlowerlimitQuantity.Quantity / (product.Product.CellMaxProductQuantity * product.Product.Unit.Count));
                                            SumSortingQuantity = Convert.ToDecimal(WholeCare * (product.Product.Unit.Count * product.Product.CellMaxProductQuantity));

                                            if (item.SortingLine.SortingLineCode == "1")
                                            {
                                                //总订单量减去当前分拣线订单量,这里是另一条线的量
                                                Quantity1 = SumlowerlimitQuantity.Quantity - product.SumQuantity;
                                                if (Quantity1 > 0)
                                                {
                                                    //整托盘数量减去另一条线的量,
                                                    Quantity1 = Math.Ceiling(Quantity1 / product.Product.Unit.Count) * product.Product.Unit.Count;
                                                    Quantity2 = SumSortingQuantity - Quantity1;

                                                    if (Quantity2 >= quantity)
                                                    {
                                                        quantity = Quantity2;
                                                        proQuan.Add(product.Product.ProductCode, SumSortingQuantity - quantity);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (proQuan.Keys.Contains(product.Product.ProductCode))
                                                {
                                                    if (proQuan[product.Product.ProductCode] >= quantity)
                                                    {
                                                        quantity = proQuan[product.Product.ProductCode];
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                //取整托盘,查询这个卷烟是否是通道机的卷烟
                                decimal wholeTray = 0;
                                var     temp4     = temp1.FirstOrDefault(s => s.Product.ProductCode == product.Product.ProductCode && s.SortType == "2");
                                if (product.Product.IsRounding == "2" || temp4 != null)
                                {
                                    wholeTray = Math.Ceiling(quantity / (product.Product.CellMaxProductQuantity * product.Product.Unit.Count));
                                    quantity  = Convert.ToDecimal(wholeTray * (product.Product.Unit.Count * product.Product.CellMaxProductQuantity));
                                }

                                if (areaQuantiy < quantity)    //判断当前这个卷烟库存是否小于移库量
                                {
                                    //出库量减去备货区库存量取整
                                    quantity = Math.Ceiling((product.SumQuantity - storQuantity) / product.Product.Unit.Count)
                                               * product.Product.Unit.Count;

                                    if (areaQuantiy < quantity)
                                    {
                                        //出库量减去备货区库存量
                                        quantity = product.SumQuantity - storQuantity;
                                    }
                                }

                                //不取整的烟直接出库。
                                if (product.Product.IsRounding == "1")
                                {
                                    quantity = product.SumQuantity - storQuantity;
                                }

                                if (quantity > 0)
                                {
                                    if (cancellationToken.IsCancellationRequested)
                                    {
                                        return;
                                    }
                                    AlltoMoveBill(moveBillMaster, product.Product, item.SortingLine.Cell, ref quantity, cancellationToken, ps, item.SortingLine.Cell.CellCode);
                                }

                                if (quantity > 0)
                                {
                                    //生成移库不完整,可能是库存不足;
                                    hasError = true;
                                    ps.State = StateType.Error;
                                    ps.Errors.Add(item.SortingLine.SortingLineCode + "线," + product.Product.ProductCode + " " + product.Product.ProductName + ",库存不足!当前总量:" + Convert.ToDecimal(product.SumQuantity / product.Product.UnitList.Unit02.Count) + "(条),缺少:" + Convert.ToDecimal(quantity / product.Product.UnitList.Unit02.Count) + "(条)");
                                    NotifyConnection(ps.Clone());
                                }
                            }
                        }

                        if (!hasError)
                        {
                            if (cancellationToken.IsCancellationRequested)
                            {
                                return;
                            }

                            OutBillMaster outBillMaster = OutBillCreater.CreateOutBillMaster(item.SortingLine.Cell.WarehouseCode,
                                                                                             item.SortingLine.OutBillTypeCode,
                                                                                             operatePersonID);
                            outBillMaster.Origin      = "2";
                            outBillMaster.Description = item.SortingLine.SortingLineCode + " 分拣调度生成!";
                            //添加出库单细单
                            foreach (var product in item.Products.ToArray())
                            {
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }
                                OutBillCreater.AddToOutBillDetail(outBillMaster, product.Product, product.Price, product.SumQuantity);
                            }

                            if (cancellationToken.IsCancellationRequested)
                            {
                                return;
                            }
                            //添加出库、移库主单和作业调度表
                            SortWorkDispatch sortWorkDisp = AddSortWorkDispMaster(moveBillMaster, outBillMaster, item.SortingLine.SortingLineCode, item.OrderDate);

                            //修改线路调度作业状态和作业ID
                            var sortDispTemp = sortOrderDispatchQuery.WhereIn(s => s.ID, work)
                                               .Where(s => s.OrderDate == item.OrderDate &&
                                                      s.SortingLineCode == item.SortingLine.SortingLineCode);

                            foreach (var sortDisp in sortDispTemp.ToArray())
                            {
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }
                                sortDisp.SortWorkDispatchID = sortWorkDisp.ID;
                                sortDisp.WorkStatus         = "2";
                            }
                            if (cancellationToken.IsCancellationRequested)
                            {
                                return;
                            }
                            SortWorkDispatchRepository.SaveChanges();
                            //scope.Complete();
                            ps.Messages.Add(item.SortingLine.SortingLineName + " 调度成功!");
                        }
                        else
                        {
                            ps.State = StateType.Info;
                            ps.Messages.Add(item.SortingLine.SortingLineName + " 调度失败!");
                            NotifyConnection(ps.Clone());
                            return;
                        }
                    }
                    //}
                }
                catch (Exception e)
                {
                    ps.State = StateType.Info;
                    ps.Errors.Add(item.SortingLine.SortingLineName + "作业调度失败! 详情:" + e.Message);
                    NotifyConnection(ps.Clone());
                    return;
                }
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            if (MoveBillCreater.CheckIsNeedSyncMoveBill(lastMoveBillMaster.WarehouseCode))
            {
                MoveBillCreater.CreateSyncMoveBillDetail(lastMoveBillMaster);
            }
            MoveBillMasterRepository.SaveChanges();

            ps.State = StateType.Info;
            ps.Messages.Add("调度完成!");
            NotifyConnection(ps.Clone());
        }
コード例 #21
0
        /// <summary>
        /// 移库单据作业
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <param name="errInfo">错误消息</param>
        /// <returns></returns>
        public bool MoveBillTask(string billNo, out string errorInfo)
        {
            bool result = true;

            errorInfo = string.Empty;
            try
            {
                var moveQuery = MoveBillDetailRepository.GetQueryable().Where(i => i.BillNo == billNo);
                if (moveQuery.Any())
                {
                    foreach (var moveItem in moveQuery.ToArray())
                    {
                        //根据“移出的货位信息的编码”查找“起始的位置信息”
                        var originCellPosition = CellPositionRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveItem.OutCellCode);
                        if (originCellPosition != null)
                        {
                            //根据“移入的货位信息”查找“目标货位位置”
                            var targetCellPosition = CellPositionRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveItem.InCellCode);
                            if (targetCellPosition != null)
                            {
                                //根据“移出的位置信息ID”去找“起始位置的位置信息”
                                var originPosition = PositionRepository.GetQueryable().FirstOrDefault(p => p.ID == originCellPosition.StockOutPositionID);
                                if (originPosition != null)
                                {
                                    //根据“移入位置ID”去找“目标位置的区域ID”信息
                                    var targetPosition = PositionRepository.GetQueryable().FirstOrDefault(p => p.ID == targetCellPosition.StockInPositionID);
                                    if (targetPosition != null)
                                    {
                                        //根据“入库的目标位置信息的区域ID”和"起始的位置信息的区域ID"去找"路径信息"
                                        var path = PathRepository.GetQueryable().FirstOrDefault(p => p.OriginRegionID == originPosition.RegionID && p.TargetRegionID == targetPosition.RegionID);
                                        if (path != null)
                                        {
                                            var moveTask = new Task();
                                            moveTask.TaskType             = "01";
                                            moveTask.TaskLevel            = 0;
                                            moveTask.PathID               = path.ID;
                                            moveTask.ProductCode          = moveItem.Product.ProductCode;
                                            moveTask.ProductName          = moveItem.Product.ProductName;
                                            moveTask.OriginStorageCode    = moveItem.OutCellCode;
                                            moveTask.TargetStorageCode    = moveItem.InCellCode;
                                            moveTask.OriginPositionID     = originPosition.ID;
                                            moveTask.TargetPositionID     = targetPosition.ID;
                                            moveTask.CurrentPositionID    = originPosition.ID;
                                            moveTask.CurrentPositionState = "01";
                                            moveTask.State           = "01";
                                            moveTask.TagState        = "01";
                                            moveTask.Quantity        = Convert.ToInt32(moveItem.RealQuantity);
                                            moveTask.TaskQuantity    = Convert.ToInt32(moveItem.RealQuantity);
                                            moveTask.OperateQuantity = Convert.ToInt32(moveItem.RealQuantity);
                                            moveTask.OrderID         = moveItem.BillNo;
                                            moveTask.OrderType       = "03";
                                            moveTask.AllotID         = moveItem.ID;
                                            moveTask.DownloadState   = "0";
                                            TaskRepository.Add(moveTask);
                                        }
                                        else
                                        {
                                            errorInfo = "未找到【路径信息】起始位置ID:" + originPosition.RegionID + ",目标位置ID:" + targetPosition.RegionID;
                                            result    = false;
                                        }
                                    }
                                    else
                                    {
                                        errorInfo = "未找到目标【位置信息】移入位置ID:" + targetCellPosition.StockInPositionID;
                                        result    = false;
                                    }
                                }
                                else
                                {
                                    errorInfo = "未找到起始【位置信息】移出位置ID:" + originCellPosition.StockOutPositionID;
                                    result    = false;
                                }
                            }
                            else
                            {
                                errorInfo = "未找到目标【货位位置】移入货位编码:" + moveItem.InCellCode;
                                result    = false;
                            }
                        }
                        else
                        {
                            errorInfo = "未找到起始【货位位置】移出货位编码:" + moveItem.OutCellCode;
                            result    = false;
                        }
                    }
                    TaskRepository.SaveChanges();
                }
                else
                {
                    errorInfo = "当前选择订单没有移库细表数据,请重新选择!";
                }
            }
            catch (Exception e)
            {
                result    = false;
                errorInfo = e.Message;
            }
            return(result);
        }
コード例 #22
0
        public object GetCellDetails(int page, int rows, string beginDate, string endDate, string type, string id)
        {
            IQueryable <InBillAllot>          InBillAllotQuery          = InBillAllotRepository.GetQueryable();
            IQueryable <OutBillAllot>         OutBillAllotQuery         = OutBillAllotRepository.GetQueryable();
            IQueryable <MoveBillDetail>       MoveBillDetailQuery       = MoveBillDetailRepository.GetQueryable();
            IQueryable <ProfitLossBillDetail> ProfitLossBillDetailQuery = ProfitLossBillDetailRepository.GetQueryable();

            if (type == "cell")
            {
                var CellHistoryAllQuery = InBillAllotQuery.Where(i => i.Status == "2" && i.CellCode == id)
                                          .Select(i => new
                {
                    i.CellCode,
                    i.Cell.CellName,
                    i.InBillMaster.BillDate,
                    i.InBillMaster.BillType.BillTypeName,
                    i.InBillMaster.BillNo,
                    i.ProductCode,
                    i.Product.ProductName,
                    i.Unit.UnitName,
                    i.RealQuantity,
                    i.Unit.Count,
                    IfMove = "0"
                }).Union(OutBillAllotQuery.Where(o => o.Status == "2" && o.CellCode == id)
                         .Select(o => new
                {
                    o.CellCode,
                    o.Cell.CellName,
                    o.OutBillMaster.BillDate,
                    o.OutBillMaster.BillType.BillTypeName,
                    o.OutBillMaster.BillNo,
                    o.ProductCode,
                    o.Product.ProductName,
                    o.Unit.UnitName,
                    o.RealQuantity,
                    o.Unit.Count,
                    IfMove = "0"
                })).Union(MoveBillDetailQuery.Where(m => m.Status == "2" && (m.InCellCode == id || m.OutCellCode == id))
                          .Select(m => new
                {
                    CellCode = m.InCellCode == id ? m.InCellCode : m.OutCellCode,
                    CellName = m.InCellCode == id ? m.InCell.CellName : m.OutCell.CellName,
                    m.MoveBillMaster.BillDate,
                    m.MoveBillMaster.BillType.BillTypeName,
                    m.MoveBillMaster.BillNo,
                    m.ProductCode,
                    m.Product.ProductName,
                    m.Unit.UnitName,
                    m.RealQuantity,
                    m.Unit.Count,
                    IfMove = m.InCellCode == id ? "1":"2"
                }
                                  )).Union(ProfitLossBillDetailQuery.Where(p => p.ProfitLossBillMaster.Status == "3" && p.CellCode == id)
                                           .Select(p => new
                {
                    p.CellCode,
                    p.Storage.Cell.CellName,
                    p.ProfitLossBillMaster.BillDate,
                    p.ProfitLossBillMaster.BillType.BillTypeName,
                    p.ProfitLossBillMaster.BillNo,
                    p.ProductCode,
                    p.Product.ProductName,
                    p.Unit.UnitName,
                    RealQuantity = p.Quantity,
                    p.Unit.Count,
                    IfMove = "0"
                }));
                if (!beginDate.Equals(string.Empty) && beginDate != "null01")
                {
                    DateTime begin = Convert.ToDateTime(beginDate);
                    CellHistoryAllQuery = CellHistoryAllQuery.Where(c => c.BillDate >= begin);
                }
                //else
                //{
                //    DateTime begin = DateTime.Now.AddDays(-30);
                //    CellHistoryAllQuery = CellHistoryAllQuery.Where(i => i.BillDate >= begin);
                //}
                if (!endDate.Equals(string.Empty) && endDate != "null02")//null02 同null01 代表传回来的日期是空值
                {
                    DateTime end = Convert.ToDateTime(endDate);
                    CellHistoryAllQuery = CellHistoryAllQuery.Where(c => c.BillDate <= end);
                }

                CellHistoryAllQuery = CellHistoryAllQuery.OrderByDescending(c => c.BillDate).Where(c => c.RealQuantity > 0);
                int total = CellHistoryAllQuery.Count();
                CellHistoryAllQuery = CellHistoryAllQuery.Skip((page - 1) * rows).Take(rows);
                var CellHistoryAll = CellHistoryAllQuery.ToArray().ToArray().Select(c => new
                {
                    c.CellCode,
                    c.CellName,
                    BillDate     = c.BillDate.ToString("yyyy-MM-dd"),
                    BillTypeName = c.IfMove == "0" ? c.BillTypeName.ToString() : c.IfMove == "1" ? c.BillTypeName.ToString() + "-移入" : c.BillTypeName.ToString() + "-移出",
                    c.BillNo,
                    c.ProductCode,
                    c.ProductName,
                    c.UnitName,
                    Quantity = c.RealQuantity / c.Count
                });
                return(new { total, rows = CellHistoryAll.ToArray() });
            }
            return(null);
        }
コード例 #23
0
        public System.Data.DataTable GetCellHistory(int page, int rows, string beginDate, string endDate, string type, string id)
        {
            IQueryable <InBillAllot>          InBillAllotQuery          = InBillAllotRepository.GetQueryable();
            IQueryable <OutBillAllot>         OutBillAllotQuery         = OutBillAllotRepository.GetQueryable();
            IQueryable <MoveBillDetail>       MoveBillDetailQuery       = MoveBillDetailRepository.GetQueryable();
            IQueryable <ProfitLossBillDetail> ProfitLossBillDetailQuery = ProfitLossBillDetailRepository.GetQueryable();

            if (type == "cell")
            {
                var CellHistoryAllQuery = InBillAllotQuery.Where(i => i.Status == "2" && i.CellCode == id)
                                          .Select(i => new
                {
                    i.CellCode,
                    i.Cell.CellName,
                    i.InBillMaster.BillDate,
                    i.InBillMaster.BillType.BillTypeName,
                    i.InBillMaster.BillNo,
                    i.ProductCode,
                    i.Product.ProductName,
                    i.Unit.UnitName,
                    i.RealQuantity,
                    i.Unit.Count,
                    IfMove = "0"
                }).Union(OutBillAllotQuery.Where(o => o.Status == "2" && o.CellCode == id)
                         .Select(o => new
                {
                    o.CellCode,
                    o.Cell.CellName,
                    o.OutBillMaster.BillDate,
                    o.OutBillMaster.BillType.BillTypeName,
                    o.OutBillMaster.BillNo,
                    o.ProductCode,
                    o.Product.ProductName,
                    o.Unit.UnitName,
                    o.RealQuantity,
                    o.Unit.Count,
                    IfMove = "0"
                })).Union(MoveBillDetailQuery.Where(m => m.Status == "2" && (m.InCellCode == id || m.OutCellCode == id))
                          .Select(m => new
                {
                    CellCode = m.InCellCode == id ? m.InCellCode : m.OutCellCode,
                    CellName = m.InCellCode == id ? m.InCell.CellName : m.OutCell.CellName,
                    m.MoveBillMaster.BillDate,
                    m.MoveBillMaster.BillType.BillTypeName,
                    m.MoveBillMaster.BillNo,
                    m.ProductCode,
                    m.Product.ProductName,
                    m.Unit.UnitName,
                    m.RealQuantity,
                    m.Unit.Count,
                    IfMove = m.InCellCode == id ? "1" : "2"
                }
                                  )).Union(ProfitLossBillDetailQuery.Where(p => p.ProfitLossBillMaster.Status == "3" && p.CellCode == id)
                                           .Select(p => new
                {
                    p.CellCode,
                    p.Storage.Cell.CellName,
                    p.ProfitLossBillMaster.BillDate,
                    p.ProfitLossBillMaster.BillType.BillTypeName,
                    p.ProfitLossBillMaster.BillNo,
                    p.ProductCode,
                    p.Product.ProductName,
                    p.Unit.UnitName,
                    RealQuantity = p.Quantity,
                    p.Unit.Count,
                    IfMove = "0"
                }));
                if (!beginDate.Equals(string.Empty) && beginDate != "null01")
                {
                    DateTime begin = Convert.ToDateTime(beginDate);
                    CellHistoryAllQuery = CellHistoryAllQuery.Where(c => c.BillDate >= begin);
                }
                if (!endDate.Equals(string.Empty) && endDate != "null02") //null02 同null01 代表传回来的日期是空值
                {
                    DateTime end = Convert.ToDateTime(endDate);
                    CellHistoryAllQuery = CellHistoryAllQuery.Where(c => c.BillDate <= end);
                }
                CellHistoryAllQuery = CellHistoryAllQuery.OrderByDescending(c => c.BillDate).Where(c => c.RealQuantity > 0);
                var CellHistoryAll = CellHistoryAllQuery.ToArray().ToArray().Select(c => new
                {
                    c.CellCode,
                    c.CellName,
                    BillDate     = c.BillDate.ToString("yyyy-MM-dd"),
                    BillTypeName = c.IfMove == "0" ? c.BillTypeName.ToString() : c.IfMove == "1" ? c.BillTypeName.ToString() + "-移入" : c.BillTypeName.ToString() + "-移出",
                    c.BillNo,
                    c.ProductCode,
                    c.ProductName,
                    c.UnitName,
                    Quantity = c.RealQuantity / c.Count
                });
                System.Data.DataTable dt = new System.Data.DataTable();
                dt.Columns.Add("货位名称", typeof(string));
                dt.Columns.Add("变动日期", typeof(string));
                dt.Columns.Add("操作类型", typeof(string));
                dt.Columns.Add("所属订单", typeof(string));
                dt.Columns.Add("商品编码", typeof(string));
                dt.Columns.Add("商品名称", typeof(string));
                dt.Columns.Add("数量", typeof(string));
                dt.Columns.Add("单位名称", typeof(string));
                foreach (var item in CellHistoryAll)
                {
                    dt.Rows.Add
                    (
                        item.CellName,
                        item.BillDate,
                        item.BillTypeName,
                        item.BillNo,
                        item.ProductCode,
                        item.ProductName,
                        item.Quantity,
                        item.UnitName
                    );
                }
                return(dt);
            }
            return(null);
        }