From 5bd68a7fba05329f73557c5e49d01aace88136d8 Mon Sep 17 00:00:00 2001 From: lihanbo Date: Sat, 8 Mar 2025 13:35:41 +0800 Subject: [PATCH] =?UTF-8?q?105040=20=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=B9=B6=E9=87=8D=E6=9E=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 `AssemblyInfo.cs` 中更新版本号至 `1.0.0.29` 和 `1.0.0.30`。 在 `Consts.cs` 中添加对 `Newtonsoft.Json` 的引用,重构常量为静态字段,并实现 `InitConfigs` 方法以支持从 JSON 配置文件读取路径。 在 `MotorExcelHelper.cs` 中更新数据文件路径引用,修改 `SaveLinesToExcel` 方法以接受新的参数。 在 `LayoutHelperViewModel.cs` 和 `LectotypeViewModel.cs` 中更新电机电缆获取逻辑和保存线材的方法签名。 在 `DesignPluginEntry.cs` 和 `PluginEntry.cs` 中调用 `Consts.InitConfigs()` 初始化配置。 --- .../Properties/AssemblyInfo.cs | 6 +- .../Properties/AssemblyInfo.cs | 6 +- Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs | 85 +++++++++++++++++-- .../Utils/MotorExcelHelper.cs | 25 ++---- .../ViewModel/LayoutHelperViewModel.cs | 4 +- .../ViewModel/LectotypeViewModel.cs | 11 ++- .../ViewModel/MainViewModel.Check.cs | 2 +- Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs | 1 + Sinvo.EplanHpD.Plugin/PluginEntry.cs | 1 + .../Properties/AssemblyInfo.cs | 6 +- Sinvo.EplanHpD.Plugin/ScanPluginEntry.cs | 1 + 11 files changed, 110 insertions(+), 38 deletions(-) diff --git a/Sinvo.EplanHpD.Plugin.Service/Properties/AssemblyInfo.cs b/Sinvo.EplanHpD.Plugin.Service/Properties/AssemblyInfo.cs index 93299dc..76761b1 100644 --- a/Sinvo.EplanHpD.Plugin.Service/Properties/AssemblyInfo.cs +++ b/Sinvo.EplanHpD.Plugin.Service/Properties/AssemblyInfo.cs @@ -29,6 +29,6 @@ using System.Runtime.InteropServices; // 生成号 // 修订号 // -[assembly: AssemblyVersion("1.0.0.28")] -[assembly: AssemblyFileVersion("1.0.0.28")] -[assembly: AssemblyInformationalVersion("1.0.0.28")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.0.29")] +[assembly: AssemblyFileVersion("1.0.0.30")] +[assembly: AssemblyInformationalVersion("1.0.0.30")] \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Properties/AssemblyInfo.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Properties/AssemblyInfo.cs index 244678d..ff5a37e 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Properties/AssemblyInfo.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Properties/AssemblyInfo.cs @@ -46,6 +46,6 @@ using System.Windows; // 生成号 // 修订号 // -[assembly: AssemblyVersion("1.0.0.28")] -[assembly: AssemblyFileVersion("1.0.0.28")] -[assembly: AssemblyInformationalVersion("1.0.0.28")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.0.29")] +[assembly: AssemblyFileVersion("1.0.0.30")] +[assembly: AssemblyInformationalVersion("1.0.0.30")] \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs index f4418cc..b566237 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs @@ -1,19 +1,36 @@ -using System.Text.RegularExpressions; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Text.RegularExpressions; namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils { - internal class Consts + public class Consts { - public const string DATA_FILE_PATH = @"\\192.168.1.160\plm系统文档\线材资料检查"; + private const string CONFIG_FILE_PATH = @"\\192.168.1.160\plm系统文档\线材资料检查"; + + public static string DATA_FILE_PATH = @"\\192.168.1.160\plm系统文档\线材资料检查"; /// /// 线材端子号码管配对表(配CE端子).xlsm /// - public const string DATA_FILE_PATH_WIRE_TERMINAL = @"线材端子号码管配对表(配CE端子).xlsm"; + public static string DATA_FILE_PATH_WIRE_TERMINAL = @"线材端子号码管配对表(配CE端子).xlsm"; /// /// 绝缘软套 /// - public const string DATA_FILE_PATH_INSULATION = @"绝缘软套规格.xlsx"; - public const string TEMPLATE_FILE_NAME = @"下单模板.xlsx"; + public static string DATA_FILE_PATH_INSULATION = @"绝缘软套规格.xlsx"; + public static string TEMPLATE_FILE_NAME = @"下单模板.xlsx"; + +#if DEBUG + public static string PLUGIN_DATA_FILE_PATH = @"D:\Desktop\EPlan\线材选型"; +#else + + public static string PLUGIN_DATA_FILE_PATH = @"\\192.168.1.160\plm系统文档\线材选型\插件";//@"D:\旧电脑文件\Desktop\EPlan\线材选型";// +#endif + public static string PLUGIN_DATA_FILE_NAME = "线材选型数据表.xlsx"; + public static string PLUGIN_DATA_FILE_NAME_BOM = "BOM表.xlsx"; + public static string PLUGIN_TEMPLATE_FILE_NAME = "下单定制线模板.xlsx"; + /// /// 线径平方规格匹配 /// @@ -22,7 +39,61 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils /// 变色套平方规格匹配 /// public static readonly Regex dRegex = new("V-[\\d]+\\.?[\\d]*", RegexOptions.Compiled); - + /// + /// 括号内容匹配 + /// public static readonly Regex regexParenthesesContent = new(@"(?<=\()[^)]*(?=\))", RegexOptions.Compiled); + + public static void InitConfigs() + { + var jsonObj = JsonConvert.DeserializeObject>(File.ReadAllText(Path.Combine(CONFIG_FILE_PATH, "config.json"))); + if(jsonObj != null) + { + if (jsonObj.ContainsKey("DATA_FILE_PATH")) + { + DATA_FILE_PATH = jsonObj["DATA_FILE_PATH"]; + Debug.WriteLine(DATA_FILE_PATH); + } + if (jsonObj.ContainsKey("DATA_FILE_PATH_WIRE_TERMINAL")) + { + DATA_FILE_PATH_WIRE_TERMINAL = jsonObj["DATA_FILE_PATH_WIRE_TERMINAL"]; + Debug.WriteLine(DATA_FILE_PATH_WIRE_TERMINAL); + } + if (jsonObj.ContainsKey("DATA_FILE_PATH_INSULATION")) + { + DATA_FILE_PATH_INSULATION = jsonObj["DATA_FILE_PATH_INSULATION"]; + Debug.WriteLine(DATA_FILE_PATH_INSULATION); + } + if (jsonObj.ContainsKey("TEMPLATE_FILE_NAME")) + { + TEMPLATE_FILE_NAME = jsonObj["TEMPLATE_FILE_NAME"]; + Debug.WriteLine(TEMPLATE_FILE_NAME); + } + + // 插件 + if (jsonObj.ContainsKey("PLUGIN_DATA_FILE_PATH")) + { + PLUGIN_DATA_FILE_PATH = jsonObj["PLUGIN_DATA_FILE_PATH"]; + Debug.WriteLine(PLUGIN_DATA_FILE_PATH); + } + if (jsonObj.ContainsKey("PLUGIN_DATA_FILE_NAME")) + { + PLUGIN_DATA_FILE_NAME = jsonObj["PLUGIN_DATA_FILE_NAME"]; + Debug.WriteLine(PLUGIN_DATA_FILE_NAME); + + } + if (jsonObj.ContainsKey("PLUGIN_DATA_FILE_NAME_BOM")) + { + PLUGIN_DATA_FILE_NAME_BOM = jsonObj["PLUGIN_DATA_FILE_NAME_BOM"]; + Debug.WriteLine(PLUGIN_DATA_FILE_NAME_BOM); + } + if (jsonObj.ContainsKey("PLUGIN_TEMPLATE_FILE_NAME")) + { + PLUGIN_TEMPLATE_FILE_NAME = jsonObj["PLUGIN_TEMPLATE_FILE_NAME"]; + Debug.WriteLine(PLUGIN_TEMPLATE_FILE_NAME); + } + + } + } } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs index 000fa2f..b53f78a 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs @@ -13,18 +13,9 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils public static MotorExcelHelper Instance = new(); private Stream dataFileStream; -#if DEBUG - public const string DATA_FILE_PATH = @"D:\Desktop\EPlan\线材选型"; -#else - - public const string DATA_FILE_PATH = @"\\192.168.1.160\plm系统文档\线材选型\插件";//@"D:\旧电脑文件\Desktop\EPlan\线材选型";// -#endif - private const string DATA_FILE_NAME = "线材选型数据表.xlsx"; - private const string DATA_FILE_NAME_BOM = "BOM表.xlsx"; - private const string TEMPLATE_FILE_NAME = "下单定制线模板.xlsx"; public void ReadDataToStream() { - var file = Path.Combine(DATA_FILE_PATH, DATA_FILE_NAME); + var file = Path.Combine(Consts.PLUGIN_DATA_FILE_PATH, Consts.PLUGIN_DATA_FILE_NAME); if (File.Exists(file)) { var bytes = File.ReadAllBytes(file); @@ -153,7 +144,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils public List GetBomList(string drawNo) { //var filePath = "D:\\Desktop\\Data\\BOM表.xlsx"; - var filePath = Path.Combine(DATA_FILE_PATH, DATA_FILE_NAME_BOM); + var filePath = Path.Combine(Consts.PLUGIN_DATA_FILE_PATH, Consts.PLUGIN_DATA_FILE_NAME_BOM); var data = MiniExcel.Query(filePath).Where(it => it.DrawingNo == drawNo).ToList(); //MiniExcel.Query<>() return data; @@ -165,11 +156,11 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils bomList ); } - public bool SaveLinesToExcel(string targetPath, List lines) + public bool SaveLinesToExcel(string targetPath,string mechanismNo, List lines) { try { - var templatePath = Path.Combine(DATA_FILE_PATH, TEMPLATE_FILE_NAME); + var templatePath = Path.Combine(Consts.PLUGIN_DATA_FILE_PATH, Consts.PLUGIN_TEMPLATE_FILE_NAME); var data = lines.Select(line => new { line.ItemSeqNo, @@ -182,11 +173,11 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils line.DrawingNo, EncoderLineLength = line.EncoderLineLength == 0 ? "" : line.EncoderLineLength.ToString(), PowerLineLength = line.PowerLineLength == 0 ? "" : line.PowerLineLength.ToString(), - OrderDate = DateTime.Now.ToString("yyyy/MM/dd"), - DeliveryDate = DateTime.Now.AddDays(7).ToString("yyyy/MM/dd"), // 交期默认一周 + OrderDate = DateTime.Now.ToString("yyyy/M/d"), + DeliveryDate = DateTime.Now.AddDays(7).ToString("yyyy/M/d"), // 交期默认一周 }).ToList(); MiniExcel.SaveAsByTemplate( - $"{targetPath}\\线材下单_{DateTime.Now:yyyy_MM_dd}.xlsx", + $"{targetPath}\\{mechanismNo}线材下单_{DateTime.Now:yyyy_MM_dd}_{DateTime.Now.Ticks}.xlsx", templatePath, new { @@ -207,7 +198,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils public void CloseStream() { - dataFileStream.Close(); + dataFileStream?.Close(); } } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs index 82bac80..150b780 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs @@ -184,7 +184,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel { SelectMotorModel = part.Parents?.First()?.Name ?? ""; Debug.WriteLine($"Select part parent -> {part.Parents?.First()?.Name} / {part.Parents?.First()?.ID}"); - } } else if (item != null) @@ -206,7 +205,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel { if (_motors != null && _motors.Any()) { - Task.Factory.StartNew(() => { var service = new MotorLectotypeService(); @@ -222,7 +220,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel Motor = _motors[CurrentMotorIndex]; return; } - } + } }).Wait(); } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs index 4f2742c..98aa20e 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs @@ -179,6 +179,7 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged { return Task.CompletedTask; } + // 当前的工作区 var designer = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); // 获取项目名 DocName = GetDocName(designer); @@ -786,7 +787,15 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged it.MechanicalName = MechanismName; it.MechanicalNo = MechanismNo; }); - MotorExcelHelper.Instance.SaveLinesToExcel(targetPath, Wires); + try + { + MotorExcelHelper.Instance.SaveLinesToExcel(targetPath, MechanismNo, Wires); + } + catch (Exception ex) + { + FlexMessageBox.Error(ex.Message); + } + } public void AddNotSavedLectotype(Dictionary value) { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.Check.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.Check.cs index fd60f76..4c01447 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.Check.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.Check.cs @@ -458,7 +458,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel } else { - + // 获取变色管颜色 var discolorationDesc = Consts.regexParenthesesContent.Match(item.DiscolorationDesc).Value; if (string.IsNullOrEmpty(discolorationDesc)) diff --git a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs index 4937067..c6ca5d5 100644 --- a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs +++ b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs @@ -87,6 +87,7 @@ namespace Sinvo.EplanHpD.Plugin { AppDomainDllLoader.SetLaoder(); ApplicationExt.InitApplication(); + Consts.InitConfigs(); } diff --git a/Sinvo.EplanHpD.Plugin/PluginEntry.cs b/Sinvo.EplanHpD.Plugin/PluginEntry.cs index 1d412de..2a0e0d0 100644 --- a/Sinvo.EplanHpD.Plugin/PluginEntry.cs +++ b/Sinvo.EplanHpD.Plugin/PluginEntry.cs @@ -150,6 +150,7 @@ namespace Sinvo.EplanHpD.Plugin //throw new NotImplementedException(); AppDomainDllLoader.SetLaoder(); ApplicationExt.InitApplication(); + Consts.InitConfigs(); } public void Terminate() diff --git a/Sinvo.EplanHpD.Plugin/Properties/AssemblyInfo.cs b/Sinvo.EplanHpD.Plugin/Properties/AssemblyInfo.cs index 0a3ecba..03e40ea 100644 --- a/Sinvo.EplanHpD.Plugin/Properties/AssemblyInfo.cs +++ b/Sinvo.EplanHpD.Plugin/Properties/AssemblyInfo.cs @@ -28,6 +28,6 @@ using System.Runtime.InteropServices; // 生成号 // 修订号 // -[assembly: AssemblyVersion("1.0.0.28")] -[assembly: AssemblyFileVersion("1.0.0.28")] -[assembly: AssemblyInformationalVersion("1.0.0.28")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.0.29")] +[assembly: AssemblyFileVersion("1.0.0.30")] +[assembly: AssemblyInformationalVersion("1.0.0.30")] \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin/ScanPluginEntry.cs b/Sinvo.EplanHpD.Plugin/ScanPluginEntry.cs index c5917e5..383b700 100644 --- a/Sinvo.EplanHpD.Plugin/ScanPluginEntry.cs +++ b/Sinvo.EplanHpD.Plugin/ScanPluginEntry.cs @@ -82,6 +82,7 @@ namespace Sinvo.EplanHpD.Plugin { AppDomainDllLoader.SetLaoder(); ApplicationExt.InitApplication(); + Consts.InitConfigs(); } public void Terminate()