|  |  | 
 |  |  | using System; | 
 |  |  | using 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.æ¥è®¡å管ç | 
 |  |  | 
 |  |  |         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,1,"0"); | 
 |  |  |  | 
 |  |  |                 //å é¤æä»¶ | 
 |  |  |                 File.Delete(ExcelPath); | 
 |  |  |  | 
 |  |  |                 //å建临æ¶è¡¨ | 
 |  |  |                 DataTable tb2 = new DataTable("dt2"); | 
 |  |  |  | 
 |  |  |                 //æ·»å åå | 
 |  |  |                 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));//ç产订å主id | 
 |  |  |                 tb2.Columns.Add("ICMOBillHEntryID", typeof(Int32));//ç产订ååid | 
 |  |  |                 tb2.Columns.Add("HProdORGID", typeof(Int32));//ç»ç»id | 
 |  |  |  | 
 |  |  |                 //æ·»å æ°æ® | 
 |  |  |                 for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++) | 
 |  |  |                 { | 
 |  |  |                     DataRow row = tb2.NewRow(); | 
 |  |  |                     for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++) | 
 |  |  |                     { | 
 |  |  |                         row[j] = ExcelDs.Tables[0].Rows[i][j].ToString(); | 
 |  |  |                     } | 
 |  |  |                     tb2.Rows.Add(row); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 var error = ""; | 
 |  |  |                 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 ç产车é´ä»£ç ='{1}' and äº§å代ç ='{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();//ç产订å主id | 
 |  |  |                         tb2.Rows[i]["ICMOBillHEntryID"] = ds.Tables[0].Rows[0]["HEntryID"].ToString();//ç产订ååid | 
 |  |  |                         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 ç©æä»£ç ='{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]["èå代ç "].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(); | 
 |  |  |                         } | 
 |  |  |                         else | 
 |  |  |                         { | 
 |  |  |                             objJsonResult.code = "0"; | 
 |  |  |                             objJsonResult.count = 0; | 
 |  |  |                             objJsonResult.Message = $"第{i + 1}è¡,åå·¥æ¥æ æ°æ®!"; | 
 |  |  |                             objJsonResult.data = tb2; | 
 |  |  |                             return objJsonResult; | 
 |  |  |                         } | 
 |  |  |  | 
 |  |  |                         //计éåä½ | 
 |  |  |                         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(); | 
 |  |  |                         } | 
 |  |  |                         else | 
 |  |  |                         { | 
 |  |  |                             objJsonResult.code = "0"; | 
 |  |  |                             objJsonResult.count = 0; | 
 |  |  |                             objJsonResult.Message = $"第{i + 1}è¡,计éå使¥æ æ°æ®!"; | 
 |  |  |                             objJsonResult.data = tb2; | 
 |  |  |                             return objJsonResult; | 
 |  |  |                         } | 
 |  |  |  | 
 |  |  |                         //çäº§èµæº | 
 |  |  |                         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(); | 
 |  |  |                         } | 
 |  |  |                         else { | 
 |  |  |                             objJsonResult.code = "0"; | 
 |  |  |                             objJsonResult.count = 0; | 
 |  |  |                             objJsonResult.Message = $"第{i+1}è¡,çäº§èµæºæ¥æ æ°æ®!"; | 
 |  |  |                             objJsonResult.data = tb2; | 
 |  |  |                             return objJsonResult; | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                     //ç»ç» | 
 |  |  |                     ds = oCN.RunProcReturn($"select * from Xt_ORGANIZATIONS  where HNumber='{tb2.Rows[i]["ç»ç»ç¼ç *"].ToString()}'", "Xt_ORGANIZATIONS"); | 
 |  |  |                     if (ds.Tables[0].Rows.Count > 0) | 
 |  |  |                     { | 
 |  |  |                         tb2.Rows[i]["HProdORGID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); | 
 |  |  |                     } | 
 |  |  |                     else | 
 |  |  |                     { | 
 |  |  |                         objJsonResult.code = "0"; | 
 |  |  |                         objJsonResult.count = 0; | 
 |  |  |                         objJsonResult.Message = $"第{i + 1}è¡,ç»ç»æ¥æ æ°æ®!"; | 
 |  |  |                         objJsonResult.data = tb2; | 
 |  |  |                         return objJsonResult; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 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) | 
 |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         #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);//è·å¾ä¸ä¸ªæ°çid | 
 |  |  |                         var HICMOBillNo = list[i]["ç产订åå·*"].ToString(); | 
 |  |  |                         var HICMOEntrySEQ = list[i]["ç产订åæç»è¡å·*"].ToString(); | 
 |  |  |                         var HProdORGID = list[i]["HProdORGID"].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,HProdORGID,HICMOInterID_Sec,HICMOEntryID_Sec)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},{HProdORGID}, {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,HSEQ," + | 
 |  |  |                     "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 | 
 |  |  |     } | 
 |  |  | } |