From e28fd58fc8715e28db1c2ea0d225386dbd4d804b Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期一, 20 二月 2023 19:49:42 +0800
Subject: [PATCH] 工艺路线删除添加存货档案关联工艺路线控制

---
 VueWebApi/DLL/DAL/ProductModelDAL.cs |  603 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 530 insertions(+), 73 deletions(-)

diff --git a/VueWebApi/DLL/DAL/ProductModelDAL.cs b/VueWebApi/DLL/DAL/ProductModelDAL.cs
index 05b65c2..23b5cff 100644
--- a/VueWebApi/DLL/DAL/ProductModelDAL.cs
+++ b/VueWebApi/DLL/DAL/ProductModelDAL.cs
@@ -72,9 +72,10 @@
                 }
                 // --------------鏌ヨ鎸囧畾鏁版嵁--------------
                 var total = 0; //鎬绘潯鏁�
-                var sql = @"select A.id,A.code,A.name,A.dict_code as stockcode,B.name as stockname,A.lm_user,A.lm_date  
+                var sql = @"select A.id,A.code,A.name,A.dict_code as stockcode,B.name as stockname,U.username as lm_user,A.lm_date  
                             from TMateriel_Type A
                             left join T_Dict B on A.dict_code=B.code and B.dict_type='CHLX'
+                            left join TUser U on A.lm_user=U.usercode
                             where A.is_delete<>'1' " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                 mes.code = "200";
@@ -101,6 +102,17 @@
             {
                 if (operType == "Add")
                 {
+                    var sql0 = @"select *  from TMateriel_Type where code=@materialtypecode";
+                    dynamicParams.Add("@materialtypecode", materialtypecode);
+                    var data = DapperHelper.selectdata(sql0, dynamicParams);
+                    if (data.Rows.Count > 0)
+                    {
+                        mes.code = "300";
+                        mes.count = 0;
+                        mes.Message = "鎿嶄綔澶辫触,缂栫爜閲嶅!";
+                        mes.data = null;
+                        return mes;
+                    }
                     var sql = @"insert into TMateriel_Type(dict_code,code,name,lm_user,lm_date) 
                             values(@stocktypecode,@materialtypecode,@materialtypename,@username,@CreateDate)";
                     dynamicParams.Add("@stocktypecode", stocktypecode);
@@ -257,6 +269,17 @@
                 //寰幆鍐欏叆鍗曚綅琛�
                 for (int i = 0; i < json.Count; i++)
                 {
+                    var sql0 = @"select *  from TUom where code=@code";
+                    dynamicParams.Add("@code", json[i].code);
+                    var data = DapperHelper.selectdata(sql0, dynamicParams);
+                    if (data.Rows.Count > 0)
+                    {
+                        mes.code = "300";
+                        mes.count = 0;
+                        mes.Message = "鎿嶄綔澶辫触,缂栫爜閲嶅!";
+                        mes.data = null;
+                        return mes;
+                    }
                     sql = @"insert into TUom(code,name,digdect,r_ule,lm_user,lm_date) values(@code,@name,@digdect,@r_ule,@username,@CreateDate)";
                     list.Add(new
                     {
@@ -441,13 +464,14 @@
                 // --------------鏌ヨ鎸囧畾鏁版嵁--------------
                 var total = 0; //鎬绘潯鏁�
                 var sql = @"select A.id,A.partcode,A.partname,A.partspec,A.uom_code,B.name as uom_name,D.code as stocktypecode,D.name as stocktypename,
-                            C.code as materialtypecode,C.name as materialtypename,A.stck_code,T.name as stck_name,A.maxqty,A.minqty,A.lm_user,
+                            C.code as materialtypecode,C.name as materialtypename,A.stck_code,T.name as stck_name,A.maxqty,A.minqty,U.username as lm_user,A.default_route,
                             A.lm_date,A.proute_id
                             from TMateriel_Info A
                             left join TUom B on A.uom_code=B.code
                             left join TMateriel_Type C on A.materieltype_code=C.code
-                            left join T_Dict D on C.dict_code=D.code and D.dict_type='CHLX'
+                            left join T_Dict D on A.stocktype_code=D.code and D.dict_type='CHLX'
                             left join T_Sec_Stck T on A.stck_code=T.code 
+                            left join TUser U on A.lm_user=U.usercode
                             where A.is_delete<>'1' " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                 mes.code = "200";
@@ -474,13 +498,25 @@
             {
                 if (operType == "Add")
                 {
-                    var sql = @"insert into TMateriel_Info(partcode,partname,partspec,uom_code,materieltype_code,stck_code,maxqty,minqty,lm_user,lm_date) 
-                            values(@materialcode,@materialname,@materialspec,@uomcode,@materialtypecode,@warehousecode,@maxstockqty,@minstockqty,@username,@CreateDate)";
+                    var sql0 = @"select *  from TMateriel_Info where partcode=@materialcode";
+                    dynamicParams.Add("@materialcode", materialcode);
+                    var data = DapperHelper.selectdata(sql0, dynamicParams);
+                    if (data.Rows.Count > 0)
+                    {
+                        mes.code = "300";
+                        mes.count = 0;
+                        mes.Message = "鎿嶄綔澶辫触,缂栫爜閲嶅!";
+                        mes.data = null;
+                        return mes;
+                    }
+                    var sql = @"insert into TMateriel_Info(partcode,partname,partspec,uom_code,stocktype_code,materieltype_code,stck_code,maxqty,minqty,lm_user,lm_date) 
+                            values(@materialcode,@materialname,@materialspec,@uomcode,@stocktypecode,@materialtypecode,@warehousecode,@maxstockqty,@minstockqty,@username,@CreateDate)";
                     dynamicParams.Add("@materialcode", materialcode);
                     dynamicParams.Add("@materialname", materialname);
                     dynamicParams.Add("@materialspec", materialspec);
                     dynamicParams.Add("@uomcode", uomcode);
                     dynamicParams.Add("@warehousecode", warehousecode);
+                    dynamicParams.Add("@stocktypecode", stocktypecode);
                     dynamicParams.Add("@materialtypecode", materialtypecode);
                     dynamicParams.Add("@minstockqty", minstockqty);
                     dynamicParams.Add("@maxstockqty", maxstockqty);
@@ -504,13 +540,14 @@
                 }
                 if (operType == "Update")
                 {
-                    var sql = @"update TMateriel_Type set partname=@materialname,partspec=@materialspec,uom_code=@uomcode,materieltype_code=@materialtypecode,stck_code=@warehousecode,
+                    var sql = @"update TMateriel_Info set partname=@materialname,partspec=@materialspec,uom_code=@uomcode,stocktype_code=@stocktypecode,materieltype_code=@materialtypecode,stck_code=@warehousecode,
                                 maxqty=@maxstockqty,minqty=@minstockqty,lm_user=@username,lm_date=@CreateDate where id=@materialid";
                     dynamicParams.Add("@materialid", materialid);
                     dynamicParams.Add("@materialname", materialname);
                     dynamicParams.Add("@materialspec", materialspec);
                     dynamicParams.Add("@uomcode", uomcode);
                     dynamicParams.Add("@warehousecode", warehousecode);
+                    dynamicParams.Add("@stocktypecode", stocktypecode);
                     dynamicParams.Add("@materialtypecode", materialtypecode);
                     dynamicParams.Add("@minstockqty", minstockqty);
                     dynamicParams.Add("@maxstockqty", maxstockqty);
@@ -610,7 +647,7 @@
                 //鏈夋病鏈夎宸ュ崟寮曠敤
 
                 //鍒犻櫎鐗╂枡
-                sql = @"update TMateriel_Info set is_delete='1' where partcode=@materialcode";
+                sql = @"delete TMateriel_Info  where partcode=@materialcode";
                 list.Add(new { str = sql, parm = new { materialcode = materialcode } });
                 bool aa = DapperHelper.DoTransaction(list);
                 if (aa)
@@ -653,7 +690,7 @@
                           select distinct route_code  from TMateriel_Route where  materiel_code=@partcode and is_delete<>'1'
                         ) B
                         on A.code=B.route_code 
-                        where  A.is_delete='0'";
+                        where  A.is_delete='0' and A.enable='Y'";
                 dynamicParams.Add("@partcode", partcode);
                 var data = DapperHelper.selectdata(sql, dynamicParams);
                 for (int i = 0; i < data.Rows.Count; i++)
@@ -689,7 +726,7 @@
         #endregion
 
         #region[瀛樿揣妗f鍏宠仈宸ヨ壓璺嚎鎻愪氦]
-        public static ToMessage SaveInventoryFile(string partcode, string username, List<ObjectData> json)
+        public static ToMessage SaveInventoryFile(string partcode, string defaultroute_code, string username, List<ObjectData> json)
         {
             var sql = "";
             List<object> list = new List<object>();
@@ -702,7 +739,7 @@
                     sql = @"delete TMateriel_Route where materiel_code=@partcode";
                     list.Add(new { str = sql, parm = new { partcode = partcode } });
                     //鏍囪鐗╂枡琛ㄥ叧鑱斿伐鑹鸿矾绾挎爣璇�
-                    sql = @"update TMateriel_Info set proute_id='N' where partcode=@partcode";
+                    sql = @"update TMateriel_Info set proute_id='N',default_route='' where partcode=@partcode";
                     list.Add(new { str = sql, parm = new { partcode = partcode } });
                 }
                 else
@@ -727,8 +764,8 @@
                         });
                     }
                     //鏍囪鐗╂枡琛ㄥ叧鑱斿伐鑹鸿矾绾挎爣璇�
-                    sql = @"update TMateriel_Info set proute_id='Y' where partcode=@partcode";
-                    list.Add(new { str = sql, parm = new { partcode = partcode } });
+                    sql = @"update TMateriel_Info set proute_id='Y',default_route=@defaultroute_code where partcode=@partcode";
+                    list.Add(new { str = sql, parm = new { partcode = partcode, defaultroute_code = defaultroute_code } });
                 }
                 bool aa = DapperHelper.DoTransaction(list);
                 if (aa)
@@ -759,6 +796,364 @@
 
 
 
+        #region[鐗╂枡娓呭崟涓诲垪琛ㄦ煡璇
+        public static ToMessage BoIventorySelect(string parentpartcode, string parentpartname, string parentpartspec, string parttype, string status, string version, string createusername, string createopendate, string createclosedate, int startNum, int endNum, string prop, string order)
+        {
+            var dynamicParams = new DynamicParameters();
+            string search = "";
+            try
+            {
+                if (parentpartcode != "" && parentpartcode != null)
+                {
+                    search += "and M.partcode like '%'+@parentpartcode+'%' ";
+                    dynamicParams.Add("@parentpartcode", parentpartcode);
+                }
+                if (parentpartname != "" && parentpartname != null)
+                {
+                    search += "and M.partname like '%'+@parentpartname+'%' ";
+                    dynamicParams.Add("@parentpartname", parentpartname);
+                }
+                if (parentpartspec != "" && parentpartspec != null)
+                {
+                    search += "and M.partspec like '%'+@parentpartspec+'%' ";
+                    dynamicParams.Add("@parentpartspec", parentpartspec);
+                }
+                if (parttype != "" && parttype != null)
+                {
+                    search += "and M.stocktype_code=@parttype ";
+                    dynamicParams.Add("@parttype", parttype);
+                }
+                if (status != "" && status != null)
+                {
+                    search += "and A.status=@status ";
+                    dynamicParams.Add("@status", status);
+                }
+                if (version != "" && version != null)
+                {
+                    search += "and A.version like '%'+@version+'%' ";
+                    dynamicParams.Add("@version", version);
+                }
+                if (createusername != "" && createusername != null)
+                {
+                    search += "and U.username like '%'+@createusername+'%' ";
+                    dynamicParams.Add("@createusername", createusername);
+                }
+                if (createopendate != "" && createopendate != null)
+                {
+                    search += "and A.lm_date between @createopendate and @createclosedate ";
+                    dynamicParams.Add("@createopendate", createopendate + " 00:00:00");
+                    dynamicParams.Add("@createclosedate", createclosedate + " 23:59:59");
+                }
+                if (search == "")
+                {
+                    search = "and 1=1 ";
+                }
+                // --------------鏌ヨ鎸囧畾鏁版嵁--------------
+                var total = 0; //鎬绘潯鏁�
+                var sql = @"select A.id, M.partcode,M.partname,M.partspec,M.stocktype_code,D.name as stocktype_name,M.uom_code,T.name as uom_name,
+                            A.quantity,A.status,A.startdate,A.version,U.username,A.lm_date  
+                            from TBom_Main A
+                            left join  TMateriel_Info M on A.materiel_code=M.partcode
+                            left join  TUom T on M.uom_code=T.code
+                            left join  TUser U on A.lm_user=U.usercode
+                            left join  T_Dict D on M.stocktype_code=D.code 
+                            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.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 MaterielDetailedVsion(string parentpartcode)
+        {
+            string sql = "";
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                sql = @"select isnull(max(substring(version,charindex('V',version)+1,len(version)-charindex('V',version))),0)+1 as version    
+                        from TBom_Main where materiel_code=@parentpartcode";
+                dynamicParams.Add("@parentpartcode", parentpartcode);
+                var data = DapperHelper.selectdata(sql, dynamicParams);
+                if (data.Rows.Count > 0)
+                {
+                    mes.code = "200";
+                    mes.Message = "鑾峰彇鐗堟湰鍙锋垚鍔�!";
+                    mes.data = "V" + data.Rows[0]["version"].ToString();
+                }
+                else
+                {
+                    mes.code = "300";
+                    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 AddUpdateBoIventory(string bomid, string parentpartcode, string parentpartname, string parentpartspec, string status, string uomcode, string quantity, string startdate, string version, string username, string opertype, List<BomSub> objs)
+        {
+            string sql = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                if (opertype == "Add")
+                {
+                    //鑾峰彇涓昏〃鏈�澶D
+                    string sql0 = @"select ISNULL(IDENT_CURRENT('TBom_Main')+1,1) as id";
+                    var dt = DapperHelper.selecttable(sql0);
+                    //鍐欏叆BOM涓昏〃
+                    sql = @"insert into TBom_Main(materiel_code,quantity,status,version,lm_user,lm_date,startdate) 
+                            values(@materiel_code,@quantity,@status,@version,@username,@CreateDate,@startdate)";
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            materiel_code = parentpartcode,
+                            quantity = quantity,
+                            status = status,
+                            version = version,
+                            username = username,
+                            CreateDate = DateTime.Now.ToString(),
+                            startdate = startdate
+                        }
+                    });
+                    //鍐欏叆BOM瀛愯〃
+                    for (int i = 0; i < objs.Count; i++)
+                    {
+                        sql = @"insert into TBom_Deta(m_id,seq,smateriel_code,base_quantity,loss_quantity,total_quantity,pn_type) 
+                            values(@m_id,@seq,@smateriel_code,@base_quantity,@loss_quantity,@total_quantity,@pn_type)";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                m_id = dt.Rows[0]["id"].ToString(),
+                                seq = objs[i].seq.ToString(),
+                                smateriel_code = objs[i].smaterirl_code.ToString(),
+                                base_quantity = objs[i].base_quantity.ToString(),
+                                loss_quantity = objs[i].loss_quantity.ToString(),
+                                total_quantity = objs[i].total_quantity.ToString(),
+                                pn_type = objs[i].pn_type.ToString()
+                            }
+                        });
+                    }
+                    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;
+                    }
+                }
+                if (opertype == "Update")
+                {
+                    //淇敼BOM涓昏〃鍩烘湰鐢ㄩ噺銆佸惎鐢ㄧ姸鎬�
+                    sql = @"update  TBom_Main set quantity=@quantity,status=@status,lm_user=@lm_user,lm_date=@lm_date where materiel_code=@materiel_code and id=@bomid";
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            bomid = bomid,
+                            materiel_code = parentpartcode,
+                            quantity = quantity,
+                            status = status,
+                            lm_user = username,
+                            lm_date = DateTime.Now.ToString()
+                        }
+                    });
+                    //鍒犻櫎BOM瀛愯〃
+                    sql = @"delete  TBom_Deta  where m_id=@bomid";
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            bomid = bomid
+                        }
+                    });
+                    //鍐欏叆BOM瀛愯〃
+                    for (int i = 0; i < objs.Count; i++)
+                    {
+                        sql = @"insert into TBom_Deta(m_id,seq,smateriel_code,base_quantity,loss_quantity,total_quantity,pn_type) 
+                            values(@m_id,@seq,@smateriel_code,@base_quantity,@loss_quantity,@total_quantity,@pn_type)";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                m_id = bomid,
+                                seq = objs[i].seq.ToString(),
+                                smateriel_code = objs[i].smaterirl_code.ToString(),
+                                base_quantity = objs[i].base_quantity.ToString(),
+                                loss_quantity = objs[i].loss_quantity.ToString(),
+                                total_quantity = objs[i].total_quantity.ToString(),
+                                pn_type = objs[i].pn_type.ToString()
+                            }
+                        });
+                    }
+                    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 BoIventorySelectView(string bomid)
+        {
+            string sql = "";
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                //鍒ゆ柇鐗╂枡绫诲瀷鏄惁鏈夊叧鑱旂墿鏂�
+                sql = @"select materiel_code from TK_Wrk_Man   where materiel_code in (select materiel_code from TBom_Main  where id=@bomid ) and bom_id=@bomid";
+                dynamicParams.Add("@bomid", bomid);
+                var data0 = DapperHelper.selectdata(sql, dynamicParams);
+                if (data0.Rows.Count > 0)
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "褰撳墠鐗╂枡娓呭崟宸茶宸ュ崟鍏宠仈浣跨敤,涓嶅厑璁镐慨鏀�!";
+                    mes.data = null;
+                    return mes;
+                }
+                //鑾峰彇Bom瀛愯〃鏁版嵁
+                sql = @"select A.seq,B.partcode,B.partname,B.partspec,B.uom_code,T.name as uom_name,
+                         A.base_quantity,A.loss_quantity,A.total_quantity,A.pn_type   
+                         from TBom_Deta A
+                         left join TMateriel_Info B on A.smateriel_code=B.partcode
+                         left join  TUom T on  B.uom_code=T.code
+                         where A.m_id=@bomid";
+                dynamicParams.Add("@bomid", bomid);
+                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 DeleteBoIventory(string bomid)
+        {
+            var sql = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                list.Clear();
+                //鍒ゆ柇鐗╂枡绫诲瀷鏄惁鏈夊叧鑱旂墿鏂�
+                sql = @"select materiel_code from TK_Wrk_Man   where materiel_code in (select materiel_code from TBom_Main  where id=@bomid ) and bom_id=@bomid";
+                dynamicParams.Add("@bomid", bomid);
+                var data = DapperHelper.selectdata(sql, dynamicParams);
+                if (data.Rows.Count > 0)
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "褰撳墠鐗╂枡娓呭崟宸茶宸ュ崟鍏宠仈浣跨敤,涓嶅厑璁稿垹闄�!";
+                    mes.data = null;
+                }
+                else
+                {
+                    //鍒犻櫎鐗╂枡娓呭崟瀛愯〃
+                    sql = @"delete TBom_Deta where m_id=@bomid";
+                    list.Add(new { str = sql, parm = new { bomid = bomid } });
+                    //鍒犻櫎鐗╂枡娓呭崟涓昏〃
+                    sql = @"delete TBom_Main where id=@bomid";
+                    list.Add(new { str = sql, parm = new { bomid = bomid } });
+                    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 RouteSearch(string routecode, string routename, string description, string createuser, int startNum, int endNum, string prop, string order)
         {
@@ -768,22 +1163,22 @@
             {
                 if (routecode != "" && routecode != null)
                 {
-                    search += "and code like '%'+@partcode+'%' ";
+                    search += "and A.code like '%'+@routecode+'%' ";
                     dynamicParams.Add("@routecode", routecode);
                 }
                 if (routename != "" && routename != null)
                 {
-                    search += "and name like '%'+@routename+'%' ";
+                    search += "and A.name like '%'+@routename+'%' ";
                     dynamicParams.Add("@routename", routename);
                 }
                 if (description != "" && description != null)
                 {
-                    search += "and description=@description ";
+                    search += "and A.description like '%'+@description+'%' ";
                     dynamicParams.Add("@description", description);
                 }
                 if (createuser != "" && createuser != null)
                 {
-                    search += "and lm_user=@createuser ";
+                    search += "and U.username like '%'+@createuser+'%' ";
                     dynamicParams.Add("@createuser", createuser);
                 }
                 if (search == "")
@@ -792,9 +1187,9 @@
                 }
                 // --------------鏌ヨ鎸囧畾鏁版嵁--------------
                 var total = 0; //鎬绘潯鏁�
-                var sql = @"select code,name,description,enable,lm_user,lm_date  
-                            from TFlw_Rout
-                            where is_delete<>'1' " + search;
+                var sql = @"select A.id,A.code,A.name,A.description,A.enable,U.username as lm_user,A.lm_date  from TFlw_Rout A
+                            left join TUser U on A.lm_user=U.usercode
+                            where A.is_delete<>'1' " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                 mes.code = "200";
                 mes.Message = "鏌ヨ鎴愬姛!";
@@ -869,23 +1264,34 @@
             {
                 if (opertype == "Add")
                 {
+                    var sql0 = @"select *  from TFlw_Rout where code=@code";
+                    dynamicParams.Add("@code", json.code);
+                    var data = DapperHelper.selectdata(sql0, dynamicParams);
+                    if (data.Rows.Count > 0)
+                    {
+                        mes.code = "300";
+                        mes.count = 0;
+                        mes.Message = "鎿嶄綔澶辫触,缂栫爜閲嶅!";
+                        mes.data = null;
+                        return mes;
+                    }
                     //鏂板宸ヨ壓璺嚎琛�
                     sql = @"insert into TFlw_Rout(code,name,description,enable,lm_user,lm_date) values(@code,@name,@description,@enable,@lm_user,@lm_date)";
                     list.Add(new { str = sql, parm = new { code = json.code, name = json.name, description = json.description, enable = json.enable, lm_user = username, lm_date = DateTime.Now.ToString() } });
-                    string is_firststep = "N"; //鏄惁棣栭亾宸ュ簭
-                    string is_laststep = "N"; //鏄惁鏈亾宸ュ簭
                     for (int i = 0; i < json.Data.Rows.Count; i++)
                     {
+                        string is_firststep = "N"; //鏄惁棣栭亾宸ュ簭
+                        string is_laststep = "N"; //鏄惁鏈亾宸ュ簭
                         if (json.Data.Rows[i]["SEQ"].ToString() == "1")  //鏄惁棣栭亾宸ュ簭
                         {
                             is_firststep = "Y";
                         }
-                        if (Convert.ToInt32(json.Data.Rows[i]["SEQ"].ToString()) == json.Data.Rows.Count) //鏄惁鏈亾宸ュ簭
+                        else if (Convert.ToInt32(json.Data.Rows[i]["SEQ"].ToString()) == json.Data.Rows.Count) //鏄惁鏈亾宸ュ簭
                         {
                             is_laststep = "Y";
                         }
                         //鏂板宸ヨ壓璺嚎鍏宠仈宸ュ簭琛�
-                        sql = @"insert TFlw_Rtdt (rout_code,seq,step_code,first_choke,last_choke,lm_user,lm_date) values()";
+                        sql = @"insert TFlw_Rtdt (rout_code,seq,step_code,first_choke,last_choke,lm_user,lm_date) values(@rout_code,@seq,@step_code,@first_choke,@last_choke,@lm_user,@lm_date)";
                         list.Add(new { str = sql, parm = new { rout_code = json.code, seq = Convert.ToInt32(json.Data.Rows[i]["SEQ"].ToString()), step_code = json.Data.Rows[i]["STEPCODE"].ToString(), first_choke = is_firststep, last_choke = is_laststep, lm_user = username, lm_date = DateTime.Now.ToString() } });
                     }
                     bool aa = DapperHelper.DoTransaction(list);
@@ -924,6 +1330,18 @@
             var dynamicParams = new DynamicParameters();
             try
             {
+                //鍒ゆ柇宸ヨ壓璺矾绾挎槸鍚﹁瀛樿揣缁戝畾
+                sql = @"select *   from TMateriel_Route where route_code=@routecode";
+                dynamicParams.Add("@routecode", routecode);
+                var data_0 = DapperHelper.selectdata(sql, dynamicParams);
+                if (data_0.Rows.Count > 0)
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "瀛樿揣妗f宸插叧鑱斿伐鑹鸿矾绾匡紝涓嶅厑璁稿垹闄�!";
+                    mes.data = null;
+                    return mes;
+                }
                 //鍒ゆ柇宸ヨ壓璺嚎鏄惁琚伐鍗曞紩鐢�(琚紩鐢ㄥ垯涓嶈兘鍒犻櫎)
                 sql = @"select *   from TK_Wrk_Man where route_code=@routecode";
                 dynamicParams.Add("@routecode", routecode);
@@ -934,6 +1352,7 @@
                     mes.count = 0;
                     mes.Message = "宸ヨ壓璺嚎宸茶宸ュ崟寮曠敤锛屼笉鍏佽鍒犻櫎!";
                     mes.data = null;
+                    return mes;
                 }
                 else
                 {
@@ -947,6 +1366,7 @@
                         mes.count = 0;
                         mes.Message = "宸ヨ壓璺嚎宸茶缃妭鎷嶅伐浠凤紝璇峰厛鍒犻櫎璁剧疆!";
                         mes.data = null;
+                        return mes;
                     }
                     else
                     {
@@ -960,21 +1380,23 @@
                         sql = @"delete TMateriel_Route  where route_code=@routecode";
                         list.Add(new { str = sql, parm = new { routecode = routecode } });
                     }
-                }
-                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;
+                    bool aa = DapperHelper.DoTransaction(list);
+                    if (aa)
+                    {
+                        mes.code = "200";
+                        mes.count = 0;
+                        mes.Message = "鍒犻櫎鎴愬姛!";
+                        mes.data = null;
+                        return mes;
+                    }
+                    else
+                    {
+                        mes.code = "300";
+                        mes.count = 0;
+                        mes.Message = "鍒犻櫎澶辫触!";
+                        mes.data = null;
+                        return mes;
+                    }
                 }
             }
             catch (Exception e)
@@ -983,6 +1405,7 @@
                 mes.count = 0;
                 mes.Message = e.Message;
                 mes.data = null;
+                return mes;
             }
             return mes;
         }
@@ -991,14 +1414,14 @@
 
 
 
-        #region[宸ヨ壓璺嚎涓嬫媺鏌ヨ鎺ュ彛]
-        public static ToMessage RouteSearch()
+        #region[宸ュ簭涓嬫媺鏌ヨ鎺ュ彛]
+        public static ToMessage StepSelect()
         {
             string sql = "";
             try
             {
-                //鑾峰彇宸ヨ壓璺嚎鏁版嵁
-                sql = @"select code,name from TFlw_Rout where is_delete<>'1' ";
+                //鑾峰彇宸ュ簭鏁版嵁
+                sql = @"select stepcode,stepname from TStep where is_delete<>'1' and enable='Y'";
                 var data = DapperHelper.selecttable(sql);
                 mes.code = "200";
                 mes.Message = "鏌ヨ鎴愬姛!";
@@ -1024,27 +1447,27 @@
             {
                 if (stepcode != "" && stepcode != null)
                 {
-                    search += "and stepcode like '%'+@stepcode+'%' ";
+                    search += "and A.stepcode like '%'+@stepcode+'%' ";
                     dynamicParams.Add("@stepcode", stepcode);
                 }
                 if (stepname != "" && stepname != null)
                 {
-                    search += "and stepname like '%'+@stepname+'%' ";
+                    search += "and A.stepname like '%'+@stepname+'%' ";
                     dynamicParams.Add("@stepname", stepname);
                 }
                 if (enable != "" && enable != null)
                 {
-                    search += "and enable=@enable ";
+                    search += "and A.enable=@enable ";
                     dynamicParams.Add("@enable", enable);
                 }
                 if (steptypecode != "" && steptypecode != null)
                 {
-                    search += "and flwtype=@steptypecode ";
+                    search += "and A.flwtype=@steptypecode ";
                     dynamicParams.Add("@steptypecode", steptypecode);
                 }
                 if (createuser != "" && createuser != null)
                 {
-                    search += "and lm_user=@createuser ";
+                    search += "and U.username=@createuser ";
                     dynamicParams.Add("@createuser", createuser);
                 }
                 if (search == "")
@@ -1053,9 +1476,9 @@
                 }
                 // --------------鏌ヨ鎸囧畾鏁版嵁--------------
                 var total = 0; //鎬绘潯鏁�
-                var sql = @"select stepcode,stepname,flwtype,enable,descr,lm_user,lm_date,is_eqp,is_defect  
-                            from TStep
-                            where is_delete<>'1' " + search;
+                var sql = @"select A.id,A.stepcode,A.stepname,A.flwtype,A.enable,A.descr,U.username as lm_user,A.lm_date,A.is_eqp,A.is_defect  from TStep A
+                            left join TUser U on A.lm_user=U.usercode
+                            where A.is_delete<>'1' " + search;
                 var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                 mes.code = "200";
                 mes.Message = "鏌ヨ鎴愬姛!";
@@ -1077,10 +1500,23 @@
         public static ToMessage AddUpdateStep(string stepid, string stepcode, string stepname, string steptypecode, string enable, string description, string username, string operType)
         {
             var dynamicParams = new DynamicParameters();
+            List<object> list = new List<object>();
+            var sql_1 = "";
             try
             {
                 if (operType == "Add")
                 {
+                    var sql0 = @"select *  from TStep where stepcode=@stepcode";
+                    dynamicParams.Add("@stepcode", stepcode);
+                    var data = DapperHelper.selectdata(sql0, dynamicParams);
+                    if (data.Rows.Count > 0)
+                    {
+                        mes.code = "300";
+                        mes.count = 0;
+                        mes.Message = "鎿嶄綔澶辫触,缂栫爜閲嶅!";
+                        mes.data = null;
+                        return mes;
+                    }
                     var sql = @"insert into TStep(stepcode,stepname,flwtype,enable,descr,lm_user,lm_date) 
                             values(@stepcode,@stepname,@steptypecode,@enable,@description,@username,@CreateDate)";
                     dynamicParams.Add("@stepcode", stepcode);
@@ -1108,6 +1544,7 @@
                 }
                 if (operType == "Update")
                 {
+                    list.Clear();
                     //濡傛灉褰撳墠宸ュ簭浣跨敤鐘舵�佷綅N(鏈惎鐢�),闇�鍒ゆ柇褰撳墠宸ュ簭瀵瑰簲宸ヨ壓璺嚎琚紩鐢ㄧ殑宸ュ崟鏄惁鍏抽棴
                     if (enable == "N")
                     {
@@ -1125,18 +1562,31 @@
                             return mes;
                         }
                     }
+                    //褰撳墠宸ュ簭绫诲瀷涓庡叧鑱斿伐浣滅珯涓殑绫诲瀷鏄惁鍖归厤,涓嶅尮閰嶅垯娓呴櫎鍏宠仈宸ヤ綔绔欐暟鎹紝鍚屾椂娓呯悊宸ュ簭鏍�(鍏宠仈宸ヤ綔绔欐爣璇嗗瓧娈典负N)
+                    var sql_10 = @"select S.flwtype  from TFlw_Rteqp  A
+                                   inner join TStep S on A.step_code=S.stepcode
+                                   where A.step_code=@stepcode";
+                    dynamicParams.Add("@stepcode", stepcode);
+                    var data_10 = DapperHelper.selectdata(sql_10, dynamicParams);
+                    if (data_10.Rows.Count > 0)
+                    {
+                        if (data_10.Rows[0]["FLWTYPE"].ToString() != steptypecode)
+                        {
+                            //鍒犻櫎宸ュ簭鍏宠仈宸ヤ綔绔欒〃
+                            sql_1 = @"delete TFlw_Rteqp  where step_code=@stepcode";
+                            list.Add(new { str = sql_1, parm = new { stepcode = stepcode } });
+                            //淇敼宸ュ簭琛ㄥ叧鑱斿伐浣滅珯鏍囪瘑
+                            sql_1 = @"update TStep set is_eqp='N' where stepcode=@stepcode";
+                            list.Add(new { str = sql_1, parm = new { stepcode = stepcode } });
+                        }
+                    }
 
-                    var sql = @"update TStep set stepname=@stepname,flwtype=@steptypecode,enable=@enable,descr=@description,
+
+                    sql_1 = @"update TStep set stepname=@stepname,flwtype=@steptypecode,enable=@enable,descr=@description,
                                 lm_user=@username,lm_date=@CreateDate where id=@stepid";
-                    dynamicParams.Add("@stepid", stepid);
-                    dynamicParams.Add("@stepname", stepname);
-                    dynamicParams.Add("@steptypecode", steptypecode);
-                    dynamicParams.Add("@enable", enable);
-                    dynamicParams.Add("@description", description);
-                    dynamicParams.Add("@username", username);
-                    dynamicParams.Add("@CreateDate", DateTime.Now.ToString());
-                    int cont = DapperHelper.SQL(sql, dynamicParams);
-                    if (cont > 0)
+                    list.Add(new { str = sql_1, parm = new { stepid = stepid, stepname = stepname, steptypecode = steptypecode, enable = enable, description = description, username = username, CreateDate = DateTime.Now.ToString() } });
+                    bool aa = DapperHelper.DoTransaction(list);
+                    if (aa)
                     {
                         mes.code = "200";
                         mes.count = 0;
@@ -1187,16 +1637,16 @@
                 }
 
                 //鍒犻櫎璁惧鑺傛媿宸ヤ环琛�
-                sql = @"delete TPrteEqp_Stad  where stepcode=@stepcode";
+                sql = @"delete TPrteEqp_Stad  where step_code=@stepcode";
                 list.Add(new { str = sql, parm = new { stepcode = stepcode } });
                 //鍒犻櫎宸ュ簭鍏宠仈宸ヤ綔绔欒〃
                 sql = @"delete TFlw_Rteqp   where step_code=@stepcode";
                 list.Add(new { str = sql, parm = new { stepcode = stepcode } });
                 //鍒犻櫎缂洪櫡鍏宠仈宸ュ簭琛�
-                sql = @"update TDefect_Step  where step_code=@stepcode";
+                sql = @"delete TDefect_Step  where step_code=@stepcode";
                 list.Add(new { str = sql, parm = new { stepcode = stepcode } });
                 //鍒犻櫎宸ュ簭
-                sql = @"update TStep set is_delete='1' where partcode=@stepcode";
+                sql = @"update TStep set is_delete='1' where stepcode=@stepcode";
                 list.Add(new { str = sql, parm = new { stepcode = stepcode } });
                 bool aa = DapperHelper.DoTransaction(list);
                 if (aa)
@@ -1247,7 +1697,7 @@
                         select distinct A.eqp_code,B.btype  from TFlw_Rteqp A 
                         inner join TCustomer B on A.eqp_code=B.code 
                         where A.step_code=@stepcode and A.is_delete<>'1' and B.is_delete<>'1'
-                        ) B on T.code=B.eqp_code where T.btype='WX' and T.is_delete<>'1'";
+                        ) B on T.btype=B.btype where T.btype='WX' and T.is_delete<>'1'";
                 dynamicParams.Add("@stepcode", stepcode);
                 var data = DapperHelper.selectdata(sql, dynamicParams);
                 for (int i = 0; i < data.Rows.Count; i++)
@@ -1289,9 +1739,10 @@
                               left join(
                               select distinct A.eqp_code  from TFlw_Rteqp A 
                               inner join TEqpInfo B on A.eqp_code=B.code 
-                              where B.wksp_code='W001' and A.is_delete<>'1' and B.is_delete<>'1'
-                              ) B on A.code=B.eqp_code and A.is_delete<>'1'";
+                              where A.step_code=@stepcode and A.is_delete<>'1' and B.is_delete<>'1'
+                              ) B on A.code=B.eqp_code where A.wksp_code=@wkspcode and A.is_delete<>'1'";
                         dynamicParams.Add("@stepcode", stepcode);
+                        dynamicParams.Add("@wkspcode", data.Rows[i]["WKSP_CODE"].ToString());
                         var data0 = DapperHelper.selectdata(sql, dynamicParams);
                         for (int j = 0; j < data0.Rows.Count; j++)
                         {
@@ -1334,7 +1785,7 @@
                     sql = @"delete TFlw_Rteqp where step_code=@stepcode";
                     list.Add(new { str = sql, parm = new { stepcode = stepcode } });
                     //鏍囪宸ュ簭琛ㄥ叧鑱斿伐浣滅珯鏍囪瘑
-                    sql = @"update TStep is_eqp='N' where stepcode=@stepcode";
+                    sql = @"update TStep set is_eqp='N' where stepcode=@stepcode";
                     list.Add(new { str = sql, parm = new { stepcode = stepcode } });
                 }
                 else
@@ -1401,7 +1852,7 @@
                 //鑾峰彇宸ュ簭鍏宠仈缂洪櫡鏁版嵁(鍖呭惈鍏宠仈鏍囪瘑)
                 sql = @"select A.code,A.name,(case when B.defect_code is null then 'N' else 'Y' end) flag from TDefect A
                         left join(
-                        select distinct defect_code  from TDefect_Step where step_code='' and is_delete<>'1'
+                        select distinct defect_code  from TDefect_Step where step_code=@stepcode and is_delete<>'1'
                         ) B on A.code=B.defect_code";
                 dynamicParams.Add("@stepcode", stepcode);
                 var data = DapperHelper.selectdata(sql, dynamicParams);
@@ -1442,7 +1893,7 @@
                     sql = @"delete TDefect_Step where step_code=@stepcode";
                     list.Add(new { str = sql, parm = new { stepcode = stepcode } });
                     //鏍囪宸ュ簭琛ㄥ叧鑱斿伐浣滅珯鏍囪瘑
-                    sql = @"update TStep is_defect='N' where stepcode=@stepcode";
+                    sql = @"update TStep set is_defect='N' where stepcode=@stepcode";
                     list.Add(new { str = sql, parm = new { stepcode = stepcode } });
                 }
                 else
@@ -1506,8 +1957,14 @@
             string sql = "";
             try
             {
-                //鑾峰彇璁惧绫诲瀷鏁版嵁
-                sql = @"select partcode,partname,partspec from TMateriel_Info where is_delete<>'1' ";
+                //鑾峰彇鐗╂枡鏁版嵁
+                sql = @"select M.partcode,M.partname,M.partspec,M.uom_code,T.name as uom_name,
+                        M.stocktype_code,D.name as stocktype_name,M.stck_code,S.name as stck_name
+                        from TMateriel_Info M
+                        left join  TUom T on M.uom_code=T.code
+                        left join  T_Dict D on M.stocktype_code=D.code
+                        left join  T_Sec_Stck S on M.stck_code=S.code
+                        where M.is_delete<>'1' ";
                 var data = DapperHelper.selecttable(sql);
                 mes.code = "200";
                 mes.Message = "鏌ヨ鎴愬姛!";
@@ -1619,7 +2076,7 @@
             {
                 // --------------鏌ヨ鎸囧畾鏁版嵁--------------
                 var total = 0; //鎬绘潯鏁�
-                var sql = @"select C.partcode,C.partname,B.wksp_code,T.org_name as wksp_name,A.eqp_value,A.stand_value,A.cavity_qty,A.unprice  
+                var sql = @"select B.code as eqpcode,B.name as eqpname,B.wksp_code,T.org_name as wksp_name,A.eqp_value,A.stand_value,A.cavity_qty,A.unprice  
                             from (
                             select materiel_code, eqp_code,eqp_value,stand_value,cavity_qty,unprice   from TPrteEqp_Stad
                             where materiel_code=@partcode  and route_code=@routecode and step_code=@stepcode 
@@ -1661,7 +2118,7 @@
                 if (partcode != "" && partcode != null)
                 {
                     search += "and A.materiel_code=@partcode ";
-                    dynamicParams.Add("@stepcode", partcode);
+                    dynamicParams.Add("@partcode", partcode);
                 }
                 if (routecode != "" && routecode != null)
                 {

--
Gitblit v1.9.3