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.CableLectotype));
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\MotorDataModel.cs" />
<Compile Include="Model\MotorModel.cs" />
<Compile Include="Model\MultiCoreWireLecDBModel.cs" />
<Compile Include="Model\UserInfo.cs" />
<Compile Include="PluginServices.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) 线 线
*/
public string Id { get; set; }
public string UniqueKey { get; set; }
public string ProjectName { get; set; }
public string UserId { get; set; }
private int _seqNo;
[ExcelColumn(Ignore = true)]
public int SeqNo
{
get => _seqNo;
@ -44,17 +50,17 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models
/// <summary>
/// 线材类型
/// </summary>
private string _wireType;
[ExcelColumn(Ignore = true)]
public string WireType
{
get => _wireType;
set
{
_wireType = value;
OnPropertyChanged(nameof(WireType));
}
}
//private string _wireType;
//[ExcelColumn(Ignore = true)]
//public string WireType
//{
// get => _wireType;
// set
// {
// _wireType = value;
// OnPropertyChanged(nameof(WireType));
// }
//}
/// <summary>
/// 线径规格mm2)

View File

@ -88,9 +88,10 @@ namespace Sinvo.EplanHpD.Plugin.Service
// 查询关联的 LectotypeLine 数据
var selectedLines = DBHelper.DB.Queryable<LectotypeLine>()
.Where(ll => ll.CableLectotypeId == cableLectotype.CableLectotypeId)
//.OrderBy(ll => ll.SeqNo)
.Where(line => line.CableLectotypeId == cableLectotype.CableLectotypeId)
.ToList();
//.OrderBy(ll => ll.SeqNo)
// 构建 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\FlagEnumConverter.cs" />
<Compile Include="Converter\NameTypeConverter.cs" />
<Compile Include="Converter\WireColorConverter.cs" />
<Compile Include="Datas\BrandData.cs" />
<Compile Include="Datas\Brands.cs" />
<Compile Include="Enum\ConnectionType.cs" />
@ -273,6 +274,7 @@
<Compile Include="Models\UserLoginModel.cs" />
<Compile Include="Selector\LectotypeLengthDataTemplateSelector.cs" />
<Compile Include="Service\MotorLectotypeService.cs" />
<Compile Include="Service\MultiCoreWireService.cs" />
<Compile Include="TestWindow.xaml.cs">
<DependentUpon>TestWindow.xaml</DependentUpon>
</Compile>
@ -289,6 +291,7 @@
<Compile Include="ViewModel\LoginViewModel.cs" />
<Compile Include="Models\MultiCoreWire\MultiCoreWireDataModel.cs" />
<Compile Include="Models\MultiCoreWire\MultiCoreWireLecModel.cs" />
<Compile Include="ViewModel\MultiCoreWireViewModel\MultiCoreWireLayoutHelperViewModel.cs" />
<Compile Include="ViewModel\MultiCoreWireViewModel\MultiCoreWireViewModel.cs" />
<Compile Include="ViewModel\WireCheck\MainViewModel.Check.cs" />
<Compile Include="ViewModel\WireCheck\MainViewModel.cs" />

View File

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

View File

@ -9,6 +9,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
{
public class ExcelHelper
{
private static IEnumerable<InsulationModel> _insulations;
private static IEnumerable<ExcelModel> _terminalMappingCache = [];
/// <summary>
/// 线材端子对照表
@ -54,8 +56,16 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
/// </summary>
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 results = MiniExcel.Query<InsulationModel>(path);
if(_insulations == null)
{
_insulations = results;
}
//.Where(item => item.Specification == wireModel)
//.ToList();
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.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
@ -27,7 +28,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
/// </summary>
/// <param name="motor"></param>
/// <returns></returns>
public static async Task<CableLectotypeViewModel> CreateOrGetAsync(MotorModel motor)
public static CableLectotypeViewModel CreateOrGetAsync(MotorModel motor)
{
if (motor == null || string.IsNullOrEmpty(motor.AxisNo))
{
@ -37,7 +38,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
}
CableLectotypeViewModel viewModel = null;
await Task.Factory.StartNew(() =>
Task.Factory.StartNew(() =>
{
var service = new MotorLectotypeService();
var data = service.GetMotorLectotypeData(motor.GetUniqueFlag());
@ -55,7 +56,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
}
}
});
}).Wait();
if (viewModel == null)
{
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.AxisNo,
line.DrawingNo,
line.InsulationMCode,
line.InsulationModel,
line.InsulationCount,
EncoderLineLength = line.EncoderLineLength == 0 ? "" : line.EncoderLineLength.ToString(),
PowerLineLength = line.PowerLineLength == 0 ? "" : line.PowerLineLength.ToString(),
OrderDate = DateTime.Now.ToString("yyyy/M/d"),

View File

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

View File

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

View File

@ -1,4 +1,5 @@
using HandyControl.Controls;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
@ -20,14 +21,28 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View.MultiCoreWire.LayoutHelper
/// </summary>
public partial class MultiCoreWireLayoutHelperWindow : GlowWindow
{
public MultiCoreWireLayoutHelperWindow()
private readonly string _uniqueKey = "";
public MultiCoreWireLayoutHelperViewModel ViewModel;
public MultiCoreWireLayoutHelperWindow(string uniqueKey)
{
InitializeComponent();
_uniqueKey = uniqueKey;
this.DataContext = ViewModel = new MultiCoreWireLayoutHelperViewModel(uniqueKey);
}
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:hc="https://handyorg.github.io/handycontrol"
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:multicorewireviewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel"
Title="多芯线数据抓取"
@ -304,7 +305,7 @@
Click="DeleteItemBtn_Click"
Content="删除"
Style="{StaticResource ButtonDanger}"
Tag="{Binding SeqNo}" />
Tag="{Binding Id}" />
</hc:SimpleStackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
@ -357,7 +358,32 @@
Text="{Binding WireModelSpecification}" />
</hc:SimpleStackPanel>
</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>
<ItemsPanelTemplate>
<WrapPanel Margin="5" IsItemsHost="True" />
@ -390,7 +416,7 @@
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ItemsControl>-->
</Expander>
</Border>
</DataTemplate>

View File

@ -1,5 +1,6 @@
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel;
using SqlSugar.Extensions;
using System.Windows;
using System.Windows.Controls;
@ -19,6 +20,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
private void Window_Loaded(object sender, RoutedEventArgs e)
{
viewModel.Init();
viewModel.LoadWiresData();
}
@ -42,10 +44,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
{
if(sender is Button btn)
{
int? seqNo = (int)btn.Tag;
if(seqNo != null)
string id = (string)btn.Tag;
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.ProjectCore;
using EPLAN.Harness.ProjectCore.Occurrences.Designer;
using HandyControl.Controls;
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.MultiCoreWire;
using Sinvo.EplanHpD.Plugin.WPFUI.Service;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using SqlSugar;
using System;
@ -15,6 +19,7 @@ using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
@ -23,6 +28,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
{
public string _docId = docId;
private readonly MultiCoreWireExcelHelper _dataHelper = MultiCoreWireExcelHelper.Instance;
private readonly MultiCoreWireService _service = new();
private string CurrUniqueKey = "";
#region Props
private ObservableCollection<MultiCoreWireDataModel> _wires = [];
@ -207,19 +214,19 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
OnPropertyChanged(nameof(ApplicationScenarios));
}
}
private List<string> _wireTypes;
/// <summary>
/// 线材类型
/// </summary>
public List<string> WireTypes
{
get => _wireTypes;
set
{
_wireTypes = value;
OnPropertyChanged(nameof(WireTypes));
}
}
//private List<string> _wireTypes;
///// <summary>
///// 线材类型
///// </summary>
//public List<string> WireTypes
//{
// get => _wireTypes;
// set
// {
// _wireTypes = value;
// OnPropertyChanged(nameof(WireTypes));
// }
//}
private List<string> _wireDiameterSpecifications;
/// <summary>
/// 线径规格
@ -404,6 +411,45 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
_datas = _dataHelper.GetMultiCoreWireLecDatas();
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;
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(HighFlexibility),it => it.IsHighFlexibilityStr == HighFlexibility)
.WhereIF(!string.IsNullOrEmpty(HighFlexibility), it => it.IsHighFlexibilityStr == HighFlexibility)
// 型号
.WhereIF(!string.IsNullOrEmpty(WireModelSpecification), it => it.WireModelSpecification == WireModelSpecification)
// 线芯数
@ -427,7 +473,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
SetDatas(canUsedDatas, propName);
}
private void SetDatas(IEnumerable<MultiCoreWireLecModel> datas,string propName = "")
private void SetDatas(IEnumerable<MultiCoreWireLecModel> datas, string propName = "")
{
if (datas != null)
{
@ -437,7 +483,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
//{
// 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))
//{
// WireType = WireTypes.FirstOrDefault();
@ -489,7 +535,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
{
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)
//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);
});
return Task.CompletedTask;
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
@ -536,62 +582,111 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel.MultiCoreWireViewModel
public void SaveLecToLine()
{
if(ApplicationScenario == null
|| WireType == null
|| WireDiameterSpecification == null
|| HighFlexibility == null
|| WireCoreCount == null
|| WireModelSpecification == null)
if (ApplicationScenario == null
|| WireDiameterSpecification == null
|| HighFlexibility == null
|| WireCoreCount == null
|| WireModelSpecification == null
|| FrontConnectorModel == null
|| BackConnectorModel == null)
{
MessageBox.Show("有信息未选择!");
HandyControl.Controls.MessageBox.Show("有信息未选择!",caption: "提示",icon: MessageBoxImage.Warning);
return;
}
var wire = new MultiCoreWireLecModel
//if(LecWires.Any(it=> it.ApplicationScenario == ApplicationScenario && it.WireModelSpecification == WireModelSpecification))
//{
// MessageBox.Show("已选择相同的线!");
// return;
//}
try
{
SeqNo = LecWires.Count + 1,
ApplicationScenario = ApplicationScenario,
WireType = WireType,
WireDiameterSpecification = WireDiameterSpecification,
IsHighFlexibility = HighFlexibility == "是",
IsHighFlexibilityStr = HighFlexibility,
WireCoreCount = WireCoreCount,
WireModelSpecification = WireModelSpecification,
FrontConnectorModel = FrontConnectorModel,
BackConnectorModel = BackConnectorModel,
};
LecWires.Add(wire);
var wire = new MultiCoreWireLecModel
{
Id = Guid.NewGuid().ToString(),
SeqNo = LecWires.Count + 1,
ApplicationScenario = ApplicationScenario,
WireDiameterSpecification = WireDiameterSpecification,
IsHighFlexibilityStr = HighFlexibility,
WireCoreCount = WireCoreCount,
WireModelSpecification = WireModelSpecification,
FrontConnectorModel = FrontConnectorModel,
BackConnectorModel = BackConnectorModel,
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()
{
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)
{
LecWires.Remove(removeItem);
try
{
LecWires.Remove(removeItem);
_service.DeleteById(id);
}
catch (Exception ex)
{
HandyControl.Controls.MessageBox.Error($"删除数据失败!{ex}");
}
}
ReOrderLecWires();
//ReOrderLecWires();
}
}
private void ReOrderLecWires()
{
int seq = 1;
LecWires.OrderBy(it => it.SeqNo).ForEach(it =>
{
it.SeqNo = seq;
seq++;
});
OnPropertyChanged(nameof(LecWires));
}
//private void ReOrderLecWires()
//{
// int seq = 1;
// LecWires.OrderBy(it => it.SeqNo).ForEach(it =>
// {
// it.SeqNo = seq;
// seq++;
// });
// OnPropertyChanged(nameof(LecWires));
//}
}
}

View File

@ -59,39 +59,27 @@ namespace Sinvo.EplanHpD.Plugin
public void Execute(HpdApi api)
{
bool isLogin = PluginServices.IsLogin;
if (!isLogin)
{
var LoginWindow = new LoginWindow();
if(LoginWindow.ShowDialog() == true)
{
isLogin = PluginServices.IsLogin;
}
}
if (isLogin)
new DBHelper().CodeFirst();
var doc = api.CurrentProject.GetActiveDocument();
if (window == null)
{
new DBHelper().CodeFirst();
var doc = api.CurrentProject.GetActiveDocument();
if (window == null)
window = new LectotypeWindow(doc.ID);
// 获取版本号并显示到窗口标题
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.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 = null;
};
window.Show();
}
else
{
window.WindowState = System.Windows.WindowState.Normal;
window.Activate();
}
window = null;
};
window.Show();
}
else
{
window.WindowState = System.Windows.WindowState.Normal;
window.Activate();
}
}
public void Initialize()

View File

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