SVN-Revision: r451
This commit is contained in:
wyf
2025-04-07 04:19:22 +00:00
parent c009dd8b71
commit ee1e8ed97d
2 changed files with 110 additions and 76 deletions
+70 -37
View File
@@ -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<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "")).ToList().CopyToDataTable();
Dictionary<string, string> childFileDic = new Dictionary<string, string>();
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,8 +150,15 @@ namespace Lskj.PubBomImport
foreach (DataRow parentRow in parentTable.Rows)
{
string code = parentRow["图号"] + "";
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
{
FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault();
if (childInfo != null && (childInfo.Name.StartsWith("QD") || childInfo.Name.StartsWith("ZZQD")))
if (childInfo == null)
{
string tempFileName = childFileDic[code];
childInfo = new FileInfo(tempFileName);
}
if (childInfo != null)
{
DataRow childRow = childTable.NewRow();
childRow["ProductId"] = parentRow["图号"] + "";
@@ -119,6 +169,7 @@ namespace Lskj.PubBomImport
childTable.Rows.Add(childRow);
}
}
}
SetProcessBar(20, 0);
frmBillInfo.GcMainView.GridControl.DataSource = childTable;
SetProcessBar(40, 0);
@@ -148,7 +199,17 @@ namespace Lskj.PubBomImport
int finishCount = (int)((decimal)(1 + nowCount) / (parentTable.Rows.Count + 1) * 100);
int.TryParse(dataRow["套数"] + "", out int tamount);
string code = (dataRow["图号"] + "").Trim();
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)
{
FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault();
if (childInfo == null)
{
string tempFileName = childFileDic[code];
childInfo = new FileInfo(tempFileName);
}
if (childInfo != null)
{
if ((code.StartsWith("QD") || code.StartsWith("ZZQD")))
@@ -184,7 +245,13 @@ namespace Lskj.PubBomImport
SetProcessBar(100, finishCount);
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
}
}
}
}
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;
}
/// <summary>
/// 附件转换byte[]
/// </summary>
/// <param name="filePath">附件路径</param>
/// <returns>二进制</returns>
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;
}
}
}
@@ -54,6 +54,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />