SVN-Revision: r618
This commit is contained in:
wyf
2025-05-22 06:18:41 +00:00
parent d5489dc011
commit 1549d52346
3 changed files with 322 additions and 294 deletions
+1 -1
View File
@@ -242,7 +242,7 @@ namespace Lskj.PubBomImport
//param[6].Value = ""; //param[6].Value = "";
//param[7].Value = auditFlag; //param[7].Value = auditFlag;
//param[8].Value = comfirm; //param[8].Value = comfirm;
SqlHelper.ExecuteNonQuery($"delete p_bomImportExecTab where guid = '{guid}'");
SqlHelper.ExecuteNonQuery($"insert into p_bomImportExecTab (guid,detailTable,masterSql,detailSql,billNo,detailGuid,UserId,billWay,billSeq,auditFlag,comfirm,newVer) " + SqlHelper.ExecuteNonQuery($"insert into p_bomImportExecTab (guid,detailTable,masterSql,detailSql,billNo,detailGuid,UserId,billWay,billSeq,auditFlag,comfirm,newVer) " +
$"values ('{guid}','{billModel.DetailTable}','{masterSql.Replace("'", "''")}','{detailSql.Replace("'", "''")}','{billNo}','{detailGuid.Replace("'", "''")}','{ERPInfo.Instance.UserId}','{(billModel.SaveState ? 2 : 1)}','{billModel.BillSeq}','0','{comfirm}','{billModel.NewVer}')"); $"values ('{guid}','{billModel.DetailTable}','{masterSql.Replace("'", "''")}','{detailSql.Replace("'", "''")}','{billNo}','{detailGuid.Replace("'", "''")}','{ERPInfo.Instance.UserId}','{(billModel.SaveState ? 2 : 1)}','{billModel.BillSeq}','0','{comfirm}','{billModel.NewVer}')");
//int result = BillImpl.BillSave(masterSql, detailSql, billModel.DetailTable, ref billNo, detailGuid, billModel.BillSeq, billModel.SaveState ? 2 : 1, comfirm, out tipMsg, 0, billModel.NewVer); //int result = BillImpl.BillSave(masterSql, detailSql, billModel.DetailTable, ref billNo, detailGuid, billModel.BillSeq, billModel.SaveState ? 2 : 1, comfirm, out tipMsg, 0, billModel.NewVer);
-6
View File
@@ -460,12 +460,6 @@ namespace Lskj.PubBomImport
} }
string fileName = sourceRow[Model.AfterBomFieldName] + ""; string fileName = sourceRow[Model.AfterBomFieldName] + "";
string dirPath = sourceRow["BomFieldNameDir"] + ""; string dirPath = sourceRow["BomFieldNameDir"] + "";
FileInfo parentInfo = null;
if (string.IsNullOrEmpty(dirPath))
{
continue;
}
parentInfo = new FileInfo(dirPath);
selectRows.Add(sourceRow); selectRows.Add(sourceRow);
} }
if (selectRows.Count > 0) if (selectRows.Count > 0)
+321 -287
View File
@@ -817,7 +817,12 @@ namespace Lskj.PubBomImport
} }
Directory.CreateDirectory("BomImportTemp"); Directory.CreateDirectory("BomImportTemp");
int execOrder = 1; int execOrder = 1;
DataRow mxRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith("MX")).FirstOrDefault(); var mxRows = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith("MX"));
if (mxRows.Count() > 1)
{
throw new Exception($"不允许出现多个MX文件");
}
DataRow mxRow = mxRows.FirstOrDefault();
if (mxRow != null) if (mxRow != null)
{ {
string mxFileName = mxRow[Model.AfterBomFieldName] + ""; string mxFileName = mxRow[Model.AfterBomFieldName] + "";
@@ -841,66 +846,101 @@ namespace Lskj.PubBomImport
throw new Exception($"物料编码{productId}的BOM建立单已存在\r\n请进行修改操作"); throw new Exception($"物料编码{productId}的BOM建立单已存在\r\n请进行修改操作");
} }
} }
FileInfo mxInfo = new FileInfo(mxDirPath); else
if (mxInfo != null)
{ {
GetFileCodeInfo(Path.GetFileNameWithoutExtension(mxInfo.Name).Trim(), out string mxsourceCode, out string mxname, out string mxsourceBB, out int mxsourceBC); DataRow billbomRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}' and stepover = '1'");
DataTable mxfiletable = BaseImpl.GetDataTableResult($"select sname,fileId from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{productId}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{mxsourceCode}%'"); if (billbomRow != null)
{
throw new Exception($"物料编码{productId}的BOM建立单已终审\r\n禁止修改操作");
}
}
GetFileCodeInfo(mxFileName.Trim(), out string mxsourceCode, out string mxname, out string mxsourceBB, out int mxsourceBC);
DataTable mxfiletable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{productId}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{mxsourceCode}%'");
FileInfo mxInfo = null;
if (!string.IsNullOrEmpty(mxDirPath))
{
mxInfo = new FileInfo(mxDirPath);
}
if (mxInfo != null || mxfiletable.Rows.Count > 0)
{
if (mxfiletable.Rows.Count > 1)
{
throw new Exception($"{mxsourceCode}存在多个版次,请进行MX修改");
}
if (mxfiletable.Rows.Count > 0) if (mxfiletable.Rows.Count > 0)
{ {
throw new Exception($"{mxsourceCode}的附件已存在"); using (WebClient webClient = new WebClient())
}
int mxMaxBc = 0;
string mxMaxBcFileId = "-1";
foreach (DataRow mxfileRow in mxfiletable.Rows)
{
string fileName = mxfileRow["sname"] + "";
string fileId = mxfileRow["fileId"] + "";
GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
if (fileBC >= mxMaxBc)
{
mxMaxBc = fileBC;
mxMaxBcFileId = fileId;
}
}
if (mxsourceBC > mxMaxBc && mxfiletable.Rows.Count > 0)
{
throw new Exception($"{mxsourceCode}的版次为{mxsourceBC},大于最大版次{mxMaxBc}\r\n请进行变更");
}
mxsourceBC = mxsourceBC >= mxMaxBc ? mxsourceBC : mxMaxBc;
FrmBillInfo frmBillInfo = new FrmBillInfo();
DataTable parentTable = ExcelToDatatable(mxInfo.FullName, Model, "", 5);
parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "") && !string.IsNullOrEmpty(n["名称"] + "")).ToList().CopyToDataTable();
StringBuilder stringBuilder = new StringBuilder();
foreach (DataRow dataRow in parentTable.Rows)
{
string code = (dataRow["图号"] + "").Trim();
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
{
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{code}')");
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{code.Replace("'", "''")}','{(dataRow[""] + "").Replace("'", "''")}','{(dataRow[""] + "").Replace("'", "''")}','0199') end;");
}
}
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
{
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
}
frmBillInfo.OnControlSourceBind += (s, args) =>
{
Task task = new Task(() =>
{ {
try try
{ {
int.TryParse(Model.FirstRowIndex, out int index); string webpath = mxfiletable.Rows[0]["webpath"] + "";
frmMain.FirstRowIndex = index; string sName = mxfiletable.Rows[0]["sName"] + "";
bool isUpload = false; webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}";
string msg = ""; string url = $"{SystemInfo.Instance.OAUrl}/{webpath}";
DataRow parentProductRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}'"); string tempFileName = $"BomImportTemp/{sName}";
Dictionary<string, DataRow> maxBcFileDic = new Dictionary<string, DataRow>(); if (!File.Exists(tempFileName))
Dictionary<string, DataTable> fileTableDic = new Dictionary<string, DataTable>();
if (parentProductRow == null)
{ {
webClient.DownloadFile(url, tempFileName);
}
mxInfo = new FileInfo(tempFileName);
}
catch (Exception)
{
throw new Exception($"Bom明细附件{mxsourceCode}获取失败\r\nBom导入失败");
}
}
}
if (mxInfo != null)
{
int mxMaxBc = 0;
string mxMaxBcFileId = "-1";
foreach (DataRow mxfileRow in mxfiletable.Rows)
{
string fileName = mxfileRow["sname"] + "";
string fileId = mxfileRow["fileId"] + "";
GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
if (fileBC >= mxMaxBc)
{
mxMaxBc = fileBC;
mxMaxBcFileId = fileId;
}
}
if (mxsourceBC > mxMaxBc && mxfiletable.Rows.Count > 0)
{
throw new Exception($"{mxsourceCode}的版次为{mxsourceBC},大于最大版次{mxMaxBc}\r\n请进行变更");
}
mxsourceBC = mxsourceBC >= mxMaxBc ? mxsourceBC : mxMaxBc;
FrmBillInfo frmBillInfo = new FrmBillInfo();
DataTable parentTable = ExcelToDatatable(mxInfo.FullName, Model, "", 5);
parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "") && !string.IsNullOrEmpty(n["名称"] + "")).ToList().CopyToDataTable();
StringBuilder stringBuilder = new StringBuilder();
foreach (DataRow dataRow in parentTable.Rows)
{
string code = (dataRow["图号"] + "").Trim();
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
{
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{code}')");
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{code.Replace("'", "''")}','{(dataRow[""] + "").Replace("'", "''")}','{(dataRow[""] + "").Replace("'", "''")}','0199') end;");
}
}
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
{
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
}
frmBillInfo.OnControlSourceBind += (s, args) =>
{
Task task = new Task(() =>
{
try
{
int.TryParse(Model.FirstRowIndex, out int index);
frmMain.FirstRowIndex = index;
bool isUpload = false;
string msg = "";
Dictionary<string, DataRow> maxBcFileDic = new Dictionary<string, DataRow>();
Dictionary<string, DataTable> fileTableDic = new Dictionary<string, DataTable>();
#region MX
frmBillInfo.OnBillAdd(); frmBillInfo.OnBillAdd();
SetProcessBar(0, 0); SetProcessBar(0, 0);
SetProcessMsg($"正在导入:{Path.GetFileName(mxInfo.FullName)}"); SetProcessMsg($"正在导入:{Path.GetFileName(mxInfo.FullName)}");
@@ -936,7 +976,10 @@ namespace Lskj.PubBomImport
{ {
string childFileName = childInfoRow[Model.AfterBomFieldName] + ""; string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
string childDirPath = childInfoRow["BomFieldNameDir"] + ""; string childDirPath = childInfoRow["BomFieldNameDir"] + "";
childInfo = new FileInfo(childDirPath); if (!string.IsNullOrEmpty(childDirPath))
{
childInfo = new FileInfo(childDirPath);
}
} }
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null) if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
{ {
@@ -1036,10 +1079,10 @@ namespace Lskj.PubBomImport
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider.ToString().Replace("'", "''")}' where guid = '{guid}'"); BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider.ToString().Replace("'", "''")}' where guid = '{guid}'");
SetProcessBar(80, 0); SetProcessBar(80, 0);
//上传文件 //上传文件
string uploadFileId = mxMaxBcFileId; string uploadMxFileId = mxMaxBcFileId;
if (mxfiletable.Rows.Count == 0) if (mxfiletable.Rows.Count == 0)
{ {
isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010106", out msg, out uploadFileId); isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010106", out msg, out uploadMxFileId);
if (!isUpload) if (!isUpload)
{ {
throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}"); throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}");
@@ -1049,7 +1092,7 @@ namespace Lskj.PubBomImport
{ {
if (mxRow.Table.Columns.Contains("qms_laddf_FileId")) if (mxRow.Table.Columns.Contains("qms_laddf_FileId"))
{ {
int.TryParse(uploadFileId, out int qms_laddf_FileId); int.TryParse(uploadMxFileId, out int qms_laddf_FileId);
mxRow["qms_laddf_FileId"] = qms_laddf_FileId; mxRow["qms_laddf_FileId"] = qms_laddf_FileId;
} }
if (mxRow.Table.Columns.Contains("qms_laddf_Exec")) if (mxRow.Table.Columns.Contains("qms_laddf_Exec"))
@@ -1062,123 +1105,211 @@ namespace Lskj.PubBomImport
} }
})); }));
execOrder += 1; execOrder += 1;
} #endregion
else SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
{ SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
string uploadFileId = mxMaxBcFileId; foreach (DataRow dataRow in parentTable.Rows)
if (mxfiletable.Rows.Count == 0)
{ {
isUpload = UploadFileToAudit(mxInfo.FullName, mxsourceCode, "010106", out msg, out uploadFileId); int childIndex = parentTable.Rows.IndexOf(dataRow);
if (!isUpload) int nowCount = 1 + childIndex;
int allCount = (int)((decimal)(1 + childIndex) / (parentTable.Rows.Count + 1) * 100);
int finishCount = (int)((decimal)(1 + nowCount) / (parentTable.Rows.Count + 1) * 100);
int.TryParse(dataRow["套数"] + "", out int tamount);
string code = (dataRow["图号"] + "").Trim();
DataTable filetable = fileTableDic.ContainsKey(code) ? fileTableDic[code] : null;
if (code.StartsWith("QD"))
{ {
throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}"); FileInfo childInfo = null;
} DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
} if (childInfoRow != null)
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{
if (mxRow.Table.Columns.Contains("qms_laddf_FileId"))
{
int.TryParse(uploadFileId, out int qms_laddf_FileId);
mxRow["qms_laddf_FileId"] = qms_laddf_FileId;
}
}));
}
SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
foreach (DataRow dataRow in parentTable.Rows)
{
int childIndex = parentTable.Rows.IndexOf(dataRow);
int nowCount = 1 + childIndex;
int allCount = (int)((decimal)(1 + childIndex) / (parentTable.Rows.Count + 1) * 100);
int finishCount = (int)((decimal)(1 + nowCount) / (parentTable.Rows.Count + 1) * 100);
int.TryParse(dataRow["套数"] + "", out int tamount);
string code = (dataRow["图号"] + "").Trim();
DataTable filetable = fileTableDic.ContainsKey(code) ? fileTableDic[code] : null;
if (code.StartsWith("QD"))
{
FileInfo childInfo = null;
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
if (childInfoRow != null)
{
string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
childInfo = new FileInfo(childDirPath);
}
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
{
using (WebClient webClient = new WebClient())
{ {
try string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
if (!string.IsNullOrEmpty(childDirPath))
{ {
string webpath = maxBcFileDic[code]["webpath"] + ""; childInfo = new FileInfo(childDirPath);
string sName = maxBcFileDic[code]["sName"] + "";
webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}";
string url = $"{SystemInfo.Instance.OAUrl}/{webpath}";
string tempFileName = $"BomImportTemp/{sName}";
if (!File.Exists(tempFileName))
{
webClient.DownloadFile(url, tempFileName);
}
childInfo = new FileInfo(tempFileName);
}
catch (Exception)
{
throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败");
} }
} }
} if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
if (childInfo == null)
{
throw new Exception($"MX明细中的{code}文件不存在");
}
if (childInfo != null)
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string qdsourceCode, out string qdname, out string qdsourceBB, out int qdsourceBC);
DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{code}'");
if (productRow == null)
{ {
string childGuid = Guid.NewGuid() + ""; using (WebClient webClient = new WebClient())
{
try
{
string webpath = maxBcFileDic[code]["webpath"] + "";
string sName = maxBcFileDic[code]["sName"] + "";
webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}";
string url = $"{SystemInfo.Instance.OAUrl}/{webpath}";
string tempFileName = $"BomImportTemp/{sName}";
if (!File.Exists(tempFileName))
{
webClient.DownloadFile(url, tempFileName);
}
childInfo = new FileInfo(tempFileName);
}
catch (Exception)
{
throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败");
}
}
}
if (childInfo == null)
{
throw new Exception($"MX明细中的{code}文件不存在");
}
if (childInfo != null)
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string qdsourceCode, out string qdname, out string qdsourceBB, out int qdsourceBC);
DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{code}'");
if (productRow == null)
{
string childGuid = childInfoRow != null && !string.IsNullOrEmpty(childInfoRow["qms_laddf_Exec"] + "") ? childInfoRow["qms_laddf_Exec"] + "" : Guid.NewGuid() + "";
string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
if (filetable.Rows.Count == 0)
{
frmBillInfo.OnBillAdd();
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 amount);
//数量暂定为自身数量
detailRow["tamount"] = amount;
detailRow["amount"] = amount;
}
if (detailTable.Rows.Count == 0)
{
throw new Exception($"{code}明细数据为空");
}
SetProcessBar(40, allCount);
string childBillMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{code}') as billdocument_id,'0' affirmer,'0' rtagid,'{code}' as productid,'{qdsourceCode}' as bak,'{qdsourceBB}' as bombb,'{qdsourceBC}' as bombc";
// 处理单据表头数据
DataRow childMasterRow = BillImpl.GetDataRowResult(childBillMasterSql);
SetProcessBar(60, allCount);
frmBillInfo.AddOrUpdateBill(childMasterRow, detailTable);
frmBillInfo.BillSaveSql(childGuid);
SetProcessBar(80, allCount);
//记录历史版本号
//string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
//SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, childBillNo));
//备份Bom清单明细
//string bakBomListSql = @"delete bom_BillListlogTab where parentProduct = '{0}' and historyVer = (select top 1 historyVer from bom_BillListTab where parentProduct = '{0}');insert into bom_BillListlogTab select * from bom_BillListTab where parentProduct = '{0}';";
//SqlHelper.ExecuteNonQuery(string.Format(bakBomListSql, code));
//确认不关联
//更新明细关联版本号
//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);
if (filetable.Rows.Count == 0)
{
isUpload = UploadFileToAudit(childInfo.FullName, qdsourceCode, "010106", out msg, out uploadFileId);
if (!isUpload)
{
throw new Exception($"{code}附件上传失败\r\n{msg}");
}
}
}
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{
if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId"))
{
int.TryParse(uploadFileId, out int qms_laddf_FileId);
childInfoRow["qms_laddf_FileId"] = qms_laddf_FileId;
}
if (childInfoRow.Table.Columns.Contains("qms_laddf_Exec"))
{
childInfoRow["qms_laddf_Exec"] = childGuid;
}
if (childInfoRow.Table.Columns.Contains("qms_laddf_ExecOrder"))
{
childInfoRow["qms_laddf_ExecOrder"] = execOrder;
}
}));
execOrder += 1;
SetProcessBar(100, finishCount);
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
}
else
{
SetProcessBar(0, allCount);
string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
if (filetable.Rows.Count == 0)
{
isUpload = UploadFileToAudit(childInfo.FullName, qdsourceCode, "010106", out msg, out uploadFileId);
if (!isUpload)
{
throw new Exception($"{code}附件上传失败\r\n{msg}");
}
}
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{
if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId"))
{
int.TryParse(uploadFileId, out int qms_laddf_FileId);
childInfoRow["qms_laddf_FileId"] = qms_laddf_FileId;
}
}));
SetProcessBar(100, finishCount);
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
}
}
else
{
throw new Exception($"目录中不包含文件{code}");
}
}
else
{
FileInfo childInfo = null;
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
if (childInfoRow != null)
{
string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
if (!string.IsNullOrEmpty(childDirPath))
{
childInfo = new FileInfo(childDirPath);
}
}
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
{
using (WebClient webClient = new WebClient())
{
try
{
string webpath = maxBcFileDic[code]["webpath"] + "";
string sName = maxBcFileDic[code]["sName"] + "";
webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}";
string url = $"{SystemInfo.Instance.OAUrl}/{webpath}";
string tempFileName = $"BomImportTemp/{sName}";
if (!File.Exists(tempFileName))
{
webClient.DownloadFile(url, tempFileName);
}
childInfo = new FileInfo(tempFileName);
}
catch (Exception)
{
throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败");
}
}
}
if (childInfo == null)
{
throw new Exception($"目录中不包含文件{code}");
}
if (childInfo != null)
{
SetProcessBar(0, allCount);
string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1"; string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
if (filetable.Rows.Count == 0) if (filetable.Rows.Count == 0)
{ {
frmBillInfo.OnBillAdd(); GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string qdsourceCode, out string qdname, out string qdsourceBB, out int qdsourceBC);
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 amount);
//数量暂定为自身数量
detailRow["tamount"] = amount;
detailRow["amount"] = amount;
}
if (detailTable.Rows.Count == 0)
{
throw new Exception($"{code}明细数据为空");
}
SetProcessBar(40, allCount);
string childBillMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{code}') as billdocument_id,'0' affirmer,'0' rtagid,'{code}' as productid,'{qdsourceCode}' as bak,'{qdsourceBB}' as bombb,'{qdsourceBC}' as bombc";
// 处理单据表头数据
DataRow childMasterRow = BillImpl.GetDataRowResult(childBillMasterSql);
SetProcessBar(60, allCount);
frmBillInfo.AddOrUpdateBill(childMasterRow, detailTable);
frmBillInfo.BillSaveSql(childGuid);
SetProcessBar(80, allCount);
//记录历史版本号
//string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
//SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, childBillNo));
//备份Bom清单明细
//string bakBomListSql = @"delete bom_BillListlogTab where parentProduct = '{0}' and historyVer = (select top 1 historyVer from bom_BillListTab where parentProduct = '{0}');insert into bom_BillListlogTab select * from bom_BillListTab where parentProduct = '{0}';";
//SqlHelper.ExecuteNonQuery(string.Format(bakBomListSql, code));
//确认不关联
//更新明细关联版本号
//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);
if (filetable.Rows.Count == 0) if (filetable.Rows.Count == 0)
{ {
isUpload = UploadFileToAudit(childInfo.FullName, qdsourceCode, "010106", out msg, out uploadFileId); isUpload = UploadFileToAudit(childInfo.FullName, qdsourceCode, "010106", out msg, out uploadFileId);
@@ -1195,140 +1326,43 @@ namespace Lskj.PubBomImport
int.TryParse(uploadFileId, out int qms_laddf_FileId); int.TryParse(uploadFileId, out int qms_laddf_FileId);
childInfoRow["qms_laddf_FileId"] = qms_laddf_FileId; childInfoRow["qms_laddf_FileId"] = qms_laddf_FileId;
} }
if (childInfoRow.Table.Columns.Contains("qms_laddf_Exec"))
{
childInfoRow["qms_laddf_Exec"] = childGuid;
}
if (childInfoRow.Table.Columns.Contains("qms_laddf_ExecOrder"))
{
childInfoRow["qms_laddf_ExecOrder"] = execOrder;
}
})); }));
execOrder += 1;
SetProcessBar(100, finishCount); SetProcessBar(100, finishCount);
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}"); SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
} }
else else
{ {
SetProcessBar(0, allCount); throw new Exception($"目录中不包含文件{code}");
string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
if (filetable.Rows.Count == 0)
{
isUpload = UploadFileToAudit(childInfo.FullName, qdsourceCode, "010106", out msg, out uploadFileId);
if (!isUpload)
{
throw new Exception($"{code}附件上传失败\r\n{msg}");
}
}
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{
if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId"))
{
int.TryParse(uploadFileId, out int qms_laddf_FileId);
childInfoRow["qms_laddf_FileId"] = qms_laddf_FileId;
}
}));
SetProcessBar(100, finishCount);
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
} }
} }
else
{
throw new Exception($"目录中不包含文件{code}");
}
} }
else this.Invoke(new Action(() =>
{ {
FileInfo childInfo = null; this.DialogResult = DialogResult.OK;
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault(); Close();
if (childInfoRow != null) ImportTimer?.Dispose();
{ }));
string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
childInfo = new FileInfo(childDirPath);
}
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
{
using (WebClient webClient = new WebClient())
{
try
{
string webpath = maxBcFileDic[code]["webpath"] + "";
string sName = maxBcFileDic[code]["sName"] + "";
webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}";
string url = $"{SystemInfo.Instance.OAUrl}/{webpath}";
string tempFileName = $"BomImportTemp/{sName}";
if (!File.Exists(tempFileName))
{
webClient.DownloadFile(url, tempFileName);
}
childInfo = new FileInfo(tempFileName);
}
catch (Exception)
{
throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败");
}
}
}
if (childInfo == null)
{
throw new Exception($"目录中不包含文件{code}");
}
if (childInfo != null)
{
SetProcessBar(0, allCount);
string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
if (filetable.Rows.Count == 0)
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string qdsourceCode, out string qdname, out string qdsourceBB, out int qdsourceBC);
if (filetable.Rows.Count == 0)
{
isUpload = UploadFileToAudit(childInfo.FullName, qdsourceCode, "010106", out msg, out uploadFileId);
if (!isUpload)
{
throw new Exception($"{code}附件上传失败\r\n{msg}");
}
}
}
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{
if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId"))
{
int.TryParse(uploadFileId, out int qms_laddf_FileId);
childInfoRow["qms_laddf_FileId"] = qms_laddf_FileId;
}
}));
SetProcessBar(100, finishCount);
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
}
else
{
throw new Exception($"目录中不包含文件{code}");
}
}
} }
this.Invoke(new Action(() => catch (Exception ex)
{ {
this.DialogResult = DialogResult.OK; MessageUtil.Show(ex.Message);
Close(); this.Invoke(new Action(() =>
ImportTimer?.Dispose(); {
})); this.DialogResult = DialogResult.Cancel;
} Close();
catch (Exception ex) ImportTimer?.Dispose();
{ }));
MessageUtil.Show(ex.Message); }
this.Invoke(new Action(() => });
{ task.Start();
this.DialogResult = DialogResult.Cancel; };
Close(); frmBillInfo.OnLoad(Model);
ImportTimer?.Dispose(); frmMain.ParentView = frmBillInfo.GcMainView;
})); }
} else
}); {
task.Start(); throw new Exception("未找到MX文件");
}; }
frmBillInfo.OnLoad(Model);
frmMain.ParentView = frmBillInfo.GcMainView;
} }
else else
{ {