EPLAN_PROD_Plugin/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/WireCheck/MainViewModel.cs

605 lines
20 KiB
C#
Raw Normal View History

2024-10-24 18:01:26 +08:00
using EPLAN.Harness.Common.Extensions;
using EPLAN.Harness.Core.Controls;
using EPLAN.Harness.Core.Settings;
2024-10-24 18:01:26 +08:00
using EPLAN.Harness.ProjectCore.Report;
2024-12-05 14:37:31 +08:00
using Sinvo.EplanHpD.Plugin.WPFUI.Enum;
2024-10-24 18:01:26 +08:00
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Controls;
using static Sinvo.EplanHpD.Plugin.WPFUI.MainWindow;
namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
public partial class MainViewModel : INotifyPropertyChanged
{
#region Properties
public UpdateDataGridColumns UpdateDataGridColumns;
private ObservableCollection<ReportModel> data;
private ObservableCollection<StuffedDataModel> stuffedData;
private ObservableCollection<ExportModel> exportData;
private ObservableCollection<DataGridColumn> dataColumns;
private ObservableCollection<StuffedDataModel> searchedData;
2024-10-24 18:01:26 +08:00
public ObservableCollection<ReportModel> Data
{
get => data;
set
{
data = value;
OnPropertyChanged(nameof(Data));
}
}
public ObservableCollection<StuffedDataModel> StuffedData
{
get => stuffedData;
set
{
stuffedData = value;
OnPropertyChanged(nameof(StuffedData));
}
}
public ObservableCollection<ExportModel> ExportData
{
get => exportData;
set
{
exportData = value;
OnPropertyChanged(nameof(ExportData));
}
}
public ObservableCollection<StuffedDataModel> SearchedData
{
get => searchedData;
set
{
searchedData = value;
OnPropertyChanged(nameof(SearchedData));
}
}
2024-10-24 18:01:26 +08:00
public ObservableCollection<DataGridColumn> DataColumns
{
get => dataColumns;
set
{
dataColumns = value;
OnPropertyChanged(nameof(DataColumns));
}
}
private bool _isRequireCe;
public bool IsRequireCe
{
get => _isRequireCe;
set
{
_isRequireCe = value;
OnPropertyChanged(nameof(IsRequireCe));
}
}
private string _projectNo;
public string ProjectNo
{
get => _projectNo;
set
{
_projectNo = value;
OnPropertyChanged(nameof(ProjectNo));
}
}
private bool _isUseDiscoloration = true;
2024-10-24 18:01:26 +08:00
/// <summary>
/// 是否使用变色管
/// </summary>
public bool IsUseDiscoloration
{
get => _isUseDiscoloration;
set
{
_isUseDiscoloration = value;
OnPropertyChanged(nameof(IsUseDiscoloration));
}
}
private string _mechanismNo;
/// <summary>
/// 机构号
/// </summary>
public string MechanismNo
{
get => _mechanismNo;
set
{
_mechanismNo = value;
OnPropertyChanged(nameof(MechanismNo));
}
}
private string _mechanismName;
/// <summary>
/// 机构名称
/// </summary>
public string MechanismName
{
get => _mechanismName;
set
{
_mechanismName = value;
OnPropertyChanged(nameof(MechanismName));
}
}
private bool _onlyShowError;
/// <summary>
/// 机构名称
/// </summary>
public bool OnlyShowError
{
get => _onlyShowError;
set
{
_onlyShowError = value;
OnPropertyChanged(nameof(OnlyShowError));
}
}
2024-10-24 18:01:26 +08:00
private WireFlagType _flagType;
public WireFlagType FlagType
{
get => _flagType;
set
{
_flagType = value;
OnPropertyChanged(nameof(FlagType));
FormUISettings.Instance.SetValue("FlagType", $"{FlagType}");
FormUISettings.Instance.SaveSingleton();
2024-10-24 18:01:26 +08:00
}
}
2024-11-13 13:39:06 +08:00
private ExportFileNameType _nameType;
public ExportFileNameType NameType
{
get => _nameType;
set
{
_nameType = value;
OnPropertyChanged(nameof(NameType));
FormUISettings.Instance.SetValue("NameType", $"{NameType}");
FormUISettings.Instance.SaveSingleton();
}
}
private string _customFileName;
public string CustomFileName
{
get => _customFileName;
set
{
_customFileName = value;
OnPropertyChanged(nameof(CustomFileName));
}
}
2024-11-13 13:39:06 +08:00
private bool _toSourceAndMinSelf;
public bool ToSourceAndMinSelf
{
get => _toSourceAndMinSelf;
set
{
_toSourceAndMinSelf = value;
OnPropertyChanged(nameof(ToSourceAndMinSelf));
}
}
2024-10-24 18:01:26 +08:00
#endregion
public Task<List<DataGridTextColumn>> GetColumns(List<ReportColumn> columns)
{
var dataColumns = new List<DataGridTextColumn>();
foreach (var column in columns)
{
//Trace.WriteLine($"/// {column.Text}\r\n public string {column.ID} {{get;set;}} ");
dataColumns.Add(new DataGridTextColumn()
{
Header = column.Text,
Binding = new System.Windows.Data.Binding(column.ID)
});
}
return Task.FromResult(dataColumns);
}
private void LoadSavedUISettings()
2024-10-24 18:01:26 +08:00
{
var savedFlagType = FormUISettings.Instance.GetValue("FlagType") ?? WireFlagType.Dual;
2024-12-05 14:37:31 +08:00
if (System.Enum.IsDefined(typeof(WireFlagType), savedFlagType))
{
2024-12-05 14:37:31 +08:00
FlagType = (WireFlagType)System.Enum.Parse(typeof(WireFlagType), savedFlagType.ToString());
}
else
{
FlagType = WireFlagType.Dual;
}
var savedNameType = FormUISettings.Instance.GetValue("NameType") ?? ExportFileNameType.Mechanism;
2024-12-05 14:37:31 +08:00
if (System.Enum.IsDefined(typeof(ExportFileNameType), savedNameType))
{
2024-12-05 14:37:31 +08:00
NameType = (ExportFileNameType)System.Enum.Parse(typeof(ExportFileNameType), savedNameType.ToString());
}
else
{
NameType = ExportFileNameType.Mechanism;
}
}
public Task<List<ReportModel>> LoadReportDataAsync(IEnumerable<BaseReportEntry> data, List<ReportColumn> columns)
{
LoadSavedUISettings();
2024-10-24 18:01:26 +08:00
var reportDatas = new ConcurrentBag<ReportModel>();
//foreach (var entry in data)
data.Where(it =>
it.OrigOcc == "OccWire"
&& !(it?.Properties["WireName"]?.GetDisplayValue()?.StartsWith("导线") ?? false)
)
.AsParallel()
.WithDegreeOfParallelism(8)
.ForAll(entry =>
2024-10-24 18:01:26 +08:00
{
var obj = new ReportModel();
foreach (var column in columns)
{
if (!entry.Properties.ContainsKey(column.ColumnID)) continue;
var value = entry.Properties[column.ColumnID].GetDisplayValue();
var property = typeof(ReportModel).GetProperty(column.ID);
property?.SetValue(obj, value ?? "");
}
obj.OccPartId = entry.ID;
reportDatas.Add(obj);
2024-10-24 18:01:26 +08:00
}
);
return Task.FromResult(reportDatas.ToList());
}
2024-11-02 11:56:50 +08:00
/// <summary>
/// 清理数据
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public async Task<List<StuffedDataModel>> StuffData(List<ReportModel> datas)
2024-10-24 18:01:26 +08:00
{
var
stuffedDatas = new ConcurrentBag<StuffedDataModel>();
2024-10-25 08:40:22 +08:00
//var isAllCe = true;
//var isL1 = false;
//var isL2 = false;
//var isL3 = false;
//var isPe = false;
2024-10-24 18:01:26 +08:00
//foreach (var item in Data)
datas.AsParallel().WithDegreeOfParallelism(8).ForAll(item =>
2024-10-24 18:01:26 +08:00
{
try
{
if (item == null) return;
var data = new StuffedDataModel();
data.OccPartId = item.OccPartId;
2024-11-02 11:56:50 +08:00
// 不再识别印记内容 取导线名称 20250327
var imprint = item.WireName;
if (!string.IsNullOrEmpty(imprint) && imprint.Contains("&"))
2024-10-24 18:01:26 +08:00
{
var splitImprint = imprint.Split('&');
2024-10-24 18:01:26 +08:00
if (splitImprint != null)
{
// 同时将印记内容拆分成两部分 imprint 只取第一部分
data.WireNumber = imprint = splitImprint[0];
2024-10-24 18:01:26 +08:00
data.DiscolorationDesc = splitImprint[1];
}
}
else
{
data.WireNumber = imprint;
2024-10-24 18:01:26 +08:00
}
data.Imprint = imprint;
2024-10-24 18:01:26 +08:00
data.WireColor = GetWireColorCode(item.DisplayColor, item.DisplayStripeColor);
2024-11-02 11:56:50 +08:00
data.WireModel = item.PartNumber.Contains(":") ? item.PartNumber.Split(':')[0] : item.PartNumber;
2024-10-24 18:01:26 +08:00
data.WireCode = item.ERPNr;
data.WireName = item.WireName;
2024-11-02 11:56:50 +08:00
更新多个文件,添加新功能和修复bug 在 `CheckTest.cs` 文件中,添加了三个新的测试方法:`CheckWireErpNrTest`、`ChecImprintTest` 和 `CheckSizeTest`。 在 `AssemblyInfo.cs` 文件中,将程序集版本和文件版本从 `1.0.0.5` 更新为 `1.0.0.6`。 在 `StuffTest.cs` 文件中,添加了一个新的断言 `Assert.IsTrue(result.Where(it => it.Imprint == "EC5L3").First().WireColor == "BK");`。 在 `LectotypeWindow.xaml` 文件中,添加了一个新的 `Window` 定义,包括资源字典、按钮和 `TabControl` 控件。 在 `LectotypeWindow.xaml.cs` 文件中,添加了 `LectotypeWindow` 类的定义和相关的事件处理方法。 在 `MainWindow.xaml` 文件中,移除了旧的样式定义,添加了新的资源字典引用,并更新了 `GroupBox` 为 `hc:Card` 控件,调整了按钮样式和 `DataGrid` 的样式。 在 `MainWindow.xaml` 文件中,更新了 `DataGrid` 的 `RowStyle` 和 `CellStyle`,并添加了新的触发器和样式设置。 在 `MainWindow.xaml` 文件中,更新了检查配置项的布局,使用 `hc:Card` 控件替换了 `GroupBox`,并调整了文本块的样式和布局。 在 `MainWindow.xaml.cs` 文件中: * 在 `MainWindow` 类中添加了对 `model.IsError` 的检查,如果为 `true`,则将 `model.IsIgnore` 设置为 `true`。 * 在 `Copy_Click` 方法中添加了 `try-catch` 块来捕获异常,并在捕获到异常时显示错误消息。 * 在 `GoToSource_Click` 方法中添加了 `try-catch` 块来捕获异常,并在捕获到异常时显示错误消息。 * 将 `Array.Empty<object>()` 替换为 `[]`。 在 `CheckedModel.cs` 文件中: * 注释掉了 `SetProperty` 方法中对 `Equals` 方法的检查。 在 `LectotypeModel.cs` 文件中: * 新增了 `LectotypeModel` 类,包含多个属性和相应的 `OnPropertyChanged` 调用。 在 `LineSegmentModel.cs` 文件中: * 新增了 `LineSegmentModel` 类,包含 `LineAxisNo`、`LineType` 和 `LineParagraph` 属性。 在 `AssemblyInfo.cs` 文件中: * 更新了程序集版本号,从 `1.0.0.5` 更新到 `1.0.0.6`。 在 `Sinvo.EplanHpD.Plugin.WPFUI.csproj` 文件中: * 添加了对 `EPLAN.Harness.MathLib` 的引用。 * 添加了 `LectotypeWindow.xaml` 和 `TestWindow.xaml` 及其对应的代码文件。 * 添加了 `HandyControl` 包的引用。 在 `TestWindow.xaml` 文件中: * 新增了 `TestWindow` 窗口的 XAML 定义,包含一个 `DataGrid` 控件。 在 `TestWindow.xaml.cs` 文件中: * 新增了 `TestWindow` 类,包含加载数据的方法。 在 `ExcelHelper.cs` 文件中: * 修改了 `GetWireTerminalMappingTable` 方法,使其在 `Prefix` 为 `null` 时也能匹配。 * 新增了 `GetWireInfo` 方法,用于获取线材信息。 在 `LectotypeViewModel.cs` 文件中: * 新增了 `LectotypeViewModel` 类,包含加载数据的方法和多个辅助方法。 在 `MainViewModel.Check.cs` 文件中: * 在 `ValidateItem` 方法中添加了对 `CheckWireErpNr` 方法的调用。 * 新增了 `CheckWireErpNr` 方法,用于检查线材料号。 * 在 `CheckNumberTube` 方法中添加了对 `item.Imprint` 是否为空的检查。 将 `data.AsParallel().WithDegreeOfParallelism(8).ForAll(entry =>` 修改为 `data.Where(it => it.OrigOcc == "OccWire" && !(it?.Properties["WireName"]?.GetDisplayValue()?.StartsWith("导线") ?? false)).AsParallel().WithDegreeOfParallelism(1).ForAll(entry =>`,以过滤出 `OrigOcc` 为 "OccWire" 且 `WireName` 不以 "导线" 开头的数据,并将并行度设置为 1。 将 `data.FrontTerminalModel = item.ConnectorFrom.Contains(":") ? item.ConnectorFrom.Split(':')[0] : item.ConnectorFrom;` 修改为 `data.FrontTerminalModel = item.ConnectorFrom?.Contains(":") ?? false ? item.ConnectorFrom.Split(':')[0] : item.ConnectorFrom ?? "";`,以处理 `ConnectorFrom` 可能为 null 的情况。 将 `data.RearTerminalModel = item.ConnectorTo.Contains(":") ? item.ConnectorTo.Split(':')[0] : item.ConnectorTo;` 修改为 `data.RearTerminalModel = item.ConnectorTo?.Contains(":") ?? false ? item.ConnectorTo.Split(':')[0] : item.ConnectorTo ?? "";`,以处理 `ConnectorTo` 可能为 null 的情况。 删除了 `if (insulationModels.Any()) { data.Insulation = insulationModels.First(); }` 语句块,简化了代码逻辑。 更新了 `GetWireColorCode` 方法中的注释,将原来的注释替换为更简洁的版本。
2024-11-07 12:14:44 +08:00
data.FrontTerminalModel = item.ConnectorFrom?.Contains(":") ?? false ? item.ConnectorFrom.Split(':')[0] : item.ConnectorFrom ?? "";
2024-10-24 18:01:26 +08:00
data.FrontTerminalMaterialCode = item.ConnectorFromERPNr;
2024-11-02 11:56:50 +08:00
2024-10-24 18:01:26 +08:00
data.FrontStripLength = item.StripLengthFrom;
2024-11-02 11:56:50 +08:00
更新多个文件,添加新功能和修复bug 在 `CheckTest.cs` 文件中,添加了三个新的测试方法:`CheckWireErpNrTest`、`ChecImprintTest` 和 `CheckSizeTest`。 在 `AssemblyInfo.cs` 文件中,将程序集版本和文件版本从 `1.0.0.5` 更新为 `1.0.0.6`。 在 `StuffTest.cs` 文件中,添加了一个新的断言 `Assert.IsTrue(result.Where(it => it.Imprint == "EC5L3").First().WireColor == "BK");`。 在 `LectotypeWindow.xaml` 文件中,添加了一个新的 `Window` 定义,包括资源字典、按钮和 `TabControl` 控件。 在 `LectotypeWindow.xaml.cs` 文件中,添加了 `LectotypeWindow` 类的定义和相关的事件处理方法。 在 `MainWindow.xaml` 文件中,移除了旧的样式定义,添加了新的资源字典引用,并更新了 `GroupBox` 为 `hc:Card` 控件,调整了按钮样式和 `DataGrid` 的样式。 在 `MainWindow.xaml` 文件中,更新了 `DataGrid` 的 `RowStyle` 和 `CellStyle`,并添加了新的触发器和样式设置。 在 `MainWindow.xaml` 文件中,更新了检查配置项的布局,使用 `hc:Card` 控件替换了 `GroupBox`,并调整了文本块的样式和布局。 在 `MainWindow.xaml.cs` 文件中: * 在 `MainWindow` 类中添加了对 `model.IsError` 的检查,如果为 `true`,则将 `model.IsIgnore` 设置为 `true`。 * 在 `Copy_Click` 方法中添加了 `try-catch` 块来捕获异常,并在捕获到异常时显示错误消息。 * 在 `GoToSource_Click` 方法中添加了 `try-catch` 块来捕获异常,并在捕获到异常时显示错误消息。 * 将 `Array.Empty<object>()` 替换为 `[]`。 在 `CheckedModel.cs` 文件中: * 注释掉了 `SetProperty` 方法中对 `Equals` 方法的检查。 在 `LectotypeModel.cs` 文件中: * 新增了 `LectotypeModel` 类,包含多个属性和相应的 `OnPropertyChanged` 调用。 在 `LineSegmentModel.cs` 文件中: * 新增了 `LineSegmentModel` 类,包含 `LineAxisNo`、`LineType` 和 `LineParagraph` 属性。 在 `AssemblyInfo.cs` 文件中: * 更新了程序集版本号,从 `1.0.0.5` 更新到 `1.0.0.6`。 在 `Sinvo.EplanHpD.Plugin.WPFUI.csproj` 文件中: * 添加了对 `EPLAN.Harness.MathLib` 的引用。 * 添加了 `LectotypeWindow.xaml` 和 `TestWindow.xaml` 及其对应的代码文件。 * 添加了 `HandyControl` 包的引用。 在 `TestWindow.xaml` 文件中: * 新增了 `TestWindow` 窗口的 XAML 定义,包含一个 `DataGrid` 控件。 在 `TestWindow.xaml.cs` 文件中: * 新增了 `TestWindow` 类,包含加载数据的方法。 在 `ExcelHelper.cs` 文件中: * 修改了 `GetWireTerminalMappingTable` 方法,使其在 `Prefix` 为 `null` 时也能匹配。 * 新增了 `GetWireInfo` 方法,用于获取线材信息。 在 `LectotypeViewModel.cs` 文件中: * 新增了 `LectotypeViewModel` 类,包含加载数据的方法和多个辅助方法。 在 `MainViewModel.Check.cs` 文件中: * 在 `ValidateItem` 方法中添加了对 `CheckWireErpNr` 方法的调用。 * 新增了 `CheckWireErpNr` 方法,用于检查线材料号。 * 在 `CheckNumberTube` 方法中添加了对 `item.Imprint` 是否为空的检查。 将 `data.AsParallel().WithDegreeOfParallelism(8).ForAll(entry =>` 修改为 `data.Where(it => it.OrigOcc == "OccWire" && !(it?.Properties["WireName"]?.GetDisplayValue()?.StartsWith("导线") ?? false)).AsParallel().WithDegreeOfParallelism(1).ForAll(entry =>`,以过滤出 `OrigOcc` 为 "OccWire" 且 `WireName` 不以 "导线" 开头的数据,并将并行度设置为 1。 将 `data.FrontTerminalModel = item.ConnectorFrom.Contains(":") ? item.ConnectorFrom.Split(':')[0] : item.ConnectorFrom;` 修改为 `data.FrontTerminalModel = item.ConnectorFrom?.Contains(":") ?? false ? item.ConnectorFrom.Split(':')[0] : item.ConnectorFrom ?? "";`,以处理 `ConnectorFrom` 可能为 null 的情况。 将 `data.RearTerminalModel = item.ConnectorTo.Contains(":") ? item.ConnectorTo.Split(':')[0] : item.ConnectorTo;` 修改为 `data.RearTerminalModel = item.ConnectorTo?.Contains(":") ?? false ? item.ConnectorTo.Split(':')[0] : item.ConnectorTo ?? "";`,以处理 `ConnectorTo` 可能为 null 的情况。 删除了 `if (insulationModels.Any()) { data.Insulation = insulationModels.First(); }` 语句块,简化了代码逻辑。 更新了 `GetWireColorCode` 方法中的注释,将原来的注释替换为更简洁的版本。
2024-11-07 12:14:44 +08:00
data.RearTerminalModel = item.ConnectorTo?.Contains(":") ?? false ? item.ConnectorTo.Split(':')[0] : item.ConnectorTo ?? "";
2024-11-02 11:56:50 +08:00
2024-10-24 18:01:26 +08:00
data.RearTerminalMaterialCode = item.ConnectorToERPNr;
2024-11-02 11:56:50 +08:00
2024-10-24 18:01:26 +08:00
data.RearStripLength = item.StripLengthTo;
//MID(输出报表!J2,1,FIND(" mm2",输出报表!J2)-1)
data.CrossSection = item.CoreDiameter.Replace(" mm2", "").Trim();
//=ROUND(MID(输出报表!H2,1,FIND(" mm",输出报表!H2)-1),0)+0
if (double.TryParse(item.Length.Replace(" mm", "").Trim(), out double wireLength))
data.WireLength = $"{Math.Round(wireLength, 0)}";
else
{
data.WireLength = string.Empty;
}
2024-10-24 18:01:26 +08:00
//data.WireNumber = item.Imprint;
data.Quantity = 1;
//"RV-"&A2&"-"&"1×"&J2&"-"&L2&"-"&"16×N2"&"-"&M2
//data.Model = $@"RV-{data.WireColor}-1×【Replace】{data.CrossSection}-{data.WireLength}-16×N2-{data.WireNumber}";
//data.Model = string.Format("RV-{0}-1{4}{1}-{2}-16×N2-{3}", data.WireColor, data.CrossSection, data.WireLength, data.WireNumber, "×");
data.Model = GenWireModel(data.WireColor, data.CrossSection, data.WireLength, data.WireNumber);
2024-10-24 18:01:26 +08:00
//data.IsChecked = true;
if (!string.IsNullOrEmpty(data.DiscolorationDesc))
{
var results = ExcelHelper.GetInsulationSoftSleeveTable(data.DiscolorationDesc);
var insulationModels = results as InsulationModel[] ?? results.ToArray();
if (insulationModels.Any())
{
data.Insulation = insulationModels.First();
}
}
else
{
data.Insulation = new InsulationModel();
}
2024-11-02 11:56:50 +08:00
var numberTubeModel = GetNumberTubeSpecification(data.CrossSection, data.WireColor);
var numberTube = ExcelHelper.GetNumberTube(numberTubeModel);
if (numberTube != null)
{
data.NumberTubeSpec = numberTube.TubeModel;
data.NumberTubeMaterialNo = numberTube.TubeMaterialCode;
}
2024-10-24 18:01:26 +08:00
{
if (data != null)
stuffedDatas.Add(data);
2024-10-24 18:01:26 +08:00
}
}
catch (Exception ex)
{
Trace.WriteLine($"{ex}");
}
});
2024-10-25 08:40:22 +08:00
//IsRequireCe = isAllCe;
//IsUseDiscoloration = isL1 && isL2 && isL3 && isPe;
//Trace.WriteLine($"isAllCE: {isAllCe}");
//Trace.WriteLine($"isSDIProject: {isL1 && isL2 && isL3 && isPe}");
return await Task.FromResult<List<StuffedDataModel>>([.. stuffedDatas]);
2024-10-24 18:01:26 +08:00
}
/// <summary>
2024-11-02 11:56:50 +08:00
/// 获取颜色代号
2024-10-24 18:01:26 +08:00
/// </summary>
2024-11-02 11:56:50 +08:00
/// <param name="displayColor">L3</param>
/// <param name="displayStripeColor">M3</param>
2024-10-24 18:01:26 +08:00
/// <returns></returns>
private static string GetWireColorCode(string displayColor, string displayStripeColor = null)
{
2024-11-02 11:56:50 +08:00
/*
=IF(AND(!L3="黄色"
更新多个文件,添加新功能和修复bug 在 `CheckTest.cs` 文件中,添加了三个新的测试方法:`CheckWireErpNrTest`、`ChecImprintTest` 和 `CheckSizeTest`。 在 `AssemblyInfo.cs` 文件中,将程序集版本和文件版本从 `1.0.0.5` 更新为 `1.0.0.6`。 在 `StuffTest.cs` 文件中,添加了一个新的断言 `Assert.IsTrue(result.Where(it => it.Imprint == "EC5L3").First().WireColor == "BK");`。 在 `LectotypeWindow.xaml` 文件中,添加了一个新的 `Window` 定义,包括资源字典、按钮和 `TabControl` 控件。 在 `LectotypeWindow.xaml.cs` 文件中,添加了 `LectotypeWindow` 类的定义和相关的事件处理方法。 在 `MainWindow.xaml` 文件中,移除了旧的样式定义,添加了新的资源字典引用,并更新了 `GroupBox` 为 `hc:Card` 控件,调整了按钮样式和 `DataGrid` 的样式。 在 `MainWindow.xaml` 文件中,更新了 `DataGrid` 的 `RowStyle` 和 `CellStyle`,并添加了新的触发器和样式设置。 在 `MainWindow.xaml` 文件中,更新了检查配置项的布局,使用 `hc:Card` 控件替换了 `GroupBox`,并调整了文本块的样式和布局。 在 `MainWindow.xaml.cs` 文件中: * 在 `MainWindow` 类中添加了对 `model.IsError` 的检查,如果为 `true`,则将 `model.IsIgnore` 设置为 `true`。 * 在 `Copy_Click` 方法中添加了 `try-catch` 块来捕获异常,并在捕获到异常时显示错误消息。 * 在 `GoToSource_Click` 方法中添加了 `try-catch` 块来捕获异常,并在捕获到异常时显示错误消息。 * 将 `Array.Empty<object>()` 替换为 `[]`。 在 `CheckedModel.cs` 文件中: * 注释掉了 `SetProperty` 方法中对 `Equals` 方法的检查。 在 `LectotypeModel.cs` 文件中: * 新增了 `LectotypeModel` 类,包含多个属性和相应的 `OnPropertyChanged` 调用。 在 `LineSegmentModel.cs` 文件中: * 新增了 `LineSegmentModel` 类,包含 `LineAxisNo`、`LineType` 和 `LineParagraph` 属性。 在 `AssemblyInfo.cs` 文件中: * 更新了程序集版本号,从 `1.0.0.5` 更新到 `1.0.0.6`。 在 `Sinvo.EplanHpD.Plugin.WPFUI.csproj` 文件中: * 添加了对 `EPLAN.Harness.MathLib` 的引用。 * 添加了 `LectotypeWindow.xaml` 和 `TestWindow.xaml` 及其对应的代码文件。 * 添加了 `HandyControl` 包的引用。 在 `TestWindow.xaml` 文件中: * 新增了 `TestWindow` 窗口的 XAML 定义,包含一个 `DataGrid` 控件。 在 `TestWindow.xaml.cs` 文件中: * 新增了 `TestWindow` 类,包含加载数据的方法。 在 `ExcelHelper.cs` 文件中: * 修改了 `GetWireTerminalMappingTable` 方法,使其在 `Prefix` 为 `null` 时也能匹配。 * 新增了 `GetWireInfo` 方法,用于获取线材信息。 在 `LectotypeViewModel.cs` 文件中: * 新增了 `LectotypeViewModel` 类,包含加载数据的方法和多个辅助方法。 在 `MainViewModel.Check.cs` 文件中: * 在 `ValidateItem` 方法中添加了对 `CheckWireErpNr` 方法的调用。 * 新增了 `CheckWireErpNr` 方法,用于检查线材料号。 * 在 `CheckNumberTube` 方法中添加了对 `item.Imprint` 是否为空的检查。 将 `data.AsParallel().WithDegreeOfParallelism(8).ForAll(entry =>` 修改为 `data.Where(it => it.OrigOcc == "OccWire" && !(it?.Properties["WireName"]?.GetDisplayValue()?.StartsWith("导线") ?? false)).AsParallel().WithDegreeOfParallelism(1).ForAll(entry =>`,以过滤出 `OrigOcc` 为 "OccWire" 且 `WireName` 不以 "导线" 开头的数据,并将并行度设置为 1。 将 `data.FrontTerminalModel = item.ConnectorFrom.Contains(":") ? item.ConnectorFrom.Split(':')[0] : item.ConnectorFrom;` 修改为 `data.FrontTerminalModel = item.ConnectorFrom?.Contains(":") ?? false ? item.ConnectorFrom.Split(':')[0] : item.ConnectorFrom ?? "";`,以处理 `ConnectorFrom` 可能为 null 的情况。 将 `data.RearTerminalModel = item.ConnectorTo.Contains(":") ? item.ConnectorTo.Split(':')[0] : item.ConnectorTo;` 修改为 `data.RearTerminalModel = item.ConnectorTo?.Contains(":") ?? false ? item.ConnectorTo.Split(':')[0] : item.ConnectorTo ?? "";`,以处理 `ConnectorTo` 可能为 null 的情况。 删除了 `if (insulationModels.Any()) { data.Insulation = insulationModels.First(); }` 语句块,简化了代码逻辑。 更新了 `GetWireColorCode` 方法中的注释,将原来的注释替换为更简洁的版本。
2024-11-07 12:14:44 +08:00
!M3="绿色")
"GNYE"
IF(AND(!L3="蓝色"
!M3="白色")
"BUWH"
IF(!L3="红色"
"RD"
IF(!L3="黄色"
"YE"
IF(!L3="蓝色"
"BU"
IF(!L3="绿色"
"GN"
IF(!L3="黑色"
"BK"
IF(!L3="灰色"
"GR"
IF(!L3="白色"
"WH"
IF(!L3="棕色"
"BN"
IF(!L3="橙色"
"OG"
IF(!L3="紫色"
"VT"
IF(!L3="绿/黄双色"
"GNYE"
IF(!L3="浅蓝色"
"LBU"
))))))))))))))
2024-11-02 11:56:50 +08:00
*/
2024-10-24 18:01:26 +08:00
string colorCode;
if (displayColor == "黄色" && displayStripeColor == "绿色")
{
return "GNYE";
}
2024-11-02 11:56:50 +08:00
else if (displayColor == "蓝色" && displayStripeColor == "白色")
{
return "BUWH";
}
else if (displayColor == "浅蓝色")
{
return "LBU";
}
2024-10-24 18:01:26 +08:00
else
{
colorCode = displayColor switch
{
"红色" => "RD",
"黄色" => "YE",
"蓝色" => "BU",
"绿色" => "GN",
"黑色" => "BK",
"灰色" => "GR",
"白色" => "WH",
"棕色" => "BN",
"橙色" => "OG",
"紫色" => "VT",
"绿/黄双色" => "GNYE",
"浅蓝色" => "BU",
_ => "",
};
}
return colorCode;
}
2024-11-02 11:56:50 +08:00
/// <summary>
/// 获取号码管规格
/// </summary>
public string GetNumberTubeSpecification(string crossSection, string colorCode)
{
if (double.TryParse(crossSection, out double crossSectionDouble))
if (crossSectionDouble >= 25)
{
if (colorCode == "YE") return "黄色热缩管φ12定制";
if (colorCode == "GN") return "绿色热缩管φ12定制";
if (colorCode == "RD") return "红色热缩管φ12定制";
if (colorCode == "BU") return "蓝色热缩管φ12定制";
if (colorCode == "GNYE") return "黄绿色热缩管φ12定制";
if (colorCode == "BK") return "白色号码管φ8定制";
}
//else if (crossSection == "0.3" || crossSection == "0.5" || crossSection == "0.75" || crossSection == "1")
else if (crossSectionDouble < 1.5)
{
return "白色号码管φ2.5/定制";
}
//else if (crossSection == "1.5")
else if (crossSectionDouble >= 1.5 && crossSectionDouble < 2.5)
{
return "白色号码管φ3定制";
}
//else if (crossSection == "2.5")
else if (crossSectionDouble >= 2.5 && crossSectionDouble < 4)
{
return "白色号码管φ4定制";
}
//else if (crossSection == "4")
else if (crossSectionDouble >= 4 && crossSectionDouble < 6)
{
return "白色号码管φ5定制";
}
//else if (crossSection == "6")
else if (crossSectionDouble >= 6 && crossSectionDouble < 10)
{
return "白色号码管φ6定制";
}
//else if (crossSection == "10")
else if (crossSectionDouble >= 10 && crossSectionDouble < 25)
{
return "白色号码管φ8定制";
}
2024-11-02 11:56:50 +08:00
return string.Empty;
}
2024-10-24 18:01:26 +08:00
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void GenExportData()
{
if (StuffedData.Any(it => !it.IsIgnore && (!it.IsChecked || it.IsError)))
{
FlexMessageBox.Info("存在未检查通过或是未做检查,不允许生成!");
return;
}
if (string.IsNullOrEmpty(MechanismNo) || string.IsNullOrEmpty(MechanismName))
{
FlexMessageBox.Info("机构信息未完善,不允许生成!");
return;
}
ExportData = [];
int seqNo = 1;
var dataList = new List<ExportModel>();
var nowDateStr = DateTime.Now;//.ToString("yyyy-MM-dd");
var nowDeliveryDateStr = DateTime.Now.AddDays(7);//.ToString("yyyy-MM-dd");
2024-10-24 18:01:26 +08:00
//foreach (var stuffedDataModel in StuffedData)
StuffedData.AsParallel().WithDegreeOfParallelism(1).ForAll(stuffedDataModel =>
{
//var numberTubeSpec = GetNumberTubeSpecification(stuffedDataModel.CrossSection, stuffedDataModel.WireColor);
2024-10-24 18:01:26 +08:00
var exportModel = new ExportModel
{
SeqNo = seqNo.ToString(),
MechanismName = MechanismName,
MechanismNo = MechanismNo,
DrawNo = stuffedDataModel.Model,
MaterialCode = "",
WireOrTubeSpec = stuffedDataModel.WireModel,
WireOrTubeMaterialNo = stuffedDataModel.WireCode,
WireOrTubeLength = Math.Round(double.Parse(stuffedDataModel.WireLength), 0),
NumberTubeSpec = stuffedDataModel.NumberTubeSpec,
NumberTubeMaterialNo = stuffedDataModel.NumberTubeMaterialNo,
2024-10-24 18:01:26 +08:00
NumberTubeContent = stuffedDataModel.Imprint,
FrontTerminalModel = stuffedDataModel.FrontTerminalModel,
FrontTerminalMaterialNo = stuffedDataModel.FrontTerminalMaterialCode,
FrontTerminalStripLength = stuffedDataModel.FrontStripLength,
RearTerminalModel = stuffedDataModel.RearTerminalModel,
RearTerminalMaterialNo = stuffedDataModel.RearTerminalMaterialCode,
RearTerminalStripLength = stuffedDataModel.RearStripLength,
InsulationModel = stuffedDataModel.Insulation?.Specification,
InsulationMaterialNo = stuffedDataModel.Insulation?.MaterialCode,
InsulationQuantity = string.IsNullOrEmpty(stuffedDataModel.Insulation?.MaterialCode) ? "" : "2",
OrderDate = nowDateStr,
DeliveryDate = nowDeliveryDateStr,
IsIgnoreError = stuffedDataModel.IsIgnore ? "是" : string.Empty
2024-10-24 18:01:26 +08:00
};
seqNo++;
dataList.Add(exportModel);
}
);
if (dataList != null && dataList.Any())
{
dataList.ForEach(ExportData.Add);
}
}
public void SearchByWireName(string wireName)
{
SearchedData.Clear();
if (string.IsNullOrEmpty(wireName))
{
stuffedData.ForEach(SearchedData.Add);
}
else
{
stuffedData.Where(it => it.WireName.Contains(wireName)
|| (it.RearTerminalModel?.Contains(wireName) ?? false)
|| (it.FrontTerminalModel?.Contains(wireName) ?? false)
)
.Where(it => it.IsError == OnlyShowError || !OnlyShowError)
.ForEach(SearchedData.Add);
}
}
2024-10-24 18:01:26 +08:00
private string GenWireModel(string wireColor, string crossSection, string wireLength, string wireNumber)
{
return $@"RV-{wireColor}-1×{crossSection}-{wireLength}-16×N2-{wireNumber}";
}
2024-10-24 18:01:26 +08:00
}