105040 Update 优化多芯线线材选型功能

This commit is contained in:
lihanbo 2025-04-24 14:22:46 +08:00
parent 0886ba4739
commit 2572dd0ea6
21 changed files with 597 additions and 178 deletions

View File

@ -44,6 +44,7 @@ namespace Sinvo.EplanHpD.Plugin.Service
DB.CodeFirst.InitTables(typeof(Model.Motor)); DB.CodeFirst.InitTables(typeof(Model.Motor));
DB.CodeFirst.InitTables(typeof(Model.CableLectotype)); DB.CodeFirst.InitTables(typeof(Model.CableLectotype));
DB.CodeFirst.InitTables(typeof(Model.LectotypeLine)); DB.CodeFirst.InitTables(typeof(Model.LectotypeLine));
DB.CodeFirst.InitTables(typeof(Model.MultiCoreWireLecDBModel));
} }
} }
} }

View File

@ -0,0 +1,62 @@
using SqlSugar;
using System.ComponentModel;
namespace Sinvo.EplanHpD.Plugin.Service.Model
{
[SugarTable("T_MCWIRE_LEC")]
public class MultiCoreWireLecDBModel
{
/*
* 线mm2) 线 线
*/
public string Id { get; set; }
public string UniqueKey { get; set; }
public string ProjectName { get; set; }
public string UserId { get; set; }
public int SeqNo { get; set; }
/// <summary>
/// 应用场景
/// </summary>
public string ApplicationScenario { get; set; }
/// <summary>
/// 线径规格mm2)
/// </summary>
public string WireDiameterSpecification { get; set; }
/// <summary>
/// 是否高柔
/// </summary>
public string IsHighFlexibilityStr { get; set; }
/// <summary>
/// 线芯数
/// </summary>
public string WireCoreCount { get; set; }
/// <summary>
/// 线材型号规格
/// </summary>
public string WireModelSpecification { get; set; }
/// <summary>
/// 前连接
/// </summary>
public string FrontConnectorModel { get; set; }
/// <summary>
/// 后连接
/// </summary>
public string BackConnectorModel { get; set; }
/// <summary>
/// 是否已布线
/// </summary>
public bool Layouted { get; set; } = false;
}
}

View File

@ -73,6 +73,7 @@
<Compile Include="Model\LectotypeLine.cs" /> <Compile Include="Model\LectotypeLine.cs" />
<Compile Include="Model\MotorDataModel.cs" /> <Compile Include="Model\MotorDataModel.cs" />
<Compile Include="Model\MotorModel.cs" /> <Compile Include="Model\MotorModel.cs" />
<Compile Include="Model\MultiCoreWireLecDBModel.cs" />
<Compile Include="Model\UserInfo.cs" /> <Compile Include="Model\UserInfo.cs" />
<Compile Include="PluginServices.cs" /> <Compile Include="PluginServices.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace Sinvo.EplanHpD.Plugin.WPFUI.Converter
{
public class WireColorConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length < 2 || values[0] == null || values[1] == null)
return Brushes.Transparent;
string primaryColor = values[0].ToString();
string secondaryColor = values[1].ToString();
bool isMultiColor = false;
if (values.Length > 2 && values[2] is bool v)
isMultiColor = v;
if (!isMultiColor || string.IsNullOrEmpty(secondaryColor))
return new SolidColorBrush((Color)ColorConverter.ConvertFromString(primaryColor));
// 创建线性渐变刷
LinearGradientBrush gradientBrush = new LinearGradientBrush();
gradientBrush.StartPoint = new System.Windows.Point(0, 0);
gradientBrush.EndPoint = new System.Windows.Point(1, 0);
gradientBrush.GradientStops.Add(
new GradientStop((Color)ColorConverter.ConvertFromString(primaryColor), 0.0));
gradientBrush.GradientStops.Add(
new GradientStop((Color)ColorConverter.ConvertFromString(secondaryColor), 1.0));
return gradientBrush;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -14,8 +14,14 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models
/* /*
* 线mm2) 线 线 * 线mm2) 线 线
*/ */
public string Id { get; set; }
public string UniqueKey { get; set; }
public string ProjectName { get; set; }
public string UserId { get; set; }
private int _seqNo; private int _seqNo;
[ExcelColumn(Ignore = true)]
public int SeqNo public int SeqNo
{ {
get => _seqNo; get => _seqNo;
@ -44,17 +50,17 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models
/// <summary> /// <summary>
/// 线材类型 /// 线材类型
/// </summary> /// </summary>
private string _wireType; //private string _wireType;
[ExcelColumn(Ignore = true)] //[ExcelColumn(Ignore = true)]
public string WireType //public string WireType
{ //{
get => _wireType; // get => _wireType;
set // set
{ // {
_wireType = value; // _wireType = value;
OnPropertyChanged(nameof(WireType)); // OnPropertyChanged(nameof(WireType));
} // }
} //}
/// <summary> /// <summary>
/// 线径规格mm2) /// 线径规格mm2)

View File

@ -88,9 +88,10 @@ namespace Sinvo.EplanHpD.Plugin.Service
// 查询关联的 LectotypeLine 数据 // 查询关联的 LectotypeLine 数据
var selectedLines = DBHelper.DB.Queryable<LectotypeLine>() var selectedLines = DBHelper.DB.Queryable<LectotypeLine>()
.Where(ll => ll.CableLectotypeId == cableLectotype.CableLectotypeId) .Where(line => line.CableLectotypeId == cableLectotype.CableLectotypeId)
//.OrderBy(ll => ll.SeqNo)
.ToList(); .ToList();
//.OrderBy(ll => ll.SeqNo)
// 构建 CableLectotypeViewModel // 构建 CableLectotypeViewModel
var viewModel = new CableLectotypeViewModel var viewModel = new CableLectotypeViewModel

View File

@ -0,0 +1,100 @@
using Newtonsoft.Json.Bson;
using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.Service.Model;
using Sinvo.EplanHpD.Plugin.WPFUI.Models.MultiCoreWire;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Shapes;
namespace Sinvo.EplanHpD.Plugin.WPFUI.Service
{
public class MultiCoreWireService
{
public IEnumerable<MultiCoreWireLecDBModel> GetByUniqueKey(string uniqueKey)
{
if (string.IsNullOrEmpty(uniqueKey))
{
return [];
}
var db = DBHelper.DB;
try
{
var result = db.Queryable<MultiCoreWireLecDBModel>()
.Where(it => it.UniqueKey == uniqueKey)
.ToList();
return result;
}
catch (Exception)
{
throw;
}
}
// 保存
public void SaveData(MultiCoreWireLecDBModel line)
{
if (string.IsNullOrEmpty(line.UniqueKey)
|| string.IsNullOrEmpty(line.UserId)
|| string.IsNullOrEmpty(line.ProjectName))
{
return;
}
var db = DBHelper.DB;
try
{
db.BeginTran();
db.Insertable(line).ExecuteCommand();
db.CommitTran();
}
catch (Exception)
{
db.RollbackTran();
throw;
}
}
internal void ClearSelf(string uniqueKey)
{
if (string.IsNullOrEmpty(uniqueKey))
{
return;
}
var db = DBHelper.DB;
try
{
db.BeginTran();
db.Deleteable<MultiCoreWireLecDBModel>().Where(it => it.UniqueKey == uniqueKey).ExecuteCommand();
db.CommitTran();
}
catch (Exception)
{
db.RollbackTran();
throw;
}
}
internal void DeleteById(string id)
{
if (string.IsNullOrEmpty(id))
{
return;
}
var db = DBHelper.DB;
try
{
db.BeginTran();
db.Deleteable<MultiCoreWireLecDBModel>().Where(it => it.Id == id).ExecuteCommand();
db.CommitTran();
}
catch (Exception)
{
db.RollbackTran();
throw;
}
}
}
}

View File

@ -242,6 +242,7 @@
<Compile Include="Converter\ConnectionTypeConverter.cs" /> <Compile Include="Converter\ConnectionTypeConverter.cs" />
<Compile Include="Converter\FlagEnumConverter.cs" /> <Compile Include="Converter\FlagEnumConverter.cs" />
<Compile Include="Converter\NameTypeConverter.cs" /> <Compile Include="Converter\NameTypeConverter.cs" />
<Compile Include="Converter\WireColorConverter.cs" />
<Compile Include="Datas\BrandData.cs" /> <Compile Include="Datas\BrandData.cs" />
<Compile Include="Datas\Brands.cs" /> <Compile Include="Datas\Brands.cs" />
<Compile Include="Enum\ConnectionType.cs" /> <Compile Include="Enum\ConnectionType.cs" />
@ -273,6 +274,7 @@
<Compile Include="Models\UserLoginModel.cs" /> <Compile Include="Models\UserLoginModel.cs" />
<Compile Include="Selector\LectotypeLengthDataTemplateSelector.cs" /> <Compile Include="Selector\LectotypeLengthDataTemplateSelector.cs" />
<Compile Include="Service\MotorLectotypeService.cs" /> <Compile Include="Service\MotorLectotypeService.cs" />
<Compile Include="Service\MultiCoreWireService.cs" />
<Compile Include="TestWindow.xaml.cs"> <Compile Include="TestWindow.xaml.cs">
<DependentUpon>TestWindow.xaml</DependentUpon> <DependentUpon>TestWindow.xaml</DependentUpon>
</Compile> </Compile>
@ -289,6 +291,7 @@
<Compile Include="ViewModel\LoginViewModel.cs" /> <Compile Include="ViewModel\LoginViewModel.cs" />
<Compile Include="Models\MultiCoreWire\MultiCoreWireDataModel.cs" /> <Compile Include="Models\MultiCoreWire\MultiCoreWireDataModel.cs" />
<Compile Include="Models\MultiCoreWire\MultiCoreWireLecModel.cs" /> <Compile Include="Models\MultiCoreWire\MultiCoreWireLecModel.cs" />
<Compile Include="ViewModel\MultiCoreWireViewModel\MultiCoreWireLayoutHelperViewModel.cs" />
<Compile Include="ViewModel\MultiCoreWireViewModel\MultiCoreWireViewModel.cs" /> <Compile Include="ViewModel\MultiCoreWireViewModel\MultiCoreWireViewModel.cs" />
<Compile Include="ViewModel\WireCheck\MainViewModel.Check.cs" /> <Compile Include="ViewModel\WireCheck\MainViewModel.Check.cs" />
<Compile Include="ViewModel\WireCheck\MainViewModel.cs" /> <Compile Include="ViewModel\WireCheck\MainViewModel.cs" />

View File

@ -40,6 +40,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
/// </summary> /// </summary>
public static readonly Regex dRegex = new("V-[\\d]+\\.?[\\d]*", RegexOptions.Compiled); public static readonly Regex dRegex = new("V-[\\d]+\\.?[\\d]*", RegexOptions.Compiled);
/// <summary> /// <summary>
/// 线径大小匹配(伺服电机线材选型)
/// </summary>
public static readonly Regex InsulationRegex = new("(?:[T]{0,}RVV\\d×)(\\d\\.{0,}\\d+)(?:-2000W)?(-CE)?", RegexOptions.Compiled);
/// <summary>
/// 括号内容匹配 /// 括号内容匹配
/// </summary> /// </summary>
public static readonly Regex regexParenthesesContent = new(@"(?<=\()[^)]*(?=\))", RegexOptions.Compiled); public static readonly Regex regexParenthesesContent = new(@"(?<=\()[^)]*(?=\))", RegexOptions.Compiled);

View File

@ -9,6 +9,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
{ {
public class ExcelHelper public class ExcelHelper
{ {
private static IEnumerable<InsulationModel> _insulations;
private static IEnumerable<ExcelModel> _terminalMappingCache = []; private static IEnumerable<ExcelModel> _terminalMappingCache = [];
/// <summary> /// <summary>
/// 线材端子对照表 /// 线材端子对照表
@ -54,8 +56,16 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
/// </summary> /// </summary>
public static IEnumerable<InsulationModel> GetInsulationSoftSleeveTable(string wireModel) public static IEnumerable<InsulationModel> GetInsulationSoftSleeveTable(string wireModel)
{ {
if(_insulations != null)
{
return _insulations.Where(item => item.Specification == wireModel);
}
var path = Path.Combine(Consts.DATA_FILE_PATH, Consts.DATA_FILE_PATH_INSULATION); var path = Path.Combine(Consts.DATA_FILE_PATH, Consts.DATA_FILE_PATH_INSULATION);
var results = MiniExcel.Query<InsulationModel>(path); var results = MiniExcel.Query<InsulationModel>(path);
if(_insulations == null)
{
_insulations = results;
}
//.Where(item => item.Specification == wireModel) //.Where(item => item.Specification == wireModel)
//.ToList(); //.ToList();
return results.Where(item => item.Specification == wireModel); return results.Where(item => item.Specification == wireModel);

View File

@ -1,4 +1,5 @@
using Sinvo.EplanHpD.Plugin.Service; using EPLAN.Harness.ProjectCore;
using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.WPFUI.Extension; using Sinvo.EplanHpD.Plugin.WPFUI.Extension;
using Sinvo.EplanHpD.Plugin.WPFUI.Models; using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
@ -27,7 +28,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
/// </summary> /// </summary>
/// <param name="motor"></param> /// <param name="motor"></param>
/// <returns></returns> /// <returns></returns>
public static async Task<CableLectotypeViewModel> CreateOrGetAsync(MotorModel motor) public static CableLectotypeViewModel CreateOrGetAsync(MotorModel motor)
{ {
if (motor == null || string.IsNullOrEmpty(motor.AxisNo)) if (motor == null || string.IsNullOrEmpty(motor.AxisNo))
{ {
@ -37,7 +38,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
} }
CableLectotypeViewModel viewModel = null; CableLectotypeViewModel viewModel = null;
await Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
var service = new MotorLectotypeService(); var service = new MotorLectotypeService();
var data = service.GetMotorLectotypeData(motor.GetUniqueFlag()); var data = service.GetMotorLectotypeData(motor.GetUniqueFlag());
@ -55,7 +56,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
} }
} }
}); }).Wait();
if (viewModel == null) if (viewModel == null)
{ {
return new CableLectotypeViewModel(motor); return new CableLectotypeViewModel(motor);
@ -67,5 +68,17 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
} }
} }
public static string GetDocName(FlexDesigner designer)
{
var docName = designer.Name;
if (docName.Contains("+"))
{
return docName.Split('+').FirstOrDefault();
}
else
{
return docName;
}
}
} }
} }

View File

@ -138,6 +138,9 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
line.CableType, line.CableType,
line.AxisNo, line.AxisNo,
line.DrawingNo, line.DrawingNo,
line.InsulationMCode,
line.InsulationModel,
line.InsulationCount,
EncoderLineLength = line.EncoderLineLength == 0 ? "" : line.EncoderLineLength.ToString(), EncoderLineLength = line.EncoderLineLength == 0 ? "" : line.EncoderLineLength.ToString(),
PowerLineLength = line.PowerLineLength == 0 ? "" : line.PowerLineLength.ToString(), PowerLineLength = line.PowerLineLength == 0 ? "" : line.PowerLineLength.ToString(),
OrderDate = DateTime.Now.ToString("yyyy/M/d"), OrderDate = DateTime.Now.ToString("yyyy/M/d"),

View File

@ -1,6 +1,7 @@
using EPLAN.Harness.Core.Settings; using EPLAN.Harness.Core.Settings;
using Newtonsoft.Json; using Newtonsoft.Json;
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 Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -110,7 +111,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
var result = viewModel.Login(); var result = viewModel.Login();
if(result != null && !string.IsNullOrEmpty(result.GUID)) if(result != null && !string.IsNullOrEmpty(result.GUID))
{ {
PluginServices.user = new Service.Model.UserInfo PluginServices.user = new UserInfo
{ {
Group = viewModel.User.UserGroup, Group = viewModel.User.UserGroup,
Role = viewModel.User.UserRole, Role = viewModel.User.UserRole,

View File

@ -7,11 +7,13 @@
xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View.MultiCoreWire.LayoutHelper" xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View.MultiCoreWire.LayoutHelper"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:multicorewireviewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel"
Title="布线助手" Title="布线助手"
Width="450" Width="450"
Height="260" Height="260"
MinWidth="450" MinWidth="450"
MinHeight="260" MinHeight="260"
d:DataContext="{d:DesignInstance Type=multicorewireviewmodel:MultiCoreWireLayoutHelperViewModel}"
ActiveGlowColor="{DynamicResource PrimaryColor}" ActiveGlowColor="{DynamicResource PrimaryColor}"
Background="White" Background="White"
FontSize="14" FontSize="14"
@ -47,11 +49,17 @@
Text="触摸屏" /> Text="触摸屏" />
</TextBlock> </TextBlock>
</hc:SimpleStackPanel> </hc:SimpleStackPanel>
<DataGrid Grid.Row="1" AutoGenerateColumns="False"> <DataGrid
Grid.Row="1"
AutoGenerateColumns="False"
ItemsSource="{Binding LecWires}">
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn Header="序号" /> <DataGridTextColumn Header="序号" />
<DataGridTextColumn MinWidth="240" Header="线型号" /> <DataGridTextColumn
<DataGridComboBoxColumn Header="已布线" /> MinWidth="240"
Binding="{Binding WireModelSpecification}"
Header="线型号" />
<DataGridCheckBoxColumn Binding="{Binding Layouted}" Header="是否已布线" />
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
<hc:SimpleStackPanel <hc:SimpleStackPanel

View File

@ -1,4 +1,5 @@
using HandyControl.Controls; using HandyControl.Controls;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -20,14 +21,28 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View.MultiCoreWire.LayoutHelper
/// </summary> /// </summary>
public partial class MultiCoreWireLayoutHelperWindow : GlowWindow public partial class MultiCoreWireLayoutHelperWindow : GlowWindow
{ {
public MultiCoreWireLayoutHelperWindow() private readonly string _uniqueKey = "";
public MultiCoreWireLayoutHelperViewModel ViewModel;
public MultiCoreWireLayoutHelperWindow(string uniqueKey)
{ {
InitializeComponent(); InitializeComponent();
_uniqueKey = uniqueKey;
this.DataContext = ViewModel = new MultiCoreWireLayoutHelperViewModel(uniqueKey);
} }
private void GlowWindow_Loaded(object sender, RoutedEventArgs e) private void GlowWindow_Loaded(object sender, RoutedEventArgs e)
{ {
} }
private void NextBtn_Click(object sender, RoutedEventArgs e)
{
}
private void PrevBtn_Click(object sender, RoutedEventArgs e)
{
}
} }
} }

View File

@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View" xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View"
xmlns:localconverter="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.Converter"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:multicorewireviewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel" xmlns:multicorewireviewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel"
Title="多芯线数据抓取" Title="多芯线数据抓取"
@ -304,7 +305,7 @@
Click="DeleteItemBtn_Click" Click="DeleteItemBtn_Click"
Content="删除" Content="删除"
Style="{StaticResource ButtonDanger}" Style="{StaticResource ButtonDanger}"
Tag="{Binding SeqNo}" /> Tag="{Binding Id}" />
</hc:SimpleStackPanel> </hc:SimpleStackPanel>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
@ -357,7 +358,32 @@
Text="{Binding WireModelSpecification}" /> Text="{Binding WireModelSpecification}" />
</hc:SimpleStackPanel> </hc:SimpleStackPanel>
</Expander.Header> </Expander.Header>
<ItemsControl ItemsSource="{Binding Children}"> <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Children}">
<DataGrid.Resources>
<localconverter:WireColorConverter x:Key="WireColorConverter" />
<Style BasedOn="{StaticResource DataGridCellStyle}" TargetType="DataGridCell">
<Setter Property="BorderBrush">
<Setter.Value>
<MultiBinding Converter="{StaticResource WireColorConverter}">
<Binding Path="WireColorHex" />
<Binding Path="WireColorHexSec" />
<Binding Path="IsMultiColor" />
</MultiBinding>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="0,0,0,2" />
<Setter Property="hc:BorderElement.CornerRadius" Value="0" />
<Setter Property="Margin" Value="0" />
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding WireModelSpecification}" Header="线芯名称" />
<DataGridTextColumn Binding="{Binding WireColorName}" Header="线芯颜色" />
<DataGridTextColumn Binding="{Binding FrontTerminalModel}" Header="前连接" />
<DataGridTextColumn Binding="{Binding BackTerminalModel}" Header="后连接" />
</DataGrid.Columns>
</DataGrid>
<!--<ItemsControl ItemsSource="{Binding Children}">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<WrapPanel Margin="5" IsItemsHost="True" /> <WrapPanel Margin="5" IsItemsHost="True" />
@ -390,7 +416,7 @@
</Border> </Border>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>-->
</Expander> </Expander>
</Border> </Border>
</DataTemplate> </DataTemplate>

View File

@ -1,5 +1,6 @@
using Sinvo.EplanHpD.Plugin.WPFUI.Models; using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel; using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel;
using SqlSugar.Extensions;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@ -19,6 +20,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
private void Window_Loaded(object sender, RoutedEventArgs e) private void Window_Loaded(object sender, RoutedEventArgs e)
{ {
viewModel.Init();
viewModel.LoadWiresData(); viewModel.LoadWiresData();
} }
@ -42,10 +44,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
{ {
if(sender is Button btn) if(sender is Button btn)
{ {
int? seqNo = (int)btn.Tag; string id = (string)btn.Tag;
if(seqNo != null) if(id != null)
{ {
viewModel.DeleteLecWireItem(seqNo); viewModel.DeleteLecWireItem(id);
} }
} }
} }

View File

@ -0,0 +1,46 @@
using Sinvo.EplanHpD.Plugin.Service.Model;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
{
public class MultiCoreWireLayoutHelperViewModel : INotifyPropertyChanged
{
private string _uniqueKey;
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public MultiCoreWireLayoutHelperViewModel(string uniqueKey)
{
_uniqueKey = uniqueKey;
}
#region Props
private ObservableCollection<MultiCoreWireLecModel> _lecWires = [];
public ObservableCollection<MultiCoreWireLecModel> LecWires
{
get { return _lecWires; }
set
{
_lecWires = value;
OnPropertyChanged(nameof(LecWires));
}
}
#endregion
}
}

View File

@ -3,9 +3,13 @@ using EPLAN.Harness.Core.Appearance;
using EPLAN.Harness.Core.Utils; using EPLAN.Harness.Core.Utils;
using EPLAN.Harness.ProjectCore; using EPLAN.Harness.ProjectCore;
using EPLAN.Harness.ProjectCore.Occurrences.Designer; using EPLAN.Harness.ProjectCore.Occurrences.Designer;
using HandyControl.Controls;
using MiniExcelLibs.Attributes; using MiniExcelLibs.Attributes;
using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.Service.Model;
using Sinvo.EplanHpD.Plugin.WPFUI.Models; using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Models.MultiCoreWire; using Sinvo.EplanHpD.Plugin.WPFUI.Models.MultiCoreWire;
using Sinvo.EplanHpD.Plugin.WPFUI.Service;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils; using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using SqlSugar; using SqlSugar;
using System; using System;
@ -15,6 +19,7 @@ using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms; using System.Windows.Forms;
namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
@ -23,6 +28,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
{ {
public string _docId = docId; public string _docId = docId;
private readonly MultiCoreWireExcelHelper _dataHelper = MultiCoreWireExcelHelper.Instance; private readonly MultiCoreWireExcelHelper _dataHelper = MultiCoreWireExcelHelper.Instance;
private readonly MultiCoreWireService _service = new();
private string CurrUniqueKey = "";
#region Props #region Props
private ObservableCollection<MultiCoreWireDataModel> _wires = []; private ObservableCollection<MultiCoreWireDataModel> _wires = [];
@ -207,19 +214,19 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
OnPropertyChanged(nameof(ApplicationScenarios)); OnPropertyChanged(nameof(ApplicationScenarios));
} }
} }
private List<string> _wireTypes; //private List<string> _wireTypes;
/// <summary> ///// <summary>
/// 线材类型 ///// 线材类型
/// </summary> ///// </summary>
public List<string> WireTypes //public List<string> WireTypes
{ //{
get => _wireTypes; // get => _wireTypes;
set // set
{ // {
_wireTypes = value; // _wireTypes = value;
OnPropertyChanged(nameof(WireTypes)); // OnPropertyChanged(nameof(WireTypes));
} // }
} //}
private List<string> _wireDiameterSpecifications; private List<string> _wireDiameterSpecifications;
/// <summary> /// <summary>
/// 线径规格 /// 线径规格
@ -404,6 +411,45 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
_datas = _dataHelper.GetMultiCoreWireLecDatas(); _datas = _dataHelper.GetMultiCoreWireLecDatas();
SetDatas(_datas); SetDatas(_datas);
try
{
var wiresData = _service.GetByUniqueKey(CurrUniqueKey);
if (wiresData != null)
{
wiresData.ForEach(wire =>
{
LecWires.Add(new MultiCoreWireLecModel
{
Id = wire.Id,
SeqNo = wire.SeqNo,
ApplicationScenario = wire.ApplicationScenario,
WireDiameterSpecification = wire.WireDiameterSpecification,
IsHighFlexibilityStr = wire.IsHighFlexibilityStr,
WireCoreCount = wire.WireCoreCount,
WireModelSpecification = wire.WireModelSpecification,
FrontConnectorModel = wire.FrontConnectorModel,
BackConnectorModel = wire.BackConnectorModel,
UserId = wire.UserId,
ProjectName = wire.ProjectName,
UniqueKey = wire.UniqueKey
});
});
}
}
catch (Exception)
{
HandyControl.Controls.MessageBox.Error("加载历史数据失败");
}
}
public void Init()
{
var des = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(it => it.ID == _docId) ?? throw new Exception("设计器不存在");
LectotypeManager.CURRENT_DOC_NAME = LectotypeManager.GetDocName(des);
CurrUniqueKey = $"{LectotypeManager.CURRENT_DOC_NAME}_{PluginServices.user.ID}";
} }
private bool LecChanging = false; private bool LecChanging = false;
public void OnLecChanged(string propName) public void OnLecChanged(string propName)
@ -418,7 +464,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
// 线径规格 // 线径规格
.WhereIF(!string.IsNullOrEmpty(WireDiameterSpecification), it => it.WireDiameterSpecification == WireDiameterSpecification) .WhereIF(!string.IsNullOrEmpty(WireDiameterSpecification), it => it.WireDiameterSpecification == WireDiameterSpecification)
// 是否高柔 // 是否高柔
.WhereIF(!string.IsNullOrEmpty(HighFlexibility),it => it.IsHighFlexibilityStr == HighFlexibility) .WhereIF(!string.IsNullOrEmpty(HighFlexibility), it => it.IsHighFlexibilityStr == HighFlexibility)
// 型号 // 型号
.WhereIF(!string.IsNullOrEmpty(WireModelSpecification), it => it.WireModelSpecification == WireModelSpecification) .WhereIF(!string.IsNullOrEmpty(WireModelSpecification), it => it.WireModelSpecification == WireModelSpecification)
// 线芯数 // 线芯数
@ -427,7 +473,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
SetDatas(canUsedDatas, propName); SetDatas(canUsedDatas, propName);
} }
private void SetDatas(IEnumerable<MultiCoreWireLecModel> datas,string propName = "") private void SetDatas(IEnumerable<MultiCoreWireLecModel> datas, string propName = "")
{ {
if (datas != null) if (datas != null)
{ {
@ -437,7 +483,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
//{ //{
// ApplicationScenario = ApplicationScenarios.FirstOrDefault(); // ApplicationScenario = ApplicationScenarios.FirstOrDefault();
//} //}
WireTypes = [.. datas.Where(it => !string.IsNullOrEmpty(it.WireType)).Select(it => it.WireType).Distinct(), ""]; //WireTypes = [.. datas.Where(it => !string.IsNullOrEmpty(it.WireType)).Select(it => it.WireType).Distinct(), ""];
//if (WireTypes.Where(it => !string.IsNullOrEmpty(it)).Count() == 1 && propName != nameof(WireType)) //if (WireTypes.Where(it => !string.IsNullOrEmpty(it)).Count() == 1 && propName != nameof(WireType))
//{ //{
// WireType = WireTypes.FirstOrDefault(); // WireType = WireTypes.FirstOrDefault();
@ -489,7 +535,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
{ {
c.Children.Where(ccc => ccc is OccWire).ForEach(cc => c.Children.Where(ccc => ccc is OccWire).ForEach(cc =>
{ {
if(cc is OccWire wire) if (cc is OccWire wire)
{ {
//var color = materials.Where(col => col == wire.Color) //var color = materials.Where(col => col == wire.Color)
//Debug.WriteLine($"\t\t{wire.Name} - {wire.LibraryName} - {FlexColors.GetName(wire.Color.Major)}"); //Debug.WriteLine($"\t\t{wire.Name} - {wire.LibraryName} - {FlexColors.GetName(wire.Color.Major)}");
@ -511,7 +557,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
Wires?.Add(wireData); Wires?.Add(wireData);
}); });
return Task.CompletedTask; return Task.CompletedTask;
} }
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName) public void OnPropertyChanged(string propertyName)
{ {
@ -536,62 +582,111 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
public void SaveLecToLine() public void SaveLecToLine()
{ {
if(ApplicationScenario == null if (ApplicationScenario == null
|| WireType == null || WireDiameterSpecification == null
|| WireDiameterSpecification == null || HighFlexibility == null
|| HighFlexibility == null || WireCoreCount == null
|| WireCoreCount == null || WireModelSpecification == null
|| WireModelSpecification == null) || FrontConnectorModel == null
|| BackConnectorModel == null)
{ {
MessageBox.Show("有信息未选择!"); HandyControl.Controls.MessageBox.Show("有信息未选择!",caption: "提示",icon: MessageBoxImage.Warning);
return; return;
} }
var wire = new MultiCoreWireLecModel //if(LecWires.Any(it=> it.ApplicationScenario == ApplicationScenario && it.WireModelSpecification == WireModelSpecification))
//{
// MessageBox.Show("已选择相同的线!");
// return;
//}
try
{ {
SeqNo = LecWires.Count + 1, var wire = new MultiCoreWireLecModel
ApplicationScenario = ApplicationScenario, {
WireType = WireType, Id = Guid.NewGuid().ToString(),
WireDiameterSpecification = WireDiameterSpecification, SeqNo = LecWires.Count + 1,
IsHighFlexibility = HighFlexibility == "是", ApplicationScenario = ApplicationScenario,
IsHighFlexibilityStr = HighFlexibility, WireDiameterSpecification = WireDiameterSpecification,
WireCoreCount = WireCoreCount, IsHighFlexibilityStr = HighFlexibility,
WireModelSpecification = WireModelSpecification, WireCoreCount = WireCoreCount,
FrontConnectorModel = FrontConnectorModel, WireModelSpecification = WireModelSpecification,
BackConnectorModel = BackConnectorModel, FrontConnectorModel = FrontConnectorModel,
}; BackConnectorModel = BackConnectorModel,
LecWires.Add(wire); UserId = PluginServices.user.ID,
ProjectName = LectotypeManager.CURRENT_DOC_NAME,
UniqueKey = $"{LectotypeManager.CURRENT_DOC_NAME}_{PluginServices.user.ID}"
};
_service.SaveData(new MultiCoreWireLecDBModel
{
Id = wire.Id,
UniqueKey = wire.UniqueKey,
ProjectName = wire.ProjectName,
UserId = wire.UserId,
SeqNo = wire.SeqNo,
ApplicationScenario = wire.ApplicationScenario,
WireDiameterSpecification = wire.WireDiameterSpecification,
IsHighFlexibilityStr = wire.IsHighFlexibilityStr,
WireCoreCount = wire.WireCoreCount,
WireModelSpecification = wire.WireModelSpecification,
FrontConnectorModel = wire.FrontConnectorModel,
BackConnectorModel = wire.BackConnectorModel
});
LecWires.Add(wire);
}
catch (Exception ex)
{
HandyControl.Controls.MessageBox.Error($"保存数据失败!{ex}");
}
} }
public void ClearLecLines() public void ClearLecLines()
{ {
LecWires.Clear(); try
{
LecWires.Clear();
_service.ClearSelf(CurrUniqueKey);
}
catch (Exception ex)
{
HandyControl.Controls.MessageBox.Error($"清除数据失败!{ex}");
}
} }
internal void DeleteLecWireItem(int? seqNo) internal void DeleteLecWireItem(string id)
{ {
if(seqNo != null) if(id != null)
{ {
var removeItem = LecWires.FirstOrDefault(it => it.SeqNo == seqNo!); var removeItem = LecWires.FirstOrDefault(it => it.Id == id!);
if(removeItem != null) if(removeItem != null)
{ {
LecWires.Remove(removeItem); try
{
LecWires.Remove(removeItem);
_service.DeleteById(id);
}
catch (Exception ex)
{
HandyControl.Controls.MessageBox.Error($"删除数据失败!{ex}");
}
} }
ReOrderLecWires(); //ReOrderLecWires();
} }
} }
private void ReOrderLecWires() //private void ReOrderLecWires()
{ //{
int seq = 1; // int seq = 1;
LecWires.OrderBy(it => it.SeqNo).ForEach(it => // LecWires.OrderBy(it => it.SeqNo).ForEach(it =>
{ // {
it.SeqNo = seq; // it.SeqNo = seq;
seq++; // seq++;
}); // });
OnPropertyChanged(nameof(LecWires)); // OnPropertyChanged(nameof(LecWires));
} //}
} }
} }

View File

@ -59,39 +59,27 @@ namespace Sinvo.EplanHpD.Plugin
public void Execute(HpdApi api) public void Execute(HpdApi api)
{ {
bool isLogin = PluginServices.IsLogin; new DBHelper().CodeFirst();
if (!isLogin) var doc = api.CurrentProject.GetActiveDocument();
{ if (window == null)
var LoginWindow = new LoginWindow();
if(LoginWindow.ShowDialog() == true)
{
isLogin = PluginServices.IsLogin;
}
}
if (isLogin)
{ {
new DBHelper().CodeFirst(); window = new LectotypeWindow(doc.ID);
var doc = api.CurrentProject.GetActiveDocument(); // 获取版本号并显示到窗口标题
if (window == null) window.Title += $" V{Version} - {doc.Name}";
ElementHost.EnableModelessKeyboardInterop(window);
var mainApp = BaseApp.ActiveApplication;
var helper = new System.Windows.Interop.WindowInteropHelper(window);
helper.Owner = mainApp.Handle;
window.Closed += delegate
{ {
window = new LectotypeWindow(doc.ID); window = null;
// 获取版本号并显示到窗口标题 };
window.Title += $" V{Version} - {doc.Name}"; window.Show();
ElementHost.EnableModelessKeyboardInterop(window); }
var mainApp = BaseApp.ActiveApplication; else
var helper = new System.Windows.Interop.WindowInteropHelper(window); {
helper.Owner = mainApp.Handle; window.WindowState = System.Windows.WindowState.Normal;
window.Closed += delegate window.Activate();
{
window = null;
};
window.Show();
}
else
{
window.WindowState = System.Windows.WindowState.Normal;
window.Activate();
}
} }
} }
public void Initialize() public void Initialize()

View File

@ -61,96 +61,83 @@ namespace Sinvo.EplanHpD.Plugin
private MainWindow window; private MainWindow window;
public void Execute(HpdApi api) public void Execute(HpdApi api)
{ {
//bool isLogin = PluginServices.IsLogin; bool isUpdated = false;
//if (!isLogin) try
//{ {
// var LoginWindow = new LoginWindow(); var doc = api.CurrentProject.GetActiveDocument();
// if (LoginWindow.ShowDialog() == true) //doc.ID
// { //if(doc is FlexReport)
// isLogin = PluginServices.IsLogin; if (doc is EPLAN.Harness.API.Projects.Documents.Report report)
// }
//}
//if (isLogin)
//{
bool isUpdated = false;
try
{ {
var doc = api.CurrentProject.GetActiveDocument(); var reportId = report.ID;
//doc.ID var allReports = FlexProject.CurrentProject.GetReports();
//if(doc is FlexReport) if (allReports.Any(item => item.ID == reportId))
if (doc is EPLAN.Harness.API.Projects.Documents.Report report)
{ {
var reportId = report.ID; var flexReport = allReports.Where(item => item.ID == reportId).First();
var allReports = FlexProject.CurrentProject.GetReports(); if (flexReport != null)
if (allReports.Any(item => item.ID == reportId))
{ {
var flexReport = allReports.Where(item => item.ID == reportId).First(); var isNeedUpdate = FlexReport.IsUpToDate(flexReport);
if (flexReport != null) if (!isNeedUpdate)
{ {
var isNeedUpdate = FlexReport.IsUpToDate(flexReport); if (FlexMessageBox.Warning(FlexMessageBox.Buttons.OK_CANCEL,
if (!isNeedUpdate) "Report",
"报表数据不是最新的,是否更新?", false) == DialogResult.OK)
{ {
if (FlexMessageBox.Warning(FlexMessageBox.Buttons.OK_CANCEL, flexReport.UpdateReport();
"Report", isUpdated = true;
"报表数据不是最新的,是否更新?", false) == DialogResult.OK)
{
flexReport.UpdateReport();
isUpdated = true;
}
} }
try }
try
{
if (window == null)
{ {
if (window == null) window = new MainWindow(flexReport);
ElementHost.EnableModelessKeyboardInterop(window);
window.Show();
}
else
{
if (isUpdated)
{ {
window.Close();
window = new MainWindow(flexReport); window = new MainWindow(flexReport);
ElementHost.EnableModelessKeyboardInterop(window); ElementHost.EnableModelessKeyboardInterop(window);
window.Show(); window.Show();
} }
else window.ShowActivated = true;
if (window.WindowState == System.Windows.WindowState.Minimized)
{ {
if (isUpdated) window.WindowState = System.Windows.WindowState.Normal;
{
window.Close();
window = new MainWindow(flexReport);
ElementHost.EnableModelessKeyboardInterop(window);
window.Show();
}
window.ShowActivated = true;
if (window.WindowState == System.Windows.WindowState.Minimized)
{
window.WindowState = System.Windows.WindowState.Normal;
}
window.Show();
window.Activate();
} }
}
catch (Exception)
{
window = new MainWindow(flexReport);
// 解决WPF窗体在WinForm中无法输入的问题
ElementHost.EnableModelessKeyboardInterop(window);
window.Show(); window.Show();
window.Activate();
} }
} }
} catch (Exception)
else {
{ window = new MainWindow(flexReport);
FlexMessageBox.Error("未找到项目中匹配的报表,请检查是否生成成功或是未保存到项目中!"); // 解决WPF窗体在WinForm中无法输入的问题
ElementHost.EnableModelessKeyboardInterop(window);
window.Show();
}
} }
} }
else else
{ {
FlexMessageBox.Error("请打开一个报表后再使用"); FlexMessageBox.Error("未找到项目中匹配的报表,请检查是否生成成功或是未保存到项目中");
} }
} }
catch (Exception ex) else
{ {
FlexMessageBox.Error(ex.ToString()); FlexMessageBox.Error("请打开一个报表后再使用!");
} }
//} }
catch (Exception ex)
{
FlexMessageBox.Error(ex.ToString());
}
} }
public void Initialize() public void Initialize()