SVN-Revision: r581
This commit is contained in:
wyf
2025-05-15 02:53:40 +00:00
parent db365b57b4
commit bb817a4e47
+82 -111
View File
@@ -513,16 +513,34 @@ namespace Lskj.PubBomImport
//string namepattern = @"^(.+?)\s+(.+)$";
string pattern = @"^(.*?)(\d+)?$";
string primaryValue = StaticControl.RightMenuMyControl.PrimaryValue;
string productCode = "";
ControlModel controlModel = StaticControl.RightMenuMyControl.ControlModels.Where(n => n.LabelText.Equals("物料编码")).FirstOrDefault();
if (controlModel == null)
if (controlModel != null)
{
MessageUtil.Show($"物料编码不存在");
productCode = StaticControl.RightMenuMyControl.GetControlValue(controlModel);
}
string productCode = StaticControl.RightMenuMyControl.GetControlValue(controlModel);
if (string.IsNullOrEmpty(productCode))
{
MessageUtil.Show($"物料编码不能为空");
throw new Exception($"物料编码不能为空");
}
string beforeName = "";
ControlModel beforeNameModel = StaticControl.RightMenuMyControl.ControlModels.Where(n => n.LabelText.Equals("原文件名")).FirstOrDefault();
if (beforeNameModel != null)
{
beforeName = StaticControl.RightMenuMyControl.GetControlValue(beforeNameModel);
}
if (string.IsNullOrEmpty(beforeName))
{
throw new Exception($"原文件名不能为空");
}
string topProductId = "";
ControlModel topModel = StaticControl.RightMenuMyControl.ControlModels.Where(n => n.LabelText.Equals("顶级编码")).FirstOrDefault();
if (topModel == null)
{
MessageUtil.Show($"顶级编码不存在");
}
topProductId = StaticControl.RightMenuMyControl.GetControlValue(topModel);
GetFileCodeInfo(beforeName, out string beforeSourceCode, out string beforeSourceName, out string beforeSourceBB, out int beforeSourceBC);
List<LabelRemarkEdit> labelRemarkList = new List<LabelRemarkEdit>();
List<ControlModel> uploadModels = StaticControl.RightMenuMyControl.ControlModels.Where(n => n.FileUploadControl).ToList();
foreach (ControlModel uploadModel in uploadModels)
@@ -555,38 +573,23 @@ namespace Lskj.PubBomImport
//如果是QD文件
if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("QD")))
{
string code = "";
string name = "";
string sourceCode = "";
string sourceBB = "";
int sourceBC = 0;
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
if (namematch.Success)
{
code = namematch.Groups[1].Value.Trim();
name = namematch.Groups[2].Value.Trim();
}
Match match = Regex.Match(code, pattern);
if (match.Success)
{
sourceCode = match.Groups[1].Value;
int.TryParse(match.Groups[2].Value, out sourceBC);//版次
Match bbMatch = Regex.Match(sourceCode, @"^.*?([A-Za-z]+)(\d*)$");
if (bbMatch.Success)
{
sourceBB = bbMatch.Groups[1].Value.Trim();
}
}
GetFileCodeInfo(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
StringBuilder stringBuilder = new StringBuilder();
if (code.StartsWith("QD"))
if (sourceCode.StartsWith("QD"))
{
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{sourceCode}')");
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{sourceCode.Replace("'", "''")}','{name.Replace("'", "''")}','','0199') end;");
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{sourceCode.Replace("'", "''")}','{sourceName.Replace("'", "''")}','','0199') end;");
}
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
{
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
}
StringBuilder insertbulider = new StringBuilder();
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;
@@ -625,6 +628,7 @@ namespace Lskj.PubBomImport
SetProcessBar(60, allCount);
string guid = Guid.NewGuid() + "";
frmBillInfo.BillSaveSql(guid);
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider}' where guid = '{guid}'");
SetProcessBar(80, allCount);
//记录guid
string updateGuidSql = @"update QMS_wenjiangenggaitab set qms_wjgg_uuid = '{0}' where qms_wjgg_billdocument_Id = '{1}'";
@@ -649,34 +653,12 @@ namespace Lskj.PubBomImport
//如果是ZZQD文件
else if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("ZZQD")))
{
ControlModel topcontrolModel = StaticControl.RightMenuMyControl.ControlModels.Where(n => n.LabelText.Equals("顶级编码")).FirstOrDefault();
if (topcontrolModel == null)
{
MessageUtil.Show($"物料编码不存在");
}
productCode = StaticControl.RightMenuMyControl.GetControlValue(topcontrolModel);
string code = "";
string name = "";
string sourceCode = "";
string sourceBB = "";
int sourceBC = 0;
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
if (namematch.Success)
{
code = namematch.Groups[1].Value.Trim();
name = namematch.Groups[2].Value.Trim();
}
Match match = Regex.Match(code, pattern);
if (match.Success)
{
sourceCode = match.Groups[1].Value;
int.TryParse(match.Groups[2].Value, out sourceBC);//版次
Match bbMatch = Regex.Match(sourceCode, @"^.*?([A-Za-z]+)(\d*)$");
if (bbMatch.Success)
{
sourceBB = bbMatch.Groups[1].Value.Trim();
}
}
productCode = topProductId;
GetFileCodeInfo(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
StringBuilder insertbulider = new StringBuilder();
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;
@@ -719,6 +701,7 @@ namespace Lskj.PubBomImport
SetProcessBar(60, allCount);
string guid = Guid.NewGuid() + "";
frmBillInfo.BillSaveSql(guid);
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider}' where guid = '{guid}'");
SetProcessBar(80, allCount);
//记录guid
string updateGuidSql = @"update QMS_wenjiangenggaitab set qms_wjgg_uuid = '{0}' where qms_wjgg_billdocument_Id = '{1}'";
@@ -743,34 +726,8 @@ namespace Lskj.PubBomImport
//如果是MX文件
else if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("MX")))
{
ControlModel topcontrolModel = StaticControl.RightMenuMyControl.ControlModels.Where(n => n.LabelText.Equals("顶级编码")).FirstOrDefault();
if (topcontrolModel == null)
{
MessageUtil.Show($"物料编码不存在");
}
productCode = StaticControl.RightMenuMyControl.GetControlValue(topcontrolModel);
string code = "";
string name = "";
string sourceCode = "";
string sourceBB = "";
int sourceBC = 0;
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
if (namematch.Success)
{
code = namematch.Groups[1].Value.Trim();
name = namematch.Groups[2].Value.Trim();
}
Match match = Regex.Match(code, pattern);
if (match.Success)
{
sourceCode = match.Groups[1].Value;
int.TryParse(match.Groups[2].Value, out sourceBC);//版次
Match bbMatch = Regex.Match(sourceCode, @"^.*?([A-Za-z]+)(\d*)$");
if (bbMatch.Success)
{
sourceBB = bbMatch.Groups[1].Value.Trim();
}
}
productCode = topProductId;
GetFileCodeInfo(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
//更新或新增并备份清单
int.TryParse(Model.FirstRowIndex, out int index);
frmMain.FirstRowIndex = index;
@@ -795,7 +752,6 @@ 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') and isdisabled = '0'";
DataRow fileRow = BaseImpl.GetDataRowResult(fileSql);
string webpath = fileRow != null ? fileRow["webpath"] + "" : "";
@@ -842,10 +798,14 @@ namespace Lskj.PubBomImport
SetProcessBar(0, 0);
SetProcessMsg($"正在导入:{Path.GetFileName(parentInfo.FullName)}");
DataTable childTable = frmBillInfo.GcMainView.GridControl.DataSourceTable().Clone();
StringBuilder insertbulider = new StringBuilder();
insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{productCode}';");
insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{productCode}','{sourceCode + sourceBC}','{sourceCode}'),'{ERPInfo.Instance.UserName}','变更';");
foreach (DataRow parentRow in parentTable.Rows)
{
int.TryParse(parentRow["套数"] + "", out int tamount);
string childCode = parentRow["图号"] + "";
insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{productCode}','{sourceCode + sourceBC}','{childCode}','{ERPInfo.Instance.UserName}','变更');");
if (childCode.StartsWith("QD") || childCode.StartsWith("ZZQD"))
{
string tempFileName = childFileDic[childCode];
@@ -856,28 +816,7 @@ namespace Lskj.PubBomImport
}
if (childInfo != null)
{
string childcode = "";
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();
childname = namematch.Groups[2].Value.Trim();
}
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();
}
}
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string childsourceCode, out string childsourceName, out string childsourceBB, out int childsourceBC);
if (childCode.StartsWith("ZZQD"))
{
DataTable zzqdTable = ExcelToDatatable(childInfo.FullName, Model, "", index);
@@ -943,6 +882,7 @@ namespace Lskj.PubBomImport
SetProcessBar(60, allCount);
string guid = Guid.NewGuid() + "";
frmBillInfo.BillSaveSql(guid);
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider}' where guid = '{guid}'");
SetProcessBar(80, allCount);
//记录guid
string updateGuidSql = @"update QMS_wenjiangenggaitab set qms_wjgg_uuid = '{0}' where qms_wjgg_billdocument_Id = '{1}'";
@@ -964,6 +904,18 @@ namespace Lskj.PubBomImport
throw new Exception($"Bom明细获取失败\r\nBom导入失败");
}
}
else
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
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','','')");
StringBuilder insertbulider = new StringBuilder();
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}','变更';");
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider}' where guid = '{guid}'");
}
}
this.DialogResult = DialogResult.OK;
}
@@ -1246,12 +1198,12 @@ namespace Lskj.PubBomImport
DataTable childTable = frmBillInfo.GcMainView.GridControl.DataSourceTable().Clone();
StringBuilder insertbulider = new StringBuilder();
insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{productId}';");
insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName) values ('{productId}','{mxsourceCode + mxsourceBC}','{mxsourceCode}');");
insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{productId}','{mxsourceCode + mxsourceBC}','{mxsourceCode}','{ERPInfo.Instance.UserName}','新增');");
foreach (DataRow parentRow in parentTable.Rows)
{
int.TryParse(parentRow["套数"] + "", out int tamount);
string code = (parentRow["图号"] + "").Trim();
insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName) values ('{productId}','{mxsourceCode + mxsourceBC}','{code}');");
insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{productId}','{mxsourceCode + mxsourceBC}','{code}','{ERPInfo.Instance.UserName}','新增');");
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;
@@ -1373,7 +1325,6 @@ namespace Lskj.PubBomImport
}
}
}
BaseImpl.ExecSqlValue(insertbulider.ToString());
SetProcessBar(20, 0);
if (childTable.Rows.Count == 0)
{
@@ -1387,6 +1338,7 @@ namespace Lskj.PubBomImport
frmBillInfo.AddOrUpdateBill(masterRow, childTable);
string guid = Guid.NewGuid() + "";
frmBillInfo.BillSaveSql(guid);
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider}' where guid = '{guid}'");
SetProcessBar(80, 0);
//上传文件
string uploadFileId = mxMaxBcFileId;
@@ -1702,6 +1654,7 @@ namespace Lskj.PubBomImport
{
string masterSql = execRow["masterSql"] + "";
string detailSql = execRow["detailSql"] + "";
string afterSql = execRow["afterSql"] + "";
string detailTable = execRow["detailTable"] + "";
string detailGuid = execRow["detailGuid"] + "";
string billSeq = execRow["billSeq"] + "";
@@ -1710,12 +1663,14 @@ namespace Lskj.PubBomImport
int.TryParse(execRow["auditFlag"] + "", out int auditFlag);
int.TryParse(execRow["newVer"] + "", out int newVer);
string billNo = execRow["billNo"] + "";
if (!string.IsNullOrEmpty(masterSql) && !string.IsNullOrEmpty(detailSql))
{
int result = BillImpl.BillSave(masterSql, detailSql, detailTable, ref billNo, detailGuid, billSeq, billWay, comfirm, out string tipMsg, auditFlag, newVer);
if (result == 1)
{
GetFileCodeInfo(afterFilename, out string fileCode, out string name, out string fileBB, out int fileBC);
BaseImpl.ExecSqlValue(afterSql);
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set success = 1 where guid = '{execGuid}'");
BaseImpl.ExecSqlValue($"insert into FileAttachmentMapping(MaterialCode, MxFileName, RelatedAttachmentName) values('{topProductId}', '', '{fileCode}');");
List<SqlParameter> sqlParamList = new List<SqlParameter>();
sqlParamList.Add(new SqlParameter("@copyFileId", SqlDbType.Int) { Value = copyFileId });
sqlParamList.Add(new SqlParameter("@copyToModule", SqlDbType.VarChar, 100) { Value = "1000202" });
@@ -1729,6 +1684,12 @@ namespace Lskj.PubBomImport
throw new Exception($"保存Bom失败\r\n{tipMsg}");
}
}
else
{
BaseImpl.ExecSqlValue(afterSql);
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set success = 1 where guid = '{execGuid}'");
}
}
SetProcessBar(100, 100);
SetProcessLabelAllMsg($"总进度:1/1");
this.DialogResult = DialogResult.OK;
@@ -1796,6 +1757,7 @@ namespace Lskj.PubBomImport
{
string masterSql = execRow["masterSql"] + "";
string detailSql = execRow["detailSql"] + "";
string afterSql = execRow["afterSql"] + "";
string detailTable = execRow["detailTable"] + "";
string detailGuid = execRow["detailGuid"] + "";
string billSeq = execRow["billSeq"] + "";
@@ -1804,9 +1766,12 @@ namespace Lskj.PubBomImport
int.TryParse(execRow["auditFlag"] + "", out int auditFlag);
int.TryParse(execRow["newVer"] + "", out int newVer);
string billNo = execRow["billNo"] + "";
if (!string.IsNullOrEmpty(masterSql) && !string.IsNullOrEmpty(detailSql))
{
int result = BillImpl.BillSave(masterSql, detailSql, detailTable, ref billNo, detailGuid, billSeq, billWay, comfirm, out string tipMsg, auditFlag, newVer);
if (result == 1)
{
BaseImpl.ExecSqlValue(afterSql);
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set success = 1 where guid = '{execGuid}'");
}
else
@@ -1814,6 +1779,12 @@ namespace Lskj.PubBomImport
throw new Exception($"保存Bom失败\r\n{tipMsg}");
}
}
else
{
BaseImpl.ExecSqlValue(afterSql);
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set success = 1 where guid = '{execGuid}'");
}
}
//using (WebClient webClient = new WebClient())
//{
// try