From adc65b06d255664c2f7b763aad04572d5a96ff46 Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期一, 27 二月 2023 13:36:45 +0800
Subject: [PATCH] 质检方案、入厂检验扫描条码、入厂检验查找检验项目接口

---
 VueWebApi/DLL/DAL/QualityManagementDAL.cs |  342 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 332 insertions(+), 10 deletions(-)

diff --git a/VueWebApi/DLL/DAL/QualityManagementDAL.cs b/VueWebApi/DLL/DAL/QualityManagementDAL.cs
index 96a995d..e32bb19 100644
--- a/VueWebApi/DLL/DAL/QualityManagementDAL.cs
+++ b/VueWebApi/DLL/DAL/QualityManagementDAL.cs
@@ -1,4 +1,5 @@
 锘縰sing Dapper;
+using Newtonsoft.Json.Linq;
 using System;
 using System.Collections.Generic;
 using System.Data;
@@ -63,7 +64,7 @@
             }
             return mes;
         }
-      
+
         #endregion
 
         #region[璐ㄩ噺绠$悊锛岀己闄峰畾涔夋柊澧炪�佺紪杈戞彁浜
@@ -267,7 +268,7 @@
                     rout.name = data.Rows[0]["NAME"].ToString();
                     rout.description = data.Rows[0]["DESCR"].ToString();
                 }
-                else 
+                else
                 {
                     mes.code = "300";
                     mes.count = 0;
@@ -393,7 +394,7 @@
                         //鏂板宸ュ簭妫�楠屾爣鍑嗗瓙琛�
                         sql = @"insert TStepCheckStandardSub (stepstaned_code,stepcheckitem_seq,stepcheckitem_code,stepcheckitem_desc,lm_user,lm_date) 
                                 values(@stepstaned_code,@stepcheckitem_seq,@stepcheckitem_code,@stepcheckitem_desc,@lm_user,@lm_date)";
-                        list.Add(new { str = sql, parm = new { stepstaned_code = json.code, stepcheckitem_seq = Convert.ToInt32(json.Data.Rows[i]["STEPCHECKITEM_SEQ"].ToString()), stepcheckitem_code = json.Data.Rows[i]["STEPCHECKITEM_CODE"].ToString(), stepcheckitem_desc= json.Data.Rows[i]["STEPCHECKITEM_DESC"].ToString(), lm_user = username, lm_date = DateTime.Now.ToString() } });
+                        list.Add(new { str = sql, parm = new { stepstaned_code = json.code, stepcheckitem_seq = Convert.ToInt32(json.Data.Rows[i]["STEPCHECKITEM_SEQ"].ToString()), stepcheckitem_code = json.Data.Rows[i]["STEPCHECKITEM_CODE"].ToString(), stepcheckitem_desc = json.Data.Rows[i]["STEPCHECKITEM_DESC"].ToString(), lm_user = username, lm_date = DateTime.Now.ToString() } });
                     }
                     bool aa = DapperHelper.DoTransaction(list);
                     if (aa)
@@ -411,14 +412,14 @@
                         mes.data = null;
                     }
                 }
-                if (opertype == "Update") 
+                if (opertype == "Update")
                 {
                     //鍒犻櫎宸ュ簭妫�楠屾爣鍑嗗瓙琛�
                     sql = @"delete from TStepCheckStandardSub where stepstaned_code=@stepstaned_code";
-                    list.Add(new { str = sql, parm = new { stepstaned_code = json.code} });
+                    list.Add(new { str = sql, parm = new { stepstaned_code = json.code } });
                     //淇敼宸ュ簭妫�楠屾爣鍑嗕富琛�
                     sql = @"update  TStepCheckStandard set name=@stepstaned_name,descr=@stepstaned_desc where code=@stepstaned_code";
-                    list.Add(new { str = sql, parm = new { stepstaned_code=json.code, stepstaned_name = json.name, stepstaned_desc=json.description } });
+                    list.Add(new { str = sql, parm = new { stepstaned_code = json.code, stepstaned_name = json.name, stepstaned_desc = json.description } });
                     //鏂板宸ュ簭妫�楠屾爣鍑嗗瓙琛�
                     for (int i = 0; i < json.Data.Rows.Count; i++)
                     {
@@ -652,7 +653,7 @@
                 }
                 if (partcode != "" && partcode != null)
                 {
-                    search += "and A.partcode like '%'+@stanedname+'%' ";
+                    search += "and A.partcode like '%'+@partcode+'%' ";
                     dynamicParams.Add("@partcode", partcode);
                 }
                 if (partname != "" && partname != null)
@@ -692,13 +693,13 @@
                 search = search.Substring(3);//鎴彇绱㈠紩2鍚庨潰鐨勫瓧绗�
                 // --------------鏌ヨ鎸囧畾鏁版嵁--------------
                 var total = 0; //鎬绘潯鏁�
-                var sql = @"select A.wo_code,A.partcode,B.partname,B.partspec,A.step_code,S.stepname,A.checkstaned_code,T.name as checkstaned_name,A.check_user,
+                var sql = @"select A.id,A.wo_code,A.partcode,B.partname,B.partspec,A.step_code,S.stepname,A.checkstaned_code,T.name as checkstaned_name,A.check_user,
                             A.check_type,A.check_result,A.check_descr,A.check_qty,U.username as lm_user,A.lm_date   
                             from TStepCheckRecord A
                             left join TMateriel_Info B on A.partcode=B.partcode
                             left join TStep S on A.step_code=S.stepcode
                             left join TStepCheckStandard T on A.checkstaned_code=T.code
-                            left join TUser U on A.lm_user=U.usercode 
+                            left join TUser U on A.check_user=U.usercode 
                             where " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                 mes.code = "200";
@@ -849,7 +850,7 @@
                             left join TUser U on A.check_user=U.usercode  
                             where " + search;
                 DataTable data = DapperHelper.selectdata(sql, dynamicParams);
-                data.TableName ="Table"; //璁剧疆DataTable鐨勫悕绉�
+                data.TableName = "Table"; //璁剧疆DataTable鐨勫悕绉�
                 string msg = DownLoad.DataTableToExcel(data, "宸ュ簭妫�楠岃褰�");
                 mes.code = "200";
                 mes.Message = "鏌ヨ鎴愬姛!";
@@ -866,5 +867,326 @@
             return mes;
         }
         #endregion
+
+
+
+        #region[璐ㄦ鏂规鍒楄〃鏌ヨ]
+        public static ToMessage QualityInspectionSearch(string qualityinsptcode, string qualityinsptname, string status, string checktype, string sampltype, string suitobject, int startNum, int endNum, string prop, string order)
+        {
+            var dynamicParams = new DynamicParameters();
+            string search = "";
+            try
+            {
+                if (qualityinsptcode != "" && qualityinsptcode != null)
+                {
+                    search += "and AA.code like '%'+@qualityinsptcode+'%' ";
+                    dynamicParams.Add("@qualityinsptcode", qualityinsptcode);
+                }
+                if (qualityinsptname != "" && qualityinsptname != null)
+                {
+                    search += "and AA.name like '%'+@qualityinsptname+'%' ";
+                    dynamicParams.Add("@qualityinsptname", qualityinsptname);
+                }
+                if (status != "" && status != null)
+                {
+                    search += "and AA.status=@status ";
+                    dynamicParams.Add("@status", status);
+                }
+                if (checktype != "" && checktype != null)
+                {
+                    search += "and AA.checktype=@checktype ";
+                    dynamicParams.Add("@checktype", checktype);
+                }
+                if (sampltype != "" && sampltype != null)
+                {
+                    search += "and AA.sampmethod=@sampltype ";
+                    dynamicParams.Add("@sampltype", sampltype);
+                }
+                if (suitobject != "" && suitobject != null)
+                {
+                    search += "and AA.suitobject=@suitobject ";
+                    dynamicParams.Add("@suitobject", suitobject);
+                }
+                if (search == "")
+                {
+                    search = "and 1=1 ";
+                }
+                search = search.Substring(3);//鎴彇绱㈠紩2鍚庨潰鐨勫瓧绗�
+                // --------------鏌ヨ鎸囧畾鏁版嵁--------------
+                var total = 0; //鎬绘潯鏁�
+                var sql = @"select *  from(
+                            select code,name,status,checktype,sampmethod,sampscare,suitobject,descr,suitpart, 
+                            case when suitobject='P' then
+                            STUFF(( SELECT ';' + partname
+                            FROM TMateriel_Info
+                            where   PATINDEX('%;' + RTRIM(TMateriel_Info.partcode) + ';%',';' + TStepCheckStandard.suitpart + ';')>0    
+                            FOR XML PATH('')), 1, 1,'')  
+                            when suitobject='PY' 
+                            then 
+                            STUFF(( SELECT ';' + name
+                            FROM T_Dict
+                            where   PATINDEX('%;' + RTRIM(T_Dict.code) + ';%',';' + TStepCheckStandard.suitpart + ';')>0    
+                            FOR XML PATH('')), 1, 1,'')
+                            end as suitpartname
+                            from TStepCheckStandard
+                            ) 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 QualityInspectionSeeEdit(string qualityinsptcode)
+        {
+            string sql = "";
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                sql = @"select A.stepcheckitem_seq,A.stepcheckitem_code,B.name as stepcheckitem_name,A.required,
+                        A.numberjudge,A.unit,A.decimal,A.standvalue,A.uppervalue,A.lowervalue  
+                        from TStepCheckStandardSub A
+                        inner join TStepCheckItem B on A.stepcheckitem_code=B.code
+                        where A.stepstaned_code=@qualityinsptcode";
+                dynamicParams.Add("@qualityinsptcode", qualityinsptcode);
+                var data = DapperHelper.selectdata(sql, dynamicParams);
+
+                mes.code = "200";
+                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 QualityInspectionAddEditSave(string qualityinsptcode, string qualityinsptname, string status, string checktype, string sampmethod, string sampscare, string suitobject, string suitpart, string descr, string checkitem, string type, string username)
+        {
+            var sql = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                string date = DateTime.Now.ToString(); //鑾峰彇绯荤粺鏃堕棿
+                //鑾峰彇璐ㄦ鍒楄〃妫�楠岄」鐩暟鎹�
+                JArray arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(checkitem);
+                list.Clear();
+                switch (type)
+                {
+                    case "Add": //鏂板
+                        //鍐欏叆璐ㄦ鏂规涓昏〃
+                        sql = @"insert into  TStepCheckStandard(code,name,status,checktype,sampmethod,sampscare,suitobject,suitpart,descr,lm_user,lm_date) 
+                                values(@code,@name,@status,@checktype,@sampmethod,@sampscare,@suitobject,@suitpart,@descr,@lm_user,@lm_date)";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                code = qualityinsptcode,
+                                name = qualityinsptname,
+                                status = status,
+                                checktype = checktype,
+                                sampmethod = sampmethod,
+                                sampscare = sampscare,
+                                suitobject = suitobject,
+                                suitpart = suitpart,
+                                descr = descr,
+                                lm_user = username,
+                                lm_date = date
+                            }
+                        });
+                        //鍐欏叆璐ㄦ鏂规瀛愯〃
+                        for (int i = 0; i < arra.Count; i++)
+                        {
+                            sql = @"insert into  TStepCheckStandardSub(stepstaned_code,stepcheckitem_seq,stepcheckitem_code,required,numberjudge,unit,decimalnum,standvalue,uppervalue,lowervalue,stepcheckitem_desc,lm_user,lm_date) 
+                                values(@stepstaned_code,@stepcheckitem_seq,@stepcheckitem_code,@required,@numberjudge,@unit,@decimalnum,@standvalue,@uppervalue,@lowervalue,@stepcheckitem_desc,@lm_user,@lm_date)";
+                            list.Add(new
+                            {
+                                str = sql,
+                                parm = new
+                                {
+                                    stepstaned_code = qualityinsptcode,
+                                    stepcheckitem_seq = Convert.ToInt32(arra[i]["stepcheckitem_seq"].ToString()),
+                                    stepcheckitem_code = arra[i]["stepcheckitem_code"].ToString(),
+                                    required = arra[i]["required"].ToString(),
+                                    numberjudge = arra[i]["numberjudge"].ToString(),
+                                    unit = arra[i]["unit"].ToString(),
+                                    decimalnum = Convert.ToInt32(arra[i]["decimalnum"].ToString()),
+                                    standvalue = arra[i]["standvalue"].ToString(),
+                                    uppervalue = arra[i]["uppervalue"].ToString(),
+                                    lowervalue = arra[i]["lowervalue"].ToString(),
+                                    stepcheckitem_desc = arra[i]["stepcheckitem_desc"].ToString(),
+                                    lm_user = username,
+                                    lm_date = date
+                                }
+                            });
+                        }
+                        break;
+                    case "Update"://淇敼
+                        //鍒ゆ柇鏄惁鐢熸垚妫�楠岃褰�(鍏ュ巶妫�楠�(InCheck)  鍑哄巶妫�楠�(OutCheck)  FirstCheck锛堥妫�锛� PatroCheck(宸℃)  EndCheck(瀹屽伐妫�))
+                        sql = @"select *  from TStepCheckRecord where checkstaned_code=@qualityinsptcode and checktype=@checktype";
+                        dynamicParams.Add("@qualityinsptcode", qualityinsptcode);
+                        dynamicParams.Add("@checktype", checktype);
+                        var data = DapperHelper.selectdata(sql, dynamicParams);
+                        if (data.Rows.Count > 0) 
+                        {
+                            mes.code = "300";
+                            mes.count = 0;
+                            mes.Message = "淇敼澶辫触,褰撳墠璐ㄦ鏂规宸茬敓鎴愬搴旀楠岃褰�!";
+                            mes.data = null;
+                            return mes;
+                        }
+                        //鍒犻櫎璐ㄦ鏂规瀛愯〃
+                        sql = @"delete from TStepCheckStandardSub where stepstaned_code=@code";
+                        list.Add(new { str = sql, parm = new { code = qualityinsptcode } });
+                        //淇敼璐ㄦ鏂规涓昏〃
+                        sql = @"update TStepCheckStandard set name=@name,status=@status,checktype=@checktype,sampmethod=@sampmethod,sampscare=@sampscare,
+                                suitobject=@suitobject,suitpart=@suitpart,descr=@descr
+                                where code=@code";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                code = qualityinsptcode,
+                                name = qualityinsptname,
+                                status = status,
+                                checktype = checktype,
+                                sampmethod = sampmethod,
+                                sampscare = sampscare,
+                                suitobject = suitobject,
+                                suitpart = suitpart,
+                                descr = descr,
+                            }
+                        });
+                        //鏂板璐ㄦ鏂规瀛愯〃
+                        for (int i = 0; i < arra.Count; i++)
+                        {
+                            sql = @"insert into  TStepCheckStandardSub(stepstaned_code,stepcheckitem_seq,stepcheckitem_code,required,numberjudge,unit,decimalnum,standvalue,uppervalue,lowervalue,stepcheckitem_desc,lm_user,lm_date) 
+                                values(@stepstaned_code,@stepcheckitem_seq,@stepcheckitem_code,@required,@numberjudge,@unit,@decimalnum,@standvalue,@uppervalue,@lowervalue,@stepcheckitem_desc,@lm_user,@lm_date)";
+                            list.Add(new
+                            {
+                                str = sql,
+                                parm = new
+                                {
+                                    stepstaned_code = qualityinsptcode,
+                                    stepcheckitem_seq = Convert.ToInt32(arra[i]["stepcheckitem_seq"].ToString()),
+                                    stepcheckitem_code = arra[i]["stepcheckitem_code"].ToString(),
+                                    required = arra[i]["required"].ToString(),
+                                    numberjudge = arra[i]["numberjudge"].ToString(),
+                                    unit = arra[i]["unit"].ToString(),
+                                    decimalnum = Convert.ToInt32(arra[i]["decimalnum"].ToString()),
+                                    standvalue = arra[i]["standvalue"].ToString(),
+                                    uppervalue = arra[i]["uppervalue"].ToString(),
+                                    lowervalue = arra[i]["lowervalue"].ToString(),
+                                    stepcheckitem_desc = arra[i]["stepcheckitem_desc"].ToString(),
+                                    lm_user = username,
+                                    lm_date = date
+                                }
+                            });
+                        }
+                        break;
+                    default:
+                        break;
+                }             
+                bool aa = DapperHelper.DoTransaction(list);
+                if (aa)
+                {
+                    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 QualityInspectionDelete(string qualityinsptcode, string username)
+        {
+            var sql = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                //鍒ゆ柇鏄惁鐢熸垚妫�楠岃褰�(鍏ュ巶妫�楠�(InCheck)  鍑哄巶妫�楠�(OutCheck)  FirstCheck锛堥妫�锛� PatroCheck(宸℃)  EndCheck(瀹屽伐妫�))
+                sql = @"select *  from TStepCheckRecord where checkstaned_code=@qualityinsptcode";
+                dynamicParams.Add("@qualityinsptcode", qualityinsptcode);
+                var data = DapperHelper.selectdata(sql, dynamicParams);
+                if (data.Rows.Count > 0)
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "鍒犻櫎澶辫触,褰撳墠璐ㄦ鏂规宸茬敓鎴愬搴旀楠岃褰�!";
+                    mes.data = null;
+                    return mes;
+                }
+                //鍒犻櫎璐ㄦ鏂规涓昏〃
+                sql = @"delete TStepCheckStandard  where code=@code";
+                list.Add(new { str = sql, parm = new { code = qualityinsptcode } });
+                //鍒犻櫎璐ㄦ鏂规瀛愯〃
+                sql = @"delete TStepCheckStandardSub  where stepstaned_code=@code";
+                list.Add(new { str = sql, parm = new { code = qualityinsptcode } });
+
+                bool aa = DapperHelper.DoTransaction(list);
+                if (aa)
+                {
+                    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
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3