105040 Update 不再使用部件ID作为唯一标识

This commit is contained in:
lihanbo 2025-01-24 11:27:14 +08:00
parent 9d2d6ccb4d
commit 2870b5ea2a
6 changed files with 35 additions and 20 deletions

View File

@ -11,11 +11,10 @@ namespace Sinvo.EplanHpD.Plugin.Service.Model
[SugarTable("T_MOTOR")] [SugarTable("T_MOTOR")]
public class Motor public class Motor
{ {
//public string MotorId { get; set; } //public string MotorId { get; set; }
[SugarColumn(IsPrimaryKey = true)]
public string OccPartId { get; set; } public string OccPartId { get; set; }
[SugarColumn(IsNullable = true)] [SugarColumn(IsPrimaryKey = true)]
public string MotorUniqueFlag { get; set; } public string MotorUniqueFlag { get; set; }
[SugarColumn(IsNullable = true)] [SugarColumn(IsNullable = true)]

View File

@ -109,5 +109,18 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models
OnPropertyChanged(nameof(MotorUniqueFlag)); OnPropertyChanged(nameof(MotorUniqueFlag));
} }
} }
/// <summary>
/// 从其他对象复制属性
/// </summary>
public void CopyFrom(MotorModel motor)
{
this.MotorPower = motor.MotorPower;
this.Brand = motor.Brand;
this.MotorSerie = motor.MotorSerie;
this.MotorModelStr = motor.MotorModelStr;
this.AxisNo = motor.AxisNo;
//this.OccPartId = motor.OccPartId;
}
} }
} }

View File

@ -254,7 +254,7 @@ namespace Sinvo.EplanHpD.Plugin.Service
} }
} }
public int SetLineDone(string motorId,string lineId) public int SetLineDone(string motorUniqueFlag,string lineId)
{ {
var db = DBHelper.DB; var db = DBHelper.DB;
@ -263,7 +263,7 @@ namespace Sinvo.EplanHpD.Plugin.Service
db.BeginTran(); db.BeginTran();
int changeCount = db.Updateable<LectotypeLine>() int changeCount = db.Updateable<LectotypeLine>()
.Where(mt => mt.MotorId == motorId && mt.LectotypeLineId == lineId) .Where(mt => mt.MotorUniqueFlag == motorUniqueFlag && mt.LectotypeLineId == lineId)
.SetColumns(it => it.IsChecked == true) .SetColumns(it => it.IsChecked == true)
.ExecuteCommand(); .ExecuteCommand();

View File

@ -40,6 +40,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
if (data != null) if (data != null)
{ {
viewModel = data; viewModel = data;
// 更新电机ID数据每次导入后可能会刷新这个ID所以从抓取的数据中更新
viewModel.Motor.OccPartId = motor.OccPartId;
} }
}).Wait(); }).Wait();

View File

@ -11,6 +11,7 @@ using EPLAN.Harness.ProjectCore;
using EPLAN.Harness.ProjectCore.Occurrences; using EPLAN.Harness.ProjectCore.Occurrences;
using EPLAN.Harness.ProjectCore.Occurrences.Designer; using EPLAN.Harness.ProjectCore.Occurrences.Designer;
using HandyControl.Controls; using HandyControl.Controls;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils; using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
using System; using System;
@ -37,10 +38,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
{ {
private FlexDesigner _currentFlexDesigner; private FlexDesigner _currentFlexDesigner;
private LayoutHelperViewModel viewModel; private LayoutHelperViewModel viewModel;
public LayoutHelperWindow(List<string> motorFlags) public LayoutHelperWindow(List<MotorModel> motors)
{ {
InitializeComponent(); InitializeComponent();
viewModel = new LayoutHelperViewModel(_currentFlexDesigner, motorFlags); viewModel = new LayoutHelperViewModel(_currentFlexDesigner, motors);
this.DataContext = viewModel; this.DataContext = viewModel;

View File

@ -29,7 +29,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
public FlexDesigner _currentFlexDesigner; public FlexDesigner _currentFlexDesigner;
private string _selectMotorModel; private string _selectMotorModel;
private MotorLectotypeService service = new(); private MotorLectotypeService service = new();
private List<string> _motorFlags; private List<MotorModel> _motors;
private MotorModel _motor; private MotorModel _motor;
private CableLectotypeViewModel cableLectotypeViewModel; private CableLectotypeViewModel cableLectotypeViewModel;
private HpdApi api; private HpdApi api;
@ -47,10 +47,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
api = HpdApi.GetInstance(); api = HpdApi.GetInstance();
api.Init(); api.Init();
} }
public LayoutHelperViewModel(FlexDesigner currentFlexDesigner, List<string> motorFlags) public LayoutHelperViewModel(FlexDesigner currentFlexDesigner, List<MotorModel> motorFlags)
{ {
_currentFlexDesigner = currentFlexDesigner; _currentFlexDesigner = currentFlexDesigner;
_motorFlags = motorFlags; _motors = motorFlags;
api = HpdApi.GetInstance(); api = HpdApi.GetInstance();
api.Init(); api.Init();
@ -101,13 +101,13 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{ {
get get
{ {
if (_motorFlags == null) return false; if (_motors == null) return false;
if (SelectedLines == null) return false; if (SelectedLines == null) return false;
if (CurrentMotorSelectLineIndex < SelectedLines.Count - 1) if (CurrentMotorSelectLineIndex < SelectedLines.Count - 1)
{ {
return true; return true;
} }
else if (CurrentMotorIndex < _motorFlags.Count - 1) else if (CurrentMotorIndex < _motors.Count - 1)
{ {
return true; return true;
} }
@ -204,13 +204,13 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
internal void GetMotorCables() internal void GetMotorCables()
{ {
if (_motorFlags != null && _motorFlags.Any()) if (_motors != null && _motors.Any())
{ {
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
var service = new MotorLectotypeService(); var service = new MotorLectotypeService();
var data = service.GetMotorLectotypeData(_motorFlags[CurrentMotorIndex]); var data = service.GetMotorLectotypeData(_motors[CurrentMotorIndex]?.MotorUniqueFlag);
if (data != null) if (data != null)
{ {
cableLectotypeViewModel = data; cableLectotypeViewModel = data;
@ -219,13 +219,13 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
SelectedLines = cableLectotypeViewModel.SelectedLines.OrderBy(it => it.CableType).ThenBy(it => it.CurrentLine).ToList(); SelectedLines = cableLectotypeViewModel.SelectedLines.OrderBy(it => it.CableType).ThenBy(it => it.CurrentLine).ToList();
SelectedLine = SelectedLines[CurrentMotorSelectLineIndex]; SelectedLine = SelectedLines[CurrentMotorSelectLineIndex];
ReSetSubLines(); ReSetSubLines();
Motor = cableLectotypeViewModel.Motor; Motor = _motors[CurrentMotorIndex];
return; return;
} }
} }
CurrentMotorIndex++; CurrentMotorIndex++;
if (CurrentMotorIndex < _motorFlags.Count) if (CurrentMotorIndex < _motors.Count)
{ {
CurrentMotorSelectLineIndex = 0; CurrentMotorSelectLineIndex = 0;
GetMotorCables(); GetMotorCables();
@ -375,7 +375,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
} }
internal void ToNextMotor() internal void ToNextMotor()
{ {
if (CurrentMotorIndex < _motorFlags.Count) if (CurrentMotorIndex < _motors.Count)
{ {
CurrentMotorIndex++; CurrentMotorIndex++;
CurrentMotorSelectLineIndex = 0; CurrentMotorSelectLineIndex = 0;
@ -388,9 +388,9 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
} }
internal void SetSubLineAndSave(string lectotypeLineId) internal void SetSubLineAndSave(string lectotypeLineId)
{ {
var motorId = Motor.OccPartId; var motorUniqueFlag = Motor.MotorUniqueFlag;
var service = new MotorLectotypeService(); var service = new MotorLectotypeService();
service.SetLineDone(motorId, lectotypeLineId); service.SetLineDone(motorUniqueFlag, lectotypeLineId);
} }
} }
} }