From c34e85eda515636993b37a752b52c0f43ae6e17b Mon Sep 17 00:00:00 2001
From: yusijie <ysj@hz-kingdee.com>
Date: 星期四, 09 一月 2025 09:17:18 +0800
Subject: [PATCH] Merge branch 'master' of http://101.37.171.70:10101/r/MES-WEB-API

---
 WebAPI/Controllers/BaseSet/Gy_MaterialController.cs | 1610 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 1,595 insertions(+), 15 deletions(-)

diff --git a/WebAPI/Controllers/BaseSet/Gy_MaterialController.cs b/WebAPI/Controllers/BaseSet/Gy_MaterialController.cs
index 7963b8a..d034440 100644
--- a/WebAPI/Controllers/BaseSet/Gy_MaterialController.cs
+++ b/WebAPI/Controllers/BaseSet/Gy_MaterialController.cs
@@ -13,6 +13,9 @@
 using System.Windows.Forms;
 using WebAPI.Models;
 using WebAPI.Service;
+using System.Text.RegularExpressions;
+using WebAPI.Controllers.SCGL.鏃ヨ鍒掔鐞�;
+using SyntacticSugar.constant;
 
 namespace WebAPI.Controllers
 {
@@ -21,7 +24,7 @@
         //鑾峰彇绯荤粺鍙傛暟
         Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
         public DBUtility.ClsPub.Enum_BillStatus BillStatus;
-
+        public string sWhere = "";
         private json objJsonResult = new json();
         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
         DataSet ds;
@@ -78,7 +81,7 @@
                     objJsonResult.data = null;
                     return objJsonResult;
                 }
-                string sql1 = string.Format(@"select * from h_v_Gy_MaterialList where 缁勭粐鍚嶇О='" + Organization + "'");
+                string sql1 = string.Format(@"select top(500) * from h_v_Gy_MaterialList where 缁勭粐鍚嶇О='" + Organization + "'");
                 if (sWhere == null || sWhere.Equals(""))
                 {
                     ds = oCN.RunProcReturn(sql1 + sWhere + " order by 鐗╂枡浠g爜 desc", "h_v_Gy_MaterialList");
@@ -113,6 +116,287 @@
                 return objJsonResult;
             }
         }
+
+        #region 鐗╂枡鍒嗛〉鍒楄〃
+        [Route("Gy_Material/page")]
+        [HttpGet]
+        public object page(string sWhere, string user, string Organization,int page,int size)
+        {
+            try
+            {
+                List<object> columnNameList = new List<object>();
+                //缂栬緫鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log_second("Gy_Material", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳煡鐪嬫潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                if (sWhere == null || sWhere.Equals(""))
+                {
+                    ds = oCN.RunProcReturn("exec h_p_Gy_MaterialList " + page + "," + size + ",'" + Organization +"'," + "''", "h_p_Gy_MaterialList");
+                }
+                else
+                {
+                    sWhere = sWhere.Replace("'", "''");
+                    ds = oCN.RunProcReturn("exec h_p_Gy_MaterialList " + page + "," + size + ",'" + Organization + "','" + sWhere + "'", "h_p_Gy_MaterialList");
+                }
+
+                //娣诲姞鍒楀悕
+                foreach (DataColumn col in ds.Tables[0].Columns)
+                {
+                    Type dataType = col.DataType;
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+                }
+
+                objJsonResult.code = "1";
+                objJsonResult.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.list = columnNameList;
+                objJsonResult.data = ds.Tables[0];
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鐗╂枡鏍规嵁鍒嗙被鑾峰彇鏈�澶х墿鏂欑紪鐮�
+        [Route("Gy_Material/getMaxNum")]
+        [HttpGet]
+        public object getMaxNum(int HMaterTypeID, string user, string Organization)
+        {
+            try
+            {
+                List<object> columnNameList = new List<object>();
+                //缂栬緫鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log_second("Gy_Material", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳煡鐪嬫潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                if (HMaterTypeID == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "娌℃湁閫夋嫨鍏蜂綋鍒嗙被锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                else
+                {
+                    ds = oCN.RunProcReturn(@"select * from h_v_Gy_MaterialList where 缁勭粐鍚嶇О='" + Organization + "'" + "and HMaterTypeID = '"+ HMaterTypeID + "'" + " order by 鐗╂枡浠g爜 desc", "h_v_Gy_MaterialList");
+                    if (ds == null || ds.Tables[0].Rows.Count == 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "娌℃湁鎵惧埌璇ュ垎绫荤殑鐗╂枡缂栫爜璇蜂娇鐢ㄦ櫘閫氭柊澧�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    string HNumber = ds.Tables[0].Rows[0]["鐗╂枡浠g爜"].ToString();
+                    // 浣跨敤姝e垯琛ㄨ揪寮忔壘鍒版暟瀛楅儴鍒�  (?<=\D)鏄竴涓浂瀹芥柇瑷�锛岃〃绀哄墠闈㈢殑瀛楃涓嶆槸鏁板瓧 (\d+)$琛ㄧず鍚庨潰璺熺潃涓�杩炰覆瀛楃涓茬煡閬撴湯灏�
+                    Match match = Regex.Match(HNumber, @"(?<=\D)(\d+)$");
+                    if (match.Success)
+                    {
+                        string prefix = HNumber.Substring(0, HNumber.Length - match.Length); // 鎻愬彇鍓嶇紑  
+                        int number = int.Parse(match.Value); // 瑙f瀽鏁板瓧  
+                        // 鏁板瓧+1  
+                        number++;
+                        // 鏍煎紡鍖栨暟瀛楋紝淇濇寔鍘熼暱搴�  
+                        string formattedNumber = number.ToString().PadLeft(match.Length, '0');
+                        // 閲嶆柊缁勫悎瀛楃涓�  
+                        string result = prefix + formattedNumber;
+
+                        objJsonResult.code = "1";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "success";
+                        objJsonResult.data = result;
+                        return objJsonResult;
+                    }
+                    else
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "姝ゅ垎绫荤墿鏂欑紪鐮佹牸寮忔湁璇�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鑾峰彇鐗╂枡绮惧害閫氳繃id
+        [Route("Gy_Material/getDecByID")]
+        [HttpGet]
+        public object getDecByID(int HMaterID)
+        {
+            try
+            {
+                if(HMaterID == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "娌℃湁閫夋嫨鐗╂枡";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                ds = oCN.RunProcReturn(@"select HQtyDec,HPriceDec,HMoneyDec from Gy_Material where HitemID=" + HMaterID , "Gy_Material");
+                if (ds == null || ds.Tables[0].Rows.Count == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "娌℃湁鎵惧埌璇ョ墿鏂欑紪鐮�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Success";
+                objJsonResult.data = ds.Tables[0];
+                return objJsonResult;
+
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鑾峰彇椤圭洰鍙�
+        [Route("Gy_Material/Get_HProject")]
+        [HttpGet]
+        public object Get_HProject()
+        {
+            try
+            {
+                DataSet oDs = new DataSet();
+                //==========
+                oDs = oCN.RunProcReturn("select top(20) HInterID as HItemID,HProName HName from PM_ProjectBillMain", "PM_ProjectBillMain");
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鑾峰彇鎴愬姛锛�";
+                objJsonResult.data = oDs.Tables[0];
+                return objJsonResult; ;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鍒犻櫎澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        /// <summary>
+        /// 鑾峰彇椤圭洰鍒楄〃
+        /// </summary>
+        /// <returns></returns>
+        [Route("Gy_Material/GetProjectGroupList_Json")]
+        [HttpGet]
+        public object GetProjectGroupList_Json(string Unit)
+            { 
+                if (Unit != "" && Unit != null)
+                {
+                    sWhere = sWhere + " and ( HBillNo like '%" + Unit + "%' or HProName like '%" + Unit + "%' ) ";
+                }
+
+                try
+                {
+                    SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
+                    if (sWhere == null || sWhere.Equals(""))
+                    {
+                        ds = oCN.RunProcReturn("Select HInterID,HBillNo 椤圭洰浠g爜,HProName 椤圭洰缁� from PM_ProjectBillMain where HCloseType = 0 Order by HInterID ", "PM_ProjectBillMain");
+                    }
+                    else
+                    {
+                        string sql1 = "Select HInterID,HBillNo 椤圭洰浠g爜,HProName 椤圭洰缁� from PM_ProjectBillMain where HCloseType = 0 ";
+                        string sql = sql1 + sWhere;
+                        ds = oCN.RunProcReturn(sql, "PM_ProjectBillMain");
+                    }
+
+                if (ds == null || ds.Tables[0].Rows.Count <= 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鑾峰彇澶辫触" + DBUtility.ClsPub.sErrInfo;
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                else
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "鑾峰彇鎴愬姛!";
+                    objJsonResult.data = ds.Tables[0];
+                    return objJsonResult;
+                }
+            }
+            catch (Exception ex)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鑾峰彇澶辫触" + ex.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #region 鑾峰彇浜嬩笟閮�
+        [Route("Gy_Material/Get_Gy_Division")]
+        [HttpGet]
+        public object Get_Gy_Division(string HOrgID)
+        {
+            try
+            {
+                DataSet oDs = new DataSet();
+                //==========
+                oDs = oCN.RunProcReturn("	select HItemID,HName from Gy_Division", "Gy_Division");
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鑾峰彇鎴愬姛锛�";
+                objJsonResult.data = oDs.Tables[0];
+                return objJsonResult; ;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鍒犻櫎澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
 
         /// <summary>
         /// 鐗╂枡璁剧疆鑾峰彇淇℃伅
@@ -376,6 +660,458 @@
             }
         }
 
+        #region 鐗╂枡 鏂囦欢瀵煎叆淇濆瓨
+        #region 鐗╂枡 鏂囦欢涓婁紶
+        [Route("Gy_Material/Gy_Material_Excel")]
+        [HttpPost]
+        public object Gy_Material_Excel()
+        {
+            try
+            {
+                //鑾峰彇鏂囦欢鍚嶇О
+                var file = HttpContext.Current.Request.Files[0];
+                //鑾峰彇鏂囦欢鐗╃悊璺緞
+                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
+                //淇濆瓨鏂囦欢
+                file.SaveAs(ExcelPath);
+
+                NpoiHelper np = new NpoiHelper();
+                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
+
+                //鍒犻櫎鏂囦欢
+                File.Delete(ExcelPath);
+
+                //鍒涘缓涓存椂琛�
+                DataTable tb2 = new DataTable("dt2");
+
+                //娣诲姞鍒楀悕
+                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
+                {
+                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
+                }
+
+                //妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁
+                tb2.Columns.Add("HOrgID", typeof(Int32));//缁勭粐ID
+                tb2.Columns.Add("HMaterClsID", typeof(Int32));//鐗╂枡灞炴�D
+                tb2.Columns.Add("HUnitGroupID", typeof(Int32));//璁¢噺鍗曚綅缁処D
+                tb2.Columns.Add("HUnitID", typeof(Int32));//鍗曚綅ID
+                tb2.Columns.Add("HSecUnitID", typeof(Int32));//杈呭姪璁¢噺鍗曚綅ID
+                tb2.Columns.Add("HWhID", typeof(Int32));//榛樿浠撳簱ID
+                //娣诲姞鏁版嵁
+                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
+                {
+                    DataRow row = tb2.NewRow();
+                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
+                    {
+                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
+                    }
+                    tb2.Rows.Add(row);
+                }
+
+
+                var error = "";
+
+                //鍒ゆ柇瀵煎叆鏂囦欢鍒楁槸鍚﹀畬鏁�
+                if (!tb2.Columns.Contains("缁勭粐浠g爜"))
+                    error += "娌℃湁鎵惧埌銆愮粍缁囦唬鐮併�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("缁勭粐鍚嶇О"))
+                    error += "娌℃湁鎵惧埌銆愮粍缁囧悕绉般�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鐗╂枡鍚嶇О"))
+                    error += "娌℃湁鎵惧埌銆愮墿鏂欏悕绉般�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鐗╂枡浠g爜"))
+                    error += "娌℃湁鎵惧埌銆愮墿鏂欎唬鐮併�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("瑙勬牸鍨嬪彿"))
+                    error += "娌℃湁鎵惧埌銆愯鏍煎瀷鍙枫�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鍔╄鐮�"))
+                    error += "娌℃湁鎵惧埌銆愬姪璁扮爜銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鐗堟湰鍙�"))
+                    error += "娌℃湁鎵惧埌銆愮増鏈彿銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鐗╂枡灞炴��"))
+                    error += "娌℃湁鎵惧埌銆愮墿鏂欏睘鎬с�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("璁¢噺鍗曚綅缁�"))
+                    error += "娌℃湁鎵惧埌銆愯閲忓崟浣嶇粍銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("璁¢噺鍗曚綅浠g爜"))
+                    error += "娌℃湁鎵惧埌銆愯閲忓崟浣嶄唬鐮併�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("璁¢噺鍗曚綅"))
+                    error += "娌℃湁鎵惧埌銆愯閲忓崟浣嶃�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("杈呭姪璁¢噺鍗曚綅"))
+                    error += "娌℃湁鎵惧埌銆愯緟鍔╄閲忓崟浣嶃�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鎹㈢畻鐜�"))
+                    error += "娌℃湁鎵惧埌銆愭崲绠楃巼銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("榛樿浠撳簱"))
+                    error += "娌℃湁鎵惧埌銆愰粯璁や粨搴撱�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鏈�楂樺簱瀛�"))
+                    error += "娌℃湁鎵惧埌銆愭渶楂樺簱瀛樸�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鏈�浣庡簱瀛�"))
+                    error += "娌℃湁鎵惧埌銆愭渶浣庡簱瀛樸�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("瀹夊叏搴撳瓨"))
+                    error += "娌℃湁鎵惧埌銆愬畨鍏ㄥ簱瀛樸�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("閲囪喘鍗曚环"))
+                    error += "娌℃湁鎵惧埌銆愰噰璐崟浠枫�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("閿�鍞崟浠�"))
+                    error += "娌℃湁鎵惧埌銆愰攢鍞崟浠枫�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("璁″垝鍗曚环"))
+                    error += "娌℃湁鎵惧埌銆愯鍒掑崟浠枫�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鏍囧噯鎴愭湰"))
+                    error += "娌℃湁鎵惧埌銆愭爣鍑嗘垚鏈�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("淇濊川鏈�"))
+                    error += "娌℃湁鎵惧埌銆愪繚璐ㄦ湡銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鏈�灏忚璐ч噺"))
+                    error += "娌℃湁鎵惧埌銆愭渶灏忚璐ч噺銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鏈�澶ц璐ч噺"))
+                    error += "娌℃湁鎵惧埌銆愭渶澶ц璐ч噺銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鑻辨枃鍚嶇О"))
+                    error += "娌℃湁鎵惧埌銆愯嫳鏂囧悕绉般�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鑻辨枃瑙勬牸"))
+                    error += "娌℃湁鎵惧埌銆愯嫳鏂囪鏍笺�戠殑鏍囬,";
+
+
+                if (error.Length > 0)
+                {
+                    objJsonResult.code = CodeConstant.FAIL;
+                    objJsonResult.count = CountConstant.FAIL;
+                    objJsonResult.Message = $"Excel妯℃澘瀛樺湪閿欒,{error}\r\n";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
+                {
+                    string HMaterName = "";
+                    string HMaterNumber = "";
+                    string HORGNumber = "";
+                    string HORGName = "";
+                    string HMaterClsName = "";
+                    string HUnitGroupName = "";
+                    string HUnitNumber = "";
+                    string HUnitName = "";
+                    string HSecUnitName = "";
+                    string HWhName = "";
+
+                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐浠g爜"].ToString());
+                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐鍚嶇О"].ToString());
+                    HMaterNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐗╂枡浠g爜"].ToString());
+                    HMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐗╂枡鍚嶇О"].ToString());
+                    HMaterClsName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐗╂枡灞炴��"].ToString());
+                    HUnitGroupName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["璁¢噺鍗曚綅缁�"].ToString());
+                    HUnitNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["璁¢噺鍗曚綅浠g爜"].ToString());
+                    HUnitName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["璁¢噺鍗曚綅"].ToString());
+                    HSecUnitName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["杈呭姪璁¢噺鍗曚綅"].ToString());
+                    HWhName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["榛樿浠撳簱"].ToString());
+                    //妫�鏌ョ墿鏂�
+                    int index = i + 1;
+
+                    if (HORGNumber != "")
+                    {
+
+                        //鏌ヨ缁勭粐
+                        ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where  HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = CodeConstant.FAIL;
+                            objJsonResult.count = CountConstant.FAIL;
+                            objJsonResult.Message = "绗�" + index + "琛�,缁勭粐涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        string HORGid = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        //鏌ヨ灞炴��
+                        if (HMaterClsName == "澶栬喘")
+                        {
+                            tb2.Rows[i]["HMaterClsID"] = 1;
+                        }
+                        else if(HMaterClsName == "鑷埗")
+                        {
+                            tb2.Rows[i]["HMaterClsID"] = 2;
+                        }
+                        else if (HMaterClsName == "濮斿")
+                        {
+                            tb2.Rows[i]["HMaterClsID"] = 3;
+                        }
+                        else
+                        {
+                            objJsonResult.code = CodeConstant.FAIL;
+                            objJsonResult.count = CountConstant.FAIL;
+                            objJsonResult.Message = "绗�" + index + "琛�,鐗╂枡灞炴�т笉瀛樺湪锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        //鏌ヨ璁¢噺鍗曚綅缁�
+                        ds = oCN.RunProcReturn("select * from Gy_UnitGroup where  HName='" + HUnitGroupName + "'", "Gy_UnitGroup");
+
+                        if (ds.Tables[0].Rows.Count == 0 && HUnitGroupName != "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" +  "璁¢噺鍗曚綅缁�:" + HUnitGroupName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else if (HMaterNumber == "")
+                        {
+                            tb2.Rows[i]["HUnitGroupID"] = 0;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HUnitGroupID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        //鏌ヨ鍗曚綅
+                        ds = oCN.RunProcReturn("select * from Gy_Unit where  HNumber='" + HUnitNumber + "'  and HUSEORGID=" + HORGid + "", "Gy_Unit");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,鍗曚綅:" + HUnitName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HUnitID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        //鏌ヨ杈呭姪鍗曚綅
+                        ds = oCN.RunProcReturn("select * from Gy_Unit where  HName='" + HSecUnitName + "'  and HUSEORGID=" + HORGid + "", "Gy_Unit");
+
+                        if (ds.Tables[0].Rows.Count == 0 && HSecUnitName != "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,鍗曚綅:" + HSecUnitName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }else if (HSecUnitName == "")
+                        {
+                            tb2.Rows[i]["HSecUnitID"] = 0;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HSecUnitID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        //鏌ヨ浠撳簱
+                        ds = oCN.RunProcReturn("select * from Gy_Warehouse where  HName='" + HWhName + "'  and HUSEORGID=" + HORGid + "", "Gy_Warehouse");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,浠撳簱:" + HWhName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HWHID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        //鐗╂枡鍚嶇О
+                        if (HMaterName == "")
+                        {
+                            objJsonResult.code = CodeConstant.FAIL;
+                            objJsonResult.count = CountConstant.FAIL;
+                            objJsonResult.Message = "绗�" + index + "琛�,鐗╂枡鍚嶇О涓嶈兘涓虹┖锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                        //鐗╂枡浠g爜
+                        if (HMaterNumber == "")
+                        {
+                            objJsonResult.code = CodeConstant.FAIL;
+                            objJsonResult.count = CountConstant.FAIL;
+                            objJsonResult.Message = "绗�" + index + "琛�,鐗╂枡缂栧彿涓嶈兘涓虹┖锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+                    else
+                    {
+                        objJsonResult.code = CodeConstant.FAIL;
+                        objJsonResult.count = CountConstant.FAIL;
+                        objJsonResult.Message = "绗�" + index + "琛�,缁勭粐浠g爜涓虹┖";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+
+                objJsonResult.code = CodeConstant.SUCCEED;
+                objJsonResult.count = CountConstant.SUCCEED;
+                objJsonResult.Message = error;
+                objJsonResult.data = tb2;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = CodeConstant.FAIL;
+                objJsonResult.count = CountConstant.FAIL;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鐗╂枡椤圭洰 瀵煎叆(淇濆瓨)
+        [Route("Gy_Material/Gy_Material_btnSave")]
+        [HttpPost]
+        public object Gy_Material_btnSave([FromBody] JObject sMainSub)
+        {
+            var _value = sMainSub["sMainSub"].ToString();
+            string msg1 = _value.ToString();
+            string[] sArray = msg1.Split(new string[] { "&鍜�" }, StringSplitOptions.RemoveEmptyEntries);
+            string msg2 = sArray[0].ToString();
+            string user = sArray[1].ToString();
+            try
+            {
+                if (!DBUtility.ClsPub.Security_Log("Gy_Material_Edit", 1, false, user))
+                {
+                    objJsonResult.code = CodeConstant.FAIL;
+                    objJsonResult.count = CountConstant.FAIL;
+                    objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
+                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
+
+                foreach (JObject item in Excel)
+                {
+                    Dictionary<string, string> dic = new Dictionary<string, string>();
+                    foreach (var itm in item.Properties())
+                    {
+                        dic.Add(itm.Name, itm.Value.ToString());
+                    }
+                    list.Add(dic);
+                }
+
+                oCN.BeginTran();
+                int i = 1;
+                foreach (Dictionary<string, string> item in list)
+                {
+                    DLL.ClsGy_Material_Ctl oBill = new DLL.ClsGy_Material_Ctl();
+                    ClsGy_Material_Model oItem = new ClsGy_Material_Model();
+                    //璧嬪�煎墠绔紶鍏ョ殑
+                    oItem.HUSEORGID = int.Parse(item["HOrgID"].ToString());
+                    oItem.HNumber = item["鐗╂枡浠g爜"].ToString();
+                    oItem.HName = item["鐗╂枡鍚嶇О"].ToString();
+                    oItem.HModel = item["瑙勬牸鍨嬪彿"].ToString();
+                    oItem.HHelpCode = item["鍔╄鐮�"].ToString();
+                    oItem.HVersion = item["鐗堟湰鍙�"].ToString();
+                    oItem.HMaterClsID = int.Parse(item["HMaterClsID"].ToString());
+                    oItem.HUnitGroupID = int.Parse(item["HUnitGroupID"].ToString());
+                    oItem.HUnitID = int.Parse(item["HUnitID"].ToString());
+                    oItem.HSecUnitID = int.Parse(item["HSecUnitID"].ToString());
+                    oItem.HSecUnitRate = double.Parse(item["鎹㈢畻鐜�"].ToString()==""?"0": item["鎹㈢畻鐜�"].ToString());
+                    oItem.HWhID = int.Parse(item["HWhID"].ToString());
+                    oItem.HHighStock = int.Parse(item["鏈�楂樺簱瀛�"].ToString() == "" ? "0" : item["鏈�楂樺簱瀛�"].ToString());
+                    oItem.HLowStock = int.Parse(item["鏈�浣庡簱瀛�"].ToString() == "" ? "0" : item["鏈�浣庡簱瀛�"].ToString());
+                    oItem.HSafeStock = int.Parse(item["瀹夊叏搴撳瓨"].ToString() == "" ? "0" : item["瀹夊叏搴撳瓨"].ToString());
+                    oItem.HOrderPrice = int.Parse(item["閲囪喘鍗曚环"].ToString() == "" ? "0" : item["閲囪喘鍗曚环"].ToString());
+                    oItem.HSalePrice = int.Parse(item["閿�鍞崟浠�"].ToString() == "" ? "0" : item["閿�鍞崟浠�"].ToString());
+                    oItem.HPlanPrice = int.Parse(item["璁″垝鍗曚环"].ToString() == "" ? "0" : item["璁″垝鍗曚环"].ToString());
+                    oItem.HstdPrice = int.Parse(item["鏍囧噯鎴愭湰"].ToString() == "" ? "0" : item["鏍囧噯鎴愭湰"].ToString());
+                    oItem.HKeepDays = int.Parse(item["淇濊川鏈�"].ToString() == "" ? "0" : item["淇濊川鏈�"].ToString());
+                    oItem.HQtyMin = int.Parse(item["鏈�灏忚璐ч噺"].ToString() == "" ? "0" : item["鏈�灏忚璐ч噺"].ToString());
+                    oItem.HQtyMin = int.Parse(item["鏈�澶ц璐ч噺"].ToString() == "" ? "0" : item["鏈�澶ц璐ч噺"].ToString());
+                    oItem.HEngName = item["鑻辨枃鍚嶇О"].ToString();
+                    oItem.HEngModel = item["鑻辨枃瑙勬牸"].ToString();
+                    //甯歌璧嬪�艰祴绌哄�奸槻姝㈡姤閿�
+                    oItem.HMaterTypeID = 0;
+                    oItem.HColorRemark = "";
+                    oItem.HColorNo = "";
+                    oItem.HMaterRuleType = "";
+                    string sShortNumber;
+                    sShortNumber = DBUtility.ClsPub.GetShortNumber(oItem.HNumber.Trim());
+                    if (sShortNumber.Trim() == "")
+                    {
+                        objJsonResult.code = CodeConstant.FAIL;
+                        objJsonResult.count = CountConstant.FAIL;
+                        objJsonResult.Message = "淇濆瓨澶辫触锛佺煭浠g爜涓虹┖锛�";
+                        objJsonResult.data = 1;
+                        return objJsonResult;
+                    }
+                    oItem.HShortNumber = sShortNumber;//鐭唬鐮�
+                    oItem.HEndFlag = true;//鏈骇鏍囧織
+                    oItem.HLevel = DBUtility.ClsPub.GetLevel(oItem.HNumber.Trim()); //绛夌骇
+                    oBill.oModel = oItem;
+                    if (!DBUtility.ClsPub.AllowNumber(oItem.HNumber.Trim()))
+                    {
+                        objJsonResult.code = CodeConstant.FAIL;
+                        objJsonResult.count = CountConstant.FAIL;
+                        objJsonResult.Message = "淇濆瓨澶辫触锛佷唬鐮佷腑涓嶈兘鍑虹幇杩炵画鈥�.鈥欏苟涓旈浣嶆湯浣嶄笉鑳戒负鈥�.鈥欙紒";
+                        objJsonResult.data = 1;
+                        return objJsonResult;
+                    }
+
+                    ds = oCN.RunProcReturn("select * from  Gy_Material where  HNumber='" + oItem.HNumber.Trim() + "'", "Gy_Material");
+
+                    if (ds.Tables[0].Rows.Count == 0)
+                    {
+
+                        oBill.AddNew();
+                    }
+                    else
+                    {
+
+                        int HItemID = int.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());
+                        oBill.oModel.HItemID = HItemID;
+                        oBill.ModifyByID(oBill.oModel.HItemID);
+
+                    }
+
+                    i++;
+                }
+
+                oCN.Commit();
+
+                objJsonResult.code = CodeConstant.SUCCEED;
+                objJsonResult.count = CountConstant.SUCCEED;
+                objJsonResult.Message = "瀵煎叆鎴愬姛!";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                LogService.Write(e);
+                objJsonResult.code = CodeConstant.FAIL;
+                objJsonResult.count = CountConstant.FAIL;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+        #endregion
         /// <summary>
         /// 鐗╂枡璁剧疆鍒犻櫎鍔熻兘
         /// </summary>
@@ -699,6 +1435,63 @@
             }
         }
 
+        #region 妯″叿鍒楄〃鍒嗛〉鍒楄〃
+        [Route("Gy_Mould/page")]
+        [HttpGet]
+        public object Gy_MouldPage(string sWhere,string ModRightNameSelect,string user, int page, int size)
+        {
+            DataSet ds;
+            json res = new json();
+            try
+            {
+                List<object> columnNameList = new List<object>();
+                if (!DBUtility.ClsPub.Security_Log(ModRightNameSelect, 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "娌℃湁鏌ョ湅鏉冮檺";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                if (sWhere == null || sWhere.Equals(""))
+                {
+                    ds = oCN.RunProcReturn("exec h_p_Gy_MouldFileList " + page + "," + size + ",''", "h_p_Gy_MouldFileList");
+                }
+                else
+                {
+                    sWhere = sWhere.Replace("'", "''");
+                    ds = oCN.RunProcReturn("exec h_p_Gy_MouldFileList " + page + "," + size + ",'" + sWhere + "'", "h_p_Gy_MouldFileList");
+                }
+
+                //娣诲姞鍒楀悕
+                foreach (DataColumn col in ds.Tables[0].Columns)
+                {
+                    Type dataType = col.DataType;
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+                }
+
+                res.code = CodeConstant.SUCCEED;
+                res.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
+                res.Message = "Sucess锛�";
+                res.list = columnNameList;
+                res.data = ds.Tables[0];
+                return res;
+            }
+            catch (Exception e)
+            {
+                res.code = CodeConstant.FAIL;
+                res.count = CountConstant.FAIL;
+                res.Message = "Exception锛�" + e.ToString();
+                res.data = null;
+                return res;
+            }
+        }
+        #endregion
+
+
+
 
         #region 鍣ㄥ叿妗f鍒楄〃 鏍戠姸鍥� 璁惧鍒嗙被鏌ヨ
         public class TreeModel
@@ -842,6 +1635,7 @@
         {
             try
             {
+                List<object> columnNameList = new List<object>();
                 //鍒ゆ柇鏄惁鏈夋煡璇㈡潈闄�
                 if (!DBUtility.ClsPub.Security_Log("Gy_BarCodeBill_Query", 1, false, user))
                 {
@@ -852,14 +1646,23 @@
                     return objJsonResult;
                 }
 
-                string sql1 = "select top 1000 * from h_v_IF_BarCodeBillList where 1 = 1 ";
+                string sql1 = "select top 15000 * from h_v_IF_BarCodeBillList where 1 = 1 ";
                 string sql = sql1 + sWhere + " order by hmainid desc";
                 ds = oCN.RunProcReturn(sql, "h_v_IF_BarCodeBillList");
+
+                //娣诲姞鍒楀悕
+                foreach (DataColumn col in ds.Tables[0].Columns)
+                {
+                    Type dataType = col.DataType;
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+                }
 
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
                 objJsonResult.Message = "Sucess锛�";
                 objJsonResult.data = ds.Tables[0];
+                objJsonResult.list = columnNameList;
                 return objJsonResult;
             }
             catch (Exception e)
@@ -938,7 +1741,18 @@
                     objJsonResult.data = null;
                     return objJsonResult;
                 }
-                
+
+                //杩涜 浼氳鏈熼棿 缁撹处 鐨勫垽鏂拰鎺у埗
+                string s = "";
+                int sYear = 0;
+                int sPeriod = 0;
+                DateTime HDate = DateTime.Now;
+                if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
+                {
+                    objJsonResult.Message = s;
+                    return objJsonResult;
+                }
+
                 Ds = oCN.RunProcReturn("Select * from h_v_IF_BarCodeBillList Where HItemID in (" + HInterID + ")", "h_v_IF_BarCodeBillList");
                 if (Ds.Tables[0].Rows.Count != 0)
                 {
@@ -1145,6 +1959,34 @@
         }
         #endregion
 
+        #region[鍣ㄥ叿妗f缂栬緫鏃惰幏鍙栧瓙琛ㄦ暟鎹甝
+        [Route("Gy_MouldFileMain/Gy_MouldFileSubDetai")]
+        [HttpGet]
+        public object Gy_MouldFileSubDetai(long HInterID)
+        {
+            try
+            {
+                List<DataTable> tableList = new List<DataTable>();
+                ds = oCN.RunProcReturn("select a.*,b.HBillNo from Gy_MouldFileSub_MaintainRule AS a left join Sc_MouldMaintainRuleBillMain as b on b.HInterID = a.HMaintainRuleID where a.HInterID = " + HInterID, "Gy_MouldFileBill_MaintainRule");
+                tableList.Add(ds.Tables[0]);
+                ds = oCN.RunProcReturn("select a.*,b.HBillNo from Gy_MouldFileSub_DotCheckRule AS a left join Sc_MouldDotCheckRuleBillMain as b on b.HInterID = a.HDotCheckRuleID where a.HInterID = " + HInterID, "Gy_MouldFileBill_DotCheckRule");
+                tableList.Add(ds.Tables[0]);
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "";
+                objJsonResult.data = tableList;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
         /// <summary>
         /// 鏂板妯″叿妗f-淇濆瓨鎸夐挳
         ///鍙傛暟锛歴tring sql銆�
@@ -1171,10 +2013,9 @@
                 return objJsonResult;
             }
             //淇濆瓨涓昏〃
-            objJsonResult = AddBillMain(msg2);
+            objJsonResult = AddBillMain(msg1);
             if (objJsonResult.code == "0")
             {
-                oCN.RollBack();
                 objJsonResult.code = "0";
                 objJsonResult.count = 0;
                 objJsonResult.Message = objJsonResult.Message;
@@ -1188,8 +2029,15 @@
             return objJsonResult;
         }
 
-        public json AddBillMain(string msg2)
+        public json AddBillMain(string msg1)
         {
+            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+            string msg2 = sArray[0].ToString();
+            string msg3 = sArray[1].ToString();//妯″潡鏉冮檺
+            string msg4 = sArray[2].ToString();//褰撳墠浜�
+            string msg5 = sArray[3].ToString();//瀛愯〃鏁版嵁
+            string msg6 = sArray[4].ToString();//瀛愯〃1鏁版嵁
+            string msg7 = sArray[5].ToString();//瀛愯〃2鏁版嵁
             try
             {
                 msg2 = "[" + msg2.ToString() + "]";
@@ -1227,6 +2075,7 @@
                 long HSPID = mainList[0].HSPID;
                 Double HDesignLife = mainList[0].HDesignLife;
                 Double HUseLife = mainList[0].HUseLife;
+                Double HInitLife = mainList[0].HInitLife;//涓婄嚎鍒濆鍖栧鍛�
                 Double HLeaveLife = mainList[0].HLeaveLife;
                 Double HProdQty = mainList[0].HProdQty;
                 Double HProdWeight = mainList[0].HProdWeight;
@@ -1244,6 +2093,31 @@
                 int HNowSupTypeID = mainList[0].HNowSupTypeID;
                 int HMadeSupID = mainList[0].HMadeSupID;
                 string HMouldClass = mainList[0].HMouldClass;
+                int HNowWHID = mainList[0].HNowWHID;
+                int HNowSPID = mainList[0].HNowSPID;
+                string HMouldUseStatus = mainList[0].HMouldUseStatus;
+
+                //淇濆瓨鍓嶆帶鍒�=========================================
+                string HBillNote = "";
+                ds = oCN.RunProcReturn("Exec h_p_Gy_MouldFileMain_BeforeSaveCtrl " + HInterID.ToString() + ", '" + HBillNo + "','" + HBillNote + "',1 ", "h_p_Gy_MouldFileMain_BeforeSaveCtrl");
+                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "淇濆瓨澶辫触!鍘熷洜:淇濆瓨鍓嶅垽鏂け璐ワ紝璇蜂笌缃戠粶绠$悊浜哄憳鑱旂郴";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "淇濆瓨澶辫触!鍘熷洜:" + ds.Tables[0].Rows[0]["HBackRemark"].ToString(); ;
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                //=========================================================
 
 
                 //涓昏〃
@@ -1257,7 +2131,7 @@
                 ",HPrintQty,HMouldStatus,HWhID,HRoutingID,HCaveQty" +
                 ",HBomID,HVersion,HSPGroupID,HSPID,HDesignLife,HNowSupID,HNowSupTypeID" +
                 ",HUseLife,HLeaveLife,HProdQty,HProdWeight,HMouldOWNER,HSaveLife,HMouldDotCheckRuleInterID,HMouldMaintainRuleInterID,HBarCode,HMadeSupID" +
-                ",HMouldClass) " +
+                ",HMouldClass,HNowWHID,HNowSPID,HInitLife,HMouldUseStatus) " +
                 " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "','" + HDate + "'" +
                 "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HMaker + "',getdate()" +
                 ",'" + HMouldNo + "','" + HName + "','" + HModel + "','" + HModel2 + "','" + HDiameter + "'" +
@@ -1267,8 +2141,7 @@
                 "," + HPrintQty + ",'" + HMouldStatus + "'," + HWHID + "," + HRoutingID + "," + HCaveQty +
                 "," + HBOMID + ",'" + HVersion + "'," + HSPGroupID + "," + HSPID + ",'" + HDesignLife + "','" + HNowSupID + "','" + HNowSupTypeID + "'" +
                 ",'" + HUseLife + "','" + HLeaveLife + "','" + HProdQty + "','" + HProdWeight + "','" + HMouldOWNER + "','" + HSaveLife + "','" + HMouldDotCheckRuleInterID + "','" + HMouldMaintainRuleInterID + "','" + HBarCode + "'," + HMadeSupID +
-                ",'"+ HMouldClass + "') ");
-
+                ",'"+ HMouldClass + "'," + HNowWHID + "," + HNowSPID + ",'" + HInitLife + "','" + HMouldUseStatus + "') ");
 
                 //瀛愯〃
                 oCN.RunProc("Insert into Gy_MouldFileSub " +
@@ -1278,6 +2151,31 @@
                 " values('" + HInterID + "',0,''" +
                 ",0,0,'','',0,0 " +
                 ") ");
+
+                objJsonResult = AddBillSub(msg5,msg6,msg7,HInterID, HBillNo);
+
+                //淇濆瓨鍚庢帶鍒�=========================================
+                ds = oCN.RunProcReturn("Exec h_p_Gy_MouldFileMain_AfterSaveCtrl " + HInterID.ToString() + ", '" + HBillNo + "','" + HBillNote + "',1 ", "h_p_Gy_MouldFileMain_AfterSaveCtrl");
+                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "淇濆瓨澶辫触!鍘熷洜:淇濆瓨鍓嶅垽鏂け璐ワ紝璇蜂笌缃戠粶绠$悊浜哄憳鑱旂郴";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "淇濆瓨澶辫触!鍘熷洜:" + ds.Tables[0].Rows[0]["HBackRemark"].ToString(); ;
+                    objJsonResult.data = null;
+                    oCN.RollBack();
+                    return objJsonResult;
+                }
+                //=========================================================
+
 
                 if (objJsonResult.code == "0")
                 {
@@ -1296,6 +2194,7 @@
             }
             catch (Exception e)
             {
+                oCN.RollBack();
                 objJsonResult.code = "0";
                 objJsonResult.count = 0;
                 objJsonResult.Message = "Exception锛�" + e.ToString();
@@ -1320,6 +2219,9 @@
             string msg2 = sArray[0].ToString();
             string msg3 = sArray[1].ToString();//妯″潡鏉冮檺
             string msg4 = sArray[2].ToString();//褰撳墠浜�
+            string msg5 = sArray[3].ToString();//瀛愯〃鏁版嵁
+            string msg6 = sArray[4].ToString();//瀛愯〃2鏁版嵁
+            string msg7 = sArray[5].ToString();//瀛愯〃3鏁版嵁
             try
             {
                 if (!DBUtility.ClsPub.Security_Log(msg3, 1, false, msg4))
@@ -1369,6 +2271,7 @@
                 long HSPID = mainList[0].HSPID;
                 Double HDesignLife = mainList[0].HDesignLife;
                 Double HUseLife = mainList[0].HUseLife;
+                Double HInitLife = mainList[0].HInitLife;
                 Double HLeaveLife = mainList[0].HLeaveLife;
                 Double HProdQty = mainList[0].HProdQty;
                 Double HProdWeight = mainList[0].HProdWeight;
@@ -1386,7 +2289,9 @@
                 int HNowSupTypeID = mainList[0].HNowSupTypeID;
                 int HMadeSupID = mainList[0].HMadeSupID;
                 string HMouldClass = mainList[0].HMouldClass;
-
+                int HNowWHID = mainList[0].HNowWHID;
+                int HNowSPID = mainList[0].HNowSPID;
+                string HMouldUseStatus = mainList[0].HMouldUseStatus;
                 //鑻AINDI閲嶅鍒欓噸鏂拌幏鍙�
                 oCN.BeginTran();
                 //涓昏〃
@@ -1440,13 +2345,22 @@
                 ",HProdWeight=" + HProdWeight.ToString() +
                 ",HBarCode='" + HBarCode.ToString() + "'" +
                 ",HMadeSupID=" + HMadeSupID +
-                " where HInterID=" + HInterID.ToString());
+                ",HNowWHID=" + HNowWHID +
+                ",HNowSPID=" + HNowSPID +
+                ",HInitLife='" + HInitLife +
+                "',HMouldUseStatus='" + HMouldUseStatus +
+                "' where HInterID=" + HInterID.ToString());
 
                 //淇敼瀛愰」鐩唬鐮�
                 //oCN.RunProc("exec h_p_Gy_UpdateNumber Gy_Department,'" + HNumber + ".','" + this.HOldNumber + ".'", ref DBUtility.ClsPub.sExeReturnInfo);
                 //灏嗕笂绾� 涓洪潪鏈骇
                 // oCN.RunProc("Update Gy_Department set HEndflag=0 where HItemID=" + HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
-                //
+
+                oCN.RunProc("delete from Gy_MouldFileSub_SubMater where HInterID='" + HInterID + "'");
+                oCN.RunProc("delete from Gy_MouldFileSub_MaintainRule where HInterID='" + HInterID + "'");
+                oCN.RunProc("delete from Gy_MouldFileSub_DotCheckRule where HInterID='" + HInterID + "'");
+                objJsonResult = AddBillSub(msg5, msg6, msg7, HInterID, HBillNo);
+
                 oCN.Commit();
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
@@ -1465,6 +2379,86 @@
             }
         }
 
+        public json AddBillSub(string msg5, string msg6, string msg7, long HInterID, string HBillNo)
+        {
+            List<Gy_MouldFileSub_SubMater> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Gy_MouldFileSub_SubMater>>(msg5);
+            List<ClsGy_MouldFileBillSub_MaintainRule> MaintainRuleColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsGy_MouldFileBillSub_MaintainRule>>(msg6);
+
+            List<ClsGy_MouldFileBillSub_DotCheckRule> DotCheckRuleColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsGy_MouldFileBillSub_DotCheckRule>>(msg7);
+            int i = 0;                                          //浣滀负瀛愯〃鍐呯爜
+            foreach (Gy_MouldFileSub_SubMater oSub in DetailColl)
+            {
+                i++;                                            //鍚屼竴涓富琛ㄤ笅鐨勫瓙琛ㄧ殑鍐呯爜鑷
+
+                int HEntryID = i;
+                string HRemark = oSub.HRemark;
+                int HMouldFileID = oSub.HMouldFileID;
+                DateTime HUnionDate = oSub.HUnionDate;
+                            
+                string sql = "insert into Gy_MouldFileSub_SubMater" +
+                    "(HInterID,HBillNo_bak,HEntryID,HRemark,HMouldFileID,HUnionDate) " +
+                    "values(" +
+                    "" + HInterID +
+                    ",'" + HBillNo +
+                    "'," + HEntryID +
+                    ",'" + HRemark +
+                    "','" + HMouldFileID +
+                    "','" + HUnionDate +                   
+                    "')";
+
+                oCN.RunProc(sql);
+            }
+            i = 0;
+            //淇濆瓨淇濆吇瑙勬牸
+            foreach (ClsGy_MouldFileBillSub_MaintainRule oSub in MaintainRuleColl)
+            {
+                i++;
+                Int64 NewHEntryID = i;
+                Int64 newHFlag = 1;
+                if (oSub.HStdFlag == true)
+                {
+                    newHFlag = 1;
+                }
+                else
+                {
+                    newHFlag = 0;
+                }
+                oCN.RunProc($@"Insert into Gy_MouldFileSub_MaintainRule 
+                (HInterID,HBillNo_bak,HEntryID,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,
+                 HMaintainRuleID,HStdFlag
+	            ) 
+                 values({HInterID},'{HBillNo}',{NewHEntryID},'{oSub.HRemark}',{oSub.HSourceInterID},{oSub.HSourceEntryID},'{oSub.HSourceBillNo}','{oSub.HSourceBillType}',{oSub.HRelationQty},{oSub.HRelationMoney}
+                ,{oSub.HMaintainRuleID},{newHFlag})");
+            }
+            i = 0;
+            //淇濆瓨鐐规瑙勭▼
+            foreach (ClsGy_MouldFileBillSub_DotCheckRule oSub in DotCheckRuleColl)
+            {
+                i++;
+                Int64 NewHEntryID = i;
+                Int64 newHFlag = 1;
+                if (oSub.HStdFlag == true)
+                {
+                    newHFlag = 1;
+                }
+                else
+                {
+                    newHFlag = 0;
+                }
+                oCN.RunProc($@"Insert into Gy_MouldFileSub_DotCheckRule 
+                (HInterID,HBillNo_bak,HEntryID,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,
+                 HDotCheckRuleID,HStdFlag
+	            ) 
+                 values({HInterID},'{HBillNo}',{NewHEntryID},'{oSub.HRemark}',{oSub.HSourceInterID},{oSub.HSourceEntryID},'{oSub.HSourceBillNo}','{oSub.HSourceBillType}',{oSub.HRelationQty},{oSub.HRelationMoney}
+                ,{oSub.HDotCheckRuleID},{newHFlag})");
+            }
+
+            objJsonResult.code = "1";
+            objJsonResult.count = 1;
+            objJsonResult.Message = null;
+            objJsonResult.data = null;
+            return objJsonResult;
+        }
 
         /// <summary>
         /// 纾ㄥ叿妗f淇敼鎸夐挳鏂规硶-璁$畻涓嬫淇濆吇/鏍℃鏃ユ湡-鑾峰彇妗f鏈�杩戜竴娆$殑淇濆吇璁板綍
@@ -1512,7 +2506,7 @@
         {
             try
             {
-                ds = oCN.RunProcReturn("select * from h_v_Gy_MouldFileList where hmainid=" + HInterID, "h_v_Gy_MouldFileList");
+                ds = oCN.RunProcReturn("select * from h_v_Gy_MouldFile_Edit where hmainid=" + HInterID, "h_v_Gy_MouldFile_Edit");
 
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
@@ -1552,6 +2546,8 @@
                 }
                 if (oBill.DeleteBill(hmainid, ref DBUtility.ClsPub.sExeReturnInfo))
                 {
+                    oCN.RunProc("Delete From Gy_MouldFileSub_MaintainRule  where HInterID=" + hmainid);
+                    oCN.RunProc("Delete From Gy_MouldFileSub_DotCheckRule  where HInterID=" + hmainid);
                     //鍐欏叆鏃ュ織
                     ClsPub.Add_Log("", "鍒犻櫎椤圭洰锛屼唬鐮侊細" + oBill.omodel.HMouldNo + ",鍚嶇О锛�" + oBill.omodel.HName, ClsPub.CurUserName);
                     //鏇存柊涓婄骇涓� 鏈骇
@@ -1809,7 +2805,7 @@
                 ,HPERUNITSTANDHOUR,HSTDLABORPREPARETIME,HSTDMACHINEPREPARETIME
                  )
                 values
-                ({jsonData.HItemID},{jsonData.HERPItemID},'{jsonData.HNumber}','{jsonData.HName}','{jsonData.HModel}',
+                ({jsonData.HItemID},{jsonData.HItemID},'{jsonData.HNumber}','{jsonData.HName}','{jsonData.HModel}',
                 '{jsonData.HShortNumber}',{jsonData.HParentID},{jsonData.HLevel},{jsonData.HEndFlag},{jsonData.HStopflag},'{jsonData.HRemark}',{jsonData.HMaterClsID},{jsonData.HUnitID},{jsonData.HUnitGroupID},{jsonData.HLength},{jsonData.HWidth},{jsonData.HHeight},{jsonData.HJQty},{jsonData.HMQty},'{jsonData.HOldMaterNumber}',{jsonData.HWHID},{jsonData.HSPID},'{jsonData.HPlanMode}','{jsonData.HUseFlag}','{jsonData.HMakeTime}',{jsonData.HMinPickQty},{jsonData.HCREATEORGID},{jsonData.HUSEORGID},'{jsonData.HBatchManager}',{jsonData.HCHECKINCOMING},{jsonData.HAuxPropFlag},{jsonData.HISKFPERIOD},{jsonData.HAuxUnitID},{jsonData.HSNUnitID},{jsonData.HBASEUNITID},{jsonData.HSALEUNITID},{jsonData.HSALEPRICEUNITID},{jsonData.HPERUNITSTANDHOUR},'{jsonData.HSTDLABORPREPARETIME}','{jsonData.HSTDMACHINEPREPARETIME}')";
 
                     oCN.RunProc(sql);
@@ -2275,5 +3271,589 @@
         }
         #endregion
 
+        #region 鍣ㄥ叿妗f 鏂囦欢瀵煎叆淇濆瓨
+        #region 鍣ㄥ叿妗f 鏂囦欢涓婁紶
+        [Route("Gy_MouldFile/Gy_MouldFile_Excel")]
+        [HttpPost]
+        public object Gy_Mould_Excel()
+        {
+            try
+            {
+                //鑾峰彇鏂囦欢鍚嶇О
+                var file = HttpContext.Current.Request.Files[0];
+                //鑾峰彇鏂囦欢鐗╃悊璺緞
+                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
+                //淇濆瓨鏂囦欢
+                file.SaveAs(ExcelPath);
+
+                NpoiHelper np = new NpoiHelper();
+                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
+
+                //鍒犻櫎鏂囦欢
+                File.Delete(ExcelPath);
+
+                //鍒涘缓涓存椂琛�
+                DataTable tb2 = new DataTable("dt2");
+
+                //娣诲姞鍒楀悕
+                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
+                {
+                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
+                }
+
+                //妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁
+                tb2.Columns.Add("HOrgID", typeof(Int32));//缁勭粐ID
+                tb2.Columns.Add("HMaterID", typeof(Int32));//鐗╂枡ID
+                tb2.Columns.Add("HMouldTypeID", typeof(Int32));//鍒嗙被ID
+                tb2.Columns.Add("HUnitID", typeof(Int32));//鍗曚綅ID
+                tb2.Columns.Add("HDeptID", typeof(Int32));//閮ㄩ棬ID
+                tb2.Columns.Add("HWHID", typeof(Int32));//浠撳簱ID
+                tb2.Columns.Add("HSupID", typeof(Int32));//渚涘簲鍟咺D
+                tb2.Columns.Add("HSPID", typeof(Int32));//浠撲綅ID
+                tb2.Columns.Add("HMadeSupID", typeof(Int32));//鍒堕�犲晢ID
+                //娣诲姞鏁版嵁
+                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
+                {
+                    DataRow row = tb2.NewRow();
+                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
+                    {
+                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
+                    }
+                    tb2.Rows.Add(row);
+                }
+
+
+                var error = "";
+
+                //鍒ゆ柇瀵煎叆鏂囦欢鍒楁槸鍚﹀畬鏁�
+                if (!tb2.Columns.Contains("缁勭粐浠g爜"))
+                    error += "娌℃湁鎵惧埌銆愮粍缁囦唬鐮併�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("缁勭粐鍚嶇О"))
+                    error += "娌℃湁鎵惧埌銆愮粍缁囧悕绉般�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鍣ㄥ叿鍚嶇О"))
+                    error += "娌℃湁鎵惧埌銆愬櫒鍏峰悕绉般�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鍣ㄥ叿缂栧彿"))
+                    error += "娌℃湁鎵惧埌銆愬櫒鍏风紪鍙枫�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鍣ㄥ叿鍒嗙被"))
+                    error += "娌℃湁鎵惧埌銆愬櫒鍏峰垎绫汇�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鍣ㄥ叿瑙勬牸"))
+                    error += "娌℃湁鎵惧埌銆愬櫒鍏疯鏍笺�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鍣ㄥ叿鍨嬪彿"))
+                    error += "娌℃湁鎵惧埌銆愬櫒鍏峰瀷鍙枫�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("绌存暟"))
+                    error += "娌℃湁鎵惧埌銆愮┐鏁般�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("杈呭姪灞炴��1"))
+                    error += "娌℃湁鎵惧埌銆愯緟鍔╁睘鎬�1銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("杈呭姪灞炴��2"))
+                    error += "娌℃湁鎵惧埌銆愯緟鍔╁睘鎬�2銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鍥惧彿"))
+                    error += "娌℃湁鎵惧埌銆愬浘鍙枫�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("瀵瑰簲ERP鐗╂枡浠g爜"))
+                    error += "娌℃湁鎵惧埌銆愬搴擡RP鐗╂枡浠g爜銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("瀵瑰簲ERP鐗╂枡"))
+                    error += "娌℃湁鎵惧埌銆愬搴擡RP鐗╂枡銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("璁¢噺鍗曚綅"))
+                    error += "娌℃湁鎵惧埌銆愯閲忓崟浣嶃�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鍣ㄥ叿鍑哄巶缂栧彿"))
+                    error += "娌℃湁鎵惧埌銆愬櫒鍏峰嚭鍘傜紪鍙枫�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("浣跨敤閮ㄩ棬"))
+                    error += "娌℃湁鎵惧埌銆愪娇鐢ㄩ儴闂ㄣ�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鐘舵��"))
+                    error += "娌℃湁鎵惧埌銆愮姸鎬併�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("榛樿浠撳簱"))
+                    error += "娌℃湁鎵惧埌銆愰粯璁や粨搴撱�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("榛樿浠撲綅"))
+                    error += "娌℃湁鎵惧埌銆愰粯璁や粨浣嶃�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鐗堟湰鍙�"))
+                    error += "娌℃湁鎵惧埌銆愮増鏈彿銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("璁捐瀵垮懡"))
+                    error += "娌℃湁鎵惧埌銆愯璁″鍛姐�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("浣跨敤瀵垮懡"))
+                    error += "娌℃湁鎵惧埌銆愪娇鐢ㄥ鍛姐�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鏉″舰鐮�"))
+                    error += "娌℃湁鎵惧埌銆愭潯褰㈢爜銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("渚涘簲鍟嗕唬鐮�"))
+                    error += "娌℃湁鎵惧埌銆愪緵搴斿晢浠g爜銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("渚涘簲鍟�"))
+                    error += "娌℃湁鎵惧埌銆愪緵搴斿晢銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鍒堕�犲晢"))
+                    error += "娌℃湁鎵惧埌銆愬埗閫犲晢銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("澶囨敞"))
+                    error += "娌℃湁鎵惧埌銆愬娉ㄣ�戠殑鏍囬,";
+
+
+                if (error.Length > 0)
+                {
+                    objJsonResult.code = CodeConstant.FAIL;
+                    objJsonResult.count = CountConstant.FAIL;
+                    objJsonResult.Message = $"Excel妯℃澘瀛樺湪閿欒,{error}\r\n";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
+                {
+                    string HMouldName = "";
+                    string HMouldNum = "";
+                    string HORGNumber = "";
+                    string HORGName = "";
+                    string HMaterNumber = "";
+                    string HMaterName = "";
+                    string HUnitName = "";
+                    string HDeptName = "";
+                    string HWHName = "";
+                    string HSPName = "";
+                    string HSupName = "";
+                    string HSupNumber = "";
+                    string HMadeSupName = "";
+                    string HMouldTypeName = "";
+
+                    HMouldName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鍣ㄥ叿鍚嶇О"].ToString());
+                    HMouldNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鍣ㄥ叿缂栧彿"].ToString());
+                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐浠g爜"].ToString());
+                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐鍚嶇О"].ToString());
+                    HMaterNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["瀵瑰簲ERP鐗╂枡浠g爜"].ToString());
+                    HMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["瀵瑰簲ERP鐗╂枡"].ToString());
+                    HUnitName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["璁¢噺鍗曚綅"].ToString());
+                    HDeptName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["浣跨敤閮ㄩ棬"].ToString());
+                    HWHName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["榛樿浠撳簱"].ToString());
+                    HSPName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["榛樿浠撲綅"].ToString());
+                    HSupName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["渚涘簲鍟�"].ToString());
+                    HSupNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["渚涘簲鍟嗕唬鐮�"].ToString());
+                    HMadeSupName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鍒堕�犲晢"].ToString());
+                    HMouldTypeName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鍣ㄥ叿鍒嗙被"].ToString());
+                    //妫�鏌ョ墿鏂�
+                    int index = i + 1;
+
+                    if (HORGNumber != "")
+                    {
+
+                        //鏌ヨ缁勭粐
+                        ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where  HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = CodeConstant.FAIL;
+                            objJsonResult.count = CountConstant.FAIL;
+                            objJsonResult.Message = "绗�" + index + "琛�,缁勭粐涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        string HORGid = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        //鏌ヨ鍒嗙被
+                        ds = oCN.RunProcReturn("select * from Gy_MouldType where  HName='" + HMouldTypeName + "' ", "Gy_MouldType");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,鍒嗙被:" + HMouldTypeName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HMouldTypeID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        //鏌ヨ鐗╂枡
+                        ds = oCN.RunProcReturn("select * from Gy_Material where  HNumber='" + HMaterNumber + "'  and HUSEORGID=" + HORGid + "", "Gy_Department");
+
+                        if (ds.Tables[0].Rows.Count == 0 && HMaterNumber != "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,鐗╂枡:" + HMaterName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else if (HMaterNumber == "")
+                        {
+                            tb2.Rows[i]["HMaterID"] = 0;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HMaterID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        //鏌ヨ鍗曚綅
+                        ds = oCN.RunProcReturn("select * from Gy_Unit where  HName='" + HUnitName + "'  and HUSEORGID=" + HORGid + "", "Gy_Unit");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,鍗曚綅:" + HUnitName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HUnitID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        //鏌ヨ閮ㄩ棬
+                        ds = oCN.RunProcReturn("select * from Gy_Department where  HName='" + HDeptName + "'  and HUSEORGID=" + HORGid + "", "Gy_Department");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,閮ㄩ棬:" + HDeptName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HDeptID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        //鏌ヨ浠撳簱
+                        ds = oCN.RunProcReturn("select * from Gy_Warehouse where  HName='" + HWHName + "'  and HUSEORGID=" + HORGid + "", "Gy_Warehouse");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,浠撳簱:" + HWHName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HWHID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        string HWHID = tb2.Rows[i]["HWHID"].ToString();
+                        //鏌ヨ浠撲綅
+                        ds = oCN.RunProcReturn("select * from Gy_StockPlace where  HName='" + HSPName + "'and HSPGroupID=" + HWHID+ "  and HUSEORGID=" + HORGid + "", "Gy_Warehouse");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,浠撲綅:" + HSPName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HSPID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        //鏌ヨ渚涘簲鍟�
+                        ds = oCN.RunProcReturn("select * from Gy_Supplier where  HNumber='" + HSupNumber + "'  and HUSEORGID=" + HORGid + "", "Gy_Supplier");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,渚涘簲鍟�:" + HSupName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HSupID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        //鏌ヨ鍒堕�犲晢
+                        ds = oCN.RunProcReturn("select * from Gy_Supplier where  HName='" + HMadeSupName + "'  and HUSEORGID=" + HORGid + "", "Gy_Supplier");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,鍒堕�犲晢:" + HMadeSupName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HMadeSupID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+
+                        //鍣ㄥ叿妗f鍚嶇О
+                        if (HMouldName == "")
+                        {
+                            objJsonResult.code = CodeConstant.FAIL;
+                            objJsonResult.count = CountConstant.FAIL;
+                            objJsonResult.Message = "绗�" + index + "琛�,鍣ㄥ叿妗f鍚嶇О涓嶈兘涓虹┖锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                        //鍣ㄥ叿妗f浠g爜
+                        if (HMouldNum == "")
+                        {
+                            objJsonResult.code = CodeConstant.FAIL;
+                            objJsonResult.count = CountConstant.FAIL;
+                            objJsonResult.Message = "绗�" + index + "琛�,鍣ㄥ叿妗f浠g爜涓嶈兘涓虹┖锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+                    else
+                    {
+                        objJsonResult.code = CodeConstant.FAIL;
+                        objJsonResult.count = CountConstant.FAIL;
+                        objJsonResult.Message = "绗�" + index + "琛�,缁勭粐浠g爜涓虹┖";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+
+                objJsonResult.code = CodeConstant.SUCCEED;
+                objJsonResult.count = CountConstant.SUCCEED;
+                objJsonResult.Message = error;
+                objJsonResult.data = tb2;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = CodeConstant.FAIL;
+                objJsonResult.count = CountConstant.FAIL;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鍣ㄥ叿妗f椤圭洰 瀵煎叆(淇濆瓨)
+        [Route("Gy_MouldFile/Gy_MouldFile_btnSave")]
+        [HttpPost]
+        public object Gy_Mould_btnSave([FromBody] JObject sMainSub)
+        {
+            var _value = sMainSub["sMainSub"].ToString();
+            string msg1 = _value.ToString();
+            string[] sArray = msg1.Split(new string[] { "&鍜�" }, StringSplitOptions.RemoveEmptyEntries);
+            string msg2 = sArray[0].ToString();
+            string user = sArray[1].ToString();
+            try
+            {
+                if (!DBUtility.ClsPub.Security_Log("Gy_MouldFile_Edit", 1, false, user))
+                {
+                    objJsonResult.code = CodeConstant.FAIL;
+                    objJsonResult.count = CountConstant.FAIL;
+                    objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
+                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
+
+                foreach (JObject item in Excel)
+                {
+                    Dictionary<string, string> dic = new Dictionary<string, string>();
+                    foreach (var itm in item.Properties())
+                    {
+                        dic.Add(itm.Name, itm.Value.ToString());
+                    }
+                    list.Add(dic);
+                }
+
+                oCN.BeginTran();
+                int i = 1;
+                foreach (Dictionary<string, string> item in list)
+                {
+                    string HOrgID = item["HOrgID"].ToString();//缁勭粐ID
+                    string BillType = "3899";
+                    //寰楀埌mainid
+                    long HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
+                    string HBillNo = DBUtility.ClsPub.CreateBillCode(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true); ;//閫掑叆type寰楀埌鐨勫崟鎹彿
+                    DateTime HDate = DateTime.Now;//鏃ユ湡
+                    int HYear = DBUtility.ClsPub.isInt(DateTime.Now.Year);
+                    double HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
+                    string HMouldNo = item["鍣ㄥ叿缂栧彿"].ToString();
+                    string HBarCode = item["鏉″舰鐮�"].ToString();
+                    string HName = item["鍣ㄥ叿鍚嶇О"].ToString();
+                    string HModel = item["鍣ㄥ叿瑙勬牸"].ToString();
+                    string HModel2 = item["鍣ㄥ叿鍨嬪彿"].ToString();
+                    string HDiameter = "";//鐩村緞
+                    string HSubjoin = item["杈呭姪灞炴��1"].ToString();
+                    string HSubjoin2 = item["杈呭姪灞炴��2"].ToString();
+                    string HPICNo = item["鍥惧彿"].ToString();
+                    string HWorkMaterModel = "";//鐢熶骇浜у搧鍨嬪彿
+                    long HMaterID = int.Parse(item["HMaterID"].ToString());
+                    long HMouleTypeID = int.Parse(item["HMouldTypeID"].ToString());
+                    long HUnitID = int.Parse(item["HUnitID"].ToString());
+                    DateTime HOutComDate = DateTime.Now;
+                    string HOutComNo = item["鍣ㄥ叿鍑哄巶缂栧彿"].ToString();
+                    long HDeptID = int.Parse(item["HDeptID"].ToString());
+                    long HSupID = int.Parse(item["HSupID"].ToString());
+                    string HMouldStatus = item["鐘舵��"].ToString();
+                    long HWHID = int.Parse(item["HWHID"].ToString());
+                    long HRoutingID = 0;//宸ヨ壓璺嚎id
+                    long HBOMID = 0;
+                    string HVersion = "";//鐗堟湰
+                    long HSPGroupID = 0;//榛樿浠撲綅缁�
+                    long HSPID = int.Parse(item["HSPID"].ToString());//浠撲綅id
+                    Double HDesignLife = item["璁捐瀵垮懡"].ToString()=="" ? 0: double.Parse(item["璁捐瀵垮懡"].ToString());
+                    Double HUseLife = item["浣跨敤瀵垮懡"].ToString() == "" ? 0 : double.Parse(item["浣跨敤瀵垮懡"].ToString());
+                    Double HInitLife = 0;//涓婄嚎鍒濆鍖栧鍛�
+                    Double HLeaveLife = 0;//鍓╀綑瀵垮懡
+                    Double HProdQty = 0;//宸茬敓浜ф暟閲�
+                    Double HProdWeight = 0;//宸茬敓浜ч噸閲�
+                    string HRemark = item["澶囨敞"].ToString();
+                    string HMaker = user;
+                    string HMaterNumber = item["瀵瑰簲ERP鐗╂枡浠g爜"].ToString();
+                    string HSupNumber = item["渚涘簲鍟嗕唬鐮�"].ToString();
+                    long HPrintQty = 0;//宸茬敓浜ф暟閲�
+                    string HMouldOWNER = "鑷垂";//璐т富绫诲瀷
+                    string HSaveLife = "";//瀹夊叏瀵垮懡
+                    int HCaveQty = item["绌存暟"].ToString() == "" ? 0 : int.Parse(item["绌存暟"].ToString());
+                    int HMouldDotCheckRuleInterID = 0;
+                    int HMouldMaintainRuleInterID = 0;
+                    int HNowSupID = 0;//铏氭嫙浠�
+                    int HNowSupTypeID = 0;
+                    int HMadeSupID = 0;
+                    string HMouldClass = "妯″叿";//鍣ㄥ叿绫诲瀷
+                    int HNowWHID = 0;
+                    int HNowSPID = 0;
+
+
+                    if (!DBUtility.ClsPub.AllowNumber(HMouldNo.Trim()))
+                    {
+                        objJsonResult.code = CodeConstant.FAIL;
+                        objJsonResult.count = CountConstant.FAIL;
+                        objJsonResult.Message = "淇濆瓨澶辫触锛佷唬鐮佷腑涓嶈兘鍑虹幇杩炵画鈥�.鈥欏苟涓旈浣嶆湯浣嶄笉鑳戒负鈥�.鈥欙紒";
+                        objJsonResult.data = 1;
+                        return objJsonResult;
+                    }
+
+                    ds = oCN.RunProcReturn("select * from Gy_MouldFileMain where HMouldNo='" + HMouldNo + "'", "Gy_MouldFileMain");
+
+                    if (ds.Tables[0].Rows.Count == 0)
+                    {
+
+                        oCN.RunProc("Insert Into Gy_MouldFileMain   " +
+                        "(HBillType,HBillSubType,HInterID,HBillNo,HDate" +
+                        ",HYear,HPeriod,HRemark,HMaker,HMakeDate" +
+                        ",HMouldNo,HName,HModel,HModel2,HDiameter" +
+                        ",HSubjoin,HSubjoin2,HPICNo,HWorkMaterModel" +
+                        ",HMaterID,HMaterNumber,HMouldType,HUnitID" +
+                        ",HOutComDate,HOutComNo,HDeptID,HSupID,HSupNumber" +
+                        ",HPrintQty,HMouldStatus,HWhID,HRoutingID,HCaveQty" +
+                        ",HBomID,HVersion,HSPGroupID,HSPID,HDesignLife,HNowSupID,HNowSupTypeID" +
+                        ",HUseLife,HLeaveLife,HProdQty,HProdWeight,HMouldOWNER,HSaveLife,HMouldDotCheckRuleInterID,HMouldMaintainRuleInterID,HBarCode,HMadeSupID" +
+                        ",HMouldClass,HNowWHID,HNowSPID,HInitLife) " +
+                        " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "','" + HDate + "'" +
+                        "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HMaker + "',getdate()" +
+                        ",'" + HMouldNo + "','" + HName + "','" + HModel + "','" + HModel2 + "','" + HDiameter + "'" +
+                        ",'" + HSubjoin + "','" + HSubjoin2 + "','" + HPICNo + "','" + HWorkMaterModel + "'" +
+                        "," + HMaterID + ",'" + HMaterNumber + "'," + HMouleTypeID + "," + HUnitID +
+                        ",'" + HOutComDate + "','" + HOutComNo + "'," + HDeptID + "," + HSupID + ",'" + HSupNumber + "'" +
+                        "," + HPrintQty + ",'" + HMouldStatus + "'," + HWHID + "," + HRoutingID + "," + HCaveQty +
+                        "," + HBOMID + ",'" + HVersion + "'," + HSPGroupID + "," + HSPID + ",'" + HDesignLife + "','" + HNowSupID + "','" + HNowSupTypeID + "'" +
+                        ",'" + HUseLife + "','" + HLeaveLife + "','" + HProdQty + "','" + HProdWeight + "','" + HMouldOWNER + "','" + HSaveLife + "','" + HMouldDotCheckRuleInterID + "','" + HMouldMaintainRuleInterID + "','" + HBarCode + "'," + HMadeSupID +
+                        ",'" + HMouldClass + "'," + HNowWHID + "," + HNowSPID + ",'" + HInitLife + "') ");
+                    }
+                    else
+                    {
+                        oCN.RunProc("UpDate Gy_MouldFileMain set  " +
+                //" HBillNo='" + HBillNo + "'" +  //鍥哄畾璧嬪��===============
+                //",HDate='" + HDate + "'" +
+                //",HYear='" + HYear.ToString() + "'" +
+                //",HPeriod='" + HPeriod.ToString() + "'" +
+                "HRemark='" + HRemark + "'" +
+                ",HUpDater='" + user + "'" +
+                ",HUpDateDate=getdate()" +
+                //========================================
+                //",HMouldNo='" + HMouldNo + "'" +
+                ",HName='" + HName + "'" +
+                ",HModel='" + HModel + "'" +
+                ",HModel2='" + HModel2 + "'" +
+                ",HDiameter='" + HDiameter + "'" +
+                ",HSubjoin='" + HSubjoin + "'" +
+                ",HSubjoin2='" + HSubjoin2 + "'" +
+                ",HPICNo='" + HPICNo + "'" +
+                ",HWorkMaterModel='" + HWorkMaterModel + "'" +
+                ",HMaterID=" + HMaterID.ToString() +
+                ",HMaterNumber='" + HMaterNumber + "'" +
+                ",HMouldClass='" + HMouldClass + "'" +
+                ",HMouldType=" + HMouleTypeID.ToString() +
+                ",HUnitID=" + HUnitID.ToString() +
+                ",HOutComDate='" + HOutComDate + "'" +
+                ",HOutComNo='" + HOutComNo + "'" +
+                ",HDeptID=" + HDeptID.ToString() +
+                ",HSupID=" + HSupID.ToString() +
+                ",HSupNumber='" + HSupNumber + "'" +
+                ",HPrintQty=" + HPrintQty.ToString() +
+                ",HMouldStatus='" + HMouldStatus + "'" +
+                ",HSaveLife='" + HSaveLife + "'" +
+                ",HWhID=" + HWHID.ToString() +
+                ",HRoutingID=" + HRoutingID.ToString() +
+                ",HBomID=" + HBOMID.ToString() +
+                ",HVersion='" + HVersion + "'" +
+                ",HSPGroupID=" + HSPGroupID.ToString() +
+                ",HSPID=" + HSPID.ToString() +
+                ",HDesignLife=" + HDesignLife.ToString() +
+                ",HCaveQty=" + HCaveQty.ToString() +
+                ",HUseLife=" + HUseLife.ToString() +
+                ",HLeaveLife=" + HLeaveLife.ToString() +
+                ",HProdQty=" + HProdQty.ToString() +
+                ",HMouldDotCheckRuleInterID=" + HMouldDotCheckRuleInterID.ToString() +
+                ",HMouldMaintainRuleInterID=" + HMouldMaintainRuleInterID.ToString() +
+                ",HMouldOWNER='" + HMouldOWNER + "'" +
+                ",HNowSupID=" + HNowSupID.ToString() +
+                ",HNowSupTypeID=" + HNowSupTypeID.ToString() +
+                ",HProdWeight=" + HProdWeight.ToString() +
+                ",HBarCode='" + HBarCode.ToString() + "'" +
+                ",HMadeSupID=" + HMadeSupID +
+                ",HNowWHID=" + HNowWHID +
+                ",HNowSPID=" + HNowSPID +
+                ",HInitLife='" + HInitLife +
+                "' where HMouldNo='" + HMouldNo.ToString()+"'");
+                    }
+
+                    i++;
+                }
+
+                oCN.Commit();
+
+                objJsonResult.code = CodeConstant.SUCCEED;
+                objJsonResult.count = CountConstant.SUCCEED;
+                objJsonResult.Message = "瀵煎叆鎴愬姛!";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                LogService.Write(e);
+                objJsonResult.code = CodeConstant.FAIL;
+                objJsonResult.count = CountConstant.FAIL;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+        #endregion
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1