|  |  | 
 |  |  | using DBUtility; | 
 |  |  | using Newtonsoft.Json; | 
 |  |  | using Newtonsoft.Json.Linq; | 
 |  |  | using System; | 
 |  |  | using System.Collections.Generic; | 
 |  |  | 
 |  |  |         private json objJsonResult = new json(); | 
 |  |  |         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); | 
 |  |  |         DataSet ds; | 
 |  |  |         Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); | 
 |  |  |  | 
 |  |  |         #region æ¥è®¡åå¹³å°åºç¡èµæ è½¦é´ä»åºå¯¹ç
§ | 
 |  |  |  | 
 |  |  | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 List<object> a = new List<object>(); | 
 |  |  |                 //æ¥è¯¢æé | 
 |  |  |                 if (!DBUtility.ClsPub.Security_Log_second("JIT_ComplementGoodBill_Query", 1, false, user)) | 
 |  |  |                 { | 
 |  |  | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 ds = oCN.RunProcReturn("select * from h_v_JIT_Gy_WorkWarehouseBillList where 1=1 " + sWhere + " order by hmainid desc ", "h_v_JIT_Gy_WorkWarehouseBillList"); | 
 |  |  |  | 
 |  |  |                 foreach (DataColumn col in ds.Tables[0].Columns)//éådsä¸ç¬¬ä¸ä¸ªè¡¨ï¼Tables[0]ï¼çææåï¼Columnsï¼æ¯æ¬¡å¾ªç¯ä¸ï¼colåé伿æå½ååçå¼ç¨ | 
 |  |  |                 { | 
 |  |  |                     Type dataType = col.DataType; //è·åå½åæ°æ®ç±»åä¼ å
¥ èªå®ä¹åédatadataType | 
 |  |  |                     string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //åç¬¦ä¸²æ¼æ¥         // å°åååæ°æ®ç±»åä¿¡æ¯æ¼æ¥æä¸ä¸ªJSONæ ¼å¼çå符串 | 
 |  |  |                     a.Add(JsonConvert.DeserializeObject(ColmString));//è·åå°DataColumnå对象çåå | 
 |  |  |                 } | 
 |  |  |                 objJsonResult.code = "1"; | 
 |  |  |                 objJsonResult.count = 1; | 
 |  |  |                 objJsonResult.Message = "Sucessï¼"; | 
 |  |  |                 objJsonResult.data = ds.Tables[0]; | 
 |  |  |                 objJsonResult.list = a; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 List<object> A = new List<object>(); | 
 |  |  |                 //æ¥è¯¢æé | 
 |  |  |                 if (!DBUtility.ClsPub.Security_Log_second("Cg_PODemandPlanConfigBill_Query", 1, false, user)) | 
 |  |  |                 { | 
 |  |  | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 ds = oCN.RunProcReturn("select * from h_v_JIT_Cg_PODemandPlanConfigBillList where 1=1 " + sWhere + " order by hmainid desc ", "h_v_JIT_Cg_PODemandPlanConfigBillList"); | 
 |  |  |  | 
 |  |  |                 foreach (DataColumn col in ds.Tables[0].Columns)//éådsä¸ç¬¬ä¸ä¸ªè¡¨ï¼Tables[0]ï¼çææåï¼Columnsï¼æ¯æ¬¡å¾ªç¯ä¸ï¼colåé伿æå½ååçå¼ç¨ | 
 |  |  |                 { | 
 |  |  |                     Type dataType = col.DataType; //è·åå½åæ°æ®ç±»åä¼ å
¥ èªå®ä¹åédatadataType | 
 |  |  |                     string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //åç¬¦ä¸²æ¼æ¥         // å°åååæ°æ®ç±»åä¿¡æ¯æ¼æ¥æä¸ä¸ªJSONæ ¼å¼çå符串 | 
 |  |  |                     A.Add(JsonConvert.DeserializeObject(ColmString));//è·åå°DataColumnå对象çåå | 
 |  |  |                 } | 
 |  |  |                 objJsonResult.code = "1"; | 
 |  |  |                 objJsonResult.count = 1; | 
 |  |  |                 objJsonResult.Message = "Sucessï¼"; | 
 |  |  |                 objJsonResult.data = ds.Tables[0]; | 
 |  |  |                 objJsonResult.list = A; | 
 |  |  |                    | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  | 
 |  |  |  | 
 |  |  |         public json AddPODBillSub(string msg3) | 
 |  |  |         { | 
 |  |  |             string Ret = ""; | 
 |  |  |             oSystemParameter.ShowBill(ref Ret); | 
 |  |  |             omodelPODsub = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Cg_PODemandPlanConfigBillSub>>(msg3); | 
 |  |  |  | 
 |  |  |             foreach (Models.Cg_PODemandPlanConfigBillSub oSub in omodelPODsub) | 
 |  |  | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |                 if (oSub.HLeadTime_Sec == 0 || oSub.HLeadTime_Sec == null) | 
 |  |  |  | 
 |  |  |                 if (oSystemParameter.omodel.WMS_CampanyName != "å¸
å¨") | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  |                     objJsonResult.count = 0; | 
 |  |  |                     objJsonResult.Message = " JITå°è´§åç½®æä¸è½ä¸ºç©º"; | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |                 if (oSub.HDeliveryDaysCtrl == 0 || oSub.HDeliveryDaysCtrl == null) | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  |                     objJsonResult.count = 0; | 
 |  |  |                     objJsonResult.Message = " JITéè´§æ§å¶å¤©æ°ä¸è½ä¸ºç©º"; | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                     if (oSub.HLeadTime_Sec == 0 || oSub.HLeadTime_Sec == null) | 
 |  |  |                     { | 
 |  |  |                         objJsonResult.code = "0"; | 
 |  |  |                         objJsonResult.count = 0; | 
 |  |  |                         objJsonResult.Message = " JITå°è´§åç½®æä¸è½ä¸ºç©º"; | 
 |  |  |                         objJsonResult.data = null; | 
 |  |  |                         return objJsonResult; | 
 |  |  |                     } | 
 |  |  |                     if (oSub.HDeliveryDaysCtrl == 0 || oSub.HDeliveryDaysCtrl == null) | 
 |  |  |                     { | 
 |  |  |                         objJsonResult.code = "0"; | 
 |  |  |                         objJsonResult.count = 0; | 
 |  |  |                         objJsonResult.Message = " JITéè´§æ§å¶å¤©æ°ä¸è½ä¸ºç©º"; | 
 |  |  |                         objJsonResult.data = null; | 
 |  |  |                         return objJsonResult; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  | 
 |  |  |                     { | 
 |  |  |                         row[j] = ExcelDs.Tables[0].Rows[i][j].ToString(); | 
 |  |  |                     } | 
 |  |  |                     tb2.Rows.Add(row); | 
 |  |  |                     //å¦æè¡¨æ ¼ç¬¬iè¡ç第ä¸å为空ï¼åå¤æä¸ºè¿ä¸è¡çæ°æ®ä¸ºç©ºï¼è·³åºå¾ªç¯å¹¶ä¸ä¸ææ°æ®åå
¥ tb2 | 
 |  |  |                     if (ExcelDs.Tables[0].Rows[i][0].ToString() == "") | 
 |  |  |                     { | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  |                     else | 
 |  |  |                     { | 
 |  |  |                         tb2.Rows.Add(row); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | 
 |  |  |                     } | 
 |  |  |                     else | 
 |  |  |                     { | 
 |  |  |                         objJsonResult.code = "1"; | 
 |  |  |                         objJsonResult.count = 1; | 
 |  |  |                         objJsonResult.code = "0"; | 
 |  |  |                         objJsonResult.count = 0; | 
 |  |  |                         objJsonResult.Message = "第" + index + "è¡,ç»ç»ä»£ç ä¸ºç©º"; | 
 |  |  |                         objJsonResult.data = null; | 
 |  |  |                         return objJsonResult; | 
 |  |  | 
 |  |  |                 int i = 1; | 
 |  |  |                 foreach (Dictionary<string, string> item in list) | 
 |  |  |                 { | 
 |  |  |                     long HInterID = DBUtility.ClsPub.CreateBillID_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo);//è·å¾ä¸ä¸ªæ°çid | 
 |  |  |                     string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo, true);//è·å¾ä¸ä¸ªæ°çåæ®å· | 
 |  |  |                     string HOrgID = item["HOrgID"].ToString();//ç»ç»ID | 
 |  |  |                     string HSupID = item["HSupID"].ToString();//ä¾åºå | 
 |  |  |                     string HSupplierName = item["ä¾åºå"].ToString(); | 
 |  |  |                     string HMaterID = item["HMaterID"].ToString();//ç©æID | 
 |  |  |                     string HOrgID = item["HOrgID"].ToString();//ç»ç»ID | 
 |  |  |                     string HSupplierName = item["ä¾åºå"].ToString(); | 
 |  |  |                     string HMaterName = item["ç©æåç§°"].ToString(); | 
 |  |  |                     string HMaterModel = item["è§æ ¼åå·"].ToString(); | 
 |  |  |                     string HUnitID = item["HUnitID"].ToString();//计éåä½ | 
 |  |  | 
 |  |  |                     string JIMLC = item["JITæå°èµ·éé"].ToString(); | 
 |  |  |                     string HRemark = item["夿³¨"].ToString(); | 
 |  |  |  | 
 |  |  |                    | 
 |  |  |                     string sql = "insert into Cg_PODemandPlanConfigBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HOrgId)" + | 
 |  |  |                         $"values({HInterID}, '{HBillNo}',{DateTime.Now.Year}, {DateTime.Now.Month}, '4611', '4611', GETDATE(), 1, '{user}', GETDATE(), {HOrgID})"; | 
 |  |  |                     string sql1 = "insert into Cg_PODemandPlanConfigBillSub(HInterID,HEntryID,HRemark,HSupplierID,HSupplierName,HMaterID," + | 
 |  |  |                    "HMaterName, HMaterModel, HJITMaterGroup, HJITSafeStock, HJITMaterDemand, HJITBatchQty, HDeliveryPeriod, " + | 
 |  |  |                    "HLeadTime, HLeadTime_Sec, HDeliveryMode, HDeliveryDaysCtrl,HUnitID,HJITMinDeliveryQty)values" + | 
 |  |  |                    $"({HInterID}, 1, '{HRemark}', {(HSupID == "" ? "0" : HSupID)}, '{HSupplierName}', {(HMaterID == "" ? "0" : HMaterID)}," + | 
 |  |  |                    $" '{HMaterName}', '{HMaterModel}', '{JITType}', {(JITPSL == "" ? "0" : JITPSL)}, {(JITMDSC == "" ? "0" : JITMDSC)},{(JIPEB == "" ? "0" : JIPEB)},{(JITPBCC == "" ? "0" : JITPBCC)}," + | 
 |  |  |                    $" {(JISLT == "" ? "0" : JISLT)}, {(JIDLT == "" ? "0" : JIDLT)}, '', {(JITDCD == "" ? "0" : JITDCD)} ,{HUnitID},{JIMLC})"; | 
 |  |  |                     LogService.Write("sql" + i + ":" + sql); | 
 |  |  |                     LogService.Write("sql1" + i + ":" + sql1); | 
 |  |  |                    //主表 | 
 |  |  |                    oCN.RunProc(sql); | 
 |  |  |                     //å表 | 
 |  |  |                     oCN.RunProc(sql1); | 
 |  |  |                     ds = oCN.RunProcReturn("select * from Cg_PODemandPlanConfigBillSub where HMaterID=" + HMaterID + " and HSupplierID=" + HSupID, "Cg_PODemandPlanConfigBillSub"); | 
 |  |  |  | 
 |  |  |                     if (ds.Tables[0].Rows.Count == 0) | 
 |  |  |                     { | 
 |  |  |  | 
 |  |  |                         long HInterID = DBUtility.ClsPub.CreateBillID_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo);//è·å¾ä¸ä¸ªæ°çid | 
 |  |  |                         string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo, true);//è·å¾ä¸ä¸ªæ°çåæ®å· | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                         string sql = "insert into Cg_PODemandPlanConfigBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HOrgId)" + | 
 |  |  |                             $"values({HInterID}, '{HBillNo}',{DateTime.Now.Year}, {DateTime.Now.Month}, '4611', '4611', GETDATE(), 1, '{user}', GETDATE(), {HOrgID})"; | 
 |  |  |                         string sql1 = "insert into Cg_PODemandPlanConfigBillSub(HInterID,HEntryID,HRemark,HSupplierID,HSupplierName,HMaterID," + | 
 |  |  |                        "HMaterName, HMaterModel, HJITMaterGroup, HJITSafeStock, HJITMaterDemand, HJITBatchQty, HDeliveryPeriod, " + | 
 |  |  |                        "HLeadTime, HLeadTime_Sec, HDeliveryMode, HDeliveryDaysCtrl,HUnitID,HJITMinDeliveryQty)values" + | 
 |  |  |                        $"({HInterID}, 1, '{HRemark}', {(HSupID == "" ? "0" : HSupID)}, '{HSupplierName}', {(HMaterID == "" ? "0" : HMaterID)}," + | 
 |  |  |                        $" '{HMaterName}', '{HMaterModel}', '{JITType}', {(JITPSL == "" ? "0" : JITPSL)}, {(JITMDSC == "" ? "0" : JITMDSC)},{(JIPEB == "" ? "0" : JIPEB)},{(JITPBCC == "" ? "0" : JITPBCC)}," + | 
 |  |  |                        $" {(JISLT == "" ? "0" : JISLT)}, {(JIDLT == "" ? "0" : JIDLT)}, '', {(JITDCD == "" ? "0" : JITDCD)} ,{HUnitID},{JIMLC})"; | 
 |  |  |                         //主表 | 
 |  |  |                         oCN.RunProc(sql); | 
 |  |  |                         //å表 | 
 |  |  |                         oCN.RunProc(sql1); | 
 |  |  |                     } | 
 |  |  |                     else | 
 |  |  |                     { | 
 |  |  |                         oCN.RunProc("   update  Cg_PODemandPlanConfigBillSub set HLeadTime=" + JISLT + "  where HMaterID=" + HMaterID + " and HSupplierID=" + HSupID); | 
 |  |  |                     } | 
 |  |  |                 | 
 |  |  |                     i++; | 
 |  |  |                 } | 
 |  |  |                |