diff --git a/插件库/Lskj.PubBomImport/FrmProgress.cs b/插件库/Lskj.PubBomImport/FrmProgress.cs index 6303c02..dfff309 100644 --- a/插件库/Lskj.PubBomImport/FrmProgress.cs +++ b/插件库/Lskj.PubBomImport/FrmProgress.cs @@ -71,9 +71,52 @@ namespace Lskj.PubBomImport FileInfo parentInfo = fileInfos.Where(n => n.Name.StartsWith("MX") && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (parentInfo != null) { + if (Directory.Exists("BomImportTemp")) + { + Directory.Delete("BomImportTemp", true); + } + Directory.CreateDirectory("BomImportTemp"); FrmBillInfo frmBillInfo = new FrmBillInfo(); DataTable parentTable = ExcelToDatatable(parentInfo.FullName, Model, "", 5); parentTable = parentTable.Rows.Cast().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "")).ToList().CopyToDataTable(); + Dictionary childFileDic = new Dictionary(); + foreach (DataRow parentRow in parentTable.Rows) + { + string fileName = (parentRow["图号"] + "").Trim(); + if (fileName.StartsWith("QD") || fileName.StartsWith("ZZQD")) + { + FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(fileName)).FirstOrDefault(); + if (childInfo == null) + { + string fileSql = $"select webpath,sName from P_fm_FileTab where sName like '{fileName}%'"; + DataRow fileRow = BaseImpl.GetDataRowResult(fileSql); + string webpath = fileRow != null ? fileRow["webpath"] + "" : ""; + string sName = fileRow != null ? fileRow["sName"] + "" : ""; + if (string.IsNullOrEmpty(webpath)) + { + throw new Exception($"Bom明细附件{fileName}不存在\r\nBom导入失败"); + } + else + { + using (WebClient webClient = new WebClient()) + { + try + { + webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}"; + string url = $"{SystemInfo.Instance.OAUrl}/{webpath}"; + string tempFileName = $"BomImportTemp/{sName}"; + webClient.DownloadFile(url, tempFileName); + childFileDic.Add(fileName, tempFileName); + } + catch (Exception) + { + throw new Exception($"Bom明细附件{fileName}获取失败\r\nBom导入失败"); + } + } + } + } + } + } StringBuilder stringBuilder = new StringBuilder(); foreach (DataRow dataRow in parentTable.Rows) { @@ -107,16 +150,24 @@ namespace Lskj.PubBomImport foreach (DataRow parentRow in parentTable.Rows) { string code = parentRow["图号"] + ""; - FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault(); - if (childInfo != null && (childInfo.Name.StartsWith("QD") || childInfo.Name.StartsWith("ZZQD"))) + if (code.StartsWith("QD") || code.StartsWith("ZZQD")) { - DataRow childRow = childTable.NewRow(); - childRow["ProductId"] = parentRow["图号"] + ""; - childRow["appellation"] = parentRow["名称"] + ""; - childRow["bak"] = parentRow["备注"] + ""; - childRow["tamount"] = parentRow["套数"] + ""; - childRow["amount"] = parentRow["套数"] + ""; - childTable.Rows.Add(childRow); + FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault(); + if (childInfo == null) + { + string tempFileName = childFileDic[code]; + childInfo = new FileInfo(tempFileName); + } + if (childInfo != null) + { + DataRow childRow = childTable.NewRow(); + childRow["ProductId"] = parentRow["图号"] + ""; + childRow["appellation"] = parentRow["名称"] + ""; + childRow["bak"] = parentRow["备注"] + ""; + childRow["tamount"] = parentRow["套数"] + ""; + childRow["amount"] = parentRow["套数"] + ""; + childTable.Rows.Add(childRow); + } } } SetProcessBar(20, 0); @@ -148,43 +199,59 @@ namespace Lskj.PubBomImport int finishCount = (int)((decimal)(1 + nowCount) / (parentTable.Rows.Count + 1) * 100); int.TryParse(dataRow["套数"] + "", out int tamount); string code = (dataRow["图号"] + "").Trim(); - FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault(); - if (childInfo != null) + if (code.StartsWith("QD") || code.StartsWith("ZZQD")) { - if ((code.StartsWith("QD") || code.StartsWith("ZZQD"))) + DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{code}'"); + if (productRow == null) { - SetProcessBar(0, allCount); - SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}"); - DataTable detailTable = new DataTable(); - frmMain.Invoke(new Action(() => + FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault(); + if (childInfo == null) { - detailTable = frmMain.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true); - })); - foreach (DataRow detailRow in detailTable.Rows) + string tempFileName = childFileDic[code]; + childInfo = new FileInfo(tempFileName); + } + if (childInfo != null) { - int.TryParse(detailRow["amount"] + "", out int lastAmount); - detailRow["tamount"] = tamount; - detailRow["amount"] = lastAmount; + if ((code.StartsWith("QD") || code.StartsWith("ZZQD"))) + { + SetProcessBar(0, allCount); + SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}"); + DataTable detailTable = new DataTable(); + frmMain.Invoke(new Action(() => + { + detailTable = frmMain.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true); + })); + foreach (DataRow detailRow in detailTable.Rows) + { + int.TryParse(detailRow["amount"] + "", out int lastAmount); + detailRow["tamount"] = tamount; + detailRow["amount"] = lastAmount; + } + frmBillInfo.GcMainView.GridControl.DataSource = detailTable; + SetProcessBar(20, allCount); + frmBillInfo.InitializeHeader(dataRow, Model.BillMasterSql); + SetProcessBar(40, allCount); + string childBillNo = ""; + frmBillInfo.BillSave(ref childBillNo); + SetProcessBar(60, allCount); + frmBillInfo.OnBillAdd(); + //记录历史版本号 + string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'"; + SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, childBillNo)); + string updateChildVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{1}') and ProductId='{0}'"; + SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId)); + SetProcessBar(80, allCount); + isUpload = UploadFile(childInfo.FullName, idValue, out msg); + SetProcessBar(100, finishCount); + SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}"); + } } - frmBillInfo.GcMainView.GridControl.DataSource = detailTable; - SetProcessBar(20, allCount); - frmBillInfo.InitializeHeader(dataRow, Model.BillMasterSql); - SetProcessBar(40, allCount); - string childBillNo = ""; - frmBillInfo.BillSave(ref childBillNo); - SetProcessBar(60, allCount); - frmBillInfo.OnBillAdd(); - //记录历史版本号 - string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'"; - SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, childBillNo)); - string updateChildVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{1}') and ProductId='{0}'"; - SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId)); - SetProcessBar(80, allCount); - isUpload = UploadFile(childInfo.FullName, idValue, out msg); - SetProcessBar(100, finishCount); - SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}"); } - else + } + else + { + FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault(); + if (childInfo != null) { isUpload = UploadFile(childInfo.FullName, idValue, out msg); SetProcessBar(100, finishCount); @@ -979,7 +1046,7 @@ namespace Lskj.PubBomImport for (int j = firstRow.FirstCellNum; j < cellCount; j++) { ICell cell = row.GetCell(j); - if (cell != null&& cell.IsMergedCell) + if (cell != null && cell.IsMergedCell) { CellRangeAddress mergrRange = FindMergedRegion(sheet, i, j); if (j == mergrRange.FirstColumn) @@ -1194,38 +1261,4 @@ namespace Lskj.PubBomImport { returnMsg = ex.Message; isUpload = false; - } - msg = returnMsg; - return isUpload; - } - /// - /// 附件转换byte[] - /// - /// 附件路径 - /// 二进制 - private byte[] ConvertFileToBytes(string filePath) - { - byte[] bytContent = null; - System.IO.FileStream fs = null; - System.IO.BinaryReader br = null; - try - { - fs = new FileStream(filePath, System.IO.FileMode.Open); - } - catch (Exception) - { - throw; - } - finally - { - if (fs != null) - br = new BinaryReader((Stream)fs); - if (br != null) - bytContent = br.ReadBytes((Int32)fs.Length); - if (fs != null) - fs.Dispose(); - } - return bytContent; - } - } -} + \ No newline at end of file diff --git a/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj b/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj index cd66c0d..f1f4c84 100644 --- a/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj +++ b/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj @@ -54,6 +54,7 @@ +