SVN-Revision: r679
This commit is contained in:
wyf
2025-06-05 12:44:25 +00:00
parent 6522fddbc4
commit 2371b12620
+123 -94
View File
@@ -746,6 +746,17 @@ namespace Lskj.PubBomImport
int execOrder = 1;
FrmBillInfo frmBillInfo = new FrmBillInfo();
string speciesno = selectRows[0]["BomAddSpeciesNo"] + "";
string productId = selectRows[0]["BomMxMainProduct"] + "";
string guid = selectRows[0]["qms_laddf_guId"] + "";
string oldfileId = selectRows[0]["BomAddChangeFileId"] + "";
if (string.IsNullOrEmpty(guid))
{
throw new Exception("Guid标识不能为空");
}
if (string.IsNullOrEmpty(oldfileId))
{
throw new Exception("更改文件Id不能为空");
}
if (string.IsNullOrEmpty(speciesno))
{
throw new Exception("未选择文件分类");
@@ -754,69 +765,61 @@ namespace Lskj.PubBomImport
{
throw new Exception("仅支持单个附件变更");
}
Dictionary<string, DataRow> maxfileRowDic = new Dictionary<string, DataRow>();
foreach (DataRow selectRow in selectRows)
GridControlEx gridControlEx = null;
if (StaticControl.BomUnionPage != null && StaticControl.BomUnionPage.Tag is GridControlEx gridDetailControl)
{
string fileName = selectRow[Model.AfterBomFieldName] + "";
string dirPath = selectRow["BomFieldNameDir"] + "";
FileInfo fileInfo = new FileInfo(dirPath);
if (fileInfo != null)
gridControlEx = gridDetailControl;
}
DataTable dataTable = gridControlEx.GridControl.DataSourceTable();
int[] bomRowIndexs = gridControlEx.GridView.GetSelectedRows();
List<DataRow> bomRows = new List<DataRow>();
foreach (int bomRowIndex in bomRowIndexs)
{
bomRows.Add(gridControlEx.GridView.GetDataRow(bomRowIndex));
}
DataRow selectRow = selectRows[0];
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)
{
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)
//如果不符合规则,则进行版本更新,会根据选择的文件向多个文件夹进行上传文件
DataRow productRow = BaseImpl.GetDataRowResult($"select ProductId from p_productTab where ProductId = '{productId}'");
if (productRow == null)
{
throw new Exception($"{fileInfo.Name}\r\n文件名不符合规则");
throw new Exception($"物料编码{code}不存在,无法修改");
}
if (string.IsNullOrEmpty(code))
DataRow fileRow = BaseImpl.GetDataRowResult($"select sname,fileId from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{productId}' and dllcoid = '1000202') and speciesno = '{speciesno}' and sname = '{fileInfo.Name}%'");
if (fileRow != null)//如果存在则不允许上传
{
throw new Exception($"编码解析为空");
throw new Exception($"{productId}下已存在附件{fileInfo.Name}");
}
if (string.IsNullOrEmpty(spec))
foreach (DataRow bomRow in bomRows)
{
throw new Exception($"规格解析为空");
}
if (string.IsNullOrEmpty(name))
{
throw new Exception($"名称解析为空");
}
if (!fileNameWithoutExtension.StartsWith("LX"))
{
throw new Exception($"文件{fileNameWithoutExtension}名称不符合规则\r\n不以LX开头");
}
else
{
if (bc <= 0)
string childname = (bomRow["附件名称"] + "").Replace("'", "''");
string childspeciesno = (bomRow["目录ID"] + "").Replace("'", "''");
string childproductid = (bomRow["目录名称"] + "").Trim();
DataRow childfileRow = BaseImpl.GetDataRowResult($"select sname,fileId from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{childproductid}' and dllcoid = '1000202') and speciesno = '{childspeciesno}' and sname = '{fileInfo.Name}%'");
if (childfileRow != null)//如果存在则不允许上传
{
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不存在可以修改的附件");
throw new Exception($"{childproductid}下已存在附件{fileInfo.Name}");
}
}
}
else
{
throw new Exception($"{fileName}的文件不存在");
//如果符合规则,则直接改变当前编码下的文件
throw new Exception("暂未开启");
}
}
else
{
throw new Exception($"{fileName}的文件不存在");
}
frmBillInfo.OnControlSourceBind += (s, args) =>
{
Task task = new Task(() =>
@@ -825,55 +828,24 @@ namespace Lskj.PubBomImport
{
int.TryParse(Model.FirstRowIndex, out int index);
frmMain.FirstRowIndex = index;
foreach (DataRow selectRow in selectRows)
if (fileInfo != null)
{
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)
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)
{
DataRow maxRow = maxfileRowDic.ContainsKey(fileInfo.Name) ? maxfileRowDic[fileInfo.Name] : null;
string uploadFileId = "";
if (maxRow != null)//如果存在则修改
//先上传自身
SetProcessBar(0, 0);
bool isUpload = UploadFileToAudit(fileInfo.FullName, productId, speciesno, out string msg, out string uploadFileId);
if (!isUpload)
{
int.TryParse(maxRow["fileid"] + "", out int fileId);
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_uniofileid"))
{
selectRow["qms_laddf_uniofileid"] = fileId;
}
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不存在可以修改的附件");
throw new Exception($"{productId}\r\n{fileNameWithoutExtension}附件上传失败\r\n{msg}");
}
SqlHelper.ExecuteNonQuery($"delete bom_filetab where billno = '{guid}'");
string oldfilename = BaseImpl.GetResult("select sname from p_fm_filetab where fileid = '{oldfileId}'") + "";
SqlHelper.ExecuteNonQuery($"insert into bom_filetab (billno,fileid,newfileid,filename,newfilename,speciesno,pid) values ('{guid}','{oldfileId}','{uploadFileId}','{oldfilename}','{fileInfo.Name}','{speciesno}','{productId}')");
SetProcessBar(100, (1 / (bomRows.Count() + 1)) * 100);
SetProcessLabelAllMsg($"总进度:1/{bomRows.Count() + 1}");
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{
if (selectRow.Table.Columns.Contains("qms_laddf_FileId"))
@@ -881,13 +853,39 @@ namespace Lskj.PubBomImport
int.TryParse(uploadFileId, out int qms_laddf_FileId);
selectRow["qms_laddf_FileId"] = qms_laddf_FileId;
}
if (selectRow.Table.Columns.Contains("qms_laddf_uploadtag"))
{
selectRow["qms_laddf_uploadtag"] = 1;
}
}));
int indexorder = 1;
foreach (DataRow bomRow in bomRows)
{
string childfileId = bomRow["文件ID"] + "";
string childname = (bomRow["附件名称"] + "").Replace("'", "''");
string childspeciesno = (bomRow["目录ID"] + "").Replace("'", "''");
string childproductid = (bomRow["目录名称"] + "").Trim();
SetProcessBar(0, (1 / (bomRows.Count() + indexorder + 1)) * 100);
bool isChildUpload = UploadFileToAudit(fileInfo.FullName, childproductid, childspeciesno, out string childmsg, out string childuploadFileId);
if (!isChildUpload)
{
throw new Exception($"{childproductid}{fileNameWithoutExtension}附件上传失败\r\n{childmsg}");
}
SqlHelper.ExecuteNonQuery($"insert into bom_filetab (billno,fileid,newfileid,filename,newfilename,speciesno,pid) values ('{guid}','{childfileId}','{childuploadFileId}','{childname}','{fileInfo.Name}','{childspeciesno}','{childproductid}')");
SetProcessBar(100, (1 / (bomRows.Count() + indexorder + 1)) * 100);
SetProcessLabelAllMsg($"总进度:{indexorder + 1}/{bomRows.Count() + 1}");
indexorder += 1;
}
}
else
{
throw new Exception($"{fileName}的文件不存在");
}
}
else
{
throw new Exception($"{fileName}的文件不存在");
}
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.OK;
@@ -3485,6 +3483,37 @@ namespace Lskj.PubBomImport
return isUpload;
}
/// <summary>
/// 记录附件变更数据
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public string BuildBomFileTabSql(DataTable dt, string billno)
{
if (dt == null || dt.Rows.Count == 0) return string.Empty;
var sb = new StringBuilder();
sb.AppendLine("BEGIN TRANSACTION;");
foreach (DataRow row in dt.Rows)
{
int fileId = Convert.ToInt32(row["文件ID"]);
string fileName = row["附件名称"].ToString().Replace("'", "''");// 单引号转义
string speciesNo = row["目录ID"].ToString().Replace("'", "''");// → speciesno
string dirName = row["目录名称"].ToString().Trim();// → pid
int pid = 0;
int.TryParse(dirName, out pid); //目录名称若为数字则转换,否则默认为 0
sb.AppendFormat(
@"IF NOT EXISTS (
SELECT 1 FROM bom_filetab
WHERE fileid = {0}
AND speciesno = '{1}'
AND pid = {2})
INSERT INTO bom_filetab (billno, fileid, filename, speciesno, pid)
VALUES ('{4}',{0}, N'{3}', '{1}', {2});
", fileId, speciesNo, pid, fileName, billno);
}
sb.AppendLine("COMMIT TRANSACTION;");
return sb.ToString();
}
/// <summary>
/// 附件转换byte[]
/// </summary>
/// <param name="filePath">附件路径</param>