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}" />
+
+
+
+
+
+
-
-
-
-
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/LayoutHelperWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/View/LayoutHelperWindow.xaml.cs
index 323f7d6..bfb9cff 100644
--- a/Sinvo.EplanHpD.Plugin.WPFUI/View/LayoutHelperWindow.xaml.cs
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/LayoutHelperWindow.xaml.cs
@@ -37,10 +37,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
{
private FlexDesigner _currentFlexDesigner;
private LayoutHelperViewModel viewModel;
- public LayoutHelperWindow(List motorIds)
+ public LayoutHelperWindow(List motorFlags)
{
InitializeComponent();
- viewModel = new LayoutHelperViewModel(_currentFlexDesigner, motorIds);
+ viewModel = new LayoutHelperViewModel(_currentFlexDesigner, motorFlags);
this.DataContext = viewModel;
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml.cs
index 86492b4..23cc402 100644
--- a/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml.cs
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml.cs
@@ -373,8 +373,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
private void StartLayoutBtn_Click(object sender, RoutedEventArgs e)
{
- var motorIds = ViewModel.Motors.Where(motor => !motor.IsError).Select(motor => motor.OccPartId).ToList();
- var window = new LayoutHelperWindow(motorIds);
+ var motorFlags = ViewModel.Motors.Where(motor => !motor.IsError).Select(motor => motor.GetUniqueFlag()).ToList();
+ var window = new LayoutHelperWindow(motorFlags);
//window.MotorIds = motorIds;
ElementHost.EnableModelessKeyboardInterop(window);
var mainApp = BaseApp.ActiveApplication;
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotypeViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotypeViewModel.cs
index 54405c8..90d6b58 100644
--- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotypeViewModel.cs
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotypeViewModel.cs
@@ -3,6 +3,7 @@ using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.Service.Model;
using Sinvo.EplanHpD.Plugin.WPFUI.Datas;
using Sinvo.EplanHpD.Plugin.WPFUI.Enum;
+using Sinvo.EplanHpD.Plugin.WPFUI.Extension;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using System;
@@ -408,10 +409,11 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
public bool SaveToDb()
- {
+ {
//var service = new MotorLectotypeService();
// 查找或添加 Motor
- return motorService.SaveMotorLectotypeData(Motor.OccPartId, this);
+ var motorUniqueFlag = Motor.GetUniqueFlag();
+ return motorService.SaveMotorLectotypeData(motorUniqueFlag, this);
}
public event PropertyChangedEventHandler PropertyChanged;
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs
index f5ef4a6..33b27b1 100644
--- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs
@@ -29,7 +29,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
public FlexDesigner _currentFlexDesigner;
private string _selectMotorModel;
private MotorLectotypeService service = new();
- private List _motorIds;
+ private List _motorFlags;
private MotorModel _motor;
private CableLectotypeViewModel cableLectotypeViewModel;
private HpdApi api;
@@ -47,10 +47,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
api = HpdApi.GetInstance();
api.Init();
}
- public LayoutHelperViewModel(FlexDesigner currentFlexDesigner, List motorIds)
+ public LayoutHelperViewModel(FlexDesigner currentFlexDesigner, List motorFlags)
{
_currentFlexDesigner = currentFlexDesigner;
- _motorIds = motorIds;
+ _motorFlags = motorFlags;
api = HpdApi.GetInstance();
api.Init();
@@ -101,13 +101,13 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{
get
{
- if (_motorIds == null) return false;
+ if (_motorFlags == null) return false;
if (SelectedLines == null) return false;
if (CurrentMotorSelectLineIndex < SelectedLines.Count - 1)
{
return true;
}
- else if (CurrentMotorIndex < _motorIds.Count - 1)
+ else if (CurrentMotorIndex < _motorFlags.Count - 1)
{
return true;
}
@@ -204,13 +204,13 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
internal void GetMotorCables()
{
- if (_motorIds != null && _motorIds.Any())
+ if (_motorFlags != null && _motorFlags.Any())
{
Task.Factory.StartNew(() =>
{
var service = new MotorLectotypeService();
- var data = service.GetMotorLectotypeData(_motorIds[CurrentMotorIndex]);
+ var data = service.GetMotorLectotypeData(_motorFlags[CurrentMotorIndex]);
if (data != null)
{
cableLectotypeViewModel = data;
@@ -225,7 +225,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
}
CurrentMotorIndex++;
- if (CurrentMotorIndex < _motorIds.Count)
+ if (CurrentMotorIndex < _motorFlags.Count)
{
CurrentMotorSelectLineIndex = 0;
GetMotorCables();
@@ -375,7 +375,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
}
internal void ToNextMotor()
{
- if (CurrentMotorIndex < _motorIds.Count)
+ if (CurrentMotorIndex < _motorFlags.Count)
{
CurrentMotorIndex++;
CurrentMotorSelectLineIndex = 0;
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs
index c601613..60f325c 100644
--- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs
@@ -125,7 +125,16 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged
OnPropertyChanged();
}
}
-
+ private string _docName;
+ public string DocName
+ {
+ get => _docName;
+ set
+ {
+ _docName = value;
+ OnPropertyChanged();
+ }
+ }
///
/// 机构号
///
@@ -166,6 +175,11 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged
return Task.CompletedTask;
}
var designer = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId);
+ // 获取项目名
+ DocName = designer.Name.Split('+').FirstOrDefault();
+ LectotypeManager.CURRENT_DOC_NAME = DocName;
+ LectotypeManager.CURRENT_DOC_CREATE_TIME = new DateTimeOffset(designer.CreatedDateDateTime).ToUnixTimeMilliseconds().ToString();
+
// 获取所有存在的
var wires = designer.GetOrganizerOccurrences(designer.ID);
//OriWires = wires.ToList();