SVN r451
SVN-Revision: r451
This commit is contained in:
@@ -71,9 +71,52 @@ namespace Lskj.PubBomImport
|
|||||||
FileInfo parentInfo = fileInfos.Where(n => n.Name.StartsWith("MX") && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
FileInfo parentInfo = fileInfos.Where(n => n.Name.StartsWith("MX") && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||||
if (parentInfo != null)
|
if (parentInfo != null)
|
||||||
{
|
{
|
||||||
|
if (Directory.Exists("BomImportTemp"))
|
||||||
|
{
|
||||||
|
Directory.Delete("BomImportTemp", true);
|
||||||
|
}
|
||||||
|
Directory.CreateDirectory("BomImportTemp");
|
||||||
FrmBillInfo frmBillInfo = new FrmBillInfo();
|
FrmBillInfo frmBillInfo = new FrmBillInfo();
|
||||||
DataTable parentTable = ExcelToDatatable(parentInfo.FullName, Model, "", 5);
|
DataTable parentTable = ExcelToDatatable(parentInfo.FullName, Model, "", 5);
|
||||||
parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "")).ToList().CopyToDataTable();
|
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();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
foreach (DataRow dataRow in parentTable.Rows)
|
foreach (DataRow dataRow in parentTable.Rows)
|
||||||
{
|
{
|
||||||
@@ -107,16 +150,24 @@ namespace Lskj.PubBomImport
|
|||||||
foreach (DataRow parentRow in parentTable.Rows)
|
foreach (DataRow parentRow in parentTable.Rows)
|
||||||
{
|
{
|
||||||
string code = parentRow["图号"] + "";
|
string code = parentRow["图号"] + "";
|
||||||
FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault();
|
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
||||||
if (childInfo != null && (childInfo.Name.StartsWith("QD") || childInfo.Name.StartsWith("ZZQD")))
|
|
||||||
{
|
{
|
||||||
DataRow childRow = childTable.NewRow();
|
FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault();
|
||||||
childRow["ProductId"] = parentRow["图号"] + "";
|
if (childInfo == null)
|
||||||
childRow["appellation"] = parentRow["名称"] + "";
|
{
|
||||||
childRow["bak"] = parentRow["备注"] + "";
|
string tempFileName = childFileDic[code];
|
||||||
childRow["tamount"] = parentRow["套数"] + "";
|
childInfo = new FileInfo(tempFileName);
|
||||||
childRow["amount"] = parentRow["套数"] + "";
|
}
|
||||||
childTable.Rows.Add(childRow);
|
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);
|
SetProcessBar(20, 0);
|
||||||
@@ -148,43 +199,59 @@ namespace Lskj.PubBomImport
|
|||||||
int finishCount = (int)((decimal)(1 + nowCount) / (parentTable.Rows.Count + 1) * 100);
|
int finishCount = (int)((decimal)(1 + nowCount) / (parentTable.Rows.Count + 1) * 100);
|
||||||
int.TryParse(dataRow["套数"] + "", out int tamount);
|
int.TryParse(dataRow["套数"] + "", out int tamount);
|
||||||
string code = (dataRow["图号"] + "").Trim();
|
string code = (dataRow["图号"] + "").Trim();
|
||||||
FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault();
|
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
||||||
if (childInfo != null)
|
|
||||||
{
|
{
|
||||||
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);
|
FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault();
|
||||||
SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}");
|
if (childInfo == null)
|
||||||
DataTable detailTable = new DataTable();
|
|
||||||
frmMain.Invoke(new Action(() =>
|
|
||||||
{
|
{
|
||||||
detailTable = frmMain.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true);
|
string tempFileName = childFileDic[code];
|
||||||
}));
|
childInfo = new FileInfo(tempFileName);
|
||||||
foreach (DataRow detailRow in detailTable.Rows)
|
}
|
||||||
|
if (childInfo != null)
|
||||||
{
|
{
|
||||||
int.TryParse(detailRow["amount"] + "", out int lastAmount);
|
if ((code.StartsWith("QD") || code.StartsWith("ZZQD")))
|
||||||
detailRow["tamount"] = tamount;
|
{
|
||||||
detailRow["amount"] = lastAmount;
|
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);
|
isUpload = UploadFile(childInfo.FullName, idValue, out msg);
|
||||||
SetProcessBar(100, finishCount);
|
SetProcessBar(100, finishCount);
|
||||||
@@ -979,7 +1046,7 @@ namespace Lskj.PubBomImport
|
|||||||
for (int j = firstRow.FirstCellNum; j < cellCount; j++)
|
for (int j = firstRow.FirstCellNum; j < cellCount; j++)
|
||||||
{
|
{
|
||||||
ICell cell = row.GetCell(j);
|
ICell cell = row.GetCell(j);
|
||||||
if (cell != null&& cell.IsMergedCell)
|
if (cell != null && cell.IsMergedCell)
|
||||||
{
|
{
|
||||||
CellRangeAddress mergrRange = FindMergedRegion(sheet, i, j);
|
CellRangeAddress mergrRange = FindMergedRegion(sheet, i, j);
|
||||||
if (j == mergrRange.FirstColumn)
|
if (j == mergrRange.FirstColumn)
|
||||||
@@ -1194,38 +1261,4 @@ namespace Lskj.PubBomImport
|
|||||||
{
|
{
|
||||||
returnMsg = ex.Message;
|
returnMsg = ex.Message;
|
||||||
isUpload = false;
|
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>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Web" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
|||||||
Reference in New Issue
Block a user