SVN-Revision: r593
This commit is contained in:
wyf
2025-05-16 06:16:01 +00:00
parent b5043e68a4
commit b32fa5f872
2 changed files with 172 additions and 25 deletions
+79 -5
View File
@@ -141,11 +141,46 @@ namespace Lskj.PubBomImport
{
Properties.Settings.Default.LastSelectFolder = dialog.SelectedPath;
string[] fileNames = Directory.GetFiles(dialog.SelectedPath);
string mxFilePath = fileNames.Where(n => Path.GetFileName(n).Trim().StartsWith("MX")).FirstOrDefault();
FileInfo parentInfo = new FileInfo(mxFilePath);
List<string> existsFileList = new List<string>();
existsFileList.Add(mxFilePath);
if (parentInfo != null)
{
DataTable parentTable = ExcelToDatatable(parentInfo.FullName, Model, "", 5);
parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "")).ToList().CopyToDataTable();
foreach (DataRow dataRow in parentTable.Rows)
{
string code = (dataRow["图号"] + "").Trim();
int count = parentTable.AsEnumerable().Where(n => (n["图号"] + "").Trim().StartsWith(code)).Count();
if (count > 1)//只允许存在一个
{
throw new Exception($"MX中的{code}重复");
}
GetFileCodeInfo(code, out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
if (sourceBC > 0)
{
throw new Exception($"MX中的{code}不允许有版次");
}
var selectFiles = fileNames.Where(n => Path.GetFileName(n).Trim().StartsWith(code));
foreach (var selectFile in selectFiles)
{
if (!existsFileList.Contains(selectFile))
{
existsFileList.Add(selectFile);
}
}
}
}
else
{
throw new Exception("MX文件不存在");
}
BomImpRtnModel bomImpRtnModel = new BomImpRtnModel()
{
ShowType = Model.ShowType,
AfterBomFieldName = Model.AfterBomFieldName,
FileNames = fileNames
FileNames = existsFileList.ToArray()
};
FormDialogModel dialogModel = new FormDialogModel()
{
@@ -458,7 +493,7 @@ namespace Lskj.PubBomImport
{
try
{
DataTable dataTable1 = ExcelToDatatable(fileName, Model.SheetName, index);
DataTable dataTable1 = ExcelToDatatable(fileName, Model, Model.SheetName, index);
FirstRowIndex = index;
isTitle = true;
break;
@@ -474,7 +509,7 @@ namespace Lskj.PubBomImport
FirstRowIndex = 0;
}
}
DataTable dataTable = ExcelToDatatable(fileName, Model.SheetName, FirstRowIndex);
DataTable dataTable = ExcelToDatatable(fileName, Model, Model.SheetName, FirstRowIndex);
DataTable importTable = GetSourceTable(dataTable);
DataTable sourceTable = this.gcMain.GridControl.DataSource as DataTable;
if (dataTable != null)
@@ -853,7 +888,7 @@ namespace Lskj.PubBomImport
/// <param name="sheetName"></param>
/// <param name="isFirstRowColumn"></param>
/// <returns></returns>
public DataTable ExcelToDatatable(string fileName, string sheetName = "", int firstRowIndex = 0)
public DataTable ExcelToDatatable(string fileName, DynamicBomImport Model, string sheetName = "", int firstRowIndex = 0)
{
DataTable data = new DataTable();
FileStream fs;
@@ -1141,7 +1176,7 @@ namespace Lskj.PubBomImport
GridView gridView = ParentView;
DataTable columnsTable = gcMain.gridControl.DataSourceTable();
DataTable table = gridView.GridControl.DataSourceTable();
DataTable sourceDataTable = ExcelToDatatable(fileName, Model.SheetName, FirstRowIndex);
DataTable sourceDataTable = ExcelToDatatable(fileName, Model, Model.SheetName, FirstRowIndex);
DataView filterDataView = new DataView(sourceDataTable);
try
{
@@ -1814,6 +1849,45 @@ namespace Lskj.PubBomImport
return returnData;
}
/// <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 = @"^(.*-S[A-Z]\d*)(.*)$";
string pattern = @"^(.*?)(\d+)?$";
string childcode = "";
string childname = "";
string childsourceCode = "";
string childsourceBB = "";
int childsourceBC = 0;
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(sourceCode).Trim(), namepattern);
if (namematch.Success)
{
childcode = namematch.Groups[1].Value.Trim();
childname = namematch.Groups[2].Value.Trim();
}
Match match = Regex.Match(childcode, pattern);
if (match.Success)
{
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();
}
}
code = childsourceCode;
name = childname;
bb = childsourceBB;
bc = childsourceBC;
}
/// <summary>
/// <para>说明:检查可用条件</para>
/// <para>创建日期:2024-3-19 </para>
/// <para>修改人:</para>
+93 -20
View File
@@ -77,7 +77,7 @@ namespace Lskj.PubBomImport
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}%' and speciesno = '010106' and parentId in (select dirid from p_fm_directorytab where dllcoid = '1000202'";
string fileSql = $"select webpath,sName from P_fm_FileTab where sName like '{fileName}%' and speciesno = '010106' and parentId in (select dirid from p_fm_directorytab where dllcoid = '1000202')";
DataRow fileRow = BaseImpl.GetDataRowResult(fileSql);
string webpath = fileRow != null ? fileRow["webpath"] + "" : "";
string sName = fileRow != null ? fileRow["sName"] + "" : "";
@@ -307,7 +307,7 @@ namespace Lskj.PubBomImport
string fileName = (parentRow["图号"] + "").Trim();
if (fileName.StartsWith("QD") || fileName.StartsWith("ZZQD"))
{
string fileSql = $"select webpath,sName from P_fm_FileTab where sName like '{fileName}%' and speciesno = '010106' and parentId in (select dirid from p_fm_directorytab where dllcoid = '1000202'";
string fileSql = $"select webpath,sName from P_fm_FileTab where sName like '{fileName}%' and speciesno = '010106' and parentId in (select dirid from p_fm_directorytab where dllcoid = '1000202')";
DataRow fileRow = BaseImpl.GetDataRowResult(fileSql);
string webpath = fileRow != null ? fileRow["webpath"] + "" : "";
string sName = fileRow != null ? fileRow["sName"] + "" : "";
@@ -509,9 +509,6 @@ namespace Lskj.PubBomImport
{
try
{
string namepattern = @"^(.*-S[A-Z]\d*)(.*)$";
//string namepattern = @"^(.+?)\s+(.+)$";
string pattern = @"^(.*?)(\d+)?$";
string primaryValue = StaticControl.RightMenuMyControl.PrimaryValue;
string productCode = "";
ControlModel controlModel = StaticControl.RightMenuMyControl.ControlModels.Where(n => n.LabelText.Equals("物料编码")).FirstOrDefault();
@@ -574,6 +571,22 @@ namespace Lskj.PubBomImport
if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("QD")))
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
DataTable filetable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{sourceCode}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{sourceCode}%'");
int childMaxBc = -1;
foreach (DataRow fileRow in filetable.Rows)
{
string fileName = fileRow["sname"] + "";
string fileId = fileRow["fileId"] + "";
GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
if (fileBC >= childMaxBc)
{
childMaxBc = fileBC;
}
}
if (sourceBC <= childMaxBc)
{
throw new Exception($"变更版次{sourceBC}小于最大版次{childMaxBc}\r\n不允许变更");
}
StringBuilder stringBuilder = new StringBuilder();
if (sourceCode.StartsWith("QD"))
{
@@ -586,9 +599,9 @@ namespace Lskj.PubBomImport
}
StringBuilder insertbulider = new StringBuilder();
string mxCode = BaseImpl.GetResult($"select MxFileName from FileAttachmentMapping where MaterialCode = '{topProductId}' and RelatedAttachmentName = '{beforeSourceCode}';") + "";
insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{topProductId}' and RelatedAttachmentName = '{beforeSourceCode}';");
insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{topProductId}','{mxCode}','{sourceCode}','{ERPInfo.Instance.UserName}','变更');");
string mxCode = BaseImpl.GetResult($"select MxFileName from FileAttachmentMapping where MaterialCode = '{productCode}' and RelatedAttachmentName = '{beforeSourceCode}';") + "";
insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{productCode}' and RelatedAttachmentName = '{beforeSourceCode}';");
insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{productCode}','{mxCode}','{sourceCode}','{ERPInfo.Instance.UserName}','变更');");
//更新或新增并备份清单
int.TryParse(Model.FirstRowIndex, out int index);
@@ -655,10 +668,26 @@ namespace Lskj.PubBomImport
{
productCode = topProductId;
GetFileCodeInfo(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
DataTable filetable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{sourceCode}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{sourceCode}%'");
int childMaxBc = -1;
foreach (DataRow fileRow in filetable.Rows)
{
string fileName = fileRow["sname"] + "";
string fileId = fileRow["fileId"] + "";
GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
if (fileBC >= childMaxBc)
{
childMaxBc = fileBC;
}
}
if (sourceBC <= childMaxBc)
{
throw new Exception($"变更版次{sourceBC}小于最大版次{childMaxBc}\r\n不允许变更");
}
StringBuilder insertbulider = new StringBuilder();
string mxCode = BaseImpl.GetResult($"select MxFileName from FileAttachmentMapping where MaterialCode = '{topProductId}' and RelatedAttachmentName = '{beforeSourceCode}';") + "";
insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{topProductId}' and RelatedAttachmentName = '{beforeSourceCode}';");
insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{topProductId}','{mxCode}','{sourceCode}','{ERPInfo.Instance.UserName}','变更');");
string mxCode = BaseImpl.GetResult($"select MxFileName from FileAttachmentMapping where MaterialCode = '{productCode}' and RelatedAttachmentName = '{beforeSourceCode}';") + "";
insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{productCode}' and RelatedAttachmentName = '{beforeSourceCode}';");
insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{productCode}','{mxCode}','{sourceCode}','{ERPInfo.Instance.UserName}','变更');");
//更新或新增并备份清单
int.TryParse(Model.FirstRowIndex, out int index);
frmMain.FirstRowIndex = index;
@@ -728,6 +757,22 @@ namespace Lskj.PubBomImport
{
productCode = topProductId;
GetFileCodeInfo(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
DataTable filetable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{topProductId}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{sourceCode}%'");
int childMaxBc = -1;
foreach (DataRow fileRow in filetable.Rows)
{
string fileName = fileRow["sname"] + "";
string fileId = fileRow["fileId"] + "";
GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
if (fileBC >= childMaxBc)
{
childMaxBc = fileBC;
}
}
if (sourceBC <= childMaxBc)
{
throw new Exception($"变更版次{sourceBC}小于最大版次{childMaxBc}\r\n不允许变更");
}
//更新或新增并备份清单
int.TryParse(Model.FirstRowIndex, out int index);
frmMain.FirstRowIndex = index;
@@ -758,7 +803,7 @@ namespace Lskj.PubBomImport
string sName = fileRow != null ? fileRow["sName"] + "" : "";
if (string.IsNullOrEmpty(webpath))
{
throw new Exception($"Bom明细附件{fileName}不存在\r\nBom导入失败");
throw new Exception($"{fileName}的明细附件不存在\r\nBom导入失败");
}
else
{
@@ -774,7 +819,7 @@ namespace Lskj.PubBomImport
}
catch (Exception)
{
throw new Exception($"Bom明细附件{fileName}获取失败\r\nBom导入失败");
throw new Exception($"{fileName}的明细附件下载失败\r\nBom导入失败");
}
}
}
@@ -907,6 +952,23 @@ namespace Lskj.PubBomImport
else
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
DataTable filetable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{sourceCode}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{sourceCode}%'");
int childMaxBc = -1;
foreach (DataRow fileRow in filetable.Rows)
{
string fileName = fileRow["sname"] + "";
string fileId = fileRow["fileId"] + "";
GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
if (fileBC >= childMaxBc)
{
childMaxBc = fileBC;
}
}
if (sourceBC <= childMaxBc)
{
throw new Exception($"变更版次{sourceBC}小于最大版次{childMaxBc}\r\n不允许变更");
}
string guid = Guid.NewGuid() + "";
SqlHelper.ExecuteNonQuery($"insert into p_bomImportExecTab (guid,detailTable,masterSql,detailSql,billNo,detailGuid,UserId,billWay,billSeq,auditFlag,comfirm,newVer) " +
$"values ('{guid}','','','','','','{ERPInfo.Instance.UserId}','','','0','','')");
@@ -1142,7 +1204,7 @@ namespace Lskj.PubBomImport
DataRow billRow = BaseImpl.GetDataRowResult($"select qms_maddf_billdocument_id from qms_BillFileAddMaintab where qms_maddf_productid = '{productId}'");
if (billRow != null)
{
throw new Exception($"物料编码{productId}的BOM新增单已存在");
throw new Exception($"物料编码{productId}的BOM新增单已存在审批流\r\n请进行审批");
}
DataRow billbomRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}'");
if (billRow != null)
@@ -1156,7 +1218,7 @@ namespace Lskj.PubBomImport
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 (mxfiletable.Rows.Count > 0)
{
throw new Exception($"{mxsourceCode}的附件已存在\r\n请进行变更");
throw new Exception($"{mxsourceCode}的附件已存在");
}
int mxMaxBc = 0;
string mxMaxBcFileId = "-1";
@@ -1206,6 +1268,7 @@ namespace Lskj.PubBomImport
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>();
List<string> notUploadFileList = new List<string>();
if (parentProductRow == null)
{
frmBillInfo.OnBillAdd();
@@ -1245,7 +1308,17 @@ namespace Lskj.PubBomImport
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
childInfo = new FileInfo(childDirPath);
}
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
//如果存在附件则判断是否已经上传了附件
if (childInfo != null)
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string childsourceCode, out string childname, out string childsourceBB, out int childsourceBC);
if (childsourceBC <= childMaxBc && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
{
notUploadFileList.Add(code);
childInfo = null;//设置为空下载附件使用
}
}
if (childInfo == null && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
{
using (WebClient webClient = new WebClient())
{
@@ -1403,7 +1476,7 @@ namespace Lskj.PubBomImport
DataTable filetable = fileTableDic.ContainsKey(code) ? fileTableDic[code] : null;
if (code.StartsWith("QD"))
{
if (filetable.Rows.Count == 0)
if (!notUploadFileList.Contains(code))
{
FileInfo childInfo = null;
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
@@ -1413,7 +1486,7 @@ namespace Lskj.PubBomImport
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
childInfo = new FileInfo(childDirPath);
}
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
if (childInfo == null && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
{
using (WebClient webClient = new WebClient())
{
@@ -1549,7 +1622,7 @@ namespace Lskj.PubBomImport
}
else
{
if (filetable.Rows.Count == 0)
if (!notUploadFileList.Contains(code))
{
FileInfo childInfo = null;
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
@@ -1559,7 +1632,7 @@ namespace Lskj.PubBomImport
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
childInfo = new FileInfo(childDirPath);
}
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
if (childInfo == null && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
{
using (WebClient webClient = new WebClient())
{