From 4b2f449a97645fd36f13f2ffa506162bab2f5a9e Mon Sep 17 00:00:00 2001 From: lihanbo Date: Mon, 23 Dec 2024 12:05:05 +0800 Subject: [PATCH] =?UTF-8?q?105040=20Update=20=E4=B8=8D=E5=86=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8json=E8=BD=AC=E6=8D=A2=EF=BC=9B=E5=A2=9E=E5=8A=A0DEBUG?= =?UTF-8?q?=E6=A0=87=E8=AE=B0=E5=88=A4=E6=96=AD=EF=BC=8C=E6=96=B9=E4=BE=BF?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModel/LayoutHelperViewModel.cs | 82 ++++++++----------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs index e42ef07..d518298 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs @@ -8,6 +8,7 @@ using EPLAN.Harness.Core.Props; using EPLAN.Harness.ProjectCore; using EPLAN.Harness.ProjectCore.Occurrences.Designer; using Sinvo.EplanHpD.Plugin.Service; +using Sinvo.EplanHpD.Plugin.Service.Model; using Sinvo.EplanHpD.Plugin.WPFUI.Models; using System; using System.Collections.Generic; @@ -15,6 +16,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; +using System.Runtime.Remoting.Contexts; using System.Security; using System.Text; using System.Threading.Tasks; @@ -70,8 +72,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel { try { - - if (_selectLineId == null) return ""; var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId); if (part != null) @@ -115,7 +115,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel { return false; } - } set { @@ -185,22 +184,18 @@ 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) { + CheckSelLine(slient: true); _selectLineId = item.ID; OnPropertyChanged(nameof(SelectLineName)); } } } - private bool IsCable(BaseOccurrence occ) - { - return occ is OccCableForked; - } - - public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged([CallerMemberName] string propertyName = null) { @@ -211,14 +206,14 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel { if (_motorIds != null && _motorIds.Any()) { - + Task.Factory.StartNew(() => { var service = new MotorLectotypeService(); var data = service.GetMotorLectotypeData(_motorIds[CurrentMotorIndex]); - if (!string.IsNullOrEmpty(data)) + if (data != null) { - cableLectotypeViewModel = Newtonsoft.Json.JsonConvert.DeserializeObject(data); + cableLectotypeViewModel = data; if (cableLectotypeViewModel?.SelectedLines?.Any() ?? false) { SelectedLines = cableLectotypeViewModel.SelectedLines; @@ -285,7 +280,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel } } - private bool CheckSelLine() + private bool CheckSelLine(bool slient = false) { try { @@ -300,7 +295,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel : part is OccCablesInsulatorGraph ? part : part.Parents?.FirstOrDefault() as OccCableForked; - if (linePart != null) { var libName = linePart?.LibraryName; @@ -327,37 +321,53 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel } if (string.IsNullOrEmpty(imprint)) { - FlexMessageBox.Warning($"当前选中的线 {libName} 印记未填写"); +#if DEBUG + return true; +#else + if(!slient) + FlexMessageBox.Warning($"当前选中的线 {libName} 印记未填写"); return false; +#endif } if ($"{SelectedLine.AxisNo}-{SelectedLine.CurrentLine}" == imprint) { subLine.IsChecked = true; //cableLectotypeViewModel.SaveToDb(); - SetSubLineAndSave(subLine.CableModel); + SetSubLineAndSave(subLine.CableLectotypeId); return SubLines.All(it => it.IsChecked); } else - { - FlexMessageBox.Warning($"当前选中的线 {libName} 印记与推荐中的线印记不一致"); + { +#if DEBUG + return true; +#else + if(!slient) + FlexMessageBox.Warning($"当前选中的线 {libName} 印记与推荐中的线印记不一致"); return false; +#endif } } } } - FlexMessageBox.Warning($"当前选中的线不是推荐中的线型号"); +#if DEBUG + return true; +#else + if(!slient) + FlexMessageBox.Warning($"当前选中的线不是推荐中的线型号"); return false; +#endif } } catch (Exception) { - FlexMessageBox.Warning("抓取线信息异常"); + if(!slient) + FlexMessageBox.Warning("抓取线信息异常"); return false; } - FlexMessageBox.Warning("请选择正确的线"); + if (!slient) + FlexMessageBox.Warning("请选择正确的线"); return false; } - internal void ToPrevMotor() { if (CurrentMotorIndex > 0) @@ -380,33 +390,9 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel { SubLines = SelectedLine.SubLines.Distinct(it => it.CableModel).ToList(); } - - internal void SetSubLineAndSave(string cableModel) + internal void SetSubLineAndSave(string cableLectotypeId) { - foreach (var it in cableLectotypeViewModel.SelectedLines) - { - if (it.AxisNo == SelectedLine.AxisNo && it.CurrentLine == SelectedLine.CurrentLine) - { - foreach (var line in it.SubLines) - { - if (cableModel == line.CableModel) - { - line.IsChecked = true; - } - } - } - } - SaveToDb(cableLectotypeViewModel); - } - - public bool SaveToDb(CableLectotypeViewModel cableLectotypeViewModel) - { - var id = cableLectotypeViewModel.Motor.OccPartId; - var json = Newtonsoft.Json.JsonConvert.SerializeObject(cableLectotypeViewModel); - var service = new MotorLectotypeService(); - return service.SaveMotorLectotypeData(id, json); + } } - - }