SVN-Revision: r666
This commit is contained in:
wyf
2025-06-04 11:21:46 +00:00
parent c7818396a7
commit 4b646f6492
2 changed files with 266 additions and 26 deletions
+61 -1
View File
@@ -259,7 +259,7 @@ namespace Lskj.PubBomImport
this.Close();
}
}
else if (Model.ShowType.Equals("1"))//新增多个其它文件,无版次版本验证,关联到物料编码下
else if (Model.ShowType.Equals("1"))//新增多个其它文件
{
BomImpRtnModel bomImpRtnModel = new BomImpRtnModel()
{
@@ -563,6 +563,66 @@ namespace Lskj.PubBomImport
frmProgress.ShowDialog();
frmProgress.Dispose();
}
else if (Model.ShowType.Equals("6"))//修改多个其它文件
{
BomImpRtnModel bomImpRtnModel = new BomImpRtnModel()
{
ShowType = Model.ShowType,
AfterBomFieldName = Model.AfterBomFieldName,
CanSave = true
};
FormDialogModel dialogModel = new FormDialogModel()
{
DialogDllName = "Lskj.PubBomImport.dll",
PubDialogType = DialogType.PubAddRecord,
ReturnTag = bomImpRtnModel
};
this.Tag = dialogModel;
DataTable sourceTable = StaticControl.RightMenuGridView.GridControl.DataSourceTable();
if (sourceTable.Columns.Contains("BomFieldNameDir"))
{
List<DataRow> selectRows = new List<DataRow>();
foreach (DataRow sourceRow in sourceTable.Rows)
{
if (sourceRow.RowState == DataRowState.Deleted)
{
continue;
}
string fileName = sourceRow[Model.AfterBomFieldName] + "";
string dirPath = sourceRow["BomFieldNameDir"] + "";
FileInfo parentInfo = null;
if (string.IsNullOrEmpty(dirPath))
{
continue;
}
parentInfo = new FileInfo(dirPath);
selectRows.Add(sourceRow);
}
if (selectRows.Count > 0)
{
FrmProgress frmProgress = new FrmProgress();
frmProgress.frmMain = this;
frmProgress.Model = Model;
frmProgress.ImportTimer.Tick += (ts, te) =>
{
frmProgress.ImportTimer.Enabled = false;
frmProgress.StartUpdateInOtherFiles(selectRows);
};
frmProgress.ImportTimer.Enabled = true;
DialogResult dialogResult = frmProgress.ShowDialog();
bomImpRtnModel.CanSave = dialogResult == DialogResult.OK;
frmProgress.Dispose();
}
else
{
this.Close();
}
}
else
{
this.Close();
}
}
}
catch (Exception ex)
{
+205 -25
View File
@@ -270,15 +270,18 @@ namespace Lskj.PubBomImport
int execOrder = 1;
FrmBillInfo frmBillInfo = new FrmBillInfo();
string bomOtherAddMode = selectRows[0]["qms_laddf_mode"] + "";
string speciesno = selectRows[0]["qms_laddf_speciesno"] + "";
string speciesno = selectRows[0]["BomAddSpeciesNo"] + "";
if (string.IsNullOrEmpty(bomOtherAddMode))
{
throw new Exception("未选择上传模式");
}
if (string.IsNullOrEmpty(speciesno))
{
throw new Exception("未选择文件分类");
}
if (bomOtherAddMode.Equals("9040"))//有规则
{
Dictionary<string, DataRow> maxfileRowDic = new Dictionary<string, DataRow>();
string pattern = @"^(\S+)\s+(\S+)\s+(.+)$";
foreach (DataRow selectRow in selectRows)
{
string fileName = selectRow[Model.AfterBomFieldName] + "";
@@ -304,17 +307,9 @@ namespace Lskj.PubBomImport
{
throw new Exception($"名称解析为空");
}
if (fileNameWithoutExtension.StartsWith("ZZQD"))
if (!fileNameWithoutExtension.StartsWith("LX"))
{
throw new Exception($"不允许补充ZZQD文件{fileNameWithoutExtension}");
}
else if (fileNameWithoutExtension.StartsWith("MX"))
{
throw new Exception($"不允许补充MX文件{fileNameWithoutExtension}");
}
else if (fileNameWithoutExtension.StartsWith("QD"))
{
throw new Exception($"不允许补充QD文件{fileNameWithoutExtension}");
throw new Exception($"文件{fileNameWithoutExtension}名称不符合规则\r\n不以LX开头");
}
else
{
@@ -322,16 +317,22 @@ namespace Lskj.PubBomImport
{
throw new Exception($"{fileInfo.Name}\r\n不为0的版次不允许新增,请进行修改");
}
DataRow productRow = BaseImpl.GetDataRowResult($"select ProductId from p_productTab where ProductId = '{code}'");
if (productRow == null)
{
throw new Exception($"物料编码{code}不存在,无法新增");
}
DataRow maxRow = BaseImpl.GetDataRowResult($"exec dbo.p_CheckLxFileRevision N'{fileInfo.Name}','{speciesno}';");
maxfileRowDic[fileInfo.Name] = maxRow;
if (maxRow != null)//如果存在则不允许上传
{
int.TryParse(maxRow["版本号"] + "", out int oldbb);
int.TryParse(maxRow["新文件版本号"] + "", out int newbb);
if (newbb > oldbb)
{
throw new Exception($"{fileInfo.Name}\r\n版本号大于最大版本号,请进行修改");
}
throw new Exception("已存在附件无法新增");
//int.TryParse(maxRow["版本号"] + "", out int oldbb);
//int.TryParse(maxRow["新文件版本号"] + "", out int newbb);
//if (newbb > oldbb)
//{
// throw new Exception($"{fileInfo.Name}\r\n版本号大于最大版本号{oldbb},请进行修改");
//}
}
}
}
@@ -364,13 +365,14 @@ namespace Lskj.PubBomImport
string uploadFileId = "";
if (maxRow != null)//如果存在则不允许上传
{
uploadFileId = maxRow["fileid"] + "";
int.TryParse(maxRow["版本号"] + "", out int oldbb);
int.TryParse(maxRow["新文件版本号"] + "", out int newbb);
if (newbb > oldbb)
{
throw new Exception($"{fileInfo.Name}\r\n版本号大于最大版本号,请进行修改");
}
throw new Exception("已存在附件无法新增");
//uploadFileId = maxRow["fileid"] + "";
//int.TryParse(maxRow["版本号"] + "", out int oldbb);
//int.TryParse(maxRow["新文件版本号"] + "", out int newbb);
//if (newbb > oldbb)
//{
// throw new Exception($"{fileInfo.Name}\r\n版本号大于最大版本号,请进行修改");
//}
}
else
{
@@ -551,6 +553,184 @@ namespace Lskj.PubBomImport
}
}
/// <summary>
/// Bom结构补充,新增其它文件,无版本控制
/// </summary>
/// <param name="dirPaths"></param>
public void StartUpdateInOtherFiles(List<DataRow> selectRows)
{
try
{
int execOrder = 1;
FrmBillInfo frmBillInfo = new FrmBillInfo();
string speciesno = selectRows[0]["qms_laddf_speciesno"] + "";
Dictionary<string, DataRow> maxfileRowDic = new Dictionary<string, DataRow>();
foreach (DataRow selectRow in selectRows)
{
string fileName = selectRow[Model.AfterBomFieldName] + "";
string dirPath = selectRow["BomFieldNameDir"] + "";
FileInfo fileInfo = new FileInfo(dirPath);
if (fileInfo != null)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.Name).Trim();
bool isMatch = GetOtherFileCodeInfo(fileInfo.Name, out string code, out string spec, out string name, out string extension, out string bb, out int bc);
if (!isMatch)
{
throw new Exception($"{fileInfo.Name}\r\n文件名不符合规则");
}
if (string.IsNullOrEmpty(code))
{
throw new Exception($"编码解析为空");
}
if (string.IsNullOrEmpty(spec))
{
throw new Exception($"规格解析为空");
}
if (string.IsNullOrEmpty(name))
{
throw new Exception($"名称解析为空");
}
if (!fileNameWithoutExtension.StartsWith("LX"))
{
throw new Exception($"文件{fileNameWithoutExtension}名称不符合规则\r\n不以LX开头");
}
else
{
if (!bb.Equals("SA"))
{
throw new Exception($"{fileInfo.Name}\r\n无法进行批量版本修改");
}
if (bc <= 0)
{
throw new Exception($"{fileInfo.Name}\r\n为0的版次不允许进行版次修改");
}
DataRow productRow = BaseImpl.GetDataRowResult($"select ProductId from p_productTab where ProductId = '{code}'");
if (productRow == null)
{
throw new Exception($"物料编码{code}不存在,无法修改");
}
DataRow maxRow = BaseImpl.GetDataRowResult($"exec dbo.p_CheckLxFileRevision N'{fileInfo.Name}','{speciesno}';");
maxfileRowDic[fileInfo.Name] = maxRow;
if (maxRow != null)//如果存在则不允许上传
{
int.TryParse(maxRow["版本号"] + "", out int oldbb);
int.TryParse(maxRow["新文件版本号"] + "", out int newbb);
if (newbb <= oldbb)
{
throw new Exception($"{fileInfo.Name}\r\n版本号小于等于最大版本号{oldbb},无法修改");
}
}
else
{
throw new Exception($"{fileInfo.Name}\r\n不存在可以修改的附件");
}
}
}
else
{
throw new Exception($"{fileName}的文件不存在");
}
}
frmBillInfo.OnControlSourceBind += (s, args) =>
{
Task task = new Task(() =>
{
try
{
int.TryParse(Model.FirstRowIndex, out int index);
frmMain.FirstRowIndex = index;
foreach (DataRow selectRow in selectRows)
{
string productId = selectRow["BomMxMainProduct"] + "";
int childIndex = selectRows.IndexOf(selectRow);
int nowCount = 1 + childIndex;
int allCount = (int)((decimal)(1 + childIndex) / (selectRows.Count + 1) * 100);
int finishCount = (int)((decimal)(1 + nowCount) / (selectRows.Count + 1) * 100);
string fileName = selectRow[Model.AfterBomFieldName] + "";
string dirPath = selectRow["BomFieldNameDir"] + "";
FileInfo fileInfo = new FileInfo(dirPath);
if (fileInfo != null)
{
DataRow maxRow = maxfileRowDic.ContainsKey(fileInfo.Name) ? maxfileRowDic[fileInfo.Name] : null;
string uploadFileId = "";
if (maxRow != null)//如果存在则不允许上传
{
int.TryParse(maxRow["版本号"] + "", out int oldbb);
int.TryParse(maxRow["新文件版本号"] + "", out int newbb);
if (newbb <= oldbb)
{
throw new Exception($"{fileInfo.Name}\r\n版本号小于等于最大版本号{oldbb},无法修改");
}
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.Name).Trim();
GetOtherFileCodeInfo(fileInfo.Name, out string code, out string spec, out string name, out string extension, out string bb, out int bc);
SetProcessBar(0, allCount);
bool isUpload = UploadFileToAudit(fileInfo.FullName, code, speciesno, out string msg, out uploadFileId);
if (!isUpload)
{
throw new Exception($"{fileNameWithoutExtension}附件上传失败\r\n{msg}");
}
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{
if (selectRow.Table.Columns.Contains("qms_laddf_uploadtag"))
{
selectRow["qms_laddf_uploadtag"] = 1;
}
}));
SetProcessBar(100, finishCount);
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{selectRows.Count + 1}");
}
else
{
throw new Exception($"{fileInfo.Name}\r\n不存在可以修改的附件");
}
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{
if (selectRow.Table.Columns.Contains("qms_laddf_FileId"))
{
int.TryParse(uploadFileId, out int qms_laddf_FileId);
selectRow["qms_laddf_FileId"] = qms_laddf_FileId;
}
}));
}
else
{
throw new Exception($"{fileName}的文件不存在");
}
}
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.OK;
Close();
ImportTimer?.Dispose();
}));
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.Cancel;
Close();
ImportTimer?.Dispose();
}));
}
});
task.Start();
};
frmBillInfo.OnLoad(Model);
frmMain.ParentView = frmBillInfo.GcMainView;
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.Cancel;
Close();
ImportTimer?.Dispose();
}));
}
}
/// <summary>
/// 修改单个文件
/// </summary>
/// <param name="dirPaths"></param>