From a1c3a3d1b0b0b8c28a19e99177e4cee5a64949b7 Mon Sep 17 00:00:00 2001
From: zrg <z18737863051@163.com>
Date: 星期二, 25 二月 2025 11:20:17 +0800
Subject: [PATCH] 增加斯莫尔  性能检测散点图报表

---
 WebAPI/Controllers/MJGL/Sc_MouldMaintainRuleBillController.cs |  646 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 621 insertions(+), 25 deletions(-)

diff --git a/WebAPI/Controllers/MJGL/Sc_MouldMaintainRuleBillController.cs b/WebAPI/Controllers/MJGL/Sc_MouldMaintainRuleBillController.cs
index bc9577d..95517a5 100644
--- a/WebAPI/Controllers/MJGL/Sc_MouldMaintainRuleBillController.cs
+++ b/WebAPI/Controllers/MJGL/Sc_MouldMaintainRuleBillController.cs
@@ -1,4 +1,6 @@
-锘縰sing Newtonsoft.Json.Linq;
+锘縰sing DBUtility;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
 using System;
 using System.Collections.Generic;
 using System.Data;
@@ -7,7 +9,10 @@
 using System.Net.Http;
 using System.Web.Http;
 using WebAPI.Models;
-
+using System.Web;
+using WebAPI.Controllers.SCGL.鏃ヨ鍒掔鐞�;
+using System.IO;
+using SyntacticSugar.constant;
 namespace WebAPI.Controllers.MJGL
 {
     public class Sc_MouldMaintainRuleBillController : ApiController
@@ -20,6 +25,14 @@
         public DAL.ClsSc_MouldMaintainRuleBill BillNew = new DAL.ClsSc_MouldMaintainRuleBill();   //瀵瑰簲鍗曟嵁绫�
         public DAL.ClsSc_MouldMaintainRuleBill BillOld = new DAL.ClsSc_MouldMaintainRuleBill();   //瀵瑰簲鍗曟嵁绫�
 
+
+        //public class HlpBill
+        //{
+        //    public int HSouceInterID = 0;
+        //    public int HSourceEntryID = 0;
+        //    public int Type = 0;
+        //    public string user { get; set; }
+        //}
         #region 鍣ㄥ叿淇濆吇瑙勭▼鍗曞垪琛�
         [Route("Sc_MouldMaintainRuleBill/GetMouldMaintainRuleList")]
         [HttpGet]
@@ -27,6 +40,9 @@
         {
             try
             {
+                List<object> columnNameList = new List<object>();
+                //鍙嶅簭鍒楀寲浼犻�掔殑鍊�
+                //HlpBill com = JsonConvert.DeserializeObject<HlpBill>(sWhere.ToString());
                 //缂栬緫鏉冮檺
                 if (!DBUtility.ClsPub.Security_Log("Sc_MouldMaintainRuleBillList", 1, false, user))
                 {
@@ -48,22 +64,79 @@
                     ds = oCN.RunProcReturn(sql, "h_v_Sc_MouldMaintainRuleBillList");
                 }
 
-                //if (ds.Tables[0].Rows.Count != 0 || ds != null)
-                //{
+                //娣诲姞鍒楀悕
+                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;
-                //}
-                //else
-                //{
-                //objJsonResult.code = "0";
-                //objJsonResult.count = 0;
-                //objJsonResult.Message = "鏃犳暟鎹�";
-                //objJsonResult.data = null;
-                //return objJsonResult;
-                //}
+            }
+            catch (Exception ex)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "娌℃湁杩斿洖浠讳綍璁板綍锛�" + ex.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鍣ㄥ叿淇濆吇瑙勭▼鍗曞垪琛≒DA
+        [Route("Sc_MouldMaintainRuleBill/GetMouldMaintainRuleListPDA")]
+        [HttpGet]
+        public object GetMouldMaintainRuleListPDA(string sWhere, string user)
+        {
+            try
+            {
+                List<object> columnNameList = new List<object>();
+                //鍙嶅簭鍒楀寲浼犻�掔殑鍊�
+                //HlpBill com = JsonConvert.DeserializeObject<HlpBill>(sWhere.ToString());
+                //缂栬緫鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log("Sc_MouldMaintainRuleBillList", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳煡鐪嬫潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                if (sWhere == null || sWhere.Equals(""))
+                {
+                    ds = oCN.RunProcReturn("select * from h_v_Sc_MouldMaintainRuleListByMould " + sWhere + " order by hmainid desc", "h_v_Sc_MouldMaintainRuleListByMould");
+                }
+                else
+                {
+                    string sql1 = "select * from h_v_Sc_MouldMaintainRuleListByMould where 1 = 1";
+                    string sql = sql1 + sWhere + " order by hmainid desc";
+                    ds = oCN.RunProcReturn(sql, "h_v_Sc_MouldMaintainRuleListByMould");
+                }
+
+                //娣诲姞鍒楀悕
+                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 ex)
             {
@@ -171,11 +244,11 @@
                 }
                 SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                 //鑾峰彇淇濆吇椤圭洰缂栬緫鏁版嵁
-                string sql = "select 淇濆吇椤圭洰ID,淇濆吇椤圭洰,淇濆吇閮ㄤ綅,鍏蜂綋瑕佹眰,璐熻矗浜篒D,璐熻矗浜轰唬鐮�,璐熻矗浜哄悕绉�,瀛愬娉�2 from h_v_Sc_MouldMaintainRuleBillList where 1 = 1 " + Swhere + "";
-                ds = oCN.RunProcReturn(sql, "h_v_Sc_MouldMaintainRuleBillList");
+                string sql = "select 淇濆吇椤圭洰ID,淇濆吇椤圭洰浠g爜,淇濆吇椤圭洰,淇濆吇閮ㄤ綅,鍏蜂綋瑕佹眰,璐熻矗浜篒D,璐熻矗浜轰唬鐮�,璐熻矗浜哄悕绉�,瀛愬娉�2 from  h_v_Sc_MouldMaintainRuleBillSub_Item where 1 = 1 " + Swhere + "";
+                ds = oCN.RunProcReturn(sql, "h_v_Sc_MouldMaintainRuleBillSub_Item");
                 //鑾峰彇閰嶄欢椤圭洰缂栬緫鏁版嵁
-                string sql1 = "select 閰嶄欢ID,閰嶄欢浠g爜,閰嶄欢鍚嶇О,鍗曚綅ID,璁¢噺鍗曚綅浠g爜,璁¢噺鍗曚綅鍚嶇О,鐢ㄩ噺,鏍囧噯鐢ㄩ噺,瀛愬娉�1 from h_v_Sc_MouldMaintainRuleBillList where 1 = 1 " + Swhere + "";
-                ds1 = oCN.RunProcReturn(sql1, "h_v_Sc_MouldMaintainRuleBillList");
+                string sql1 = "select 閰嶄欢ID,閰嶄欢浠g爜,閰嶄欢鍚嶇О,鍗曚綅ID,璁¢噺鍗曚綅浠g爜,璁¢噺鍗曚綅鍚嶇О,鐢ㄩ噺,鏍囧噯鐢ㄩ噺,瀛愬娉�1 from h_v_Sc_MouldMaintainRuleBillSub where 1 = 1 " + Swhere + "";
+                ds1 = oCN.RunProcReturn(sql1, "h_v_Sc_MouldMaintainRuleBillSub");
 
                 list.Add(ds.Tables[0]);
                 list.Add(ds1.Tables[0]);
@@ -203,7 +276,7 @@
             if (string.IsNullOrEmpty(HID))
                 return new ApiResult<DataSet> { code = -1, msg = "ID涓嶈兘涓虹┖" };
             SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
-            var dataSet = oCN.RunProcReturn("select top 1 * from Sc_MouldMaintainRuleBillMain  where HInterID= " + HID + " ", "Sc_MouldMaintainRuleBillMain");
+            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_Sc_MouldMaintainRuleBill_Edit  where HInterID= " + HID + " ", "h_v_Sc_MouldMaintainRuleBill_Edit");
             if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                 return new ApiResult<DataSet> { code = -1, msg = "涓嶅瓨鍦ㄥ櫒鍏蜂繚鍏昏绋嬭褰�" };
             return new ApiResult<DataSet> { code = 1, msg = "鏌ヨ鎴愬姛", data = dataSet };
@@ -231,11 +304,11 @@
                 }
                 SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                 //鑾峰彇淇濆吇椤圭洰缂栬緫鏁版嵁
-                string sql = "select 淇濆吇椤圭洰ID HMaintainItemID,淇濆吇椤圭洰浠g爜 HMaintainItemNumber,淇濆吇椤圭洰 HMaintainItem,淇濆吇閮ㄤ綅 HMaintainPart,鍏蜂綋瑕佹眰 HClaim,璐熻矗浜篒D HManagerID,璐熻矗浜轰唬鐮� HManagerNumber,璐熻矗浜哄悕绉� HManagerName,瀛愬娉�2 HRemark from h_v_Sc_MouldMaintainRuleBillList where 1 = 1 " + Swhere + "";
-                ds = oCN.RunProcReturn(sql, "h_v_Sc_MouldMaintainRuleBillList");
+                string sql = "select 淇濆吇椤圭洰ID HMaintainItemID,淇濆吇椤圭洰浠g爜 HMaintainItemNumber,淇濆吇椤圭洰 HMaintainItem,淇濆吇閮ㄤ綅 HMaintainPart,鍏蜂綋瑕佹眰 HClaim,璐熻矗浜篒D HManagerID,璐熻矗浜轰唬鐮� HManagerNumber,璐熻矗浜哄悕绉� HManagerName,瀛愬娉�2 HRemark from h_v_Sc_MouldMaintainRuleBillSub_Item where 1 = 1 " + Swhere + "";
+                ds = oCN.RunProcReturn(sql, "h_v_Sc_MouldMaintainRuleBillSub_Item");
                 //鑾峰彇閰嶄欢椤圭洰缂栬緫鏁版嵁
-                string sql1 = "select 閰嶄欢ID HMaterID,閰嶄欢浠g爜 HMaterNumber,閰嶄欢鍚嶇О HMaterName,鍗曚綅ID HUnitID,璁¢噺鍗曚綅浠g爜 HUnitNumber,璁¢噺鍗曚綅鍚嶇О HUnitName,鐢ㄩ噺 HQty,瀛愬娉�1 HRemark from h_v_Sc_MouldMaintainRuleBillList where 1 = 1 " + Swhere + "";
-                ds1 = oCN.RunProcReturn(sql1, "h_v_Sc_MouldMaintainRuleBillList");
+                string sql1 = "select 閰嶄欢ID HMaterID,閰嶄欢浠g爜 HMaterNumber,閰嶄欢鍚嶇О HMaterName,鍗曚綅ID HUnitID,璁¢噺鍗曚綅浠g爜 HUnitNumber,璁¢噺鍗曚綅鍚嶇О HUnitName,鐢ㄩ噺 HQty,瀛愬娉�1 HRemark from h_v_Sc_MouldMaintainRuleBillSub where 1 = 1 " + Swhere + "";
+                ds1 = oCN.RunProcReturn(sql1, "h_v_Sc_MouldMaintainRuleBillSub");
 
                 list.Add(ds.Tables[0]);
                 list.Add(ds1.Tables[0]);
@@ -271,9 +344,8 @@
             string msg2 = sArray[0].ToString();
             string msg3 = sArray[1].ToString();
             string msg4 = sArray[2].ToString();
-            string msg5 = sArray[2].ToString();
+            string msg5 = sArray[3].ToString();
 
-            string UserName = "";
             ListModels oListModels = new ListModels();
             try
             {
@@ -295,7 +367,7 @@
                 lsmain = oListModels.getObjectByJson_Sc_MouldMaintainRuleBillMain(msg2);
                 foreach (Model.ClsSc_MouldMaintainRuleBillMain oItem in lsmain)
                 {
-                    UserName = oItem.HMaker;  //鍒跺崟浜�
+                    DBUtility.ClsPub.CurUserName = oItem.HMaker;  //鍒跺崟浜�
                     oItem.HBillType = "3833";
                     oItem.HBillSubType = "3833";
 
@@ -404,5 +476,529 @@
             }
         }
         #endregion
+
+        #region 鍣ㄥ叿淇濆吇瑙勭▼瀹℃牳/鍙嶅鏍稿姛鑳�
+        [Route("Sc_MouldMaintainRuleBill/CheckSc_MouldMaintainRuleBill")]
+        [HttpGet]
+        public object CheckSc_MouldMaintainRuleBill(string HInterID, int Type, string user, string HBillSubType)
+        {
+            try
+            {
+                //鍒ゆ柇鏄惁鏈夊鏍告潈闄�
+                if (!DBUtility.ClsPub.Security_Log("Sc_MouldMaintainRuleBill_Check", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "娌℃湁瀹℃牳鏉冮檺!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+              
+                if (string.IsNullOrWhiteSpace(HInterID))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "HInterID涓虹┖锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                ClsPub.CurUserName = user;
+                BillOld.MvarItemKey = "Sc_MouldMaintainRuleBillMain";
+                oCN.BeginTran();//寮�濮嬩簨鍔�
+
+                //Type 1 瀹℃牳  2  鍙嶅鏍�
+                if (Type == 1)
+                {
+                    //鍒ゆ柇鍗曟嵁鏄惁宸茬粡瀹℃牳
+                    DataSet ds;
+                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
+                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
+                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
+                    {
+                        if (ds.Tables[0].Rows[0]["HChecker"] != null && ds.Tables[0].Rows[0]["HChecker"].ToString() != "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "鍗曟嵁宸插鏍�!涓嶉渶瑕佸啀瀹℃牳!";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+
+                    //瀹℃牳鍓嶆帶鍒�
+                    string HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
+                    sql = "exec h_p_Sc_MouldMaintainRuleBill_BeforeCheckCtrl " + int.Parse(HInterID) + ",'" + HBillNo + "','" + user + "'";
+                    ds = oCN.RunProcReturn(sql, "h_p_Sc_MouldMaintainRuleBill_BeforeCheckCtrl");
+                    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]["HRemark"].ToString(); ;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+
+                    //瀹℃牳鍗曟嵁
+                    if (!BillOld.CheckBill(Int64.Parse(HInterID), HBillNo, "h_p_Sc_MouldMaintainRuleBill_AfterCheckCtrl", user, ref ClsPub.sExeReturnInfo))
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+                else
+                {
+                    //鍒ゆ柇鍗曟嵁鏄惁宸茬粡鍙嶅鏍�
+                    DataSet ds;
+                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
+                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
+                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
+                    {
+                        if (ds.Tables[0].Rows[0]["HChecker"] == null || ds.Tables[0].Rows[0]["HChecker"].ToString() == "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "鍗曟嵁宸插弽瀹℃牳!涓嶉渶瑕佸啀鍙嶅鏍�!";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+
+                    //鍙嶅鏍稿墠鎺у埗
+                    string HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
+                    sql = "exec h_p_Sc_MouldMaintainRuleBill_BeforeUnCheckCtrl " + int.Parse(HInterID) + ",'" + HBillNo + "','" + user + "'";
+                    ds = oCN.RunProcReturn(sql, "h_p_Sc_MouldMaintainRuleBill_BeforeUnCheckCtrl");
+                    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]["HRemark"].ToString(); ;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    //鍙嶅鏍稿崟鎹�
+                    if (!BillOld.AbandonCheck(Int64.Parse(HInterID), HBillNo, "h_p_Sc_MouldMaintainRuleBill_AfterUnCheckCtrl", user, ref ClsPub.sExeReturnInfo))
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+
+                oCN.Commit();//鎻愪氦浜嬪姟
+
+                objJsonResult.code = "0";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鎵ц鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult; ;
+
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鎵ц澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鍣ㄥ叿淇濆吇瑙勭▼ 鏂囦欢瀵煎叆淇濆瓨
+        #region 鍣ㄥ叿淇濆吇瑙勭▼ 鏂囦欢涓婁紶
+        [Route("Sc_MouldMaintainRuleBill/Sc_MouldMaintainRuleBill_Excel")]
+        [HttpPost]
+        public object Sc_MouldMaintainRuleBill_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("HMaintainItemID", typeof(Int32));//淇濆吇椤圭洰ID
+                tb2.Columns.Add("HManagerID", typeof(Int32));//璐熻矗浜篒D
+                //娣诲姞鏁版嵁
+                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("淇濆吇椤圭洰浠g爜"))
+                    error += "娌℃湁鎵惧埌銆愪繚鍏婚」鐩唬鐮併�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("淇濆吇椤圭洰鍚嶇О"))
+                    error += "娌℃湁鎵惧埌銆愪繚鍏婚」鐩悕绉般�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("淇濆吇閮ㄤ綅"))
+                    error += "娌℃湁鎵惧埌銆愪繚鍏婚儴浣嶃�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鍏蜂綋瑕佹眰"))
+                    error += "娌℃湁鎵惧埌銆愬叿浣撹姹傘�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("璐熻矗浜轰唬鐮�"))
+                    error += "娌℃湁鎵惧埌銆愯礋璐d汉浠g爜銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("璐熻矗浜�"))
+                    error += "娌℃湁鎵惧埌銆愯礋璐d汉銆戠殑鏍囬,";
+
+                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 HName = "";
+                    string HNum = "";
+                    string HORGNumber = "";
+                    string HORGName = "";
+                    string HManagerName = "";
+                    string HManagerNumber = "";
+                    string HMaintainItemNumber = "";
+                    string HMaintainItemName = "";
+
+                    HName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["瑙勭▼缂栧彿"].ToString());
+                    HNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["瑙勭▼鍚嶇О"].ToString());
+                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐浠g爜"].ToString());
+                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐鍚嶇О"].ToString());
+                    HManagerNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["璐熻矗浜轰唬鐮�"].ToString());
+                    HManagerName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["璐熻矗浜�"].ToString());
+                    HMaintainItemNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["淇濆吇椤圭洰浠g爜"].ToString());
+                    HMaintainItemName = 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();
+                    }
+                    else
+                    {
+                        objJsonResult.code = CodeConstant.FAIL;
+                        objJsonResult.count = CountConstant.FAIL;
+                        objJsonResult.Message = "绗�" + index + "琛�,缁勭粐浠g爜涓虹┖";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //淇濆吇椤圭洰浠g爜
+                    if (HMaintainItemNumber != "")
+                    {
+                        //鏌ヨ缁勭粐
+                        ds = oCN.RunProcReturn("select * from Gy_Maintain where  HNumber='" + HMaintainItemNumber + "' and Hname='" + HMaintainItemName + "'", "Gy_Maintain");
+
+                        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]["HMaintainItemID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        string HMaintainItemID = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                    }
+                    else
+                    {
+                        objJsonResult.code = CodeConstant.FAIL;
+                        objJsonResult.count = CountConstant.FAIL;
+                        objJsonResult.Message = "绗�" + index + "琛�,淇濆吇椤圭洰浠g爜涓虹┖";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //璐熻矗浜轰唬鐮�
+                    if (HManagerNumber != "")
+                    {
+                        //鏌ヨ缁勭粐
+                        ds = oCN.RunProcReturn("select * from Gy_Employee where  HNumber='" + HManagerNumber + "' and Hname='" + HManagerName + "'", "Gy_Employee");
+
+                        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]["HManagerID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                    }
+                    //鍣ㄥ叿淇濆吇瑙勭▼鍚嶇О
+                    if (HName == "")
+                    {
+                        objJsonResult.code = CodeConstant.FAIL;
+                        objJsonResult.count = CountConstant.FAIL;
+                        objJsonResult.Message = "绗�" + index + "琛�,鍣ㄥ叿淇濆吇瑙勭▼鍚嶇О涓嶈兘涓虹┖锛�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    //鍣ㄥ叿淇濆吇瑙勭▼浠g爜
+                    if (HNum == "")
+                    {
+                        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("Sc_MouldMaintainRuleBill/Sc_MouldMaintainRuleBill_btnSave")]
+        [HttpPost]
+        public object Sc_MouldMaintainRuleBill_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("Sc_MouldMaintainRuleBill_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 HBillType = "3833";
+                    string HMaker = user;//鍒跺崟浜�
+                    DateTime HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --鏃ユ湡
+                    long HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
+                    long HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
+                    string HOrgID = item["HOrgID"].ToString();//缁勭粐ID
+                    string HName = item["瑙勭▼鍚嶇О"].ToString();
+                    string HBillNo = item["瑙勭▼缂栧彿"].ToString();
+                    string HCycleUnit = item["鍛ㄦ湡鍗曚綅"].ToString();
+                    string HCheckCycle = item["淇濆吇鍛ㄦ湡"].ToString();
+                    string HExplanation = item["鎽樿"].ToString();
+                    string HRemark = item["琛ㄥご澶囨敞"].ToString();
+                    //瀛愯〃
+                    string HMaintainItemID = item["HMaintainItemID"].ToString();//淇濆吇椤圭洰
+                    string HManagerID = item["HManagerID"].ToString() == "" ? "0" : item["HManagerID"].ToString();//璐熻矗浜�
+                    string HMaintainPart = item["淇濆吇閮ㄤ綅"].ToString();
+                    string HClaim = item["鍏蜂綋瑕佹眰"].ToString();
+                    string HSubRemark = item["琛ㄤ綋澶囨敞"].ToString();
+                    string HMaintainItem = item["淇濆吇椤圭洰鍚嶇О"].ToString();
+                    ds = oCN.RunProcReturn("select * from Sc_MouldMaintainRuleBillMain where HBillNo='" + HBillNo + "'", "Sc_MouldMaintainRuleBillMain");
+
+                    if (ds.Tables[0].Rows.Count == 0)
+                    {
+                        long HInterID = DBUtility.ClsPub.CreateBillID(HBillType, ref DBUtility.ClsPub.sExeReturnInfo);
+                        //鎻掑叆涓昏〃
+                        oCN.RunProc("Insert Into Sc_MouldMaintainRuleBillMain" +
+                         "(HBillType,HBillSubType,HInterID,HBillNo,HDate" +
+                        ",HYear,HPeriod,HRemark,HMaker,HMakeDate" +
+                        ",HCycleUnit,HCheckCycle,HExplanation,HInnerBillNo,HMaintainLevID,HUseQtys,HSafeDays,HErrWarDays,HErrWarQtys" +
+                        ") " +
+                        " values('" + HBillType + "','" + HBillType + "'," + HInterID + ",'" + HBillNo + "','" + HDate + "'" +
+                        ", " + HYear.ToString() + "," + HPeriod.ToString() + ",'" + HRemark + "','" + HMaker + "',getdate()" +
+                        ",'" + HCycleUnit + "'," + HCheckCycle.ToString() + ",'" + HExplanation + "','" + " " + "'," + 0 + "," + 0 + "," + 0 + "," + 0 + "," + 0 +
+                        ") ");
+                        //鎻掑叆瀛愯〃
+                        oCN.RunProc("Insert into Sc_MouldMaintainRuleBillSub_Item " +
+                          " (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark" +
+                          ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" +
+                          ",HMaintainItemID,HMaintainItem,HMaintainPart" +
+                          ",HClaim,HManagerID" +
+                          ") values("
+                          + HInterID.ToString() + "," + 1 + ",'" + "" + "'," + DateTime.Now.ToShortDateString() + "," + Convert.ToString(false ? 1 : 0) + ",'" + HSubRemark + "'" +
+                          "," + 0 + "," + 0 + ",'" + "" + "','" + "" + "'," + 0 + "," + 0 +
+                          "," + HMaintainItemID.ToString() + ",'" + HMaintainItem + "','" + HMaintainPart + "','" + HClaim + "'," + HManagerID.ToString() +
+                          ") ");
+                    }
+                    else
+                    {
+                        long HInterID = long.Parse(ds.Tables[0].Rows[0]["HInterID"].ToString());
+                        //鑾峰彇鏈�澶у瓙id
+                        DataSet ds2 = oCN.RunProcReturn("select max(HEntryID) HEntryID from Sc_MouldMaintainRuleBillSub_Item where HInterID='" + HInterID + "'", "Sc_MouldMaintainRuleBillSub_Item");
+                        long HEntryID = 1;
+                        if (ds2.Tables[0].Rows.Count > 0)
+                        {
+                             HEntryID = long.Parse(ds2.Tables[0].Rows[0]["HEntryID"].ToString())+1;
+                        }
+                            //鎻掑叆瀛愯〃
+                        oCN.RunProc("Insert into Sc_MouldMaintainRuleBillSub_Item " +
+                        " (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark" +
+                        ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" +
+                        ",HMaintainItemID,HMaintainItem,HMaintainPart" +
+                        ",HClaim,HManagerID" +
+                        ") values("
+                        + HInterID.ToString() + "," + HEntryID + ",'" + "" + "'," + DateTime.Now.ToShortDateString() + "," + Convert.ToString(false ? 1 : 0) + ",'" + HSubRemark + "'" +
+                        "," + 0 + "," + 0 + ",'" + "" + "','" + "" + "'," + 0 + "," + 0 +
+                        "," + HMaintainItemID.ToString() + ",'" + HMaintainItem + "','" + HMaintainPart + "','" + HClaim + "'," + HManagerID.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);
+                oCN.RollBack();
+                objJsonResult.code = CodeConstant.FAIL;
+                objJsonResult.count = CountConstant.FAIL;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+        #endregion
+
     }
 }

--
Gitblit v1.9.1