From 42c5ed8edc862ebc80c117ed9a26e00f6f3e844d Mon Sep 17 00:00:00 2001
From: wtt <1985833171@qq.com>
Date: 星期二, 17 十二月 2024 08:24:11 +0800
Subject: [PATCH] 基础资料单据(产品工艺参数、设备启动点检清单、产品防错验证清单)增加 导入按钮

---
 WebAPI/Controllers/BaseSet/Gy_MaterialController.cs | 2283 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 2,251 insertions(+), 32 deletions(-)

diff --git a/WebAPI/Controllers/BaseSet/Gy_MaterialController.cs b/WebAPI/Controllers/BaseSet/Gy_MaterialController.cs
index 44a29f5..6763499 100644
--- a/WebAPI/Controllers/BaseSet/Gy_MaterialController.cs
+++ b/WebAPI/Controllers/BaseSet/Gy_MaterialController.cs
@@ -7,10 +7,15 @@
 using System.Collections.Generic;
 using System.Data;
 using System.Data.SqlClient;
+using System.IO;
+using System.Web;
 using System.Web.Http;
 using System.Windows.Forms;
 using WebAPI.Models;
 using WebAPI.Service;
+using System.Text.RegularExpressions;
+using WebAPI.Controllers.SCGL.鏃ヨ鍒掔鐞�;
+using SyntacticSugar.constant;
 
 namespace WebAPI.Controllers
 {
@@ -19,11 +24,11 @@
         //鑾峰彇绯荤粺鍙傛暟
         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;
-
+        string fileip = System.Configuration.ConfigurationManager.AppSettings["FileIP"];
 
 
         ////妫�娴� 褰撳墠閫変腑琛岀殑 椤圭洰鐘舵��
@@ -76,14 +81,14 @@
                     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爜 ", "h_v_Gy_MaterialList");
+                    ds = oCN.RunProcReturn(sql1 + sWhere + " order by 鐗╂枡浠g爜 desc", "h_v_Gy_MaterialList");
                 }
                 else
                 {
-                    string sql = sql1 + sWhere + " order by 鐗╂枡浠g爜 ";
+                    string sql = sql1 + sWhere + " order by 鐗╂枡浠g爜 desc";
                     ds = oCN.RunProcReturn(sql, "h_v_Gy_MaterialList");
                 }
 
@@ -111,6 +116,285 @@
                 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
+                {
+                    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>
         /// 鐗╂枡璁剧疆鑾峰彇淇℃伅
@@ -192,7 +476,7 @@
                     {
                         objJsonResult.code = "0";
                         objJsonResult.count = 0;
-                        objJsonResult.Message = "淇濆瓨澶辫触锛佺墿鏂欏睘鎬т笉鑳戒负绌猴紒";
+                        objJsonResult.Message = "淇濆瓨澶辫触锛佺墿鏂欏垎绫讳笉鑳戒负绌猴紒";
                         objJsonResult.data = 1;
                         return objJsonResult;
                     }
@@ -374,6 +658,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>
@@ -386,6 +1122,7 @@
             try
             {
                 SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
+
                 if (user == "10000")//api鍚屾鏂瑰紡
                 {
                     oCN.RunProc("delete from Gy_Material where HERPItemID=" + HItemID);
@@ -395,6 +1132,7 @@
                     objJsonResult.data = null;
                     return objJsonResult; ;
                 }
+
                 //鍒犻櫎鏉冮檺
                 if (!DBUtility.ClsPub.Security_Log("Gy_Material_Delete", 1, false, user))
                 {
@@ -416,6 +1154,7 @@
                 ds = oCN.RunProcReturn("select * from Gy_Material where HItemID=" + HItemID, "Gy_Material");
                 if (ds == null || ds.Tables[0].Rows.Count == 0)
                 {
+                    oCN.RollBack();//鍥炴粴浜嬪姟
                     objJsonResult.code = "0";
                     objJsonResult.count = 0;
                     objJsonResult.Message = "娌℃湁鏁版嵁锛屾棤娉曞垹闄わ紒";
@@ -444,6 +1183,7 @@
             }
             catch (Exception e)
             {
+                oCN.RollBack();//鍥炴粴浜嬪姟
                 objJsonResult.code = "0";
                 objJsonResult.count = 0;
                 objJsonResult.Message = "鍒犻櫎澶辫触锛�" + e.ToString();
@@ -451,6 +1191,200 @@
                 return objJsonResult;
             }
         }
+
+
+
+        #region 鐗╂枡瀹℃牳銆佸弽瀹℃牳
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="HInterID">鍗曟嵁ID</param>
+        /// <param name="IsAudit">瀹℃牳(0),鍙嶅鏍�(1)</param>
+        /// <param name="CurUserName">瀹℃牳浜�</param>
+        /// <returns></returns>
+        [Route("Gy_Material/AuditGy_Material")]
+        [HttpGet]
+        public object AuditGy_Material(int HInterID, int IsAudit, string CurUserName)
+        {
+            try
+            {
+                //瀹℃牳鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log_second("Gy_Material_Check", 1, false, CurUserName))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "瀹℃牳澶辫触锛佹棤鏉冮檺锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                var ds = oCN.RunProcReturn("select * from Gy_Material where HItemID=" + HInterID, "Gy_Material");
+                if (ds.Tables[0].Rows.Count > 0)
+                {
+                    if (IsAudit == 0)  //瀹℃牳鍒ゆ柇
+                    {
+                        if (ds.Tables[0].Rows[0]["HCheckEmp"].ToString() != "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "鍗曟嵁宸插鏍�!涓嶈兘鍐嶆瀹℃牳锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+                    if (IsAudit == 1) //鍙嶅鏍稿垽鏂�
+                    {
+                        if (ds.Tables[0].Rows[0]["HCheckEmp"].ToString() == "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "鍗曟嵁鏈鏍�!涓嶉渶瑕佸弽瀹℃牳!";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+                }
+                else
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍗曟嵁涓嶅瓨鍦�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                oCN.BeginTran();
+
+                if (IsAudit == 0)  //瀹℃牳鍒ゆ柇
+                {
+                    oCN.RunProc("update Gy_Material set HCheckEmp='" + CurUserName + "',HCheckTime=getdate() where HItemID=" + HInterID);
+
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "瀹℃牳鎴愬姛";
+                    objJsonResult.data = null;
+                }
+                if (IsAudit == 1) //鍙嶅鏍稿垽鏂�
+                {
+                    oCN.RunProc("update Gy_Material set HCheckEmp='',HCheckTime=null where HItemID=" + HInterID);
+
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "鍙嶅鏍告垚鍔�";
+                    objJsonResult.data = null;
+                }
+                oCN.Commit();
+
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "瀹℃牳澶辫触鎴栬�呭弽瀹℃牳澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鐗╂枡绂佺敤銆佸弽绂佺敤
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="HInterID">鍗曟嵁ID</param>
+        /// <param name="IsStop">绂佺敤(0),鍙嶇鐢�(1)</param>
+        /// <param name="CurUserName">瀹℃牳浜�</param>
+        /// <returns></returns>
+        [Route("Gy_Material/StopGy_Material")]
+        [HttpGet]
+        public object StopGy_Material(int HInterID, int IsStop, string CurUserName)
+        {
+            try
+            {
+                //瀹℃牳鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log_second("Gy_Material_Stop", 1, false, CurUserName))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "绂佺敤澶辫触锛佹棤鏉冮檺锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                var ds = oCN.RunProcReturn("select * from Gy_Material where HItemID=" + HInterID, "Gy_Material");
+                if (ds.Tables[0].Rows.Count > 0)
+                {
+                    if (IsStop == 0)  //绂佺敤鍒ゆ柇
+                    {
+                        if (ds.Tables[0].Rows[0]["HStopEmp"].ToString() != "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "鍗曟嵁宸茬鐢�!涓嶈兘鍐嶆绂佺敤锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+                    if (IsStop == 1) //鍙嶇鐢ㄥ垽鏂�
+                    {
+                        if (ds.Tables[0].Rows[0]["HStopEmp"].ToString() == "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "鍗曟嵁鏈鐢�!涓嶉渶瑕佸弽绂佺敤!";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+                }
+                else
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍗曟嵁涓嶅瓨鍦�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                oCN.BeginTran();
+
+                if (IsStop == 0)  //绂佺敤鍒ゆ柇
+                {
+                    oCN.RunProc("update Gy_Material set HStopEmp='" + CurUserName + "',HStopTime=getdate(),HStopflag=1 where HItemID=" + HInterID);
+
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "绂佺敤鎴愬姛";
+                    objJsonResult.data = null;
+                }
+                if (IsStop == 1) //鍙嶇鐢ㄥ垽鏂�
+                {
+                    oCN.RunProc("update Gy_Material set HStopEmp='',HStopTime=null,HStopflag=0 where HItemID=" + HInterID);
+
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "鍙嶇鐢ㄦ垚鍔�";
+                    objJsonResult.data = null;
+                }
+                oCN.Commit();
+
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "绂佺敤澶辫触鎴栬�呭弽绂佺敤澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+
 
 
         /// <summary>
@@ -499,6 +1433,86 @@
             }
         }
 
+
+        #region 鍣ㄥ叿妗f鍒楄〃 鏍戠姸鍥� 璁惧鍒嗙被鏌ヨ
+        public class TreeModel
+        {
+            public string id { get; set; }
+            public string title { get; set; }
+            public List<TreeModel> children = new List<TreeModel>();
+        }
+        [Route("Gy_Mould/TreeList")]
+        [HttpGet]
+        public object TreeList(string sWhere, string user)
+        {
+            try
+            {
+
+                ds = oCN.RunProcReturn("select HItemID,HNumber,HName  from Gy_MouldType", "Gy_MouldType");
+
+                List<TreeModel> treeModels = new List<TreeModel>();
+                TreeModel first = new TreeModel();
+                first.id = "0";
+                first.title = "鍣ㄥ叿鍒嗙被璁剧疆";
+                treeModels.Add(first);
+
+                foreach (DataRow row in ds.Tables[0].Rows)
+                {
+                    var strLen = row["hitemid"].ToString().Split('.');
+                    if (strLen.Length == 1)
+                    {
+                        TreeModel tree = new TreeModel();
+                        tree.id = row["HItemID"].ToString();
+                        tree.title = row["HName"].ToString();
+                        treeModels[0].children.Add(tree);
+                    }
+                }
+                digui(ds.Tables[0], treeModels[0].children, 2);
+
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.data = Newtonsoft.Json.JsonConvert.SerializeObject(treeModels);
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        /// <summary>
+        /// 閫掑綊鍑芥暟
+        /// </summary>
+        public void digui(DataTable dt, List<TreeModel> tree, int num)
+        {
+            for (int m = 0; m < tree.Count; m++)
+            {
+                tree[m].children = new List<TreeModel>();
+                for (int i = 0; i < dt.Rows.Count; i++)//绗竴娆″惊鐜紝寰楀埌鎵�鏈夋牴鑺傜偣鐨勫瓙闆�
+                {
+                    var strLen = dt.Rows[i]["HNumber"].ToString().Split('.');
+                    if (strLen.Length == num && dt.Rows[i]["HNumber"].ToString().Contains(tree[m].id + "."))
+                    {
+                        TreeModel tbjson = new TreeModel();
+                        tbjson.id = dt.Rows[i]["HItemID"].ToString();
+                        tbjson.title = dt.Rows[i]["HName"].ToString();
+                        tree[m].children.Add(tbjson);
+                    }
+                }
+                var strLens = tree[m].id.Split('.');
+                for (int i = 0; i < tree[m].children.Count; i++)
+                {
+                    digui(dt, tree[m].children, strLens.Length + 2);//鍐嶆鐢ㄥ瓙闆嗗幓寰幆锛屾嬁鍑哄瓙闆嗙殑瀛愰泦
+                }
+            }
+
+        }
+        #endregion
 
 
 
@@ -562,6 +1576,7 @@
         {
             try
             {
+                List<object> columnNameList = new List<object>();
                 //鍒ゆ柇鏄惁鏈夋煡璇㈡潈闄�
                 if (!DBUtility.ClsPub.Security_Log("Gy_BarCodeBill_Query", 1, false, user))
                 {
@@ -572,14 +1587,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)
@@ -607,19 +1631,47 @@
             string HInter = sArray[0].ToString();
             string HInterID = HInter.Replace("\"", "");
             string user = sArray[1].ToString();
-
-            //缂栬緫鏉冮檺
-            if (!DBUtility.ClsPub.Security_Log("Gy_BarCodeBillList_Edit", 1, false, user))
-            {
-                objJsonResult.code = "0";
-                objJsonResult.count = 0;
-                objJsonResult.Message = "鏃犲垹闄ゆ潈闄愶紒";
-                objJsonResult.data = null;
-                return objJsonResult;
-            }
+            string HBarCode = sArray[2].ToString().Replace("\"","");
+            string HComputerName = SystemInformation.ComputerName; //璁惧鍚嶇О           
 
             try
             {
+                DataSet Ds;
+
+                string[] NewBarCode;
+                NewBarCode = HBarCode.Split(Convert.ToChar(","));
+
+                //缂栬緫鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log("Gy_BarCodeBill_Del", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犲垹闄ゆ潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                //鍒犻櫎鏉$爜鍓嶈繘琛屽垽鏂�
+                Ds = oCN.RunProcReturn("exec h_p_Gy_BarCodeBill_MulDelete_Before '" + HInterID + "','" + HBarCode + "'", "h_p_Gy_BarCodeBill_MulDelete_Before", ref DBUtility.ClsPub.sExeReturnInfo);
+                if (Ds == null || Ds.Tables[0].Rows.Count <= 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍒犻櫎鏉$爜鍓嶅垽鏂彂鐢熼敊璇紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                else
+                {
+                    if (DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0][0]) == "1")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HRemark"]);
+                        objJsonResult.data = null;
+                        return objJsonResult;                       
+                    }
+                }
                 //Int64 lngBillKey = 0;
                 //lngBillKey = DBUtility.ClsPub.isLong(HInterID);
                 if (HInterID == "")
@@ -630,12 +1682,43 @@
                     objJsonResult.data = null;
                     return objJsonResult;
                 }
-                DataSet Ds;
+
+                //杩涜 浼氳鏈熼棿 缁撹处 鐨勫垽鏂拰鎺у埗
+                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)
                 {
                     oCN.BeginTran();
-                    oCN.RunProc("Delete from Gy_BarCodeBill Where HItemID in (" + HInterID + ")");
+
+                    //鑾峰彇绯荤粺鍙傛暟
+                    string Ret = "";
+                    if (oSystemParameter.ShowBill(ref Ret))
+                    {
+                        //鍒ゆ柇鏄惁鍙兘鍒犻櫎鑷繁鐢熸垚鐨勬潯鐮�
+                        if (oSystemParameter.omodel.BarCode_DeleterAndMakerMustSame == "Y") //绯荤粺鍙傛暟                      
+                        {
+                            oCN.RunProc("Delete from Gy_BarCodeBill Where HItemID in (" + HInterID + ")" + " and HMaker = '" + user + "'");
+                        }
+                        else
+                        {
+                            oCN.RunProc("Delete from Gy_BarCodeBill Where HItemID in (" + HInterID + ")");
+                        }
+                    }                    
+
+                    //鍐欏叆绯荤粺鏃ュ織
+                    for (int i = 0; i <= NewBarCode.Length - 1; i++)
+                    {
+                        oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "缃戦〉鐗堝垹闄ゆ潯鐮侊細" + NewBarCode[i] + "','WMS绯荤粺-鏉$爜妗f鍒楄〃妯″潡','" + DBUtility.ClsPub.IPAddress + "','鍒犻櫎鏉$爜'", ref DBUtility.ClsPub.sExeReturnInfo);                     
+                    }
 
                     oCN.Commit();
                     objJsonResult.code = "1";
@@ -665,7 +1748,186 @@
         }
         #endregion
 
+        #region 鏉$爜涓绘。缁存姢 浣滃簾/鍙嶄綔搴�
+        /// <summary>
+        /// </summary>
+        /// <param name="HInterID">鍗曟嵁ID</param>
+        /// <param name="IsAudit">浣滃簾(0),鍙嶄綔搴�(1)</param>
+        /// <param name="CurUserName">浣滃簾浜�</param>
+        /// <returns></returns>
+        [Route("Gy_BarCodeBillList/DeleteGy_BarCodeBillList")]
+        [HttpGet]
+        public object DeleteGy_BarCodeBillList(int HInterID, int IsAudit, string CurUserName)
+        {
+            string ModRightNameCheck = "Gy_BarCodeBillList_Delete";
+            DBUtility.ClsPub.CurUserName = CurUserName;
+            try
+            {
+                //妫�鏌ユ潈闄�
+                if (!DBUtility.ClsPub.Security_Log_second(ModRightNameCheck, 1, false, CurUserName))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "浣滃簾澶辫触锛佹棤鏉冮檺锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                //HInterID鏁版嵁鍒ゆ柇
+                if (HInterID <= 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "HInterID灏忎簬0锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
 
+
+                Int64 lngBillKey = 0;
+                lngBillKey = DBUtility.ClsPub.isLong(HInterID);                                         //瀵笻InterID杩涜绫诲瀷鐨勮浆鎹�
+
+                //杩涜闇�瑕佽繘琛岀殑浣滃簾/鍙嶄綔搴熸搷浣�
+                if (IsAudit == 0) //浣滃簾鎻愪氦
+                {
+                    oCN.BeginTran();
+
+                    //浣滃簾鏉$爜
+                    oCN.RunProc("update Gy_BarCodeBill set HStopflag=1,HDeleteMan='" + CurUserName + "',HDeleteDate=getdate() where HItemID in (" + HInterID + ")", ref DBUtility.ClsPub.sExeReturnInfo);
+
+                    string sql = "select * from Gy_BarCodeBill where HItemID = " + HInterID;
+                    ds = oCN.RunProcReturn(sql, "Gy_BarCodeBill");
+                    if(ds!=null && ds.Tables[0].Rows.Count > 0)
+                    {
+                        string HBarCode = ds.Tables[0].Rows[0]["HBarCode"].ToString();
+
+                        //娣诲姞鎿嶄綔鏃ュ織
+                        oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + CurUserName + "','" + DBUtility.ClsPub.ComputerName + "','浣滃簾鏉$爜锛�" + HBarCode + "','WMS绯荤粺-鏉$爜妗f鍒楄〃妯″潡','" + DBUtility.ClsPub.IPAddress + "','浣滃簾'", ref DBUtility.ClsPub.sExeReturnInfo);
+
+                        objJsonResult.code = "1";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "浣滃簾鎴愬姛";
+                        objJsonResult.data = null;
+
+                        oCN.Commit();
+                    }
+                    else
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "浣滃簾澶辫触!鍘熷洜:" + DBUtility.ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+
+                        oCN.RollBack();
+                    }
+
+
+                    return objJsonResult;
+                }
+                if (IsAudit == 1) //鍙嶅叧闂彁浜�
+                {
+                    oCN.BeginTran();
+
+                    #region 鍙嶄綔搴熸潯鐮佸墠杩涜鍒ゆ柇
+                    //鍙嶄綔搴熸潯鐮佸墠杩涜鍒ゆ柇------------------------------------------------------------------------------------------------------------------------------------------------------
+                    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+                    DataSet DS = oCN.RunProcReturn("exec h_p_Gy_BarCodeBill_UnCancelltion '" + HInterID + "','N'", "h_p_Gy_BarCodeBill_UnCancelltion", ref DBUtility.ClsPub.sExeReturnInfo);
+                    if (DS == null || DS.Tables[0].Rows.Count <= 0)
+                    {
+                        oCN.RollBack();
+
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鍙嶄綔搴熷け璐ワ紝鍘熷洜锛氬弽浣滃簾鏉$爜鍓嶅垽鏂彂鐢熼敊璇紒";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    else
+                    {
+                        if (DBUtility.ClsPub.isStrNull(DS.Tables[0].Rows[0][0]) == "1")
+                        {
+                            oCN.RollBack();
+
+                            objJsonResult.code = "1";
+                            objJsonResult.count = 1;
+                            objJsonResult.Message = "鍙嶄綔搴熷け璐ワ紝鍘熷洜锛�" + DBUtility.ClsPub.isStrNull(DS.Tables[0].Rows[0]["HRemark"]);
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+                    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+                    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+                    #endregion
+
+                    //鍙嶄綔搴熸潯鐮�
+                    oCN.RunProc("update Gy_BarCodeBill set HStopflag=0,HDeleteMan='',HDeleteDate=null where HItemID in (" + HInterID + ")", ref DBUtility.ClsPub.sExeReturnInfo);
+
+                    //澧炲姞鎿嶄綔鏃ュ織
+                    string sql = "select * from Gy_BarCodeBill where HItemID = " + HInterID;
+                    ds = oCN.RunProcReturn(sql, "Gy_BarCodeBill");
+                    if (ds != null && ds.Tables[0].Rows.Count > 0)
+                    {
+                        string HBarCode = ds.Tables[0].Rows[0]["HBarCode"].ToString();
+                        oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + CurUserName + "','" + DBUtility.ClsPub.ComputerName + "','鍙嶄綔搴熸潯鐮侊細" + HBarCode + "','WMS绯荤粺-鏉$爜妗f鍒楄〃妯″潡','" + DBUtility.ClsPub.IPAddress + "','鍙嶄綔搴�'", ref DBUtility.ClsPub.sExeReturnInfo);
+
+                        objJsonResult.code = "1";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "鍙嶄綔搴熸垚鍔�";
+                        objJsonResult.data = null;
+                        oCN.Commit();
+                        return objJsonResult;
+                    }
+                    else
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鍙嶄綔搴熷け璐�!鍘熷洜:" + DBUtility.ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        oCN.RollBack();
+                        return objJsonResult;
+                    }
+                }
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "浣滃簾澶辫触鎴栬�呭弽浣滃簾澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #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銆�
@@ -692,10 +1954,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;
@@ -709,8 +1970,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() + "]";
@@ -748,6 +2016,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;
@@ -763,7 +2032,33 @@
                 int HMouldMaintainRuleInterID = mainList[0].HMouldMaintainRuleInterID;
                 int HNowSupID = mainList[0].HNowSupID;
                 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;
+                }
+                //=========================================================
 
 
                 //涓昏〃
@@ -776,8 +2071,8 @@
                 ",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" +
-                ") " +
+                ",HUseLife,HLeaveLife,HProdQty,HProdWeight,HMouldOWNER,HSaveLife,HMouldDotCheckRuleInterID,HMouldMaintainRuleInterID,HBarCode,HMadeSupID" +
+                ",HMouldClass,HNowWHID,HNowSPID,HInitLife,HMouldUseStatus) " +
                 " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "','" + HDate + "'" +
                 "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HMaker + "',getdate()" +
                 ",'" + HMouldNo + "','" + HName + "','" + HModel + "','" + HModel2 + "','" + HDiameter + "'" +
@@ -786,9 +2081,8 @@
                 ",'" + 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 + "'" +
-                ") ");
-
+                ",'" + HUseLife + "','" + HLeaveLife + "','" + HProdQty + "','" + HProdWeight + "','" + HMouldOWNER + "','" + HSaveLife + "','" + HMouldDotCheckRuleInterID + "','" + HMouldMaintainRuleInterID + "','" + HBarCode + "'," + HMadeSupID +
+                ",'"+ HMouldClass + "'," + HNowWHID + "," + HNowSPID + ",'" + HInitLife + "','" + HMouldUseStatus + "') ");
 
                 //瀛愯〃
                 oCN.RunProc("Insert into Gy_MouldFileSub " +
@@ -798,6 +2092,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")
                 {
@@ -816,6 +2135,7 @@
             }
             catch (Exception e)
             {
+                oCN.RollBack();
                 objJsonResult.code = "0";
                 objJsonResult.count = 0;
                 objJsonResult.Message = "Exception锛�" + e.ToString();
@@ -840,6 +2160,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))
@@ -889,6 +2212,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;
@@ -904,7 +2228,11 @@
                 int HMouldMaintainRuleInterID = mainList[0].HMouldMaintainRuleInterID;
                 int HNowSupID = mainList[0].HNowSupID;
                 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();
                 //涓昏〃
@@ -928,6 +2256,7 @@
                 ",HWorkMaterModel='" + HWorkMaterModel + "'" +
                 ",HMaterID=" + HMaterID.ToString() +
                 ",HMaterNumber='" + HMaterNumber + "'" +
+                ",HMouldClass='" + HMouldClass + "'" +
                 ",HMouldType=" + HMouleTypeID.ToString() +
                 ",HUnitID=" + HUnitID.ToString() +
                 ",HOutComDate='" + HOutComDate + "'" +
@@ -956,13 +2285,23 @@
                 ",HNowSupTypeID=" + HNowSupTypeID.ToString() +
                 ",HProdWeight=" + HProdWeight.ToString() +
                 ",HBarCode='" + HBarCode.ToString() + "'" +
-                " where HInterID=" + HInterID.ToString());
+                ",HMadeSupID=" + HMadeSupID +
+                ",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;
@@ -981,7 +2320,121 @@
             }
         }
 
+        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鏈�杩戜竴娆$殑淇濆吇璁板綍
+        ///鍙傛暟锛歴tring sql銆�
+        ///杩斿洖鍊硷細object銆�
+        /// </summary>
+        [Route("Gy_Mould_Edit/calculateHNextMainDate")]
+        [HttpGet]
+        public object calculateHNextMainDate(long HInterID)
+        {
+            try
+            {
+                string sql = @"select top(1) a.HInterID, b.HEndDate 淇濆吇璁板綍缁撴潫鏃ユ湡
+                            from Gy_MouldFileMain AS a LEFT OUTER JOIN
+                            Sc_MouldMaintainBillMain AS b on a.HInterID = b.HMouldID
+                            where a.HInterID = " + HInterID +
+                            " order by b.HEndDate desc";
+
+                ds = oCN.RunProcReturn(sql, "Sc_MouldMaintainBillMain");
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "";
+                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;
+            }
+        }
 
         /// <summary>
         /// 纾ㄥ叿妗f淇敼鎸夐挳鏂规硶
@@ -994,7 +2447,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;
@@ -1034,6 +2487,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);
                     //鏇存柊涓婄骇涓� 鏈骇
@@ -1291,7 +2746,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);
@@ -1577,5 +3032,769 @@
             public string msg { get; set; }   //鏈骇鏍囧織
 
         }
+        #region  鐗╂枡鏂囦欢涓婁紶澶勭悊
+        [Route("Gy_Mater/UploadFile")]
+        [HttpPost]
+        public object UploadFile()
+        {
+
+            string HNumber = HttpContext.Current.Request.Params["HNumber"];  //鐗╂枡浠g爜
+            string HRemark = HttpContext.Current.Request.Params["HRemark"];  //澶囨敞
+            string HUserName = HttpContext.Current.Request.Params["HUserName"];  //鍒涘缓浜�
+            HttpPostedFile files = HttpContext.Current.Request.Files["file"];
+            string path = HttpContext.Current.Server.MapPath("~/../Files/Material/" + HNumber);
+            //string path = @"D:\\Files\Material\\"+ HBillNo;
+            dynamic dyResult = UpLoadFile(files, path, HNumber, HRemark, HUserName);
+            if (dyResult != null && dyResult.result == 1)
+            {
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "涓婁紶鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            else
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = dyResult.returnval;
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+
+        }
+
+        public dynamic UpLoadFile(HttpPostedFile files, string path, string HNumber, string HRemark, string HUserName)
+        {
+            dynamic Result_Ob = new { result = 1, returnval = "涓婁紶鎴愬姛锛�" };
+            string filePath = Path.GetFullPath(files.FileName);//鏂囦欢涓婁紶璺緞
+            string fileExtension = Path.GetExtension(files.FileName);// 鏂囦欢鎵╁睍鍚�
+            string filename = files.FileName;//鏂囦欢鍚�
+            string fileSavePath = path;// 涓婁紶淇濆瓨璺緞
+            int filesize = files.ContentLength;//鑾峰彇涓婁紶鏂囦欢鐨勫ぇ灏忓崟浣嶄负瀛楄妭byte
+            int Maxsize = 40000 * 1024;//瀹氫箟涓婁紶鏂囦欢鐨勬渶澶х┖闂村ぇ灏忎负40M
+            try
+            {
+                if (files == null || files.ContentLength <= 0)
+                {
+                    Result_Ob = new { result = 0, returnval = "鏂囦欢涓嶈兘涓虹┖!" };
+                    return Result_Ob;
+                }
+                if (filesize >= Maxsize)
+                {
+                    Result_Ob = new { result = 0, returnval = "涓婁紶鏂囦欢瓒呰繃40M锛屼笉鑳戒笂浼狅紒" };
+                    return Result_Ob;
+                }
+
+                string fileurl = Path.Combine(fileSavePath, filename);
+                if (Directory.Exists(fileurl) == true)  //濡傛灉瀛樺湪閲嶅悕鏂囦欢灏辨彁绀�  
+                {
+                    Result_Ob = new { result = 0, returnval = "瀛樺湪鍚屽悕鏂囦欢锛�" };
+                    return Result_Ob;
+                }
+                //鍒犻櫎鏁版嵁琛ㄦ暟鎹�
+                ds = oCN.RunProcReturn("delete from MES_AccessoriesList where HSourceBillNo ='" + HNumber + "' and HFileName='" + filename + "'", "MES_AccessoriesList");
+                if (Directory.Exists(path))
+                {
+                    File.Delete(fileurl);      //鍒犻櫎鎸囧畾鏂囦欢
+                    files.SaveAs(fileurl);
+                    string StrPath = "/files/Material/" + HNumber + "/" + filename;
+                    if (File.Exists(fileurl))
+                    {
+                        //杩欓噷鍙互鎵ц涓�浜涘叾瀹冪殑鎿嶄綔锛屾瘮濡傛洿鏂版暟鎹簱
+                        //鍐欏叆鏁版嵁琛�
+                        oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" +
+                                    ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" +
+                                    ",HFileClsID,HSourceBillNo" +
+                                   ") values('"
+                                    + filename.ToString() + "','" + StrPath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" +
+                                    ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize +
+                                    "','" + 0 + "','" + HNumber +
+                                   "') ");
+                    }
+                    else
+                    {
+                        Result_Ob = new { result = 0, returnval = "涓婁紶澶辫触锛佹鏂囦欢涓烘伓鎰忔枃浠�" };
+                    }
+                }
+                else
+                {
+                    Directory.CreateDirectory(fileSavePath); //娣诲姞鏂囦欢澶�
+                    files.SaveAs(fileurl);
+                    string StrPath = "/files/Material/" + HNumber + "/" + filename;
+                    if (File.Exists(fileurl))
+                    {
+                        //杩欓噷鍙互鎵ц涓�浜涘叾瀹冪殑鎿嶄綔锛屾瘮濡傛洿鏂版暟鎹簱
+                        //鍐欏叆鏁版嵁琛�
+                        oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" +
+                                    ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" +
+                                    ",HFileClsID,HSourceBillNo" +
+                                   ") values('"
+                                    + filename.ToString() + "','" + StrPath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" +
+                                    ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize +
+                                    "','" + 0 + "','" + HNumber +
+                                   "') ");
+                    }
+                    else
+                    {
+                        Result_Ob = new { result = 0, returnval = "涓婁紶澶辫触锛佹鏂囦欢涓烘伓鎰忔枃浠�" };
+                    }
+                }
+
+            }
+            catch (Exception e)
+            {
+                Result_Ob = new { result = 0, returnval = e.Message };
+            }
+            return Result_Ob;
+        }
+
+        /// <summary>
+        /// 鏍规嵁鍗曟嵁鍙锋煡鎵句笂浼犳枃浠跺垪琛�
+        /// </summary>
+        /// <param name="sWhere"></param>
+        /// <returns></returns>
+        [Route("Gy_Mater/Filelist")]
+        [HttpGet]
+        public object Filelist(string HNumber)
+        {
+            var url = fileip + "/files/Material/" + HNumber + "/";
+            //@"C:\\files\\"
+            try
+            {
+                ds = oCN.RunProcReturn("select *,'" + url + "'+CAST(HFileName as varchar(200))as url  from MES_AccessoriesList where HSourceBillNo='" + HNumber + "'", "MES_AccessoriesList");
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                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;
+            }
+        }
+
+        /// <summary>
+        /// 鏍规嵁ID,鍗曟嵁鍙�,鏂囦欢鍚� 鍒犻櫎鏂囦欢
+        /// </summary>
+        /// <param name="sWhere"></param>
+        /// <returns></returns>
+        [Route("Gy_Mater/DeleteFilelist")]
+        [HttpGet]
+        public object DeleteFilelist(string HItemID, string HSourceBillNo, string HFileName)
+        {
+            try
+            {
+
+                oCN.RunProc("delete from MES_AccessoriesList where HItemID =" + HItemID);
+                string fileurl = Path.Combine(HttpContext.Current.Server.MapPath("~/../Files/Material/" + HSourceBillNo), HFileName);
+                File.Delete(fileurl);      //鍒犻櫎鎸囧畾鏂囦欢
+                objJsonResult.code = "1";
+                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 鍣ㄥ叿妗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