From 98df216faec7c947877c33a35d740b51a820243e Mon Sep 17 00:00:00 2001 From: lihanbo Date: Wed, 22 Jan 2025 16:45:50 +0800 Subject: [PATCH] =?UTF-8?q?105040=20Update=20=E4=B8=8D=E5=86=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8Eplan=E5=86=85=E9=83=A8=E7=9A=84=E9=9B=B6=E4=BB=B6ID?= =?UTF-8?q?=EF=BC=8C=E6=94=B9=E4=B8=BA=E4=BD=BF=E7=94=A8=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E7=9A=84=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= =?UTF-8?q?+=E8=BD=B4=E5=8F=B7=E4=BD=9C=E4=B8=BA=E7=94=B5=E6=9C=BA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BF=9D=E5=AD=98=E7=9A=84=E5=94=AF=E4=B8=80?= =?UTF-8?q?=E6=A0=87=E8=AF=86=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加电机唯一标识及相关属性和方法 在多个文件中添加了 `MotorUniqueFlag` 属性,并将其设置为可为空。在 `MotorModel.cs` 文件中还添加了 `DocName` 属性。新增了 `GetUniqueFlag` 扩展方法,用于生成电机的唯一标识,并在相关文件中使用该方法。修改了界面显示和方法参数,将“电机ID”替换为“电机唯一标识”。在 `LectotypeManager.cs` 文件中添加了 `CURRENT_DOC_NAME` 和 `CURRENT_DOC_CREATE_TIME` 静态字段。 --- .../Model/CableLectotype.cs | 2 + .../Model/LectotypeLine.cs | 2 + .../Model/MotorModel.cs | 5 +++ .../Extension/MotorModelUniqueFlagExt.cs | 19 ++++++++ .../Models/MotorModel.cs | 16 ++++++- .../Service/MotorLectotypeService.cs | 43 +++++++++++-------- .../Utils/LectotypeManager.cs | 9 ++-- .../View/CableLectotypeUserControl.xaml | 42 ++++++++---------- .../View/LayoutHelperWindow.xaml.cs | 4 +- .../View/LectotypeWindow.xaml.cs | 4 +- .../ViewModel/CableLectotypeViewModel.cs | 6 ++- .../ViewModel/LayoutHelperViewModel.cs | 18 ++++---- .../ViewModel/LectotypeViewModel.cs | 16 ++++++- 13 files changed, 123 insertions(+), 63 deletions(-) create mode 100644 Sinvo.EplanHpD.Plugin.WPFUI/Extension/MotorModelUniqueFlagExt.cs diff --git a/Sinvo.EplanHpD.Plugin.Service/Model/CableLectotype.cs b/Sinvo.EplanHpD.Plugin.Service/Model/CableLectotype.cs index f73940f..e014352 100644 --- a/Sinvo.EplanHpD.Plugin.Service/Model/CableLectotype.cs +++ b/Sinvo.EplanHpD.Plugin.Service/Model/CableLectotype.cs @@ -16,6 +16,8 @@ namespace Sinvo.EplanHpD.Plugin.Service.Model [SugarColumn(IsNullable = true)] public string MotorId { get; set; } + [SugarColumn(IsNullable = true)] + public string MotorUniqueFlag { get; set; } [SugarColumn(IsNullable = true)] public int CableConnectionType { get; set; } diff --git a/Sinvo.EplanHpD.Plugin.Service/Model/LectotypeLine.cs b/Sinvo.EplanHpD.Plugin.Service/Model/LectotypeLine.cs index 3510fc4..b5808c1 100644 --- a/Sinvo.EplanHpD.Plugin.Service/Model/LectotypeLine.cs +++ b/Sinvo.EplanHpD.Plugin.Service/Model/LectotypeLine.cs @@ -15,6 +15,8 @@ namespace Sinvo.EplanHpD.Plugin.Service.Model public string ParentLectotypeLineId { get; set; } public string MotorId { get; set; } + [SugarColumn(IsNullable = true)] + public string MotorUniqueFlag { get; set; } public int SeqNo { get; set; } [SugarColumn(IsNullable = true)] diff --git a/Sinvo.EplanHpD.Plugin.Service/Model/MotorModel.cs b/Sinvo.EplanHpD.Plugin.Service/Model/MotorModel.cs index 6e80ec5..8b5b348 100644 --- a/Sinvo.EplanHpD.Plugin.Service/Model/MotorModel.cs +++ b/Sinvo.EplanHpD.Plugin.Service/Model/MotorModel.cs @@ -14,7 +14,12 @@ namespace Sinvo.EplanHpD.Plugin.Service.Model //public string MotorId { get; set; } [SugarColumn(IsPrimaryKey = true)] public string OccPartId { get; set; } + + [SugarColumn(IsNullable = true)] + public string MotorUniqueFlag { get; set; } + [SugarColumn(IsNullable = true)] + public string DocName { get; set; } public string MotorPower { get; set; } [SugarColumn(IsNullable = true)] diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Extension/MotorModelUniqueFlagExt.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Extension/MotorModelUniqueFlagExt.cs new file mode 100644 index 0000000..361a251 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Extension/MotorModelUniqueFlagExt.cs @@ -0,0 +1,19 @@ +using Sinvo.EplanHpD.Plugin.WPFUI.Models; +using Sinvo.EplanHpD.Plugin.WPFUI.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Extension +{ + public static class MotorModelUniqueFlagExt + { + public static string GetUniqueFlag(this MotorModel model) + { + // 调整唯一标识生成规则,项目名称+轴号 + return $"{LectotypeManager.CURRENT_DOC_CREATE_TIME}_{model.AxisNo}"; + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs index 9204519..5dee40f 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs @@ -1,4 +1,6 @@ -namespace Sinvo.EplanHpD.Plugin.WPFUI.Models +using Sinvo.EplanHpD.Plugin.WPFUI.Extension; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Models { public class MotorModel : CheckedModel { @@ -95,5 +97,17 @@ OnPropertyChanged(nameof(OccPartId)); } } + + /// + /// 部件ID + /// + public string MotorUniqueFlag + { + get => this.GetUniqueFlag(); + set + { + OnPropertyChanged(nameof(MotorUniqueFlag)); + } + } } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Service/MotorLectotypeService.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Service/MotorLectotypeService.cs index 7e016d1..455b1c5 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Service/MotorLectotypeService.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Service/MotorLectotypeService.cs @@ -1,6 +1,7 @@ using Sinvo.EplanHpD.Plugin.Service.Model; using Sinvo.EplanHpD.Plugin.WPFUI.Enum; using Sinvo.EplanHpD.Plugin.WPFUI.Models; +using Sinvo.EplanHpD.Plugin.WPFUI.Utils; using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; using System; using System.Collections.Generic; @@ -17,10 +18,10 @@ namespace Sinvo.EplanHpD.Plugin.Service DBHelper.DB.Insertable(motor).ExecuteCommand(); } - public Motor GetMotorById(string occPartId) + public Motor GetMotorByFlag(string motorUniqueFlag) { var data = DBHelper.DB.Queryable("mt") - .Where(mt => mt.OccPartId == occPartId) + .Where(mt => mt.MotorUniqueFlag == motorUniqueFlag) .First(); return data; } @@ -40,11 +41,11 @@ namespace Sinvo.EplanHpD.Plugin.Service // } //} - public CableLectotypeViewModel GetMotorLectotypeData(string motorOccId) + public CableLectotypeViewModel GetMotorLectotypeData(string motorUniqueFlag) { // 查询 Motor 数据 var motor = DBHelper.DB.Queryable() - .Where(m => m.OccPartId == motorOccId) + .Where(m => m.MotorUniqueFlag == motorUniqueFlag) .First(); if (motor == null) @@ -54,7 +55,7 @@ namespace Sinvo.EplanHpD.Plugin.Service // 查询关联的 CableLectotype 数据 var cableLectotype = DBHelper.DB.Queryable() - .Where(cl => cl.MotorId == motor.OccPartId) + .Where(cl => cl.MotorUniqueFlag == motor.MotorUniqueFlag) .First(); if (cableLectotype == null) @@ -78,7 +79,8 @@ namespace Sinvo.EplanHpD.Plugin.Service MotorSerie = motor.MotorSerie, MotorModelStr = motor.MotorModelStr, AxisNo = motor.AxisNo, - OccPartId = motor.OccPartId + MotorUniqueFlag = motor.MotorUniqueFlag, + //OccPartId = motor.OccPartId }, CableConnectionType = (ConnectionType)Enum.Parse(typeof(ConnectionType), cableLectotype.CableConnectionType.ToString()), AxisNo = cableLectotype.AxisNo, @@ -129,34 +131,35 @@ namespace Sinvo.EplanHpD.Plugin.Service }).ToList(); } - public bool ClearSubLines(string motorOccId) - { - var changeCount = DBHelper.DB.Deleteable() - .Where(sl => sl.MotorId == motorOccId) - .ExecuteCommand(); - return changeCount > 0; - } + //public bool ClearSubLines(string motorUniqueFlag) + //{ + // var changeCount = DBHelper.DB.Deleteable() + // .Where(sl => sl.MotorUniqueFlag == motorUniqueFlag) + // .ExecuteCommand(); + // return changeCount > 0; + //} - public bool SaveMotorLectotypeData(string motorOccId, CableLectotypeViewModel data) + public bool SaveMotorLectotypeData(string motorUniqueFlag, CableLectotypeViewModel data) { var db = DBHelper.DB; db.BeginTran(); try { - var motor = GetMotorById(data.Motor.OccPartId);//.FirstOrDefault(m => m.OccPartId == Motor.OccPartId); + var motor = GetMotorByFlag(motorUniqueFlag);//.FirstOrDefault(m => m.OccPartId == Motor.OccPartId); if (motor == null) { motor = new Motor { //MotorId = Guid.NewGuid().ToString(), - //motorOccId + //OccPartId = Guid.NewGuid().ToString(), MotorPower = data.Motor.MotorPower, Brand = data.Motor.Brand, MotorSerie = data.Motor.MotorSerie, MotorModelStr = data.Motor.MotorModelStr, AxisNo = data.Motor.AxisNo, OccPartId = data.Motor.OccPartId, + MotorUniqueFlag = motorUniqueFlag, CableLectotypeLines = [] }; AddMotor(motor); @@ -171,7 +174,7 @@ namespace Sinvo.EplanHpD.Plugin.Service { //Motor = motor, CableLectotypeId = Guid.NewGuid().ToString(), - MotorId = motor.OccPartId, + MotorUniqueFlag = motor.MotorUniqueFlag, CableConnectionType = (int)data.CableConnectionType, AxisNo = data.AxisNo, @@ -190,6 +193,7 @@ namespace Sinvo.EplanHpD.Plugin.Service { CableLectotypeId = cableLectotype.CableLectotypeId, MotorId = motor.OccPartId, + MotorUniqueFlag = motor.MotorUniqueFlag, LectotypeLineId = Guid.NewGuid().ToString(), SeqNo = line.SeqNo, AxisNo = line.AxisNo, @@ -217,6 +221,7 @@ namespace Sinvo.EplanHpD.Plugin.Service { LectotypeLineId = Guid.NewGuid().ToString(), MotorId = motor.OccPartId, + MotorUniqueFlag = motor.MotorUniqueFlag, SeqNo = subLine.SeqNo, ParentLectotypeLineId = lectotypeLine.LectotypeLineId, CableModel = subLine.CableModel, @@ -230,10 +235,10 @@ namespace Sinvo.EplanHpD.Plugin.Service } db.Storageable(motor).ExecuteCommand(); // 清空后再保存 - db.Deleteable().Where(it => it.MotorId == motor.OccPartId).ExecuteCommand(); + db.Deleteable().Where(it => it.MotorUniqueFlag == motor.MotorUniqueFlag).ExecuteCommand(); db.Storageable(cableLectotype).ExecuteCommand(); - db.Deleteable().Where(it => it.MotorId == motor.OccPartId).ExecuteCommand(); + db.Deleteable().Where(it => it.MotorUniqueFlag == motor.MotorUniqueFlag).ExecuteCommand(); db.Storageable(motor.CableLectotypeLines.ToList()).ExecuteCommand(); db.Storageable(motor.CableLectotypeLines.SelectMany(it => it.SubLines).ToList()).ExecuteCommand(); diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs index 04129f8..35946ec 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 Sinvo.EplanHpD.Plugin.WPFUI.Extension; using Sinvo.EplanHpD.Plugin.WPFUI.Models; using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; using System; @@ -15,6 +16,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils public static class LectotypeManager { public static string CURRENT_DOC_ID = ""; + public static string CURRENT_DOC_NAME = ""; + public static string CURRENT_DOC_CREATE_TIME = ""; public class LectotypeViewModelFactory { @@ -22,9 +25,9 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils public static async Task CreateOrGetAsync(MotorModel motor) { - if (motor == null || string.IsNullOrEmpty(motor.OccPartId)) + if (motor == null || string.IsNullOrEmpty(motor.AxisNo)) { - Debug.WriteLine($"CreateOrGet Create for null-> {motor?.MotorModelStr} => {motor?.OccPartId}"); + Debug.WriteLine($"CreateOrGet Create for null-> {motor?.MotorModelStr} => {motor?.AxisNo}"); return new CableLectotypeViewModel(new MotorModel()); } @@ -33,7 +36,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils Task.Factory.StartNew(() => { var service = new MotorLectotypeService(); - var data = service.GetMotorLectotypeData(motor.OccPartId); + var data = service.GetMotorLectotypeData(motor.GetUniqueFlag()); if (data != null) { viewModel = data; diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeUserControl.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeUserControl.xaml index de2b941..5b4a2f0 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeUserControl.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeUserControl.xaml @@ -36,7 +36,6 @@ - @@ -67,12 +66,12 @@ Margin="0,10,0,0" DataContext="{Binding Motor}" Orientation="Horizontal"> - + + Text="{Binding MotorUniqueFlag}" /> @@ -225,7 +225,22 @@ Content="生成线材推荐列表" Style="{StaticResource ButtonPrimary}" /> + + +