diff --git a/插件库/Lskj.PubBomImport/FrmProgress.cs b/插件库/Lskj.PubBomImport/FrmProgress.cs index 9bc99d3..4fb324d 100644 --- a/插件库/Lskj.PubBomImport/FrmProgress.cs +++ b/插件库/Lskj.PubBomImport/FrmProgress.cs @@ -800,7 +800,7 @@ namespace Lskj.PubBomImport 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 }','{sourceCode}','{ERPInfo.Instance.UserName}','变更');"); + //insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{productCode}','{sourceCode }','{sourceCode}','{ERPInfo.Instance.UserName}','变更');"); foreach (DataRow parentRow in parentTable.Rows) { int.TryParse(parentRow["套数"] + "", out int tamount); @@ -1144,6 +1144,11 @@ namespace Lskj.PubBomImport { throw new Exception($"物料编码{productId}的BOM新增单已存在"); } + DataRow billbomRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}'"); + if (billRow != null) + { + throw new Exception($"物料编码{productId}的BOM建立单已存在\r\n请进行修改操作"); + } FileInfo mxInfo = new FileInfo(mxDirPath); if (mxInfo != null) { @@ -1197,6 +1202,7 @@ namespace Lskj.PubBomImport DataRow parentProductRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}'"); Dictionary maxBcFileDic = new Dictionary(); Dictionary fileTableDic = new Dictionary(); + List notUploadFileList = new List(); if (parentProductRow == null) { frmBillInfo.OnBillAdd(); @@ -1205,7 +1211,7 @@ 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,OperatorUser,ChangeStatus) values ('{productId}','{mxsourceCode }','{mxsourceCode}','{ERPInfo.Instance.UserName}','新增');"); + //insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{productId}','{mxsourceCode }','{mxsourceCode}','{ERPInfo.Instance.UserName}','新增');"); foreach (DataRow parentRow in parentTable.Rows) { int.TryParse(parentRow["套数"] + "", out int tamount); @@ -1213,7 +1219,7 @@ namespace Lskj.PubBomImport insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{productId}','{mxsourceCode }','{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; + int childMaxBc = -1; foreach (DataRow fileRow in filetable.Rows) { string fileName = fileRow["sname"] + ""; @@ -1234,15 +1240,16 @@ namespace Lskj.PubBomImport string childFileName = childInfoRow[Model.AfterBomFieldName] + ""; string childDirPath = childInfoRow["BomFieldNameDir"] + ""; FileInfo childInfo = new FileInfo(childDirPath); - //if (childInfo != null) - //{ - // GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string childsourceCode, out string childname, out string childsourceBB, out int childsourceBC); - // //如果文件夹中有附件,则比较版次,如果大于最大版次,则提示 - // if (childsourceBC > childMaxBc && filetable.Rows.Count > 0) - // { - // throw new Exception($"{childsourceCode}的版次为{childsourceBC},大于最大版次{childMaxBc}\r\n请进行变更"); - // } - //} + //如果存在附件则判断是否已经上传了附件 + if (childInfo != null) + { + GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string childsourceCode, out string childname, out string childsourceBB, out int childsourceBC); + if (childsourceBC <= childMaxBc && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null) + { + notUploadFileList.Add(code); + childInfo = null;//设置为空下载附件使用 + } + } if (childInfo == null && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null) { using (WebClient webClient = new WebClient()) @@ -1352,7 +1359,7 @@ namespace Lskj.PubBomImport string uploadFileId = mxMaxBcFileId; if (mxfiletable.Rows.Count == 0) { - isUpload = UploadFileToAudit(mxInfo.FullName, mxsourceCode, "010106", out msg, out uploadFileId); + isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010106", out msg, out uploadFileId); if (!isUpload) { throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}"); @@ -1409,12 +1416,16 @@ namespace Lskj.PubBomImport DataTable filetable = fileTableDic.ContainsKey(code) ? fileTableDic[code] : null; if (code.StartsWith("QD")) { - DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault(); - if (childInfoRow != null) + if (!notUploadFileList.Contains(code)) { - string childFileName = childInfoRow[Model.AfterBomFieldName] + ""; - string childDirPath = childInfoRow["BomFieldNameDir"] + ""; - FileInfo childInfo = new FileInfo(childDirPath); + FileInfo childInfo = null; + DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault(); + if (childInfoRow != null) + { + string childFileName = childInfoRow[Model.AfterBomFieldName] + ""; + string childDirPath = childInfoRow["BomFieldNameDir"] + ""; + childInfo = new FileInfo(childDirPath); + } if (childInfo == null && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null) { using (WebClient webClient = new WebClient()) @@ -1543,20 +1554,47 @@ namespace Lskj.PubBomImport SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}"); } } - } - else - { - throw new Exception($"目录中不包含文件{code}"); + else + { + throw new Exception($"目录中不包含文件{code}"); + } } } else { - DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault(); - if (childInfoRow != null) + if (!notUploadFileList.Contains(code)) { - string childFileName = childInfoRow[Model.AfterBomFieldName] + ""; - string childDirPath = childInfoRow["BomFieldNameDir"] + ""; - FileInfo childInfo = new FileInfo(childDirPath); + FileInfo childInfo = null; + DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault(); + if (childInfoRow != null) + { + string childFileName = childInfoRow[Model.AfterBomFieldName] + ""; + string childDirPath = childInfoRow["BomFieldNameDir"] + ""; + childInfo = new FileInfo(childDirPath); + } + if (childInfo == null && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null) + { + using (WebClient webClient = new WebClient()) + { + try + { + string webpath = maxBcFileDic[code]["webpath"] + ""; + string sName = maxBcFileDic[code]["sName"] + ""; + webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}"; + string url = $"{SystemInfo.Instance.OAUrl}/{webpath}"; + string tempFileName = $"BomImportTemp/{sName}"; + if (!File.Exists(tempFileName)) + { + webClient.DownloadFile(url, tempFileName); + } + childInfo = new FileInfo(tempFileName); + } + catch (Exception) + { + throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败"); + } + } + } if (childInfo == null) { throw new Exception($"目录中不包含文件{code}"); @@ -1584,10 +1622,10 @@ namespace Lskj.PubBomImport SetProcessBar(100, finishCount); SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}"); } - } - else - { - throw new Exception($"目录中不包含文件{code}"); + else + { + throw new Exception($"目录中不包含文件{code}"); + } } } }