105040 Update 不再使用Eplan内部的零件ID,改为使用当前文档的创建时间+轴号作为电机数据保存的唯一标识;

添加电机唯一标识及相关属性和方法

在多个文件中添加了 `MotorUniqueFlag` 属性,并将其设置为可为空。在 `MotorModel.cs` 文件中还添加了 `DocName` 属性。新增了 `GetUniqueFlag` 扩展方法,用于生成电机的唯一标识,并在相关文件中使用该方法。修改了界面显示和方法参数,将“电机ID”替换为“电机唯一标识”。在 `LectotypeManager.cs` 文件中添加了 `CURRENT_DOC_NAME` 和 `CURRENT_DOC_CREATE_TIME` 静态字段。
This commit is contained in:
lihanbo 2025-01-22 16:45:50 +08:00
parent 373e23ba08
commit 98df216fae
13 changed files with 123 additions and 63 deletions

View File

@ -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; }

View File

@ -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)]

View File

@ -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)]

View File

@ -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}";
}
}
}

View File

@ -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));
}
}
/// <summary>
/// 部件ID
/// </summary>
public string MotorUniqueFlag
{
get => this.GetUniqueFlag();
set
{
OnPropertyChanged(nameof(MotorUniqueFlag));
}
}
}
}

View File

@ -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<Motor>("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<Motor>()
.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<CableLectotype>()
.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<LectotypeLine>()
.Where(sl => sl.MotorId == motorOccId)
.ExecuteCommand();
return changeCount > 0;
}
//public bool ClearSubLines(string motorUniqueFlag)
//{
// var changeCount = DBHelper.DB.Deleteable<LectotypeLine>()
// .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<CableLectotype>().Where(it => it.MotorId == motor.OccPartId).ExecuteCommand();
db.Deleteable<CableLectotype>().Where(it => it.MotorUniqueFlag == motor.MotorUniqueFlag).ExecuteCommand();
db.Storageable(cableLectotype).ExecuteCommand();
db.Deleteable<LectotypeLine>().Where(it => it.MotorId == motor.OccPartId).ExecuteCommand();
db.Deleteable<LectotypeLine>().Where(it => it.MotorUniqueFlag == motor.MotorUniqueFlag).ExecuteCommand();
db.Storageable(motor.CableLectotypeLines.ToList()).ExecuteCommand();
db.Storageable(motor.CableLectotypeLines.SelectMany(it => it.SubLines).ToList()).ExecuteCommand();

View File

@ -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<CableLectotypeViewModel> 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;

View File

@ -36,7 +36,6 @@
<Grid Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="60" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400" />
@ -67,12 +66,12 @@
Margin="0,10,0,0"
DataContext="{Binding Motor}"
Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="电机ID" />
<TextBlock VerticalAlignment="Center" Text="电机唯一标识" />
<hc:TextBox
VerticalAlignment="Center"
IsReadOnly="True"
Style="{StaticResource TextBoxPlusBaseStyle}"
Text="{Binding OccPartId}" />
Text="{Binding MotorUniqueFlag}" />
</hc:SimpleStackPanel>
<hc:SimpleStackPanel
Margin="0,10,0,0"
@ -117,6 +116,7 @@
Height="30"
HorizontalAlignment="Left"
hc:TitleElement.TitleWidth="120"
IsReadOnly="True"
Text="{Binding AxisNo, Mode=TwoWay}" />
</hc:SimpleStackPanel>
@ -225,7 +225,22 @@
Content="生成线材推荐列表"
Style="{StaticResource ButtonPrimary}" />
</hc:SimpleStackPanel>
<hc:SimpleStackPanel
Margin="0,150"
HorizontalAlignment="Center"
Orientation="Horizontal">
<Button
Margin="10,0,0,0"
hc:IconElement.Geometry="{StaticResource SaveGeometry}"
Click="SaveBtn_Click"
Content="保存"
FontSize="14"
Style="{StaticResource ButtonSuccess}" />
</hc:SimpleStackPanel>
</hc:SimpleStackPanel>
</hc:Card>
<hc:Card
Grid.Row="0"
@ -361,27 +376,6 @@
</DataGrid>
</hc:Card>
<hc:SimpleStackPanel
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button
Margin="10,0,0,0"
hc:IconElement.Geometry="{StaticResource SaveGeometry}"
Click="SaveBtn_Click"
Content="保存"
FontSize="14"
Style="{StaticResource ButtonSuccess}" />
<Button
Margin="10,0,10,0"
hc:IconElement.Geometry="{StaticResource CloseGeometry}"
Click="CloseBtn_Click"
Content="关闭"
FontSize="14"
Style="{StaticResource ButtonDanger}" />
</hc:SimpleStackPanel>
</Grid>
</UserControl>

View File

@ -37,10 +37,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
{
private FlexDesigner _currentFlexDesigner;
private LayoutHelperViewModel viewModel;
public LayoutHelperWindow(List<string> motorIds)
public LayoutHelperWindow(List<string> motorFlags)
{
InitializeComponent();
viewModel = new LayoutHelperViewModel(_currentFlexDesigner, motorIds);
viewModel = new LayoutHelperViewModel(_currentFlexDesigner, motorFlags);
this.DataContext = viewModel;

View File

@ -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;

View File

@ -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;

View File

@ -29,7 +29,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
public FlexDesigner _currentFlexDesigner;
private string _selectMotorModel;
private MotorLectotypeService service = new();
private List<string> _motorIds;
private List<string> _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<string> motorIds)
public LayoutHelperViewModel(FlexDesigner currentFlexDesigner, List<string> 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;

View File

@ -125,7 +125,16 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged
OnPropertyChanged();
}
}
private string _docName;
public string DocName
{
get => _docName;
set
{
_docName = value;
OnPropertyChanged();
}
}
/// <summary>
/// 机构号
/// </summary>
@ -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();