SVN-Revision: r577
This commit is contained in:
wyf
2025-05-14 11:34:51 +00:00
parent 655763a1c0
commit da1a53eb06
+266 -178
View File
@@ -1153,9 +1153,11 @@ namespace Lskj.PubBomImport
{ {
try try
{ {
string namepattern = @"^([A-Z]+(?:-[A-Z]+)*(?:-\d+)+-[A-Z]+\d*)\s*(.*)$"; if (Directory.Exists("BomImportTemp"))
//string namepattern = @"^(.+?)\s+(.+)$"; {
string pattern = @"^(.*?)(\d+)?$"; Directory.Delete("BomImportTemp", true);
}
Directory.CreateDirectory("BomImportTemp");
int execOrder = 1; int execOrder = 1;
DataRow mxRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith("MX")).FirstOrDefault(); DataRow mxRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith("MX")).FirstOrDefault();
if (mxRow != null) if (mxRow != null)
@@ -1175,49 +1177,28 @@ namespace Lskj.PubBomImport
FileInfo mxInfo = new FileInfo(mxDirPath); FileInfo mxInfo = new FileInfo(mxDirPath);
if (mxInfo != null) if (mxInfo != null)
{ {
string mxcode = ""; GetFileCodeInfo(Path.GetFileNameWithoutExtension(mxInfo.Name).Trim(), out string mxsourceCode, out string mxname, out string mxsourceBB, out int mxsourceBC);
string mxname = ""; DataTable mxfiletable = BaseImpl.GetDataTableResult($"select sname,fileId from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{mxsourceCode}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{mxsourceCode}%'");
string mxsourceCode = ""; int mxMaxBc = 0;
string mxsourceBB = ""; string mxMaxBcFileId = "-1";
int mxsourceBC = 0; foreach (DataRow mxfileRow in mxfiletable.Rows)
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(mxInfo.Name).Trim(), namepattern);
if (namematch.Success)
{ {
mxcode = namematch.Groups[1].Value.Trim(); string fileName = mxfileRow["sname"] + "";
mxname = namematch.Groups[2].Value.Trim(); string fileId = mxfileRow["fileId"] + "";
} GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
Match match = Regex.Match(mxcode, pattern); if (fileBC >= mxMaxBc)
if (match.Success)
{
mxsourceCode = match.Groups[1].Value;
int.TryParse(match.Groups[2].Value, out mxsourceBC);//版次
Match bbMatch = Regex.Match(mxsourceCode, @"^.*?([A-Za-z]+)(\d*)$");
if (bbMatch.Success)
{ {
mxsourceBB = bbMatch.Groups[1].Value.Trim(); mxMaxBc = fileBC;
mxMaxBcFileId = fileId;
} }
} }
if (mxsourceBC > mxMaxBc && mxfiletable.Rows.Count > 0)
{
throw new Exception($"{mxsourceCode}的版次为{mxsourceBC},大于最大版次{mxMaxBc}\r\n请进行变更");
}
FrmBillInfo frmBillInfo = new FrmBillInfo(); FrmBillInfo frmBillInfo = new FrmBillInfo();
DataTable parentTable = ExcelToDatatable(mxInfo.FullName, Model, "", 5); 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(); parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "") && !string.IsNullOrEmpty(n["名称"] + "")).ToList().CopyToDataTable();
foreach (DataRow parentRow in parentTable.Rows)
{
string fileName = (parentRow["图号"] + "").Trim();
if (fileName.StartsWith("QD") || fileName.StartsWith("ZZQD"))
{
DataRow childRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(fileName)).FirstOrDefault();
if (childRow != null)
{
string childFileName = childRow[Model.AfterBomFieldName] + "";
string childDirPath = childRow["BomFieldNameDir"] + "";
FileInfo childInfo = new FileInfo(childDirPath);
if (childInfo == null)
{
throw new Exception($"MX明细中不包含文件{childFileName}");
}
}
}
}
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
foreach (DataRow dataRow in parentTable.Rows) foreach (DataRow dataRow in parentTable.Rows)
{ {
@@ -1243,115 +1224,151 @@ namespace Lskj.PubBomImport
bool isUpload = false; bool isUpload = false;
string msg = ""; string msg = "";
DataRow parentProductRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}'"); DataRow parentProductRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}'");
Dictionary<string, DataRow> maxBcFileDic = new Dictionary<string, DataRow>();
Dictionary<string, DataTable> fileTableDic = new Dictionary<string, DataTable>();
if (parentProductRow == null) if (parentProductRow == null)
{ {
frmBillInfo.OnBillAdd(); frmBillInfo.OnBillAdd();
SetProcessBar(0, 0); SetProcessBar(0, 0);
SetProcessMsg($"正在导入:{Path.GetFileName(mxInfo.FullName)}"); SetProcessMsg($"正在导入:{Path.GetFileName(mxInfo.FullName)}");
DataTable childTable = frmBillInfo.GcMainView.GridControl.DataSourceTable().Clone(); DataTable childTable = frmBillInfo.GcMainView.GridControl.DataSourceTable().Clone();
//foreach (GridColumn gridColumn in frmBillInfo.GcMainView.Columns) StringBuilder insertbulider = new StringBuilder();
//{ insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{productId}';");
// if (!childTable.Columns.Contains(gridColumn.FieldName)) insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName) values ('{productId}','{mxsourceCode + mxsourceBC}','{mxsourceCode}');");
// {
// childTable.Columns.Add(gridColumn.FieldName, gridColumn.ColumnType);
// }
//}
foreach (DataRow parentRow in parentTable.Rows) foreach (DataRow parentRow in parentTable.Rows)
{ {
int.TryParse(parentRow["套数"] + "", out int tamount); int.TryParse(parentRow["套数"] + "", out int tamount);
string code = (parentRow["图号"] + "").Trim(); string code = (parentRow["图号"] + "").Trim();
if (code.StartsWith("QD") || code.StartsWith("ZZQD")) insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName) values ('{productId}','{mxsourceCode + mxsourceBC}','{code}');");
DataTable filetable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{code}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{code}%'");
fileTableDic[code] = filetable;
int childMaxBc = 0;
foreach (DataRow fileRow in filetable.Rows)
{ {
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault(); string fileName = fileRow["sname"] + "";
if (childInfoRow != null) string fileId = fileRow["fileId"] + "";
GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
if (fileBC >= childMaxBc)
{ {
string childFileName = childInfoRow[Model.AfterBomFieldName] + ""; childMaxBc = fileBC;
string childDirPath = childInfoRow["BomFieldNameDir"] + ""; maxBcFileDic[code] = fileRow;
FileInfo childInfo = new FileInfo(childDirPath); }
if (childInfo == null) }
//判断code是否已经上传,如果已经上传则不再上传,
//如果附件不存在文件夹中,则直接使用最新的
//如果附件不存在则提示
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
if (childInfoRow != null)
{
string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
FileInfo childInfo = new FileInfo(childDirPath);
if (childInfo != null)
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string childsourceCode, out string childname, out string childsourceBB, out int childsourceBC);
//如果文件夹中有附件,则比较版次,如果大于最大版次,则提示
if (childsourceBC > childMaxBc && filetable.Rows.Count > 0)
{ {
throw new Exception($"MX明细中不包含文件{childFileName}"); throw new Exception($"{childsourceCode}的版次为{childsourceBC},大于最大版次{childMaxBc}\r\n请进行变更");
} }
if (childInfo != null) }
if (childInfo == null && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
{
using (WebClient webClient = new WebClient())
{ {
string childcode = ""; try
string childname = "";
string childsourceCode = "";
string childsourceBB = "";
int childsourceBC = 0;
namematch = Regex.Match(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), namepattern);
if (namematch.Success)
{ {
childcode = namematch.Groups[1].Value.Trim(); string webpath = maxBcFileDic[code]["webpath"] + "";
childname = namematch.Groups[2].Value.Trim(); string sName = maxBcFileDic[code]["sName"] + "";
} webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}";
match = Regex.Match(childcode, pattern); string url = $"{SystemInfo.Instance.OAUrl}/{webpath}";
if (match.Success) string tempFileName = $"BomImportTemp/{sName}";
{ if (!File.Exists(tempFileName))
childsourceCode = match.Groups[1].Value;
int.TryParse(match.Groups[2].Value, out childsourceBC);//版次
Match bbMatch = Regex.Match(childsourceCode, @"^.*?([A-Za-z]+)(\d*)$");
if (bbMatch.Success)
{ {
childsourceBB = bbMatch.Groups[1].Value.Trim(); webClient.DownloadFile(url, tempFileName);
}
childInfo = new FileInfo(tempFileName);
}
catch (Exception)
{
throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败");
}
}
}
if (childInfo != null)
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string childsourceCode, out string childname, out string childsourceBB, out int childsourceBC);
//如果文件夹中有附件,则比较版次,如果大于最大版次,则提示
if (childsourceBC > childMaxBc && filetable.Rows.Count > 0)
{
throw new Exception($"{childsourceCode}的版次为{childsourceBC},大于最大版次{childMaxBc}\r\n请进行变更");
}
if (code.StartsWith("ZZQD"))
{
DataTable zzqdTable = ExcelToDatatable(childInfo.FullName, Model, "", index);
DataView filterDataView = new DataView(zzqdTable);
try
{
if (!string.IsNullOrEmpty(Model.ReadTableCond))
{
filterDataView.RowFilter = Model.ReadTableCond;
} }
} }
if (code.StartsWith("ZZQD")) catch (Exception)
{ {
DataTable zzqdTable = ExcelToDatatable(childInfo.FullName, Model, "", index);
//frmMain.Invoke(new Action(() =>
//{
// zzqdTable = frmMain.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true);
//}));
DataView filterDataView = new DataView(zzqdTable);
try
{
if (!string.IsNullOrEmpty(Model.ReadTableCond))
{
filterDataView.RowFilter = Model.ReadTableCond;
}
}
catch (Exception)
{
}
zzqdTable = filterDataView.ToTable();
foreach (DataRow zzqdItem in zzqdTable.Rows)
{
DataRow childRow = childTable.NewRow();
childRow["ProductId"] = zzqdItem["物料编码"] + "";
childRow["appellation"] = zzqdItem["名称"] + "";
childRow["bak"] = childsourceCode;
childRow["bombb"] = childsourceBB;
childRow["bombc"] = childsourceBC;
childRow["tamount"] = parentRow["套数"] + "";
int.TryParse(zzqdItem["数量"] + "", out int amount);
childRow["amount"] = amount * tamount;
childTable.Rows.Add(childRow);
}
} }
else zzqdTable = filterDataView.ToTable();
foreach (DataRow zzqdItem in zzqdTable.Rows)
{ {
DataRow childRow = childTable.NewRow(); DataRow childRow = childTable.NewRow();
childRow["ProductId"] = parentRow["图号"] + ""; childRow["ProductId"] = zzqdItem["物料编码"] + "";
childRow["appellation"] = parentRow["名称"] + ""; childRow["appellation"] = zzqdItem["名称"] + "";
childRow["bak"] = childsourceCode; childRow["bak"] = childsourceCode;
childRow["bombb"] = childsourceBB; childRow["bombb"] = childsourceBB;
childRow["bombc"] = childsourceBC; childRow["bombc"] = childsourceBC;
childRow["tamount"] = parentRow["套数"] + ""; childRow["tamount"] = parentRow["套数"] + "";
childRow["amount"] = parentRow["套数"] + ""; int.TryParse(zzqdItem["数量"] + "", out int amount);
childRow["amount"] = amount * tamount;
childTable.Rows.Add(childRow); childTable.Rows.Add(childRow);
} }
} }
else if (code.StartsWith("QD"))
{
DataRow childRow = childTable.NewRow();
childRow["ProductId"] = parentRow["图号"] + "";
childRow["appellation"] = parentRow["名称"] + "";
childRow["bak"] = childsourceCode;
childRow["bombb"] = childsourceBB;
childRow["bombc"] = childsourceBC;
childRow["tamount"] = parentRow["套数"] + "";
childRow["amount"] = parentRow["套数"] + "";
childTable.Rows.Add(childRow);
}
}
else
{
if (filetable.Rows.Count == 0)
{
throw new Exception($"{code}的附件不存在,请检查文件");
}
}
}
else
{
if (filetable.Rows.Count == 0)
{
throw new Exception($"{code}的附件不存在,请检查文件");
} }
} }
} }
BaseImpl.ExecSqlValue(insertbulider.ToString());
SetProcessBar(20, 0); SetProcessBar(20, 0);
if (childTable.Rows.Count == 0) if (childTable.Rows.Count == 0)
{ {
throw new Exception($"MX明细数据空"); throw new Exception($"MX明细数据不能空");
} }
SetProcessBar(40, 0); SetProcessBar(40, 0);
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{productId}') as billdocument_id,'0' affirmer,'0' rtagid,'{productId}' as productid,'{mxcode}' as bak,'{mxsourceBB}' as bombb,'{mxsourceBC}' as bombc"; string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{productId}') as billdocument_id,'0' affirmer,'0' rtagid,'{productId}' as productid,'{mxsourceCode}' as bak,'{mxsourceBB}' as bombb,'{mxsourceBC}' as bombc";
// 处理单据表头数据 // 处理单据表头数据
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql); DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
SetProcessBar(60, 0); SetProcessBar(60, 0);
@@ -1359,23 +1376,21 @@ namespace Lskj.PubBomImport
string guid = Guid.NewGuid() + ""; string guid = Guid.NewGuid() + "";
frmBillInfo.BillSaveSql(guid); frmBillInfo.BillSaveSql(guid);
SetProcessBar(80, 0); SetProcessBar(80, 0);
//确认不反写子集
//string billdocumentId = Model.MaintabFocusedRow["单据编号"] + "";
//string billdocumentId = BaseImpl.GetResult("") + "";//
//string idValue = BaseImpl.GetResult($"select top 1 billdocument_id from bom_billListTab where ParentProduct = '{productId}'") + "";
//string updateParentVerSql = @"update bom_BillListTab set Ver = '{0}' where Billdocument_Id='{1}' and ProductId='{0}'";
//SqlHelper.ExecuteNonQuery(string.Format(updateParentVerSql, idValue, billdocumentId));
//上传文件 //上传文件
isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010106", out msg, out string fileId); string uploadFileId = mxMaxBcFileId;
if (!isUpload) if (mxfiletable.Rows.Count == 0)
{ {
throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}"); isUpload = UploadFileToAudit(mxInfo.FullName, mxsourceCode, "010106", out msg, out uploadFileId);
if (!isUpload)
{
throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}");
}
} }
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() => StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{ {
if (mxRow.Table.Columns.Contains("qms_laddf_FileId")) if (mxRow.Table.Columns.Contains("qms_laddf_FileId"))
{ {
int.TryParse(fileId, out int qms_laddf_FileId); int.TryParse(uploadFileId, 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"))
@@ -1391,12 +1406,20 @@ namespace Lskj.PubBomImport
} }
else else
{ {
isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010106", out msg, out string fileId); string uploadFileId = mxMaxBcFileId;
if (mxfiletable.Rows.Count == 0)
{
isUpload = UploadFileToAudit(mxInfo.FullName, mxsourceCode, "010106", out msg, out uploadFileId);
if (!isUpload)
{
throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}");
}
}
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() => StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{ {
if (mxRow.Table.Columns.Contains("qms_laddf_FileId")) if (mxRow.Table.Columns.Contains("qms_laddf_FileId"))
{ {
int.TryParse(fileId, out int qms_laddf_FileId); int.TryParse(uploadFileId, out int qms_laddf_FileId);
mxRow["qms_laddf_FileId"] = qms_laddf_FileId; mxRow["qms_laddf_FileId"] = qms_laddf_FileId;
} }
})); }));
@@ -1411,6 +1434,7 @@ 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();
DataTable filetable = fileTableDic.ContainsKey(code) ? fileTableDic[code] : null;
if (code.StartsWith("QD")) if (code.StartsWith("QD"))
{ {
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault(); DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
@@ -1419,35 +1443,36 @@ namespace Lskj.PubBomImport
string childFileName = childInfoRow[Model.AfterBomFieldName] + ""; string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
string childDirPath = childInfoRow["BomFieldNameDir"] + ""; string childDirPath = childInfoRow["BomFieldNameDir"] + "";
FileInfo childInfo = new FileInfo(childDirPath); FileInfo childInfo = new FileInfo(childDirPath);
if (childInfo == null && 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) if (childInfo == null)
{ {
throw new Exception($"MX明细中不包含文件{childFileName}"); throw new Exception($"MX明细中的{code}文件不存在");
} }
if (childInfo != null) if (childInfo != null)
{ {
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string qdsourceCode, out string qdname, out string qdsourceBB, out int qdsourceBC);
string qdcode = "";
string qdname = "";
string qdsourceCode = "";
string qdsourceBB = "";
int qdsourceBC = 0;
namematch = Regex.Match(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), namepattern);
if (namematch.Success)
{
qdcode = namematch.Groups[1].Value.Trim();
qdname = namematch.Groups[2].Value.Trim();
}
match = Regex.Match(qdcode, pattern);
if (match.Success)
{
qdsourceCode = match.Groups[1].Value;
int.TryParse(match.Groups[2].Value, out qdsourceBC);//版次
Match bbMatch = Regex.Match(qdsourceCode, @"^.*?([A-Za-z]+)(\d*)$");
if (bbMatch.Success)
{
qdsourceBB = bbMatch.Groups[1].Value.Trim();
}
}
DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{code}'"); DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{code}'");
if (productRow == null) if (productRow == null)
{ {
@@ -1473,7 +1498,7 @@ namespace Lskj.PubBomImport
throw new Exception($"{code}明细数据为空"); throw new Exception($"{code}明细数据为空");
} }
SetProcessBar(40, allCount); 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,'{qdcode}' as bak,'{qdsourceBB}' as bombb,'{qdsourceBC}' as bombc"; 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); DataRow childMasterRow = BillImpl.GetDataRowResult(childBillMasterSql);
SetProcessBar(60, allCount); SetProcessBar(60, allCount);
@@ -1492,16 +1517,20 @@ namespace Lskj.PubBomImport
//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}'"; //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)); //SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId));
SetProcessBar(80, allCount); SetProcessBar(80, allCount);
isUpload = UploadFileToAudit(childInfo.FullName, code, "010106", out msg, out string childFieldId); string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
if (!isUpload) if (filetable.Rows.Count == 0)
{ {
throw new Exception($"{childInfo.Name}附件上传失败\r\n{msg}"); 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(() => StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{ {
if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId")) if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId"))
{ {
int.TryParse(childFieldId, 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")) if (childInfoRow.Table.Columns.Contains("qms_laddf_Exec"))
@@ -1521,16 +1550,20 @@ namespace Lskj.PubBomImport
else else
{ {
SetProcessBar(0, allCount); SetProcessBar(0, allCount);
isUpload = UploadFileToAudit(childInfo.FullName, code, "010106", out msg, out string existFieldId); string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
if (!isUpload) if (filetable.Rows.Count == 0)
{ {
throw new Exception($"{childInfo.Name}附件上传失败\r\n{msg}"); 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(() => StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{ {
if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId")) if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId"))
{ {
int.TryParse(existFieldId, 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;
} }
})); }));
@@ -1558,16 +1591,21 @@ namespace Lskj.PubBomImport
} }
if (childInfo != null) if (childInfo != null)
{ {
isUpload = UploadFileToAudit(childInfo.FullName, productId, "010106", out msg, out string otherFieldId); GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string qdsourceCode, out string qdname, out string qdsourceBB, out int qdsourceBC);
if (!isUpload) string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
if (filetable.Rows.Count == 0)
{ {
throw new Exception($"{childInfo.Name}附件上传失败\r\n{msg}"); 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(() => StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{ {
if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId")) if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId"))
{ {
int.TryParse(otherFieldId, 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;
} }
})); }));
@@ -1641,6 +1679,7 @@ namespace Lskj.PubBomImport
{ {
string execGuid = sourceRow["qms_wjgg_uuid"] + ""; string execGuid = sourceRow["qms_wjgg_uuid"] + "";
string productid = sourceRow["qms_wjgg_productid"] + ""; string productid = sourceRow["qms_wjgg_productid"] + "";
string afterFilename = sourceRow["qms_wjgg_NewFileName"] + "";
int.TryParse(sourceRow["fileId"] + "", out int copyFileId); int.TryParse(sourceRow["fileId"] + "", out int copyFileId);
int.TryParse(sourceRow["qms_wjgg_fileId"] + "", out int coverFileId); int.TryParse(sourceRow["qms_wjgg_fileId"] + "", out int coverFileId);
int coverTag = (sourceRow["qms_wjgg_iscover"] + "").Equals("True") ? 1 : 0; int coverTag = (sourceRow["qms_wjgg_iscover"] + "").Equals("True") ? 1 : 0;
@@ -1661,11 +1700,12 @@ namespace Lskj.PubBomImport
int result = BillImpl.BillSave(masterSql, detailSql, detailTable, ref billNo, detailGuid, billSeq, billWay, comfirm, out string tipMsg, auditFlag, newVer); int result = BillImpl.BillSave(masterSql, detailSql, detailTable, ref billNo, detailGuid, billSeq, billWay, comfirm, out string tipMsg, auditFlag, newVer);
if (result == 1) if (result == 1)
{ {
GetFileCodeInfo(afterFilename, out string fileCode, out string name, out string fileBB, out int fileBC);
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set success = 1 where guid = '{execGuid}'"); BaseImpl.ExecSqlValue($"update p_bomImportExecTab set success = 1 where guid = '{execGuid}'");
List<SqlParameter> sqlParamList = new List<SqlParameter>(); List<SqlParameter> sqlParamList = new List<SqlParameter>();
sqlParamList.Add(new SqlParameter("@copyFileId", SqlDbType.Int) { Value = copyFileId }); sqlParamList.Add(new SqlParameter("@copyFileId", SqlDbType.Int) { Value = copyFileId });
sqlParamList.Add(new SqlParameter("@copyToModule", SqlDbType.VarChar, 100) { Value = "1000202" }); sqlParamList.Add(new SqlParameter("@copyToModule", SqlDbType.VarChar, 100) { Value = "1000202" });
sqlParamList.Add(new SqlParameter("@copyToIdValue", SqlDbType.VarChar, 100) { Value = productid }); sqlParamList.Add(new SqlParameter("@copyToIdValue", SqlDbType.VarChar, 100) { Value = fileCode });
sqlParamList.Add(new SqlParameter("@coverFileId", SqlDbType.Int) { Value = coverFileId }); sqlParamList.Add(new SqlParameter("@coverFileId", SqlDbType.Int) { Value = coverFileId });
sqlParamList.Add(new SqlParameter("@coverTag", SqlDbType.Int) { Value = coverTag }); sqlParamList.Add(new SqlParameter("@coverTag", SqlDbType.Int) { Value = coverTag });
BaseImpl.ExecProcedure("p_CopyAttcFileInfo", sqlParamList.ToArray()); BaseImpl.ExecProcedure("p_CopyAttcFileInfo", sqlParamList.ToArray());
@@ -2240,23 +2280,23 @@ namespace Lskj.PubBomImport
} }
if (!string.IsNullOrEmpty(token)) if (!string.IsNullOrEmpty(token))
{ {
string selectSql = $"select * from P_fm_FileTab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{idValue}' and dllcoid = '1000202') and speciesno = '{speciesno}' and sname = '{name.Replace(" ", "")}'"; //string selectSql = $"select * from P_fm_FileTab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{idValue}' and dllcoid = '1000202') and speciesno = '{speciesno}' and sname = '{name.Replace(" ", "")}'";
DataTable deleteTable = BaseImpl.GetDataTableResult(selectSql); //DataTable deleteTable = BaseImpl.GetDataTableResult(selectSql);
if (deleteTable != null && deleteTable.Rows.Count > 0) //if (deleteTable != null && deleteTable.Rows.Count > 0)
{ //{
foreach (DataRow deleteRow in deleteTable.Rows) // foreach (DataRow deleteRow in deleteTable.Rows)
{ // {
string field = HttpUtility.UrlEncode(deleteRow["fileId"] + ""); // string field = HttpUtility.UrlEncode(deleteRow["fileId"] + "");
string webpath = HttpUtility.UrlEncode(deleteRow["webpath"] + ""); // string webpath = HttpUtility.UrlEncode(deleteRow["webpath"] + "");
//删除文件 // //删除文件
string deleteUrl = "{0}Api/FileUploadApi.ashx?fileId={1}&filename={2}&method={3}"; // string deleteUrl = "{0}Api/FileUploadApi.ashx?fileId={1}&filename={2}&method={3}";
deleteUrl = string.Format(deleteUrl, SystemInfo.Instance.OAUrl, field, webpath, "DoDelete"); // deleteUrl = string.Format(deleteUrl, SystemInfo.Instance.OAUrl, field, webpath, "DoDelete");
HttpHelper.Setting("application/x-www-form-urlencoded", null, null); // HttpHelper.Setting("application/x-www-form-urlencoded", null, null);
Dictionary<string, string> deleteHeaderDic = new Dictionary<string, string>(); // Dictionary<string, string> deleteHeaderDic = new Dictionary<string, string>();
deleteHeaderDic.Add("Authorization", $"Bearer {token}"); // deleteHeaderDic.Add("Authorization", $"Bearer {token}");
HttpWebResponse deleteWebResponse = HttpHelper.Post(deleteUrl, fileStream, null, deleteHeaderDic, out string deleteResult); // HttpWebResponse deleteWebResponse = HttpHelper.Post(deleteUrl, fileStream, null, deleteHeaderDic, out string deleteResult);
} // }
} //}
postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, "1000202", HttpUtility.UrlEncode(idValue), "file", fileBytes.Length, 0, HttpUtility.UrlEncode(name), "DoWebUpload", speciesno); postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, "1000202", HttpUtility.UrlEncode(idValue), "file", fileBytes.Length, 0, HttpUtility.UrlEncode(name), "DoWebUpload", speciesno);
HttpTools.setting("application/x-www-form-urlencoded", null, null); HttpTools.setting("application/x-www-form-urlencoded", null, null);
string result = ""; string result = "";
@@ -2310,4 +2350,52 @@ namespace Lskj.PubBomImport
throw new Exception($"文件{Path.GetFileName(filePath)}上传失败\r\n{ex.Message}"); throw new Exception($"文件{Path.GetFileName(filePath)}上传失败\r\n{ex.Message}");
isUpload = false; isUpload = false;
} }
msg = returnM msg = returnMsg;
outFileId = fileId;
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;
}
/// <summary>
/// 解析code信息
/// </summary>
/// <param name="sourceCode"></param>
/// <param name="code"></param>
/// <param name="name"></param>
/// <param name="bb"></param>
/// <param name="bc"></param>
private void GetFileCodeInfo(string sourceCode, out string code, out string name, out string bb, out int bc)
{
string namepattern = @"^([A-Z]+(?:-[A-Z0-9]+)*)(?:\s+(.*))?$";
string pattern = @"^(.*?)(\d+)?$";
string childcode = "";
string childname = "";
string childsourceCode = "";