From dc708ece0dce875d0d296ba56f8b59ae6f392e27 Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期五, 22 三月 2024 09:56:13 +0800
Subject: [PATCH] 1.生产进度报表查询参数删减 2.新工单带出历史最新一次工序信息查询接口修改

---
 VueWebCoreApi/DLL/DAL/WorkOrderDAL.cs | 1808 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 1,568 insertions(+), 240 deletions(-)

diff --git a/VueWebCoreApi/DLL/DAL/WorkOrderDAL.cs b/VueWebCoreApi/DLL/DAL/WorkOrderDAL.cs
index 73794b2..3ed3504 100644
--- a/VueWebCoreApi/DLL/DAL/WorkOrderDAL.cs
+++ b/VueWebCoreApi/DLL/DAL/WorkOrderDAL.cs
@@ -7,6 +7,9 @@
 using System.Linq;
 using System.Threading.Tasks;
 using VueWebCoreApi.Models;
+using VueWebCoreApi.Models.ErpOrder;
+using VueWebCoreApi.Models.ReportVerify;
+using VueWebCoreApi.Models.UpdateReport;
 using VueWebCoreApi.Models.WorkData;
 using VueWebCoreApi.Tools;
 
@@ -16,6 +19,7 @@
     {
         public static DataTable dt;    //瀹氫箟鍏ㄥ眬鍙橀噺dt
         public static bool res;       //瀹氫箟鍏ㄥ眬鍙橀噺dt
+
         public static ToMessage mes = new ToMessage(); //瀹氫箟鍏ㄥ眬杩斿洖淇℃伅瀵硅薄
         public static string strProcName = ""; //瀹氫箟鍏ㄥ眬sql鍙橀噺
         public static List<SqlParameter> listStr = new List<SqlParameter>(); //瀹氫箟鍏ㄥ眬鍙傛暟闆嗗悎
@@ -23,7 +27,7 @@
 
 
         #region[ERP璁㈠崟鏌ヨ]
-        public static ToMessage ErpOrderSearch(string erporderstus, string erpordercode, string saleordercode, string partcode, string partname, string partspec, int startNum, string paydatestartdate, string paydateenddate, string paydatestartdate1, string paydateenddate2, 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 paydatestartdate, string paydateenddate, string paydatestartdate1, string paydateenddate2, string creatuser, int endNum, string prop, string order)
         {
             var dynamicParams = new DynamicParameters();
             string search = "";
@@ -33,6 +37,11 @@
                 {
                     search += "and A.status=@erporderstus ";
                     dynamicParams.Add("@erporderstus", erporderstus);
+                }
+                if (wkshopcode != "" && wkshopcode != null)
+                {
+                    search += "and A.wkshp_code=@wkshopcode ";
+                    dynamicParams.Add("@wkshopcode", wkshopcode);
                 }
                 if (erpordercode != "" && erpordercode != null)
                 {
@@ -84,7 +93,7 @@
                 // --------------鏌ヨ鎸囧畾鏁版嵁--------------
                 var total = 0; //鎬绘潯鏁�
                 var sql = @"select A.id, A.status,A.wo,A.materiel_code as partcode,B.partname,B.partspec,A.qty,A.relse_qty,A.wkshp_code,C.torg_name as wkshp_name,
-                            A.stck_code,D.name as stck_name,A.saleOrderCode,A.saleOrderDeliveryDate,A.planstartdate,A.planenddate,U.username as createuser,A.createdate,A.sbid 
+                            A.stck_code,D.name as stck_name,A.saleOrderCode,A.saleOrderDeliveryDate,A.planstartdate,A.planenddate,U.username as createuser,A.createdate,A.sbid,A.clerkuser
                             from TKimp_Ewo A
                             left join TMateriel_Info B on A.materiel_code=B.partcode
                             left join TOrganization C on A.wkshp_code=C.torg_code
@@ -93,7 +102,7 @@
                             where A.is_delete<>'1' " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                 mes.code = "200";
-                mes.Message = "鏌ヨ鎴愬姛!";
+                mes.message = "鏌ヨ鎴愬姛!";
                 mes.count = total;
                 mes.data = data.ToList();
             }
@@ -101,7 +110,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -109,7 +118,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, 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 clerkuser, User us)
         {
             var sql = "";
             List<object> list = new List<object>();
@@ -147,7 +156,7 @@
                     }
                     if (i == Convert.ToInt32(ordernum))  //鏈�鍚庝竴鍗曟椂
                     {
-                        sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,stck_code,sbid,materiel_code,sourceid,m_po,lm_user,lm_date,saleOrderCode,saleOrderDeliveryDate,data_sources,isstep) values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@stck_code,@sbid,@materiel_code,@sourceid,@m_po,@username,@CreateDate,@saleOrderCode,@saleOrderDeliveryDate,@data_sources,@isstep)";
+                        sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,stck_code,sbid,materiel_code,sourceid,m_po,lm_user,lm_date,saleOrderCode,saleOrderDeliveryDate,data_sources,isstep,clerkuser) values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@stck_code,@sbid,@materiel_code,@sourceid,@m_po,@username,@CreateDate,@saleOrderCode,@saleOrderDeliveryDate,@data_sources,@isstep,@clerkuser)";
                         list.Add(new
                         {
                             str = sql,
@@ -168,7 +177,8 @@
                                 saleOrderCode = saleordercode,
                                 saleOrderDeliveryDate = Convert.ToDateTime(saleOrderDeliveryDate),
                                 data_sources = "ERP",
-                                isstep = "N"  //鏄惁鍏宠仈宸ュ簭
+                                isstep = "N",  //鏄惁鍏宠仈宸ュ簭
+                                clerkuser= clerkuser //閿�鍞鍗曚笟鍔″憳
                             }
                         });
                         sumqty = sumqty + (decimal.Parse(markqty) - sumqty);
@@ -176,7 +186,7 @@
                     else
                     {
 
-                        sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,stck_code,sbid,materiel_code,sourceid,m_po,lm_user,lm_date,saleOrderCode,saleOrderDeliveryDate,data_sources,isstep) values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@stck_code,@sbid,@materiel_code,@sourceid,@m_po,@username,@CreateDate,@saleOrderCode,@saleOrderDeliveryDate,@data_sources,@isstep)";
+                        sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,stck_code,sbid,materiel_code,sourceid,m_po,lm_user,lm_date,saleOrderCode,saleOrderDeliveryDate,data_sources,isstep,clerkuser) values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@stck_code,@sbid,@materiel_code,@sourceid,@m_po,@username,@CreateDate,@saleOrderCode,@saleOrderDeliveryDate,@data_sources,@isstep,@clerkuser)";
                         list.Add(new
                         {
                             str = sql,
@@ -197,7 +207,8 @@
                                 saleOrderCode = saleordercode,
                                 saleOrderDeliveryDate = Convert.ToDateTime(saleOrderDeliveryDate),
                                 data_sources = "ERP",
-                                isstep = "N"//鏄惁鍏宠仈宸ュ簭
+                                isstep = "N",//鏄惁鍏宠仈宸ュ簭
+                                clerkuser= clerkuser
                             }
                         });
                     }
@@ -239,14 +250,14 @@
                     LogHelper.DbOperateLog(us.usercode, "涓嬭揪", "涓嬭揪浜嗗伐鍗�:" + wo, us.usertype);
                     mes.code = "200";
                     mes.count = 0;
-                    mes.Message = "涓嬭揪MES宸ュ崟鎴愬姛!";
+                    mes.message = "涓嬭揪MES宸ュ崟鎴愬姛!";
                     mes.data = null;
                 }
                 else
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "涓嬭揪MES宸ュ崟鎴愬姛澶辫触!";
+                    mes.message = "涓嬭揪MES宸ュ崟鎴愬姛澶辫触!";
                     mes.data = null;
                 }
             }
@@ -254,7 +265,110 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[璁㈠崟鎵归噺涓嬭揪]
+        public static ToMessage MarkBatchSaveErpOrder(List<ErpOrderBatch> obj, User us)
+        {
+            var sql = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+
+            try
+            {
+                list.Clear();
+                string result = "";
+                //var groupedModels = obj.GroupBy(m => m.erpordercode);
+                var groupedModels = obj.GroupBy(s => s.erpordercode).Select(g => new { erpordercode = g.Key }).ToList();
+                foreach (var group in groupedModels)
+                {
+                    string erpordercode = group.erpordercode;
+                    int count = 1;
+                    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   
+                                from TK_Wrk_Man where  m_po=@erpordercode";
+                        dynamicParams.Add("@erpordercode", model.erpordercode);
+                        var data = DapperHelper.selectdata(sql, dynamicParams);
+                        int num = Convert.ToInt32(data.Rows[0]["WORKNUMB"].ToString());
+                        string wo = model.erpordercode + "_" + (num + count);
+                        result += wo.ToString() + ",";
+                        //鍐欏叆宸ュ崟琛�
+                        sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,stck_code,sbid,materiel_code,sourceid,m_po,lm_user,lm_date,saleOrderCode,saleOrderDeliveryDate,data_sources,isstep,clerkuser) values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@stck_code,@sbid,@materiel_code,@sourceid,@m_po,@username,@CreateDate,@saleOrderCode,@saleOrderDeliveryDate,@data_sources,@isstep,@clerkuser)";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                wo_code = wo,
+                                wotype = "PO",
+                                status = "NEW",
+                                wkshp_code = model.wkshopcode,
+                                plan_qty = decimal.Parse(model.erpqty),  //璁㈠崟鏁伴噺
+                                stck_code = model.warehousecode,
+                                sbid = model.sbid,
+                                materiel_code = model.partcode,
+                                sourceid = model.erporderid,
+                                m_po = model.erpordercode,
+                                username = us.usercode,
+                                CreateDate = DateTime.Now.ToString(),
+                                saleOrderCode = model.saleordercode,
+                                saleOrderDeliveryDate = Convert.ToDateTime(model.saleOrderDeliveryDate),
+                                data_sources = "ERP",
+                                isstep = "N",  //鏄惁鍏宠仈宸ュ簭
+                                clerkuser= model.clerkuser //閿�鍞鍗曚笟鍔″憳
+                            }
+                        });
+
+                        //鏇存柊璁㈠崟鐘舵��
+                        sql = @"update  TKimp_Ewo set status='CREATED',saleOrderDeliveryDate=@saleOrderDeliveryDate,relse_qty=relse_qty+@sumqty where wo=@wo and id=@erporderid";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                wo = model.erpordercode,
+                                erporderid = model.erporderid,
+                                sumqty = decimal.Parse(model.markqty),
+                                saleOrderDeliveryDate = Convert.ToDateTime(model.saleOrderDeliveryDate)
+                            }
+                        });
+                        count++;
+                    }
+                }
+
+
+
+                bool aa = DapperHelper.DoTransaction(list);
+                if (aa)
+                {
+                    //鍐欏叆鎿嶄綔璁板綍琛�
+                    LogHelper.DbOperateLog(us.usercode, "鎵归噺涓嬭揪", "鎵归噺涓嬭揪浜嗗伐鍗�:" + result.TrimEnd(','), us.usertype);
+                    mes.code = "200";
+                    mes.count = 0;
+                    mes.message = "鎵归噺涓嬭揪MES宸ュ崟鎴愬姛!";
+                    mes.data = null;
+                }
+                else
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.message = "鎵归噺涓嬭揪MES宸ュ崟鎴愬姛澶辫触!";
+                    mes.data = null;
+                }
+
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -276,7 +390,7 @@
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "褰撳墠璁㈠崟鏈変笅杈炬湭鍏抽棴鐨凪ES宸ュ崟,璁㈠崟涓嶅厑璁稿叧闂�,璇峰厛鍒犻櫎鎴栧叧闂浉鍏冲伐鍗�!";
+                    mes.message = "褰撳墠璁㈠崟鏈変笅杈炬湭鍏抽棴鐨凪ES宸ュ崟,璁㈠崟涓嶅厑璁稿叧闂�,璇峰厛鍒犻櫎鎴栧叧闂浉鍏冲伐鍗�!";
                     mes.data = null;
                 }
                 else
@@ -300,14 +414,14 @@
                     LogHelper.DbOperateLog(us.usercode, "鍏抽棴", "鍏抽棴浜嗚鍗�:" + erpordercode, us.usertype);
                     mes.code = "200";
                     mes.count = 0;
-                    mes.Message = "璁㈠崟鍏抽棴鎴愬姛!";
+                    mes.message = "璁㈠崟鍏抽棴鎴愬姛!";
                     mes.data = null;
                 }
                 else
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "璁㈠崟鍏抽棴澶辫触!";
+                    mes.message = "璁㈠崟鍏抽棴澶辫触!";
                     mes.data = null;
                 }
             }
@@ -315,7 +429,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -338,7 +452,7 @@
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "褰撳墠璁㈠崟涓嬫湁宸ュ崟宸叉淳鍙戞垨宸插紑宸ユ垨宸插畬宸�(鍏抽棴),涓嶅厑璁稿垹闄�!";
+                    mes.message = "褰撳墠璁㈠崟涓嬫湁宸ュ崟宸叉淳鍙戞垨宸插紑宸ユ垨宸插畬宸�(鍏抽棴),涓嶅厑璁稿垹闄�!";
                     mes.data = null;
                     return mes;
                 }
@@ -375,14 +489,14 @@
                     LogHelper.DbOperateLog(us.usercode, "鍒犻櫎", "鍒犻櫎浜嗚鍗�:" + erpordercode, us.usertype);
                     mes.code = "200";
                     mes.count = 0;
-                    mes.Message = "璁㈠崟鍒犻櫎鎴愬姛!";
+                    mes.message = "璁㈠崟鍒犻櫎鎴愬姛!";
                     mes.data = null;
                 }
                 else
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "璁㈠崟鍒犻櫎澶辫触!";
+                    mes.message = "璁㈠崟鍒犻櫎澶辫触!";
                     mes.data = null;
                 }
             }
@@ -390,7 +504,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -400,7 +514,7 @@
 
 
         #region[MES宸ュ崟鏌ヨ]
-        public static ToMessage MesOrderSearch(string mesorderstus, string mesordercode, string sourceorder, string saleordercode, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, 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 createdate, int endNum, string prop, string order)
         {
             var dynamicParams = new DynamicParameters();
             string search = "";
@@ -410,6 +524,11 @@
                 {
                     search += "and A.status=@mesorderstus ";
                     dynamicParams.Add("@mesorderstus", mesorderstus);
+                }
+                if (wkshopcode != "" && wkshopcode != null)
+                {
+                    search += "and A.wkshp_code=@wkshopcode ";
+                    dynamicParams.Add("@wkshopcode", wkshopcode);
                 }
                 if (mesordercode != "" && mesordercode != null)
                 {
@@ -464,9 +583,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,
-                            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.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
+                            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
                             left join TOrganization C on A.wkshp_code=C.torg_code
                             left join TSecStck D on A.stck_code=D.code 
@@ -475,7 +594,7 @@
                             where A.is_delete<>'1' " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                 mes.code = "200";
-                mes.Message = "鏌ヨ鎴愬姛!";
+                mes.message = "鏌ヨ鎴愬姛!";
                 mes.count = total;
                 mes.data = data.ToList();
             }
@@ -483,7 +602,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -491,12 +610,17 @@
         #endregion
 
         #region[MES鎶ュ簾琛ュ崟宸ュ崟鏌ヨ]
-        public static ToMessage MesBadOrderSearch(string mesordercode, string sourceorder, string saleordercode, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order)
+        public static ToMessage MesBadOrderSearch(string wkshopcode, string mesordercode, string sourceorder, string saleordercode, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order)
         {
             var dynamicParams = new DynamicParameters();
             string search = "";
             try
             {
+                if (wkshopcode != "" && wkshopcode != null)
+                {
+                    search += "and A.wkshp_code=@wkshopcode ";
+                    dynamicParams.Add("@wkshopcode", wkshopcode);
+                }
                 if (mesordercode != "" && mesordercode != null)
                 {
                     search += "and A.wo_code like '%'+@mesordercode+'%' ";
@@ -547,7 +671,7 @@
                 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,
                             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
                             from TK_Wrk_Man A
-                            left join TKimp_Ewo W on A.m_po=W.wo and A.materiel_code=W.materiel_code
+                            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
                             left join TMateriel_Info B on A.materiel_code=B.partcode
                             left join TOrganization C on A.wkshp_code=C.torg_code
@@ -556,7 +680,7 @@
                             where A.is_delete<>'1'  and (S.laborbad_qty+S.materielbad_qty)>0 " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                 mes.code = "200";
-                mes.Message = "鏌ヨ鎴愬姛!";
+                mes.message = "鏌ヨ鎴愬姛!";
                 mes.count = total;
                 mes.data = data.ToList();
             }
@@ -564,7 +688,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -584,14 +708,14 @@
                         FROM TK_Wrk_Man where wo_code like '%SGPO%'";
                 var data = DapperHelper.selecttable(sql);
                 mes.code = "200";
-                mes.Message = "鏌ヨ鎴愬姛!";
+                mes.message = "鏌ヨ鎴愬姛!";
                 mes.data = data.Rows[0]["numct"].ToString();
             }
             catch (Exception e)
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -653,14 +777,14 @@
                 dir.Add("stepdata", data1);
                 mes.code = "200";
                 mes.count = data1.Rows.Count;
-                mes.Message = "鏌ヨ鎴愬姛";
+                mes.message = "鏌ヨ鎴愬姛";
                 mes.data = dir;
             }
             catch (Exception e)
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -732,14 +856,14 @@
                         LogHelper.DbOperateLog(us.usercode, "鏂板", "鏂板浜嗗伐鍗�:" + json.wocode, us.usertype);
                         mes.code = "200";
                         mes.count = 0;
-                        mes.Message = "MES宸ュ崟鏂板缓鎴愬姛!";
+                        mes.message = "MES宸ュ崟鏂板缓鎴愬姛!";
                         mes.data = null;
                     }
                     else
                     {
                         mes.code = "300";
                         mes.count = 0;
-                        mes.Message = "MES宸ュ崟鏂板缓澶辫触!";
+                        mes.message = "MES宸ュ崟鏂板缓澶辫触!";
                         mes.data = null;
                     }
                 }
@@ -808,14 +932,14 @@
                         LogHelper.DbOperateLog(us.usercode, "淇敼", "淇敼浜嗗伐鍗�:" + json.wocode, us.usertype);
                         mes.code = "200";
                         mes.count = 0;
-                        mes.Message = "淇敼鎿嶄綔鎴愬姛!";
+                        mes.message = "淇敼鎿嶄綔鎴愬姛!";
                         mes.data = null;
                     }
                     else
                     {
                         mes.code = "300";
                         mes.count = 0;
-                        mes.Message = "淇敼鎿嶄綔澶辫触!";
+                        mes.message = "淇敼鎿嶄綔澶辫触!";
                         mes.data = null;
                     }
                 }
@@ -824,7 +948,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -882,7 +1006,7 @@
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "宸ュ崟鎵ц涓垨宸插叧闂紝涓嶅厑璁稿垹闄�!";
+                    mes.message = "宸ュ崟鎵ц涓垨宸插叧闂紝涓嶅厑璁稿垹闄�!";
                     mes.data = null;
                 }
                 bool aa = DapperHelper.DoTransaction(list);
@@ -892,14 +1016,14 @@
                     LogHelper.DbOperateLog(us.usercode, "鍒犻櫎", "鍒犻櫎浜嗗伐鍗�:" + wocode, us.usertype);
                     mes.code = "200";
                     mes.count = 0;
-                    mes.Message = "鍒犻櫎鎴愬姛!";
+                    mes.message = "鍒犻櫎鎴愬姛!";
                     mes.data = null;
                 }
                 else
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "鍒犻櫎澶辫触!";
+                    mes.message = "鍒犻櫎澶辫触!";
                     mes.data = null;
                 }
             }
@@ -907,7 +1031,45 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[MES宸ュ崟鏌ユ壘鍘嗗彶寮曠敤鏈�鏂板伐搴忎俊鎭痌
+        public static ToMessage MesOrderNewStepContent(string wkshopcode, 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
+                        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", wkshopcode);
+                dynamicParams.Add("@partcode", partcode);
+                var data = DapperHelper.selectdata(sql, dynamicParams);
+                mes.code = "200";
+                mes.count = data.Rows.Count;
+                mes.data = data;
+                mes.message = "鏌ヨ鎴愬姛!";
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -951,14 +1113,14 @@
                     LogHelper.DbOperateLog(us.usercode, "娲惧彂", "娲惧彂浜嗗伐鍗�:" + string.Join(",", wocodelist), us.usertype);
                     mes.code = "200";
                     mes.count = 0;
-                    mes.Message = "MES宸ュ崟娲惧彂鎴愬姛!";
+                    mes.message = "MES宸ュ崟娲惧彂鎴愬姛!";
                     mes.data = null;
                 }
                 else
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "MES宸ュ缓娲惧彂澶辫触!";
+                    mes.message = "MES宸ュ缓娲惧彂澶辫触!";
                     mes.data = null;
                 }
 
@@ -967,7 +1129,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -976,7 +1138,7 @@
 
 
         #region[宸ュ崟鍏抽棴鍒楄〃鏌ヨ]
-        public static ToMessage MesOrderClosedSearch(string mesorderstus, string mesordercode, string sourceorder, string saleordercode, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order)
+        public static ToMessage MesOrderClosedSearch(string mesorderstus, string wkshopcode, string mesordercode, string sourceorder, string saleordercode, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order)
         {
             var dynamicParams = new DynamicParameters();
             string search = "";
@@ -991,6 +1153,11 @@
                 {
                     search += "and A.status<>@mesorderstus ";
                     dynamicParams.Add("@mesorderstus", "CLOSED");
+                }
+                if (wkshopcode != "" && wkshopcode != null)
+                {
+                    search += "and A.wkshp_code=@wkshopcode ";
+                    dynamicParams.Add("@wkshopcode", wkshopcode);
                 }
                 if (mesordercode != "" && mesordercode != null)
                 {
@@ -1056,7 +1223,7 @@
                             where A.is_delete<>'1' " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                 mes.code = "200";
-                mes.Message = "鏌ヨ鎴愬姛!";
+                mes.message = "鏌ヨ鎴愬姛!";
                 mes.count = total;
                 mes.data = data.ToList();
             }
@@ -1064,7 +1231,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -1095,14 +1262,14 @@
                     LogHelper.DbOperateLog(us.usercode, "鍏抽棴", "鍏抽棴浜嗗伐鍗�:" + string.Join(",", wocodelist), us.usertype);
                     mes.code = "200";
                     mes.count = 0;
-                    mes.Message = "宸ュ崟鍏抽棴鎴愬姛!";
+                    mes.message = "宸ュ崟鍏抽棴鎴愬姛!";
                     mes.data = null;
                 }
                 else
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "宸ュ崟鍏抽棴澶辫触!";
+                    mes.message = "宸ュ崟鍏抽棴澶辫触!";
                     mes.data = null;
                 }
             }
@@ -1110,7 +1277,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -1119,7 +1286,7 @@
 
 
         #region[鐢熶骇寮�鎶ュ伐鎵爜鑾峰彇宸ュ崟瀵瑰簲宸ュ簭浠诲姟(鑷埗)]
-        public static ToMessage MesOrderStepSearch(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 partcode, string partname, string partspec, int startNum, int endNum, string prop, string order)
         {
             var sql = "";
             string search = "";
@@ -1129,6 +1296,11 @@
             var total = 0; //鎬绘潯鏁�
             try
             {
+                if (wkshopcode != "" && wkshopcode != null)
+                {
+                    search += "and B.wkshp_code=@wkshopcode ";
+                    dynamicParams.Add("@wkshopcode", wkshopcode);
+                }
                 if (wocode != "" && wocode != null)
                 {
                     string[] arra = wocode.Split(';');
@@ -1142,7 +1314,7 @@
                         stepcode = arra[1]; //鑾峰彇鎸囧畾瀛楃涓插墠闈㈢殑瀛楃
                     }
 
-                    if (ordercode != "" && stepcode == null) //宸ュ崟鍙蜂笉涓虹┖,宸ュ簭鍙蜂负绌�
+                    if (ordercode != "" && (stepcode == null || stepcode == "")) //宸ュ崟鍙蜂笉涓虹┖,宸ュ簭鍙蜂负绌�
                     {
                         search += "and A.wo_code=@ordercode ";
                         dynamicParams.Add("@ordercode", ordercode);
@@ -1167,7 +1339,7 @@
                         {
                             mes.code = "300";
                             mes.count = 0;
-                            mes.Message = "褰撳墠宸ュ簭浠诲姟涓哄鍗忓伐搴忎换鍔�,璇峰墠寰�澶栧崗鎿嶄綔椤电鎵ц!";
+                            mes.message = "褰撳墠宸ュ簭浠诲姟涓哄鍗忓伐搴忎换鍔�,璇峰墠寰�澶栧崗鎿嶄綔椤电鎵ц!";
                             mes.data = null;
                             return mes;
                         }
@@ -1189,36 +1361,26 @@
                     dynamicParams.Add("@partspec", partspec);
                 }
                 //鏍规嵁鏉′欢鏌ヨ宸ュ崟宸ュ簭浠诲姟(鑷埗宸ュ簭)
-                sql = @"select A.status,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,M.partcode,M.partname,M.partspec,A.seq,A.isbott,A.isend,
                         S.stepcode,S.stepname,S.descr,A.plan_qty,A.good_qty,A.ng_qty,A.laborbad_qty,A.materielbad_qty,B.lm_date
                         from TK_Wrk_Step A
                         left join TK_Wrk_Man B on A.wo_code=B.wo_code
                         left join TMateriel_Info M on B.materiel_code=M.partcode
                         left join TStep S on A.step_code=S.stepcode
+                        left join TOrganization T on B.wkshp_code=T.torg_code
                         where A.status in('ALLO','START') and S.flwtype='Z'  " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
-                if (data.ToList().Count > 0)
-                {
-                    mes.code = "200";
-                    mes.count = total;
-                    mes.Message = "鏌ヨ鎴愬姛!";
-                    mes.data = data.ToList();
-                    return mes;
-                }
-                else
-                {
-                    mes.code = "300";
-                    mes.count = 0;
-                    mes.Message = "鏃犲彲鎵ц鐨勭敓浜т换鍔�,浠诲姟宸插畬鎴愭垨宸插叧闂�!";
-                    mes.data = null;
-                    return mes;
-                }
+                mes.code = "200";
+                mes.count = total;
+                mes.message = "鏌ヨ鎴愬姛!";
+                mes.data = data.ToList();
+                return mes;
             }
             catch (Exception e)
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -1226,7 +1388,7 @@
         #endregion
 
         #region[鐢熶骇寮�鎶ュ伐鎵爜鑾峰彇宸ュ崟瀵瑰簲宸ュ簭浠诲姟(澶栧崗)]
-        public static ToMessage MesOrderWxStepSearch(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 partcode, string partname, string partspec, int startNum, int endNum, string prop, string order)
         {
             var sql = "";
             string search = "";
@@ -1236,6 +1398,11 @@
             var total = 0; //鎬绘潯鏁�
             try
             {
+                if (wkshopcode != "" && wkshopcode != null)
+                {
+                    search += "and B.wkshp_code=@wkshopcode ";
+                    dynamicParams.Add("@wkshopcode", wkshopcode);
+                }
                 if (wocode != "" && wocode != null)
                 {
                     string[] arra = wocode.Split(';');
@@ -1249,7 +1416,7 @@
                         stepcode = arra[1]; //鑾峰彇鎸囧畾瀛楃涓插墠闈㈢殑瀛楃
                     }
 
-                    if (ordercode != "" && stepcode == null) //宸ュ崟鍙蜂笉涓虹┖,宸ュ簭鍙蜂负绌�
+                    if (ordercode != "" && (stepcode == null || stepcode == "")) //宸ュ崟鍙蜂笉涓虹┖,宸ュ簭鍙蜂负绌�
                     {
                         search += "and A.wo_code=@ordercode ";
                         dynamicParams.Add("@ordercode", ordercode);
@@ -1274,7 +1441,7 @@
                         {
                             mes.code = "300";
                             mes.count = 0;
-                            mes.Message = "褰撳墠宸ュ簭浠诲姟涓鸿嚜鍒跺伐搴忎换鍔�,璇峰墠寰�鑷埗鎿嶄綔椤电鎵ц!";
+                            mes.message = "褰撳墠宸ュ簭浠诲姟涓鸿嚜鍒跺伐搴忎换鍔�,璇峰墠寰�鑷埗鎿嶄綔椤电鎵ц!";
                             mes.data = null;
                             return mes;
                         }
@@ -1296,36 +1463,29 @@
                     dynamicParams.Add("@partspec", partspec);
                 }
                 //鏍规嵁鏉′欢鏌ヨ宸ュ崟宸ュ簭浠诲姟(鑷埗宸ュ簭)
-                sql = @"select A.status,A.wo_code,M.partcode,M.partname,M.partspec,A.seq,A.isbott,A.isend,
-                        S.stepcode,S.stepname,S.descr,A.plan_qty,A.good_qty,A.ng_qty,A.laborbad_qty,A.materielbad_qty,A.plan_startdate,A.plan_enddate,B.lm_date
+                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,
+                        S.stepcode,S.stepname,S.descr,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
                         from TK_Wrk_Step A
                         left join TK_Wrk_Man B on A.wo_code=B.wo_code
                         left join TMateriel_Info M on B.materiel_code=M.partcode
                         left join TStep S on A.step_code=S.stepcode
+                        left join TOrganization T on B.wkshp_code=T.torg_code
                         where A.status in('ALLO','START') and S.flwtype='W'  " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
-                if (data.ToList().Count > 0)
-                {
-                    mes.code = "200";
-                    mes.count = total;
-                    mes.Message = "鏌ヨ鎴愬姛!";
-                    mes.data = data.ToList();
-                    return mes;
-                }
-                else
-                {
-                    mes.code = "300";
-                    mes.count = 0;
-                    mes.Message = "鏃犲彲鎵ц鐨勭敓浜т换鍔�,浠诲姟宸插畬鎴愭垨宸插叧闂�!";
-                    mes.data = null;
-                    return mes;
-                }
+                mes.code = "200";
+                mes.count = total;
+                mes.message = "鏌ヨ鎴愬姛!";
+                mes.data = data.ToList();
+                return mes;
+
             }
             catch (Exception e)
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -1333,7 +1493,7 @@
         #endregion
 
         #region[鐢熶骇寮�鎶ュ伐鎵爜鑾峰彇宸ュ崟瀵瑰簲宸ュ簭浠诲姟(涓嶈壇)]
-        public static ToMessage MesOrderNgStepSearch(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 partcode, string partname, string partspec, int startNum, int endNum, string prop, string order)
         {
             var sql = "";
             string search = "";
@@ -1343,6 +1503,11 @@
             var total = 0; //鎬绘潯鏁�
             try
             {
+                if (wkshopcode != "" && wkshopcode != null)
+                {
+                    search += "and B.wkshp_code=@wkshopcode ";
+                    dynamicParams.Add("@wkshopcode", wkshopcode);
+                }
                 if (wocode != "" && wocode != null)
                 {
                     string[] arra = wocode.Split(';');
@@ -1356,7 +1521,7 @@
                         stepcode = arra[1]; //鑾峰彇鎸囧畾瀛楃涓插墠闈㈢殑瀛楃
                     }
 
-                    if (ordercode != "" && stepcode == null) //宸ュ崟鍙蜂笉涓虹┖,宸ュ簭鍙蜂负绌�
+                    if (ordercode != "" && (stepcode == null || stepcode == "")) //宸ュ崟鍙蜂笉涓虹┖,宸ュ簭鍙蜂负绌�
                     {
                         search += "and A.wo_code=@ordercode ";
                         dynamicParams.Add("@ordercode", ordercode);
@@ -1380,7 +1545,7 @@
                     {
                         mes.code = "300";
                         mes.count = 0;
-                        mes.Message = "褰撳墠宸ュ簭浠诲姟涓嶅瓨鍦�,鏃犳晥鏉$爜!";
+                        mes.message = "褰撳墠宸ュ簭浠诲姟涓嶅瓨鍦�,鏃犳晥鏉$爜!";
                         mes.data = null;
                         return mes;
                     }
@@ -1401,36 +1566,26 @@
                     dynamicParams.Add("@partspec", partspec);
                 }
                 //鏍规嵁鏉′欢鏌ヨ宸ュ崟宸ュ簭浠诲姟(鑷埗宸ュ簭)
-                sql = @"select 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,M.partcode,M.partname,M.partspec,A.seq,A.isend,
                         S.stepcode,S.stepname,S.descr,A.plan_qty,A.good_qty,A.ng_qty,A.laborbad_qty,A.materielbad_qty,B.lm_date
                         from TK_Wrk_Step A
                         left join TK_Wrk_Man B on A.wo_code=B.wo_code
                         left join TMateriel_Info M on B.materiel_code=M.partcode
                         left join TStep S on A.step_code=S.stepcode
+                        left join TOrganization T on B.wkshp_code=T.torg_code
                         where A.status in('ALLO','START') and A.ng_qty>0  " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
-                if (data.ToList().Count > 0)
-                {
-                    mes.code = "200";
-                    mes.count = total;
-                    mes.Message = "鏌ヨ鎴愬姛!";
-                    mes.data = data.ToList();
-                    return mes;
-                }
-                else
-                {
-                    mes.code = "300";
-                    mes.count = 0;
-                    mes.Message = "鏃犲彲鎵ц鐨勭敓浜т换鍔�,浠诲姟宸插畬鎴愭垨宸插叧闂�!";
-                    mes.data = null;
-                    return mes;
-                }
+                mes.code = "200";
+                mes.count = total;
+                mes.message = "鏌ヨ鎴愬姛!";
+                mes.data = data.ToList();
+                return mes;
             }
             catch (Exception e)
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -1495,7 +1650,7 @@
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "褰撳墠宸ュ簭浠诲姟涓嶅瓨鍦�!";
+                    mes.message = "褰撳墠宸ュ簭浠诲姟涓嶅瓨鍦�!";
                     mes.data = null;
                     return mes;
                 }
@@ -1511,14 +1666,14 @@
                     list.Add("data2", dt);
                     mes.code = "200";
                     mes.count = 0;
-                    mes.Message = "鏌ヨ鎴愬姛!";
+                    mes.message = "鏌ヨ鎴愬姛!";
                     mes.data = list;
                 }
                 else
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "鏃犲彲鎵ц鐨勭敓浜т换鍔�,浠诲姟宸插畬鎴愭垨宸插叧闂�!";
+                    mes.message = "鏃犲彲鎵ц鐨勭敓浜т换鍔�,浠诲姟宸插畬鎴愭垨宸插叧闂�!";
                     mes.data = null;
                 }
             }
@@ -1526,7 +1681,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -1545,7 +1700,7 @@
                         mes = ScanStartReport.ZZEncodingSeach(wocode, stepcode);
                         break;
                     case "WX":
-                        mes = ScanStartReport.WXEncodingSeach(SelectType, stepcode, stepcode);
+                        mes = ScanStartReport.WXEncodingSeach(SelectType, wocode, stepcode);
                         break;
                     default:
                         break;
@@ -1555,7 +1710,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -1563,18 +1718,19 @@
         #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 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 taskqty, string startqty, string reportqty, List<ReportDefectList> defectobjs, string remarks, User us)
         {
             var sql = "";
             decimal ngqty = 0;
             string[] arra1 = new string[] { };
+            List<object> list0 = new List<object>();
             List<object> list = new List<object>();
             var dynamicParams = new DynamicParameters();
             try
             {
                 string date = DateTime.Now.ToString(); //鑾峰彇绯荤粺鏃堕棿
                 //鑾峰彇鎶ュ伐浜哄憳銆佸垎閰嶆瘮渚�
-                JArray arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(reportuser);
+                //JArray arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(reportuser);
                 //鍒ゆ柇鏄惁鏈変笉鑹暟鎹�
                 var groupedItems = defectobjs.GroupBy(item => item.defect_code) // 鎸夌紪鐮乧ode鍒嗙粍
                         .Select(group => new { defect_code = group.Key, badqty = group.Sum(item => Convert.ToDecimal(item.badqty)) }).ToList(); // 姹囨�讳笉鑹暟閲�
@@ -1594,22 +1750,36 @@
                 dynamicParams.Add("@step_code", stepcode);
                 dynamicParams.Add("@eqpcode", eqpcode);
                 var data0 = DapperHelper.selectdata(sql, dynamicParams);
-                if (data0.Rows.Count <= 0) 
+                if (data0.Rows.Count <= 0)
                 {
                     //鍐欏叆寮�鎶ュ伐璁板綍琛�
                     sql = @"insert into  TK_Wrk_Record(wo_code,step_seq,step_code,step_price,eqp_code,materiel_code,open_person,open_time,task_qty,start_qty,style,lm_user,lm_date) 
                                 values(@mesordercode,@stepseq,@stepcode,@step_price,@eqpcode,@partcode,@username,@opentime,@taskqty,@startqty,@style,@lm_user,@lm_date)";
-                    list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, step_price=stepprice, eqpcode = eqpcode, partcode = partcode, username = us.usercode, opentime = date, taskqty = taskqty, startqty = startqty, style = "S", lm_user = us.usercode, lm_date = date } });
+                    list0.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, step_price = stepprice, eqpcode = eqpcode, partcode = partcode, username = us.usercode, opentime = date, taskqty = taskqty, startqty = startqty, style = "S", lm_user = us.usercode, lm_date = date } });
                     //鍥炲啓宸ュ崟宸ュ簭琛ㄧ姸鎬佷负START: 寮�宸�
                     sql = @"update TK_Wrk_Step set status='START'  where wo_code=@mesordercode and step_code=@stepcode";
-                    list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode } });
+                    list0.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode } });
 
-                    //鍥炲啓宸ュ崟宸ュ簭琛ㄧ姸鎬佷负宸插紑宸�
-                    sql = @"update TK_Wrk_Step set status='START'  where wo_code=@mesordercode and step_code=@stepcode";
-                    list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode } });
                     //鍥炲啓宸ュ崟琛ㄧ姸鎬佷负锛� 寮�宸ワ細START 
                     sql = @"update TK_Wrk_Man set status='START'  where wo_code=@mesordercode";
-                    list.Add(new { str = sql, parm = new { mesordercode = mesordercode } });
+                    list0.Add(new { str = sql, parm = new { mesordercode = mesordercode } });
+                    bool st = DapperHelper.DoTransaction(list0);
+                    if (st)
+                    {
+                        //鍐欏叆鎿嶄綔璁板綍琛�
+                        LogHelper.DbOperateLog(us.usercode, "寮�宸�", "寮�宸ヤ簡宸ュ崟:" + mesordercode + "宸ュ簭:" + stepcode, 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;
+                    }
                 }
 
                 //鍒ゆ柇鏄惁鏈夋姤宸ヨ褰�(鏈夛細淇敼 鏃狅細鏂板)
@@ -1629,7 +1799,7 @@
                 //{
                 //    mes.code = "300";
                 //    mes.count = 0;
-                //    mes.Message = "鎿嶄綔澶辫触,褰撳墠鎶ュ伐浜х嚎搴斾负锛�" + da.Rows[0]["NAME"].ToString() + "!";
+                //    mes.message = "鎿嶄綔澶辫触,褰撳墠鎶ュ伐浜х嚎搴斾负锛�" + da.Rows[0]["NAME"].ToString() + "!";
                 //    mes.data = null;
                 //    return mes;
                 //}
@@ -1642,34 +1812,30 @@
                     //鍐欏叆寮�鎶ュ伐璁板綍琛�
                     sql = @"insert into  TK_Wrk_Record(wo_code,step_seq,step_code,step_price,eqp_code,materiel_code,task_qty,start_qty,good_qty,ng_qty,style,lm_user,lm_date,inbarcode) 
                                 values(@mesordercode,@stepseq,@stepcode,@step_price,@eqpcode,@partcode,@taskqty,@startqty,@reportqty,@ngqty,@style,@lm_user,@lm_date,@inbarcode)";
-                    list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, step_price=stepprice, eqpcode = eqpcode, partcode = partcode, taskqty = taskqty, startqty = startqty, reportqty = reportqty, ngqty = ngqty, style = "B", lm_user = us.usercode, lm_date = date, inbarcode = inbarcode } });
+                    list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, step_price = stepprice, eqpcode = eqpcode, partcode = partcode, taskqty = taskqty, startqty = startqty, reportqty = reportqty, ngqty = ngqty, style = "B", lm_user = us.usercode, lm_date = date, inbarcode = inbarcode } });
 
                     //鍐欏叆瀛愯〃
-                    for (int i = 0; i < arra.Count; i++)
-                    {
-                        sql = @"insert into  TK_Wrk_RecordSub(m_id,eqp_code,report_person,report_date,report_qty,reckway,usergroup_code,ratio,ng_qty,style,lm_user,lm_date) 
+                    sql = @"insert into  TK_Wrk_RecordSub(m_id,eqp_code,report_person,report_date,report_qty,reckway,usergroup_code,ratio,ng_qty,style,lm_user,lm_date) 
                                 values(@m_id,@eqp_code,@report_person,@report_date,@report_qty,@reckway,@usergroup_code,@ratio,@ng_qty,@style,@lm_user,@lm_date)";
-                        list.Add(new
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
                         {
-                            str = sql,
-                            parm = new
-                            {
-                                m_id = int.Parse(dt.Rows[0]["ID"].ToString()),
-                                eqp_code = eqpcode,
-                                report_person = arra[i]["usercode"].ToString(),
-                                report_date = date,
-                                report_qty = reportqty,
-                                reckway = reckway,
-                                usergroup_code = usergroupcode,
-                                ratio = decimal.Parse(arra[i]["ratio"].ToString()),
-                                ng_qty = ngqty,
-                                style = "B",
-                                lm_user = us.usercode,
-                                lm_date = date
-                            }
-                        });
-
-                    }
+                            m_id = int.Parse(dt.Rows[0]["ID"].ToString()),
+                            eqp_code = eqpcode,
+                            report_person = reportuser,
+                            report_date = date,
+                            report_qty = reportqty,
+                            reckway = reckway,
+                            usergroup_code = usergroupcode,
+                            ratio = 0, //鍒嗛厤姣斾緥
+                            ng_qty = ngqty,
+                            style = "B",
+                            lm_user = us.usercode,
+                            lm_date = date
+                        }
+                    });
                     if (groupedItems.Count > 0)
                     {
                         //鍐欏叆缂洪櫡璁板綍琛�
@@ -1690,34 +1856,30 @@
                     //鍐欏叆寮�鎶ュ伐璁板綍琛�
                     sql = @"insert into  TK_Wrk_Record(wo_code,step_seq,step_code,step_price,eqp_code,materiel_code,task_qty,start_qty,good_qty,ng_qty,style,lm_user,lm_date,inbarcode) 
                                 values(@mesordercode,@stepseq,@stepcode,@step_price,@eqpcode,@partcode,@taskqty,@startqty,@reportqty,@ngqty,@style,@lm_user,@lm_date,@inbarcode)";
-                    list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, step_price=stepprice, eqpcode = eqpcode, partcode = partcode, taskqty = taskqty, startqty = startqty, reportqty = reportqty, ngqty = ngqty, style = "B", lm_user = us.usercode, lm_date = date, inbarcode = inbarcode } });
+                    list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, step_price = stepprice, eqpcode = eqpcode, partcode = partcode, taskqty = taskqty, startqty = startqty, reportqty = reportqty, ngqty = ngqty, style = "B", lm_user = us.usercode, lm_date = date, inbarcode = inbarcode } });
 
                     //鍐欏叆瀛愯〃
-                    for (int i = 0; i < arra.Count; i++)
-                    {
-                        sql = @"insert into  TK_Wrk_RecordSub(m_id,eqp_code,report_person,report_date,report_qty,reckway,usergroup_code,ratio,ng_qty,style,lm_user,lm_date) 
+                    sql = @"insert into  TK_Wrk_RecordSub(m_id,eqp_code,report_person,report_date,report_qty,reckway,usergroup_code,ratio,ng_qty,style,lm_user,lm_date) 
                                 values(@m_id,@eqp_code,@report_person,@report_date,@report_qty,@reckway,@usergroup_code,@ratio,@ng_qty,@style,@lm_user,@lm_date)";
-                        list.Add(new
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
                         {
-                            str = sql,
-                            parm = new
-                            {
-                                m_id = int.Parse(dt.Rows[0]["ID"].ToString()),
-                                eqp_code = eqpcode,
-                                report_person = arra[i]["usercode"].ToString(),
-                                report_date = date,
-                                report_qty = reportqty,
-                                reckway = reckway,
-                                usergroup_code = usergroupcode,
-                                ratio = decimal.Parse(arra[i]["ratio"].ToString()),
-                                ng_qty = ngqty,
-                                style = "B",
-                                lm_user = us.usercode,
-                                lm_date = date
-                            }
-                        });
-
-                    }
+                            m_id = int.Parse(dt.Rows[0]["ID"].ToString()),
+                            eqp_code = eqpcode,
+                            report_person = reportuser,
+                            report_date = date,
+                            report_qty = reportqty,
+                            reckway = reckway,
+                            usergroup_code = usergroupcode,
+                            ratio = 0, //鍒嗛厤姣斾緥
+                            ng_qty = ngqty,
+                            style = "B",
+                            lm_user = us.usercode,
+                            lm_date = date
+                        }
+                    });
                     if (groupedItems.Count > 0)
                     {
                         //鍐欏叆缂洪櫡璁板綍琛�
@@ -1747,16 +1909,18 @@
                 bool aa = DapperHelper.DoTransaction(list);
                 if (aa)
                 {
+                    //鍐欏叆鎿嶄綔璁板綍琛�
+                    LogHelper.DbOperateLog(us.usercode, "鎶ュ伐", "鎶ュ伐浜嗗伐鍗�:" + mesordercode + "宸ュ簭:" + stepcode, us.usertype);
                     mes.code = "200";
                     mes.count = 0;
-                    mes.Message = "鎿嶄綔鎴愬姛!";
+                    mes.message = "鎿嶄綔鎴愬姛!";
                     mes.data = null;
                 }
                 else
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "鎿嶄綔澶辫触!";
+                    mes.message = "鎿嶄綔澶辫触!";
                     mes.data = null;
                 }
             }
@@ -1764,7 +1928,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -1792,7 +1956,7 @@
                     //淇敼鍙戞枡璁板綍
                     sql = @"update TK_Wrk_OutRecord set fqty=fqty+@fqty,lm_user=@username,lm_date=@CreateDate
                              where wo_code=@mesordercode and step_code=@stepcode and wx_code=@wx_code and style='F'";
-                    list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode, wx_code = wxcode, fqty = decimal.Parse(fqty), username =us.usercode, CreateDate = date } });
+                    list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode, wx_code = wxcode, fqty = decimal.Parse(fqty), username = us.usercode, CreateDate = date } });
                     //鍐欏叆瀛愯〃
                     sql = @"insert into  TK_Wrk_OutRecordSub(m_id,wx_code,out_person,out_time,fqty,style,lm_user,lm_date) 
                                 values(@m_id,@wx_code,@out_person,@out_time,@fqty,@style,@lm_user,@lm_date)";
@@ -1824,16 +1988,18 @@
                 bool aa = DapperHelper.DoTransaction(list);
                 if (aa)
                 {
+                    //鍐欏叆鎿嶄綔璁板綍琛�
+                    LogHelper.DbOperateLog(us.usercode, "澶栧崗鍙戞枡", "澶栧崗鍙戞枡宸ュ崟:" + mesordercode + "宸ュ簭:" + stepcode, us.usertype);
                     mes.code = "200";
                     mes.count = 0;
-                    mes.Message = "鍙戞枡鎴愬姛!";
+                    mes.message = "鍙戞枡鎴愬姛!";
                     mes.data = null;
                 }
                 else
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "鍙戞枡澶辫触!";
+                    mes.message = "鍙戞枡澶辫触!";
                     mes.data = null;
                 }
             }
@@ -1841,7 +2007,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -1899,7 +2065,7 @@
                     string wxstring = (string.Join(",", dr.Select(x => x.ToString()).ToArray()));
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡澶栧崗渚涙柟涓庡彂鏂欏鍗忎緵搴斿晢涓嶅尮閰�,搴斾负锛氥��" + wxstring + "銆�!";
+                    mes.message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡澶栧崗渚涙柟涓庡彂鏂欏鍗忎緵搴斿晢涓嶅尮閰�,搴斾负锛氥��" + wxstring + "銆�!";
                     mes.data = null;
                     return mes;
                 }
@@ -1907,7 +2073,7 @@
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡鏁伴噺+涓嶈壇鏁伴噺,涓嶈兘澶т簬鍙戞枡鏁伴噺:" + da.Rows[0]["FQTY"].ToString() + "!";
+                    mes.message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡鏁伴噺+涓嶈壇鏁伴噺,涓嶈兘澶т簬鍙戞枡鏁伴噺:" + da.Rows[0]["FQTY"].ToString() + "!";
                     mes.data = null;
                     return mes;
                 }
@@ -1915,7 +2081,7 @@
                 //{
                 //    mes.code = "300";
                 //    mes.count = 0;
-                //    mes.Message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡澶栧崗渚涙柟搴斾负锛�" + da.Rows[0]["NAME"].ToString() + "!";
+                //    mes.message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡澶栧崗渚涙柟搴斾负锛�" + da.Rows[0]["NAME"].ToString() + "!";
                 //    mes.data = null;
                 //    return mes;
                 //}
@@ -1927,7 +2093,7 @@
                     {
                         mes.code = "300";
                         mes.count = 0;
-                        mes.Message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡鏁伴噺+涓嶈壇鏁伴噺,涓嶈兘澶т簬寰呮敹鏁伴噺:" + (sum_fqty - sum_sqty) + "!";
+                        mes.message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡鏁伴噺+涓嶈壇鏁伴噺,涓嶈兘澶т簬寰呮敹鏁伴噺:" + (sum_fqty - sum_sqty) + "!";
                         mes.data = null;
                         return mes;
                     }
@@ -2001,16 +2167,18 @@
                 bool aa = DapperHelper.DoTransaction(list);
                 if (aa)
                 {
+                    //鍐欏叆鎿嶄綔璁板綍琛�
+                    LogHelper.DbOperateLog(us.usercode, "澶栧崗鏀舵枡", "澶栧崗鏀舵枡宸ュ崟:" + mesordercode + "宸ュ簭:" + stepcode, us.usertype);
                     mes.code = "200";
                     mes.count = 0;
-                    mes.Message = "鏀舵垚鍔�!";
+                    mes.message = "鏀舵垚鍔�!";
                     mes.data = null;
                 }
                 else
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "鏀舵枡澶辫触!";
+                    mes.message = "鏀舵枡澶辫触!";
                     mes.data = null;
                 }
             }
@@ -2018,7 +2186,7 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
                 mes.data = null;
             }
             return mes;
@@ -2032,7 +2200,7 @@
             string[] arra1 = new string[] { };
             List<object> list = new List<object>();
             var dynamicParams = new DynamicParameters();
-            decimal sumrepair_qty = 0, sumlaborbad_qty = 0,summaterielbad_qty=0;  //绱缁翠慨鏁伴噺銆佺疮璁″伐搴熸暟閲忋�佺疮璁℃枡搴熸暟閲�
+            decimal sumrepair_qty = 0, sumlaborbad_qty = 0, summaterielbad_qty = 0;  //绱缁翠慨鏁伴噺銆佺疮璁″伐搴熸暟閲忋�佺疮璁℃枡搴熸暟閲�
             try
             {
                 string date = DateTime.Now.ToString(); //鑾峰彇绯荤粺鏃堕棿
@@ -2076,7 +2244,7 @@
                             }
                         });
                         //鍥炲啓缂洪櫡璁板綍琛ㄧ殑寰呭鐞嗘暟閲�
-                        sql = @"update CSR_WorkRecord_Defect set defect_pendqty=defect_pendqty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
+                        sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty-@repair_qty-@laborbad_qty-@materielbad_qty, defect_pendqty=defect_pendqty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
                         where wo_code=@wo_code and step_code=@step_code and id=@id and style='B'";
                         list.Add(new
                         {
@@ -2091,28 +2259,56 @@
                                 id = int.Parse(json.Data.Rows[i]["ID"].ToString())
                             }
                         });
-                        //鍐欏叆鎶ュ伐缂洪櫡澶勭悊璁板綍琛�
-                        sql = @"insert into  CSR_WorkRecord_DefectHandle(defect_id,wo_code,partnumber,step_seq,step_code,repair_qty,laborbad_qty,materielbad_qty,defect_code,style,lm_user,lm_date) 
-                                values(@defect_id,@wo_code,@partcode,@stepseq,@stepcode,@repair_qty,@laborbad_qty,@materielbad_qty,@defect_code,@style,@lm_user,@lm_date)";
-                        list.Add(new
+                        //鍒ゆ柇缂洪櫡璁板綍澶勭悊琛ㄦ槸鍚﹀瓨鍦ㄨ褰�
+                        sql = @"select *  from CSR_WorkRecord_DefectHandle where wo_code=@wo_code and step_code=@step_code and  defect_id=@defect_id";
+                        dynamicParams.Add("@wo_code", json.Data.Rows[i]["WO_CODE"].ToString());
+                        dynamicParams.Add("@step_code", json.Data.Rows[i]["STEP_CODE"].ToString());
+                        dynamicParams.Add("@defect_id", json.Data.Rows[i]["ID"].ToString());
+                        var data = DapperHelper.selectdata(sql, dynamicParams);
+                        if (data.Rows.Count <= 0)
                         {
-                            str = sql,
-                            parm = new
+                            //鍐欏叆鎶ュ伐缂洪櫡澶勭悊璁板綍琛�
+                            sql = @"insert into  CSR_WorkRecord_DefectHandle(defect_id,wo_code,partnumber,step_seq,step_code,repair_qty,laborbad_qty,materielbad_qty,defect_code,style,lm_user,lm_date) 
+                                values(@defect_id,@wo_code,@partcode,@stepseq,@stepcode,@repair_qty,@laborbad_qty,@materielbad_qty,@defect_code,@style,@lm_user,@lm_date)";
+                            list.Add(new
                             {
-                                defect_id = int.Parse(json.Data.Rows[i]["ID"].ToString()),
-                                wo_code = json.Data.Rows[i]["WO_CODE"].ToString(),
-                                partcode = json.Data.Rows[i]["MATERIEL_CODE"].ToString(),
-                                stepseq = json.Data.Rows[i]["SEQ"].ToString(),
-                                stepcode = json.Data.Rows[i]["STEP_CODE"].ToString(),
-                                repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()),
-                                laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()),
-                                materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()),
-                                defect_code = json.Data.Rows[i]["DEFECT_CODE"].ToString(),
-                                style = "B",
-                                lm_user = us.usercode,
-                                lm_date = date
-                            }
-                        });
+                                str = sql,
+                                parm = new
+                                {
+                                    defect_id = int.Parse(json.Data.Rows[i]["ID"].ToString()),
+                                    wo_code = json.Data.Rows[i]["WO_CODE"].ToString(),
+                                    partcode = json.Data.Rows[i]["MATERIEL_CODE"].ToString(),
+                                    stepseq = json.Data.Rows[i]["SEQ"].ToString(),
+                                    stepcode = json.Data.Rows[i]["STEP_CODE"].ToString(),
+                                    repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()),
+                                    laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()),
+                                    materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()),
+                                    defect_code = json.Data.Rows[i]["DEFECT_CODE"].ToString(),
+                                    style = "B",
+                                    lm_user = us.usercode,
+                                    lm_date = date
+                                }
+                            });
+                        }
+                        else
+                        {
+                            //鏇存柊鎶ュ伐缂洪櫡澶勭悊璁板綍琛�
+                            sql = @"update CSR_WorkRecord_DefectHandle set repair_qty=repair_qty+@repair_qty,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";
+                            list.Add(new
+                            {
+                                str = sql,
+                                parm = new
+                                {
+                                    defect_id = int.Parse(json.Data.Rows[i]["ID"].ToString()),
+                                    wo_code = json.Data.Rows[i]["WO_CODE"].ToString(),
+                                    step_code = json.Data.Rows[i]["STEP_CODE"].ToString(),
+                                    repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()),
+                                    laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()),
+                                    materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString())
+                                }
+                            });
+                        }
 
                         sumrepair_qty = sumrepair_qty + decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString());
                         sumlaborbad_qty = sumlaborbad_qty + decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString());
@@ -2152,7 +2348,7 @@
                             }
                         });
                         //鍥炲啓缂洪櫡璁板綍琛ㄧ殑寰呭鐞嗘暟閲�
-                        sql = @"update CSR_WorkRecord_Defect set defect_pendqty=defect_pendqty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
+                        sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty-@repair_qty-@laborbad_qty-@materielbad_qty,defect_pendqty=defect_pendqty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty
                         where wo_code=@wo_code and step_code=@step_code and id=@id and style='S'";
                         list.Add(new
                         {
@@ -2167,28 +2363,56 @@
                                 id = int.Parse(json.Data.Rows[i]["ID"].ToString())
                             }
                         });
-                        //鍐欏叆鎶ュ伐缂洪櫡澶勭悊璁板綍琛�
-                        sql = @"insert into  CSR_WorkRecord_DefectHandle(defect_id,wo_code,partnumber,step_seq,step_code,repair_qty,laborbad_qty,materielbad_qty,defect_code,style,lm_user,lm_date) 
-                                values(@defect_id,@wo_code,@partcode,@stepseq,@stepcode,@repair_qty,@laborbad_qty,@materielbad_qty,@defect_code,@style,@lm_user,@lm_date)";
-                        list.Add(new
+                        //鍒ゆ柇缂洪櫡璁板綍澶勭悊琛ㄦ槸鍚﹀瓨鍦ㄨ褰�
+                        sql = @"select *  from CSR_WorkRecord_DefectHandle where wo_code=@wo_code and step_code=@step_code and  defect_id=@defect_id";
+                        dynamicParams.Add("@wo_code", json.Data.Rows[i]["WO_CODE"].ToString());
+                        dynamicParams.Add("@step_code", json.Data.Rows[i]["STEP_CODE"].ToString());
+                        dynamicParams.Add("@defect_id", json.Data.Rows[i]["ID"].ToString());
+                        var data = DapperHelper.selectdata(sql, dynamicParams);
+                        if (data.Rows.Count <= 0)
                         {
-                            str = sql,
-                            parm = new
+                            //鍐欏叆鎶ュ伐缂洪櫡澶勭悊璁板綍琛�
+                            sql = @"insert into  CSR_WorkRecord_DefectHandle(defect_id,wo_code,partnumber,step_seq,step_code,repair_qty,laborbad_qty,materielbad_qty,defect_code,style,lm_user,lm_date) 
+                                values(@defect_id,@wo_code,@partcode,@stepseq,@stepcode,@repair_qty,@laborbad_qty,@materielbad_qty,@defect_code,@style,@lm_user,@lm_date)";
+                            list.Add(new
                             {
-                                defect_id = int.Parse(json.Data.Rows[i]["ID"].ToString()),
-                                wo_code = json.Data.Rows[i]["WO_CODE"].ToString(),
-                                partcode = json.Data.Rows[i]["MATERIEL_CODE"].ToString(),
-                                stepseq = json.Data.Rows[i]["SEQ"].ToString(),
-                                stepcode = json.Data.Rows[i]["STEP_CODE"].ToString(),
-                                repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()),
-                                laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()),
-                                materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()),
-                                defect_code = json.Data.Rows[i]["DEFECT_CODE"].ToString(),
-                                style = "S",
-                                lm_user = us.usercode,
-                                lm_date = date
-                            }
-                        });
+                                str = sql,
+                                parm = new
+                                {
+                                    defect_id = int.Parse(json.Data.Rows[i]["ID"].ToString()),
+                                    wo_code = json.Data.Rows[i]["WO_CODE"].ToString(),
+                                    partcode = json.Data.Rows[i]["MATERIEL_CODE"].ToString(),
+                                    stepseq = json.Data.Rows[i]["SEQ"].ToString(),
+                                    stepcode = json.Data.Rows[i]["STEP_CODE"].ToString(),
+                                    repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()),
+                                    laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()),
+                                    materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()),
+                                    defect_code = json.Data.Rows[i]["DEFECT_CODE"].ToString(),
+                                    style = "S",
+                                    lm_user = us.usercode,
+                                    lm_date = date
+                                }
+                            });
+                        }
+                        else
+                        {
+                            //鏇存柊鎶ュ伐缂洪櫡澶勭悊璁板綍琛�
+                            sql = @"update CSR_WorkRecord_DefectHandle set repair_qty=repair_qty+@repair_qty,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";
+                            list.Add(new
+                            {
+                                str = sql,
+                                parm = new
+                                {
+                                    defect_id = int.Parse(json.Data.Rows[i]["ID"].ToString()),
+                                    wo_code = json.Data.Rows[i]["WO_CODE"].ToString(),
+                                    step_code = json.Data.Rows[i]["STEP_CODE"].ToString(),
+                                    repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()),
+                                    laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()),
+                                    materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString())
+                                }
+                            });
+                        }
                         sumrepair_qty = sumrepair_qty + decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString());
                         sumlaborbad_qty = sumlaborbad_qty + decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString());
                         summaterielbad_qty = summaterielbad_qty + decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString());
@@ -2207,22 +2431,24 @@
                         stepcode = json.Data.Rows[0]["STEP_CODE"].ToString(),
                         sumrepair_qty = sumrepair_qty,
                         sumlaborbad_qty = sumlaborbad_qty,
-                        summaterielbad_qty= summaterielbad_qty
+                        summaterielbad_qty = summaterielbad_qty
                     }
                 });
                 bool aa = DapperHelper.DoTransaction(list);
                 if (aa)
                 {
+                    //鍐欏叆鎿嶄綔璁板綍琛�
+                    LogHelper.DbOperateLog(us.usercode, "涓嶈壇澶勭悊", "宸ュ崟:" + json.Data.Rows[0]["WO_CODE"].ToString() + "宸ュ簭:" + json.Data.Rows[0]["STEP_CODE"].ToString(), us.usertype);
                     mes.code = "200";
                     mes.count = 0;
-                    mes.Message = "鎿嶄綔鎴愬姛!";
+                    mes.message = "鎿嶄綔鎴愬姛!";
                     mes.data = null;
                 }
                 else
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "鎿嶄綔澶辫触!";
+                    mes.message = "鎿嶄綔澶辫触!";
                     mes.data = null;
                 }
             }
@@ -2230,7 +2456,1109 @@
             {
                 mes.code = "300";
                 mes.count = 0;
-                mes.Message = e.Message;
+                mes.message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+
+
+        #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)
+        {
+            var dynamicParams = new DynamicParameters();
+            string search = "";
+            try
+            {
+                if (wkshopcode != "" && wkshopcode != null)
+                {
+                    search += "and AA.wkshp_code=@wkshopcode ";
+                    dynamicParams.Add("@wkshopcode", wkshopcode);
+                }
+                if (wo_code != "" && wo_code != null)
+                {
+                    search += "and AA.wo_code like '%'+@wo_code+'%' ";
+                    dynamicParams.Add("@wo_code", wo_code);
+                }
+                if (partnumber != "" && partnumber != null)
+                {
+                    search += "and AA.partnumber like '%'+@partnumber+'%' ";
+                    dynamicParams.Add("@partnumber", partnumber);
+                }
+                if (partname != "" && partname != null)
+                {
+                    search += "and AA.partname like '%'+@partname+'%' ";
+                    dynamicParams.Add("@partname", partname);
+                }
+                if (partspec != "" && partspec != null)
+                {
+                    search += "and AA.partspec like '%'+@partspec+'%' ";
+                    dynamicParams.Add("@partspec", partspec);
+                }
+                if (reportuser != "" && reportuser != null)
+                {
+                    search += "and AA.usercode like '%'+@reportuser+'%' ";
+                    dynamicParams.Add("@reportuser", reportuser);
+                }
+                if (reportdateopendate != "" && reportdateopendate != null)
+                {
+                    search += "and AA.report_date between @reportdateopendate and @reportdateclosedate ";
+                    dynamicParams.Add("@reportdateopendate", reportdateopendate + " 00:00:00");
+                    dynamicParams.Add("@reportdateclosedate", reportdateclosedate + " 23:59:59");
+                }
+
+
+                if (search == "")
+                {
+                    search = "and 1=1 ";
+                }
+                search = search.Substring(3);//鎴彇绱㈠紩2鍚庨潰鐨勫瓧绗�
+                // --------------鏌ヨ鎸囧畾鑷埗鎶ュ伐澶栧崗鏀舵枡鏁版嵁--------------
+                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,A.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
+                                    FROM TUser U
+                                    WHERE CHARINDEX(',' + U.usercode + ',', ',' + B.report_person + ',') > 0
+                                    FOR XML PATH('')), 1, 1, '') AS username,
+                            B.report_date,B.report_qty,B.ng_qty,B.laborbad_qty,B.materielbad_qty,'' as wx_code,'' as wx_name
+                            from TK_Wrk_Record A
+                            inner join TK_Wrk_RecordSub B on A.id=B.m_id
+                            left join TK_Wrk_Man M on A.wo_code=M.wo_code
+                            left join TK_Wrk_Step K on M.wo_code=K.wo_code and A.step_code=K.step_code
+                            left join TStep S on A.step_code=S.stepcode
+                            left join TMateriel_Info P on A.materiel_code=P.partcode
+                            left join TOrganization T on M.wkshp_code=T.torg_code
+                            left join TEqpInfo E on A.eqp_code=E.code
+                            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,M.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
+                                    FROM TUser U
+                                    WHERE CHARINDEX(',' + U.usercode + ',', ',' + B.in_person + ',') > 0
+                                    FOR XML PATH('')), 1, 1, '') AS username,
+                            B.in_time as report_date,B.sqty as report_qty,B.ng_qty,B.laborbad_qty,B.materielbad_qty,A.wx_code,C.name as wx_name
+                            from TK_Wrk_OutRecord A
+                            inner join TK_Wrk_OutRecordSub B on A.id = B.m_id
+                            left join TK_Wrk_Man M on A.wo_code = M.wo_code
+                            left join TK_Wrk_Step K on M.wo_code=K.wo_code and A.step_code=K.step_code
+                            left join TStep S on A.step_code = S.stepcode
+                            left join TMateriel_Info P on A.materiel_code = P.partcode
+                            left join TOrganization T on M.wkshp_code = T.torg_code
+                            left join TCustomer E on A.wx_code = E.code 
+                            left join TCustomer C on A.wx_code=C.code
+                            where A.style = 'S' and B.style = 'S' and M.status<>'CLOSED' and A.verify='N'
+                            ) as AA where" + search;
+                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
+                mes.code = "200";
+                mes.message = "鏌ヨ鎴愬姛!";
+                mes.count = total;
+                mes.data = data.ToList();
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[鐢熶骇鎵ц,鎶ュ伐璋冩暣鑾峰彇閫夊畾鎶ュ伐璁板綍鐨勪笉鑹暟鎹甝
+        public static ToMessage MesOrderStepModelSearch(string wo_code, string step_code, string step_type, string isbott, string isend, string id, string sbid)
+        {
+            var sql = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                if (step_type == "Z")
+                {
+                    sql = @"select D.id,D.record_id,D.defect_code,
+                            STUFF((SELECT ',' + F.name
+                                    FROM TDefect F
+                                    WHERE CHARINDEX(',' + F.code + ',', ',' + D.defect_code + ',') > 0
+                                    FOR XML PATH('')), 1, 1, '') AS defect_name,
+                            D.defect_qty,laborbad_qty,materielbad_qty   
+                            from CSR_WorkRecord_Defect D  
+                            where wo_code=@wo_code and step_code=@step_code and record_id=@id";
+                    dynamicParams.Add("@wo_code", wo_code);
+                    dynamicParams.Add("@step_code", step_code);
+                    dynamicParams.Add("@id", id);
+                    var data = DapperHelper.selectdata(sql, dynamicParams);
+                    mes.code = "200";
+                    mes.count = 0;
+                    mes.message = "鏌ヨ鎴愬姛!";
+                    mes.data = data;
+
+                }
+                if (step_type == "W")
+                {
+                    sql = @"select D.id,D.record_id,D.defect_code,
+                            STUFF((SELECT ',' + F.name
+                                    FROM TDefect F
+                                    WHERE CHARINDEX(',' + F.code + ',', ',' + D.defect_code + ',') > 0
+                                    FOR XML PATH('')), 1, 1, '') AS defect_name,
+                            D.defect_qty,laborbad_qty,materielbad_qty   
+                            from CSR_WorkRecord_Defect D  
+                            where wo_code=@wo_code and step_code=@step_code and record_id=@id";
+                    dynamicParams.Add("@wo_code", wo_code);
+                    dynamicParams.Add("@step_code", step_code);
+                    dynamicParams.Add("@id", id);
+                    var data = DapperHelper.selectdata(sql, dynamicParams);
+                    mes.code = "200";
+                    mes.count = 0;
+                    mes.message = "鏌ヨ鎴愬姛!";
+                    mes.data = data;
+                }
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[鐢熶骇鎵ц,鎶ュ伐璋冩暣鏁版嵁鎻愪氦]
+        public static ToMessage MesOrderStepUpdateSeave(User us, List<UpdateProductReport> json)
+        {
+            var sql = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                //鎺у埗閫昏緫锛氶閬撳伐搴忚皟鏁�-> 鏈亾宸ュ簭褰撳墠璋冩暣鎬绘暟(鍚堟牸+涓嶈壇+鎶ュ簾)+鏈亾宸ュ簭闈炲綋鍓嶆姤宸ユ�绘暟(鍚堟牸+涓嶈壇+鎶ュ簾)>浠诲姟鏁伴噺   ==涓嶈兘澶т簬浠诲姟鏁伴噺
+                //鎺у埗閫昏緫锛氶閬撳伐搴忚皟鏁�-> (鏈亾宸ュ簭褰撳墠璋冩暣鍚堟牸鏁�+鏈亾宸ュ簭闈炲綋鍓嶆姤宸ュ悎鏍兼�绘暟)<涓嬮亾宸ュ簭鎶ュ伐鎬绘暟(鍚堟牸+涓嶈壇+鎶ュ簾)   ==涓嶈兘灏忎簬涓嬮亾鎶ュ伐鎬绘暟
+                //鎺у埗閫昏緫锛氭湯閬撳伐搴忚皟鏁�-> 鏈亾宸ュ簭褰撳墠璋冩暣鎬绘暟(鍚堟牸+涓嶈壇+鎶ュ簾)+鏈亾宸ュ簭闈炲綋鍓嶆姤宸ユ�绘暟(鍚堟牸+涓嶈壇+鎶ュ簾)>涓婇亾宸ュ簭鎶ュ伐鍚堟牸鎬绘暟   ==涓嶈兘澶т簬涓婇亾宸ュ簭鎶ュ伐鍚堟牸鎬绘暟
+                //鎺у埗閫昏緫锛氫腑闂村伐搴忚皟鏁�-> 鏈亾宸ュ簭褰撳墠璋冩暣鎬绘暟(鍚堟牸+涓嶈壇+鎶ュ簾)+鏈亾宸ュ簭闈炲綋鍓嶆姤宸ユ�绘暟(鍚堟牸+涓嶈壇+鎶ュ簾)>涓婇亾宸ュ簭鎶ュ伐鍚堟牸鎬绘暟   ==涓嶈兘澶т簬涓婇亾宸ュ簭鎶ュ伐鍚堟牸鎬绘暟
+                //鎺у埗閫昏緫锛氫腑闂村伐搴忚皟鏁�-> (鏈亾宸ュ簭褰撳墠璋冩暣鍚堟牸鏁�+鏈亾宸ュ簭闈炲綋鍓嶆姤宸ュ悎鏍兼�绘暟)<涓嬮亾宸ュ簭鎶ュ伐鎬绘暟(鍚堟牸+涓嶈壇+鎶ュ簾)   ==涓嶈兘灏忎簬涓嬮亾鎶ュ伐鎬绘暟
+                string date = DateTime.Now.ToString(); //鑾峰彇绯荤粺鏃堕棿
+                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
+                                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")
+                    {
+                        //鏌ヨ褰撳墠棣栭亾鎶ュ伐宸ュ簭闈炴娆℃姤宸ワ細鎬绘姤宸ユ暟閲忋�佹�讳笉鑹暟閲忋�佹�诲伐搴熸暟閲忋�佹�绘枡搴熸暟閲�
+                        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;
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    ///////////////////////////////淇敼鎶ュ伐//////////////////////////////
+
+                    //鍥炲啓瀵瑰簲鐨勬姤宸ヨ褰曞瓙琛ㄥ悎鏍兼暟閲忋�佷笉鑹暟閲忋�佹姤搴熸暟閲�
+                    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
+                                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;
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    ///////////////////////////////淇敼鎶ュ伐//////////////////////////////
+
+                    //鍥炲啓瀵瑰簲鐨勫鍗忚褰曞瓙琛ㄦ敹鏂欐暟閲忋�佷笉鑹暟閲忋�佹姤搴熸暟閲�
+                    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
+                            }
+                        });
+                    }
+                }
+
+                bool aa = DapperHelper.DoTransaction(list);
+                if (aa)
+                {
+                    //鍐欏叆鎿嶄綔璁板綍琛�
+                    LogHelper.DbOperateLog(us.usercode, "鎶ュ伐璋冩暣", "宸ュ崟:" + json[0].wo_code + "宸ュ簭:" + json[0].step_code, 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
+
+
+
+        #region[鐢熶骇鎵ц,鎶ュ伐瀹℃牳鍒楄〃鏁版嵁鏌ヨ鎺ュ彛]
+        public static ToMessage MesOrderStepReportVerifySearch(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)
+        {
+            var dynamicParams = new DynamicParameters();
+            string search = "";
+            try
+            {
+                if (wkshopcode != "" && wkshopcode != null)
+                {
+                    search += "and AA.wkshp_code=@wkshopcode ";
+                    dynamicParams.Add("@wkshopcode", wkshopcode);
+                }
+                if (wo_code != "" && wo_code != null)
+                {
+                    search += "and AA.wo_code like '%'+@wo_code+'%' ";
+                    dynamicParams.Add("@wo_code", wo_code);
+                }
+                if (partnumber != "" && partnumber != null)
+                {
+                    search += "and AA.partnumber like '%'+@partnumber+'%' ";
+                    dynamicParams.Add("@partnumber", partnumber);
+                }
+                if (partname != "" && partname != null)
+                {
+                    search += "and AA.partname like '%'+@partname+'%' ";
+                    dynamicParams.Add("@partname", partname);
+                }
+                if (partspec != "" && partspec != null)
+                {
+                    search += "and AA.partspec like '%'+@partspec+'%' ";
+                    dynamicParams.Add("@partspec", partspec);
+                }
+                if (stepname != "" && stepname != null)
+                {
+                    search += "and AA.stepname like '%'+@stepname+'%' ";
+                    dynamicParams.Add("@stepname", stepname);
+                }
+                if (reportuser != "" && reportuser != null)
+                {
+                    search += "and AA.usercode like '%'+@reportuser+'%' ";
+                    dynamicParams.Add("@reportuser", reportuser);
+                }
+                if (reportdateopendate != "" && reportdateopendate != null)
+                {
+                    search += "and AA.report_date between @reportdateopendate and @reportdateclosedate ";
+                    dynamicParams.Add("@reportdateopendate", reportdateopendate + " 00:00:00");
+                    dynamicParams.Add("@reportdateclosedate", reportdateclosedate + " 23:59:59");
+                }
+
+
+                if (search == "")
+                {
+                    search = "and 1=1 ";
+                }
+                search = search.Substring(3);//鎴彇绱㈠紩2鍚庨潰鐨勫瓧绗�
+                // --------------鏌ヨ鎸囧畾鑷埗鎶ュ伐澶栧崗鏀舵枡鏁版嵁--------------
+                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,A.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
+                                    FROM TUser U
+                                    WHERE CHARINDEX(',' + U.usercode + ',', ',' + B.report_person + ',') > 0
+                                    FOR XML PATH('')), 1, 1, '') AS username,
+                            B.report_date,B.report_qty,B.ng_qty,B.laborbad_qty,B.materielbad_qty,'' as wx_code,'' as wx_name,A.verify
+                            from TK_Wrk_Record A
+                            inner join TK_Wrk_RecordSub B on A.id=B.m_id
+                            left join TK_Wrk_Man M on A.wo_code=M.wo_code
+                            left join TK_Wrk_Step K on M.wo_code=K.wo_code and A.step_code=K.step_code
+                            left join TStep S on A.step_code=S.stepcode
+                            left join TMateriel_Info P on A.materiel_code=P.partcode
+                            left join TOrganization T on M.wkshp_code=T.torg_code
+                            left join TEqpInfo E on A.eqp_code=E.code
+                            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,M.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
+                                    FROM TUser U
+                                    WHERE CHARINDEX(',' + U.usercode + ',', ',' + B.in_person + ',') > 0
+                                    FOR XML PATH('')), 1, 1, '') AS username,
+                            B.in_time as report_date,B.sqty as report_qty,B.ng_qty,B.laborbad_qty,B.materielbad_qty,A.wx_code,C.name as wx_name,A.verify
+                            from TK_Wrk_OutRecord A
+                            inner join TK_Wrk_OutRecordSub B on A.id = B.m_id
+                            left join TK_Wrk_Man M on A.wo_code = M.wo_code
+                            left join TK_Wrk_Step K on M.wo_code=K.wo_code and A.step_code=K.step_code
+                            left join TStep S on A.step_code = S.stepcode
+                            left join TMateriel_Info P on A.materiel_code = P.partcode
+                            left join TOrganization T on M.wkshp_code = T.torg_code
+                            left join TCustomer E on A.wx_code = E.code 
+                            left join TCustomer C on A.wx_code=C.code
+                            where A.style = 'S' and B.style = 'S' and M.status<>'CLOSED'
+                            ) as AA where" + search;
+                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
+                mes.code = "200";
+                mes.message = "鏌ヨ鎴愬姛!";
+                mes.count = total;
+                mes.data = data.ToList();
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[鐢熶骇鎵ц,鎶ュ伐瀹℃牳鏁版嵁鎻愪氦]
+        public static ToMessage MesOrderStepReportVerifySeave(User us, DataModel json)
+        {
+            var sql = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                if (json.zdata.Count > 0)
+                {
+                    //鍥炲啓鎶ュ伐璁板綍涓昏〃瀹℃牳鐘舵�併�佸鏍镐汉銆佸鏍告椂闂�
+                    sql = @"update TK_Wrk_Record set verify='Y',verifyuser=@verifyuser,verifydate=@verifydate  where id in @id";
+                    list.Add(new { str = sql, parm = new { verifyuser = us.usercode, verifydate = DateTime.Now.ToString(), id = json.zdata } });
+                    //鍥炲啓鎶ュ伐璁板綍瀛愯〃瀹℃牳鐘舵�併�佸鏍镐汉銆佸鏍告椂闂�
+                    sql = @"update TK_Wrk_RecordSub set verify='Y',verifyuser=@verifyuser,verifydate=@verifydate  where m_id in @id";
+                    list.Add(new { str = sql, parm = new { verifyuser = us.usercode, verifydate = DateTime.Now.ToString(), id = json.zdata } });
+                }
+                if (json.wdata.Count > 0)
+                {
+                    //鍥炲啓澶栧崗璁板綍涓昏〃瀹℃牳鐘舵�併�佸鏍镐汉銆佸鏍告椂闂�
+                    sql = @"update TK_Wrk_OutRecord set verify='Y',verifyuser=@verifyuser,verifydate=@verifydate  where id in @id";
+                    list.Add(new { str = sql, parm = new { verifyuser = us.usercode, verifydate = DateTime.Now.ToString(), id = json.wdata } });
+                    //鍥炲啓澶栧崗璁板綍瀛愯〃瀹℃牳鐘舵�併�佸鏍镐汉銆佸鏍告椂闂�
+                    sql = @"update TK_Wrk_OutRecordSub set verify='Y',verifyuser=@verifyuser,verifydate=@verifydate  where m_id in @id";
+                    list.Add(new { str = sql, parm = new { verifyuser = us.usercode, verifydate = DateTime.Now.ToString(), id = json.wdata } });
+                }
+                bool aa = DapperHelper.DoTransaction(list);
+                if (aa)
+                {
+                    //鍐欏叆鎿嶄綔璁板綍琛�
+                    LogHelper.DbOperateLog(us.usercode, "鎶ュ伐瀹℃牳", "鑷埗鎶ュ伐璁板綍id:" + string.Join(",", json.zdata), us.usertype);
+                    LogHelper.DbOperateLog(us.usercode, "鎶ュ伐瀹℃牳", "澶栧崗鏀舵枡璁板綍id:" + string.Join(",", json.wdata), 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;

--
Gitblit v1.9.3