示例#1
0
        /// <summary>
        /// 生成出库单号
        /// </summary>
        /// <param name="userName">登陆用户</param>
        /// <returns></returns>
        public object GenInBillNo(string userName)
        {
            string billno = "";
            IQueryable <OutBillMaster> outBillMasterQuery = OutBillMasterRepository.GetQueryable();
            string sysTime       = System.DateTime.Now.ToString("yyMMdd");
            var    outBillMaster = outBillMasterQuery.Where(i => i.BillNo.Contains(sysTime)).ToArray().OrderBy(i => i.BillNo).Select(i => new { i.BillNo }.BillNo);
            var    employee      = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

            if (outBillMaster.Count() == 0)
            {
                billno = System.DateTime.Now.ToString("yyMMdd") + "0001" + "OU";
            }
            else
            {
                string billNoStr = outBillMaster.Last(b => b.Contains(sysTime));
                int    i         = Convert.ToInt32(billNoStr.ToString().Substring(6, 4));
                i++;
                string newcode = i.ToString();
                for (int j = 0; j < 4 - i.ToString().Length; j++)
                {
                    newcode = "0" + newcode;
                }
                billno = System.DateTime.Now.ToString("yyMMdd") + newcode + "OU";
            }
            var findBillInfo = new
            {
                BillNo       = billno,
                billNoDate   = DateTime.Now.ToString("yyyy-MM-dd"),
                employeeID   = employee == null ? string.Empty : employee.ID.ToString(),
                employeeCode = employee == null ? string.Empty : employee.EmployeeCode,
                employeeName = employee == null ? string.Empty : employee.EmployeeName
            };

            return(findBillInfo);
        }
示例#2
0
        /// <summary>
        /// 出库审核
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <param name="userName">登陆用户</param>
        /// <returns></returns>
        public bool Audit(string billNo, string userName, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var outbm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

            if (outbm != null && outbm.Status == "1")
            {
                if (string.IsNullOrEmpty(outbm.TargetCellCode))//判断出库主单是否有指定货位
                {
                    outbm.Status         = "2";
                    outbm.VerifyDate     = DateTime.Now;
                    outbm.UpdateTime     = DateTime.Now;
                    outbm.VerifyPersonID = employee.ID;
                    OutBillMasterRepository.SaveChanges();
                    result = true;
                }
                else//如果出库主单指定了货位那么就从指定的货位出库
                {
                    result    = OutAllot(outbm, employee.ID);
                    errorInfo = infoStr;
                }
            }
            return(result);
        }
示例#3
0
        public bool Delete(string BillNo, out string errorInfo)
        {
            errorInfo = string.Empty;
            var ibm = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1");

            if (ibm != null)
            {
                try
                {
                    //Del(OutBillDetailRepository, ibm.OutBillAllots);
                    Del(OutBillDetailRepository, ibm.OutBillDetails);
                    OutBillMasterRepository.Delete(ibm);
                    OutBillMasterRepository.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    errorInfo = "删除失败!原因:" + e.Message;
                    return(false);
                }
            }
            else
            {
                errorInfo = "删除失败!未找到当前需要删除的数据!";
                return(false);
            }
        }
示例#4
0
        public string CreateOutBillNo()
        {
            string billno = "";
            IQueryable <OutBillMaster> outBillMasterQuery = OutBillMasterRepository.GetQueryable();
            string sysTime = System.DateTime.Now.ToString("yyMMdd");
            var    billNos = outBillMasterQuery.Where(i => i.BillNo.Contains(sysTime))
                             .AsEnumerable().OrderBy(i => i.BillNo)
                             .Select(i => i.BillNo);

            if (billNos.Count() == 0)
            {
                billno = System.DateTime.Now.ToString("yyMMdd") + "0001" + "CK";
            }
            else
            {
                string billNoStr = billNos.Last(b => b.Contains(sysTime));
                int    i         = Convert.ToInt32(billNoStr.ToString().Substring(6, 4));
                i++;
                string newcode = i.ToString();
                for (int j = 0; j < 4 - i.ToString().Length; j++)
                {
                    newcode = "0" + newcode;
                }
                billno = System.DateTime.Now.ToString("yyMMdd") + newcode + "CK";
            }

            return(billno);
        }
示例#5
0
        public object GetOutBillMaster()
        {
            var outBillMaster = OutBillMasterRepository.GetQueryable()
                                .Where(i => i.Status == "4" || i.Status == "5")
                                .Select(i => new { BillNo = i.BillNo, BillType = "2" })
                                .ToArray();

            return(outBillMaster);
        }
示例#6
0
        public bool DownOutBillMaster(string beginDate, string endDate, out string errorInfo)
        {
            errorInfo = string.Empty;
            bool   result           = false;
            string outBillStr       = "";
            string outBillMasterStr = "";

            try
            {
                var outBillNos = OutBillMasterRepository.GetQueryable().Where(i => i.BillNo == i.BillNo).Select(i => new { i.BillNo }).ToArray();

                for (int i = 0; i < outBillNos.Length; i++)
                {
                    outBillStr += outBillNos[i].BillNo + ",";
                }
                OutBillMaster[] outBillMasterList = OutBillMasterDownService.GetOutBillMaster(outBillStr);
                foreach (var master in outBillMasterList)
                {
                    var outBillMaster = new OutBillMaster();
                    outBillMaster.BillNo        = master.BillNo;
                    outBillMaster.BillDate      = master.BillDate;
                    outBillMaster.BillTypeCode  = master.BillTypeCode;
                    outBillMaster.WarehouseCode = master.WarehouseCode;
                    outBillMaster.Status        = "1";
                    outBillMaster.IsActive      = master.IsActive;
                    outBillMaster.UpdateTime    = DateTime.Now;
                    OutBillMasterRepository.Add(outBillMaster);
                    outBillMasterStr += master.BillNo + ",";
                }
                if (outBillMasterStr != string.Empty)
                {
                    OutBillDetail[] outBillDetailList = OutBillMasterDownService.GetOutBillDetail(outBillMasterStr);
                    foreach (var detail in outBillDetailList)
                    {
                        var outBillDetail = new OutBillDetail();
                        outBillDetail.BillNo        = detail.BillNo;
                        outBillDetail.ProductCode   = detail.ProductCode;
                        outBillDetail.UnitCode      = detail.UnitCode;
                        outBillDetail.Price         = detail.Price;
                        outBillDetail.BillQuantity  = detail.BillQuantity;
                        outBillDetail.AllotQuantity = detail.AllotQuantity;
                        outBillDetail.RealQuantity  = detail.RealQuantity;
                        outBillDetail.Description   = detail.Description;
                        OutBillDetailRepository.Add(outBillDetail);
                    }
                }
                OutBillMasterRepository.SaveChanges();
                result = true;
            }
            catch (Exception e)
            {
                errorInfo = "出错,原因:" + e.Message;
            }
            return(result);
        }
示例#7
0
        public bool AllotCancelConfirm(string billNo, out string strResult)
        {
            bool result = false;
            var  ibm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "4");

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    try
                    {
                        using (var scope = new TransactionScope())
                        {
                            if (ibm.MoveBillMaster != null)
                            {
                                try
                                {
                                    MoveBillCreater.DeleteMoveBillDetail(ibm.MoveBillMaster);
                                    MoveBillMasterRepository.Delete(ibm.MoveBillMaster);
                                    MoveBillMasterRepository.SaveChanges();
                                }
                                catch (Exception)
                                {
                                    strResult = "删除同步移库单失败,请重新取消!";
                                    return(false);
                                }
                            }

                            ibm.Status     = "3";
                            ibm.UpdateTime = DateTime.Now;
                            OutBillMasterRepository.SaveChanges();
                            result    = true;
                            strResult = "取消成功";

                            scope.Complete();
                        }
                    }
                    catch (Exception)
                    {
                        strResult = "当前订单其他人正在操作,请稍候重试!";
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已确认,或当前订单不存在!";
            }
            return(result);
        }
示例#8
0
        public System.Data.DataTable GetStockOut(int page, int rows, string BillNo)
        {
            IQueryable <OutBillMaster> OutBillMasterQuery = OutBillMasterRepository.GetQueryable().Where(o => o.Status != "6");

            var outBillMaster = OutBillMasterQuery.Where(i => i.BillNo.Contains(BillNo)).OrderBy(i => i.BillNo).Select(s => new
            {
                s.BillNo,
                s.Warehouse.WarehouseName,
                s.BillType.BillTypeName,
                //BillDate = s.BillDate.ToString("yyyy-MM-dd hh:mm:ss"),
                OperatePersonName = s.OperatePerson.EmployeeName,
                //s.OperatePersonID,
                //Status = WhatStatus(s.Status),
                s.Status,
                VerifyPersonName = s.VerifyPersonID == null ? string.Empty : s.VerifyPerson.EmployeeName,
                //VerifyDate = (s.VerifyDate == null ? string.Empty : ((DateTime)s.VerifyDate).ToString("yyyy-MM-dd hh:mm:ss")),
                Description = s.Description,
                //UpdateTime = s.UpdateTime.ToString("yyyy-MM-dd hh:mm:ss"),
                s.TargetCellCode
            });

            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("BillDate", typeof(string));
            //dt.Columns.Add("VerifyDate", typeof(string));
            //dt.Columns.Add("UpdateTime", typeof(string));
            dt.Columns.Add("备注", typeof(string));
            dt.Columns.Add("目标货位编码", typeof(string));

            foreach (var o in outBillMaster)
            {
                dt.Rows.Add
                (
                    o.BillNo
                    , o.WarehouseName
                    , o.BillTypeName
                    , o.OperatePersonName
                    , o.VerifyPersonName
                    , o.Status
                    //, o.BillDate
                    //, o.VerifyDate
                    //, o.UpdateTime
                    , o.Description
                    , o.TargetCellCode
                );
            }
            return(dt);
        }
示例#9
0
        public bool AntiTrial(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 != "2")
                {
                    errorInfo = "当前选择的调度记录不是已审核,未能反审!";
                    return(false);
                }
                if (sortWork.OutBillMaster.Status != "2")
                {
                    errorInfo = "当前选择的调度记录出库单不是已审核,未能反审!";
                    return(false);
                }
                if (sortWork.MoveBillMaster.Status != "2")
                {
                    errorInfo = "当前选择的调度记录移库单不是已审核,未能反审!";
                    return(false);
                }
                using (var scope = new TransactionScope())
                {
                    //出库反审
                    var outMaster = OutBillMasterRepository.GetQueryable().FirstOrDefault(o => o.BillNo == sortWork.OutBillNo);
                    outMaster.Status     = "1";
                    outMaster.UpdateTime = DateTime.Now;
                    //移库反审
                    var moveMater = MoveBillMasterRepository.GetQueryable().FirstOrDefault(m => m.BillNo == sortWork.MoveBillNo);
                    moveMater.Status     = "1";
                    moveMater.UpdateTime = DateTime.Now;
                    //分拣作业反审
                    sortWork.DispatchStatus = "1";
                    sortWork.UpdateTime     = DateTime.Now;
                    SortWorkDispatchRepository.SaveChanges();
                    scope.Complete();
                    return(true);
                }
            }
            catch (Exception e)
            {
                errorInfo = "反审失败,详情:" + e.Message;
                return(false);
            }
        }
示例#10
0
        public bool AllotDelete(string billNo, long id, out string strResult)
        {
            bool result = false;
            var  ibm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "3");

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    var allotDetail = ibm.OutBillAllots.Single(a => a.ID == (int)id);
                    if (string.IsNullOrEmpty(allotDetail.Storage.LockTag))
                    {
                        try
                        {
                            allotDetail.OutBillDetail.AllotQuantity -= allotDetail.AllotQuantity;
                            allotDetail.Storage.OutFrozenQuantity   -= allotDetail.AllotQuantity;
                            allotDetail.Storage.LockTag              = string.Empty;
                            ibm.OutBillAllots.Remove(allotDetail);
                            OutBillAllotRepository.Delete(allotDetail);
                            if (ibm.OutBillAllots.Count == 0)
                            {
                                ibm.Status     = "2";
                                ibm.UpdateTime = DateTime.Now;
                            }
                            OutBillAllotRepository.SaveChanges();
                            strResult = "";
                            result    = true;
                        }
                        catch (Exception)
                        {
                            strResult = "当前储位或订单其他人正在操作,请稍候重试!";
                        }
                    }
                    else
                    {
                        strResult = "当前储位其他人正在操作,请稍候重试!";
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
示例#11
0
        public OutBillMaster CreateOutBillMaster(string warehouseCode, string billTypeCode, string operatePersonID)
        {
            //添加移库单主单
            string        billNo        = CreateOutBillNo();
            OutBillMaster outBillMaster = new OutBillMaster();

            outBillMaster.BillNo          = billNo;
            outBillMaster.BillDate        = DateTime.Now;
            outBillMaster.BillTypeCode    = billTypeCode;
            outBillMaster.Origin          = "1";
            outBillMaster.WarehouseCode   = warehouseCode;
            outBillMaster.OperatePersonID = Guid.Parse(operatePersonID);
            outBillMaster.Status          = "1";;
            outBillMaster.IsActive        = "1";
            outBillMaster.UpdateTime      = DateTime.Now;
            OutBillMasterRepository.Add(outBillMaster);
            return(outBillMaster);
        }
示例#12
0
        private bool CheckAndLock(OutBillMaster billMaster, ProgressState ps)
        {
            if ((new string[] { "1" }).Any(s => s == billMaster.Status))
            {
                ps.State = StateType.Info;
                ps.Messages.Add("当前订单未审核,不可以进行分配!");
                NotifyConnection(ps.Clone());
                return(false);
            }

            if ((new string[] { "4", "5", "6" }).Any(s => s == billMaster.Status))
            {
                ps.State = StateType.Info;
                ps.Messages.Add("分配已确认生效不能再分配!");
                NotifyConnection(ps.Clone());
                return(false);
            }

            if (!string.IsNullOrEmpty(billMaster.LockTag))
            {
                ps.State = StateType.Error;
                ps.Errors.Add("当前订单被锁定不可以进行分配!");
                NotifyConnection(ps.Clone());
                return(false);
            }
            else
            {
                try
                {
                    billMaster.LockTag = ConnectionId;
                    OutBillMasterRepository.SaveChanges();
                    ps.Messages.Add("完成锁定当前订单");
                    NotifyConnection(ps.Clone());
                    return(true);
                }
                catch (Exception)
                {
                    ps.State = StateType.Error;
                    ps.Errors.Add("锁定当前订单失败不可以进行分配!");
                    NotifyConnection(ps.Clone());
                    return(false);
                }
            }
        }
示例#13
0
        /// <summary>
        /// 出库审核
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <param name="userName">登陆用户</param>
        /// <returns></returns>
        public bool Audit(string billNo, string userName, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var outbm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

            if (outbm != null && outbm.Status == "1")
            {
                outbm.Status         = "2";
                outbm.VerifyDate     = DateTime.Now;
                outbm.UpdateTime     = DateTime.Now;
                outbm.VerifyPersonID = employee.ID;
                OutBillMasterRepository.SaveChanges();
                result = true;
            }
            return(result);
        }
示例#14
0
        public object GetOutBillMaster()
        {
            string str          = "";
            var    outBillAllot = OutBillAllotRepository.GetQueryable().Where(a => a.Status != "2").Select(a => a.BillNo).ToArray();

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

            return(outBillMaster);
        }
示例#15
0
        public bool Add(OutBillMaster outBillMaster, string userName, out string errorInfo)
        {
            errorInfo = string.Empty;
            var outbm    = new OutBillMaster();
            var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

            if (employee != null)
            {
                try
                {
                    outbm.BillNo          = outBillMaster.BillNo;
                    outbm.BillDate        = outBillMaster.BillDate;
                    outbm.BillTypeCode    = outBillMaster.BillTypeCode;
                    outbm.WarehouseCode   = outBillMaster.WarehouseCode;
                    outbm.OperatePersonID = employee.ID;
                    outbm.Status          = "1";
                    outbm.VerifyPersonID  = outBillMaster.VerifyPersonID;
                    outbm.VerifyDate      = outBillMaster.VerifyDate;
                    outbm.Description     = outBillMaster.Description;
                    //outbm.IsActive = outBillMaster.IsActive;
                    outbm.IsActive       = "1";
                    outbm.UpdateTime     = DateTime.Now;
                    outbm.Origin         = "1";
                    outbm.TargetCellCode = outBillMaster.TargetCellCode;

                    OutBillMasterRepository.Add(outbm);
                    OutBillMasterRepository.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    errorInfo = "添加失败!原因:" + e.Message;
                    return(false);
                }
            }
            else
            {
                errorInfo = "找不到当前登陆用户!请重新登陆!";
                return(false);
            }
        }
示例#16
0
        /// <summary>
        /// 出库反审
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <returns></returns>
        public bool AntiTrial(string billNo, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var outbm = OutBillMasterRepository.GetQueryable().Where(i => billNo.Contains(i.BillNo));

            if (outbm.Count() > 0)
            {
                foreach (var item in outbm.ToArray())
                {
                    if (item.Status == "2")
                    {
                        try
                        {
                            item.Status         = "1";
                            item.VerifyDate     = null;
                            item.UpdateTime     = DateTime.Now;
                            item.VerifyPersonID = null;
                            OutBillMasterRepository.SaveChanges();
                            result = true;
                        }
                        catch (Exception e)
                        {
                            errorInfo = item.BillNo + "其他人员正在操作!无法保存!" + e.Message;
                        }
                    }
                    else
                    {
                        errorInfo = item.BillNo + "这条单据状态不是已审核!";
                    }
                }
            }
            else
            {
                errorInfo = "保存失败!没有找到这些数据!";
            }
            return(result);
        }
示例#17
0
        public bool Save(OutBillMaster outBillMaster, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var outbm = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == outBillMaster.BillNo && i.Status == "1");

            if (outbm != null)
            {
                try
                {
                    outbm.BillDate        = outBillMaster.BillDate;
                    outbm.BillTypeCode    = outBillMaster.BillTypeCode;
                    outbm.WarehouseCode   = outBillMaster.WarehouseCode;
                    outbm.OperatePersonID = outBillMaster.OperatePersonID;
                    outbm.Status          = "1";
                    outbm.VerifyPersonID  = outBillMaster.VerifyPersonID;
                    outbm.VerifyDate      = outBillMaster.VerifyDate;
                    outbm.Description     = outBillMaster.Description;
                    outbm.IsActive        = "1";
                    outbm.UpdateTime      = DateTime.Now;
                    outbm.Origin          = "1";
                    outbm.TargetCellCode  = outBillMaster.TargetCellCode;

                    OutBillMasterRepository.SaveChanges();
                    result = true;
                }
                catch (Exception e)
                {
                    errorInfo = "删除失败!原因:" + e.Message;
                }
            }
            else
            {
                errorInfo = "保存失败!没有找到这条数据!";
            }
            return(result);
        }
示例#18
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);
            }
        }
示例#19
0
        public bool AllotConfirm(string billNo, string userName, ref string errorInfo)
        {
            try
            {
                var ibm      = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "3");
                var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

                if (employee == null)
                {
                    errorInfo = "当前用户不存在或不可用,未能审核!";
                    return(false);
                }
                if (ibm == null)
                {
                    errorInfo = "当前订单状态不是已分配,或当前订单不存在!";
                    return(false);
                }
                if (!(ibm.OutBillDetails.All(b => b.BillQuantity == b.AllotQuantity) &&
                      ibm.OutBillDetails.Sum(b => b.BillQuantity) == ibm.OutBillAllots.Sum(a => a.AllotQuantity)))
                {
                    errorInfo = "当前订单分配未完成或分配结果不正确!";
                    return(false);
                }
                if (!string.IsNullOrEmpty(ibm.LockTag))
                {
                    errorInfo = "当前订单其他人正在操作,请稍候重试!";
                    return(false);
                }
                using (var scope = new TransactionScope())
                {
                    if (MoveBillCreater.CheckIsNeedSyncMoveBill(ibm.WarehouseCode))
                    {
                        var moveBillMaster = MoveBillCreater.CreateMoveBillMaster(ibm.WarehouseCode, "3001", employee.ID.ToString());
                        MoveBillCreater.CreateSyncMoveBillDetail(moveBillMaster);
                        moveBillMaster.Status         = "2";
                        moveBillMaster.Description    = "出库生成同步移库单!";
                        moveBillMaster.VerifyDate     = DateTime.Now;
                        moveBillMaster.VerifyPersonID = employee.ID;
                        if (MoveBillCreater.CheckIsNeedSyncMoveBill(ibm.WarehouseCode))
                        {
                            errorInfo = "生成同步移库单不完整,请重新确认!";
                            return(false);
                        }
                        else
                        {
                            ibm.MoveBillMasterBillNo = moveBillMaster.BillNo;
                        }
                    }

                    ibm.Status     = "4";
                    ibm.UpdateTime = DateTime.Now;
                    OutBillMasterRepository.SaveChanges();
                    scope.Complete();
                    return(true);
                }
            }
            catch (Exception e)
            {
                errorInfo = "确认分配失败,详情:" + e.Message;
                return(false);
            }
        }
示例#20
0
        public bool AllotEdit(string billNo, long id, string cellCode, decimal allotQuantity, out string strResult)
        {
            bool result = false;
            var  ibm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "3");
            var  cell   = CellRepository.GetQueryable().Single(c => c.CellCode == cellCode);

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    var allotDetail = ibm.OutBillAllots.Single(a => a.ID == (int)id);
                    if (string.IsNullOrEmpty(allotDetail.Storage.LockTag))
                    {
                        Storage storage;
                        if (allotDetail.CellCode == cellCode)
                        {
                            storage = allotDetail.Storage;
                            storage.OutFrozenQuantity -= allotDetail.AllotQuantity;
                        }
                        else
                        {
                            storage = Locker.LockNoEmpty(cell, allotDetail.Product);
                            allotDetail.Storage.OutFrozenQuantity -= allotDetail.AllotQuantity;
                        }
                        if (storage != null)
                        {
                            decimal q1 = allotDetail.OutBillDetail.BillQuantity - allotDetail.OutBillDetail.AllotQuantity;
                            decimal q2 = allotQuantity * allotDetail.Unit.Count;
                            decimal q3 = storage.Quantity - storage.OutFrozenQuantity;
                            if (q1 >= q2 && q2 <= q3)
                            {
                                try
                                {
                                    allotDetail.OutBillDetail.AllotQuantity -= allotDetail.AllotQuantity;
                                    allotDetail.OutBillDetail.AllotQuantity += q2;
                                    storage.OutFrozenQuantity += q2;
                                    storage.LockTag            = string.Empty;
                                    allotDetail.CellCode       = storage.Cell.CellCode;
                                    allotDetail.StorageCode    = storage.StorageCode;
                                    allotDetail.AllotQuantity  = q2;
                                    OutBillAllotRepository.SaveChanges();
                                    strResult = "保存修改成功!";
                                    result    = true;
                                }
                                catch (Exception)
                                {
                                    strResult = "保存修改失败,订单或储位其他人正在操作!";
                                }
                            }
                            else
                            {
                                strResult = "分配数量超过订单数量,或者当前储位库存量不足!";
                            }
                        }
                        else
                        {
                            strResult = "当前选择的储位不可用,其他人正在操作或没有库存!";
                        }
                    }
                    else
                    {
                        strResult = "当前储位其他人正在操作,请稍候重试!";
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
示例#21
0
        public object GetDetails(int page, int rows, string BillNo, string beginDate, string endDate, string OperatePersonCode, string CheckPersonCode, string Status, string IsActive)
        {
            IQueryable <OutBillMaster> OutBillMasterQuery = OutBillMasterRepository.GetQueryable().Where(o => o.Status != "6");

            var outBillMaster = OutBillMasterQuery
                                .OrderByDescending(t => t.BillDate)
                                .OrderByDescending(t => t.BillNo)
                                .Select(i => i);

            if (!BillNo.Equals(string.Empty) && BillNo != null)
            {
                outBillMaster = outBillMaster.Where(i => i.BillNo.Contains(BillNo));
            }
            if (!beginDate.Equals(string.Empty))
            {
                DateTime begin = Convert.ToDateTime(beginDate);
                outBillMaster = outBillMaster.Where(i => i.BillDate >= begin);
            }
            if (!endDate.Equals(string.Empty))
            {
                DateTime end = Convert.ToDateTime(endDate).AddDays(1);
                outBillMaster = outBillMaster.Where(i => i.BillDate <= end);
            }
            if (!OperatePersonCode.Equals(string.Empty) && OperatePersonCode != null)
            {
                outBillMaster = outBillMaster.Where(i => i.OperatePerson.EmployeeCode.Contains(OperatePersonCode));
            }
            if (!Status.Equals(string.Empty))
            {
                outBillMaster = outBillMaster.Where(i => i.Status.Contains(Status) && i.Status != "6");
            }
            if (!IsActive.Equals(string.Empty))
            {
                outBillMaster = outBillMaster.Where(i => i.IsActive.Contains(IsActive));
            }
            if (!CheckPersonCode.Equals(string.Empty))
            {
                outBillMaster = outBillMaster.Where(i => i.VerifyPerson.EmployeeCode == CheckPersonCode);
            }
            int total = outBillMaster.Count();

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

            var temp = outBillMaster.ToArray().AsEnumerable().Select(i => new
            {
                i.BillNo,
                BillDate = i.BillDate.ToString("yyyy-MM-dd HH:mm:ss"),
                i.Warehouse.WarehouseCode,
                i.Warehouse.WarehouseName,
                i.OperatePersonID,
                i.VerifyPersonID,
                OperatePersonCode = i.OperatePerson.EmployeeCode,
                OperatePersonName = i.OperatePerson.EmployeeName,
                VerifyPersonCode  = i.VerifyPersonID == null ? string.Empty : i.VerifyPerson.EmployeeCode,
                VerifyPersonName  = i.VerifyPersonID == null ? string.Empty : i.VerifyPerson.EmployeeName,
                SumQuantity       = i.OutBillDetails.Sum(s => s.BillQuantity / s.Product.Unit.Count),
                BillTypeCode      = i.BillType.BillTypeCode,
                BillTypeName      = i.BillType.BillTypeName,
                VerifyDate        = i.VerifyDate == null ? string.Empty : ((DateTime)i.VerifyDate).ToString("yyyy-MM-dd HH:mm:ss"),
                Status            = WhatStatus(i.Status),
                IsActive          = i.IsActive == "1" ? "可用" : "不可用",
                Description       = i.Description,
                UpdateTime        = i.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                i.TargetCellCode
            });

            return(new { total, rows = temp.ToArray() });
        }
示例#22
0
        public bool AllotAdd(string billNo, long id, string cellCode, string productName, out string strResult, out decimal allotQuantity)
        {
            bool    result = false;
            var     ibm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var     cell   = CellRepository.GetQueryable().Single(c => c.CellCode == cellCode);
            var     obm    = OutBillDetailRepository.GetQueryable().FirstOrDefault(o => o.ID == id);
            var     stor   = StorageRepository.GetQueryable().Single(c => c.CellCode == cellCode);
            decimal q1     = obm.BillQuantity - obm.AllotQuantity;

            allotQuantity = 0;
            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    Storage storage = Locker.LockNoEmpty(cell, obm.Product);
                    if (storage != null)
                    {
                        if (stor.Product.ProductName == productName)
                        {
                            if (q1 > 0)
                            {
                                OutBillAllot billAllot = null;
                                decimal      q3        = storage.Quantity - storage.OutFrozenQuantity;
                                if (q1 <= q3)
                                {
                                    try
                                    {
                                        billAllot = new OutBillAllot()
                                        {
                                            BillNo          = billNo,
                                            OutBillDetailId = obm.ID,
                                            ProductCode     = obm.ProductCode,
                                            CellCode        = storage.CellCode,
                                            StorageCode     = storage.StorageCode,
                                            UnitCode        = obm.UnitCode,
                                            AllotQuantity   = q1,
                                            RealQuantity    = 0,
                                            Status          = "0"
                                        };
                                        allotQuantity              = (q3 - q1) / storage.Product.Unit.Count;
                                        obm.AllotQuantity         += q1;
                                        storage.OutFrozenQuantity += q1;
                                        ibm.OutBillAllots.Add(billAllot);
                                        ibm.Status      = "3";
                                        storage.LockTag = string.Empty;
                                        StorageRepository.SaveChanges();
                                        strResult = "保存修改成功!";
                                        result    = true;
                                    }
                                    catch (Exception)
                                    {
                                        strResult = "保存添加失败,订单或储位其他人正在操作!";
                                    }
                                }
                                else
                                {
                                    try
                                    {
                                        billAllot = new OutBillAllot()
                                        {
                                            BillNo          = billNo,
                                            OutBillDetailId = obm.ID,
                                            ProductCode     = obm.ProductCode,
                                            CellCode        = storage.CellCode,
                                            StorageCode     = storage.StorageCode,
                                            UnitCode        = obm.UnitCode,
                                            AllotQuantity   = q3,
                                            RealQuantity    = 0,
                                            Status          = "0"
                                        };
                                        obm.AllotQuantity         += q3;
                                        storage.OutFrozenQuantity += q3;
                                        ibm.OutBillAllots.Add(billAllot);
                                        ibm.Status      = "3";
                                        storage.LockTag = string.Empty;
                                        StorageRepository.SaveChanges();
                                        strResult = "保存修改成功!";
                                        result    = true;
                                    }
                                    catch (Exception)
                                    {
                                        strResult = "保存添加失败,订单或储位其他人正在操作!";
                                    }
                                }
                            }
                            else
                            {
                                strResult = "该产品已无分配任务!";
                            }
                        }
                        else
                        {
                            strResult = "该卷烟没有出库任务!";
                        }
                    }
                    else
                    {
                        strResult = "当前选择的储位不可用,其他人正在操作或没有库存!";
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
示例#23
0
        public bool AllotCancel(string billNo, out string strResult)
        {
            bool result = false;
            var  ibm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "3");

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    try
                    {
                        using (var scope = new TransactionScope())
                        {
                            var outAllot = OutBillAllotRepository.GetQueryable()
                                           .Where(o => o.BillNo == ibm.BillNo)
                                           .ToArray();

                            var storages = outAllot.Select(i => i.Storage).ToArray();

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

                            outAllot.AsParallel().ForAll(
                                (Action <OutBillAllot>) delegate(OutBillAllot o)
                            {
                                if (o.Storage.ProductCode == o.ProductCode &&
                                    o.Storage.OutFrozenQuantity >= o.AllotQuantity)
                                {
                                    lock (o.OutBillDetail)
                                    {
                                        o.OutBillDetail.AllotQuantity -= o.AllotQuantity;
                                    }
                                    o.Storage.OutFrozenQuantity -= o.AllotQuantity;
                                    o.Storage.LockTag            = string.Empty;
                                }
                                else
                                {
                                    throw new Exception("储位的卷烟或出库冻结量与当前分配不符,信息可能被异常修改,不能取消当前出库分配!");
                                }
                            }
                                );

                            OutBillAllotRepository.SaveChanges();

                            OutBillAllotRepository.GetObjectSet()
                            .DeleteEntity(i => i.BillNo == ibm.BillNo);

                            ibm.Status     = "2";
                            ibm.UpdateTime = DateTime.Now;
                            OutBillMasterRepository.SaveChanges();
                            result    = true;
                            strResult = "取消成功";

                            scope.Complete();
                        }
                    }
                    catch (Exception e)
                    {
                        strResult = "取消分配失败,详情:" + e.Message;
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
示例#24
0
        /// <summary>
        /// 出库分配
        /// </summary>
        /// <param name="outBillMaster">出库主单</param>
        /// <returns></returns>
        public bool OutAllot(OutBillMaster outBillMaster, Guid employeeId)
        {
            try
            {
                bool result = false;
                //出库单出库
                var storages = StorageRepository.GetQueryable().Where(s => s.CellCode == outBillMaster.TargetCellCode &&
                                                                      s.Quantity - s.OutFrozenQuantity > 0).ToArray();

                if (!Locker.Lock(storages))
                {
                    throw new Exception("锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!");
                }
                var outDetails = OutBillDetailRepository.GetQueryableIncludeProduct()
                                 .Where(o => o.BillNo == 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          = outBillMaster.BillNo,
                                    OutBillDetailId = o.ID,
                                    ProductCode     = o.ProductCode,
                                    CellCode        = s.CellCode,
                                    StorageCode     = s.StorageCode,
                                    UnitCode        = o.UnitCode,
                                    AllotQuantity   = allotQuantity,
                                    RealQuantity    = allotQuantity,
                                    Status          = "2"
                                };
                                lock (outBillMaster.OutBillAllots)
                                {
                                    outBillMaster.OutBillAllots.Add(billAllot);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    if (o.BillQuantity - o.AllotQuantity > 0)
                    {
                        throw new Exception(o.ProductCode + " " + o.Product.ProductName + "库存不足,未能结单!");
                    }
                });

                result = true;
                storages.AsParallel().ForAll(s => s.LockTag = string.Empty);
                //出库结单
                outBillMaster.Status         = "6";
                outBillMaster.VerifyDate     = DateTime.Now;
                outBillMaster.VerifyPersonID = employeeId;
                outBillMaster.UpdateTime     = DateTime.Now;
                OutBillMasterRepository.SaveChanges();

                return(result);
            }
            catch (AggregateException ex)
            {
                infoStr = "审核失败,详情:" + ex.InnerExceptions.Select(i => i.Message).Aggregate((m, n) => m + n);
                return(false);
            }
        }
示例#25
0
        public bool AllotAdd(string billNo, long id, string productCode, string cellCode, int allotQuantity, out string strResult)
        {
            bool result = false;
            var  ibm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var  cell   = CellRepository.GetQueryable().Single(c => c.CellCode == cellCode);
            var  obm    = OutBillDetailRepository.GetQueryable().FirstOrDefault(o => o.ProductCode == productCode);

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    Storage storage = Locker.LockNoEmpty(cell, obm.Product);
                    if (storage != null && allotQuantity > 0)
                    {
                        OutBillAllot billAllot = null;
                        decimal      q1        = obm.BillQuantity - obm.AllotQuantity;
                        decimal      q2        = allotQuantity * obm.Unit.Count;
                        decimal      q3        = storage.Quantity - storage.OutFrozenQuantity;
                        if (q1 >= q2 && q2 <= q3)
                        {
                            try
                            {
                                billAllot = new OutBillAllot()
                                {
                                    BillNo          = billNo,
                                    OutBillDetailId = obm.ID,
                                    ProductCode     = obm.ProductCode,
                                    CellCode        = storage.CellCode,
                                    StorageCode     = storage.StorageCode,
                                    UnitCode        = obm.UnitCode,
                                    AllotQuantity   = q2,
                                    RealQuantity    = 0,
                                    Status          = "0"
                                };
                                obm.AllotQuantity         += q2;
                                storage.OutFrozenQuantity += q2;
                                ibm.OutBillAllots.Add(billAllot);
                                ibm.Status      = "3";
                                storage.LockTag = string.Empty;
                                StorageRepository.SaveChanges();
                                strResult = "保存修改成功!";
                                result    = true;
                            }
                            catch (Exception)
                            {
                                strResult = "保存添加失败,订单或储位其他人正在操作!";
                            }
                        }
                        else
                        {
                            strResult = "分配数量超过订单数量,或者当前储位库存量不足!";
                        }
                    }
                    else
                    {
                        strResult = "当前选择的储位不可用,其他人正在操作或没有库存!";
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
示例#26
0
        public DataSet Insert()
        {
            IQueryable <OutBillMaster> outBillMaster = OutBillMasterRepository.GetQueryable();
            IQueryable <OutBillAllot>  outBillAllot  = OutBillAllotRepository.GetQueryable();
            IQueryable <OutBillDetail> outBillDetail = OutBillDetailRepository.GetQueryable();
            var outBillMasterQuery = outBillMaster.Where(i => i.Status == "6").Select(i => new
            {
                STORE_BILL_ID        = i.BillNo,
                RELATE_BUSI_BILL_NUM = outBillAllot.Count(a => a.BillNo == i.BillNo),
                DIST_CTR_CODE        = i.WarehouseCode,
                QUANTITY_SUM         = outBillAllot.Where(a => a.BillNo == i.BillNo).Sum(a => a.AllotQuantity / 200),
                AMOUNT_SUM           = outBillDetail.Where(d => d.BillNo == i.BillNo).Sum(d => d.Price * d.AllotQuantity / 200),
                DETAIL_NUM           = outBillDetail.Count(d => d.BillNo == i.BillNo),
                personCode           = i.VerifyPerson,
                personDate           = i.VerifyDate,
                operater             = i.OperatePerson,
                operateDate          = i.BillDate,
                BILL_TYPE            = i.BillTypeCode
            });
            DataSet ds      = this.GenerateEmptyTables();
            DataRow inbrddr = ds.Tables["WMS_OUT_BILLMASTER"].NewRow();

            foreach (var p in outBillMasterQuery)
            {
                inbrddr["STORE_BILL_ID"]        = p.STORE_BILL_ID;
                inbrddr["RELATE_BUSI_BILL_NUM"] = p.RELATE_BUSI_BILL_NUM;
                inbrddr["DIST_CTR_CODE"]        = p.DIST_CTR_CODE;
                inbrddr["AREA_TYPE"]            = "0901";
                inbrddr["QUANTITY_SUM"]         = -p.QUANTITY_SUM;
                inbrddr["AMOUNT_SUM"]           = p.AMOUNT_SUM;
                inbrddr["DETAIL_NUM"]           = p.DETAIL_NUM;
                inbrddr["CREATOR_CODE"]         = p.operater.ToString() ?? "";
                inbrddr["CREATE_DATE"]          = p.operateDate;
                inbrddr["AUDITOR_CODE"]         = p.personCode.ToString() ?? "";
                inbrddr["AUDIT_DATE"]           = p.personDate;
                inbrddr["ASSIGNER_CODE"]        = p.operater;
                inbrddr["ASSIGN_DATE"]          = p.operateDate;
                inbrddr["AFFIRM_CODE"]          = p.operater;
                inbrddr["AFFIRM_DATE"]          = p.operateDate;
                inbrddr["IN_OUT_TYPE"]          = "1203";
                inbrddr["BILL_TYPE"]            = p.BILL_TYPE;
                inbrddr["BILL_STATUS"]          = "99";
                inbrddr["DISUSE_STATUS"]        = "0";
                inbrddr["IS_IMPORT"]            = "0";
                ds.Tables["WMS_OUT_BILLMASTER"].Rows.Add(inbrddr);
            }
            DataRow inbrddrDetail      = ds.Tables["WMS_OUT_BILLDETAIL"].NewRow();
            var     outBillDetailQuery = outBillDetail.Where(i => i.OutBillMaster.Status == "6").Select(i => new
            {
                STORE_BILL_DETAIL_ID = i.ID,
                STORE_BILL_ID        = i.BillNo,
                BRAND_CODE           = i.ProductCode,
                BRAND_NAME           = i.Product.ProductName,
                QUANTITY             = i.BillQuantity / 200
            });

            foreach (var p in outBillDetailQuery)
            {
                inbrddrDetail["STORE_BILL_DETAIL_ID"] = p.STORE_BILL_DETAIL_ID;
                inbrddrDetail["STORE_BILL_ID"]        = p.STORE_BILL_ID;
                inbrddrDetail["BRAND_CODE"]           = p.BRAND_CODE;
                inbrddrDetail["BRAND_NAME"]           = p.BRAND_NAME;
                inbrddrDetail["QUANTITY"]             = -p.QUANTITY;
                inbrddrDetail["IS_IMPORT"]            = "0";
                ds.Tables["WMS_OUT_BILLDETAIL"].Rows.Add(inbrddrDetail);
            }
            DataRow inbrddrAllot      = ds.Tables["WMS_OUT_BILLALLOT"].NewRow();
            var     outBillAllotQuery = outBillAllot.Where(i => i.OutBillMaster.Status == "6").Select(i => new
            {
                BUSI_ACT_ID         = i.ID,
                BUSI_BILL_DETAIL_ID = i.OutBillDetailId,
                BUSI_BILL_ID        = i.BillNo,
                BRAND_CODE          = i.ProductCode,
                BRAND_NAME          = i.Product.ProductName,
                QUANTITY            = i.AllotQuantity / 200,
                DIST_CTR_CODE       = i.OutBillMaster.WarehouseCode,
                STORE_PLACE_CODE    = i.Storage.CellCode,
                UPDATE_CODE         = i.Operator,
                //BEGIN_STOCK_QUANTITY =StorageRepository.GetQueryable().Where(s=>s.ProductCode==i.ProductCode).Sum(s=>s.Quantity/200)-i.AllotQuantity,
                //END_STOCK_QUANTITY = i.AllotQuantity,
                BILL_TYPE = i.OutBillMaster.BillTypeCode
            });

            foreach (var p in outBillAllotQuery)
            {
                inbrddrAllot["BUSI_ACT_ID"]          = p.BUSI_ACT_ID;
                inbrddrAllot["BUSI_BILL_DETAIL_ID"]  = p.BUSI_BILL_DETAIL_ID;
                inbrddrAllot["BUSI_BILL_ID"]         = p.BUSI_BILL_ID;
                inbrddrAllot["BRAND_CODE"]           = p.BRAND_CODE;
                inbrddrAllot["BRAND_NAME"]           = p.BRAND_NAME;
                inbrddrAllot["QUANTITY"]             = -p.QUANTITY;
                inbrddrAllot["DIST_CTR_CODE"]        = p.DIST_CTR_CODE;
                inbrddrAllot["ORG_CODE"]             = "01";
                inbrddrAllot["STORE_ROOM_CODE"]      = "001";
                inbrddrAllot["STORE_PLACE_CODE"]     = p.STORE_PLACE_CODE;
                inbrddrAllot["TARGET_NAME"]          = p.STORE_PLACE_CODE;
                inbrddrAllot["IN_OUT_TYPE"]          = "1203";
                inbrddrAllot["BILL_TYPE"]            = p.BILL_TYPE;
                inbrddrAllot["BEGIN_STOCK_QUANTITY"] = 0;
                inbrddrAllot["END_STOCK_QUANTITY"]   = 0;
                inbrddrAllot["DISUSE_STATUS"]        = "0";
                inbrddrAllot["RECKON_STATUS"]        = "1";
                inbrddrAllot["RECKON_DATE"]          = DateTime.Now.ToString("yyyy-MM-dd");
                inbrddrAllot["UPDATE_CODE"]          = p.UPDATE_CODE;
                inbrddrAllot["UPDATE_DATE"]          = DateTime.Now.ToString("yyyy-MM-dd");
                inbrddrAllot["IS_IMPORT"]            = "0";
                ds.Tables["WMS_OUT_BILLALLOT"].Rows.Add(inbrddrAllot);
            }
            return(ds);
        }
示例#27
0
        public bool Audit(string id, string userName, ref string errorInfo)
        {
            try
            {
                Guid ID       = new Guid(id);
                var  sortWork = SortWorkDispatchRepository.GetQueryable().FirstOrDefault(s => s.ID == ID);
                var  employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

                if (employee == null)
                {
                    errorInfo = "当前用户不存在或不可用,未能审核!";
                    return(false);
                }
                if (sortWork == null)
                {
                    errorInfo = "当前选择的调度记录不存在,未能审核!";
                    return(false);
                }
                if (sortWork.DispatchStatus != "1")
                {
                    errorInfo = "当前选择的调度记录不是已调度,未能审核!";
                    return(false);
                }
                if (sortWork.OutBillMaster.Status != "1")
                {
                    errorInfo = "当前选择的调度记录出库单不是已录入,未能审核!";
                    return(false);
                }
                if (sortWork.MoveBillMaster.Status != "1")
                {
                    errorInfo = "当前选择的调度记录移库单不是已录入,未能审核!";
                    return(false);
                }
                using (var scope = new TransactionScope())
                {
                    //出库审核
                    var outMaster = OutBillMasterRepository.GetQueryable()
                                    .FirstOrDefault(o => o.BillNo == sortWork.OutBillNo);
                    outMaster.Status         = "2";
                    outMaster.VerifyPersonID = employee.ID;
                    outMaster.VerifyDate     = DateTime.Now;
                    outMaster.UpdateTime     = DateTime.Now;
                    //移库审核
                    var moveMater = MoveBillMasterRepository.GetQueryable()
                                    .FirstOrDefault(m => m.BillNo == sortWork.MoveBillNo);
                    moveMater.Status         = "2";
                    moveMater.VerifyPersonID = employee.ID;
                    moveMater.VerifyDate     = DateTime.Now;
                    moveMater.UpdateTime     = DateTime.Now;
                    //分拣作业审核
                    sortWork.DispatchStatus = "2";
                    sortWork.UpdateTime     = DateTime.Now;
                    SortWorkDispatchRepository.SaveChanges();
                    scope.Complete();
                    return(true);
                }
            }
            catch (Exception e)
            {
                errorInfo = "审核失败,详情:" + e.Message;
                return(false);
            }
        }
示例#28
0
        public void Allot(string connectionId, Model.ProgressState ps, System.Threading.CancellationToken cancellationToken, string billNo, string[] areaCodes)
        {
            Locker.LockKey = billNo;
            ConnectionId   = connectionId;
            ps.State       = StateType.Start;
            NotifyConnection(ps.Clone());

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

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

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

            //选择未分配的细单;
            var billDetails = billMaster.OutBillDetails.Where(b => (b.BillQuantity - b.AllotQuantity) > 0).ToArray();
            //选择当前订单操作目标仓库;
            var storages = storageQuery.Where(s => s.Cell.WarehouseCode == billMaster.WarehouseCode);

            if (areaCodes.Length > 0)
            {
                //选择指定库区;
                storages = storages.Where(s => areaCodes.Any(a => a == s.Cell.AreaCode));
            }
            else
            {
                storages = storages.Where(s => s.Cell.Area.AllotOutOrder > 0);
            }
            storages = storages.Where(s => string.IsNullOrEmpty(s.LockTag) && s.Cell.IsActive == "1" &&
                                      s.Quantity - s.OutFrozenQuantity > 0);

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

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

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

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

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

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

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

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

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

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

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

            string billno = billMaster.BillNo;

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

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

                billMaster.Status = "3";
                try
                {
                    if (!cancellationToken.IsCancellationRequested)
                    {
                        billMaster.LockTag = string.Empty;
                        CellRepository.SaveChanges();
                        ps.State = StateType.Info;
                        ps.Messages.Clear();
                        ps.Messages.Add("分配成功!");
                        NotifyConnection(ps.Clone());
                    }
                }
                catch (Exception e)
                {
                    ps.State = StateType.Error;
                    ps.Messages.Add("保存失败,详情:" + e.Message);
                    NotifyConnection(ps.Clone());
                }
                finally
                {
                    OutBillMasterRepository.GetObjectSet()
                    .UpdateEntity(i => i.BillNo == billno,
                                  i => new OutBillMaster()
                    {
                        LockTag = ""
                    });
                }
            }
        }
示例#29
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());
        }
示例#30
0
        /// <summary>
        /// 出库结单
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <param name="errorInfo">错误信息</param>
        /// <returns></returns>
        public bool Settle(string billNo, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var outbm = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);

            if (outbm != null && outbm.Status == "5")
            {
                using (var scope = new TransactionScope())
                {
                    try
                    {
                        //结单移库单,修改冻结量
                        var moveDetail = MoveBillDetailRepository.GetQueryable()
                                         .Where(m => m.BillNo == outbm.MoveBillMasterBillNo &&
                                                m.Status != "2");
                        //结单出库单,修改冻结量
                        var outAllot = OutBillAllotRepository.GetQueryable()
                                       .Where(o => o.BillNo == outbm.BillNo &&
                                              o.Status != "2");

                        var sourceStorages = moveDetail.Select(m => m.OutStorage).ToArray();
                        var targetStorages = moveDetail.Select(m => m.InStorage).ToArray();
                        var storages       = outAllot.Select(i => i.Storage).ToArray();

                        if (!Locker.Lock(storages) ||
                            !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("储位的卷烟或入库冻结量与当前分配不符,信息可能被异常修改,不能结单!");
                            }
                        }
                            );
                        MoveBillDetailRepository.SaveChanges();

                        outAllot.AsParallel().ForAll(
                            (Action <OutBillAllot>) delegate(OutBillAllot o)
                        {
                            if (o.Storage.ProductCode == o.ProductCode &&
                                o.Storage.OutFrozenQuantity >= o.AllotQuantity)
                            {
                                o.Storage.OutFrozenQuantity -= o.AllotQuantity;
                                o.Storage.LockTag            = string.Empty;
                            }
                            else
                            {
                                throw new Exception("储位的卷烟或入库冻结量与当前分配不符,信息可能被异常修改,不能结单!");
                            }
                        }
                            );

                        if (outbm.MoveBillMaster != null)
                        {
                            outbm.MoveBillMaster.Status     = "4";
                            outbm.MoveBillMaster.UpdateTime = DateTime.Now;
                        }

                        outbm.Status     = "6";
                        outbm.UpdateTime = DateTime.Now;
                        OutBillMasterRepository.SaveChanges();
                        scope.Complete();
                        result = true;
                    }
                    catch (Exception e)
                    {
                        errorInfo = "出库单结单出错!原因:" + e.Message;
                        return(false);
                    }
                }
            }
            return(result);
        }