VueWebCoreApi/DLL/DAL/WorkOrderDAL.cs
@@ -42,8 +42,9 @@
                }
                if (wkshopcode != "" && wkshopcode != null)
                {
                    search += "and A.wkshp_code=@wkshopcode ";
                    dynamicParams.Add("@wkshopcode", wkshopcode);
                    string[] wkshoplist = Array.ConvertAll<string, string>(wkshopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[]
                    search += "and A.wkshp_code in @wkshoplist ";
                    dynamicParams.Add("@wkshoplist", wkshoplist);
                }
                if (erpordercode != "" && erpordercode != null)
                {
@@ -132,7 +133,7 @@
        #endregion
        #region[ERP订单下达]
        public static ToMessage MarkSaveErpOrder(string erporderid, string sbid, string erpordercode, string saleordercode, string partcode,string deptcode, string wkshopcode, string warehousecode, string erpqty, string markqty, string ordernum, string relse_qty, string idTopInventory, string TopInventoryCode, string TopInventoryName, 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 deptcode, string wkshopcode, string warehousecode, string erpqty, string markqty, string ordernum, string relse_qty, string idTopInventory, string TopInventoryCode, string TopInventoryName, string saleOrderDeliveryDate, string paystartdate, string payenddate, string clerkuser, User us)
        {
            var sql = "";
            string orderstatus = "", isstep = ""; //工单状态、是否绑定工艺
@@ -229,7 +230,7 @@
                                wo_code = wo,
                                wotype = "PO",
                                status = orderstatus,  //"NEW"
                                dept_code= deptcode,
                                dept_code = deptcode,
                                wkshp_code = wkshopcode,
                                plan_qty = cdqty + (decimal.Parse(markqty) - sumqty),  //末单下单数量=切分数量+(下单数量-累计切分下单数量)
                                stck_code = warehousecode,
@@ -297,7 +298,7 @@
                                wo_code = wo,
                                wotype = "PO",
                                status = orderstatus, //"NEW"
                                dept_code=deptcode,
                                dept_code = deptcode,
                                wkshp_code = wkshopcode,
                                plan_qty = cdqty,
                                stck_code = warehousecode,
@@ -338,8 +339,8 @@
                                        step_code = data0.Rows[j]["step_code"].ToString(),
                                        route_code = data0.Rows[j]["default_route"].ToString(),
                                        stepprice = decimal.Parse(data0.Rows[j]["unprice"].ToString() == "" || data0.Rows[j]["unprice"].ToString() == null ? "0" : data0.Rows[j]["unprice"].ToString()),
                                        plan_quantity = cdqty + (decimal.Parse(markqty) - sumqty),  //末单下单数量=切分数量+(下单数量-累计切分下单数量),
                                        plan_qty = cdqty + (decimal.Parse(markqty) - sumqty),  //末单下单数量=切分数量+(下单数量-累计切分下单数量),
                                        plan_quantity = cdqty,
                                        plan_qty = cdqty,
                                        ratio = 0,
                                        status = orderstatus,
                                        isbott = data0.Rows[j]["first_choke"].ToString(),
@@ -499,13 +500,13 @@
                                wo_code = wo,
                                wotype = "PO",
                                status = orderstatus, //"NEW"
                                dept_code=model.deptcode,
                                dept_code = model.deptcode,
                                wkshp_code = model.wkshopcode,
                                plan_qty = decimal.Parse(model.erpqty),  //订单数量
                                stck_code = model.warehousecode,
                                sbid = model.sbid,
                                materiel_code = model.partcode,
                                route_code=data0.Rows.Count<=0?"": data0.Rows[0]["default_route"].ToString(),
                                route_code = data0.Rows.Count <= 0 ? "" : data0.Rows[0]["default_route"].ToString(),
                                sourceid = model.erporderid,
                                m_po = model.erpordercode,
                                username = us.usercode,
@@ -517,7 +518,7 @@
                                data_sources = "ERP",
                                isstep = isstep,  //是否关联工序 "N"
                                clerkuser = model.clerkuser, //销售订单业务员
                                idTopInventory =model.idTopInventory,
                                idTopInventory = model.idTopInventory,
                                TopInventoryCode = model.TopInventoryCode,
                                TopInventoryName = model.TopInventoryName
                            }
@@ -539,7 +540,7 @@
                                        seq = data0.Rows[i]["seq"].ToString(),
                                        step_code = data0.Rows[i]["step_code"].ToString(),
                                        route_code = data0.Rows[i]["default_route"].ToString(),
                                        stepprice = decimal.Parse(data0.Rows[i]["unprice"].ToString()==""|| data0.Rows[i]["unprice"].ToString() ==null? "0":data0.Rows[i]["unprice"].ToString()),
                                        stepprice = decimal.Parse(data0.Rows[i]["unprice"].ToString() == "" || data0.Rows[i]["unprice"].ToString() == null ? "0" : data0.Rows[i]["unprice"].ToString()),
                                        plan_quantity = decimal.Parse(model.erpqty),  //订单数量
                                        plan_qty = decimal.Parse(model.erpqty),  //订单数量
                                        ratio = 0,
@@ -609,30 +610,47 @@
            var dynamicParams = new DynamicParameters();
            try
            {
                sql = @"select *  from TK_Wrk_Man where m_po=@erpordercode and status<> 'CLOSED'";
                sql = @"select *  from TK_Wrk_Man where m_po=@erpordercode and sourceid=@sourceid";
                dynamicParams.Add("@erpordercode", erpordercode);
                dynamicParams.Add("@sourceid", erporderid);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                if (data.Rows.Count > 0)
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.message = "当前订单有下达未关闭的MES工单,订单不允许关闭,请先删除或关闭相关工单!";
                    mes.data = null;
                }
                else
                {
                    //关闭订单
                    sql = @"update  TKimp_Ewo set status='CLOSED' where wo=@wo and id=@erporderid";
                    // 使用LINQ和lambda表达式来转换wo_code字段的值为逗号隔开的字符串数组
                    string[] result = data.AsEnumerable().Select(row => "" + row.Field<string>("wo_code") + "").ToArray();
                    //关闭工序任务
                    sql = @"update  TK_Wrk_Step set status='CLOSED',closebeforestatus=status where wo_code in @wocode";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            wo = erpordercode,
                            erporderid = erporderid
                            wocode = result
                        }
                    });
                    //关闭工单
                    sql = @"update  TK_Wrk_Man set status='CLOSED',closebeforestatus=status where m_po=@erpordercode and sourceid=@sourceid";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            erpordercode = erpordercode,
                            sourceid = erporderid
                        }
                    });
                }
                //关闭订单
                sql = @"update  TKimp_Ewo set status='CLOSED',closebeforestatus=status where wo=@wo and id=@erporderid";
                list.Add(new
                {
                    str = sql,
                    parm = new
                    {
                        wo = erpordercode,
                        erporderid = erporderid
                    }
                });
                bool aa = DapperHelper.DoTransaction(list);
                if (aa)
                {
@@ -833,8 +851,9 @@
                }
                if (wkshopcode != "" && wkshopcode != null)
                {
                    search += "and A.wkshp_code=@wkshopcode ";
                    dynamicParams.Add("@wkshopcode", wkshopcode);
                    string[] wkshoplist = Array.ConvertAll<string, string>(wkshopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[]
                    search += "and A.wkshp_code in @wkshoplist ";
                    dynamicParams.Add("@wkshoplist", wkshoplist);
                }
                if (mesordercode != "" && mesordercode != null)
                {
@@ -848,7 +867,7 @@
                }
                if (saleordercode != "" && saleordercode != null)
                {
                    search += "and W.saleOrderCode like '%'+@saleordercode+'%' ";
                    search += "and A.saleOrderCode like '%'+@saleordercode+'%' ";
                    dynamicParams.Add("@saleordercode", saleordercode);
                }
                if (ordertype != "" && ordertype != null)
@@ -910,9 +929,9 @@
                }
                // --------------查询指定数据--------------
                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.route_code,B.default_route,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,
                            B.priuserdefnvc1,B.priuserdefnvc2,B.priuserdefnvc3,B.priuserdefnvc4,B.priuserdefnvc5,B.priuserdefnvc6,A.printcount
                var sql = @"select A.id, A.status,A.wotype,A.wo_code,A.materiel_code as partcode,B.partname,B.partspec,A.idTopInventory,A.TopInventoryCode,A.TopInventoryName,A.route_code,B.default_route,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,A.saleOrderCode,U.username as lm_user,A.lm_date,A.data_sources,A.isstep,A.clerkuser,
                            B.priuserdefnvc1,B.priuserdefnvc2,B.priuserdefnvc3,B.priuserdefnvc4,B.priuserdefnvc5,B.priuserdefnvc6,A.printcount,W.memo,W.bomsubspec
                            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
                            left join TMateriel_Info B on A.materiel_code=B.partcode
@@ -998,9 +1017,9 @@
                }
                // --------------查询指定数据--------------
                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.idTopInventory,A.TopInventoryCode,A.TopInventoryName,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,S.laborbad_qty,S.materielbad_qty,
                            B.priuserdefnvc1,B.priuserdefnvc2,B.priuserdefnvc3,B.priuserdefnvc4,B.priuserdefnvc5,B.priuserdefnvc6
                            B.priuserdefnvc1,B.priuserdefnvc2,B.priuserdefnvc3,B.priuserdefnvc4,B.priuserdefnvc5,B.priuserdefnvc6,W.memo,W.bomsubspec
                            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
                            left join (select wo_code,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty from  TK_Wrk_Step where (laborbad_qty+materielbad_qty)>0 group by wo_code) S on A.wo_code=S.wo_code
@@ -1142,8 +1161,8 @@
                if (operType == "Add")
                {
                    //写入工单表
                    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)";
                    sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,lm_user,lm_date,materiel_code,route_code,sourceid,saleOrderCode,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,@saleOrderCode,@m_po,@saleOrderDeliveryDate,@plan_startdate,@plan_enddate,@orderlev,@isaps,@data_sources,@isstep)";
                    list.Add(new
                    {
                        str = sql,
@@ -1159,6 +1178,7 @@
                            materiel_code = json.partcode,
                            route_code = route_code,
                            sourceid = json.sourceid == "" ? null : json.sourceid, //无源单时赋值NULL
                            saleOrderCode = json.saleordercode,
                            m_po = json.sourcewo,
                            saleOrderDeliveryDate = json.deliverydate,
                            plan_startdate = json.paystartdate,
@@ -1186,7 +1206,7 @@
                                stepprice = json.WorkListSub[i].stepprice,
                                plan_quantity = json.woqty,
                                plan_qty = json.WorkListSub[i].sumqty,
                                ratio=json.WorkListSub[i].ratio,
                                ratio = json.WorkListSub[i].ratio,
                                status = json.wostatus,
                                isbott = json.WorkListSub[i].isbott,
                                isend = json.WorkListSub[i].isend,
@@ -1217,7 +1237,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,route_code=@route_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,saleOrderCode=@saleOrderCode,m_po=@m_po,saleOrderDeliveryDate=@saleOrderDeliveryDate,plan_startdate=@plan_startdate,plan_enddate=@plan_enddate,isstep=@isstep
                            where wo_code=@wo_code";
                    list.Add(new
                    {
@@ -1231,6 +1251,7 @@
                            materiel_code = json.partcode,
                            route_code = route_code,
                            sourceid = json.sourceid == "" ? null : json.sourceid, //无源单时赋值NULL
                            saleOrderCode = json.saleordercode,
                            m_po = json.sourcewo,
                            saleOrderDeliveryDate = json.deliverydate,
                            plan_startdate = json.paystartdate,
@@ -1267,7 +1288,7 @@
                                stepprice = json.WorkListSub[i].stepprice,
                                plan_quantity = json.woqty,
                                plan_qty = json.WorkListSub[i].sumqty,
                                ratio=json.WorkListSub[i].ratio,
                                ratio = json.WorkListSub[i].ratio,
                                status = json.wostatus,
                                isbott = json.WorkListSub[i].isbott,
                                isend = json.WorkListSub[i].isend,
@@ -1361,7 +1382,7 @@
                    if (worksteplist[i].data_sources == "ERP")  //数据来源ERP
                    {
                        //查询当前工单可修改数量=订单总数-已下达工单总数
                        sql = @"select isnull(plan_qty,0) as plan_qty   from TK_Wrk_Man 
                            where sourceid=@sourceid and m_po=@sourcewo and wo_code=@wocode";
@@ -1400,7 +1421,7 @@
                    // 向字典中添加数据
                    dict.Add("canupdate_qty", canupdate_qty);
                    dict.Add("stepdata", data1);
                    dict.Add("stepdata", data1);
                    // 将字典添加到列表中
                    dir.Add(dict);
                    mes.code = "200";
@@ -1440,8 +1461,8 @@
                    {
                        route_code = json[i].routecode;
                        //写入工单表
                        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)";
                        sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,lm_user,lm_date,materiel_code,route_code,sourceid,saleOrderCode,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,@saleOrderCode,@m_po,@saleOrderDeliveryDate,@plan_startdate,@plan_enddate,@orderlev,@isaps,@data_sources,@isstep)";
                        list.Add(new
                        {
                            str = sql,
@@ -1457,6 +1478,7 @@
                                materiel_code = json[i].partcode,
                                route_code = route_code,
                                sourceid = json[i].sourceid == "" ? null : json[i].sourceid, //无源单时赋值NULL
                                saleOrderCode = json[i].saleordercode,
                                m_po = json[i].sourcewo,
                                saleOrderDeliveryDate = json[i].deliverydate,
                                plan_startdate = json[i].paystartdate,
@@ -1484,7 +1506,7 @@
                                    stepprice = json[i].WorkListSub[j].stepprice,
                                    plan_quantity = json[i].woqty,
                                    plan_qty = json[i].WorkListSub[j].sumqty,
                                    ratio=json[i].WorkListSub[j].ratio,
                                    ratio = json[i].WorkListSub[j].ratio,
                                    status = json[i].wostatus,
                                    isbott = json[i].WorkListSub[j].isbott,
                                    isend = json[i].WorkListSub[j].isend,
@@ -1519,7 +1541,7 @@
                        route_code = json[i].routecode;
                        //修改工单表
                        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,route_code=@route_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,saleOrderCode=@saleOrderCode,m_po=@m_po,saleOrderDeliveryDate=@saleOrderDeliveryDate,plan_startdate=@plan_startdate,plan_enddate=@plan_enddate,isstep=@isstep
                            where wo_code=@wo_code";
                        list.Add(new
                        {
@@ -1533,6 +1555,7 @@
                                materiel_code = json[i].partcode,
                                route_code = route_code,
                                sourceid = json[i].sourceid == "" ? null : json[i].sourceid, //无源单时赋值NULL
                                saleOrderCode = json[i].saleordercode,
                                m_po = json[i].sourcewo,
                                saleOrderDeliveryDate = json[i].deliverydate,
                                plan_startdate = json[i].paystartdate,
@@ -1569,7 +1592,7 @@
                                    stepprice = json[i].WorkListSub[j].stepprice,
                                    plan_quantity = json[i].woqty,
                                    plan_qty = json[i].WorkListSub[j].sumqty,
                                    ratio=json[i].WorkListSub[j].ratio,
                                    ratio = json[i].WorkListSub[j].ratio,
                                    status = json[i].wostatus,
                                    isbott = json[i].WorkListSub[j].isbott,
                                    isend = json[i].WorkListSub[j].isend,
@@ -1833,6 +1856,82 @@
        }
        #endregion
        #region[MES工单批量查找历史引用最新工序信息]
        public static ToMessage MesOrderNewStepListContent(List<BatchProcess> list, User us)
        {
            var sql = "";
            List<Dictionary<object, object>> dir = new List<Dictionary<object, object>>();
            var dynamicParams = new DynamicParameters();
            try
            {
                dynamic dynObj = JObject.Parse(us.mesSetting);
                bool route = dynObj.route;
                for (int i = 0; i < list.Count; i++)
                {
                    if (route) //工艺路线版
                    {
                        Dictionary<object, object> dict = new Dictionary<object, object>();
                        //MES工单查找历史引用最新工序信息
                        sql = @"select S.wo_code,S.seq,S.step_code as stepcode,T.stepname as stepname,S.stepprice,S.isbott,S.isend,S.ratio
                        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", list[i].wkshopcode);
                        dynamicParams.Add("@partcode", list[i].partcode);
                        dynamicParams.Add("@routecode", list[i].routecode);
                        var data = DapperHelper.selectdata(sql, dynamicParams);
                        // 向字典中添加数据
                        dict.Add("partcode", list[i].partcode);
                        dict.Add("stepdata", data);
                        // 将字典添加到列表中
                        dir.Add(dict);
                    }
                    else
                    {
                        Dictionary<object, object> dict = new Dictionary<object, object>();
                        //MES工单查找历史引用最新工序信息
                        sql = @"select S.wo_code,S.seq,S.step_code as stepcode,T.stepname as stepname,S.stepprice,S.isbott,S.isend,S.ratio
                        from TK_Wrk_Step S
                        inner join (
                        select top 1 A.wo_code   from TK_Wrk_Man A
                        inner join TK_Wrk_Step S on A.wo_code=S.wo_code
                        where A.materiel_code=@partcode and A.wkshp_code=@wkshopcode
                        order by A.lm_date desc
                        ) 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", list[i].wkshopcode);
                        dynamicParams.Add("@partcode", list[i].partcode);
                        var data = DapperHelper.selectdata(sql, dynamicParams);
                        // 向字典中添加数据
                        dict.Add("partcode", list[i].partcode);
                        dict.Add("stepdata", data);
                        // 将字典添加到列表中
                        dir.Add(dict);
                    }
                }
                mes.code = "200";
                mes.count = dir.Count;
                mes.data = dir;
                mes.message = "查询成功!";
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[MES工单查看工单SOP]
        public static ToMessage MesOrderSopSearch(string wocode, string materielcode)
        {
@@ -1935,8 +2034,8 @@
                    {
                        wocode = wocodelist,
                        status = "ALLO",
                        distributionuser=us.usercode,
                        distributiontime= DateTime.Now.ToString()
                        distributionuser = us.usercode,
                        distributiontime = DateTime.Now.ToString()
                    }
                });
                //更新工序任务表状态
@@ -2177,7 +2276,7 @@
        #region[生产开报工扫码获取工单对应工序任务(自制)]
        public static ToMessage MesOrderStepSearch(string wkshopcode, string wocode, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order)
        public static ToMessage MesOrderStepSearch(string wkshopcode, string wocode, string orderno, string saorderno, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order)
        {
            var sql = "";
            string search = "";
@@ -2210,7 +2309,7 @@
                        search += "and A.wo_code=@ordercode ";
                        dynamicParams.Add("@ordercode", ordercode);
                    }
                    if (ordercode != "" && stepcode != "") //工单号不为空,工序号不为空
                    if (saorderno != "" && saorderno != "") //工单号不为空,工序号不为空
                    {
                        search += "and A.wo_code=@ordercode ";
                        dynamicParams.Add("@ordercode", ordercode);
@@ -2236,6 +2335,16 @@
                        }
                    }
                }
                if (orderno != "" && orderno != null)
                {
                    search += "and B.m_po like '%'+@orderno+'%' ";
                    dynamicParams.Add("@orderno", orderno);
                }
                if (saorderno != "" && saorderno != null)
                {
                    search += "and B.saleOrderCode like '%'+@saorderno+'%' ";
                    dynamicParams.Add("@saorderno", saorderno);
                }
                if (partcode != "" && partcode != null)
                {
                    search += "and M.partcode like '%'+@partcode+'%' ";
@@ -2252,7 +2361,7 @@
                    dynamicParams.Add("@partspec", partspec);
                }
                //根据条件查询工单工序任务(自制工序)
                sql = @"select A.id,A.status,B.wkshp_code,T.torg_name as wkshp_name,A.wo_code,M.partcode,M.partname,M.partspec,A.seq,A.isbott,A.isend,
                sql = @"select A.id,A.status,B.wkshp_code,T.torg_name as wkshp_name,A.wo_code,B.m_po,B.saleOrderCode,M.partcode,M.partname,M.partspec,A.seq,A.isbott,A.isend,
                        S.stepcode,S.stepname,S.descr,A.plan_quantity,A.plan_qty,A.good_qty,A.ng_qty,A.laborbad_qty,A.materielbad_qty,B.lm_date,
                        M.priuserdefnvc1,M.priuserdefnvc2,M.priuserdefnvc3,M.priuserdefnvc4,M.priuserdefnvc5,M.priuserdefnvc6
                        from TK_Wrk_Step A
@@ -2280,7 +2389,7 @@
        #endregion
        #region[生产开报工扫码获取工单对应工序任务(外协)]
        public static ToMessage MesOrderWxStepSearch(string wkshopcode, string wocode, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order)
        public static ToMessage MesOrderWxStepSearch(string wkshopcode, string wocode, string orderno, string saorderno, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order)
        {
            var sql = "";
            string search = "";
@@ -2339,6 +2448,16 @@
                        }
                    }
                }
                if (orderno != "" && orderno != null)
                {
                    search += "and B.m_po like '%'+@orderno+'%' ";
                    dynamicParams.Add("@orderno", orderno);
                }
                if (saorderno != "" && saorderno != null)
                {
                    search += "and B.saleOrderCode like '%'+@saorderno+'%' ";
                    dynamicParams.Add("@saorderno", saorderno);
                }
                if (partcode != "" && partcode != null)
                {
                    search += "and M.partcode like '%'+@partcode+'%' ";
@@ -2355,7 +2474,7 @@
                    dynamicParams.Add("@partspec", partspec);
                }
                //根据条件查询工单工序任务(自制工序)
                sql = @"select A.id,A.status,B.wkshp_code,T.torg_name as wkshp_name,A.wo_code,M.partcode,M.partname,M.partspec,A.seq,A.isbott,A.isend,
                sql = @"select A.id,A.status,B.wkshp_code,T.torg_name as wkshp_name,A.wo_code,B.m_po,B.saleOrderCode,M.partcode,M.partname,M.partspec,A.seq,A.isbott,A.isend,
                        S.stepcode,S.stepname,S.descr,A.plan_quantity,A.plan_qty,A.good_qty,A.ng_qty,
                        (select isnull(sum(fqty),0) as fqty   from TK_Wrk_OutRecord where wo_code=A.wo_code and step_code=A.step_code and style='F') as fqty,
                        A.laborbad_qty,A.materielbad_qty,A.plan_startdate,A.plan_enddate,B.lm_date,
@@ -2386,7 +2505,7 @@
        #endregion
        #region[生产开报工扫码获取工单对应工序任务(不良)]
        public static ToMessage MesOrderNgStepSearch(string wkshopcode, string wocode, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order)
        public static ToMessage MesOrderNgStepSearch(string wkshopcode, string wocode, string orderno, string saorderno, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order)
        {
            var sql = "";
            string search = "";
@@ -2443,6 +2562,16 @@
                        return mes;
                    }
                }
                if (orderno != "" && orderno != null)
                {
                    search += "and B.m_po like '%'+@orderno+'%' ";
                    dynamicParams.Add("@orderno", orderno);
                }
                if (saorderno != "" && saorderno != null)
                {
                    search += "and B.saleOrderCode like '%'+@saorderno+'%' ";
                    dynamicParams.Add("@saorderno", saorderno);
                }
                if (partcode != "" && partcode != null)
                {
                    search += "and M.partcode like '%'+@partcode+'%' ";
@@ -2459,7 +2588,7 @@
                    dynamicParams.Add("@partspec", partspec);
                }
                //根据条件查询工单工序任务(自制工序)
                sql = @"select A.id,B.wkshp_code,T.torg_name as wkshp_name,A.wo_code,M.partcode,M.partname,M.partspec,A.seq,A.isend,
                sql = @"select A.id,B.wkshp_code,T.torg_name as wkshp_name,A.wo_code,B.saleOrderCode,B.m_po,M.partcode,M.partname,M.partspec,A.seq,A.isend,
                        S.stepcode,S.stepname,S.descr,A.plan_quantity,A.plan_qty,A.good_qty,A.ng_qty,A.laborbad_qty,A.materielbad_qty,B.lm_date,
                        M.priuserdefnvc1,M.priuserdefnvc2,M.priuserdefnvc3,M.priuserdefnvc4,M.priuserdefnvc5,M.priuserdefnvc6
                        from TK_Wrk_Step A
@@ -2497,7 +2626,7 @@
            try
            {
                //1.根据工单+工序查找当前工序是否首道工序
                sql = @"select A.wo_code,P.partcode,P.partname,P.partspec, T.stepcode,T.stepname,A.seq,T.flwtype,T.descr,A.status,
                sql = @"select A.wo_code,M.m_po,P.partcode,P.partname,P.partspec, T.stepcode,T.stepname,A.seq,T.flwtype,T.descr,A.status,
                        A.plan_quantity,A.plan_qty,A.good_qty,A.ng_qty,A.laborbad_qty,A.materielbad_qty,A.isbott,A.isend
                        from TK_Wrk_Step A
                        left join  TStep T on A.step_code=T.stepcode
@@ -2510,6 +2639,7 @@
                if (data.Rows.Count > 0)
                {
                    rt.wo_code = data.Rows[0]["wo_code"].ToString(); //工单号
                    rt.orderno = data.Rows[0]["m_po"].ToString(); //订单号
                    rt.partnumber = data.Rows[0]["partcode"].ToString(); //产品编码
                    rt.partname = data.Rows[0]["partname"].ToString(); //产品名称
                    rt.partspec = data.Rows[0]["partspec"].ToString(); //产品规格
@@ -2517,7 +2647,7 @@
                    rt.stepname = data.Rows[0]["stepname"].ToString(); //工序名称
                    rt.stepdesc = data.Rows[0]["descr"].ToString(); //工序描述
                    rt.planqty = decimal.Parse(data.Rows[0]["plan_qty"].ToString()); //任务超产总数量
                    rt.planquantity= decimal.Parse(data.Rows[0]["plan_quantity"].ToString()); //任务数量
                    rt.planquantity = decimal.Parse(data.Rows[0]["plan_quantity"].ToString()); //任务数量
                    rt.noreportqty = decimal.Parse(data.Rows[0]["good_qty"].ToString()); //报工数量
                    rt.noputqty = decimal.Parse(data.Rows[0]["ng_qty"].ToString()); //不良数量
                    string isend = data.Rows[0]["isend"].ToString();//末道工序
@@ -2611,7 +2741,7 @@
                        else //不按序收发料
                        {
                            mes = ScanStartReport.NoWXEncodingSeach(SelectType, wocode, stepcode);
                        }
                        }
                        break;
                    default:
                        break;
@@ -2629,7 +2759,7 @@
        #endregion
        #region[生产开报工,报工提交]
        public static ToMessage SavaMesOrderStepReport(string mesordercode, string partcode, string stepseq, string stepcode, string stepprice, string eqpcode, string inbarcode, string reckway, string usergroupcode, string reportuser,string payrate, string taskqty, string startqty, string reportqty, List<ReportDefectList> defectobjs, string remarks, User us)
        public static ToMessage SavaMesOrderStepReport(string mesordercode, string partcode, string stepseq, string stepcode, string stepprice, string eqpcode, string inbarcode, string reckway, string usergroupcode, string reportuser, string payrate, string taskqty, string startqty, string reportqty, List<ReportDefectList> defectobjs, string remarks, User us)
        {
            var sql = "";
            decimal ngqty = 0;
@@ -2735,7 +2865,7 @@
                        {
                            m_id = int.Parse(dt.Rows[0]["ID"].ToString()),
                            eqp_code = eqpcode,
                            payrate= payrate,
                            payrate = payrate,
                            report_person = reportuser,
                            report_date = date,
                            report_qty = reportqty,
@@ -2753,9 +2883,9 @@
                        //写入缺陷记录表
                        for (int i = 0; i < groupedItems.Count; i++)
                        {
                            sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,remarks,style,lm_user,lm_date)
                                values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@remarks,@style,@lm_user,@lm_date)";
                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code, remarks = remarks, style = "B", lm_user = us.usercode, lm_date = date } });
                            sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,report_person,usergroup_code,remarks,style,lm_user,lm_date)
                                values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@report_person,@usergroup_code,@remarks,@style,@lm_user,@lm_date)";
                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code,report_person=reportuser,usergroup_code= usergroupcode, remarks = remarks, style = "B", lm_user = us.usercode, lm_date = date } });
                        }
                    }
@@ -2780,7 +2910,7 @@
                        {
                            m_id = int.Parse(dt.Rows[0]["ID"].ToString()),
                            eqp_code = eqpcode,
                            payrate= payrate,
                            payrate = payrate,
                            report_person = reportuser,
                            report_date = date,
                            report_qty = reportqty,
@@ -2798,9 +2928,9 @@
                        //写入缺陷记录表
                        for (int i = 0; i < groupedItems.Count; i++)
                        {
                            sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,remarks,style,lm_user,lm_date)
                                values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@remarks,@style,@lm_user,@lm_date)";
                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code, remarks = remarks, style = "B", lm_user = us.usercode, lm_date = date } });
                            sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,report_person,usergroup_code,remarks,style,lm_user,lm_date)
                                values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@report_person,@usergroup_code,@remarks,@style,@lm_user,@lm_date)";
                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code, report_person=reportuser, usergroup_code =usergroupcode, remarks = remarks, style = "B", lm_user = us.usercode, lm_date = date } });
                        }
                    }
@@ -3030,9 +3160,9 @@
                        //写入缺陷记录表
                        for (int i = 0; i < groupedItems.Count; i++)
                        {
                            sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,remarks,style,lm_user,lm_date)
                                values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@remarks,@style,@lm_user,@lm_date)";
                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code, remarks = remarks, style = "S", lm_user = us.usercode, lm_date = date } });
                            sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,report_person,remarks,style,lm_user,lm_date)
                                values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@report_person,@remarks,@style,@lm_user,@lm_date)";
                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code, report_person=inuser, remarks = remarks, style = "S", lm_user = us.usercode, lm_date = date } });
                        }
                    }
@@ -3057,9 +3187,9 @@
                        //写入缺陷记录表
                        for (int i = 0; i < groupedItems.Count; i++)
                        {
                            sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,remarks,style,lm_user,lm_date)
                                values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@remarks,@style,@lm_user,@lm_date)";
                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code, remarks = remarks, style = "S", lm_user = us.usercode, lm_date = date } });
                            sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,report_person,remarks,style,lm_user,lm_date)
                                values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@report_person,@remarks,@style,@lm_user,@lm_date)";
                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code, report_person=inuser, remarks = remarks, style = "S", lm_user = us.usercode, lm_date = date } });
                        }
                    }
@@ -3379,7 +3509,7 @@
        #region[生产执行,报工调整数据查询接口]
        public static ToMessage MesOrderStepVerifySearch(string wkshopcode, string wo_code, string partnumber, string partname, string partspec, string reportuser, string reportdateopendate, string reportdateclosedate, int startNum, int endNum, string prop, string order)
        public static ToMessage MesOrderStepVerifySearch(string wkshopcode, string wo_code, string orderno, string saorderno, string partnumber, string partname, string partspec, string stepcode, string reportuser, string reportdateopendate, string reportdateclosedate, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
@@ -3395,6 +3525,16 @@
                    search += "and AA.wo_code like '%'+@wo_code+'%' ";
                    dynamicParams.Add("@wo_code", wo_code);
                }
                if (orderno != "" && orderno != null)
                {
                    search += "and AA.m_po like '%'+@orderno+'%' ";
                    dynamicParams.Add("@orderno", orderno);
                }
                if (saorderno != "" && saorderno != null)
                {
                    search += "and AA.saleOrderCode like '%'+@saorderno+'%' ";
                    dynamicParams.Add("@saorderno", saorderno);
                }
                if (partnumber != "" && partnumber != null)
                {
                    search += "and AA.partnumber like '%'+@partnumber+'%' ";
@@ -3409,6 +3549,11 @@
                {
                    search += "and AA.partspec like '%'+@partspec+'%' ";
                    dynamicParams.Add("@partspec", partspec);
                }
                if (stepcode != "" && stepcode != null)
                {
                    search += "and AA.step_code=@stepcode ";
                    dynamicParams.Add("@stepcode", stepcode);
                }
                if (reportuser != "" && reportuser != null)
                {
@@ -3431,8 +3576,8 @@
                // --------------查询指定自制报工外协收料数据--------------
                var total = 0; //总条数
                var sql = @"select *  from(
                            select A.id,B.id as sbid,A.wo_code,A.materiel_code as partnumber,P.partname,P.partspec,K.plan_quantity,K.plan_qty as task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.eqp_code,E.name as eqp_name,
                            A.step_seq,A.step_code,S.stepname,S.flwtype as steptype,k.isbott as first_choke,k.isend as last_choke,A.step_price,B.reckway,B.usergroup_code,G.usergroupname as usergroup_name,
                            select A.id,B.id as sbid,A.wo_code,M.m_po,M.saleOrderCode,A.materiel_code as partnumber,P.partname,P.partspec,K.plan_quantity,K.plan_qty as task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.eqp_code,E.name as eqp_name,
                            A.step_seq,A.step_code,S.stepname,S.flwtype as steptype,A.style,k.isbott as first_choke,k.isend as last_choke,A.step_price,B.reckway,B.usergroup_code,G.usergroupname as usergroup_name,
                            B.report_person as usercode,
                             STUFF((SELECT ',' + U.username
                                    FROM TUser U
@@ -3450,8 +3595,8 @@
                            left join TGroup G on G.usergroupcode=B.usergroup_code
                            where A.style='B' and B.style='B' and M.status<>'CLOSED' and A.verify='N'
                            union all
                            select A.id,B.id as sbid,A.wo_code,A.materiel_code as partnumber,P.partname,P.partspec,K.plan_quantity,K.plan_qty as task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.wx_code as eqp_code,E.name as eqp_name,
                            A.step_seq,A.step_code,S.stepname,S.flwtype as steptype,k.isbott as first_choke,k.isend as last_choke,A.step_price,'person' as reckway,'' as usergroup_code,'' as usergroup_name,
                            select A.id,B.id as sbid,A.wo_code,M.m_po,M.saleOrderCode,A.materiel_code as partnumber,P.partname,P.partspec,K.plan_quantity,K.plan_qty as task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.wx_code as eqp_code,E.name as eqp_name,
                            A.step_seq,A.step_code,S.stepname,S.flwtype as steptype,A.style,k.isbott as first_choke,k.isend as last_choke,A.step_price,'person' as reckway,'' as usergroup_code,'' as usergroup_name,
                            B.in_person as usercode,
                            STUFF((SELECT ',' + U.username
                                    FROM TUser U
@@ -4072,7 +4217,7 @@
                                    }
                                }
                            }
                        }
                        }
                    }
                }
                else //不按序
@@ -4080,10 +4225,10 @@
                    //控制逻辑:当前工序报工调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废)   ==不能小于下道报工总数
                    list.Clear();
                    //判断当前工序是自制工序还是外协工序
                    if (json[0].flw_type.ToString() == "Z")
                    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);
@@ -4105,7 +4250,7 @@
                            return mes;
                        }
                    }
                    if (json[0].flw_type.ToString() == "W")
                    if (json[0].flw_type.ToString() == "W")
                    {
                        //获取当前工序、供应商对应的总发料数量
                        sql = @"select isnull(sum(fqty),0) as fqty
@@ -4127,7 +4272,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()))
@@ -4148,7 +4293,7 @@
                        //回写对应的报工记录子表合格数量、不良数量、报废数量
                        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
                            report_person=@report_person,usergroup_code=@usergroup_code,updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where  m_id=@m_id and id=@id and style='B'";
                        list.Add(new
                        {
@@ -4162,6 +4307,8 @@
                                laborbad_qty = this_laborbad_dvalue,
                                materielbad_qty = this_materielbad_dvalue,
                                //bad_money = decimal.Parse(json[i].badmoney_dvalue),
                                report_person = json[0].usercode,
                                usergroup_code = json[0].groupcode,
                                updatereportuser = us.usercode,
                                updatereportdate = date
                            }
@@ -4175,7 +4322,7 @@
                            str = sql,
                            parm = new
                            {
                                step_price=decimal.Parse(json[0].unprice),
                                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,
@@ -4208,7 +4355,7 @@
                        {
                            //回写不良
                            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
                                report_person=@report_person,usergroup_code=@usergroup_code,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
                            {
@@ -4222,6 +4369,8 @@
                                    step_code = json[0].step_code,
                                    ng_id = int.Parse(json[0].children[i].ng_id),
                                    record_id = json[0].id,
                                    report_person = json[0].usercode,
                                    usergroup_code = json[0].groupcode,
                                    updatereportuser = us.usercode,
                                    updatereportdate = date
                                }
@@ -4250,7 +4399,7 @@
                        //回写对应的外协记录子表收料数量、不良数量、报废数量
                        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
                            out_person=@out_person,updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where  m_id=@m_id and id=@id and style='S' and wx_code=@wx_code";
                        list.Add(new
                        {
@@ -4265,6 +4414,7 @@
                                materielbad_qty = this_materielbad_dvalue,
                                wx_code = json[0].wxcode,
                                //bad_money = decimal.Parse(json[i].badmoney_dvalue),
                                out_person = json[0].usercode,
                                updatereportuser = us.usercode,
                                updatereportdate = date
                            }
@@ -4278,7 +4428,7 @@
                            str = sql,
                            parm = new
                            {
                                step_price=decimal.Parse(json[0].unprice),
                                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,
@@ -4312,7 +4462,7 @@
                        {
                            //回写不良
                            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
                                report_person=@report_person,usergroup_code=@usergroup_code,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
                            {
@@ -4326,6 +4476,8 @@
                                    step_code = json[0].step_code,
                                    ng_id = int.Parse(json[0].children[i].ng_id),
                                    record_id = json[0].id,
                                    report_person = json[0].usercode,
                                    usergroup_code = json[0].groupcode,
                                    updatereportuser = us.usercode,
                                    updatereportdate = date
                                }
@@ -4381,10 +4533,122 @@
        }
        #endregion
        #region[生产执行,报工调整批量改价数据提交]
        public static ToMessage MesOrderStepPriceBatchUpdateSeave(User us, List<BatchPrice> json)
        {
            string sql = "";
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                if (json.Count > 0)
                {
                    // 使用Lambda表达式判断类型分布:全部报工或者全部收料
                    bool allB = json.All(p => p.type == "B");
                    bool allS = json.All(p => p.type == "S");
                    if (allB)//全部报工
                    {
                        //将List<BatchPrice>中的id字段转换为字符串数组
                        string[] idArray = json.Select(bp => bp.id).ToArray();
                        //回写对应的报工记录主表工价
                        sql = @"update TK_Wrk_Record set step_price=@step_price where id in @idArray and style='B'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                step_price = decimal.Parse(json[0].price),
                                idArray = idArray
                            }
                        });
                    }
                    else if (allS)//全部收料
                    {
                        //将List<BatchPrice>中的id字段转换为字符串数组
                        string[] idArray = json.Select(bp => bp.id).ToArray();
                        //回写对应的报工记录主表工价
                        sql = @"update TK_Wrk_OutRecord set step_price=@step_price where id in @idArray and style='S'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                step_price = decimal.Parse(json[0].price),
                                idArray = idArray
                            }
                        });
                    }
                    else // 混合情况
                    {
                        //将List<BatchPrice>中为报工的id字段转换为字符串数组
                        var bList = json.Where(p => p.type == "B").ToList();
                        string[] idBArray = bList.Select(bp => bp.id).ToArray();
                        //回写对应的报工记录主表工价
                        sql = @"update TK_Wrk_Record set step_price=@step_price where id in @idBArray and style='B'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                step_price = decimal.Parse(json[0].price),
                                idBArray = idBArray
                            }
                        });
                        //将List<BatchPrice>中为收料的id字段转换为字符串数组
                        var sList = json.Where(p => p.type == "S").ToList();
                        string[] idSArray = sList.Select(bp => bp.id).ToArray();
                        //回写对应的报工记录主表工价
                        sql = @"update TK_Wrk_OutRecord set step_price=@step_price where id in @idSArray and style='S'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                step_price = decimal.Parse(json[0].price),
                                idSArray = idSArray
                            }
                        });
                    }
                    bool aa = DapperHelper.DoTransaction(list);
                    if (aa)
                    {
                        //写入操作记录表
                        LogHelper.DbOperateLog(us.usercode, "批量修改工价", "报工ID:" + string.Join(",", json.Select(bp => bp.id).ToArray()) + ",操作类型:" + string.Join(",", json.Select(bp => bp.type).ToArray()), 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;
                    }
                }
                else
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.message = "请选择需要批量调整工价的报工记录!";
                    mes.data = null;
                    return mes;
                }
                return mes;
            }
            catch (Exception)
            {
                throw;
            }
        }
        #endregion
        #region[生产执行,报工审核列表数据查询接口]
        public static ToMessage MesOrderStepReportVerifySearch(string reviewstatus, string wkshopcode, string wo_code, string partnumber, string partname, string partspec, string stepname, string reportuser, string reportdateopendate, string reportdateclosedate, int startNum, int endNum, string prop, string order)
        public static ToMessage MesOrderStepReportVerifySearch(string reviewstatus, string wkshopcode, string wo_code, string orderno, string saorderno, string partnumber, string partname, string partspec, string stepname, string reportuser, string reportdateopendate, string reportdateclosedate, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
@@ -4404,6 +4668,16 @@
                {
                    search += "and AA.wo_code like '%'+@wo_code+'%' ";
                    dynamicParams.Add("@wo_code", wo_code);
                }
                if (orderno != "" && orderno != null)
                {
                    search += "and AA.m_po like '%'+@orderno+'%' ";
                    dynamicParams.Add("@orderno", orderno);
                }
                if (saorderno != "" && saorderno != null)
                {
                    search += "and AA.saleOrderCode like '%'+@saorderno+'%' ";
                    dynamicParams.Add("@saorderno", saorderno);
                }
                if (partnumber != "" && partnumber != null)
                {
@@ -4446,7 +4720,7 @@
                // --------------查询指定自制报工外协收料数据--------------
                var total = 0; //总条数
                var sql = @"select *  from(
                            select A.id,B.id as sbid,A.wo_code,A.materiel_code as partnumber,P.partname,P.partspec,K.plan_quantity,K.plan_qty as task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.eqp_code,E.name as eqp_name,
                            select A.id,B.id as sbid,A.wo_code,M.m_po,M.saleOrderCode,A.materiel_code as partnumber,P.partname,P.partspec,K.plan_quantity,K.plan_qty as task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.eqp_code,E.name as eqp_name,
                            A.step_seq,A.step_code,S.stepname,S.flwtype as steptype,k.isbott as first_choke,k.isend as last_choke,A.step_price,B.reckway,B.usergroup_code,G.usergroupname as usergroup_name,
                            B.report_person as usercode,
                             STUFF((SELECT ',' + U.username
@@ -4465,7 +4739,7 @@
                            left join TGroup G on G.usergroupcode=B.usergroup_code
                            where A.style='B' and B.style='B' and M.status<>'CLOSED' 
                            union all
                            select A.id,B.id as sbid,A.wo_code,A.materiel_code as partnumber,P.partname,P.partspec,K.plan_quantity,K.plan_qty as task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.wx_code as eqp_code,E.name as eqp_name,
                            select A.id,B.id as sbid,A.wo_code,M.m_po,M.saleOrderCode,A.materiel_code as partnumber,P.partname,P.partspec,K.plan_quantity,K.plan_qty as task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.wx_code as eqp_code,E.name as eqp_name,
                            A.step_seq,A.step_code,S.stepname,S.flwtype as steptype,k.isbott as first_choke,k.isend as last_choke,A.step_price,'person' as reckway,'' as usergroup_code,'' as usergroup_name,
                            B.in_person as usercode,
                            STUFF((SELECT ',' + U.username
@@ -4620,6 +4894,7 @@
        #endregion
        #region[生产入库条码补打]
        public static ToMessage ProductInHouseLabCode(string ordercode)
        {
@@ -4663,12 +4938,26 @@
        #endregion
        #region[生产入库信息查询]
        public static ToMessage ProductInHouseOrderSearch(string deptno, string saleordercode, string wkshopcode, string erpordercode, string mesordercode, string partcode, string partname, string partspec)
        public static ToMessage ProductInHouseOrderSearch(string issouceorder, string deptno, string saleordercode, string wkshopcode, string erpordercode, string mesordercode, string partcode, string partname, string partspec)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (issouceorder != "" && issouceorder != null)
                {
                    switch (issouceorder)
                    {
                        case "Y":
                            search += " and AA.m_po<>'' ";
                            break;
                        case "N":
                            search += " and AA.m_po='' ";
                            break;
                        default:
                            break;
                    }
                }
                if (deptno != "" && deptno != null)
                {
                    search += "and AA.dept_code=@deptno ";
@@ -4714,7 +5003,8 @@
                var sql = @"select *   from(
                              select A.inbarcode,E.saleOrderid,isnull(E.saleOrderCode,'') as saleOrderCode,E.saleOrderDetailId,E.woid as mpoid,M.m_po,E.sbid,M.id as wo_id,A.wo_code,E.materiel_id,P.partcode,P.partname,P.partspec,E.unitid,E.unitcode,E.unitname,
                              A.step_code,T.stepname,M.wkshp_code,O.torg_name as wkshp_name,COALESCE(K.noid, E.stck_id) as stockid,COALESCE(K.code, E.stck_code) as stockcode,k.name as stockname,E.dept_id,E.dept_code,
                              E.saleOrderqty,E.qty,M.plan_qty,A.good_qty,isnull(A.inhouseqty,0) as inhouseqty,A.good_qty-isnull(A.inhouseqty,0) as stinhouseqty,M.lm_date,A.style,E.voucherdate
                              E.saleOrderqty,E.qty,M.plan_qty,A.good_qty,isnull(A.inhouseqty,0) as inhouseqty,A.good_qty-isnull(A.inhouseqty,0) as stinhouseqty,M.lm_date,A.style,
                              (case when E.voucherdate is null then M.lm_date else E.voucherdate end) as voucherdate
                              from  TK_Wrk_Record A
                              inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code
                              inner join TK_Wrk_Man M on S.wo_code=M.wo_code
@@ -4727,7 +5017,8 @@
                              union all
                              select A.inbarcode,E.saleOrderid,isnull(E.saleOrderCode,'') as saleOrderCode,E.saleOrderDetailId,E.woid as mpoid,M.m_po,E.sbid,M.id as wo_id,A.wo_code,E.materiel_id,P.partcode,P.partname,P.partspec,E.unitid,E.unitcode,E.unitname,
                              A.step_code,T.stepname,M.wkshp_code,O.torg_name as wkshp_name,COALESCE(K.noid, E.stck_id) as stockid,COALESCE(K.code, E.stck_code) as stockcode,k.name as stockname,E.dept_id,E.dept_code,
                              E.saleOrderqty,E.qty,M.plan_qty,A.sqty as sqty,isnull(A.inhouseqty,0) as inhouseqty,A.sqty-isnull(A.inhouseqty,0) as stinhouseqty,M.lm_date,A.style,E.voucherdate
                              E.saleOrderqty,E.qty,M.plan_qty,A.sqty as sqty,isnull(A.inhouseqty,0) as inhouseqty,A.sqty-isnull(A.inhouseqty,0) as stinhouseqty,M.lm_date,A.style,
                              (case when E.voucherdate is null then M.lm_date else E.voucherdate end) as voucherdate
                              from  TK_Wrk_OutRecord A
                              inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code
                              inner join TK_Wrk_Man M on S.wo_code=M.wo_code