yl
2024-06-17 cd23b00f03ac749e998a823a530f277772e734af
VueWebCoreApi/DLL/DAL/WorkOrderDAL.cs
@@ -27,7 +27,7 @@
        #region[ERP订单查询]
        public static ToMessage ErpOrderSearch(string erporderstus, string wkshopcode, string erpordercode, string saleordercode, string partcode, string partname, string partspec, int startNum,string datatype, string paydatestartdate, string paydateenddate, string creatuser, int endNum, string prop, string order)
        public static ToMessage ErpOrderSearch(string erporderstus, string wkshopcode, string erpordercode, string saleordercode, string partcode, string partname, string partspec, int startNum, string datatype, string paydatestartdate, string paydateenddate, string creatuser, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
@@ -129,7 +129,7 @@
        #endregion
        #region[ERP订单下达]
        public static ToMessage MarkSaveErpOrder(string erporderid, string sbid, string erpordercode, string saleordercode, string partcode, string wkshopcode, string warehousecode, string erpqty, string markqty, string ordernum, string relse_qty, string saleOrderDeliveryDate,string paystartdate,string payenddate, string clerkuser, User us)
        public static ToMessage MarkSaveErpOrder(string erporderid, string sbid, string erpordercode, string saleordercode, string partcode, string wkshopcode, string warehousecode, string erpqty, string markqty, string ordernum, string relse_qty, string saleOrderDeliveryDate, string paystartdate, string payenddate, string clerkuser, User us)
        {
            var sql = "";
            List<object> list = new List<object>();
@@ -192,7 +192,7 @@
                                plan_enddate = Convert.ToDateTime(payenddate),
                                data_sources = "ERP",
                                isstep = "N",  //是否关联工序
                                clerkuser= clerkuser //销售订单业务员
                                clerkuser = clerkuser //销售订单业务员
                            }
                        });
                        sumqty = sumqty + (decimal.Parse(markqty) - sumqty);
@@ -225,7 +225,7 @@
                                plan_enddate = Convert.ToDateTime(payenddate),
                                data_sources = "ERP",
                                isstep = "N",//是否关联工序
                                clerkuser= clerkuser
                                clerkuser = clerkuser
                            }
                        });
                    }
@@ -306,7 +306,7 @@
                {
                    string erpordercode = group.erpordercode;
                    int count = 1;
                    foreach (var model in obj.Where(s => s.erpordercode==erpordercode).ToList())
                    foreach (var model in obj.Where(s => s.erpordercode == erpordercode).ToList())
                    {
                        //获取当前最大工单号
                        sql = @"select isnull(max(cast(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code)) as numeric)),0) as worknumb   
@@ -342,7 +342,7 @@
                                plan_enddate = Convert.ToDateTime(model.payenddate),
                                data_sources = "ERP",
                                isstep = "N",  //是否关联工序
                                clerkuser= model.clerkuser //销售订单业务员
                                clerkuser = model.clerkuser //销售订单业务员
                            }
                        });
@@ -534,7 +534,7 @@
        #region[MES工单查询]
        public static ToMessage MesOrderSearch(string mesorderstus, string wkshopcode, string mesordercode, string sourceorder, string saleordercode, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string datatype,string paydatestartdate,string paydateenddate, int endNum, string prop, string order)
        public static ToMessage MesOrderSearch(string mesorderstus, string wkshopcode, string mesordercode, string sourceorder, string saleordercode, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string datatype, string paydatestartdate, string paydateenddate, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
@@ -624,7 +624,7 @@
                }
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select A.id, A.status,A.wotype,A.wo_code,A.materiel_code as partcode,B.partname,B.partspec,A.plan_qty,A.wkshp_code,C.torg_name as wkshp_name,
                var sql = @"select A.id, A.status,A.wotype,A.wo_code,A.materiel_code as partcode,B.partname,B.partspec,A.route_code,R.name as route_name,A.plan_qty,A.wkshp_code,C.torg_name as wkshp_name,
                            A.stck_code,D.name as stck_name,A.plan_startdate,A.plan_enddate,A.piroque,A.sourceid,A.m_po,A.saleOrderDeliveryDate,W.saleOrderCode,U.username as lm_user,A.lm_date,A.data_sources,A.isstep,A.clerkuser
                            from TK_Wrk_Man A
                            left join TKimp_Ewo W on A.m_po=W.wo and A.materiel_code=W.materiel_code and A.sbid=W.sbid
@@ -633,6 +633,7 @@
                            left join TSecStck D on A.stck_code=D.code 
                            left join TUser U on A.lm_user=U.usercode 
                            left join TOrganization L on  C.parent_id=L.id
                            left join TFlw_Rout R on A.route_code=R.code
                            where A.is_delete<>'1' " + search;
                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                mes.code = "200";
@@ -775,10 +776,9 @@
                if (data_sources == "ERP")  //数据来源ERP
                {
                    //查询订单任务总数
                    sql = @"select qty  from TKimp_Ewo where id=@sourceid and wo=@sourcewo";
                    sql = @"select qty,relse_qty  from TKimp_Ewo where id=@sourceid and wo=@sourcewo";
                    dynamicParams.Add("@sourceid", sourceid);
                    dynamicParams.Add("@sourcewo", sourcewo);
                    dynamicParams.Add("@wocode", wocode);
                    var data0 = DapperHelper.selectdata(sql, dynamicParams);
                    //查询当前工单可修改数量=订单总数-已下达工单总数
                    sql = @"select isnull(sum(plan_qty),0) as plan_qty   from TK_Wrk_Man 
@@ -836,16 +836,26 @@
        #region[MES工单新增、编辑提交]
        public static ToMessage AddUpdateMesOrder(string operType, WorkList json, User us)
        {
            string sql = "";
            string sql = "", route_code = "";
            var dynamicParams = new DynamicParameters();
            List<object> list = new List<object>();
            try
            {
                dynamic dynObj = JObject.Parse(us.mesSetting);
                bool route = dynObj.route;
                if (route) //工艺路线版
                {
                    route_code = json.routecode;
                }
                else //工序版
                {
                    route_code = null;
                }
                if (operType == "Add")
                {
                    //写入工单表
                    sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,lm_user,lm_date,materiel_code,sourceid,m_po,saleOrderDeliveryDate,plan_startdate,plan_enddate,piroque,isaps,data_sources,isstep)
                                values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@lm_user,@lm_date,@materiel_code,@sourceid,@m_po,@saleOrderDeliveryDate,@plan_startdate,@plan_enddate,@orderlev,@isaps,@data_sources,@isstep)";
                    sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,lm_user,lm_date,materiel_code,route_code,sourceid,m_po,saleOrderDeliveryDate,plan_startdate,plan_enddate,piroque,isaps,data_sources,isstep)
                                values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@lm_user,@lm_date,@materiel_code,@route_code,@sourceid,@m_po,@saleOrderDeliveryDate,@plan_startdate,@plan_enddate,@orderlev,@isaps,@data_sources,@isstep)";
                    list.Add(new
                    {
                        str = sql,
@@ -859,6 +869,7 @@
                            lm_user = us.usercode,
                            lm_date = DateTime.Now.ToString(),
                            materiel_code = json.partcode,
                            route_code = route_code,
                            sourceid = json.sourceid == "" ? null : json.sourceid, //无源单时赋值NULL
                            m_po = json.sourcewo,
                            saleOrderDeliveryDate = json.deliverydate,
@@ -873,8 +884,8 @@
                    //写入工序任务表
                    for (int i = 0; i < json.WorkListSub.Count; i++)
                    {
                        sql = @"insert into TK_Wrk_Step(wo_code,seq,step_code,stepprice,plan_qty,status,isbott,isend,lm_user,lm_date)
                                values(@wo_code,@seq,@step_code,@stepprice,@plan_qty,@status,@isbott,@isend,@lm_user,@lm_date)";
                        sql = @"insert into TK_Wrk_Step(wo_code,seq,step_code,route_code,stepprice,plan_qty,status,isbott,isend,lm_user,lm_date)
                                values(@wo_code,@seq,@step_code,@route_code,@stepprice,@plan_qty,@status,@isbott,@isend,@lm_user,@lm_date)";
                        list.Add(new
                        {
                            str = sql,
@@ -883,6 +894,7 @@
                                wo_code = json.wocode,
                                seq = json.WorkListSub[i].stepseq,
                                step_code = json.WorkListSub[i].stepcode,
                                route_code = route_code,
                                stepprice = json.WorkListSub[i].stepprice,
                                plan_qty = json.woqty,
                                status = json.wostatus,
@@ -915,7 +927,7 @@
                {
                    //修改工单表
                    sql = @"update TK_Wrk_Man set wotype=@wotype,wkshp_code=@wkshp_code,plan_qty=@plan_qty,lm_user=@lm_user,lm_date=@lm_date,
                            materiel_code=@materiel_code,sourceid=@sourceid,m_po=@m_po,saleOrderDeliveryDate=@saleOrderDeliveryDate,plan_startdate=@plan_startdate,plan_enddate=@plan_enddate,isstep=@isstep
                            materiel_code=@materiel_code,route_code=@route_code,sourceid=@sourceid,m_po=@m_po,saleOrderDeliveryDate=@saleOrderDeliveryDate,plan_startdate=@plan_startdate,plan_enddate=@plan_enddate,isstep=@isstep
                            where wo_code=@wo_code";
                    list.Add(new
                    {
@@ -927,6 +939,7 @@
                            wkshp_code = json.wkshopcode,
                            plan_qty = json.woqty,
                            materiel_code = json.partcode,
                            route_code = route_code,
                            sourceid = json.sourceid == "" ? null : json.sourceid, //无源单时赋值NULL
                            m_po = json.sourcewo,
                            saleOrderDeliveryDate = json.deliverydate,
@@ -950,8 +963,8 @@
                    //写入工单工序表
                    for (int i = 0; i < json.WorkListSub.Count; i++)
                    {
                        sql = @"insert into TK_Wrk_Step(wo_code,seq,step_code,stepprice,plan_qty,status,isbott,isend,lm_user,lm_date)
                                values(@wo_code,@seq,@step_code,@stepprice,@plan_qty,@status,@isbott,@isend,@lm_user,@lm_date)";
                        sql = @"insert into TK_Wrk_Step(wo_code,seq,step_code,route_code,stepprice,plan_qty,status,isbott,isend,lm_user,lm_date)
                                values(@wo_code,@seq,@step_code,@route_code,@stepprice,@plan_qty,@status,@isbott,@isend,@lm_user,@lm_date)";
                        list.Add(new
                        {
                            str = sql,
@@ -960,6 +973,7 @@
                                wo_code = json.wocode,
                                seq = json.WorkListSub[i].stepseq,
                                step_code = json.WorkListSub[i].stepcode,
                                route_code = route_code,
                                stepprice = json.WorkListSub[i].stepprice,
                                plan_qty = json.woqty,
                                status = json.wostatus,
@@ -969,6 +983,45 @@
                                lm_date = DateTime.Now.ToString()
                            }
                        });
                    }
                    //判断源头单据是否来源ERP
                    if (json.data_sources == "ERP")
                    {
                        //判断工单修改数量差值是否为0
                        if (json.difference != "0")
                        {
                            string staus = "";
                            //查询订单总数,已下达数量
                            sql = @"select qty,relse_qty  from TKimp_Ewo where id=@sourceid and wo=@sourcewo";
                            dynamicParams.Add("@sourceid", json.sourceid);
                            dynamicParams.Add("@sourcewo", json.sourcewo);
                            var data0 = DapperHelper.selectdata(sql, dynamicParams);
                            //当前工单可修改数量=订单数量-非当前工单总下达工单数量
                            decimal qty = decimal.Parse(data0.Rows[0]["qty"].ToString());//订单总数
                            decimal relse_qty = decimal.Parse(data0.Rows[0]["relse_qty"].ToString());//订单已下达总数
                            relse_qty = relse_qty + decimal.Parse(json.difference);//新的下达数量=原始下达数量+差值(正负)
                            if (qty == relse_qty)
                            {
                                staus = "CREATED"; //全部下达
                            }
                            else
                            {
                                staus = "CREATING";//部分下达
                            }
                            //更新订单表状态、已下达数量
                            sql = @"update TKimp_Ewo set status=@status,relse_qty=@relse_qty where id=@sourceid and wo=@sourcewo";
                            list.Add(new
                            {
                                str = sql,
                                parm = new
                                {
                                    status = staus,
                                    relse_qty = relse_qty,
                                    sourceid = json.sourceid,
                                    sourcewo = json.sourcewo
                                }
                            });
                        }
                    }
                    bool aa = DapperHelper.DoTransaction(list);
@@ -1085,15 +1138,36 @@
        #endregion
        #region[MES工单查找历史引用最新工序信息]
        public static ToMessage MesOrderNewStepContent(string wkshopcode, string partcode, User us)
        public static ToMessage MesOrderNewStepContent(string wkshopcode, string routecode, string partcode, User us)
        {
            var sql = "";
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                //MES工单查找历史引用最新工序信息
                sql = @"select S.wo_code,S.seq,S.step_code,S.stepprice,isbott,isend
                dynamic dynObj = JObject.Parse(us.mesSetting);
                bool route = dynObj.route;
                if (route) //工艺路线版
                {
                    //MES工单查找历史引用最新工序信息
                    sql = @"select S.wo_code,S.seq,S.step_code,S.stepprice,isbott,isend
                        from TK_Wrk_Step S
                        inner join (
                        select top 1 A.wo_code,A.route_code   from TK_Wrk_Man A
                        inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.route_code=S.route_code
                        where A.materiel_code=@partcode and A.wkshp_code=@wkshopcode and A.route_code=@routecode
                        order by A.lm_date desc
                        ) as W on S.wo_code=W.wo_code and S.route_code=W.route_code
                        left join TStep  T on S.step_code=T.stepcode
                        order by S.seq";
                    dynamicParams.Add("@wkshopcode", wkshopcode);
                    dynamicParams.Add("@partcode", partcode);
                    dynamicParams.Add("@routecode", routecode);
                }
                else
                {
                    //MES工单查找历史引用最新工序信息
                    sql = @"select S.wo_code,S.seq,S.step_code,S.stepprice,isbott,isend
                        from TK_Wrk_Step S
                        inner join (
                        select top 1 A.wo_code   from TK_Wrk_Man A
@@ -1103,8 +1177,10 @@
                        ) as W on S.wo_code=W.wo_code
                        left join TStep  T on S.step_code=T.stepcode
                        order by S.seq";
                dynamicParams.Add("@wkshopcode", wkshopcode);
                dynamicParams.Add("@partcode", partcode);
                    dynamicParams.Add("@wkshopcode", wkshopcode);
                    dynamicParams.Add("@partcode", partcode);
                }
                var data = DapperHelper.selectdata(sql, dynamicParams);
                mes.code = "200";
                mes.count = data.Rows.Count;
@@ -1735,18 +1811,34 @@
        #endregion
        #region [生产开报工:报工/外协(发料/收料)时条件判断及数据返回接口]
        public static ToMessage MesOrderStepStart(string OperType, string SelectType, string wocode, string stepcode)
        public static ToMessage MesOrderStepStart(string OperType, string SelectType, string wocode, string stepcode, User us)
        {
            var dynamicParams = new DynamicParameters();
            try
            {
                dynamic dynObj = JObject.Parse(us.mesSetting);
                bool isOrder = dynObj.isOrder;
                switch (OperType)
                {
                    case "ZZ":
                        mes = ScanStartReport.ZZEncodingSeach(wocode, stepcode);
                        if (isOrder) //按序生产
                        {
                            mes = ScanStartReport.ZZEncodingSeach(wocode, stepcode);
                        }
                        else //不按序生产
                        {
                            mes = ScanStartReport.NoZZEncodingSeach(wocode, stepcode);
                        }
                        break;
                    case "WX":
                        mes = ScanStartReport.WXEncodingSeach(SelectType, wocode, stepcode);
                        if (isOrder) //按序收发料
                        {
                            mes = ScanStartReport.WXEncodingSeach(SelectType, wocode, stepcode);
                        }
                        else //不按序收发料
                        {
                            mes = ScanStartReport.NoWXEncodingSeach(SelectType, wocode, stepcode);
                        }
                        break;
                    default:
                        break;
@@ -2686,42 +2778,537 @@
            var dynamicParams = new DynamicParameters();
            try
            {
                //控制逻辑:首道工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>任务数量   ==不能大于任务数量
                //控制逻辑:首道工序调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废)   ==不能小于下道报工总数
                //控制逻辑:末道工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>上道工序报工合格总数   ==不能大于上道工序报工合格总数
                //控制逻辑:中间工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>上道工序报工合格总数   ==不能大于上道工序报工合格总数
                //控制逻辑:中间工序调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废)   ==不能小于下道报工总数
                dynamic dynObj = JObject.Parse(us.mesSetting);
                bool isOrder = dynObj.isOrder;
                //获取此次报工调整提交的数据(合格数量、不良数量、工废数量、料废数量)
                decimal this_reportqty = decimal.Parse(json[0].report_qty.ToString()); //报工数量(合格)
                decimal this_ngqty = json[0].children.Sum(item => decimal.Parse(item.ng_qty));//不良数量汇总
                decimal this_laborbadqty = json[0].children.Sum(item => decimal.Parse(item.laborbad_qty));//工废数量汇总
                decimal this_materielbadqty = json[0].children.Sum(item => decimal.Parse(item.materielbad_qty));//料废数量汇总
                decimal this_ng_dvalue = json[0].children.Sum(item => decimal.Parse(item.ng_dvalue));//不良数量差值汇总
                decimal this_laborbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.laborbad_dvalue));//工废数量差值汇总
                decimal this_materielbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.materielbad_dvalue));//料废数量差值汇总
                string date = DateTime.Now.ToString(); //获取系统时间
                list.Clear();
                //获取当前工序上道工序及属性
                sql = @"select T.stepcode,T.stepname,T.flwtype from TK_Wrk_Step A
                if (isOrder) //按序
                {
                    //控制逻辑:首道工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>任务数量   ==不能大于任务数量
                    //控制逻辑:首道工序调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废)   ==不能小于下道报工总数
                    //控制逻辑:末道工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>上道工序报工合格总数   ==不能大于上道工序报工合格总数
                    //控制逻辑:中间工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>上道工序报工合格总数   ==不能大于上道工序报工合格总数
                    //控制逻辑:中间工序调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废)   ==不能小于下道报工总数
                    list.Clear();
                    //获取当前工序上道工序及属性
                    sql = @"select T.stepcode,T.stepname,T.flwtype from TK_Wrk_Step A
                                left join  TStep T on A.step_code=T.stepcode
                                where A.wo_code=@ordercode and A.seq=@seq-1 ";
                dynamicParams.Add("@ordercode", json[0].wo_code);
                dynamicParams.Add("@seq", json[0].step_seq);
                var pre = DapperHelper.selectdata(sql, dynamicParams);
                //获取当前工序下道工序及属性
                sql = @"select T.stepcode,T.stepname,T.flwtype from TK_Wrk_Step A
                    dynamicParams.Add("@ordercode", json[0].wo_code);
                    dynamicParams.Add("@seq", json[0].step_seq);
                    var pre = DapperHelper.selectdata(sql, dynamicParams);
                    //获取当前工序下道工序及属性
                    sql = @"select T.stepcode,T.stepname,T.flwtype from TK_Wrk_Step A
                                left join  TStep T on A.step_code=T.stepcode
                                where A.wo_code=@ordercode and A.seq=@seq+1 ";
                dynamicParams.Add("@ordercode", json[0].wo_code);
                dynamicParams.Add("@seq", json[0].step_seq);
                var next = DapperHelper.selectdata(sql, dynamicParams);
                //判断当前工序是自制工序还是外协工序
                if (json[0].flw_type.ToString() == "Z")//自制工序
                {
                    //获取此次报工调整提交的数据(合格数量、不良数量、工废数量、料废数量)
                    decimal this_reportqty = decimal.Parse(json[0].report_qty.ToString()); //报工数量(合格)
                    decimal this_ngqty = json[0].children.Sum(item => decimal.Parse(item.ng_qty));//不良数量汇总
                    decimal this_laborbadqty = json[0].children.Sum(item => decimal.Parse(item.laborbad_qty));//工废数量汇总
                    decimal this_materielbadqty = json[0].children.Sum(item => decimal.Parse(item.materielbad_qty));//料废数量汇总
                    decimal this_ng_dvalue = json[0].children.Sum(item => decimal.Parse(item.ng_dvalue));//不良数量差值汇总
                    decimal this_laborbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.laborbad_dvalue));//工废数量差值汇总
                    decimal this_materielbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.materielbad_dvalue));//料废数量差值汇总
                    //首道工序的报工
                    if (json[0].first_choke == "Y")
                    dynamicParams.Add("@ordercode", json[0].wo_code);
                    dynamicParams.Add("@seq", json[0].step_seq);
                    var next = DapperHelper.selectdata(sql, dynamicParams);
                    //判断当前工序是自制工序还是外协工序
                    if (json[0].flw_type.ToString() == "Z")//自制工序
                    {
                        //查询当前首道报工工序非此次报工:总报工数量、总不良数量、总工废数量、总料废数量
                        //首道工序的报工
                        if (json[0].first_choke == "Y")
                        {
                            //查询当前首道报工工序非此次报工:总报工数量、总不良数量、总工废数量、总料废数量
                            sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                from TK_Wrk_Record where wo_code=@wo_code and style='B' and id<>@id and step_code=@step_code";
                            dynamicParams.Add("@wo_code", json[0].wo_code);
                            dynamicParams.Add("@id", json[0].id);
                            dynamicParams.Add("@step_code", json[0].step_code);
                            var dt = DapperHelper.selectdata(sql, dynamicParams);
                            decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前工序非本次报工总数
                            decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前工序非本次报工总不良数
                            decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前工序非本次报工总工废数
                            decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前工序非本次报工总料废数
                            //判断:当前工序报工记录:本次报工数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次报工总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>工单任务数量
                            decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty;
                            if (updatereportsumqty > decimal.Parse(json[0].task_qty.ToString()))
                            {
                                mes.code = "300";
                                mes.count = 0;
                                mes.message = "当前首道工序修改报工总数量:【" + updatereportsumqty + "】不能大于工单任务数量:【" + json[0].task_qty.ToString() + "】!";
                                mes.data = null;
                                return mes;
                            }
                            //判断是否存在下道工序及属性
                            if (next.Rows.Count > 0)
                            {
                                if (next.Rows[0]["flwtype"].ToString() == "Z")
                                {
                                    //查询当前工序下道工序:总报工数量、总不良数量、总报废数量
                                    sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq+1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt0.Rows.Count > 0)
                                    {
                                        //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量
                                        decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                        decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                        decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString());  //下道工序工废总数量
                                        decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString());  //下道工序料废总数量
                                        decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                        //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序报工总数
                                        if ((notthis_reportqty + this_reportqty) < last_updatereportsumqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前首道工序修改报工总合格数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                                else
                                {
                                    //查询当前工序下道工序:总发料数量
                                    sql = @"select isnull(sum(fqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='S'  and step_seq=@step_seq+1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt0.Rows.Count > 0)
                                    {
                                        //判断当前工序:发料总数数量
                                        decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序发料总数量
                                                                                                                     //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序发料总数
                                        if ((notthis_reportqty + this_reportqty) < last_reportqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前首道工序修改报工总合格数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                            }
                        }
                        //末道工序的报工
                        else if (json[0].last_choke == "Y")
                        {
                            //查询当前末道报工工序非此次报工:总报工数量、总不良数量、总工废数量、总料废数量
                            sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                from TK_Wrk_Record where wo_code=@wo_code and style='B' and id<>@id and step_code=@step_code";
                            dynamicParams.Add("@wo_code", json[0].wo_code);
                            dynamicParams.Add("@id", json[0].id);
                            dynamicParams.Add("@step_code", json[0].step_code);
                            var dt = DapperHelper.selectdata(sql, dynamicParams);
                            decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前末道工序非本次报工总数
                            decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前末道工序非本次报工总数
                            decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前末道工序非本次报工工废总数
                            decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前末道工序非本次报工料废总数
                                                                                                                        //获取当前末道工序报工总数量:本次修改报工数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前末道工序非本次报工总数+当前末道工序非本次不良总数+当前末道工序非本次工废总数+当前末道工序非本次料废总数
                            decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty;
                            //判断是否存在上道工序及属性
                            if (pre.Rows.Count > 0)
                            {
                                if (pre.Rows[0]["flwtype"].ToString() == "Z")
                                {
                                    //查询当前末道工序上道工序:总报工数量、总不良数量、总报废数量
                                    sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq-1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt0.Rows.Count > 0)
                                    {
                                        decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //上道工序报工总数量
                                        decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //上道工序不良总数量
                                        decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString());  //上道工序工废总数量
                                        decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString());  //上道工序料废总数量
                                        decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                        //判断:当前末道工序报工记录:当前末道工序报工总数量>上道工序报工合格总数
                                        if (updatereportsumqty > last_reportqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前末道工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序报工总合格数量:【" + last_reportqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                                else
                                {
                                    //查询当前工序上道工序:总收料数量
                                    sql = @"select isnull(sum(sqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='S'  and step_seq=@step_seq-1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt0.Rows.Count > 0)
                                    {
                                        //判断当前工序:收料总数数量
                                        decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序发料总数量
                                                                                                                     //判断:当前末道工序报工记录:当前末道工序报工总数量>上道工序收料合格总数
                                        if (updatereportsumqty > last_reportqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前末道工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序收料总合格数量:【" + last_reportqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                            }
                        }
                        else //中间工序的报工
                        {
                            //查询当前中间报工工序非此次报工:总报工数量、总不良数量、总报废数量
                            sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B' and id<>@id and step_code=@step_code";
                            dynamicParams.Add("@wo_code", json[0].wo_code);
                            dynamicParams.Add("@id", json[0].id);
                            dynamicParams.Add("@step_code", json[0].step_code);
                            var dt = DapperHelper.selectdata(sql, dynamicParams);
                            decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前工序非本次报工总数
                            decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前工序非本次报工总数
                            decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前工序非本次报工工费总数
                            decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前工序非本次报工料废总数
                                                                                                                        //获取当前中间工序报工总数量:本次修改报工数量+本次修改不良数量+本次修改工废数量+本次修改料废总数+当前工序非本次报工总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数
                            decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty;
                            //判断是否存在上道工序及属性
                            if (pre.Rows.Count > 0)
                            {
                                if (pre.Rows[0]["flwtype"].ToString() == "Z")
                                {
                                    //查询当前工序上道工序:总报工数量、总不良数量、总工废数量、总料废数量
                                    sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq-1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt0.Rows.Count > 0)
                                    {
                                        decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //上道工序报工总合格数量
                                        decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //上道工序不良总数量
                                        decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString());  //上道工序工废总数量
                                        decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString());//上道工序料废总数量
                                        decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                        //判断:当前工序报工记录:当前工序报工总数>上道工序报工总合格数
                                        if (updatereportsumqty > last_reportqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序报工总合格数量:【" + last_reportqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                                else
                                {
                                    //查询当前工序上道工序:总收料数量
                                    sql = @"select isnull(sum(sqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='S'  and step_seq=@step_seq-1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt0.Rows.Count > 0)
                                    {
                                        //判断当前工序:收料总数数量
                                        decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //上道工序收料总合格数量
                                                                                                                     //判断:当前末道工序报工记录:当前工序报工总数量>上道工序收料总合格数量
                                        if (updatereportsumqty > last_reportqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序收料总合格数量:【" + last_reportqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                            }
                            //判断是否存在下道工序属性
                            if (next.Rows.Count > 0)
                            {
                                if (next.Rows[0]["flwtype"].ToString() == "Z")
                                {
                                    //查询当前工序下道工序:总报工数量、总不良数量、总报废数量
                                    sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq+1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt1 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt1.Rows.Count > 0)
                                    {
                                        decimal last_reportqty = decimal.Parse(dt1.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                        decimal last_ngqty = decimal.Parse(dt1.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                        decimal last_laborbad_qty = decimal.Parse(dt1.Rows[0]["laborbad_qty"].ToString());  //下道工序工废总数量
                                        decimal last_materielbad_qty = decimal.Parse(dt1.Rows[0]["materielbad_qty"].ToString());  //下道工序料废总数量
                                        decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                        //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序报工总数
                                        if ((notthis_reportqty + this_reportqty) < last_updatereportsumqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前工序修改报工总合格数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道工序报工总数量:【" + last_updatereportsumqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                                else
                                {
                                    //查询当前工序下道工序:总发料数量
                                    sql = @"select isnull(sum(fqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='F'  and step_seq=@step_seq+1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt0.Rows.Count > 0)
                                    {
                                        //判断当前工序:发料总数数量
                                        decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序发料总合格数量
                                                                                                                     //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序发料总数
                                        if ((notthis_reportqty + this_reportqty) < last_reportqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前工序修改报工总数量:【" + (notthis_reportqty + this_reportqty) + "】不能大于下道工序发料总数量:【" + last_reportqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (json[0].flw_type.ToString() == "W")//外协工序
                    {
                        //查询当前首道工序非此次供应商收料:总收料数量
                        sql = @"select isnull(sum(sqty),0) as sqty
                                from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code<>@wx_code";
                        dynamicParams.Add("@wo_code", json[0].wo_code);
                        dynamicParams.Add("@id", json[0].id);
                        dynamicParams.Add("@step_code", json[0].step_code);
                        dynamicParams.Add("@wx_code", json[0].wxcode);
                        var dt_c = DapperHelper.selectdata(sql, dynamicParams);
                        //获取当前工序、供应商对应的发料数量
                        sql = @"select isnull(sum(fqty),0) as fqty
                                from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and id<>@id and step_code=@step_code and wx_code=@wx_code";
                        dynamicParams.Add("@wo_code", json[0].wo_code);
                        dynamicParams.Add("@id", json[0].id);
                        dynamicParams.Add("@step_code", json[0].step_code);
                        dynamicParams.Add("@wx_code", json[0].wxcode);
                        var dt_0 = DapperHelper.selectdata(sql, dynamicParams);
                        //首道工序的收料
                        if (json[0].first_choke == "Y")
                        {
                            //查询当前首道工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量
                            sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code";
                            dynamicParams.Add("@wo_code", json[0].wo_code);
                            dynamicParams.Add("@id", json[0].id);
                            dynamicParams.Add("@step_code", json[0].step_code);
                            dynamicParams.Add("@wx_code", json[0].wxcode);
                            var dt = DapperHelper.selectdata(sql, dynamicParams);
                            decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前工序非本次收料总数
                            decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前工序非本次报工总不良数
                            decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前工序非本次报工总工废数
                            decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前工序非本次报工总料废数
                            //判断:当前工序报工记录:本次收料数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>发料数量
                            decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty;
                            if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString()))
                            {
                                mes.code = "300";
                                mes.count = 0;
                                mes.message = "当前外协工序对应供应商收料总数量:【" + updatereportsumqty + "】不能大于发料数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!";
                                mes.data = null;
                                return mes;
                            }
                            //判断是否存在下道工序及属性
                            if (next.Rows.Count > 0)
                            {
                                if (next.Rows[0]["flwtype"].ToString() == "Z")
                                {
                                    //查询当前工序下道工序:总报工数量、总不良数量、总报废数量
                                    sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq+1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt0.Rows.Count > 0)
                                    {
                                        //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量
                                        decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                        decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                        decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString());  //下道工序工废总数量
                                        decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString());  //下道工序料废总数量
                                        decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                        //判断(当前非本次收料数+本次收料调整数+非当前供应商同工序收料总数)<下道工序报工总数
                                        if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_updatereportsumqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前外协工序收料数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                                else
                                {
                                    //查询当前工序下道工序:总发料数量
                                    sql = @"select isnull(sum(fqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='F'  and step_seq=@step_seq+1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt0.Rows.Count > 0)
                                    {
                                        //判断当前工序:发料总数数量
                                        decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序发料总数量
                                                                                                                     //判断(当前非本次收料数+本次报工调整收料数)<下道工序发料总数
                                        if ((notthis_reportqty + this_reportqty) < last_reportqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前外协工序收料总数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                            }
                        }
                        //末道工序的报工
                        else if (json[0].last_choke == "Y")
                        {
                            //查询当前末道报工工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量
                            sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code  and wx_code=@wx_code";
                            dynamicParams.Add("@wo_code", json[0].wo_code);
                            dynamicParams.Add("@id", json[0].id);
                            dynamicParams.Add("@step_code", json[0].step_code);
                            var dt = DapperHelper.selectdata(sql, dynamicParams);
                            decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前末道工序非本次收料总数
                            decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前末道工序非本次报工总数
                            decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前末道工序非本次报工工废总数
                            decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前末道工序非本次报工料废总数
                                                                                                                        //获取当前末道工序收料总数量:本次修改收料数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前末道工序非本次收料总数+当前末道工序非本次不良总数+当前末道工序非本次工废总数+当前末道工序非本次料废总数
                            decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty;
                            //判断当前工序供应商收料总数>当前工序供应商对应发料数量
                            if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString()))
                            {
                                mes.code = "300";
                                mes.count = 0;
                                mes.message = "当前工序供应商收料总数量:【" + updatereportsumqty + "】不能大于工序供应商发料总数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!";
                                mes.data = null;
                                return mes;
                            }
                        }
                        else //中间工序的报工
                        {
                            //查询当前首道工序供应商非此次收料:总收料数量、总不良数量、总工废数量、总料废数量
                            sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code";
                            dynamicParams.Add("@wo_code", json[0].wo_code);
                            dynamicParams.Add("@id", json[0].id);
                            dynamicParams.Add("@step_code", json[0].step_code);
                            dynamicParams.Add("@wx_code", json[0].wxcode);
                            var dt = DapperHelper.selectdata(sql, dynamicParams);
                            decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前工序非本次收料总数
                            decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前工序非本次报工总不良数
                            decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前工序非本次报工总工废数
                            decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前工序非本次报工总料废数
                                                                                                                       //判断:当前工序报工记录:本次收料数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>发料数量
                            decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty;
                            if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString()))
                            {
                                mes.code = "300";
                                mes.count = 0;
                                mes.message = "当前外协工序对应供应商收料总数量:【" + updatereportsumqty + "】不能大于发料数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!";
                                mes.data = null;
                                return mes;
                            }
                            //判断是否存在下道工序及属性
                            if (next.Rows.Count > 0)
                            {
                                if (next.Rows[0]["flwtype"].ToString() == "Z")
                                {
                                    //查询当前工序下道工序:总报工数量、总不良数量、总报废数量
                                    sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq+1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt0.Rows.Count > 0)
                                    {
                                        //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量
                                        decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                        decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                        decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString());  //下道工序工废总数量
                                        decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString());  //下道工序料废总数量
                                        decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                        //判断(当前非本次收料数+本次收料调整数+非当前供应商同工序收料总数)<下道工序报工总数
                                        if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_updatereportsumqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前外协工序收料数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                                else
                                {
                                    //查询当前工序下道工序:总发料数量
                                    sql = @"select isnull(sum(fqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='F'  and step_seq=@step_seq+1";
                                    dynamicParams.Add("@wo_code", json[0].wo_code);
                                    dynamicParams.Add("@step_seq", json[0].step_seq);
                                    var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                    if (dt0.Rows.Count > 0)
                                    {
                                        //判断当前工序:发料总数数量
                                        decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序发料总数量
                                                                                                                     //判断(当前非本次收料数+本次报工调整收料数+非当前供应商同工序收料总数)<下道工序发料总数
                                        if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_reportqty)
                                        {
                                            mes.code = "300";
                                            mes.count = 0;
                                            mes.message = "当前外协工序收料总数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!";
                                            mes.data = null;
                                            return mes;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else //不按序
                {
                    //控制逻辑:当前工序报工调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废)   ==不能小于下道报工总数
                    list.Clear();
                    //判断当前工序是自制工序还是外协工序
                    if (json[0].flw_type.ToString() == "Z")
                    {
                       //查询当前报工工序非此次报工:总报工数量、总不良数量、总工废数量、总料废数量
                        sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty   
                                from TK_Wrk_Record where wo_code=@wo_code and style='B' and id<>@id and step_code=@step_code";
                        dynamicParams.Add("@wo_code", json[0].wo_code);
@@ -2738,472 +3325,23 @@
                        {
                            mes.code = "300";
                            mes.count = 0;
                            mes.message = "当前首道工序修改报工总数量:【" + updatereportsumqty + "】不能大于工单任务数量:【" + json[0].task_qty.ToString() + "】!";
                            mes.message = "当前工序修改报工总数量:【" + updatereportsumqty + "】不能大于工单任务数量:【" + json[0].task_qty.ToString() + "】!";
                            mes.data = null;
                            return mes;
                        }
                        //判断是否存在下道工序及属性
                        if (next.Rows.Count > 0)
                        {
                            if (next.Rows[0]["flwtype"].ToString() == "Z")
                            {
                                //查询当前工序下道工序:总报工数量、总不良数量、总报废数量
                                sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq+1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt0.Rows.Count > 0)
                                {
                                    //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量
                                    decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                    decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                    decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString());  //下道工序工废总数量
                                    decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString());  //下道工序料废总数量
                                    decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                    //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序报工总数
                                    if ((notthis_reportqty + this_reportqty) < last_updatereportsumqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前首道工序修改报工总合格数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                            else
                            {
                                //查询当前工序下道工序:总发料数量
                                sql = @"select isnull(sum(fqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='S'  and step_seq=@step_seq+1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt0.Rows.Count > 0)
                                {
                                    //判断当前工序:发料总数数量
                                    decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序发料总数量
                                    //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序发料总数
                                    if ((notthis_reportqty + this_reportqty) < last_reportqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前首道工序修改报工总合格数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                        }
                    }
                    //末道工序的报工
                    else if (json[0].last_choke == "Y")
                    if (json[0].flw_type.ToString() == "W")
                    {
                        //查询当前末道报工工序非此次报工:总报工数量、总不良数量、总工废数量、总料废数量
                        sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                from TK_Wrk_Record where wo_code=@wo_code and style='B' and id<>@id and step_code=@step_code";
                        dynamicParams.Add("@wo_code", json[0].wo_code);
                        dynamicParams.Add("@id", json[0].id);
                        dynamicParams.Add("@step_code", json[0].step_code);
                        var dt = DapperHelper.selectdata(sql, dynamicParams);
                        decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前末道工序非本次报工总数
                        decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前末道工序非本次报工总数
                        decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前末道工序非本次报工工废总数
                        decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前末道工序非本次报工料废总数
                        //获取当前末道工序报工总数量:本次修改报工数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前末道工序非本次报工总数+当前末道工序非本次不良总数+当前末道工序非本次工废总数+当前末道工序非本次料废总数
                        decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty;
                        //判断是否存在上道工序及属性
                        if (pre.Rows.Count > 0)
                        {
                            if (pre.Rows[0]["flwtype"].ToString() == "Z")
                            {
                                //查询当前末道工序上道工序:总报工数量、总不良数量、总报废数量
                                sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq-1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt0.Rows.Count > 0)
                                {
                                    decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //上道工序报工总数量
                                    decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //上道工序不良总数量
                                    decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString());  //上道工序工废总数量
                                    decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString());  //上道工序料废总数量
                                    decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                    //判断:当前末道工序报工记录:当前末道工序报工总数量>上道工序报工合格总数
                                    if (updatereportsumqty > last_reportqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前末道工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序报工总合格数量:【" + last_reportqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                            else
                            {
                                //查询当前工序上道工序:总收料数量
                                sql = @"select isnull(sum(sqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='S'  and step_seq=@step_seq-1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt0.Rows.Count > 0)
                                {
                                    //判断当前工序:收料总数数量
                                    decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序发料总数量
                                    //判断:当前末道工序报工记录:当前末道工序报工总数量>上道工序收料合格总数
                                    if (updatereportsumqty > last_reportqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前末道工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序收料总合格数量:【" + last_reportqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                        }
                    }
                    else //中间工序的报工
                    {
                        //查询当前中间报工工序非此次报工:总报工数量、总不良数量、总报废数量
                        sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B' and id<>@id and step_code=@step_code";
                        dynamicParams.Add("@wo_code", json[0].wo_code);
                        dynamicParams.Add("@id", json[0].id);
                        dynamicParams.Add("@step_code", json[0].step_code);
                        var dt = DapperHelper.selectdata(sql, dynamicParams);
                        decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前工序非本次报工总数
                        decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前工序非本次报工总数
                        decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前工序非本次报工工费总数
                        decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前工序非本次报工料废总数
                        //获取当前中间工序报工总数量:本次修改报工数量+本次修改不良数量+本次修改工废数量+本次修改料废总数+当前工序非本次报工总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数
                        decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty;
                        //判断是否存在上道工序及属性
                        if (pre.Rows.Count > 0)
                        {
                            if (pre.Rows[0]["flwtype"].ToString() == "Z")
                            {
                                //查询当前工序上道工序:总报工数量、总不良数量、总工废数量、总料废数量
                                sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq-1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt0.Rows.Count > 0)
                                {
                                    decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //上道工序报工总合格数量
                                    decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //上道工序不良总数量
                                    decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString());  //上道工序工废总数量
                                    decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString());//上道工序料废总数量
                                    decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                    //判断:当前工序报工记录:当前工序报工总数>上道工序报工总合格数
                                    if (updatereportsumqty > last_reportqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序报工总合格数量:【" + last_reportqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                            else
                            {
                                //查询当前工序上道工序:总收料数量
                                sql = @"select isnull(sum(sqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='S'  and step_seq=@step_seq-1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt0.Rows.Count > 0)
                                {
                                    //判断当前工序:收料总数数量
                                    decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //上道工序收料总合格数量
                                    //判断:当前末道工序报工记录:当前工序报工总数量>上道工序收料总合格数量
                                    if (updatereportsumqty > last_reportqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序收料总合格数量:【" + last_reportqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                        }
                        //判断是否存在下道工序属性
                        if (next.Rows.Count > 0)
                        {
                            if (next.Rows[0]["flwtype"].ToString() == "Z")
                            {
                                //查询当前工序下道工序:总报工数量、总不良数量、总报废数量
                                sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq+1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt1 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt1.Rows.Count > 0)
                                {
                                    decimal last_reportqty = decimal.Parse(dt1.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                    decimal last_ngqty = decimal.Parse(dt1.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                    decimal last_laborbad_qty = decimal.Parse(dt1.Rows[0]["laborbad_qty"].ToString());  //下道工序工废总数量
                                    decimal last_materielbad_qty = decimal.Parse(dt1.Rows[0]["materielbad_qty"].ToString());  //下道工序料废总数量
                                    decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                    //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序报工总数
                                    if ((notthis_reportqty + this_reportqty) < last_updatereportsumqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前工序修改报工总合格数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道工序报工总数量:【" + last_updatereportsumqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                            else
                            {
                                //查询当前工序下道工序:总发料数量
                                sql = @"select isnull(sum(fqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='F'  and step_seq=@step_seq+1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt0.Rows.Count > 0)
                                {
                                    //判断当前工序:发料总数数量
                                    decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序发料总合格数量
                                    //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序发料总数
                                    if ((notthis_reportqty + this_reportqty) < last_reportqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前工序修改报工总数量:【" + (notthis_reportqty + this_reportqty) + "】不能大于下道工序发料总数量:【" + last_reportqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                        }
                    }
                    ///////////////////////////////修改报工//////////////////////////////
                    //回写对应的报工记录子表合格数量、不良数量、报废数量
                    sql = @"update TK_Wrk_RecordSub set report_qty=report_qty+@repair_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                            updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where  m_id=@m_id and id=@id and style='B'";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            m_id = int.Parse(json[0].id),
                            id = int.Parse(json[0].sbid),
                            repair_qty = decimal.Parse(json[0].report_dvalue),
                            ng_qty = this_ng_dvalue,
                            laborbad_qty = this_laborbad_dvalue,
                            materielbad_qty = this_materielbad_dvalue,
                            //bad_money = decimal.Parse(json[i].badmoney_dvalue),
                            updatereportuser = us.usercode,
                            updatereportdate = date
                        }
                    });
                    //回写对应的报工记录主表合格数量、不良数量、报废数量
                    sql = @"update TK_Wrk_Record set start_qty=start_qty+@good_qty, good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                            updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where wo_code=@wo_code and step_code=@step_code and id=@id and style='B'";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            good_qty = decimal.Parse(json[0].report_dvalue),
                            ng_qty = this_ng_dvalue,
                            laborbad_qty = this_laborbad_dvalue,
                            materielbad_qty = this_materielbad_dvalue,
                            wo_code = json[0].wo_code,
                            step_code = json[0].step_code,
                            id = int.Parse(json[0].id),
                            updatereportuser = us.usercode,
                            updatereportdate = date
                        }
                    });
                    //回写工单工序表
                    sql = @"update TK_Wrk_Step set good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
                            where wo_code=@wo_code and step_code=@step_code";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            good_qty = decimal.Parse(json[0].report_dvalue),
                            ng_qty = this_ng_dvalue,
                            laborbad_qty = this_laborbad_dvalue,
                            materielbad_qty = this_materielbad_dvalue,
                            wo_code = json[0].wo_code,
                            step_code = json[0].step_code
                        }
                    });
                    for (int i = 0; i < json[0].children.Count; i++)
                    {
                        //回写不良
                        sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty+@ng_qty,defect_pendqty=defect_pendqty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                                updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                                where wo_code=@wo_code and step_code=@step_code and id=@ng_id and record_id=@record_id and style='B'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                ng_qty = decimal.Parse(json[0].children[i].ng_dvalue),
                                laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue),
                                materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue),
                                wo_code = json[0].wo_code,
                                step_code = json[0].step_code,
                                ng_id = int.Parse(json[0].children[i].ng_id),
                                record_id = json[0].id,
                                updatereportuser = us.usercode,
                                updatereportdate = date
                            }
                        });
                        //回写不良处理
                        sql = @"update CSR_WorkRecord_DefectHandle set laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
                                where wo_code=@wo_code and step_code=@step_code and defect_id=@defect_id and style='B'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue),
                                materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue),
                                wo_code = json[0].wo_code,
                                step_code = json[0].step_code,
                                defect_id = int.Parse(json[0].children[i].ng_id),
                                updatereportuser = us.usercode,
                                updatereportdate = date
                            }
                        });
                    }
                }
                if (json[0].flw_type.ToString() == "W")//外协工序
                {
                    //查询当前首道工序非此次供应商收料:总收料数量
                    sql = @"select isnull(sum(sqty),0) as sqty
                                from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code<>@wx_code";
                    dynamicParams.Add("@wo_code", json[0].wo_code);
                    dynamicParams.Add("@id", json[0].id);
                    dynamicParams.Add("@step_code", json[0].step_code);
                    dynamicParams.Add("@wx_code", json[0].wxcode);
                    var dt_c = DapperHelper.selectdata(sql, dynamicParams);
                    //获取此次报工调整提交的数据(收料数量、不良数量、工废数量、料废数量)
                    decimal this_reportqty = decimal.Parse(json[0].report_qty.ToString()); //收料数量
                    decimal this_ngqty = json[0].children.Sum(item => decimal.Parse(item.ng_qty));//不良数量汇总
                    decimal this_laborbadqty = json[0].children.Sum(item => decimal.Parse(item.laborbad_qty));//工废数量汇总
                    decimal this_materielbadqty = json[0].children.Sum(item => decimal.Parse(item.materielbad_qty));//料废数量汇总
                    decimal this_ng_dvalue = json[0].children.Sum(item => decimal.Parse(item.ng_dvalue));//不良数量差值汇总
                    decimal this_laborbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.laborbad_dvalue));//工废数量差值汇总
                    decimal this_materielbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.materielbad_dvalue));//料废数量差值汇总
                    //获取当前工序、供应商对应的发料数量
                    sql = @"select isnull(sum(fqty),0) as fqty
                        //获取当前工序、供应商对应的总发料数量
                        sql = @"select isnull(sum(fqty),0) as fqty
                                from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and id<>@id and step_code=@step_code and wx_code=@wx_code";
                    dynamicParams.Add("@wo_code", json[0].wo_code);
                    dynamicParams.Add("@id", json[0].id);
                    dynamicParams.Add("@step_code", json[0].step_code);
                    dynamicParams.Add("@wx_code", json[0].wxcode);
                    var dt_0 = DapperHelper.selectdata(sql, dynamicParams);
                    //首道工序的收料
                    if (json[0].first_choke == "Y")
                    {
                        //查询当前首道工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量
                        sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code";
                        dynamicParams.Add("@wo_code", json[0].wo_code);
                        dynamicParams.Add("@id", json[0].id);
                        dynamicParams.Add("@step_code", json[0].step_code);
                        dynamicParams.Add("@wx_code", json[0].wxcode);
                        var dt = DapperHelper.selectdata(sql, dynamicParams);
                        decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前工序非本次收料总数
                        decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前工序非本次报工总不良数
                        decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前工序非本次报工总工废数
                        decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前工序非本次报工总料废数
                        //判断:当前工序报工记录:本次收料数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>发料数量
                        decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty;
                        if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString()))
                        {
                            mes.code = "300";
                            mes.count = 0;
                            mes.message = "当前首道工序对应供应商收料总数量:【" + updatereportsumqty + "】不能大于发料数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!";
                            mes.data = null;
                            return mes;
                        }
                        //判断是否存在下道工序及属性
                        if (next.Rows.Count > 0)
                        {
                            if (next.Rows[0]["flwtype"].ToString() == "Z")
                            {
                                //查询当前工序下道工序:总报工数量、总不良数量、总报废数量
                                sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq+1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt0.Rows.Count > 0)
                                {
                                    //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量
                                    decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                    decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                    decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString());  //下道工序工废总数量
                                    decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString());  //下道工序料废总数量
                                    decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                    //判断(当前非本次收料数+本次收料调整数+非当前供应商同工序收料总数)<下道工序报工总数
                                    if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_updatereportsumqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前首道工序收料数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                            else
                            {
                                //查询当前工序下道工序:总发料数量
                                sql = @"select isnull(sum(fqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='F'  and step_seq=@step_seq+1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt0.Rows.Count > 0)
                                {
                                    //判断当前工序:发料总数数量
                                    decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序发料总数量
                                    //判断(当前非本次收料数+本次报工调整收料数)<下道工序发料总数
                                    if ((notthis_reportqty + this_reportqty) < last_reportqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前首道工序收料总数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                        }
                        var dt_0 = DapperHelper.selectdata(sql, dynamicParams);
                    }
                    //末道工序的报工
                    else if (json[0].last_choke == "Y")
                    {
                        //查询当前末道报工工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量
                        //查询当前工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量
                        sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty   
                                from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code  and wx_code=@wx_code";
                        dynamicParams.Add("@wo_code", json[0].wo_code);
@@ -3214,7 +3352,7 @@
                        decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前末道工序非本次报工总数
                        decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前末道工序非本次报工工废总数
                        decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前末道工序非本次报工料废总数
                        //获取当前末道工序收料总数量:本次修改收料数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前末道工序非本次收料总数+当前末道工序非本次不良总数+当前末道工序非本次工废总数+当前末道工序非本次料废总数
                       //获取当前末道工序收料总数量:本次修改收料数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数
                        decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty;
                        //判断当前工序供应商收料总数>当前工序供应商对应发料数量
                        if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString()))
@@ -3225,192 +3363,220 @@
                            mes.data = null;
                            return mes;
                        }
                    }
                    else //中间工序的报工
                    {
                        //查询当前首道工序供应商非此次收料:总收料数量、总不良数量、总工废数量、总料废数量
                        sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code";
                        dynamicParams.Add("@wo_code", json[0].wo_code);
                        dynamicParams.Add("@id", json[0].id);
                        dynamicParams.Add("@step_code", json[0].step_code);
                        dynamicParams.Add("@wx_code", json[0].wxcode);
                        var dt = DapperHelper.selectdata(sql, dynamicParams);
                        decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前工序非本次收料总数
                        decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前工序非本次报工总不良数
                        decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前工序非本次报工总工废数
                        decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前工序非本次报工总料废数
                        //判断:当前工序报工记录:本次收料数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>发料数量
                        decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty;
                        if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString()))
                        {
                            mes.code = "300";
                            mes.count = 0;
                            mes.message = "当前首道工序对应供应商收料总数量:【" + updatereportsumqty + "】不能大于发料数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!";
                            mes.data = null;
                            return mes;
                        }
                        //判断是否存在下道工序及属性
                        if (next.Rows.Count > 0)
                        {
                            if (next.Rows[0]["flwtype"].ToString() == "Z")
                            {
                                //查询当前工序下道工序:总报工数量、总不良数量、总报废数量
                                sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq+1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt0.Rows.Count > 0)
                                {
                                    //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量
                                    decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                    decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                    decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString());  //下道工序工废总数量
                                    decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString());  //下道工序料废总数量
                                    decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty;
                                    //判断(当前非本次收料数+本次收料调整数+非当前供应商同工序收料总数)<下道工序报工总数
                                    if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_updatereportsumqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前首道工序收料数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                            else
                            {
                                //查询当前工序下道工序:总发料数量
                                sql = @"select isnull(sum(fqty),0) as good_qty
                                    from TK_Wrk_OutRecord where wo_code=@wo_code and style='F'  and step_seq=@step_seq+1";
                                dynamicParams.Add("@wo_code", json[0].wo_code);
                                dynamicParams.Add("@step_seq", json[0].step_seq);
                                var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                                if (dt0.Rows.Count > 0)
                                {
                                    //判断当前工序:发料总数数量
                                    decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序发料总数量
                                    //判断(当前非本次收料数+本次报工调整收料数+非当前供应商同工序收料总数)<下道工序发料总数
                                    if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_reportqty)
                                    {
                                        mes.code = "300";
                                        mes.count = 0;
                                        mes.message = "当前首道工序收料总数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!";
                                        mes.data = null;
                                        return mes;
                                    }
                                }
                            }
                        }
                    }
                    ///////////////////////////////修改报工//////////////////////////////
                    //回写对应的外协记录子表收料数量、不良数量、报废数量
                    sql = @"update TK_Wrk_OutRecordSub set sqty=sqty+@repair_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                            updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where  m_id=@m_id and id=@id and style='S' and wx_code=@wx_code";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            m_id = int.Parse(json[0].id),
                            id = int.Parse(json[0].sbid),
                            repair_qty = decimal.Parse(json[0].report_dvalue),
                            ng_qty = this_ng_dvalue,
                            laborbad_qty = this_laborbad_dvalue,
                            materielbad_qty = this_materielbad_dvalue,
                            wx_code = json[0].wxcode,
                            //bad_money = decimal.Parse(json[i].badmoney_dvalue),
                            updatereportuser = us.usercode,
                            updatereportdate = date
                        }
                    });
                    //回写对应的收料记录主表收料数量、不良数量、报废数量
                    sql = @"update TK_Wrk_OutRecord set sqty=sqty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                            updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where wo_code=@wo_code and step_code=@step_code and id=@id and style='S' and wx_code=@wx_code";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            good_qty = decimal.Parse(json[0].report_dvalue),
                            ng_qty = this_ng_dvalue,
                            laborbad_qty = this_laborbad_dvalue,
                            materielbad_qty = this_materielbad_dvalue,
                            wx_code = json[0].wxcode,
                            wo_code = json[0].wo_code,
                            step_code = json[0].step_code,
                            id = int.Parse(json[0].id),
                            updatereportuser = us.usercode,
                            updatereportdate = date
                        }
                    });
                    //回写工单工序表
                    sql = @"update TK_Wrk_Step set good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
                            where wo_code=@wo_code and step_code=@step_code";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            good_qty = decimal.Parse(json[0].report_dvalue),
                            ng_qty = this_ng_dvalue,
                            laborbad_qty = this_laborbad_dvalue,
                            materielbad_qty = this_materielbad_dvalue,
                            wo_code = json[0].wo_code,
                            step_code = json[0].step_code
                        }
                    });
                    for (int i = 0; i < json[0].children.Count; i++)
                    {
                        //回写不良
                        sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty+@ng_qty,defect_pendqty=defect_pendqty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                                updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                                where wo_code=@wo_code and step_code=@step_code and id=@ng_id and record_id=@record_id and style='S'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                ng_qty = decimal.Parse(json[0].children[i].ng_dvalue),
                                laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue),
                                materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue),
                                wo_code = json[0].wo_code,
                                step_code = json[0].step_code,
                                ng_id = int.Parse(json[0].children[i].ng_id),
                                record_id = json[0].id,
                                updatereportuser = us.usercode,
                                updatereportdate = date
                            }
                        });
                        //回写不良处理
                        sql = @"update CSR_WorkRecord_DefectHandle set laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
                                where wo_code=@wo_code and step_code=@step_code and defect_id=@defect_id and style='S'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue),
                                materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue),
                                wo_code = json[0].wo_code,
                                step_code = json[0].step_code,
                                defect_id = int.Parse(json[0].children[i].ng_id),
                                updatereportuser = us.usercode,
                                updatereportdate = date
                            }
                        });
                    }
                }
                switch (json[0].flw_type.ToString())
                {
                    case "Z":
                        ///////////////////////////////修改报工//////////////////////////////
                        //回写对应的报工记录子表合格数量、不良数量、报废数量
                        sql = @"update TK_Wrk_RecordSub set report_qty=report_qty+@repair_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                            updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where  m_id=@m_id and id=@id and style='B'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                m_id = int.Parse(json[0].id),
                                id = int.Parse(json[0].sbid),
                                repair_qty = decimal.Parse(json[0].report_dvalue),
                                ng_qty = this_ng_dvalue,
                                laborbad_qty = this_laborbad_dvalue,
                                materielbad_qty = this_materielbad_dvalue,
                                //bad_money = decimal.Parse(json[i].badmoney_dvalue),
                                updatereportuser = us.usercode,
                                updatereportdate = date
                            }
                        });
                        //回写对应的报工记录主表合格数量、不良数量、报废数量
                        sql = @"update TK_Wrk_Record set step_price=@step_price,start_qty=start_qty+@good_qty, good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                            updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where wo_code=@wo_code and step_code=@step_code and id=@id and style='B'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                step_price=decimal.Parse(json[0].unprice),
                                good_qty = decimal.Parse(json[0].report_dvalue),
                                ng_qty = this_ng_dvalue,
                                laborbad_qty = this_laborbad_dvalue,
                                materielbad_qty = this_materielbad_dvalue,
                                wo_code = json[0].wo_code,
                                step_code = json[0].step_code,
                                id = int.Parse(json[0].id),
                                updatereportuser = us.usercode,
                                updatereportdate = date
                            }
                        });
                        //回写工单工序表
                        sql = @"update TK_Wrk_Step set good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
                            where wo_code=@wo_code and step_code=@step_code";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                good_qty = decimal.Parse(json[0].report_dvalue),
                                ng_qty = this_ng_dvalue,
                                laborbad_qty = this_laborbad_dvalue,
                                materielbad_qty = this_materielbad_dvalue,
                                wo_code = json[0].wo_code,
                                step_code = json[0].step_code
                            }
                        });
                        for (int i = 0; i < json[0].children.Count; i++)
                        {
                            //回写不良
                            sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty+@ng_qty,defect_pendqty=defect_pendqty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                                updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                                where wo_code=@wo_code and step_code=@step_code and id=@ng_id and record_id=@record_id and style='B'";
                            list.Add(new
                            {
                                str = sql,
                                parm = new
                                {
                                    ng_qty = decimal.Parse(json[0].children[i].ng_dvalue),
                                    laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue),
                                    materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue),
                                    wo_code = json[0].wo_code,
                                    step_code = json[0].step_code,
                                    ng_id = int.Parse(json[0].children[i].ng_id),
                                    record_id = json[0].id,
                                    updatereportuser = us.usercode,
                                    updatereportdate = date
                                }
                            });
                            //回写不良处理
                            sql = @"update CSR_WorkRecord_DefectHandle set laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
                                where wo_code=@wo_code and step_code=@step_code and defect_id=@defect_id and style='B'";
                            list.Add(new
                            {
                                str = sql,
                                parm = new
                                {
                                    laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue),
                                    materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue),
                                    wo_code = json[0].wo_code,
                                    step_code = json[0].step_code,
                                    defect_id = int.Parse(json[0].children[i].ng_id),
                                    updatereportuser = us.usercode,
                                    updatereportdate = date
                                }
                            });
                        }
                        break;
                    case "W":
                        ///////////////////////////////修改报工//////////////////////////////
                        //回写对应的外协记录子表收料数量、不良数量、报废数量
                        sql = @"update TK_Wrk_OutRecordSub set sqty=sqty+@repair_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                            updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where  m_id=@m_id and id=@id and style='S' and wx_code=@wx_code";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                m_id = int.Parse(json[0].id),
                                id = int.Parse(json[0].sbid),
                                repair_qty = decimal.Parse(json[0].report_dvalue),
                                ng_qty = this_ng_dvalue,
                                laborbad_qty = this_laborbad_dvalue,
                                materielbad_qty = this_materielbad_dvalue,
                                wx_code = json[0].wxcode,
                                //bad_money = decimal.Parse(json[i].badmoney_dvalue),
                                updatereportuser = us.usercode,
                                updatereportdate = date
                            }
                        });
                        //回写对应的收料记录主表收料数量、不良数量、报废数量
                        sql = @"update TK_Wrk_OutRecord set step_price=@step_price,sqty=sqty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                            updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where wo_code=@wo_code and step_code=@step_code and id=@id and style='S' and wx_code=@wx_code";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                step_price=decimal.Parse(json[0].unprice),
                                good_qty = decimal.Parse(json[0].report_dvalue),
                                ng_qty = this_ng_dvalue,
                                laborbad_qty = this_laborbad_dvalue,
                                materielbad_qty = this_materielbad_dvalue,
                                wx_code = json[0].wxcode,
                                wo_code = json[0].wo_code,
                                step_code = json[0].step_code,
                                id = int.Parse(json[0].id),
                                updatereportuser = us.usercode,
                                updatereportdate = date
                            }
                        });
                        //回写工单工序表
                        sql = @"update TK_Wrk_Step set good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
                            where wo_code=@wo_code and step_code=@step_code";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                good_qty = decimal.Parse(json[0].report_dvalue),
                                ng_qty = this_ng_dvalue,
                                laborbad_qty = this_laborbad_dvalue,
                                materielbad_qty = this_materielbad_dvalue,
                                wo_code = json[0].wo_code,
                                step_code = json[0].step_code
                            }
                        });
                        for (int i = 0; i < json[0].children.Count; i++)
                        {
                            //回写不良
                            sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty+@ng_qty,defect_pendqty=defect_pendqty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                                updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                                where wo_code=@wo_code and step_code=@step_code and id=@ng_id and record_id=@record_id and style='S'";
                            list.Add(new
                            {
                                str = sql,
                                parm = new
                                {
                                    ng_qty = decimal.Parse(json[0].children[i].ng_dvalue),
                                    laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue),
                                    materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue),
                                    wo_code = json[0].wo_code,
                                    step_code = json[0].step_code,
                                    ng_id = int.Parse(json[0].children[i].ng_id),
                                    record_id = json[0].id,
                                    updatereportuser = us.usercode,
                                    updatereportdate = date
                                }
                            });
                            //回写不良处理
                            sql = @"update CSR_WorkRecord_DefectHandle set laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
                                where wo_code=@wo_code and step_code=@step_code and defect_id=@defect_id and style='S'";
                            list.Add(new
                            {
                                str = sql,
                                parm = new
                                {
                                    laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue),
                                    materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue),
                                    wo_code = json[0].wo_code,
                                    step_code = json[0].step_code,
                                    defect_id = int.Parse(json[0].children[i].ng_id),
                                    updatereportuser = us.usercode,
                                    updatereportdate = date
                                }
                            });
                        }
                        break;
                    default:
                        break;
                }
                bool aa = DapperHelper.DoTransaction(list);
                if (aa)
                {
@@ -3615,5 +3781,67 @@
            return mes;
        }
        #endregion
        #region[生产执行,报工弃审数据提交]
        public static ToMessage MesOrderStepReportNotVerifySeave(User us, string id, string steptype)
        {
            var sql = "";
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                if (steptype == "Z")//自制工序
                {
                    //回写报工记录主表审核状态、审核人、审核时间
                    sql = @"update TK_Wrk_Record set verify='N',verifyuser=@verifyuser,verifydate=@verifydate  where id=@id";
                    list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } });
                    //回写报工记录子表审核状态、审核人、审核时间
                    sql = @"update TK_Wrk_RecordSub set verify='N',verifyuser=@verifyuser,verifydate=@verifydate  where m_id=@id";
                    list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } });
                }
                if (steptype == "W")//外协工序
                {
                    //回写外协记录主表审核状态、审核人、审核时间
                    sql = @"update TK_Wrk_OutRecord set verify='N',verifyuser=@verifyuser,verifydate=@verifydate  where id=@id";
                    list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } });
                    //回写外协记录子表审核状态、审核人、审核时间
                    sql = @"update TK_Wrk_OutRecordSub set verify='N',verifyuser=@verifyuser,verifydate=@verifydate  where m_id=@id";
                    list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } });
                }
                bool aa = DapperHelper.DoTransaction(list);
                if (aa)
                {
                    if (steptype == "Z")
                    {
                        //写入操作记录表
                        LogHelper.DbOperateLog(us.usercode, "报工弃审", "自制报工记录id:" + string.Join(",", id), us.usertype);
                    }
                    if (steptype == "W")
                    {
                        LogHelper.DbOperateLog(us.usercode, "报工弃审", "外协收料记录id:" + string.Join(",", id), us.usertype);
                    }
                    mes.code = "200";
                    mes.count = 0;
                    mes.message = "审核成功!";
                    mes.data = null;
                }
                else
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.message = "审核失败!";
                    mes.data = null;
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
    }
}