From d1b14d00d9ee4ff4a1b271e6b4fe094f5049a55f Mon Sep 17 00:00:00 2001
From: duhe <226547893@qq.com>
Date: 星期一, 17 三月 2025 09:23:16 +0800
Subject: [PATCH] 采购入库单:下推采购退料单

---
 WebAPI/Controllers/SBGL/Sb_EquipMaintainBillController.cs |  797 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 715 insertions(+), 82 deletions(-)

diff --git a/WebAPI/Controllers/SBGL/Sb_EquipMaintainBillController.cs b/WebAPI/Controllers/SBGL/Sb_EquipMaintainBillController.cs
index e735caf..74adc1b 100644
--- a/WebAPI/Controllers/SBGL/Sb_EquipMaintainBillController.cs
+++ b/WebAPI/Controllers/SBGL/Sb_EquipMaintainBillController.cs
@@ -1,8 +1,11 @@
-锘縰sing Newtonsoft.Json.Linq;
+锘縰sing Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
 using Pub_Class;
 using System;
 using System.Collections.Generic;
 using System.Data;
+using System.IO;
+using System.Web;
 using System.Web.Http;
 using WebAPI.Models;
 namespace WebAPI.Controllers
@@ -16,6 +19,8 @@
         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
         public DAL.ClsSb_EquipDotCheckBill BillNew = new DAL.ClsSb_EquipDotCheckBill();   //瀵瑰簲鍗曟嵁绫�
         public DAL.ClsSb_EquipDotCheckBill BillOld = new DAL.ClsSb_EquipDotCheckBill();   //瀵瑰簲鍗曟嵁绫�
+        public DAL.ClsSb_EquipMaintainBill BillOld2 = new DAL.ClsSb_EquipMaintainBill();   //璁惧淇濆吇璁板綍鍗�
+        string fileip = System.Configuration.ConfigurationManager.AppSettings["FileIP"];
 
         #region 璁惧淇濆吇璁″垝琛�
 
@@ -25,10 +30,19 @@
         /// <returns></returns>
         [Route("Sb_EquipMaintainBill/GetEquipMaintainBillList")]
         [HttpGet]
-        public object GetEquipMaintainBillList(string sWhere)
+        public object GetEquipMaintainBillList(string sWhere,string user)
         {
             try
             {
+                List<object> columnNameList = new List<object>();
+                if (!DBUtility.ClsPub.Security_Log("Sb_EquipMaintainBillList", 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_EquipMaintain " + sWhere + " order by hmainid desc", "h_v_Sc_EquipMaintain");
@@ -39,22 +53,32 @@
                     string sql = sql1 + sWhere + " order by hmainid desc";
                     ds = oCN.RunProcReturn(sql, "h_v_Sc_EquipMaintain");
                 }
-                if (ds == null || ds.Tables[0].Rows.Count == 0)
+
+                //娣诲姞鍒楀悕
+                foreach (DataColumn col in ds.Tables[0].Columns)
                 {
-                    objJsonResult.code = "0";
-                    objJsonResult.count = 0;
-                    objJsonResult.Message = "娌℃湁浣犺鎵剧殑璁板綍锛�";
-                    objJsonResult.data = null;
-                    return objJsonResult;
+                    Type dataType = col.DataType;
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
                 }
-                else
-                {
-                    objJsonResult.code = "1";
-                    objJsonResult.count = 1;
-                    objJsonResult.Message = "杩斿洖璁板綍鎴愬姛锛�";
-                    objJsonResult.data = ds.Tables[0];
-                    return objJsonResult;
-                }
+
+                //if (ds.Tables[0].Rows.Count != 0 || ds != null)
+                //{
+                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)
             {
@@ -65,6 +89,149 @@
                 return objJsonResult;
             }
         }
+
+        #region 璁惧淇濆吇璁板綍鍒嗛〉鏌ヨ
+        [Route("Sb_EquipMaintainBill/GetEquipMaintainBillListPage")]
+        [HttpGet]
+        public object GetEquipMaintainBillListPage(string sWhere, string user, int page, int size)
+        {
+            try
+            {
+                List<object> columnNameList = new List<object>();
+                //缂栬緫鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log_second("Sb_EquipMaintainBillList", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳煡鐪嬫潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                sWhere = sWhere.Replace("'", "''");
+                if (sWhere == null || sWhere.Equals(""))
+                {
+                    ds = oCN.RunProcReturn("exec h_p_Sc_EquipMaintainListPage " + page + "," + size + ",''", "h_p_Sc_EquipMaintainListPage");
+                }
+                else
+                {
+                    ds = oCN.RunProcReturn("exec h_p_Sc_EquipMaintainListPage " + page + "," + size + ",'" + sWhere + "'", "h_p_Sc_EquipMaintainListPage");
+                }
+
+                //娣诲姞鍒楀悕
+                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 璁惧淇濆吇璁板綍缁熻鍒嗘瀽 
+        /// <summary>
+        /// 杩斿洖璁惧淇濆吇璁板綍缁熻鍒嗘瀽 鍒楄〃
+        ///鍙傛暟锛歴tring sql銆�
+        ///杩斿洖鍊硷細object銆�
+        /// </summary>
+        [Route("Sb_EquipMaintainReport/Statistics")]
+        [HttpGet]
+        public object Statistics(string DateYear, string HType, string user)
+        {
+            try
+            {
+                List<object> columnNameList = new List<object>();
+
+                if (DateYear == null || DateYear.Equals(""))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "璇烽�夋嫨鏈夋晥骞翠唤";
+                    return objJsonResult;
+                }
+                else
+                {
+                    ds = oCN.RunProcReturn("exec h_p_Sb_EquipMaintainBillReport '" + DateYear + "','" + HType + "'", "h_p_Sb_EquipMaintainBillReport");
+                }
+
+                //娣诲姞鍒楀悕
+                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)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+
+        #region 璁惧璐熻嵎鍒嗘瀽琛� 
+        [Route("Sb_EquipMaintainReport/Sb_EquipmentLoadReportList")]
+        [HttpGet]
+        public object Sb_EquipmentLoadReportList(string HDeptID, string HWorkCenterID, string user)
+        {
+            try
+            {
+                List<object> columnNameList = new List<object>();
+
+                ds = oCN.RunProcReturn("exec h_p_Sb_EquipmentLoadReportListt '" + HDeptID + "','" + HWorkCenterID + "'", "h_p_Sb_EquipmentLoadReportListt");
+
+                //娣诲姞鍒楀悕
+                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;
+                objJsonResult.list = columnNameList;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
 
         #region sql璇彞
 
@@ -91,11 +258,20 @@
             string msg2 = sArray[0].ToString();
             string msg3 = sArray[1].ToString();
             string msg4 = sArray[2].ToString();
+            string msg5 = sArray[3].ToString();
 
             string UserName = "";
             ListModels oListModels = new ListModels();
             try
             {
+                if (!DBUtility.ClsPub.Security_Log("Sb_EquipMaintainBill_Edit", 1, false, msg5))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
                 DAL.ClsSb_EquipMaintainBill oBill = new DAL.ClsSb_EquipMaintainBill();
                 List<Model.ClsSb_EquipMaintainBillMain> lsmain = new List<Model.ClsSb_EquipMaintainBillMain>();
                 msg2 = msg2.Replace("\\", "");
@@ -165,7 +341,7 @@
                 msg4 = msg4.Substring(1, msg4.Length - 2);
                 msg4 = msg4.Replace("\\", "");
                 msg4 = msg4.Replace("\n", "");  //\n
-                //msg2 = msg2.Replace("'", "鈥�");
+                                                //msg2 = msg2.Replace("'", "鈥�");
                 List<Model.ClsSb_EquipMaintainBillSub> ls1 = new List<Model.ClsSb_EquipMaintainBillSub>();
                 ls1 = oListModels.getObjectByJson_Sb_EquipMaintainBillSub(msg4);
                 int j = 0;
@@ -177,11 +353,11 @@
                     //oItemSub.HCloseMan = "";       //琛屽叧闂�
                     oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                     oItemSub.HCloseType = false;   //鍏抽棴绫诲瀷
-                    //oItemSub.HRemark = "";         //澶囨敞
+                                                   //oItemSub.HRemark = "";         //澶囨敞
                     oItemSub.HSourceInterID = 0;     // 婧愬崟涓诲唴鐮�
                     oItemSub.HSourceEntryID = 0;   //婧愬崟瀛愬唴鐮�
-                    //oItemSub.HSourceBillNo = "";  //婧愬崟鍗曞彿
-                    //oItemSub.HSourceBillType = ""; //婧愬崟绫诲瀷
+                                                   //oItemSub.HSourceBillNo = "";  //婧愬崟鍗曞彿
+                                                   //oItemSub.HSourceBillType = ""; //婧愬崟绫诲瀷
                     oItemSub.HRelationQty = 0;     //鍏宠仈鏁伴噺
                                                    //oItemSub.HRelationMoney = 0;   //鍏宠仈閲戦
                                                    //HMaterID = "";//閰嶄欢浠g爜
@@ -240,17 +416,17 @@
         /// <returns></returns>
         [Route("Sb_EquipMaintainBill/DeltetEquipMaintainBillList")]
         [HttpGet]
-        public object DeltetEquipMaintainBillList(string HInterID)
+        public object DeltetEquipMaintainBillList(string HInterID,string user)
         {
             //缂栬緫鏉冮檺
-            //if (!DBUtility.ClsPub.Security_Log("Sb_MouldRepairWorkBill_Delete", 1, true, DBUtility.ClsPub.CurUserName))
-            //{
-            //    objJsonResult.code = "0";
-            //    objJsonResult.count = 0;
-            //    objJsonResult.Message = "鏃犲垹闄ゆ潈闄愶紒";
-            //    objJsonResult.data = null;
-            //    return objJsonResult;
-            //}
+            if (!DBUtility.ClsPub.Security_Log("Sb_EquipMaintainBill_Delete", 1, false, user))
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鏃犲垹闄ゆ潈闄愶紒";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
 
 
             Int64 lngBillKey = 0;
@@ -283,7 +459,29 @@
                     return objJsonResult;
                 }
 
-                bool IsDete = oBill.DeleteBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
+                //鍒犻櫎鍓嶆帶鍒�
+                DataSet BeforeDs = oCN.RunProcReturn("Exec h_p_Sb_EquipMaintainBill_BeforeDelCtrl " + HInterID.ToString() + ",'" + user + "'", "h_p_Sb_EquipMaintainBill_BeforeDelCtrl");
+                if (BeforeDs == null || BeforeDs.Tables[0].Rows.Count == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍒犻櫎鍓嶅垽鏂け璐ワ紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                else
+                {
+                    if (DBUtility.ClsPub.isLong(BeforeDs.Tables[0].Rows[0]["HBack"]) == 1)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鍒犻櫎澶辫触锛�" + DBUtility.ClsPub.isStrNull(BeforeDs.Tables[0].Rows[0]["HRemark"]);
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+
+                bool IsDete = oBill.DeleteBill(oBill.omodel.HInterID, oBill.omodel.HBillNo, "h_p_Sb_EquipMaintainBill_AfterDelCtrl", user, ref DBUtility.ClsPub.sExeReturnInfo);
                 if (IsDete)
                 {
                     objJsonResult.code = "0";
@@ -390,7 +588,7 @@
                 }
                 SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                 //鑾峰彇淇濆吇椤圭洰缂栬緫鏁版嵁
-                string sql = "select 淇濆吇椤圭洰ID HMaintainItemID, 淇濆吇椤圭洰浠g爜 HMaintainItemNumber,淇濆吇椤圭洰鍚嶇О HMaintainItem,淇濆吇閮ㄤ綅 HMaintainPart,鍏蜂綋瑕佹眰 HClaim,HManagerID,璐熻矗浜轰唬鐮� HManagerNumber,璐熻矗浜� HManagerName,琛ㄤ綋澶囨敞 HRemark  from h_v_Sb_EquipMaintainBillSub_Item where 1 = 1 " + Swhere + "";
+                string sql = "select 淇濆吇椤圭洰ID HMaintainItemID, 淇濆吇椤圭洰浠g爜 HMaintainItemNumber,淇濆吇椤圭洰鍚嶇О HMaintainItem,淇濆吇閮ㄤ綅 HMaintainPart,鍏蜂綋瑕佹眰 HClaim,HManagerID,璐熻矗浜轰唬鐮� HManagerNumber,璐熻矗浜� HManagerName,琛ㄤ綋澶囨敞 HRemark,淇濆吇缁撴灉 HMaintainResult  from h_v_Sb_EquipMaintainBillSub_Item where 1 = 1 " + Swhere + "";
                 ds = oCN.RunProcReturn(sql, "h_v_Sb_EquipMaintainBillSub_Item");
                 //鑾峰彇閰嶄欢椤圭洰缂栬緫鏁版嵁
                 string sql1 = "select HMaterID, 閰嶄欢浠g爜 HMaterNumber,閰嶄欢鍚嶇О HMaterName,鍗曚綅ID HUnitID,鍗曚綅浠g爜 HUnitNumber,鍗曚綅鍚嶇О HUnitName,瀹為檯鐢ㄩ噺 HQty,鏍囧噯鐢ㄩ噺 HQtyMust,琛ㄤ綋澶囨敞 HRemark,璐熻矗浜篒D HManagerID,璐熻矗浜轰唬鐮� HManagerNumber,璐熻矗浜� HManagerName  from h_v_Sb_EquipMaintainBillList where 1 = 1 " + Swhere + "";
@@ -438,7 +636,7 @@
                     return objJsonResult;
                 }
                 //寰楀埌淇℃伅
-                ds = oCN.RunProcReturn("select top 1 * from Gy_EquipMent  where HNumber= '" + HBarCode + "'", "Gy_EquipMent");
+                ds = oCN.RunProcReturn("select top 1 * from Gy_EquipFileBillMain  where HEquipFileNumber= '" + HBarCode + "'", "Gy_EquipFileBillMain");
                 //鍐欏叆淇℃伅
                 if (ds == null || ds.Tables[0].Rows.Count == 0)
                 {
@@ -475,49 +673,39 @@
             string msg1 = _value.ToString();
             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
             string msg2 = sArray[0].ToString();
+            string msg3 = sArray[1].ToString();
 
             string UserName = "";
 
             ListModels oListModels = new ListModels();
             try
             {
-                DLL.ClsSb_EquipMaintainBill oBill = new DLL.ClsSb_EquipMaintainBill();
-                List<Models.ClsSb_EquipMaintainBillMain > lsmain = new List<Models.ClsSb_EquipMaintainBillMain>();
+                DAL.ClsSb_EquipMaintainBill oBill = new DAL.ClsSb_EquipMaintainBill();
+                List<Model.ClsSb_EquipMaintainBillMain> lsmain = new List<Model.ClsSb_EquipMaintainBillMain>();
                 msg2 = msg2.Replace("\\", "");
                 msg2 = msg2.Replace("\n", "");  //\n
-                lsmain = oListModels.getObjectByJson_Sb_EquipMaintainBillMainPDA(msg2);
-                foreach (Models.ClsSb_EquipMaintainBillMain oItem in lsmain)
+                lsmain = oListModels.getObjectByJson_Sb_EquipMaintainBillMain(msg2);
+                foreach (Model.ClsSb_EquipMaintainBillMain oItem in lsmain)
                 {
-                    //鍗曟嵁鍙锋槸鍚﹂噸澶�
-                    if (BillNew.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, BillOld.omodel.HInterID))
-                    {
-                        objJsonResult.code = "0";
-                        objJsonResult.count = 0;
-                        objJsonResult.Message = "鍗曟嵁鍙烽噸澶嶏紒涓嶅厑璁镐繚瀛橈紒";
-                        objJsonResult.data = 1;
-                        return objJsonResult;
-                    }
-
                     //oItem.HMaker = "";
-                    UserName = oItem.HMaker;  //鍒跺崟浜�
+                    DBUtility.ClsPub.CurUserName = oItem.HMaker;  //鍒跺崟浜�
                     oItem.HBillType = "3901";
                     oItem.HBillSubType = "3901";
-                    //oItem.HBillNo = "";    //鍗曟嵁鍙�
-                    //oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --鏃ユ湡
-                    //oItem.HInnerBillNo = "";  //  --鍐呴儴鍗曟嵁鍙�
-                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
-                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
-                    //oItem.HEquipID = 0;    //璁惧ID(Gy_EquipMent)
-                    //oItem.HPeriod = 0;
-                    //oItem.HCheckBeginDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));  //  --缁翠慨鏃ユ湡
-                    //oItem.HCheckResult = "";     //楠屾敹缁撹--(姝e父锛屽紓甯�)
-                    //oItem.HEmpID = 0;           //楠屾敹浜�(Gy_Employee)
-                    //oItem.HManagerID = 0;      //璐熻矗浜�(Gy_Employee)
-                    //oItem.HDeptID = 0;        //楠屾敹閮ㄩ棬(Gy_Department)
-                    //oItem.HExplanation = "";  //鎽樿(鏁呴殰鎻忚堪)  
-                    //oItem.HRemark = "";       //澶囨敞
 
-                    //oItem.HMainSourceInterID = oItem.HInterID;
+                    //oItem.HInterID =0;
+                    //oItem.HBillNo = "";
+                    oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --鏃ユ湡
+                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
+                    //oItem.HMakeDate = "";
+                    //oItem.HYear = "";
+                    //oItem.HPeriod = "";
+                    //oItem.HRemark = "";
+                    //oItem.HCycleUnit = "";
+                    //oItem.HCheckCycle = "";
+                    //oItem.HBeginDate = "";
+                    //oItem.HEndDate = "";
+                    //oItem.HInnerBillNo = "";
+                    //oItem.HExplanation = "";
 
                     //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
                     if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
@@ -530,34 +718,30 @@
                     }
                     oBill.omodel = oItem;
                 }
-                //瀛愯〃浣撴暟鎹�
-
-                List<Models.ClsSb_EquipMaintainBillSub> ls = new List<Models.ClsSb_EquipMaintainBillSub>();
-                ls = oListModels.getObjectByJson_Sb_EquipMaintainBillSubPDA(msg2);
+                //淇濆吇椤硅〃浣撴暟鎹�
+                //鎸� },{鏉ユ媶鍒嗘暟缁� //鍘绘帀銆愬拰銆�
+                msg3 = msg3.Substring(1, msg3.Length - 2);
+                msg3 = msg3.Replace("\\", "");
+                msg3 = msg3.Replace("\n", "");  //\n
+                //msg2 = msg2.Replace("'", "鈥�");
+                List<Model.ClsSc_EquipMaintainBillSub_Item> ls = new List<Model.ClsSc_EquipMaintainBillSub_Item>();
+                ls = oListModels.getObjectByJson_Sc_EquipMaintainBillSub_Item(msg3);
                 int i = 0;
-                foreach (Models.ClsSb_EquipMaintainBillSub oItemSub in ls)
+                foreach (Model.ClsSc_EquipMaintainBillSub_Item item in ls)
                 {
 
                     i++;
-                    oItemSub.HEntryID = i;
-
-                    //oItemSub.HRepairCheckID = 0;   //楠屾敹椤圭洰ID
-                    //oItemSub.HRepairCheckContent = ""; //楠屾敹鍐呭
-                    //oItemSub.HManagerID = 0;   //璐熻矗浜篒D
+                    item.HEntryID = i;
                     //oItemSub.HCloseMan = "";       //琛屽叧闂�
-                    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
-                    oItemSub.HCloseType = false;   //鍏抽棴绫诲瀷
+                    item.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
+                    item.HCloseType = false;   //鍏抽棴绫诲瀷
                     //oItemSub.HRemark = "";         //澶囨敞
-                    oItemSub.HSourceInterID = 0;     // 婧愬崟涓诲唴鐮�
-                    oItemSub.HSourceEntryID = 0;   //婧愬崟瀛愬唴鐮�
+                    //item.HSourceInterID = 0;     // 婧愬崟涓诲唴鐮�
+                    //item.HSourceEntryID = 0;   //婧愬崟瀛愬唴鐮�
                     //oItemSub.HSourceBillNo = "";  //婧愬崟鍗曞彿
                     //oItemSub.HSourceBillType = ""; //婧愬崟绫诲瀷
-                    //oItemSub.HRelationQty = 0;     //鍏宠仈鏁伴噺
-                    //oItemSub.HRelationMoney = 0;   //鍏宠仈閲戦 
-                    //oItemSub.HRepairID = 0;       //缁翠慨椤圭洰
-                    //oItemSub.HRepairExplanation ="";   //缁翠慨瑕佹眰
-                    //oItemSub.HMoney = 0;        //缁翠慨璐圭敤
-                    oBill.DetailColl.Add(oItemSub);
+                    item.HRelationQty = 0;     //鍏宠仈鏁伴噺
+                    oBill.DetailCol.Add(item);
 
                 }
                 //淇濆瓨
@@ -601,6 +785,455 @@
         }
         #endregion
 
+
+        #region 璁惧淇濆吇璁板綍鍗曞鏍�/鍙嶅鏍稿姛鑳�
+        [Route("Sb_EquipMaintainBill/CheckSb_EquipMaintainBill")]
+        [HttpGet]
+        public object CheckSb_EquipMaintainBill(string HInterID, int Type, string user)
+        {
+            string sql = "";
+            try
+            {
+                //鍒ゆ柇鏄惁鏈夊垹闄ゆ潈闄�
+                if (!DBUtility.ClsPub.Security_Log("Sb_EquipMaintainBill_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;
+                ds = oCN.RunProcReturn("select * from Sb_EquipMaintainBillMain where HInterID = " + int.Parse(HInterID), "Sb_EquipMaintainBillMain");
+                string HBillNo = "";
+                if (ds == null || ds.Tables[0].Rows.Count == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍗曟嵁涓嶅瓨鍦�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                else
+                {
+                    HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
+                }
+
+                oCN.BeginTran();//寮�濮嬩簨鍔�
+
+                //Type 1 瀹℃牳  2  鍙嶅鏍�
+                if (Type == 1)
+                {
+                    //瀹℃牳鍓嶆帶鍒�
+                    sql = "exec h_p_Sb_EquipMaintainBill_BeforeCheckCtrl " + int.Parse(HInterID) + ",'" + HBillNo + "','" + user + "'";
+                    ds = oCN.RunProcReturn(sql, "h_p_Sb_EquipMaintainBill_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 (!BillOld2.CheckBill(int.Parse(HInterID), HBillNo, "h_p_Sb_EquipMaintainBill_AfterCheckCtrl", user, ref ClsPub.sExeReturnInfo))
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+                else
+                {
+                    //鍙嶅鏍稿墠鎺у埗
+                    sql = "exec h_p_Sb_EquipMaintainBill_BeforeUnCheckCtrl " + int.Parse(HInterID) + ",'" + HBillNo + "','" + user + "'";
+                    ds = oCN.RunProcReturn(sql, "h_p_Sb_EquipMaintainBill_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 (BillOld2.AbandonCheck(int.Parse(HInterID), HBillNo, "h_p_Sb_EquipMaintainBill_AfterUnCheckCtrl", user, ref ClsPub.sExeReturnInfo))
+                    {
+                        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
+
+                    }
+                    else
+                    {
+                        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 璁惧淇濆吇璁板綍鍗曞叧闂�/鍙嶅叧闂姛鑳�
+        [Route("Sb_EquipMaintainBill/CloseSb_EquipMaintainBill")]
+        [HttpGet]
+        public object CloseSb_EquipMaintainBill(string HInterID, int Type, string user)
+        {
+            try
+            {
+                //鍒ゆ柇鏄惁鏈夊垹闄ゆ潈闄�
+                if (!DBUtility.ClsPub.Security_Log("Sb_EquipMaintainBill_Close", 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;
+
+                oCN.BeginTran();//寮�濮嬩簨鍔�
+
+                //Type 1 鍏抽棴  2  鍙嶅叧闂�
+                if (Type == 1)
+                {
+                    if (!BillOld2.CloseBill(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "鍏抽棴澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+                else
+                {
+                    if (!BillOld2.CancelClose(int.Parse(HInterID), 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
+
+        #endregion
+
+        #region 璁惧淇濆吇閫炬湡棰勮鎶ヨ〃
+
+        [Route("Sb_EquipMaintainWarning/Report")]
+        [HttpGet]
+        public object Report(string HYear, string HEquipTypeID, string user)
+        {
+            try
+            {
+                List<object> columnNameList = new List<object>();
+                //if (!DBUtility.ClsPub.Security_Log("Gy_EquipFileList", 1, false, user))
+                //{
+                //    objJsonResult.code = "0";
+                //    objJsonResult.count = 0;
+                //    objJsonResult.Message = "娌℃湁鏌ョ湅鏉冮檺";
+                //    objJsonResult.data = null;
+                //    return objJsonResult;
+                //}
+                if (HYear == null || HYear.Equals(""))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "璇烽�夋嫨鏈夋晥骞翠唤";
+                    objJsonResult.data = "";
+                    objJsonResult.list = columnNameList;
+                    return objJsonResult;
+                }
+                else
+                {
+                    string sql = "exec h_p_Sb_EquipMaintainWarningReport " + HYear + "," + HEquipTypeID;
+                    ds = oCN.RunProcReturn(sql, "h_p_Sb_EquipMaintainWarningReport");
+                }
+
+                //娣诲姞鍒楀悕
+                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)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 璁惧淇濆吇璁板綍鎷嶇収涓婁紶
+        [Route("Sb_EquipMaintainBill/UploadFile")]
+        [HttpPost]
+        public object UploadFile()
+        {
+
+            string HBillNo = HttpContext.Current.Request.Params["HBillNo"];  //鍗曟嵁鍙�
+            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/EquipFolder/" + HBillNo);
+            //string path = @"D:\\Files\\"+ HBillNo;
+            dynamic dyResult = UpLoadFile(files, path, HBillNo, 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 HBillNo, 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 ='" + HBillNo + "' and HFileName='" + filename + "'", "MES_AccessoriesList");
+                if (Directory.Exists(path))
+                {
+                    File.Delete(fileurl);      //鍒犻櫎鎸囧畾鏂囦欢
+                    files.SaveAs(fileurl);
+                    string StrPath = "/files/EquipFolder/" + HBillNo + "/" + 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 + "','" + HBillNo +
+                                   "') ");
+                    }
+                    else
+                    {
+                        Result_Ob = new { result = 0, returnval = "涓婁紶澶辫触锛佹鏂囦欢涓烘伓鎰忔枃浠�" };
+                    }
+                }
+                else
+                {
+                    Directory.CreateDirectory(fileSavePath); //娣诲姞鏂囦欢澶�
+                    files.SaveAs(fileurl);
+                    string StrPath = "/files/EquipFolder/" + HBillNo + "/" + 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 + "','" + HBillNo +
+                                   "') ");
+                    }
+                    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("Sb_EquipMaintainBill/Filelist")]
+        [HttpGet]
+        public object Filelist(string HBillNo)
+        {
+            var url = fileip + "/files/EquipFolder/" + HBillNo + "/";
+            //@"C:\\files\\"
+            try
+            {
+                ds = oCN.RunProcReturn("select *,'" + url + "'+CAST(HFileName as varchar(200))as url  from MES_AccessoriesList where HSourceBillNo='" + HBillNo + "'", "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("Sb_EquipMaintainBill/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/EquipFolder/" + 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    
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1