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>