105040 Update 不再使用json转换;增加DEBUG标记判断,方便调试

This commit is contained in:
lihanbo 2024-12-23 12:05:05 +08:00
parent 5b11cae2cd
commit 4b2f449a97
1 changed files with 34 additions and 48 deletions

View File

@ -8,6 +8,7 @@ using EPLAN.Harness.Core.Props;
using EPLAN.Harness.ProjectCore; using EPLAN.Harness.ProjectCore;
using EPLAN.Harness.ProjectCore.Occurrences.Designer; using EPLAN.Harness.ProjectCore.Occurrences.Designer;
using Sinvo.EplanHpD.Plugin.Service; using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.Service.Model;
using Sinvo.EplanHpD.Plugin.WPFUI.Models; using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -15,6 +16,7 @@ using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.Remoting.Contexts;
using System.Security; using System.Security;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -70,8 +72,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{ {
try try
{ {
if (_selectLineId == null) return ""; if (_selectLineId == null) return "";
var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId); var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId);
if (part != null) if (part != null)
@ -115,7 +115,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{ {
return false; return false;
} }
} }
set set
{ {
@ -185,22 +184,18 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{ {
SelectMotorModel = part.Parents?.First()?.Name ?? ""; SelectMotorModel = part.Parents?.First()?.Name ?? "";
Debug.WriteLine($"Select part parent -> {part.Parents?.First()?.Name} / {part.Parents?.First()?.ID}"); Debug.WriteLine($"Select part parent -> {part.Parents?.First()?.Name} / {part.Parents?.First()?.ID}");
} }
} }
else if (item != null) else if (item != null)
{ {
CheckSelLine(slient: true);
_selectLineId = item.ID; _selectLineId = item.ID;
OnPropertyChanged(nameof(SelectLineName)); OnPropertyChanged(nameof(SelectLineName));
} }
} }
} }
private bool IsCable(BaseOccurrence occ)
{
return occ is OccCableForked;
}
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName = null) public void OnPropertyChanged([CallerMemberName] string propertyName = null)
{ {
@ -216,9 +211,9 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{ {
var service = new MotorLectotypeService(); var service = new MotorLectotypeService();
var data = service.GetMotorLectotypeData(_motorIds[CurrentMotorIndex]); var data = service.GetMotorLectotypeData(_motorIds[CurrentMotorIndex]);
if (!string.IsNullOrEmpty(data)) if (data != null)
{ {
cableLectotypeViewModel = Newtonsoft.Json.JsonConvert.DeserializeObject<CableLectotypeViewModel>(data); cableLectotypeViewModel = data;
if (cableLectotypeViewModel?.SelectedLines?.Any() ?? false) if (cableLectotypeViewModel?.SelectedLines?.Any() ?? false)
{ {
SelectedLines = cableLectotypeViewModel.SelectedLines; SelectedLines = cableLectotypeViewModel.SelectedLines;
@ -285,7 +280,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
} }
} }
private bool CheckSelLine() private bool CheckSelLine(bool slient = false)
{ {
try try
{ {
@ -300,7 +295,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
: part is OccCablesInsulatorGraph ? : part is OccCablesInsulatorGraph ?
part part
: part.Parents?.FirstOrDefault() as OccCableForked; : part.Parents?.FirstOrDefault() as OccCableForked;
if (linePart != null) if (linePart != null)
{ {
var libName = linePart?.LibraryName; var libName = linePart?.LibraryName;
@ -327,37 +321,53 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
} }
if (string.IsNullOrEmpty(imprint)) if (string.IsNullOrEmpty(imprint))
{ {
#if DEBUG
return true;
#else
if(!slient)
FlexMessageBox.Warning($"当前选中的线 {libName} 印记未填写"); FlexMessageBox.Warning($"当前选中的线 {libName} 印记未填写");
return false; return false;
#endif
} }
if ($"{SelectedLine.AxisNo}-{SelectedLine.CurrentLine}" == imprint) if ($"{SelectedLine.AxisNo}-{SelectedLine.CurrentLine}" == imprint)
{ {
subLine.IsChecked = true; subLine.IsChecked = true;
//cableLectotypeViewModel.SaveToDb(); //cableLectotypeViewModel.SaveToDb();
SetSubLineAndSave(subLine.CableModel); SetSubLineAndSave(subLine.CableLectotypeId);
return SubLines.All(it => it.IsChecked); return SubLines.All(it => it.IsChecked);
} }
else else
{ {
#if DEBUG
return true;
#else
if(!slient)
FlexMessageBox.Warning($"当前选中的线 {libName} 印记与推荐中的线印记不一致"); FlexMessageBox.Warning($"当前选中的线 {libName} 印记与推荐中的线印记不一致");
return false; return false;
#endif
} }
} }
} }
} }
#if DEBUG
return true;
#else
if(!slient)
FlexMessageBox.Warning($"当前选中的线不是推荐中的线型号"); FlexMessageBox.Warning($"当前选中的线不是推荐中的线型号");
return false; return false;
#endif
} }
} }
catch (Exception) catch (Exception)
{ {
if(!slient)
FlexMessageBox.Warning("抓取线信息异常"); FlexMessageBox.Warning("抓取线信息异常");
return false; return false;
} }
if (!slient)
FlexMessageBox.Warning("请选择正确的线"); FlexMessageBox.Warning("请选择正确的线");
return false; return false;
} }
internal void ToPrevMotor() internal void ToPrevMotor()
{ {
if (CurrentMotorIndex > 0) if (CurrentMotorIndex > 0)
@ -380,33 +390,9 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{ {
SubLines = SelectedLine.SubLines.Distinct(it => it.CableModel).ToList(); SubLines = SelectedLine.SubLines.Distinct(it => it.CableModel).ToList();
} }
internal void SetSubLineAndSave(string cableLectotypeId)
{
internal void SetSubLineAndSave(string cableModel)
{
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);
}
}
} }