示例#1
0
        /// <summary>
        /// 层级拉动
        /// </summary>
        /// <param name="maintainInhouseLogisticStandardInfo"></param>
        /// <param name="requireQty"></param>
        /// <param name="loginUser"></param>
        /// <param name="counterFid"></param>
        /// <param name="partBoxCode"></param>
        /// <returns></returns>
        public static string LevelPullCounter(MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandardInfo, decimal requireQty, string loginUser, Guid counterFid, TwdPartBoxInfo twdPartBoxInfo)
        {
            ///未能成功获取零件类信息
            if (twdPartBoxInfo == null)
            {
                return(string.Empty);
            }
            ///零件类未启用
            if (twdPartBoxInfo.Status.GetValueOrDefault() != (int)BasicDataStatusConstants.Enable)
            {
                return(string.Empty);
            }
            ///根据物料拉动信息外键获取计数器,未能成功获取时需要创建
            TwdCounterInfo twdCounterInfo = new TwdCounterDAL().GetInfoByPartPullFid(maintainInhouseLogisticStandardInfo.Fid.GetValueOrDefault());

            if (twdCounterInfo == null)
            {
                ///创建计数器
                twdCounterInfo = CreateTwdCounterInfo(loginUser);
                ///以物料拉动信息填充计数器
                GetTwdCounterInfo(maintainInhouseLogisticStandardInfo, ref twdCounterInfo);
                ///以零件类信息填充计数器
                GetTwdCounterInfo(twdPartBoxInfo, ref twdCounterInfo);
                ///
                twdCounterInfo.Id = new TwdCounterDAL().Add(twdCounterInfo);
                if (twdCounterInfo.Id == 0)
                {
                    throw new Exception("MC:0x00000453");///时间窗计数器创建失败
                }
            }
            ///计数器状态未处于启用
            if (twdCounterInfo.Status != (int)BasicDataStatusConstants.Enable)
            {
                return(string.Empty);
            }
            ///
            StringBuilder stringBuilder = new StringBuilder();

            ///
            stringBuilder.AppendLine(UpdateTwdCounter(maintainInhouseLogisticStandardInfo, twdPartBoxInfo, requireQty, twdCounterInfo.Id, loginUser));
            ///创建计数器日志
            TwdCounterLogInfo twdCounterLogInfo = TwdCounterLogBLL.CreateTwdCounterLogInfo(twdCounterInfo.Fid.GetValueOrDefault(), loginUser);

            ///以物料拉动信息填充计数器日志
            TwdCounterLogBLL.GetTwdCounterLogInfo(maintainInhouseLogisticStandardInfo, ref twdCounterLogInfo);
            ///以零件类信息填充计数器日志
            TwdCounterLogBLL.GetTwdCounterLogInfo(twdPartBoxInfo, ref twdCounterLogInfo);
            ///PART_QTY
            twdCounterLogInfo.PartQty = requireQty;
            ///SOURCE_DATA_FID
            twdCounterLogInfo.SourceDataFid = counterFid;
            ///SOURCE_DATA_TYPE
            twdCounterLogInfo.SourceDataType = (int)TwdCounterSourceDataTypeConstants.Calculator;
            ///SOURCE_DATA
            twdCounterLogInfo.SourceData = twdPartBoxInfo.PartBoxCode;
            ///
            stringBuilder.AppendLine(TwdCounterLogDAL.GetInsertSql(twdCounterLogInfo));
            ///触发层级拉动
            stringBuilder.AppendLine(LevelPullCounter(
                                         maintainInhouseLogisticStandardInfo,
                                         requireQty,
                                         loginUser,
                                         twdCounterInfo.Fid.GetValueOrDefault(),
                                         twdPartBoxInfo));
            return(stringBuilder.ToString());
        }
示例#2
0
        /// <summary>
        /// 获取层级拉动需求累计语句
        /// </summary>
        /// <param name="maintainInhouseLogisticStandardInfo"></param>
        /// <param name="requireQty"></param>
        /// <param name="loginUser"></param>
        /// <param name="counterFid"></param>
        /// <param name="partBoxCode"></param>
        /// <returns></returns>
        public static string LevelPullRequirementCounter(MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandardInfo, decimal requireQty, string loginUser, Guid counterFid, string partBoxCode)
        {
            ///当物料拉动信息中的是否层级拉动标记 =False或未设置时函数直接返回空
            if (!maintainInhouseLogisticStandardInfo.IsTriggerPull.GetValueOrDefault())
            {
                return(string.Empty);
            }
            ///根据物料拉动信息中的层级拉动仓库存储区以及物料号、供应商获取物料拉动信息表中目标仓库存储区对应的物料号、供应商数据
            List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandardInfos = new MaintainInhouseLogisticStandardDAL().GetList("" +
                                                                                                                                               "[T_WM_NO] = N'" + maintainInhouseLogisticStandardInfo.WmNo + "' and " +
                                                                                                                                               "[T_ZONE_NO] = N'" + maintainInhouseLogisticStandardInfo.ZoneNo + "' and " +
                                                                                                                                               "[PART_NO] = N'" + maintainInhouseLogisticStandardInfo.PartNo + "' and " +
                                                                                                                                               "[STATUS] = " + (int)BasicDataStatusConstants.Enable + " and " +
                                                                                                                                               "[INHOUSE_SYSTEM_MODE] = N'" + (int)PullModeConstants.Twd + "'", string.Empty);
            ///若获取不成功则将供应商条件去除重新获取,此处在程序执行时可以先根据物料号获取,再过滤供应商
            MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandard = maintainInhouseLogisticStandardInfos.FirstOrDefault(d => d.SupplierNum == maintainInhouseLogisticStandardInfo.SupplierNum);

            if (maintainInhouseLogisticStandard == null)
            {
                maintainInhouseLogisticStandardInfo = maintainInhouseLogisticStandardInfos.FirstOrDefault();
            }
            ///未能成功获取物料拉动信息
            if (maintainInhouseLogisticStandard == null)
            {
                return(string.Empty);
            }
            ///获取零件类信息
            TwdPartBoxInfo twdPartBoxInfo = new TwdPartBoxDAL().GetInfo(maintainInhouseLogisticStandard.InhousePartClass);

            ///未能成功获取零件类信息
            if (twdPartBoxInfo == null)
            {
                return(string.Empty);
            }
            ///零件类未启用
            if (twdPartBoxInfo.Status.GetValueOrDefault() != (int)BasicDataStatusConstants.Enable)
            {
                return(string.Empty);
            }
            ///根据物料拉动信息外键获取计数器,未能成功获取时需要创建
            TwdCounterInfo twdCounterInfo = new TwdCounterDAL().GetInfoByPartPullFid(maintainInhouseLogisticStandard.Fid.GetValueOrDefault());

            if (twdCounterInfo == null)
            {
                ///创建计数器
                twdCounterInfo = CreateTwdCounterInfo(loginUser);
                ///以物料拉动信息填充计数器
                GetTwdCounterInfo(maintainInhouseLogisticStandard, ref twdCounterInfo);
                ///以零件类信息填充计数器
                GetTwdCounterInfo(twdPartBoxInfo, ref twdCounterInfo);
                ///
                twdCounterInfo.Id = new TwdCounterDAL().Add(twdCounterInfo);
                if (twdCounterInfo.Id == 0)
                {
                    throw new Exception("MC:0x00000453");///时间窗计数器创建失败
                }
            }
            ///计数器状态未处于启用
            if (twdCounterInfo.Status != (int)BasicDataStatusConstants.Enable)
            {
                return(string.Empty);
            }
            ///
            StringBuilder stringBuilder = new StringBuilder();

            ///
            stringBuilder.AppendLine(UpdateTwdCounter(maintainInhouseLogisticStandard, twdPartBoxInfo, requireQty, twdCounterInfo.Id, loginUser));
            ///创建计数器日志
            TwdCounterLogInfo twdCounterLogInfo = TwdCounterLogBLL.CreateTwdCounterLogInfo(twdCounterInfo.Fid.GetValueOrDefault(), loginUser);

            ///以物料拉动信息填充计数器日志
            TwdCounterLogBLL.GetTwdCounterLogInfo(maintainInhouseLogisticStandard, ref twdCounterLogInfo);
            ///以零件类信息填充计数器日志
            TwdCounterLogBLL.GetTwdCounterLogInfo(twdPartBoxInfo, ref twdCounterLogInfo);
            ///PART_QTY
            twdCounterLogInfo.PartQty = requireQty;
            ///SOURCE_DATA_FID
            twdCounterLogInfo.SourceDataFid = counterFid;
            ///SOURCE_DATA_TYPE
            twdCounterLogInfo.SourceDataType = (int)TwdCounterSourceDataTypeConstants.Calculator;
            ///SOURCE_DATA
            twdCounterLogInfo.SourceData = partBoxCode;
            ///
            stringBuilder.AppendLine(TwdCounterLogDAL.GetInsertSql(twdCounterLogInfo));
            ///触发层级拉动
            stringBuilder.AppendLine(LevelPullRequirementCounter(
                                         maintainInhouseLogisticStandard,
                                         requireQty,
                                         loginUser,
                                         twdCounterInfo.Fid.GetValueOrDefault(),
                                         twdCounterInfo.PartBoxCode));
            return(stringBuilder.ToString());
        }
        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="info"></param>
        /// <param name="rowsKeyValues"></param>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        public bool EntitySubmitInfos(TwdCounterUpdateInfo info, List <string> rowsKeyValues, string loginUser)
        {
            List <TwdCounterInfo> twdCounterInfos = new TwdCounterDAL().GetList("[ID] in (" + string.Join(",", rowsKeyValues.ToArray()) + ")", string.Empty);

            if (twdCounterInfos.Count == 0)
            {
                throw new Exception("MC:0x00000084");///数据错误
            }
            string sql = string.Empty;

            foreach (var twdCounterInfo in twdCounterInfos)
            {
                if (twdCounterInfo.Status.GetValueOrDefault() == (int)BasicDataStatusConstants.Disabled)
                {
                    throw new Exception("MC:0x00000455");///计数器已作废不能修改数量
                }
                sql += "update [LES].[TT_MPM_TWD_COUNTER] set " +
                       "[CURRENT_QTY] = isnull([CURRENT_QTY],0) +" + info.SubmitQty.GetValueOrDefault() + "," +
                       "[MODIFY_DATE] = GETDATE()," +
                       "[MODIFY_USER] = N'" + loginUser + "' where " +
                       "[ID] = " + twdCounterInfo.Id + ";";
                ///根据计数器的物料拉动信息外键获取物料拉动信息
                MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandardInfo = new MaintainInhouseLogisticStandardDAL().GetInfoByFid(twdCounterInfo.PartPullFid.GetValueOrDefault());
                if (maintainInhouseLogisticStandardInfo == null)
                {
                    throw new Exception("MC:0x00000213");///物料拉动信息数据错误
                }
                if (maintainInhouseLogisticStandardInfo.Status.GetValueOrDefault() != (int)BasicDataStatusConstants.Enable)
                {
                    throw new Exception("MC:0x00000233");///没有已启用的物料拉动信息
                }
                ///获取零件类信息
                TwdPartBoxInfo twdPartBoxInfo = new TwdPartBoxDAL().GetInfo(maintainInhouseLogisticStandardInfo.InhousePartClass);
                ///未能成功获取零件类信息
                if (twdPartBoxInfo == null)
                {
                    throw new Exception("MC:0x00000225");///拉动零件类数据错误
                }
                ///零件类未启用
                if (twdPartBoxInfo.Status.GetValueOrDefault() != (int)BasicDataStatusConstants.Enable)
                {
                    throw new Exception("MC:0x00000456");///零件类未启用
                }
                ///创建计数器日志
                TwdCounterLogInfo twdCounterLogInfo = TwdCounterLogBLL.CreateTwdCounterLogInfo(twdCounterInfo.Fid.GetValueOrDefault(), loginUser);
                ///以物料拉动信息填充计数器日志
                TwdCounterLogBLL.GetTwdCounterLogInfo(maintainInhouseLogisticStandardInfo, ref twdCounterLogInfo);
                ///以零件类信息填充计数器日志
                TwdCounterLogBLL.GetTwdCounterLogInfo(twdPartBoxInfo, ref twdCounterLogInfo);
                ///PART_QTY
                twdCounterLogInfo.PartQty = info.SubmitQty.GetValueOrDefault();
                ///SOURCE_DATA_FID
                twdCounterLogInfo.SourceDataFid = twdCounterInfo.Fid;
                ///SOURCE_DATA_TYPE
                twdCounterLogInfo.SourceDataType = (int)TwdCounterSourceDataTypeConstants.Manual;
                ///SOURCE_DATA
                twdCounterLogInfo.SourceData = twdCounterInfo.PartBoxCode;
                ///Comments
                twdCounterLogInfo.Comments = info.Comments;
                ///
                sql += TwdCounterLogDAL.GetInsertSql(twdCounterLogInfo);

                ///触发层级拉动
                sql += TwdCounterBLL.LevelPullRequirementCounter(
                    maintainInhouseLogisticStandardInfo,
                    info.SubmitQty.GetValueOrDefault(),
                    loginUser,
                    twdCounterInfo.Fid.GetValueOrDefault(),
                    twdCounterInfo.PartBoxCode);
            }
            ///
            using (var trans = new TransactionScope())
            {
                if (!string.IsNullOrEmpty(sql))
                {
                    CommonDAL.ExecuteNonQueryBySql(sql);
                }
                trans.Complete();
            }
            ///
            return(true);
        }
示例#4
0
        /// <summary>
        /// 执行导入EXCEL数据
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="fieldNames"></param>
        /// <returns></returns>
        public bool ImportDataByExcel(DataTable dataTable, Dictionary <string, string> fieldNames, string loginUser)
        {
            List <TwdCounterInfo> twdCounterExcelInfos = CommonDAL.DatatableConvertToList <TwdCounterInfo>(dataTable).ToList();

            if (twdCounterExcelInfos.Count == 0)
            {
                throw new Exception("MC:1x00000043");///数据格式不符合导入规范
            }
            List <TwdCounterInfo> twdCounterInfos = dal.GetList("" +
                                                                "[PART_BOX_CODE] in ('" + string.Join("','", twdCounterExcelInfos.Select(d => d.PartBoxCode).ToArray()) + "') and " +
                                                                "[PART_NO] in ('" + string.Join("','", twdCounterExcelInfos.Select(d => d.PartNo).ToArray()) + "') and " +
                                                                "[PACKAGE_MODEL] in ('" + string.Join("','", twdCounterExcelInfos.Select(d => d.PackageModel).ToArray()) + "')", string.Empty);

            List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandardInfos = new MaintainInhouseLogisticStandardDAL().GetList("" +
                                                                                                                                               "[INHOUSE_SYSTEM_MODE] = N'" + (int)PullModeConstants.Twd + "' and " +
                                                                                                                                               "[INHOUSE_PART_CLASS] in ('" + string.Join("','", twdCounterExcelInfos.Select(d => d.PartBoxCode).ToArray()) + "') and " +
                                                                                                                                               "[PART_NO] in ('" + string.Join("','", twdCounterExcelInfos.Select(d => d.PartNo).ToArray()) + "')", string.Empty);

            ///获取零件类信息
            List <TwdPartBoxInfo> twdPartBoxInfos = new TwdPartBoxDAL().GetList("" +
                                                                                "[PART_BOX_CODE] in ('" + string.Join("','", twdCounterExcelInfos.Select(d => d.PartBoxCode).ToArray()) + "')", string.Empty);


            StringBuilder @string = new StringBuilder();

            foreach (TwdCounterInfo twdCounterExcelInfo in twdCounterExcelInfos)
            {
                /// 零件类代码②、工厂③车间⑤生产线⑥工段⑬工位⑭、物料号⑩、物料版本⑫、包装容器⑰为联合主键,差异数量DiffQty作为累加当前计数⑮的依据,备注直接更新
                TwdCounterInfo twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                               d.PartBoxCode == twdCounterExcelInfo.PartBoxCode &&
                                                                               d.PartNo == twdCounterExcelInfo.PartNo &&
                                                                               d.PackageModel == twdCounterExcelInfo.PackageModel &&
                                                                               d.Plant == twdCounterExcelInfo.Plant &&
                                                                               d.Workshop == twdCounterExcelInfo.Workshop &&
                                                                               d.AssemblyLine == twdCounterExcelInfo.AssemblyLine &&
                                                                               d.WorkshopSection == twdCounterExcelInfo.WorkshopSection &&
                                                                               d.Location == twdCounterExcelInfo.Location &&
                                                                               d.PartVersion == twdCounterExcelInfo.PartVersion);

                #region 逐步减低维度处理
                if (twdCounterInfo == null)
                {
                    twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                    d.PartBoxCode == twdCounterExcelInfo.PartBoxCode &&
                                                                    d.PartNo == twdCounterExcelInfo.PartNo &&
                                                                    d.PackageModel == twdCounterExcelInfo.PackageModel &&
                                                                    d.Plant == twdCounterExcelInfo.Plant &&
                                                                    d.Workshop == twdCounterExcelInfo.Workshop &&
                                                                    d.AssemblyLine == twdCounterExcelInfo.AssemblyLine &&
                                                                    d.WorkshopSection == twdCounterExcelInfo.WorkshopSection &&
                                                                    d.Location == twdCounterExcelInfo.Location);
                }
                if (twdCounterInfo == null)
                {
                    twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                    d.PartBoxCode == twdCounterExcelInfo.PartBoxCode &&
                                                                    d.PartNo == twdCounterExcelInfo.PartNo &&
                                                                    d.PackageModel == twdCounterExcelInfo.PackageModel &&
                                                                    d.Plant == twdCounterExcelInfo.Plant &&
                                                                    d.Workshop == twdCounterExcelInfo.Workshop &&
                                                                    d.AssemblyLine == twdCounterExcelInfo.AssemblyLine &&
                                                                    d.WorkshopSection == twdCounterExcelInfo.WorkshopSection);
                }
                if (twdCounterInfo == null)
                {
                    twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                    d.PartBoxCode == twdCounterExcelInfo.PartBoxCode &&
                                                                    d.PartNo == twdCounterExcelInfo.PartNo &&
                                                                    d.PackageModel == twdCounterExcelInfo.PackageModel &&
                                                                    d.Plant == twdCounterExcelInfo.Plant &&
                                                                    d.Workshop == twdCounterExcelInfo.Workshop &&
                                                                    d.AssemblyLine == twdCounterExcelInfo.AssemblyLine);
                }
                if (twdCounterInfo == null)
                {
                    twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                    d.PartBoxCode == twdCounterExcelInfo.PartBoxCode &&
                                                                    d.PartNo == twdCounterExcelInfo.PartNo &&
                                                                    d.PackageModel == twdCounterExcelInfo.PackageModel &&
                                                                    d.Plant == twdCounterExcelInfo.Plant &&
                                                                    d.Workshop == twdCounterExcelInfo.Workshop);
                }
                if (twdCounterInfo == null)
                {
                    twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                    d.PartBoxCode == twdCounterExcelInfo.PartBoxCode &&
                                                                    d.PartNo == twdCounterExcelInfo.PartNo &&
                                                                    d.PackageModel == twdCounterExcelInfo.PackageModel &&
                                                                    d.Plant == twdCounterExcelInfo.Plant);
                }
                if (twdCounterInfo == null)
                {
                    twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                    d.PartBoxCode == twdCounterExcelInfo.PartBoxCode &&
                                                                    d.PartNo == twdCounterExcelInfo.PartNo &&
                                                                    d.PackageModel == twdCounterExcelInfo.PackageModel);
                }
                if (twdCounterInfo == null)
                {
                    twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                    d.PartBoxCode == twdCounterExcelInfo.PartBoxCode &&
                                                                    d.PartNo == twdCounterExcelInfo.PartNo);
                }
                if (twdCounterInfo == null)
                {
                    throw new Exception("MC:0x00000255");///数据格式不符合导入规范
                }
                #endregion

                if (twdCounterInfo.Status.GetValueOrDefault() == (int)BasicDataStatusConstants.Disabled)
                {
                    throw new Exception("MC:0x00000455");///计数器已作废不能修改数量
                }
                @string.AppendLine("update [LES].[TT_MPM_TWD_COUNTER] set " +
                                   "[CURRENT_QTY] = isnull([CURRENT_QTY],0) + " + twdCounterExcelInfo.DiffQty + "," +
                                   "[MODIFY_USER] = N'" + loginUser + "'," +
                                   "[MODIFY_DATE] = GETDATE() where " +
                                   "[ID] = " + twdCounterInfo.Id + ";");

                ///根据计数器的物料拉动信息外键获取物料拉动信息
                MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandardInfo = maintainInhouseLogisticStandardInfos.FirstOrDefault(d => d.Fid == twdCounterInfo.PartPullFid.GetValueOrDefault());
                if (maintainInhouseLogisticStandardInfo == null)
                {
                    throw new Exception("MC:0x00000213");///物料拉动信息数据错误
                }
                if (maintainInhouseLogisticStandardInfo.Status.GetValueOrDefault() != (int)BasicDataStatusConstants.Enable)
                {
                    throw new Exception("MC:0x00000233");///没有已启用的物料拉动信息
                }
                ///获取零件类信息
                TwdPartBoxInfo twdPartBoxInfo = twdPartBoxInfos.FirstOrDefault(d => d.PartBoxCode == maintainInhouseLogisticStandardInfo.InhousePartClass);
                ///未能成功获取零件类信息
                if (twdPartBoxInfo == null)
                {
                    throw new Exception("MC:0x00000225");///拉动零件类数据错误
                }
                ///零件类未启用
                if (twdPartBoxInfo.Status.GetValueOrDefault() != (int)BasicDataStatusConstants.Enable)
                {
                    throw new Exception("MC:0x00000456");///零件类未启用
                }
                ///创建计数器日志
                TwdCounterLogInfo twdCounterLogInfo = TwdCounterLogBLL.CreateTwdCounterLogInfo(twdCounterInfo.Fid.GetValueOrDefault(), loginUser);
                ///以物料拉动信息填充计数器日志
                TwdCounterLogBLL.GetTwdCounterLogInfo(maintainInhouseLogisticStandardInfo, ref twdCounterLogInfo);
                ///以零件类信息填充计数器日志
                TwdCounterLogBLL.GetTwdCounterLogInfo(twdPartBoxInfo, ref twdCounterLogInfo);
                ///PART_QTY
                twdCounterLogInfo.PartQty = twdCounterExcelInfo.DiffQty;
                ///SOURCE_DATA_FID
                twdCounterLogInfo.SourceDataFid = twdCounterInfo.Fid;
                ///SOURCE_DATA_TYPE
                twdCounterLogInfo.SourceDataType = (int)TwdCounterSourceDataTypeConstants.Manual;
                ///SOURCE_DATA
                twdCounterLogInfo.SourceData = twdCounterInfo.PartBoxCode;
                ///Comments
                twdCounterLogInfo.Comments = twdCounterExcelInfo.Comments;
                ///
                @string.AppendLine(TwdCounterLogDAL.GetInsertSql(twdCounterLogInfo));

                ///触发层级拉动
                @string.AppendLine(LevelPullRequirementCounter(
                                       maintainInhouseLogisticStandardInfo,
                                       twdCounterExcelInfo.DiffQty,
                                       loginUser,
                                       twdCounterInfo.Fid.GetValueOrDefault(),
                                       twdCounterInfo.PartBoxCode));
            }
            ///执行
            using (var trans = new TransactionScope())
            {
                if (@string.Length == 0)
                {
                    throw new Exception("MC:0x00000283");///没有可导入更新的数据
                }
                CommonDAL.ExecuteNonQueryBySql(@string.ToString());
                trans.Complete();
            }
            ///
            return(true);
        }
        /// <summary>
        /// 对于MPM-036逻辑进行函数封装
        /// </summary>
        /// <param name="emergencyPullingCartInfos"></param>
        /// <param name="loginUser"></param>
        public static string Handler(List <EmergencyPullingCartInfo> emergencyPullingCartInfos, string loginUser)
        {
            ///执行语句
            StringBuilder @string = new StringBuilder();
            ///获取系统配置是否允许过量提前拉动
            string allowedFlag = new ConfigDAL().GetValueByCode("ENABLE_EXCEED_COUNTER_QTY_WHEN_ADVANCE_PULL");

            ///接收紧急拉动购物车对象集合进行处理
            if (emergencyPullingCartInfos.Count == 0)
            {
                throw new Exception("MC:0x00000084");///数据错误
            }
            ///对应的物料拉动信息
            List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandardInfos = new MaintainInhouseLogisticStandardBLL().GetList("" +
                                                                                                                                               " and [STATUS] =" + (int)BasicDataStatusConstants.Enable + "" +
                                                                                                                                               " and [FID] in ('" + string.Join("','", emergencyPullingCartInfos.Select(d => d.LogisticStandardFid).ToArray()) + "')", string.Empty);

            if (maintainInhouseLogisticStandardInfos.Count == 0)
            {
                throw new Exception("MC:0x00000213");///物料拉动信息数据错误
            }
            ///首先需要将其按照拉动方式、零件类进行分组,每个分组产生一张紧急拉动单
            var cartGroups = emergencyPullingCartInfos.GroupBy(d => new { d.PullMode, d.PartBoxCode }).ToList();

            #region 手工拉动 PLAN
            var planCartGroups = cartGroups.Where(d => d.Key.PullMode == (int)PullModeConstants.Plan).ToList();
            ///计划拉动零件类
            List <PlanPartBoxInfo> planPartBoxInfos = new PlanPartBoxBLL().GetList("" +
                                                                                   " and [STATUS] = " + (int)BasicDataStatusConstants.Enable + "" +
                                                                                   " and [PART_BOX_CODE] in ('" + string.Join("','", planCartGroups.Select(d => d.Key.PartBoxCode).ToArray()) + "')", string.Empty);
            foreach (var planCartGroup in planCartGroups)
            {
                ///从参数集合从提取对应的紧急拉动购物车集合
                List <EmergencyPullingCartInfo> pullingCartInfos = emergencyPullingCartInfos.Where(d =>
                                                                                                   d.PullMode == planCartGroup.Key.PullMode && d.PartBoxCode == planCartGroup.Key.PartBoxCode).ToList();
                if (pullingCartInfos.Count == 0)
                {
                    continue;
                }
                ///计划零件类
                PlanPartBoxInfo planPartBoxInfo = planPartBoxInfos.FirstOrDefault(d => d.PartBoxCode == planCartGroup.Key.PartBoxCode);
                if (planPartBoxInfo == null)
                {
                    continue;
                }
                ///计划拉动-->仓储衔接主表
                MaterialPullingOrderInfo materialPulling = MaterialPullingCommonBLL.CreateMaterialPullingOrderInfo();
                ///计划拉动单主表
                PlanPullOrderInfo planPullOrderInfo = PlanPullOrderBLL.CreatePlanPullOrder(loginUser);
                ///OrderType 拉动单类型
                planPullOrderInfo.OrderType = (int)PullOrderTypeConstants.Emergency;
                ///PlanPartBoxInfo-->PlanPullOrderInfo
                PlanPullOrderBLL.GetPlanPullOrder(planPartBoxInfo, ref planPullOrderInfo);
                ///计划拉动单主表sql
                @string.AppendLine(PlanPullOrderDAL.GetInsertSql(planPullOrderInfo));
                ///PlanPullOrderInfo -> MaterialPullingOrderInfo
                MaterialPullingCommonBLL.GetMaterialPlanPullingOrderInfo(planPullOrderInfo, ref materialPulling);
                foreach (EmergencyPullingCartInfo planCartInfo in pullingCartInfos)
                {
                    ///物料拉动信息
                    MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandardInfo = maintainInhouseLogisticStandardInfos.FirstOrDefault(d => d.Fid == planCartInfo.LogisticStandardFid);
                    if (maintainInhouseLogisticStandardInfo == null)
                    {
                        continue;
                    }
                    ///物料包装数量在此需要根据单包装数量以及物料需求数量进行向上圆整计算
                    ///REQUIRED_BOX_QTY:物料包装数量  PULL_PACKAGE_QTY:单包装数量 REQUIRED_PART_QTY:物料需求数量
                    if (planCartInfo.PullPackageQty.GetValueOrDefault() == 0)
                    {
                        continue;                                                      ///O不能做被除数
                    }
                    planCartInfo.RequiredBoxQty = Convert.ToInt32(Math.Ceiling(planCartInfo.RequiredPartQty.GetValueOrDefault() / planCartInfo.PullPackageQty.GetValueOrDefault()));
                    ///仓储衔接明细表
                    MaterialPullingOrderDetailInfo detailInfo = MaterialPullingCommonBLL.CreateMaterialPullingOrderDetailInfo();
                    ///计划拉动单明细
                    PlanPullOrderDetailInfo planPullOrderDetailInfo = PlanPullOrderDetailBLL.CreatePlanPullOrderDetail(loginUser);
                    ///MaintainInhouseLogisticStandardInfo -> PlanPullOrderDetailInfo
                    PlanPullOrderDetailBLL.GetPlanPullOrderDetail(maintainInhouseLogisticStandardInfo, ref planPullOrderDetailInfo);
                    ///TwdPullOrderInfo -> TwdPullOrderDetailInfo
                    PlanPullOrderDetailBLL.GetPlanPullOrderDetailInfo(planPullOrderInfo, ref planPullOrderDetailInfo);
                    ///RequiredPackageQty
                    planPullOrderDetailInfo.RequiredPackageQty = planCartInfo.RequiredBoxQty.GetValueOrDefault();
                    ///RequiredPartQty
                    planPullOrderDetailInfo.RequiredPartQty = planCartInfo.RequiredPartQty.GetValueOrDefault();
                    ///计划拉动明细sql
                    @string.AppendLine(PlanPullOrderDetailDAL.GetInsertSql(planPullOrderDetailInfo));
                    ///PlanPullOrderDetailInfo -> MaterialPullingOrderDetailInfo
                    MaterialPullingCommonBLL.GetMaterialPullingOrderDetail(planPullOrderDetailInfo, ref detailInfo);
                    ///仓储明细集合Add
                    materialPulling.MaterialPullingOrderDetailInfos.Add(detailInfo);
                }
                ///拉动单生成后需要调用拉动仓储衔接函数获取语句
                @string.AppendLine(MaterialPullingCommonBLL.Handler(materialPulling, loginUser));
            }

            #endregion

            #region 提前拉动 TWD
            var twdCartGroups = cartGroups.Where(d => d.Key.PullMode == (int)PullModeConstants.Pcs || d.Key.PullMode == (int)PullModeConstants.Twd).ToList();
            ///TWD计数器
            List <TwdCounterInfo> twdCounterInfos = new TwdCounterBLL().GetList("" +
                                                                                "[STATUS] =" + (int)BasicDataStatusConstants.Enable + " and " +
                                                                                "[PART_PULL_FID] in ('" + string.Join("','", maintainInhouseLogisticStandardInfos.Select(d => d.Fid).ToArray()) + "')  and " +
                                                                                "isnull([CURRENT_QTY],0) > 0", string.Empty);
            ///TWD零件类
            List <TwdPartBoxInfo> twdPartBoxInfos = new TwdPartBoxBLL().GetList("" +
                                                                                "[STATUS] =" + (int)BasicDataStatusConstants.Enable + " and " +
                                                                                "[PART_BOX_CODE] in ('" + string.Join("','", twdCartGroups.Select(d => d.Key.PartBoxCode).ToArray()) + "')", string.Empty);
            foreach (var twdCartGroup in twdCartGroups)
            {
                ///从参数集合从提取对应的紧急拉动购物车集合
                List <EmergencyPullingCartInfo> pullingCartInfos = emergencyPullingCartInfos.Where(d =>
                                                                                                   d.PullMode == twdCartGroup.Key.PullMode && d.PartBoxCode == twdCartGroup.Key.PartBoxCode).ToList();
                if (pullingCartInfos.Count == 0)
                {
                    continue;
                }
                ///TWD零件类
                TwdPartBoxInfo twdPartBoxInfo = twdPartBoxInfos.FirstOrDefault(d => d.PartBoxCode == twdCartGroup.Key.PartBoxCode);
                if (twdPartBoxInfo == null)
                {
                    continue;
                }
                ///触发层级拉动的集合
                List <EmergencyPullingCartInfo> pullingLevelCartInfos = pullingCartInfos.Where(d => d.TriggerPullFlag == true).ToList();
                foreach (EmergencyPullingCartInfo pullingLevelCartInfo in pullingLevelCartInfos)
                {
                    ///需要根据其物料拉动信息外键获取对应的计数器数据(状态必须为已启用)
                    TwdCounterInfo twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                                   d.PartPullFid == pullingLevelCartInfo.LogisticStandardFid.GetValueOrDefault() &&
                                                                                   d.Status == (int)BasicDataStatusConstants.Enable);
                    if (twdCounterInfo == null)
                    {
                        continue;
                    }
                    ///在此之前需要根据物料图号、供应商、层级仓库、层级存储区在物料拉动信息中获取匹配的目标仓库、目标存储区数据
                    MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandardInfo = maintainInhouseLogisticStandardInfos.FirstOrDefault(d =>
                                                                                                                                                  d.PartNo == pullingLevelCartInfo.PartNo &&
                                                                                                                                                  d.SupplierNum == pullingLevelCartInfo.SupplierNum &&
                                                                                                                                                  d.WmNo == pullingLevelCartInfo.TriggerWmNo &&
                                                                                                                                                  d.ZoneNo == pullingLevelCartInfo.TriggerZoneNo);
                    ///触发层级拉动
                    @string.AppendFormat(TwdCounterBLL.LevelPullCounter(maintainInhouseLogisticStandardInfo, pullingLevelCartInfo.RequiredPartQty.GetValueOrDefault(), loginUser, twdCounterInfo.Fid.GetValueOrDefault(), twdPartBoxInfo));
                }
                ///提前拉动的集合
                List <EmergencyPullingCartInfo> advancePullCartInfos = pullingCartInfos.Where(d =>
                                                                                              d.TriggerPullFlag == false && d.EmergencyPullMode == (int)EmergencyPullModeConstants.AdvancePull).ToList();
                if (advancePullCartInfos.Count == 0)
                {
                    continue;
                }
                ///仓储衔接主表
                MaterialPullingOrderInfo materialPulling = MaterialPullingCommonBLL.CreateMaterialPullingOrderInfo();
                ///TWD拉动单主表
                TwdPullOrderInfo twdPullOrderInfo = TwdPullOrderBLL.CreateTwdPullOrderInfo(loginUser);
                ///TwdPartBoxInfo -> TwdPullOrderInfo
                TwdPullOrderBLL.GetTwdPullOrderInfo(twdPartBoxInfo, ref twdPullOrderInfo);
                ///TWD拉动单主表sql
                @string.AppendLine(TwdPullOrderDAL.GetInsertSql(twdPullOrderInfo));
                ///TwdPullOrderInfo-->MaterialPullingOrderInfo
                MaterialPullingCommonBLL.GetMaterialPullingOrderInfo(twdPullOrderInfo, ref materialPulling);
                int rowNo = 0; ///行号
                               ///逐条循环每个购物车
                foreach (EmergencyPullingCartInfo advancePullCartInfo in advancePullCartInfos)
                {
                    ///需要根据其物料拉动信息外键获取对应的计数器数据(状态必须为已启用)
                    ///TT_MPM_TWD_COUNTER TWD计数器
                    TwdCounterInfo twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                                   d.PartPullFid == advancePullCartInfo.LogisticStandardFid.GetValueOrDefault() &&
                                                                                   d.Status == (int)BasicDataStatusConstants.Enable);
                    if (twdCounterInfo == null)
                    {
                        continue;
                    }
                    ///物料拉动信息
                    MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandardInfo = maintainInhouseLogisticStandardInfos.FirstOrDefault(d => d.Fid == advancePullCartInfo.LogisticStandardFid);
                    if (maintainInhouseLogisticStandardInfo == null)
                    {
                        continue;
                    }
                    ///物料包装数量在此需要根据单包装数量以及物料需求数量进行向上圆整计算
                    ///REQUIRED_BOX_QTY:物料包装数量  PULL_PACKAGE_QTY:单包装数量 REQUIRED_PART_QTY:物料需求数量
                    if (advancePullCartInfo.PullPackageQty.GetValueOrDefault() == 0)
                    {
                        continue;                                                             ///O不能做被除数
                    }
                    advancePullCartInfo.RequiredBoxQty = Convert.ToInt32(Math.Ceiling(advancePullCartInfo.RequiredPartQty.GetValueOrDefault() / advancePullCartInfo.PullPackageQty.GetValueOrDefault()));
                    ///若该系统配置标记为false时、计数器当前累计数量不允许小于购物车物料需求数量,
                    if (allowedFlag.ToLower() == "false" && twdCounterInfo.CurrentQty.GetValueOrDefault() < advancePullCartInfo.RequiredPartQty.GetValueOrDefault())
                    {
                        continue;
                    }
                    ///仓储衔接明细表
                    MaterialPullingOrderDetailInfo detailInfo = MaterialPullingCommonBLL.CreateMaterialPullingOrderDetailInfo();
                    ///TWD明细表
                    TwdPullOrderDetailInfo pullOrderDetailInfo = TwdPullOrderDetailBLL.CreateTwdPullOrderDetailInfo(loginUser);
                    ///MaintainInhouseLogisticStandardInfo -> TwdPullOrderDetailInfo
                    TwdPullOrderDetailBLL.GetTwdPullOrderDetailInfo(maintainInhouseLogisticStandardInfo, ref pullOrderDetailInfo);
                    ///TwdPullOrderInfo -> TwdPullOrderDetailInfo
                    TwdPullOrderDetailBLL.GetTwdPullOrderDetailInfo(twdPullOrderInfo, ref pullOrderDetailInfo);
                    ///ROW_NO,行号
                    pullOrderDetailInfo.RowNo = ++rowNo;
                    ///REQUIRED_PACKAGE_QTY,需求包装数
                    pullOrderDetailInfo.RequiredPackageQty = advancePullCartInfo.RequiredBoxQty.GetValueOrDefault();
                    ///REQUIRED_PART_QTY,需求物料数量
                    pullOrderDetailInfo.RequiredPartQty = advancePullCartInfo.RequiredPartQty.GetValueOrDefault();
                    ///TWD明细表sql
                    @string.AppendLine(TwdPullOrderDetailDAL.GetInsertSql(pullOrderDetailInfo));
                    ///TwdPullOrderDetailInfo -> MaterialPullingOrderDetailInfo
                    MaterialPullingCommonBLL.GetMaterialPullingOrderDetailInfo(pullOrderDetailInfo, ref detailInfo);
                    ///仓储衔接集合Add
                    materialPulling.MaterialPullingOrderDetailInfos.Add(detailInfo);
                    ///否则直接对计数器的当前累计数量按购物车物料需求数量进行扣减
                    @string.AppendLine("update [LES].[TT_MPM_TWD_COUNTER] " +
                                       "set [CURRENT_QTY] = isnull([CURRENT_QTY],0) - " + advancePullCartInfo.RequiredPartQty.GetValueOrDefault() + "," +
                                       "[MODIFY_DATE] = GETDATE()," +
                                       "[MODIFY_USER] = N'" + loginUser + "' " +
                                       "where [ID]= " + twdCounterInfo.Id + ";");
                    ///同时记录计数器日志并标记其类型为提前拉动
                    TwdCounterLogInfo twdCounterLogInfo = TwdCounterLogBLL.CreateTwdCounterLogInfo(twdCounterInfo.Fid.GetValueOrDefault(), loginUser);
                    ///TwdCounterInfo -> TwdCounterLogInfo
                    TwdCounterLogBLL.GetTwdCounterLogInfo(twdCounterInfo, ref twdCounterLogInfo);
                    ///PART_QTY,物料数量
                    twdCounterLogInfo.PartQty = 0 - advancePullCartInfo.RequiredPartQty.GetValueOrDefault();
                    ///SOURCE_DATA,目视来源数据
                    twdCounterLogInfo.SourceData = twdPullOrderInfo.OrderCode;
                    ///SOURCE_DATA_FID,数据来源外键
                    twdCounterLogInfo.SourceDataFid = twdPullOrderInfo.Fid;
                    ///SOURCE_DATA_TYPE,数据来源类型
                    twdCounterLogInfo.SourceDataType = (int)TwdCounterSourceDataTypeConstants.AdvancePull;
                    ///计数器日志sql
                    @string.AppendLine(TwdCounterLogDAL.GetInsertSql(twdCounterLogInfo));
                }
                ///拉动单生成后需要调用拉动仓储衔接函数获取语句
                @string.AppendLine(MaterialPullingCommonBLL.Handler(materialPulling, loginUser));
            }

            #endregion

            return(@string.ToString());
        }