From bb817a4e47bcb097c857ba7e6ef4692628f2e89f Mon Sep 17 00:00:00 2001 From: wyf Date: Thu, 15 May 2025 02:53:40 +0000 Subject: [PATCH] SVN r581 SVN-Revision: r581 --- 插件库/Lskj.PubBomImport/FrmProgress.cs | 225 +++++++++++------------- 1 file changed, 98 insertions(+), 127 deletions(-) diff --git a/插件库/Lskj.PubBomImport/FrmProgress.cs b/插件库/Lskj.PubBomImport/FrmProgress.cs index 52a3483..71d49b4 100644 --- a/插件库/Lskj.PubBomImport/FrmProgress.cs +++ b/插件库/Lskj.PubBomImport/FrmProgress.cs @@ -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 labelRemarkList = new List(); List 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,23 +1663,31 @@ namespace Lskj.PubBomImport int.TryParse(execRow["auditFlag"] + "", out int auditFlag); int.TryParse(execRow["newVer"] + "", out int newVer); string billNo = execRow["billNo"] + ""; - int result = BillImpl.BillSave(masterSql, detailSql, detailTable, ref billNo, detailGuid, billSeq, billWay, comfirm, out string tipMsg, auditFlag, newVer); - if (result == 1) + if (!string.IsNullOrEmpty(masterSql) && !string.IsNullOrEmpty(detailSql)) { - GetFileCodeInfo(afterFilename, out string fileCode, out string name, out string fileBB, out int fileBC); - BaseImpl.ExecSqlValue($"update p_bomImportExecTab set success = 1 where guid = '{execGuid}'"); - BaseImpl.ExecSqlValue($"insert into FileAttachmentMapping(MaterialCode, MxFileName, RelatedAttachmentName) values('{topProductId}', '', '{fileCode}');"); - List sqlParamList = new List(); - sqlParamList.Add(new SqlParameter("@copyFileId", SqlDbType.Int) { Value = copyFileId }); - sqlParamList.Add(new SqlParameter("@copyToModule", SqlDbType.VarChar, 100) { Value = "1000202" }); - sqlParamList.Add(new SqlParameter("@copyToIdValue", SqlDbType.VarChar, 100) { Value = fileCode }); - sqlParamList.Add(new SqlParameter("@coverFileId", SqlDbType.Int) { Value = coverFileId }); - sqlParamList.Add(new SqlParameter("@coverTag", SqlDbType.Int) { Value = coverTag }); - BaseImpl.ExecProcedure("p_CopyAttcFileInfo", sqlParamList.ToArray()); + 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}'"); + List sqlParamList = new List(); + sqlParamList.Add(new SqlParameter("@copyFileId", SqlDbType.Int) { Value = copyFileId }); + sqlParamList.Add(new SqlParameter("@copyToModule", SqlDbType.VarChar, 100) { Value = "1000202" }); + sqlParamList.Add(new SqlParameter("@copyToIdValue", SqlDbType.VarChar, 100) { Value = fileCode }); + sqlParamList.Add(new SqlParameter("@coverFileId", SqlDbType.Int) { Value = coverFileId }); + sqlParamList.Add(new SqlParameter("@coverTag", SqlDbType.Int) { Value = coverTag }); + BaseImpl.ExecProcedure("p_CopyAttcFileInfo", sqlParamList.ToArray()); + } + else + { + throw new Exception($"保存Bom失败\r\n{tipMsg}"); + } } else { - throw new Exception($"保存Bom失败\r\n{tipMsg}"); + BaseImpl.ExecSqlValue(afterSql); + BaseImpl.ExecSqlValue($"update p_bomImportExecTab set success = 1 where guid = '{execGuid}'"); } } SetProcessBar(100, 100); @@ -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,14 +1766,23 @@ namespace Lskj.PubBomImport int.TryParse(execRow["auditFlag"] + "", out int auditFlag); int.TryParse(execRow["newVer"] + "", out int newVer); string billNo = execRow["billNo"] + ""; - int result = BillImpl.BillSave(masterSql, detailSql, detailTable, ref billNo, detailGuid, billSeq, billWay, comfirm, out string tipMsg, auditFlag, newVer); - if (result == 1) + if (!string.IsNullOrEmpty(masterSql) && !string.IsNullOrEmpty(detailSql)) { - BaseImpl.ExecSqlValue($"update p_bomImportExecTab set success = 1 where guid = '{execGuid}'"); + 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 + { + throw new Exception($"保存Bom失败\r\n{tipMsg}"); + } } else { - throw new Exception($"保存Bom失败\r\n{tipMsg}"); + BaseImpl.ExecSqlValue(afterSql); + BaseImpl.ExecSqlValue($"update p_bomImportExecTab set success = 1 where guid = '{execGuid}'"); } } //using (WebClient webClient = new WebClient())