From 2572dd0ea640e0ef452853690001e391e52e7e4c Mon Sep 17 00:00:00 2001 From: lihanbo Date: Thu, 24 Apr 2025 14:22:46 +0800 Subject: [PATCH] =?UTF-8?q?105040=20Update=20=E4=BC=98=E5=8C=96=E5=A4=9A?= =?UTF-8?q?=E8=8A=AF=E7=BA=BF=E7=BA=BF=E6=9D=90=E9=80=89=E5=9E=8B=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sinvo.EplanHpD.Plugin.Service/DBHelper.cs | 1 + .../Model/MultiCoreWireLecDBModel.cs | 62 ++++++ .../Sinvo.EplanHpD.Plugin.Service.csproj | 1 + .../Converter/WireColorConverter.cs | 47 ++++ .../MultiCoreWire/MultiCoreWireLecModel.cs | 28 ++- .../Service/MotorLectotypeService.cs | 5 +- .../Service/MultiCoreWireService.cs | 100 +++++++++ .../Sinvo.EplanHpD.Plugin.WPFUI.csproj | 3 + Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs | 4 + .../Utils/ExcelHelper.cs | 10 + .../Utils/LectotypeManager.cs | 21 +- .../Utils/MotorExcelHelper.cs | 3 + .../View/LoginWindow.xaml.cs | 3 +- .../MultiCoreWireLayoutHelperWindow.xaml | 14 +- .../MultiCoreWireLayoutHelperWindow.xaml.cs | 17 +- .../MultiCoreWire/MultiCoreWireWindow.xaml | 32 ++- .../MultiCoreWire/MultiCoreWireWindow.xaml.cs | 8 +- .../MultiCoreWireLayoutHelperViewModel.cs | 46 ++++ .../MultiCoreWireViewModel.cs | 205 +++++++++++++----- Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs | 50 ++--- Sinvo.EplanHpD.Plugin/PluginEntry.cs | 115 +++++----- 21 files changed, 597 insertions(+), 178 deletions(-) create mode 100644 Sinvo.EplanHpD.Plugin.Service/Model/MultiCoreWireLecDBModel.cs create mode 100644 Sinvo.EplanHpD.Plugin.WPFUI/Converter/WireColorConverter.cs create mode 100644 Sinvo.EplanHpD.Plugin.WPFUI/Service/MultiCoreWireService.cs create mode 100644 Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MultiCoreWireViewModel/MultiCoreWireLayoutHelperViewModel.cs diff --git a/Sinvo.EplanHpD.Plugin.Service/DBHelper.cs b/Sinvo.EplanHpD.Plugin.Service/DBHelper.cs index 0ad9552..57d0d3b 100644 --- a/Sinvo.EplanHpD.Plugin.Service/DBHelper.cs +++ b/Sinvo.EplanHpD.Plugin.Service/DBHelper.cs @@ -44,6 +44,7 @@ namespace Sinvo.EplanHpD.Plugin.Service DB.CodeFirst.InitTables(typeof(Model.Motor)); DB.CodeFirst.InitTables(typeof(Model.CableLectotype)); DB.CodeFirst.InitTables(typeof(Model.LectotypeLine)); + DB.CodeFirst.InitTables(typeof(Model.MultiCoreWireLecDBModel)); } } } diff --git a/Sinvo.EplanHpD.Plugin.Service/Model/MultiCoreWireLecDBModel.cs b/Sinvo.EplanHpD.Plugin.Service/Model/MultiCoreWireLecDBModel.cs new file mode 100644 index 0000000..a9f4017 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.Service/Model/MultiCoreWireLecDBModel.cs @@ -0,0 +1,62 @@ +using SqlSugar; +using System.ComponentModel; + +namespace Sinvo.EplanHpD.Plugin.Service.Model +{ + [SugarTable("T_MCWIRE_LEC")] + public class MultiCoreWireLecDBModel + { + /* + * 应用场景 类型 线径规格(mm2) 是否高柔 线芯数 线材型号规格 插头型号 前端子型号 后端子型号 + */ + public string Id { get; set; } + public string UniqueKey { get; set; } + public string ProjectName { get; set; } + public string UserId { get; set; } + + public int SeqNo { get; set; } + + + /// + /// 应用场景 + /// + public string ApplicationScenario { get; set; } + + + /// + /// 线径规格(mm2) + /// + public string WireDiameterSpecification { get; set; } + + + + /// + /// 是否高柔 + /// + public string IsHighFlexibilityStr { get; set; } + + /// + /// 线芯数 + /// + public string WireCoreCount { get; set; } + + /// + /// 线材型号规格 + /// + public string WireModelSpecification { get; set; } + /// + /// 前连接 + /// + public string FrontConnectorModel { get; set; } + + /// + /// 后连接 + /// + public string BackConnectorModel { get; set; } + + /// + /// 是否已布线 + /// + public bool Layouted { get; set; } = false; + } +} diff --git a/Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj b/Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj index 0b43136..de6c2c4 100644 --- a/Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj +++ b/Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj @@ -73,6 +73,7 @@ + diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Converter/WireColorConverter.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Converter/WireColorConverter.cs new file mode 100644 index 0000000..3d8f45f --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Converter/WireColorConverter.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Converter +{ + public class WireColorConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length < 2 || values[0] == null || values[1] == null) + return Brushes.Transparent; + + string primaryColor = values[0].ToString(); + string secondaryColor = values[1].ToString(); + bool isMultiColor = false; + + if (values.Length > 2 && values[2] is bool v) + isMultiColor = v; + + if (!isMultiColor || string.IsNullOrEmpty(secondaryColor)) + return new SolidColorBrush((Color)ColorConverter.ConvertFromString(primaryColor)); + + // 创建线性渐变刷 + LinearGradientBrush gradientBrush = new LinearGradientBrush(); + gradientBrush.StartPoint = new System.Windows.Point(0, 0); + gradientBrush.EndPoint = new System.Windows.Point(1, 0); + + gradientBrush.GradientStops.Add( + new GradientStop((Color)ColorConverter.ConvertFromString(primaryColor), 0.0)); + gradientBrush.GradientStops.Add( + new GradientStop((Color)ColorConverter.ConvertFromString(secondaryColor), 1.0)); + + return gradientBrush; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/MultiCoreWire/MultiCoreWireLecModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/MultiCoreWire/MultiCoreWireLecModel.cs index 1502878..ec59cd1 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Models/MultiCoreWire/MultiCoreWireLecModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/MultiCoreWire/MultiCoreWireLecModel.cs @@ -14,8 +14,14 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models /* * 应用场景 类型 线径规格(mm2) 是否高柔 线芯数 线材型号规格 插头型号 前端子型号 后端子型号 */ + public string Id { get; set; } + public string UniqueKey { get; set; } + public string ProjectName { get; set; } + public string UserId { get; set; } + private int _seqNo; + [ExcelColumn(Ignore = true)] public int SeqNo { get => _seqNo; @@ -44,17 +50,17 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models /// /// 线材类型 /// - private string _wireType; - [ExcelColumn(Ignore = true)] - public string WireType - { - get => _wireType; - set - { - _wireType = value; - OnPropertyChanged(nameof(WireType)); - } - } + //private string _wireType; + //[ExcelColumn(Ignore = true)] + //public string WireType + //{ + // get => _wireType; + // set + // { + // _wireType = value; + // OnPropertyChanged(nameof(WireType)); + // } + //} /// /// 线径规格(mm2) diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Service/MotorLectotypeService.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Service/MotorLectotypeService.cs index 2bda638..cfd7145 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Service/MotorLectotypeService.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Service/MotorLectotypeService.cs @@ -88,9 +88,10 @@ namespace Sinvo.EplanHpD.Plugin.Service // 查询关联的 LectotypeLine 数据 var selectedLines = DBHelper.DB.Queryable() - .Where(ll => ll.CableLectotypeId == cableLectotype.CableLectotypeId) - //.OrderBy(ll => ll.SeqNo) + .Where(line => line.CableLectotypeId == cableLectotype.CableLectotypeId) .ToList(); + //.OrderBy(ll => ll.SeqNo) + // 构建 CableLectotypeViewModel var viewModel = new CableLectotypeViewModel diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Service/MultiCoreWireService.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Service/MultiCoreWireService.cs new file mode 100644 index 0000000..8cfe7de --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Service/MultiCoreWireService.cs @@ -0,0 +1,100 @@ +using Newtonsoft.Json.Bson; +using Sinvo.EplanHpD.Plugin.Service; +using Sinvo.EplanHpD.Plugin.Service.Model; +using Sinvo.EplanHpD.Plugin.WPFUI.Models.MultiCoreWire; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Shapes; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Service +{ + public class MultiCoreWireService + { + public IEnumerable GetByUniqueKey(string uniqueKey) + { + + if (string.IsNullOrEmpty(uniqueKey)) + { + return []; + } + var db = DBHelper.DB; + try + { + var result = db.Queryable() + .Where(it => it.UniqueKey == uniqueKey) + .ToList(); + return result; + } + catch (Exception) + { + throw; + } + } + + // 保存 + public void SaveData(MultiCoreWireLecDBModel line) + { + if (string.IsNullOrEmpty(line.UniqueKey) + || string.IsNullOrEmpty(line.UserId) + || string.IsNullOrEmpty(line.ProjectName)) + { + return; + } + var db = DBHelper.DB; + try + { + db.BeginTran(); + db.Insertable(line).ExecuteCommand(); + db.CommitTran(); + } + catch (Exception) + { + db.RollbackTran(); + throw; + } + } + + internal void ClearSelf(string uniqueKey) + { + if (string.IsNullOrEmpty(uniqueKey)) + { + return; + } + var db = DBHelper.DB; + try + { + db.BeginTran(); + db.Deleteable().Where(it => it.UniqueKey == uniqueKey).ExecuteCommand(); + db.CommitTran(); + } + catch (Exception) + { + db.RollbackTran(); + throw; + } + } + + internal void DeleteById(string id) + { + if (string.IsNullOrEmpty(id)) + { + return; + } + var db = DBHelper.DB; + try + { + db.BeginTran(); + db.Deleteable().Where(it => it.Id == id).ExecuteCommand(); + db.CommitTran(); + } + catch (Exception) + { + db.RollbackTran(); + throw; + } + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj index 41342f4..b7d1bb5 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj @@ -242,6 +242,7 @@ + @@ -273,6 +274,7 @@ + TestWindow.xaml @@ -289,6 +291,7 @@ + diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs index dd0c145..0675864 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs @@ -40,6 +40,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils /// public static readonly Regex dRegex = new("V-[\\d]+\\.?[\\d]*", RegexOptions.Compiled); /// + /// 线径大小匹配(伺服电机线材选型) + /// + public static readonly Regex InsulationRegex = new("(?:[T]{0,}RVV\\d×)(\\d\\.{0,}\\d+)(?:-2000W)?(-CE)?", RegexOptions.Compiled); + /// /// 括号内容匹配 /// public static readonly Regex regexParenthesesContent = new(@"(?<=\()[^)]*(?=\))", RegexOptions.Compiled); diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ExcelHelper.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ExcelHelper.cs index 4332427..0253982 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ExcelHelper.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ExcelHelper.cs @@ -9,6 +9,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils { public class ExcelHelper { + private static IEnumerable _insulations; + private static IEnumerable _terminalMappingCache = []; /// /// 线材端子对照表 @@ -54,8 +56,16 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils /// public static IEnumerable GetInsulationSoftSleeveTable(string wireModel) { + if(_insulations != null) + { + return _insulations.Where(item => item.Specification == wireModel); + } var path = Path.Combine(Consts.DATA_FILE_PATH, Consts.DATA_FILE_PATH_INSULATION); var results = MiniExcel.Query(path); + if(_insulations == null) + { + _insulations = results; + } //.Where(item => item.Specification == wireModel) //.ToList(); return results.Where(item => item.Specification == wireModel); diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs index 1709c68..39dcf73 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.Service; +using EPLAN.Harness.ProjectCore; +using Sinvo.EplanHpD.Plugin.Service; using Sinvo.EplanHpD.Plugin.WPFUI.Extension; using Sinvo.EplanHpD.Plugin.WPFUI.Models; using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; @@ -27,7 +28,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils /// /// /// - public static async Task CreateOrGetAsync(MotorModel motor) + public static CableLectotypeViewModel CreateOrGetAsync(MotorModel motor) { if (motor == null || string.IsNullOrEmpty(motor.AxisNo)) { @@ -37,7 +38,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils } CableLectotypeViewModel viewModel = null; - await Task.Factory.StartNew(() => + Task.Factory.StartNew(() => { var service = new MotorLectotypeService(); var data = service.GetMotorLectotypeData(motor.GetUniqueFlag()); @@ -55,7 +56,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils } } - }); + }).Wait(); if (viewModel == null) { return new CableLectotypeViewModel(motor); @@ -67,5 +68,17 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils } } + public static string GetDocName(FlexDesigner designer) + { + var docName = designer.Name; + if (docName.Contains("+")) + { + return docName.Split('+').FirstOrDefault(); + } + else + { + return docName; + } + } } } \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs index a8e5b5c..f13e3e5 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs @@ -138,6 +138,9 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils line.CableType, line.AxisNo, line.DrawingNo, + line.InsulationMCode, + line.InsulationModel, + line.InsulationCount, EncoderLineLength = line.EncoderLineLength == 0 ? "" : line.EncoderLineLength.ToString(), PowerLineLength = line.PowerLineLength == 0 ? "" : line.PowerLineLength.ToString(), OrderDate = DateTime.Now.ToString("yyyy/M/d"), diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml.cs index b873e1d..7fb6896 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml.cs @@ -1,6 +1,7 @@ using EPLAN.Harness.Core.Settings; using Newtonsoft.Json; using Sinvo.EplanHpD.Plugin.Service; +using Sinvo.EplanHpD.Plugin.Service.Model; using Sinvo.EplanHpD.Plugin.WPFUI.Models; using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; using System.Threading.Tasks; @@ -110,7 +111,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View var result = viewModel.Login(); if(result != null && !string.IsNullOrEmpty(result.GUID)) { - PluginServices.user = new Service.Model.UserInfo + PluginServices.user = new UserInfo { Group = viewModel.User.UserGroup, Role = viewModel.User.UserRole, diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/LayoutHelper/MultiCoreWireLayoutHelperWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/LayoutHelper/MultiCoreWireLayoutHelperWindow.xaml index 2b8e323..1045605 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/LayoutHelper/MultiCoreWireLayoutHelperWindow.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/LayoutHelper/MultiCoreWireLayoutHelperWindow.xaml @@ -7,11 +7,13 @@ xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View.MultiCoreWire.LayoutHelper" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:multicorewireviewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel" Title="布线助手" Width="450" Height="260" MinWidth="450" MinHeight="260" + d:DataContext="{d:DesignInstance Type=multicorewireviewmodel:MultiCoreWireLayoutHelperViewModel}" ActiveGlowColor="{DynamicResource PrimaryColor}" Background="White" FontSize="14" @@ -47,11 +49,17 @@ Text="触摸屏" /> - + - - + + public partial class MultiCoreWireLayoutHelperWindow : GlowWindow { - public MultiCoreWireLayoutHelperWindow() + private readonly string _uniqueKey = ""; + public MultiCoreWireLayoutHelperViewModel ViewModel; + public MultiCoreWireLayoutHelperWindow(string uniqueKey) { InitializeComponent(); + _uniqueKey = uniqueKey; + this.DataContext = ViewModel = new MultiCoreWireLayoutHelperViewModel(uniqueKey); } private void GlowWindow_Loaded(object sender, RoutedEventArgs e) { } + + private void NextBtn_Click(object sender, RoutedEventArgs e) + { + + } + + private void PrevBtn_Click(object sender, RoutedEventArgs e) + { + + } } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/MultiCoreWireWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/MultiCoreWireWindow.xaml index e466999..c5631f0 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/MultiCoreWireWindow.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/MultiCoreWireWindow.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View" + xmlns:localconverter="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.Converter" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:multicorewireviewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel" Title="多芯线数据抓取" @@ -304,7 +305,7 @@ Click="DeleteItemBtn_Click" Content="删除" Style="{StaticResource ButtonDanger}" - Tag="{Binding SeqNo}" /> + Tag="{Binding Id}" /> @@ -357,7 +358,32 @@ Text="{Binding WireModelSpecification}" /> - + + + + + + + + + + + + + diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/MultiCoreWireWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/MultiCoreWireWindow.xaml.cs index 953b938..58f600f 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/MultiCoreWireWindow.xaml.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/MultiCoreWire/MultiCoreWireWindow.xaml.cs @@ -1,5 +1,6 @@ using Sinvo.EplanHpD.Plugin.WPFUI.Models; using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel; +using SqlSugar.Extensions; using System.Windows; using System.Windows.Controls; @@ -19,6 +20,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View private void Window_Loaded(object sender, RoutedEventArgs e) { + viewModel.Init(); viewModel.LoadWiresData(); } @@ -42,10 +44,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View { if(sender is Button btn) { - int? seqNo = (int)btn.Tag; - if(seqNo != null) + string id = (string)btn.Tag; + if(id != null) { - viewModel.DeleteLecWireItem(seqNo); + viewModel.DeleteLecWireItem(id); } } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MultiCoreWireViewModel/MultiCoreWireLayoutHelperViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MultiCoreWireViewModel/MultiCoreWireLayoutHelperViewModel.cs new file mode 100644 index 0000000..bfe7b1c --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MultiCoreWireViewModel/MultiCoreWireLayoutHelperViewModel.cs @@ -0,0 +1,46 @@ +using Sinvo.EplanHpD.Plugin.Service.Model; +using Sinvo.EplanHpD.Plugin.WPFUI.Models; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel +{ + public class MultiCoreWireLayoutHelperViewModel : INotifyPropertyChanged + { + + private string _uniqueKey; + + + public event PropertyChangedEventHandler PropertyChanged; + public void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + public MultiCoreWireLayoutHelperViewModel(string uniqueKey) + { + _uniqueKey = uniqueKey; + } + + + #region Props + + private ObservableCollection _lecWires = []; + + public ObservableCollection LecWires + { + get { return _lecWires; } + set + { + _lecWires = value; + OnPropertyChanged(nameof(LecWires)); + } + } + #endregion + + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MultiCoreWireViewModel/MultiCoreWireViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MultiCoreWireViewModel/MultiCoreWireViewModel.cs index 1469f74..5b41f8c 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MultiCoreWireViewModel/MultiCoreWireViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MultiCoreWireViewModel/MultiCoreWireViewModel.cs @@ -3,9 +3,13 @@ using EPLAN.Harness.Core.Appearance; using EPLAN.Harness.Core.Utils; using EPLAN.Harness.ProjectCore; using EPLAN.Harness.ProjectCore.Occurrences.Designer; +using HandyControl.Controls; using MiniExcelLibs.Attributes; +using Sinvo.EplanHpD.Plugin.Service; +using Sinvo.EplanHpD.Plugin.Service.Model; using Sinvo.EplanHpD.Plugin.WPFUI.Models; using Sinvo.EplanHpD.Plugin.WPFUI.Models.MultiCoreWire; +using Sinvo.EplanHpD.Plugin.WPFUI.Service; using Sinvo.EplanHpD.Plugin.WPFUI.Utils; using SqlSugar; using System; @@ -15,6 +19,7 @@ using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; +using System.Windows; using System.Windows.Forms; namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel @@ -23,6 +28,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel { public string _docId = docId; private readonly MultiCoreWireExcelHelper _dataHelper = MultiCoreWireExcelHelper.Instance; + private readonly MultiCoreWireService _service = new(); + private string CurrUniqueKey = ""; #region Props private ObservableCollection _wires = []; @@ -207,19 +214,19 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel OnPropertyChanged(nameof(ApplicationScenarios)); } } - private List _wireTypes; - /// - /// 线材类型 - /// - public List WireTypes - { - get => _wireTypes; - set - { - _wireTypes = value; - OnPropertyChanged(nameof(WireTypes)); - } - } + //private List _wireTypes; + ///// + ///// 线材类型 + ///// + //public List WireTypes + //{ + // get => _wireTypes; + // set + // { + // _wireTypes = value; + // OnPropertyChanged(nameof(WireTypes)); + // } + //} private List _wireDiameterSpecifications; /// /// 线径规格 @@ -404,6 +411,45 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel _datas = _dataHelper.GetMultiCoreWireLecDatas(); SetDatas(_datas); + try + { + + var wiresData = _service.GetByUniqueKey(CurrUniqueKey); + if (wiresData != null) + { + wiresData.ForEach(wire => + { + LecWires.Add(new MultiCoreWireLecModel + { + Id = wire.Id, + SeqNo = wire.SeqNo, + ApplicationScenario = wire.ApplicationScenario, + WireDiameterSpecification = wire.WireDiameterSpecification, + IsHighFlexibilityStr = wire.IsHighFlexibilityStr, + WireCoreCount = wire.WireCoreCount, + WireModelSpecification = wire.WireModelSpecification, + FrontConnectorModel = wire.FrontConnectorModel, + BackConnectorModel = wire.BackConnectorModel, + UserId = wire.UserId, + ProjectName = wire.ProjectName, + UniqueKey = wire.UniqueKey + }); + }); + } + } + catch (Exception) + { + HandyControl.Controls.MessageBox.Error("加载历史数据失败"); + } + } + + public void Init() + { + + var des = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(it => it.ID == _docId) ?? throw new Exception("设计器不存在"); + LectotypeManager.CURRENT_DOC_NAME = LectotypeManager.GetDocName(des); + + CurrUniqueKey = $"{LectotypeManager.CURRENT_DOC_NAME}_{PluginServices.user.ID}"; } private bool LecChanging = false; public void OnLecChanged(string propName) @@ -418,7 +464,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel // 线径规格 .WhereIF(!string.IsNullOrEmpty(WireDiameterSpecification), it => it.WireDiameterSpecification == WireDiameterSpecification) // 是否高柔 - .WhereIF(!string.IsNullOrEmpty(HighFlexibility),it => it.IsHighFlexibilityStr == HighFlexibility) + .WhereIF(!string.IsNullOrEmpty(HighFlexibility), it => it.IsHighFlexibilityStr == HighFlexibility) // 型号 .WhereIF(!string.IsNullOrEmpty(WireModelSpecification), it => it.WireModelSpecification == WireModelSpecification) // 线芯数 @@ -427,7 +473,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel SetDatas(canUsedDatas, propName); } - private void SetDatas(IEnumerable datas,string propName = "") + private void SetDatas(IEnumerable datas, string propName = "") { if (datas != null) { @@ -437,7 +483,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel //{ // ApplicationScenario = ApplicationScenarios.FirstOrDefault(); //} - WireTypes = [.. datas.Where(it => !string.IsNullOrEmpty(it.WireType)).Select(it => it.WireType).Distinct(), ""]; + //WireTypes = [.. datas.Where(it => !string.IsNullOrEmpty(it.WireType)).Select(it => it.WireType).Distinct(), ""]; //if (WireTypes.Where(it => !string.IsNullOrEmpty(it)).Count() == 1 && propName != nameof(WireType)) //{ // WireType = WireTypes.FirstOrDefault(); @@ -489,7 +535,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel { c.Children.Where(ccc => ccc is OccWire).ForEach(cc => { - if(cc is OccWire wire) + if (cc is OccWire wire) { //var color = materials.Where(col => col == wire.Color) //Debug.WriteLine($"\t\t{wire.Name} - {wire.LibraryName} - {FlexColors.GetName(wire.Color.Major)}"); @@ -511,7 +557,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel Wires?.Add(wireData); }); return Task.CompletedTask; - } + } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propertyName) { @@ -536,62 +582,111 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel public void SaveLecToLine() { - if(ApplicationScenario == null - || WireType == null - || WireDiameterSpecification == null - || HighFlexibility == null - || WireCoreCount == null - || WireModelSpecification == null) + if (ApplicationScenario == null + || WireDiameterSpecification == null + || HighFlexibility == null + || WireCoreCount == null + || WireModelSpecification == null + || FrontConnectorModel == null + || BackConnectorModel == null) { - MessageBox.Show("有信息未选择!"); + HandyControl.Controls.MessageBox.Show("有信息未选择!",caption: "提示",icon: MessageBoxImage.Warning); return; } - var wire = new MultiCoreWireLecModel + //if(LecWires.Any(it=> it.ApplicationScenario == ApplicationScenario && it.WireModelSpecification == WireModelSpecification)) + //{ + // MessageBox.Show("已选择相同的线!"); + // return; + //} + + try { - SeqNo = LecWires.Count + 1, - ApplicationScenario = ApplicationScenario, - WireType = WireType, - WireDiameterSpecification = WireDiameterSpecification, - IsHighFlexibility = HighFlexibility == "是", - IsHighFlexibilityStr = HighFlexibility, - WireCoreCount = WireCoreCount, - WireModelSpecification = WireModelSpecification, - FrontConnectorModel = FrontConnectorModel, - BackConnectorModel = BackConnectorModel, - }; - LecWires.Add(wire); + var wire = new MultiCoreWireLecModel + { + Id = Guid.NewGuid().ToString(), + SeqNo = LecWires.Count + 1, + ApplicationScenario = ApplicationScenario, + WireDiameterSpecification = WireDiameterSpecification, + IsHighFlexibilityStr = HighFlexibility, + WireCoreCount = WireCoreCount, + WireModelSpecification = WireModelSpecification, + FrontConnectorModel = FrontConnectorModel, + BackConnectorModel = BackConnectorModel, + UserId = PluginServices.user.ID, + ProjectName = LectotypeManager.CURRENT_DOC_NAME, + UniqueKey = $"{LectotypeManager.CURRENT_DOC_NAME}_{PluginServices.user.ID}" + }; + _service.SaveData(new MultiCoreWireLecDBModel + { + Id = wire.Id, + UniqueKey = wire.UniqueKey, + ProjectName = wire.ProjectName, + UserId = wire.UserId, + SeqNo = wire.SeqNo, + ApplicationScenario = wire.ApplicationScenario, + WireDiameterSpecification = wire.WireDiameterSpecification, + IsHighFlexibilityStr = wire.IsHighFlexibilityStr, + WireCoreCount = wire.WireCoreCount, + WireModelSpecification = wire.WireModelSpecification, + FrontConnectorModel = wire.FrontConnectorModel, + BackConnectorModel = wire.BackConnectorModel + }); + LecWires.Add(wire); + } + catch (Exception ex) + { + HandyControl.Controls.MessageBox.Error($"保存数据失败!{ex}"); + } } - + public void ClearLecLines() { - LecWires.Clear(); + try + { + LecWires.Clear(); + _service.ClearSelf(CurrUniqueKey); + } + catch (Exception ex) + { + HandyControl.Controls.MessageBox.Error($"清除数据失败!{ex}"); + } + } - internal void DeleteLecWireItem(int? seqNo) + internal void DeleteLecWireItem(string id) { - if(seqNo != null) + if(id != null) { - var removeItem = LecWires.FirstOrDefault(it => it.SeqNo == seqNo!); + var removeItem = LecWires.FirstOrDefault(it => it.Id == id!); if(removeItem != null) { - LecWires.Remove(removeItem); + try + { + LecWires.Remove(removeItem); + _service.DeleteById(id); + } + catch (Exception ex) + { + HandyControl.Controls.MessageBox.Error($"删除数据失败!{ex}"); + } + } - ReOrderLecWires(); + //ReOrderLecWires(); } } - private void ReOrderLecWires() - { - int seq = 1; - LecWires.OrderBy(it => it.SeqNo).ForEach(it => - { - it.SeqNo = seq; - seq++; - }); - OnPropertyChanged(nameof(LecWires)); - } + //private void ReOrderLecWires() + //{ + // int seq = 1; + // LecWires.OrderBy(it => it.SeqNo).ForEach(it => + // { + // it.SeqNo = seq; + // seq++; + // }); + // OnPropertyChanged(nameof(LecWires)); + //} } } diff --git a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs index 7bf7329..cf770c5 100644 --- a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs +++ b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs @@ -59,39 +59,27 @@ namespace Sinvo.EplanHpD.Plugin public void Execute(HpdApi api) { - bool isLogin = PluginServices.IsLogin; - if (!isLogin) - { - var LoginWindow = new LoginWindow(); - if(LoginWindow.ShowDialog() == true) - { - isLogin = PluginServices.IsLogin; - } - } - if (isLogin) + new DBHelper().CodeFirst(); + var doc = api.CurrentProject.GetActiveDocument(); + if (window == null) { - new DBHelper().CodeFirst(); - var doc = api.CurrentProject.GetActiveDocument(); - if (window == null) + window = new LectotypeWindow(doc.ID); + // 获取版本号并显示到窗口标题 + window.Title += $" V{Version} - {doc.Name}"; + ElementHost.EnableModelessKeyboardInterop(window); + var mainApp = BaseApp.ActiveApplication; + var helper = new System.Windows.Interop.WindowInteropHelper(window); + helper.Owner = mainApp.Handle; + window.Closed += delegate { - window = new LectotypeWindow(doc.ID); - // 获取版本号并显示到窗口标题 - window.Title += $" V{Version} - {doc.Name}"; - ElementHost.EnableModelessKeyboardInterop(window); - var mainApp = BaseApp.ActiveApplication; - var helper = new System.Windows.Interop.WindowInteropHelper(window); - helper.Owner = mainApp.Handle; - window.Closed += delegate - { - window = null; - }; - window.Show(); - } - else - { - window.WindowState = System.Windows.WindowState.Normal; - window.Activate(); - } + window = null; + }; + window.Show(); + } + else + { + window.WindowState = System.Windows.WindowState.Normal; + window.Activate(); } } public void Initialize() diff --git a/Sinvo.EplanHpD.Plugin/PluginEntry.cs b/Sinvo.EplanHpD.Plugin/PluginEntry.cs index ad94036..218fa13 100644 --- a/Sinvo.EplanHpD.Plugin/PluginEntry.cs +++ b/Sinvo.EplanHpD.Plugin/PluginEntry.cs @@ -61,96 +61,83 @@ namespace Sinvo.EplanHpD.Plugin private MainWindow window; public void Execute(HpdApi api) { - //bool isLogin = PluginServices.IsLogin; - //if (!isLogin) - //{ - // var LoginWindow = new LoginWindow(); - // if (LoginWindow.ShowDialog() == true) - // { - // isLogin = PluginServices.IsLogin; - // } - //} - //if (isLogin) - //{ - - bool isUpdated = false; - try + bool isUpdated = false; + try + { + var doc = api.CurrentProject.GetActiveDocument(); + //doc.ID + //if(doc is FlexReport) + if (doc is EPLAN.Harness.API.Projects.Documents.Report report) { - var doc = api.CurrentProject.GetActiveDocument(); - //doc.ID - //if(doc is FlexReport) - if (doc is EPLAN.Harness.API.Projects.Documents.Report report) + var reportId = report.ID; + var allReports = FlexProject.CurrentProject.GetReports(); + if (allReports.Any(item => item.ID == reportId)) { - var reportId = report.ID; - var allReports = FlexProject.CurrentProject.GetReports(); - if (allReports.Any(item => item.ID == reportId)) + var flexReport = allReports.Where(item => item.ID == reportId).First(); + if (flexReport != null) { - var flexReport = allReports.Where(item => item.ID == reportId).First(); - if (flexReport != null) + var isNeedUpdate = FlexReport.IsUpToDate(flexReport); + if (!isNeedUpdate) { - var isNeedUpdate = FlexReport.IsUpToDate(flexReport); - if (!isNeedUpdate) + if (FlexMessageBox.Warning(FlexMessageBox.Buttons.OK_CANCEL, + "Report", + "报表数据不是最新的,是否更新?", false) == DialogResult.OK) { - if (FlexMessageBox.Warning(FlexMessageBox.Buttons.OK_CANCEL, - "Report", - "报表数据不是最新的,是否更新?", false) == DialogResult.OK) - { - flexReport.UpdateReport(); - isUpdated = true; - } + flexReport.UpdateReport(); + isUpdated = true; } - try + } + try + { + + if (window == null) { - if (window == null) + window = new MainWindow(flexReport); + ElementHost.EnableModelessKeyboardInterop(window); + window.Show(); + } + else + { + if (isUpdated) { - + window.Close(); window = new MainWindow(flexReport); ElementHost.EnableModelessKeyboardInterop(window); window.Show(); } - else + window.ShowActivated = true; + if (window.WindowState == System.Windows.WindowState.Minimized) { - if (isUpdated) - { - window.Close(); - window = new MainWindow(flexReport); - ElementHost.EnableModelessKeyboardInterop(window); - window.Show(); - } - window.ShowActivated = true; - if (window.WindowState == System.Windows.WindowState.Minimized) - { - window.WindowState = System.Windows.WindowState.Normal; - } - window.Show(); - window.Activate(); + window.WindowState = System.Windows.WindowState.Normal; } - } - catch (Exception) - { - window = new MainWindow(flexReport); - // 解决WPF窗体在WinForm中无法输入的问题 - ElementHost.EnableModelessKeyboardInterop(window); window.Show(); + window.Activate(); } } - } - else - { - FlexMessageBox.Error("未找到项目中匹配的报表,请检查是否生成成功或是未保存到项目中!"); + catch (Exception) + { + window = new MainWindow(flexReport); + // 解决WPF窗体在WinForm中无法输入的问题 + ElementHost.EnableModelessKeyboardInterop(window); + window.Show(); + } } } else { - FlexMessageBox.Error("请打开一个报表后再使用!"); + FlexMessageBox.Error("未找到项目中匹配的报表,请检查是否生成成功或是未保存到项目中!"); } } - catch (Exception ex) + else { - FlexMessageBox.Error(ex.ToString()); + FlexMessageBox.Error("请打开一个报表后再使用!"); } - //} + } + catch (Exception ex) + { + FlexMessageBox.Error(ex.ToString()); + } } public void Initialize()