From 68965068bdb4af5efdc33aa048f7b60817d2aa37 Mon Sep 17 00:00:00 2001 From: tdx Date: Thu, 15 May 2025 12:18:47 +0000 Subject: [PATCH] SVN r588 SVN-Revision: r588 --- 插件库/Lskj.PubBomImport/FrmProgress.cs | 185 ++++++++---------- .../Lskj.PubBomImport.csproj | 5 +- 2 files changed, 89 insertions(+), 101 deletions(-) diff --git a/插件库/Lskj.PubBomImport/FrmProgress.cs b/插件库/Lskj.PubBomImport/FrmProgress.cs index 4fb324d..50bf827 100644 --- a/插件库/Lskj.PubBomImport/FrmProgress.cs +++ b/插件库/Lskj.PubBomImport/FrmProgress.cs @@ -586,9 +586,9 @@ namespace Lskj.PubBomImport } 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}','变更');"); + string mxCode = BaseImpl.GetResult($"select MxFileName from FileAttachmentMapping where MaterialCode = '{topProductId}' and RelatedAttachmentName = '{beforeSourceCode}';") + ""; + insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{topProductId}' and RelatedAttachmentName = '{beforeSourceCode}';"); + insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{topProductId}','{mxCode}','{sourceCode}','{ERPInfo.Instance.UserName}','变更');"); //更新或新增并备份清单 int.TryParse(Model.FirstRowIndex, out int index); @@ -656,9 +656,9 @@ namespace Lskj.PubBomImport 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}','变更');"); + string mxCode = BaseImpl.GetResult($"select MxFileName from FileAttachmentMapping where MaterialCode = '{topProductId}' and RelatedAttachmentName = '{beforeSourceCode}';") + ""; + insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{topProductId}' and RelatedAttachmentName = '{beforeSourceCode}';"); + insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{topProductId}','{mxCode}','{sourceCode}','{ERPInfo.Instance.UserName}','变更');"); //更新或新增并备份清单 int.TryParse(Model.FirstRowIndex, out int index); frmMain.FirstRowIndex = index; @@ -1153,7 +1153,11 @@ namespace Lskj.PubBomImport if (mxInfo != null) { GetFileCodeInfo(Path.GetFileNameWithoutExtension(mxInfo.Name).Trim(), out string mxsourceCode, out string mxname, out string mxsourceBB, out int mxsourceBC); - DataTable mxfiletable = BaseImpl.GetDataTableResult($"select sname,fileId from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{mxsourceCode}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{mxsourceCode}%'"); + DataTable mxfiletable = BaseImpl.GetDataTableResult($"select sname,fileId from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{productId}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{mxsourceCode}%'"); + if (mxfiletable.Rows.Count > 0) + { + throw new Exception($"{mxsourceCode}的附件已存在\r\n请进行变更"); + } int mxMaxBc = 0; string mxMaxBcFileId = "-1"; foreach (DataRow mxfileRow in mxfiletable.Rows) @@ -1202,7 +1206,6 @@ 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(); @@ -1234,102 +1237,86 @@ namespace Lskj.PubBomImport //判断code是否已经上传,如果已经上传则不再上传, //如果附件不存在文件夹中,则直接使用最新的 //如果附件不存在则提示 + 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"] + ""; - FileInfo childInfo = new FileInfo(childDirPath); - //如果存在附件则判断是否已经上传了附件 - if (childInfo != null) + childInfo = new FileInfo(childDirPath); + } + if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null) + { + using (WebClient webClient = new WebClient()) { - 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) + try { - notUploadFileList.Add(code); - childInfo = null;//设置为空下载附件使用 + 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 && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null) + } + 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) { - 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导入失败"); - } - } + throw new Exception($"{childsourceCode}的版次为{childsourceBC},大于最大版次{childMaxBc}\r\n请进行变更"); } - if (childInfo != null) + childsourceBC = childsourceBC >= childMaxBc ? childsourceBC : childMaxBc; + if (code.StartsWith("ZZQD")) { - 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) + DataTable zzqdTable = ExcelToDatatable(childInfo.FullName, Model, "", index); + DataView filterDataView = new DataView(zzqdTable); + try { - throw new Exception($"{childsourceCode}的版次为{childsourceBC},大于最大版次{childMaxBc}\r\n请进行变更"); - } - childsourceBC = childsourceBC >= childMaxBc ? childsourceBC : childMaxBc; - if (code.StartsWith("ZZQD")) - { - DataTable zzqdTable = ExcelToDatatable(childInfo.FullName, Model, "", index); - DataView filterDataView = new DataView(zzqdTable); - try + if (!string.IsNullOrEmpty(Model.ReadTableCond)) { - if (!string.IsNullOrEmpty(Model.ReadTableCond)) - { - filterDataView.RowFilter = Model.ReadTableCond; - } - } - catch (Exception) - { - } - zzqdTable = filterDataView.ToTable(); - foreach (DataRow zzqdItem in zzqdTable.Rows) - { - DataRow childRow = childTable.NewRow(); - childRow["ProductId"] = zzqdItem["物料编码"] + ""; - childRow["appellation"] = zzqdItem["名称"] + ""; - childRow["bak"] = childsourceCode; - childRow["bombb"] = childsourceBB; - childRow["bombc"] = childsourceBC; - childRow["tamount"] = parentRow["套数"] + ""; - int.TryParse(zzqdItem["数量"] + "", out int amount); - childRow["amount"] = amount * tamount; - childTable.Rows.Add(childRow); + filterDataView.RowFilter = Model.ReadTableCond; } } - else if (code.StartsWith("QD")) + catch (Exception) + { + } + zzqdTable = filterDataView.ToTable(); + foreach (DataRow zzqdItem in zzqdTable.Rows) { DataRow childRow = childTable.NewRow(); - childRow["ProductId"] = parentRow["图号"] + ""; - childRow["appellation"] = parentRow["名称"] + ""; + childRow["ProductId"] = zzqdItem["物料编码"] + ""; + childRow["appellation"] = zzqdItem["名称"] + ""; childRow["bak"] = childsourceCode; childRow["bombb"] = childsourceBB; childRow["bombc"] = childsourceBC; childRow["tamount"] = parentRow["套数"] + ""; - childRow["amount"] = parentRow["套数"] + ""; + int.TryParse(zzqdItem["数量"] + "", out int amount); + childRow["amount"] = amount * tamount; childTable.Rows.Add(childRow); } } - else + else if (code.StartsWith("QD")) { - if (filetable.Rows.Count == 0) - { - throw new Exception($"{code}的附件不存在,请检查文件"); - } + DataRow childRow = childTable.NewRow(); + childRow["ProductId"] = parentRow["图号"] + ""; + childRow["appellation"] = parentRow["名称"] + ""; + childRow["bak"] = childsourceCode; + childRow["bombb"] = childsourceBB; + childRow["bombc"] = childsourceBC; + childRow["tamount"] = parentRow["套数"] + ""; + childRow["amount"] = parentRow["套数"] + ""; + childTable.Rows.Add(childRow); } } else @@ -1416,7 +1403,7 @@ namespace Lskj.PubBomImport DataTable filetable = fileTableDic.ContainsKey(code) ? fileTableDic[code] : null; if (code.StartsWith("QD")) { - if (!notUploadFileList.Contains(code)) + if (filetable.Rows.Count == 0) { FileInfo childInfo = null; DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault(); @@ -1426,7 +1413,7 @@ namespace Lskj.PubBomImport string childDirPath = childInfoRow["BomFieldNameDir"] + ""; childInfo = new FileInfo(childDirPath); } - if (childInfo == null && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null) + if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null) { using (WebClient webClient = new WebClient()) { @@ -1562,7 +1549,7 @@ namespace Lskj.PubBomImport } else { - if (!notUploadFileList.Contains(code)) + if (filetable.Rows.Count == 0) { FileInfo childInfo = null; DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault(); @@ -1572,7 +1559,7 @@ namespace Lskj.PubBomImport string childDirPath = childInfoRow["BomFieldNameDir"] + ""; childInfo = new FileInfo(childDirPath); } - if (childInfo == null && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null) + if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null) { using (WebClient webClient = new WebClient()) { @@ -2193,23 +2180,23 @@ namespace Lskj.PubBomImport } if (!string.IsNullOrEmpty(token)) { - string selectSql = $"select * from P_fm_FileTab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{idValue}' and dllcoid = '1000202') and speciesno = '{speciesno}' and sname = '{name.Replace(" ", "")}'"; - DataTable deleteTable = BaseImpl.GetDataTableResult(selectSql); - if (deleteTable != null && deleteTable.Rows.Count > 0) - { - foreach (DataRow deleteRow in deleteTable.Rows) - { - string field = HttpUtility.UrlEncode(deleteRow["fileId"] + ""); - string webpath = HttpUtility.UrlEncode(deleteRow["webpath"] + ""); - //删除文件 - string deleteUrl = "{0}Api/FileUploadApi.ashx?fileId={1}&filename={2}&method={3}"; - deleteUrl = string.Format(deleteUrl, SystemInfo.Instance.OAUrl, field, webpath, "DoDelete"); - HttpHelper.Setting("application/x-www-form-urlencoded", null, null); - Dictionary deleteHeaderDic = new Dictionary(); - deleteHeaderDic.Add("Authorization", $"Bearer {token}"); - HttpWebResponse deleteWebResponse = HttpHelper.Post(deleteUrl, fileStream, null, deleteHeaderDic, out string deleteResult); - } - } + //string selectSql = $"select * from P_fm_FileTab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{idValue}' and dllcoid = '1000202') and speciesno = '{speciesno}' and sname = '{name.Replace(" ", "")}'"; + //DataTable deleteTable = BaseImpl.GetDataTableResult(selectSql); + //if (deleteTable != null && deleteTable.Rows.Count > 0) + //{ + // foreach (DataRow deleteRow in deleteTable.Rows) + // { + // string field = HttpUtility.UrlEncode(deleteRow["fileId"] + ""); + // string webpath = HttpUtility.UrlEncode(deleteRow["webpath"] + ""); + // //删除文件 + // string deleteUrl = "{0}Api/FileUploadApi.ashx?fileId={1}&filename={2}&method={3}"; + // deleteUrl = string.Format(deleteUrl, SystemInfo.Instance.OAUrl, field, webpath, "DoDelete"); + // HttpHelper.Setting("application/x-www-form-urlencoded", null, null); + // Dictionary deleteHeaderDic = new Dictionary(); + // deleteHeaderDic.Add("Authorization", $"Bearer {token}"); + // HttpWebResponse deleteWebResponse = HttpHelper.Post(deleteUrl, fileStream, null, deleteHeaderDic, out string deleteResult); + // } + //} postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, "1000202", HttpUtility.UrlEncode(idValue), "file", fileBytes.Length, 0, HttpUtility.UrlEncode(name), "DoWebUpload", speciesno); HttpTools.setting("application/x-www-form-urlencoded", null, null); string result = ""; diff --git a/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj b/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj index 26a1444..63cb521 100644 --- a/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj +++ b/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj @@ -34,11 +34,12 @@ + - + False - D:\工作\lserp_cs_6.0\引用DLL\Newtonsoft.Json.dll + ..\..\引用DLL\Newtonsoft.Json.dll ..\..\..\引用DLL\NPOI.dll