From 2740456d41d05a1a5966cac5efab7bae2da7e18b Mon Sep 17 00:00:00 2001 From: lihanbo Date: Tue, 3 Dec 2024 11:50:36 +0800 Subject: [PATCH] =?UTF-8?q?105040=20=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E4=BF=9D=E5=AD=98=EF=BC=8C=E4=BC=98=E5=8C=96=E7=95=8C?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sinvo.EplanHpD.Plugin.Service/DBHelper.cs | 36 ++++ .../Model/MotorDataModel.cs | 18 ++ .../MotorLectotypeService.cs | 34 ++++ .../PluginServices.cs | 12 ++ .../Properties/AssemblyInfo.cs | 33 ++++ .../Sinvo.EplanHpD.Plugin.Service.csproj | 56 ++++++ .../Sinvo.EplanHpD.Plugin.WPFUI.csproj | 7 + .../Utils/LectotypeManager.cs | 26 ++- .../Utils/MessageSend.cs | 7 + .../View/CableLectotypeWindow.xaml | 37 +--- .../View/CableLectotypeWindow.xaml.cs | 116 +++++++++--- .../View/LectotypeWindow.xaml | 171 +++++++++++------- .../View/LectotypeWindow.xaml.cs | 82 +++------ .../ViewModel/CableLectotypeViewModel.cs | 55 +++++- Sinvo.EplanHpD.Plugin.sln | 14 ++ 15 files changed, 523 insertions(+), 181 deletions(-) create mode 100644 Sinvo.EplanHpD.Plugin.Service/DBHelper.cs create mode 100644 Sinvo.EplanHpD.Plugin.Service/Model/MotorDataModel.cs create mode 100644 Sinvo.EplanHpD.Plugin.Service/MotorLectotypeService.cs create mode 100644 Sinvo.EplanHpD.Plugin.Service/PluginServices.cs create mode 100644 Sinvo.EplanHpD.Plugin.Service/Properties/AssemblyInfo.cs create mode 100644 Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj diff --git a/Sinvo.EplanHpD.Plugin.Service/DBHelper.cs b/Sinvo.EplanHpD.Plugin.Service/DBHelper.cs new file mode 100644 index 0000000..d749221 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.Service/DBHelper.cs @@ -0,0 +1,36 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.Service +{ + public class DBHelper + { + private static string _dbUser = "sa"; + private static string _dbPassword = "Sa1234"; + private static string _dbServer = "."; + private static string _dbName = "MotorData"; + + private static string _connectionString => $"Server={_dbServer};Database={_dbName};User Id={_dbUser};Password={_dbPassword};"; + + private static SqlSugarClient _db; + public static SqlSugarClient DB + { + get + { + _db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = _connectionString, + DbType = DbType.SqlServer, + IsAutoCloseConnection = true, + InitKeyType = InitKeyType.Attribute + }); + return _db; + } + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.Service/Model/MotorDataModel.cs b/Sinvo.EplanHpD.Plugin.Service/Model/MotorDataModel.cs new file mode 100644 index 0000000..993654c --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.Service/Model/MotorDataModel.cs @@ -0,0 +1,18 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.Service.Model +{ + [SugarTable("T_MOTOR_DATA")] + public class MotorDataModel + { + [SugarColumn(IsPrimaryKey = true, ColumnDataType = "VARCHAR(64)")] + public string ID { get; set; } + [SugarColumn(ColumnDataType = "TEXT")] + public string Data { get; set; } + } +} diff --git a/Sinvo.EplanHpD.Plugin.Service/MotorLectotypeService.cs b/Sinvo.EplanHpD.Plugin.Service/MotorLectotypeService.cs new file mode 100644 index 0000000..ff85951 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.Service/MotorLectotypeService.cs @@ -0,0 +1,34 @@ +using Sinvo.EplanHpD.Plugin.Service.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.Service +{ + public class MotorLectotypeService + { + public string GetMotorLectotypeData(string motorOccId) + { + var data = DBHelper.DB.Queryable("mt") + .Where(mt => mt.ID == motorOccId) + .First(); + if (data != null) + { + return data.Data; + } + else + { + return ""; + } + } + + public bool SaveMotorLectotypeData(string motorOccId, string data) + { + var motorData = new MotorDataModel { ID = motorOccId, Data = data }; + var result = DBHelper.DB.Storageable(motorData).WhereColumns(p => p.ID).ExecuteCommand(); + return result != 0; + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.Service/PluginServices.cs b/Sinvo.EplanHpD.Plugin.Service/PluginServices.cs new file mode 100644 index 0000000..3d57250 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.Service/PluginServices.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.Service +{ + public class PluginServices + { + } +} diff --git a/Sinvo.EplanHpD.Plugin.Service/Properties/AssemblyInfo.cs b/Sinvo.EplanHpD.Plugin.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8b9b33e --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Sinvo.EplanHpD.Plugin.Service")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Sinvo.EplanHpD.Plugin.Service")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("ad1aa2bc-9289-46ae-bdc0-30ae13f51b3f")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj b/Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj new file mode 100644 index 0000000..b9954d9 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj @@ -0,0 +1,56 @@ + + + + + Debug + AnyCPU + {AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F} + Library + Properties + Sinvo.EplanHpD.Plugin.Service + Sinvo.EplanHpD.Plugin.Service + v4.8 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + 5.1.4.170 + + + + \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj index 19470f4..975e64b 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj @@ -245,6 +245,10 @@ {60d3c75c-e71d-4116-bd7e-cac68c4dd96b} PdfiumViewer + + {AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F} + Sinvo.EplanHpD.Plugin.Service + @@ -256,6 +260,9 @@ 1.34.2 + + 13.0.3 + 1.14.1 runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs index 2576969..3e43c8d 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs @@ -1,4 +1,5 @@ -using Sinvo.EplanHpD.Plugin.WPFUI.Models; +using Sinvo.EplanHpD.Plugin.Service; +using Sinvo.EplanHpD.Plugin.WPFUI.Models; using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; using System; using System.Collections.Generic; @@ -6,6 +7,7 @@ using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; using System.Windows.Markup; namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils @@ -19,7 +21,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils { private static readonly IDictionary _motorViewModel = new Dictionary(); - public static CableLectotypeViewModel CreateOrGet(MotorModel motor) + public static async Task CreateOrGetAsync(MotorModel motor) { if (motor == null || string.IsNullOrEmpty(motor.OccPartId)) { @@ -27,16 +29,24 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils return new CableLectotypeViewModel(new MotorModel()); } - if (_motorViewModel.ContainsKey(motor.OccPartId)) + + CableLectotypeViewModel viewModel = null; + Task.Factory.StartNew(() => { - Debug.WriteLine($"CreateOrGet Get -> {motor.MotorModelStr} => {motor.OccPartId}"); - return _motorViewModel[motor.OccPartId]; + var service = new MotorLectotypeService(); + var data = service.GetMotorLectotypeData(motor.OccPartId); + if (!string.IsNullOrEmpty(data)) + { + viewModel = Newtonsoft.Json.JsonConvert.DeserializeObject(data); + } + + }).Wait(); + if (viewModel == null) + { + return new CableLectotypeViewModel(motor); } else { - var viewModel = new CableLectotypeViewModel(motor); - _motorViewModel.Add(motor.OccPartId, viewModel); - Debug.WriteLine($"CreateOrGet Create -> {motor.MotorModelStr} => {motor.OccPartId}"); return viewModel; } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MessageSend.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MessageSend.cs index 27aedb6..1012d09 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MessageSend.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MessageSend.cs @@ -33,6 +33,13 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils } } } + public static void Unsubscribe(string message) + { + if (_subscribers.ContainsKey(message)) + { + _subscribers.Remove(message); + } + } public static void Publish(string message, object parameter = null) { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml index 2f5d25a..0208b3c 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml @@ -1,4 +1,4 @@ - - + @@ -32,8 +31,8 @@ - - + + @@ -42,20 +41,7 @@ - - - + + ContentTemplate="{StaticResource LoadingMask}" + Visibility="Collapsed" /> -