From f9ef44a67fbf73f073efe65600bc25e204fde04f Mon Sep 17 00:00:00 2001
From: ch <37327@LLOOCCY>
Date: 星期一, 30 五月 2022 17:38:41 +0800
Subject: [PATCH] Merge branch 'master' of http://101.37.171.70:10101/r/MES-WEB-API

---
 WebAPI/Controllers/SCGL/日计划管理/JIT_DayPlanPlatFormImportController.cs |  364 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 355 insertions(+), 9 deletions(-)

diff --git "a/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormImportController.cs" "b/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormImportController.cs"
index 9705a9f..3d73e5b 100644
--- "a/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormImportController.cs"
+++ "b/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormImportController.cs"
@@ -1,9 +1,13 @@
-锘縰sing System;
+锘縰sing Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
 using System.Collections.Generic;
 using System.Data;
+using System.IO;
 using System.Linq;
 using System.Web;
 using System.Web.Http;
+using System.Web.Script.Serialization;
 using WebAPI.Models;
 
 namespace WebAPI.Controllers.SCGL.鏃ヨ鍒掔鐞�
@@ -14,25 +18,161 @@
         public DataSet ds = new DataSet();
         public WebServer webserver = new WebServer();
         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
+        public static string BillType = "4610";
+        Sc_WorkBillSortBillMain omdelMian = new Sc_WorkBillSortBillMain();
 
-        #region 鐢熶骇鏃ヨ鍒掑鍏�
+        #region 鐢熶骇鏃ヨ鍒� 鏂囦欢涓婁紶
         [Route("JIT_DayPlanPlatFormImport/JIT_DayPlanPlatFormImport_DR")]
         [HttpPost]
-        public object JIT_DayPlanPlatFormImport_DR(HttpPostedFileBase file)
+        public object JIT_DayPlanPlatFormImport_DR()
         {
             try
             {
-                if (file != null)
+                //鑾峰彇鏂囦欢鍚嶇О
+                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);
+
+                //鍒犻櫎鏂囦欢
+                File.Delete(ExcelPath);
+
+                //鍒涘缓涓存椂琛�
+                DataTable tb2 = new DataTable("dt2");
+                DataTable tb3 = new DataTable("dt3");
+
+                //娣诲姞鍒楀悕
+                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
                 {
-                    NpoiHelper np = new NpoiHelper();
-                    DataSet ds = np.ReadExcel(@"C:\Users\Harold\Desktop\鏂板缓XLS宸ヤ綔琛�.xls", 1);
-                    DataTable dt = ds.Tables[0];
+                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
+                }
+                //妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁
+                tb2.Columns.Add("hmainid", typeof(Int32));
+                tb2.Columns.Add("HMaterID", typeof(Int32));//鐗╂枡ID
+                tb2.Columns.Add("鍗曟嵁鍙�", typeof(string));
+                tb2.Columns.Add("HWorkShopID", typeof(Int32));//鐢熶骇杞﹂棿
+                tb2.Columns.Add("HEmpID", typeof(Int32));//鑱屽憳
+                tb2.Columns.Add("HUnitID", typeof(Int32));//璁¢噺鍗曚綅
+                tb2.Columns.Add("HSourceID", typeof(Int32));//鐢熶骇璧勬簮id
+                tb2.Columns.Add("ICMOBillHInterID", typeof(Int32));//鐢熶骇璁㈠崟涓籭d
+                tb2.Columns.Add("ICMOBillHEntryID", 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);
+                }
+
+                ExcelDs.Tables.Add(tb2);
+
+                var error = "";
+                var ErrorResult = "";
+
+                //鏌ヨ鐢熶骇璁㈠崟琛ㄥ垽鏂湁娌℃湁鐢熶骇璁㈠崟淇℃伅
+                for (int i = 0; i < tb2.Rows.Count; i++)
+                {
+                    if (tb2.Rows[i]["缁勭粐缂栫爜*"].ToString() == "")
+                        error += "缁勭粐缂栫爜涓嶈兘涓虹┖;";
+                    if (tb2.Rows[i]["鐢熶骇璁㈠崟鍙�*"].ToString() == "")
+                        error += "鐢熶骇璁㈠崟鍙蜂笉鑳戒负绌�;\n";
+                    if (tb2.Rows[i]["鐢熶骇璁㈠崟鏄庣粏琛屽彿*"].ToString() == "")
+                        error += "鐢熶骇璁㈠崟鏄庣粏琛屽彿涓嶈兘涓虹┖;";
+                    if (tb2.Rows[i]["鐢熶骇杞﹂棿缂栫爜*"].ToString() == "")
+                        error += "鐢熶骇杞﹂棿缂栫爜涓嶈兘涓虹┖;";
+                    if (tb2.Rows[i]["鐢熶骇璧勬簮缂栫爜*"].ToString() == "")
+                        error += "鐢熶骇璧勬簮缂栫爜涓嶈兘涓虹┖;";
+                    if (tb2.Rows[i]["鐗╂枡缂栫爜*"].ToString() == "")
+                        error += "鐗╂枡缂栫爜涓嶈兘涓虹┖;";
+
+                    if (error.Length > 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = ErrorResult += $"Excel妯℃澘瀛樺湪閿欒锛岃鏁皗i + 1}:{error}\r\n"; ;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    string sql1 = string.Format("select * from h_v_IF_ICMOBillList where 鍗曟嵁鍙�='{0}' and 鐢熶骇杞﹂棿浠g爜='{1}' and 浜у搧浠g爜='{2}' and 鏄庣粏琛屽彿={3} ",
+                        tb2.Rows[i]["鐢熶骇璁㈠崟鍙�*"].ToString(), tb2.Rows[i]["鐢熶骇杞﹂棿缂栫爜*"].ToString(), tb2.Rows[i]["鐗╂枡缂栫爜*"].ToString(), tb2.Rows[i]["鐢熶骇璁㈠崟鏄庣粏琛屽彿*"].ToString());
+                    ds = oCN.RunProcReturn(sql1, "h_v_IF_ICMOBillList");
+
+                    if (ds.Tables[0].Rows.Count == 0)
+                        error += $"娌℃湁鐢熶骇璁㈠崟淇℃伅锛岀敓浜ц鍗曞彿:{ tb2.Rows[i]["鐢熶骇璁㈠崟鍙�*"].ToString()},鐢熶骇杞﹂棿缂栫爜:{tb2.Rows[i]["鐢熶骇杞﹂棿缂栫爜*"].ToString()}" +
+                            $",鐢熶骇璁㈠崟鏄庣粏琛屽彿:{ tb2.Rows[i]["鐢熶骇璁㈠崟鏄庣粏琛屽彿*"].ToString()},鐗╂枡缂栫爜:{ tb2.Rows[i]["鐗╂枡缂栫爜*"].ToString()}";
+
+                    if (error.Length > 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = ErrorResult += $"Excel妯℃澘瀛樺湪閿欒锛岃鏁皗i + 1}:{error}\r\n"; ;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    else
+                    {
+                        tb2.Rows[i]["HMaterID"] = ds.Tables[0].Rows[0]["HMaterID"].ToString();
+                        tb2.Rows[i]["鐗╂枡鍚嶇О"] = ds.Tables[0].Rows[0]["浜у搧鍚嶇О"].ToString();
+                        tb2.Rows[i]["瑙勬牸鍨嬪彿"] = ds.Tables[0].Rows[0]["瑙勬牸鍨嬪彿"].ToString();
+                        tb2.Rows[i]["HWorkShopID"] = ds.Tables[0].Rows[0]["HDeptID"].ToString();
+                        tb2.Rows[i]["ICMOBillHInterID"] = ds.Tables[0].Rows[0]["hmainid"].ToString();//鐢熶骇璁㈠崟涓籭d
+                        tb2.Rows[i]["ICMOBillHEntryID"] = ds.Tables[0].Rows[0]["HEntryID"].ToString();//鐢熶骇璁㈠崟瀛恑d
+                        tb2.Rows[i]["鐢熶骇璁㈠崟鏁伴噺"] = ds.Tables[0].Rows[0]["鐢熶骇浠诲姟鍗曟暟閲�"].ToString();//鐢熶骇璁㈠崟鏁伴噺
+                    }
+
+                    ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkBillSortBillList " +
+                        $"where  鐢熶骇璁㈠崟鍙�='{tb2.Rows[i]["鐢熶骇璁㈠崟鍙�*"].ToString()}'  and 鐢熶骇璁㈠崟鏄庣粏琛屽彿='{tb2.Rows[i]["鐢熶骇璁㈠崟鏄庣粏琛屽彿*"].ToString()}' " +
+                        $"and 鐢熶骇杞﹂棿缂栫爜='{tb2.Rows[i]["鐢熶骇杞﹂棿缂栫爜*"].ToString()}' and 鐗╂枡浠g爜='{tb2.Rows[i]["鐗╂枡缂栫爜*"].ToString()}' " +
+                        $"and 鐢熶骇璧勬簮缂栫爜='{tb2.Rows[i]["鐢熶骇璧勬簮缂栫爜*"].ToString()}' ", "h_v_JIT_Sc_WorkBillSortBillList");
+                    //缁勭粐缂栫爜='{tb2.Rows[i]["缁勭粐缂栫爜*"].ToString()}' and
+                    //and 鐢熶骇璧勬簮缂栫爜='{tb2.Rows[i]["鐢熶骇璧勬簮缂栫爜*"].ToString()}'
+
+                    if (ds.Tables[0].Rows.Count > 0)
+                    {
+                        tb2.Rows[i]["hmainid"] = ds.Tables[0].Rows[0]["hmainid"].ToString();
+                        tb2.Rows[i]["鍗曟嵁鍙�"] = ds.Tables[0].Rows[0]["鍗曟嵁鍙�"].ToString();
+                        tb2.Rows[i]["浼樺厛绾�"] = ds.Tables[0].Rows[0]["浼樺厛绾�"].ToString();
+                        tb2.Rows[i]["HSourceID"] = ds.Tables[0].Rows[0]["HSourceID"].ToString();
+                        tb2.Rows[i]["HEmpID"] = ds.Tables[0].Rows[0]["HEmpID"].ToString();
+                        tb2.Rows[i]["鍛樺伐缂栫爜"] = ds.Tables[0].Rows[0]["鑱屽憳浠g爜"].ToString();
+                        tb2.Rows[i]["HUnitID"] = ds.Tables[0].Rows[0]["HUnitID"].ToString();
+                        tb2.Rows[i]["璁¢噺鍗曚綅"] = ds.Tables[0].Rows[0]["璁¢噺鍗曚綅"].ToString();
+                        tb2.Rows[i]["鎵规鍙�"] = ds.Tables[0].Rows[0]["鎵规"].ToString();
+                        tb2.Rows[i]["閿�鍞鍗曟暟閲�"] = ds.Tables[0].Rows[0]["閿�鍞鍗曟暟閲�"].ToString();
+                        tb2.Rows[i]["鎬婚綈濂楁暟閲�"] = ds.Tables[0].Rows[0]["榻愬鏁伴噺"].ToString();
+                    }
+                    else
+                    {
+                        //鍛樺伐
+                        ds = oCN.RunProcReturn($"select * from Gy_Employee  where HNumber='{tb2.Rows[i]["鍛樺伐缂栫爜"].ToString()}'", "Gy_Employee");
+                        if (ds.Tables[0].Rows.Count > 0)
+                            tb2.Rows[i]["鍛樺伐缂栫爜"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+
+                        //璁¢噺鍗曚綅
+                        ds = oCN.RunProcReturn($"select * from Gy_Unit  where HNumber='{tb2.Rows[i]["璁¢噺鍗曚綅"].ToString()}'", "Gy_Unit");
+                        if (ds.Tables[0].Rows.Count > 0)
+                            tb2.Rows[i]["HUnitID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+
+                        //鐢熶骇璧勬簮
+                        ds = oCN.RunProcReturn($"select * from Gy_Source  where HNumber='{tb2.Rows[i]["鐢熶骇璧勬簮缂栫爜*"].ToString()}'", "Gy_Source");
+                        if (ds.Tables[0].Rows.Count > 0)
+                            tb2.Rows[i]["HSourceID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                    }
                 }
 
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
-                objJsonResult.Message = "Sucess锛�";
-                objJsonResult.data = ds.Tables[0];
+                objJsonResult.Message = ErrorResult;
+                objJsonResult.data = tb2;
                 return objJsonResult;
             }
             catch (Exception e)
@@ -45,5 +185,211 @@
             }
         }
         #endregion
+
+        #region 鐢熶骇鏃ヨ鍒� 瀵煎叆(淇濆瓨)
+        [Route("JIT_DayPlanPlatFormImport/JIT_DayPlanPlatFormImport_btnSave")]
+        [HttpPost]
+        public object JIT_DayPlanPlatFormImport_btnSave([FromBody] JObject sMainSub)
+        {
+            var _value = sMainSub["sMainSub"].ToString();
+            string msg1 = _value.ToString();
+            oCN.BeginTran();
+            //淇濆瓨涓昏〃
+            objJsonResult = AddBillMain(msg1);
+            if (objJsonResult.code == "0")
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = objJsonResult.Message;
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            oCN.Commit();
+            objJsonResult.code = "1";
+            objJsonResult.count = 1;
+            objJsonResult.Message = "鍗曟嵁淇濆瓨鎴愬姛锛�";
+            objJsonResult.data = null;
+            return objJsonResult;
+        }
+
+        public json AddBillMain(string msg1)
+        {
+            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+            string msg2 = sArray[0].ToString();
+            string msg3 = sArray[1].ToString();
+            string user = sArray[2].ToString();
+
+            try
+            {
+                if (!DBUtility.ClsPub.Security_Log("Sc_WorkBillSortBill_Edit", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                //琛ㄥご瀛楁
+                omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject<Sc_WorkBillSortBillMain>(msg2);
+
+                //JSON搴忓垪鍖栬浆鎹㈠瓧鍏搁泦鍚�
+                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
+                List<object> jb = JsonConvert.DeserializeObject<List<object>>(msg3);
+                foreach (JObject item in jb)
+                {
+                    Dictionary<string, string> dic = new Dictionary<string, string>();
+                    foreach (var itm in item.Properties())
+                    {
+                        dic.Add(itm.Name, itm.Value.ToString());
+                    }
+                    list.Add(dic);
+                }
+
+              
+                int TrueCount = 0, SumCount = 0;
+
+                for (int i = 0; i < list.Count; i++)
+                {
+                    long HInterID = 0;
+                    var HBillNo = "";
+                    if (list[i]["鍗曟嵁鍙�"].ToString() == "" && list[i]["hmainid"].ToString() == "")
+                    {
+                        HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true);//鑾峰緱涓�涓柊鐨勫崟鎹彿
+                        HInterID = DBUtility.ClsPub.CreateBillID_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo);//鑾峰緱涓�涓柊鐨刬d
+                        var HICMOBillNo = list[i]["鐢熶骇璁㈠崟鍙�*"].ToString();
+                        var HICMOEntrySEQ = list[i]["鐢熶骇璁㈠崟鏄庣粏琛屽彿*"].ToString();
+                        var HWorkShopID = list[i]["HWorkShopID"].ToString();
+                        var HSourceID = list[i]["HSourceID"].ToString();
+                        var HYX = list[i]["浼樺厛绾�"].ToString();
+                        var HEmpID = list[i]["HEmpID"].ToString();
+                        var HMaterID = list[i]["HMaterID"].ToString();
+                        var HMaterName = list[i]["鐗╂枡鍚嶇О"].ToString();
+                        var HMaterModel = list[i]["瑙勬牸鍨嬪彿"].ToString();
+                        var HUnitID = list[i]["HUnitID"].ToString();
+                        var HBatchNo = list[i]["鎵规鍙�"].ToString();
+                        var HSeOrderBillQty = list[i]["閿�鍞鍗曟暟閲�"].ToString();
+                        var HPlanQty = list[i]["鐢熶骇璁㈠崟鏁伴噺"].ToString();
+                        var HCompleteQty = list[i]["鎬婚綈濂楁暟閲�"].ToString();
+                        var HOrderType = omdelMian.HOrderType;
+                        var HDate = omdelMian.HDate;
+                        var HMainSourceInterID = list[i]["ICMOBillHInterID"].ToString();
+                        var HMainSourceEntryID = list[i]["ICMOBillHEntryID"].ToString();
+
+                        ds = oCN.RunProcReturn($"select * from  Sc_WorkBillSortBillMain where HMainSourceInterID={HMainSourceInterID}" +
+                          $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}", "Sc_WorkBillSortBillMain");
+                        if (ds.Tables[0].Rows.Count > 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = $"绗瑊i + 1}琛岀敓浜ц祫婧愭湁閲嶅,璇蜂慨鏀�!";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                        //涓昏〃
+                        oCN.RunProc("insert into Sc_WorkBillSortBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType," +
+                            "HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HICMOBillNo,HOrderType," +
+                            "HICMOEntrySEQ,HWorkShopID,HSourceID, HYX, HEmpID," +
+                            " HMaterID, HMaterName, HMaterModel, HUnitID, HBatchNo," +
+                            " HSeOrderBillQty, HPlanQty, HCompleteQty,HPreparatDate," +
+                            "HMainSourceInterID,HMainSourceEntryID)values" +
+                            $"({HInterID},'{HBillNo}',{DateTime.Now.Year},{DateTime.Now.Month},'{BillType}'," +
+                            $"'{BillType}',GETDATE(),1,'{user}','{HDate}','{HICMOBillNo}','{HOrderType}'," +
+                            $"{(HICMOEntrySEQ == "" ? 0.ToString() : HICMOEntrySEQ)},{(HWorkShopID == "" ? 0.ToString() : HWorkShopID)},{(HSourceID == "" ? 0.ToString() : HSourceID)}, {(HYX == "" ? 0.ToString() : HYX)}, {(HEmpID == "" ? 0.ToString() : HEmpID)}," +
+                            $" {(HMaterID == "" ? 0.ToString() : HMaterID)}, '{HMaterName}', '{HMaterModel}', {(HUnitID == "" ? 0.ToString() : HUnitID)}, '{HBatchNo}'," +
+                            $" {(HSeOrderBillQty == "" ? 0.ToString() : HSeOrderBillQty)}, {(HPlanQty == "" ? 0.ToString() : HPlanQty)}, {(HCompleteQty == "" ? 0.ToString() : HCompleteQty)},getdate()," +
+                            $" {HMainSourceInterID},{HMainSourceEntryID})");
+                    }
+
+                    int SumDay = 31; //鍔ㄦ�佷袱鏈堜箣宸� DateTime.Now.AddMonths(1).AddDays(-1).Subtract(DateTime.Now).Days;
+
+                    for (int j = 0; j < SumDay; j++)
+                    {
+                        //涓昏〃瀛愯〃閮芥湁鏁版嵁
+                        if (list[i][DateTime.Now.AddDays(j).ToString("yyyy-MM-dd")].ToString() != "")
+                        {
+                            SumCount += 1;
+                            ////淇濆瓨瀛愯〃
+                            objJsonResult = AddBillSub(HInterID == 0 ? list[i]["hmainid"].ToString() : HInterID.ToString()
+                                , HBillNo == "" ? list[i]["鍗曟嵁鍙�"].ToString() : HBillNo
+                                 , DateTime.Parse(DateTime.Now.AddDays(j).ToString("yyyy-MM-dd").ToString())
+                                 , int.Parse(list[i][DateTime.Now.AddDays(j).ToString("yyyy-MM-dd")].ToString()));
+
+                            if (objJsonResult.count == 1)
+                            {
+                                TrueCount += 1;
+                            }
+                        }
+                        //涓昏〃鏈夋暟鎹� 瀛愯〃鏃犳暟鎹�
+                        if (j == 30 && SumCount == 0 && HInterID != 0 && HBillNo != "")
+                        {
+                            objJsonResult = AddBillSub(HInterID.ToString(), HBillNo, DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd").ToString()), 0);
+                        }
+                    }
+                }
+
+                if (TrueCount != SumCount)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = objJsonResult.Message;
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = null;
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+
+        public json AddBillSub(string HInterID,string HBillNo, DateTime date, int HQTY)
+        {
+            //鑾峰彇琛ㄦ牸鏁版嵁
+            ds = oCN.RunProcReturn($"select * from  h_v_JIT_Sc_WorkBillSortBillList where 鍗曟嵁鍙�='{HBillNo}'", "h_v_JIT_Sc_WorkBillSortBillList");
+
+            int count = 0;
+            if (ds.Tables[0].Rows.Count > 0)
+            {
+                //鍒ゆ柇瀛愯〃鏄惁鏈夊綋鏃ョ殑鏃ユ湡浠ュ強鏃ユ湡鎵�瀵瑰簲鐨勬暟閲�
+                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
+                {
+                    if (DateTime.Parse(ds.Tables[0].Rows[i]["鏃ヨ鍒掔敓浜ф棩鏈�"].ToString()) == date)
+                    {
+                        oCN.RunProc($"update Sc_WorkBillSortBillSub set HMasterDate='{date}',HQty={HQTY}" +
+                            $"  where HInterID={HInterID} and HEntryID={ds.Tables[0].Rows[i]["hsubid"].ToString()}");
+                        count += 1;
+                    }
+                }
+            }
+
+            if (count != 1)
+            {
+                //鎻掑叆瀛愯〃
+                oCN.RunProc("insert into Sc_WorkBillSortBillSub(HInterID,HEntryID," +
+                    "HMasterDate,HQty)" +
+                            $"values({HInterID}, {(ds.Tables[0].Rows.Count + 1)}," +
+                            $" '{date}', {HQTY})");
+            }
+
+            objJsonResult.code = "1";
+            objJsonResult.count = 1;
+            objJsonResult.Message = null;
+            objJsonResult.data = null;
+            return objJsonResult;
+        }
+        #endregion
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1