| | |
| | | var HDeptNumbers_sub = list.Select(x => x["é¨é¨ä»£ç "].ToString()).Distinct().ToList(); |
| | | var materialNumbers = list.Select(x => x["ç©æç¼ç "].ToString()).Distinct().ToList(); |
| | | var materialNames = list.Select(x => x["ç©æåç§°"].ToString()).Distinct().ToList(); |
| | | var EmpNumbers = list.Select(x => x["èå代ç "].ToString()).Distinct().ToList(); |
| | | var EmpNames = list.Select(x => x["èå"].ToString()).Distinct().ToList(); |
| | | //var EmpNumbers = list.Select(x => x["èå代ç "].ToString()).Distinct().ToList(); |
| | | //var EmpNames = list.Select(x => x["èå"].ToString()).Distinct().ToList(); |
| | | var EmpNumbers = list.Select(x => x["èå代ç "]?.ToString()) |
| | | .Where(s => !string.IsNullOrEmpty(s)) |
| | | .Distinct() |
| | | .ToList(); |
| | | var EmpNames = list.Select(x => x["èå"]?.ToString()) |
| | | .Where(s => !string.IsNullOrEmpty(s)) |
| | | .Distinct() |
| | | .ToList(); |
| | | var CostNumbers = list.Select(x => x["ææ¬é¡¹ç®ä»£ç "].ToString()).Distinct().ToList(); |
| | | var CostNames = list.Select(x => x["ææ¬é¡¹ç®"].ToString()).Distinct().ToList(); |
| | | var ICMONumbers = list.Select(x => x["ç产订åå·"].ToString()).Distinct().ToList(); |
| | | |
| | | // 2. æ¹éæ¥è¯¢ç产订åå
ç |
| | | string ICMOQuery = $"SELECT HInterID,HBillNo FROM Sc_ICMOBillMain WHERE HBillNo IN ({string.Join(",", ICMONumbers.Select(s => $"'{s.Replace("'", "''")}'"))})"; |
| | | string ICMOQuery = $"SELECT HInterID,HBillNo FROM Sc_ICMOBillMain WHERE HBillNo IN ({string.Join(",", ICMONumbers.Select(s => $"'{s.Replace("'", "''")}'"))}) and HPRDORGID={organ}"; |
| | | DataSet icmoData = oCN.RunProcReturn(ICMOQuery, "Sc_ICMOBillMain"); |
| | | Dictionary<string, int> ICMODict = new Dictionary<string, int>(); |
| | | foreach (DataRow row in icmoData.Tables[0].Rows) |
| | |
| | | //} |
| | | |
| | | // 2.1 æ¹éæ¥è¯¢ä¸»å表é¨é¨ä¿¡æ¯ |
| | | string supplierQuery_sub = $"SELECT HItemID, HName FROM Gy_Department WHERE HName IN ({string.Join(",", HDeptNames_sub.Select(s => $"'{s.Replace("'", "''")}'"))})"; |
| | | string supplierQuery_sub = $"SELECT HItemID, HName FROM Gy_Department WHERE HName IN ({string.Join(",", HDeptNames_sub.Select(s => $"'{s.Replace("'", "''")}'"))}) and HUSEORGID ={organ}"; |
| | | DataSet supData_sub = oCN.RunProcReturn(supplierQuery_sub, "Gy_Department"); |
| | | Dictionary<string, int> supplierDict_sub = new Dictionary<string, int>(); |
| | | foreach (DataRow row in supData_sub.Tables[0].Rows) |
| | |
| | | |
| | | // 3. æ¹éæ¥è¯¢ç©æä¿¡æ¯ |
| | | string materialQuery = |
| | | $"SELECT HItemID, HNumber, HName FROM Gy_Material WHERE HNumber IN ({string.Join(",", materialNumbers.Select(m => $"'{m.Replace("'", "''")}'"))}) AND HName IN ({string.Join(",", materialNames.Select(m => $"'{m.Replace("'", "''")}'"))})"; |
| | | $"SELECT HItemID, HNumber, HName FROM Gy_Material WHERE HNumber IN ({string.Join(",", materialNumbers.Select(m => $"'{m.Replace("'", "''")}'"))}) AND HName IN ({string.Join(",", materialNames.Select(m => $"'{m.Replace("'", "''")}'"))}) and HUSEORGID ={organ}"; |
| | | DataSet materData = oCN.RunProcReturn(materialQuery, "Gy_Material"); |
| | | Dictionary<string, int> materialDict = new Dictionary<string, int>(); |
| | | foreach (DataRow row in materData.Tables[0].Rows) |
| | |
| | | string key = $"{row["HNumber"]}_{row["HName"]}"; |
| | | materialDict[key] = (int)row["HItemID"]; |
| | | } |
| | | if (EmpNames.Count == 0 && EmpNumbers.Count == 0) |
| | | { |
| | | |
| | | } |
| | | // 3. æ¹éæ¥è¯¢èåä¿¡æ¯ |
| | | string EmployeeQuery = |
| | | $"SELECT HItemID, HNumber, HName FROM Gy_Employee WHERE HNumber IN ({string.Join(",", EmpNumbers.Select(m => $"'{m.Replace("'", "''")}'"))}) AND HName IN ({string.Join(",", EmpNames.Select(m => $"'{m.Replace("'", "''")}'"))})"; |
| | | string empNumbersIn = EmpNumbers.Any() |
| | | ? string.Join(",", EmpNumbers.Select(m => $"'{m.Replace("'", "''")}'")) |
| | | : "''"; |
| | | string empNamesIn = EmpNames.Any() |
| | | ? string.Join(",", EmpNames.Select(m => $"'{m.Replace("'", "''")}'")) |
| | | : "''"; |
| | | string EmployeeQuery = $"SELECT HItemID, HNumber, HName FROM Gy_Employee WHERE HNumber IN ({empNumbersIn}) AND HName IN ({empNamesIn}) and HUSEORGID ={organ}"; |
| | | DataSet EmpData = oCN.RunProcReturn(EmployeeQuery, "Gy_Employee"); |
| | | Dictionary<string, int> EmpDict = new Dictionary<string, int>(); |
| | | foreach (DataRow row in EmpData.Tables[0].Rows) |
| | |
| | | } |
| | | |
| | | // 3. æ¹éæ¥è¯¢chengbenxiangmuä¿¡æ¯ |
| | | string CostQuery = $"SELECT HItemID, HNumber, HName FROM Gy_ItemMoney_1 WHERE HNumber IN ({string.Join(",", CostNumbers.Select(m => $"'{m.Replace("'", "''")}'"))}) AND HName IN ({string.Join(",", CostNames.Select(m => $"'{m.Replace("'", "''")}'"))})"; |
| | | string CostQuery = $"SELECT HItemID, HNumber, HName FROM Gy_ItemMoney_1 WHERE HNumber IN ({string.Join(",", CostNumbers.Select(m => $"'{m.Replace("'", "''")}'"))}) AND HName IN ({string.Join(",", CostNames.Select(m => $"'{m.Replace("'", "''")}'"))}) and HUSEORGID ={organ}"; |
| | | DataSet CostData = oCN.RunProcReturn(CostQuery, "Gy_ItemMoney_1"); |
| | | Dictionary<string, int> CostDict = new Dictionary<string, int>(); |
| | | foreach (DataRow row in CostData.Tables[0].Rows) |
| | |
| | | CostDict[key] = (int)row["HItemID"]; |
| | | } |
| | | // 3.1 æ¹éæ¥è¯¢å·¥åºä¿¡æ¯ |
| | | string ProcessQuery = $"SELECT HItemID, HNumber, HName FROM Gy_Process WHERE HName IN ({string.Join(",", HProc.Select(m => $"'{m.Replace("'", "''")}'"))})"; |
| | | string ProcessQuery = $"SELECT HItemID, HNumber, HName FROM Gy_Process WHERE HName IN ({string.Join(",", HProc.Select(m => $"'{m.Replace("'", "''")}'"))}) and HUSEORGID ={organ}"; |
| | | DataSet ProcData = oCN.RunProcReturn(ProcessQuery, "Gy_Process"); |
| | | Dictionary<string, int> ProcDict = new Dictionary<string, int>(); |
| | | foreach (DataRow row in ProcData.Tables[0].Rows) |
| | |
| | | // 5. æ£æ¥ç¼ºå¤±çé¨é¨åç©æï¼å¹¶è®°å½è¡å· |
| | | List<string> missingSupplierMessages = new List<string>(); |
| | | List<string> missingMaterialMessages = new List<string>(); |
| | | List<string> missingCostMessages = new List<string>(); |
| | | List<string> missingmoneyMessages = new List<string>(); |
| | | List<string> missingEmployeeMessages = new List<string>(); |
| | | |
| | | // é忝ä¸è¡æ°æ®ï¼è®°å½è¡å·ï¼ä»1å¼å§ï¼ |
| | | for (int i = 0; i < list.Count; i++) |
| | |
| | | int lineNumber = i + 1; // è¡å·ä»1å¼å§ |
| | | |
| | | string ICMOcheck = item["ç产订åå·"]; |
| | | string Costcheck = item["ææ¬é¡¹ç®"]; |
| | | string Procheck = item["å·¥åº"]; |
| | | string supplier = item["é¨é¨"]; |
| | | string materialNumber = item["ç©æç¼ç "]; |
| | | string materialName = item["ç©æåç§°"]; |
| | | string monetcheck = item["éé¢"]; |
| | | string materialKey = $"{materialNumber}_{materialName}"; |
| | | |
| | | string empName = item["èå"]; |
| | | if (!string.IsNullOrEmpty(empName) && !EmpDict.ContainsKey(empName)) |
| | | { |
| | | missingEmployeeMessages.Add($"第{lineNumber}è¡çèåã{empName}ã"); |
| | | } |
| | | // æ£æ¥ä¾åºå |
| | | if (!supplierDict_sub.ContainsKey(supplier)) |
| | | { |
| | |
| | | if (!string.IsNullOrEmpty(ICMOcheck) && !ICMODict.ContainsKey(ICMOcheck)) |
| | | { |
| | | missingMaterialMessages.Add($"第{lineNumber}è¡çç产订åã{ICMOcheck}ã"); |
| | | } |
| | | // æ£æ¥é¡¹ç®ææ¬ |
| | | if (CostDict.Count == 0) |
| | | { |
| | | missingCostMessages.Add($"第{lineNumber}è¡çé¡¹ç®ææ¬ã{Costcheck}ã"); |
| | | } |
| | | // æ£æ¥å·¥åº |
| | | if (ProcDict.Count == 0 && Procheck != "") |
| | | { |
| | | missingCostMessages.Add($"第{lineNumber}è¡çå·¥åºã{Procheck}ã"); |
| | | } |
| | | if (monetcheck == "" || monetcheck == null) |
| | | { |
| | | missingmoneyMessages.Add($"第{lineNumber}è¡éé¢ã{monetcheck}ã"); |
| | | } |
| | | } |
| | | |
| | |
| | | errorMessage.Append(string.Join("ã", missingMaterialMessages)); |
| | | errorMessage.Append("ï¼"); |
| | | } |
| | | if (missingCostMessages.Any()) |
| | | { |
| | | errorMessage.Append("ææ¬é¡¹ç®æªç»´æ¤ææè¯¯ï¼"); |
| | | errorMessage.Append(string.Join("ã", missingCostMessages)); |
| | | errorMessage.Append("ï¼"); |
| | | } |
| | | if (missingmoneyMessages.Any()) |
| | | { |
| | | errorMessage.Append("é颿ªç»´æ¤ææè¯¯ï¼"); |
| | | errorMessage.Append(string.Join("ã", missingmoneyMessages)); |
| | | errorMessage.Append("ï¼"); |
| | | } |
| | | if (missingEmployeeMessages.Any()) |
| | | { |
| | | errorMessage.Append("以ä¸èåæªç»´æ¤ï¼"); |
| | | errorMessage.Append(string.Join("ã", missingEmployeeMessages)); |
| | | errorMessage.Append("ï¼"); |
| | | } |
| | | |
| | | if (errorMessage.Length > 0) |
| | | { |
| | |
| | | return res; |
| | | } |
| | | |
| | | // 6. æ¹éæ¥è¯¢å·²åå¨çè®°å½ |
| | | var materialIds = list.Select(x => materialDict[$"{x["ç©æç¼ç "]}_{x["ç©æåç§°"]}"]).Distinct().ToList(); |
| | | var supplierIds = list.Select(x => supplierDict_sub[x["é¨é¨"]]).Distinct().ToList(); |
| | | |
| | | string existQuery = $"select * from h_v_CB_ItemMoneyBillMain_Edit_excel WHERE HMaterID IN ({string.Join(",", materialIds)}) AND HDeptID_sub IN ({string.Join(",", supplierIds)})"; |
| | | DataSet existData = oCN.RunProcReturn(existQuery, "h_v_CB_ItemMoneyBillMain_Edit_excel"); |
| | | HashSet<string> existRecords = new HashSet<string>(); |
| | | foreach (DataRow row in existData.Tables[0].Rows) |
| | | { |
| | | existRecords.Add($"{row["HMaterID"]}_{row["HDeptID_sub"]}"); |
| | | } |
| | | |
| | | |
| | | // 7. æç
§é¨é¨ä»£ç ãé¨é¨ãèå代ç ãèåãç产订åå·è¿è¡åç» |
| | | var groupedData = list.GroupBy(item => new |
| | |
| | | |
| | | // è·åç»ä¿¡æ¯ |
| | | int HSupplierID = supplierDict_sub[firstItem["é¨é¨"]]; |
| | | int EmpID = EmpDict[firstItem["èå"]]; |
| | | //int EmpID = EmpDict[firstItem["èå"]]; |
| | | int EmpID; |
| | | string empName = firstItem["èå"]; |
| | | if (string.IsNullOrEmpty(empName)) |
| | | EmpID = 0; // æå
¶ä»é»è®¤å¼ |
| | | else |
| | | EmpID = EmpDict[empName]; |
| | | string ICMO = firstItem["ç产订åå·"]; |
| | | int ICMOInterID = !string.IsNullOrEmpty(ICMO) && ICMODict.ContainsKey(ICMO) ? ICMODict[ICMO] : 0; |
| | | |
| | |
| | | string HBillNo = DBUtility.ClsPub.CreateBillCode("1802", ref DBUtility.ClsPub.sExeReturnInfo, true); |
| | | long HInterID = DBUtility.ClsPub.CreateBillID("1802", ref DBUtility.ClsPub.sExeReturnInfo); |
| | | |
| | | // æ£æ¥è¯¥ç»æ¯å¦å·²åå¨ï¼æ ¹æ®é¨é¨IDåç©æIDç»åï¼ |
| | | bool groupExists = false; |
| | | foreach (var item in group) |
| | | { |
| | | int HMaterID = materialDict[$"{item["ç©æç¼ç "]}_{item["ç©æåç§°"]}"]; |
| | | string recordKey = $"{HMaterID}_{HSupplierID}"; |
| | | if (existRecords.Contains(recordKey)) |
| | | { |
| | | groupExists = true; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (!groupExists) |
| | | { |
| | | |
| | | |
| | | |
| | | // æå
¥ä¸»è¡¨ï¼æ¯ç»æå
¥ä¸æ¬¡ï¼ |
| | | insertSql.AppendLine($"INSERT INTO CB_ItemMoneyBillMain ([HInterID], [HBillNo], [HDate], [HYear], [HPeriod], [HBillType], [HBillSubType], [HBillStatus], [HCheckItemNowID], [HCheckItemNextID], [HCheckFlowID], [HRemark], [HBacker], [HBackDate], [HBackRemark], [HChecker], [HCheckDate], [HMaker], [HMakeDate], [HUpDater], [HUpDateDate], [HCloseMan], [HCloseDate], [HCloseType], [HDeleteMan], [HDeleteDate], [HMainSourceBillType], [HMainSourceInterID], [HMainSourceEntryID], [HMainSourceBillNo], [HPrintQty], [HEmpID], [HDeptID], [HICMOInterID], [HMaterID], [HICMOBillNo], [HExplanation], [HInnerBillNo], [HBeginDate], [HEndDate], [HOrgID]) VALUES ("); |
| | | insertSql.AppendLine($"'{HInterID}', '{HBillNo}', '{DateTime.Now}', {list[0]["年份"]}, {list[0]["æä»½"]}, {"1802"}, '{"1802"}', '{"1"}', '{"0"}', '{"0"}', '{"0"}', '{"excel导å
¥"}', '{""}', '{DateTime.Now}', '{""}', '{""}', '{DateTime.Now}', '{""}', '{DateTime.Now}', '{""}', '{DateTime.Now}', '{""}', '{DateTime.Now}', '{"0"}', '{""}', '{DateTime.Now}', '{""}', '{"0"}', '{"0"}', '{""}', '{"0"}', '{EmpID}', '{HSupplierID}', '{ICMOInterID}','{0}','{ICMO}','{""}','{"0"}','{DateTime.Now}','{DateTime.Now}','{"100038"}');"); |
| | |
| | | insertSql_sub.AppendLine($"'{HInterID}', '{HEntryID}', '{""}', '{DateTime.Now}', '{"0"}', '{"excel导å
¥"}','{"0"}', '{"0"}', '{"0"}', '{"0"}','{"0"}', '{"0"}', '{""}', '{HCostID}', '{HSupplierID}', '{item["æ°é"]}', '{item["åä»·"]}', '{item["éé¢"]}','{HMaterID}', '{item["æèé"] ?? "0"}', '{DateTime.Now}', '{"0"}', '{"0"}', '{"0"}', '{HProcID}');"); |
| | | HEntryID++; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | // æ§è¡æ¹éæä½ |