105040 Update 增加动力线与动力编码器线绝缘软套信息匹配

This commit is contained in:
lihanbo 2025-04-24 14:21:42 +08:00
parent 4212086da1
commit 6630e4c877
7 changed files with 219 additions and 66 deletions

View File

@ -1,13 +1,15 @@
using EPLAN.Harness.AppCore.AttributeEvents; using EPLAN.Harness.AppCore.AttributeEvents;
using Sinvo.EplanHpD.Plugin.WPFUI.Datas; using Sinvo.EplanHpD.Plugin.WPFUI.Datas;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils; using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
namespace Sinvo.EplanHpD.Plugin.WPFUI.Models namespace Sinvo.EplanHpD.Plugin.WPFUI.Models
{ {
public class LectotypeLineModel : CheckedModel public class
LectotypeLineModel : CheckedModel
{ {
public string CableLectotypeId { get; set; } public string CableLectotypeId { get; set; }
@ -416,5 +418,92 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models
CableType = it.Name CableType = it.Name
}).ToList(); }).ToList();
} }
public bool SubLineNeedInsulation
{
get
{
return SubLines != null && SubLines.Any(it => it.NeedInsulation);
}
}
//private bool _needInsulation;
public bool NeedInsulation
{
get
{
return (CableType == "动力线" || CableType == "动力刹车线") && (CableModel?.Contains("黄绿色") ?? false);
}
}
private string _insulationMCode;
/// <summary>
/// 绝缘软套物料编码
/// </summary>
public string InsulationMCode
{
get
{
return _insulationMCode;
}
set
{
_insulationMCode = value;
OnPropertyChanged(nameof(InsulationMCode));
}
}
/// <summary>
/// 绝缘软套物料编码
/// </summary>
public int? InsulationCount
{
get
{
return NeedInsulation ? 1 : null;
}
set
{
OnPropertyChanged(nameof(InsulationCount));
}
}
public string InsulationModel
{
get
{
return GetInsulation();
}
set {
}
}
private string GetInsulation()
{
if (string.IsNullOrEmpty(CableModel) || !NeedInsulation)
return "";
// 线径
var matchGroups = Consts.InsulationRegex.Match(CableModel).Groups;
var wireDiameter = matchGroups[1]?.Value;
var ceFlag = matchGroups[2]?.Value ?? "";
if (string.IsNullOrEmpty(ceFlag) && CableModel.Contains("-CE"))
{
ceFlag = "-CE";
}
if (double.Parse(wireDiameter) <= 1.5)
{
wireDiameter = "1.5";
}
var insulationModel = $"V-{wireDiameter}{ceFlag}(绿色)/定制";
var insData = ExcelHelper.GetInsulationSoftSleeveTable(insulationModel).FirstOrDefault();
if (insData != null)
{
InsulationMCode = insData.MaterialCode;
OnPropertyChanged(nameof(NeedInsulation));
return insData.Specification;
}
else
{
return " - ";
}
}
} }
} }

View File

@ -50,7 +50,7 @@
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Panel.ZIndex="99" Panel.ZIndex="99"
ContentTemplate="{StaticResource LoadingMask}" ContentTemplate="{StaticResource LoadingMask}"
Visibility="Collapsed" /> Visibility="Hidden" />
<hc:Card <hc:Card
x:Name="InfoCard" x:Name="InfoCard"
Grid.Row="0" Grid.Row="0"
@ -401,6 +401,30 @@
</DataTemplate> </DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn.CellTemplate>
</GridViewColumn> </GridViewColumn>
<GridViewColumn Width="150">
<GridViewColumnHeader Content="绝缘软套料号" Visibility="{Binding SubLineNeedInsulation, Converter={StaticResource Boolean2VisibilityConverter}}" />
<GridViewColumn.CellTemplate>
<DataTemplate>
<hc:TextBox
MinWidth="100"
IsReadOnly="True"
Text="{Binding InsulationMCode}"
Visibility="{Binding NeedInsulation, Converter={StaticResource Boolean2VisibilityConverter}}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="420">
<GridViewColumnHeader Content="绝缘软套型号" Visibility="{Binding SubLineNeedInsulation, Converter={StaticResource Boolean2VisibilityConverter}}" />
<GridViewColumn.CellTemplate>
<DataTemplate>
<hc:TextBox
MinWidth="400"
IsReadOnly="True"
Text="{Binding InsulationModel}"
Visibility="{Binding NeedInsulation, Converter={StaticResource Boolean2VisibilityConverter}}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<!--<GridViewColumn Header="是否布线完成"> <!--<GridViewColumn Header="是否布线完成">
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>

View File

@ -8,6 +8,7 @@ using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
@ -58,7 +59,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
try try
{ {
LoadingContentMask.Visibility = Visibility.Visible; LoadingContentMask.Visibility = Visibility.Visible;
var oldViewModel = LectotypeViewModelFactory.CreateOrGetAsync(_motor).Result; var oldViewModel = LectotypeViewModelFactory.CreateOrGetAsync(_motor);
if (oldViewModel != null) if (oldViewModel != null)
{ {
ViewModel.Apply(oldViewModel); ViewModel.Apply(oldViewModel);
@ -77,18 +78,30 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
} }
private void CableratorBtn_Click(object sender, RoutedEventArgs e) private void CableratorBtn_Click(object sender, RoutedEventArgs e)
{ {
ViewModel.Cablerator(); LoadingContentMask.Visibility = Visibility.Visible;
//var motor = Motor as MotorModel; Dispatcher.Invoke(() => { });
if(Motor is CableLectotypeViewModel motor) Task.Factory.StartNew(() =>
{ {
// 发送消息,用户生成了数据 ViewModel.Cablerator();
WeakReferenceMessenger.Default.Send<LectotypeMessage,string>(new LectotypeMessage
(new System.Collections.Generic.Dictionary<string, string> }).ContinueWith(x =>
{
Dispatcher.BeginInvoke(() =>
{ {
if (Motor is CableLectotypeViewModel motor)
{
// 发送消息,用户生成了数据
WeakReferenceMessenger.Default.Send<LectotypeMessage, string>(new LectotypeMessage
(new System.Collections.Generic.Dictionary<string, string>
{
{motor.Motor.MotorModelStr,motor.Motor.AxisNo} {motor.Motor.MotorModelStr,motor.Motor.AxisNo}
}), "Lectotype" }), "Lectotype"
); );
} }
LoadingContentMask.Visibility = Visibility.Collapsed;
});
});
} }
private void ListView_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) private void ListView_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
@ -115,32 +128,43 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
private void SaveBtn_Click(object sender, RoutedEventArgs e) private void SaveBtn_Click(object sender, RoutedEventArgs e)
{ {
LoadingContentMask.Visibility = Visibility.Visible; LoadingContentMask.Visibility = Visibility.Visible;
try bool saved = false;
Task.Factory.StartNew(() =>
{ {
if (ViewModel.SaveToDb()) try
{ {
if (Motor is CableLectotypeViewModel motor)
{
WeakReferenceMessenger.Default.Send(new LectotypeMessage
(new System.Collections.Generic.Dictionary<string, string>
{
{motor.Motor.MotorModelStr,motor.Motor.AxisNo}
}), "LectotypeSaved"
);
}
Growl.Success("保存成功", "CableLectotypeMessage");
}
else
{
Growl.Error("保存失败", "CableLectotypeMessage");
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
LoadingContentMask.Visibility = Visibility.Collapsed;
saved = ViewModel.SaveToDb();
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}).ContinueWith(x =>
{
Dispatcher.BeginInvoke(() =>
{
if (saved)
{
if (Motor is CableLectotypeViewModel motor)
{
WeakReferenceMessenger.Default.Send(new LectotypeMessage
(new System.Collections.Generic.Dictionary<string, string>
{
{motor.Motor.MotorModelStr,motor.Motor.AxisNo}
}), "LectotypeSaved"
);
}
Growl.Success("保存成功", "CableLectotypeMessage");
}
else
{
Growl.Error("保存失败", "CableLectotypeMessage");
}
LoadingContentMask.Visibility = Visibility.Collapsed;
});
});
} }
private void CloseBtn_Click(object sender, RoutedEventArgs e) private void CloseBtn_Click(object sender, RoutedEventArgs e)
{ {

View File

@ -496,6 +496,8 @@
</DataGridTemplateColumn> </DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding CableType}" Header="线材类型" /> <DataGridTextColumn Binding="{Binding CableType}" Header="线材类型" />
<DataGridTextColumn Binding="{Binding CableConnectionClass}" Header="线材连接方式" /> <DataGridTextColumn Binding="{Binding CableConnectionClass}" Header="线材连接方式" />
<DataGridTextColumn Binding="{Binding InsulationModel}" Header="绝缘软套型号" />
<DataGridTextColumn Binding="{Binding InsulationMCode}" Header="绝缘软套料号" />
<DataGridTextColumn Binding="{Binding CheckedMsg}" Header="异常信息" /> <DataGridTextColumn Binding="{Binding CheckedMsg}" Header="异常信息" />
<DataGridTemplateColumn> <DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>

View File

@ -88,6 +88,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
{ {
//DrawPDFHelper.CacheAllPdfToMemory(); //DrawPDFHelper.CacheAllPdfToMemory();
MotorExcelHelper.Instance.ReadDataToStream(); MotorExcelHelper.Instance.ReadDataToStream();
ExcelHelper.GetInsulationSoftSleeveTable("");
LoadData(); LoadData();
} }
catch (System.Exception ex) catch (System.Exception ex)

View File

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
@ -29,14 +30,13 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
/// </summary> /// </summary>
public void Cablerator() public void Cablerator()
{ {
SelectedLines?.Clear(); SelectedLines?.Clear();
if (string.IsNullOrEmpty(Motor.MotorPower)) if (string.IsNullOrEmpty(Motor.MotorPower))
{ {
ShowWarning("电机功率不能为空!"); ShowWarning("电机功率不能为空!");
return; return;
} }
if(IsEnableParagraph) if (IsEnableParagraph)
{ {
if (EncoderLineParagraph == 0 || PowerLineParagraph == 0) if (EncoderLineParagraph == 0 || PowerLineParagraph == 0)
{ {
@ -67,7 +67,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
{ {
AxisNo = AxisNo, AxisNo = AxisNo,
CableConnectionClass = CableConnectionType == ConnectionType.FullParagraph ? "前段" : "直通", CableConnectionClass = CableConnectionType == ConnectionType.FullParagraph ? "前段" : "直通",
CableType = brandData.ComplexLine ? $"{CableTypePrimary}+{CableTypeSecond}" : CableTypePrimary, CableType = brandData.ComplexLine ? $"{CableTypePrimary}+{CableTypeSecond}" : CableTypePrimary,
CableModelNo = CableModelStr, CableModelNo = CableModelStr,
IsLectotype = true, IsLectotype = true,
CurrentLine = 1, CurrentLine = 1,
@ -75,7 +75,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
}; };
line.DrawingNo = line.GetCableDrawNo(); line.DrawingNo = line.GetCableDrawNo();
line.SubLines = GetSubLines(line.DrawingNo); line.SubLines = GetSubLines(line.DrawingNo);
var startIndex = 1; var startIndex = 1;
if (CableConnectionType == ConnectionType.FullParagraph) if (CableConnectionType == ConnectionType.FullParagraph)
{ {
LectotypeList.Clear(); LectotypeList.Clear();
@ -95,11 +95,11 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
// 第一条线为所选线 // 第一条线为所选线
LectotypeList.Add(line); LectotypeList.Add(line);
var secLine = new LectotypeLineModel var secLine = new LectotypeLineModel
{ {
AxisNo = AxisNo, AxisNo = AxisNo,
CableConnectionClass = CableConnectionType == ConnectionType.FullParagraph ? "前段" : "直通", CableConnectionClass = CableConnectionType == ConnectionType.FullParagraph ? "前段" : "直通",
CableType = CableTypeSecond, CableType = CableTypeSecond,
CableModelNo = CableModelStr, CableModelNo = CableModelStr,
IsLectotype = true, IsLectotype = true,
CurrentLine = 1, CurrentLine = 1,
Motor = Motor Motor = Motor
@ -169,11 +169,11 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
if (_passthroughCableCount >= 2 && !string.IsNullOrEmpty(CableTypeSecond)) if (_passthroughCableCount >= 2 && !string.IsNullOrEmpty(CableTypeSecond))
{ {
var secLine = new LectotypeLineModel var secLine = new LectotypeLineModel
{ {
AxisNo = AxisNo, AxisNo = AxisNo,
CableConnectionClass = "直通", CableConnectionClass = "直通",
CableType = CableTypeSecond, CableType = CableTypeSecond,
CableModelNo = CableModelStr, CableModelNo = CableModelStr,
IsLectotype = true, IsLectotype = true,
CurrentLine = 1, CurrentLine = 1,
Motor = Motor Motor = Motor
@ -185,11 +185,11 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
if (_passthroughCableCount >= 3 && !string.IsNullOrEmpty(CableTypeThree)) if (_passthroughCableCount >= 3 && !string.IsNullOrEmpty(CableTypeThree))
{ {
var secLine = new LectotypeLineModel var secLine = new LectotypeLineModel
{ {
AxisNo = AxisNo, AxisNo = AxisNo,
CableConnectionClass = "直通", CableConnectionClass = "直通",
CableType = CableTypeThree, CableType = CableTypeThree,
CableModelNo = CableModelStr, CableModelNo = CableModelStr,
IsLectotype = true, IsLectotype = true,
CurrentLine = 1, CurrentLine = 1,
Motor = Motor Motor = Motor
@ -199,7 +199,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
LectotypeList.Add(secLine); LectotypeList.Add(secLine);
} }
} }
} }
var sortedLines = LectotypeList.OrderBy(it => it.CableType).ThenBy(it => it.CurrentLine).ToList(); var sortedLines = LectotypeList.OrderBy(it => it.CableType).ThenBy(it => it.CurrentLine).ToList();
sortedLines.ForEach(it => sortedLines.ForEach(it =>
@ -462,6 +462,18 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
OnPropertyChanged(nameof(IsEnableSecCableType)); OnPropertyChanged(nameof(IsEnableSecCableType));
} }
} }
private bool _loading;
public bool Loading
{
get => _loading;
set
{
_loading = value;
OnPropertyChanged(nameof(Loading));
}
}
public bool SaveToDb() public bool SaveToDb()
{ {
//var service = new MotorLectotypeService(); //var service = new MotorLectotypeService();

View File

@ -169,9 +169,9 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged
// 当前的工作区 // 当前的工作区
var designer = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); var designer = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId);
// 获取项目名 // 获取项目名
DocName = GetDocName(designer); DocName = LectotypeManager.GetDocName(designer);
LectotypeManager.CURRENT_DOC_NAME = DocName; LectotypeManager.CURRENT_DOC_NAME = DocName;
LectotypeManager.CURRENT_DOC_CREATE_TIME = new DateTimeOffset(designer.CreatedDateDateTime).ToUnixTimeMilliseconds().ToString(); //LectotypeManager.CURRENT_DOC_CREATE_TIME = new DateTimeOffset(designer.CreatedDateDateTime).ToUnixTimeMilliseconds().ToString();
// 获取所有存在的 // 获取所有存在的
var wires = designer.GetOrganizerOccurrences(designer.ID); var wires = designer.GetOrganizerOccurrences(designer.ID);
@ -212,6 +212,7 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged
return new LectotypeLineModel return new LectotypeLineModel
{ {
Name= GetLectotypeName(occCable.LibraryName), Name= GetLectotypeName(occCable.LibraryName),
CableModel = GetLectotypeName(occCable.LibraryName),
LibraryName = occCable.LibraryName, LibraryName = occCable.LibraryName,
CableName = occCable.Name, CableName = occCable.Name,
AxisNo = GetAxisNo(insulatorGraph.Imprint), AxisNo = GetAxisNo(insulatorGraph.Imprint),
@ -262,18 +263,18 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged
} }
} }
public string GetDocName(FlexDesigner designer) //public string GetDocName(FlexDesigner designer)
{ //{
var docName = designer.Name; // var docName = designer.Name;
if (docName.Contains("+")) // if (docName.Contains("+"))
{ // {
return docName.Split('+').FirstOrDefault(); // return docName.Split('+').FirstOrDefault();
} // }
else // else
{ // {
return docName; // return docName;
} // }
} //}
public List<LectotypeLineModel> StuffData(List<LectotypeLineModel> cables) public List<LectotypeLineModel> StuffData(List<LectotypeLineModel> cables)
{ {
List<LectotypeLineModel> datas = []; List<LectotypeLineModel> datas = [];