From 09c4e983bd1916488f8c68829a60fe050478d5bd Mon Sep 17 00:00:00 2001 From: lihanbo Date: Sat, 2 Nov 2024 11:56:50 +0800 Subject: [PATCH] =?UTF-8?q?105040=20=E5=A2=9E=E5=8A=A0=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sinvo.EplanHpD.Plugin.Test/CheckTest.cs | 3 + .../Sinvo.EplanHpD.Plugin.Test.csproj | 1 + Sinvo.EplanHpD.Plugin.Test/StuffTest.cs | 102 ++++++++++++ Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml | 1 + .../MainWindow.xaml.cs | 1 - .../Utils/ExcelHelper.cs | 4 +- .../ViewModel/MainViewModel.cs | 151 ++++++++++++------ 7 files changed, 212 insertions(+), 51 deletions(-) create mode 100644 Sinvo.EplanHpD.Plugin.Test/StuffTest.cs diff --git a/Sinvo.EplanHpD.Plugin.Test/CheckTest.cs b/Sinvo.EplanHpD.Plugin.Test/CheckTest.cs index a8a834f..5eb2617 100644 --- a/Sinvo.EplanHpD.Plugin.Test/CheckTest.cs +++ b/Sinvo.EplanHpD.Plugin.Test/CheckTest.cs @@ -205,5 +205,8 @@ w_00196 BK 黑色RV1.5-CE/定制 42012300001005 C45-1.5-CE/定制 4202010000 Assert.IsFalse(!stuffedData.IsError); } + + + } } diff --git a/Sinvo.EplanHpD.Plugin.Test/Sinvo.EplanHpD.Plugin.Test.csproj b/Sinvo.EplanHpD.Plugin.Test/Sinvo.EplanHpD.Plugin.Test.csproj index ce9a6b2..5eff753 100644 --- a/Sinvo.EplanHpD.Plugin.Test/Sinvo.EplanHpD.Plugin.Test.csproj +++ b/Sinvo.EplanHpD.Plugin.Test/Sinvo.EplanHpD.Plugin.Test.csproj @@ -51,6 +51,7 @@ + diff --git a/Sinvo.EplanHpD.Plugin.Test/StuffTest.cs b/Sinvo.EplanHpD.Plugin.Test/StuffTest.cs new file mode 100644 index 0000000..392d110 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.Test/StuffTest.cs @@ -0,0 +1,102 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Sinvo.EplanHpD.Plugin.WPFUI.Models; +using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; +using System.Collections.Generic; +using System.Linq; + +namespace Sinvo.EplanHpD.Plugin.Test +{ + [TestClass] + public class StuffTest + { + [TestMethod("数据处理测试")] + public void StuffedTest() + { + + var vm = new MainViewModel(); + var result = vm.StuffData(new List + { + /* +序号 项目 归属机构 电缆名称 规格型号 品牌 电线标码 长度(mm) 外径 截面积 物料编号 电线颜色 电线条颜色 导线名称 绞线 前端子型号 前端子物料编码 前端剥线长度 后端子型号 后端子物料编码 后端剥线长度 +1 放卷2 隔膜放卷_&G000111006-033_DQ 黑色RV10.0/定制 EC5L1 593.9 mm 6.7 mm 10 mm2 42020100000222 浅蓝色 电线 C45-10/定制 42020100000386 8 mm RNB8-8/定制 42020100000148 8 mm +2 放卷2 隔膜放卷_&G000111006-033_DQ 黑色RV10.0/定制 EC5L2 581.8 mm 6.7 mm 10 mm2 42020100000222 蓝色 白色 电线 RNB8-8/定制 42020100000148 8 mm C45-10/定制 42020100000386 8 mm +3 放卷2 隔膜放卷_&G000111006-033_DQ 黑色RV10.0/定制 EC5L3 584.1 mm 6.7 mm 10 mm2 42020100000222 黑色 电线 C45-10/定制 42020100000386 8 mm RNB8-8/定制 42020100000148 8 mm + + */ + new ReportModel + { +Project = "放卷2", + Document = "隔膜放卷_&G000111006-033_DQ", + CableName = "", + PartNumber = "黑色RV10.0/定制", + ManufacturerCompany = "", + Imprint = "EC5L1", + Length = "593.9 mm", + OutsideDiameter = "6.7 mm", + CoreDiameter = "10 mm2", + ERPNr = "42020100000222", + DisplayColor = "浅蓝色", + DisplayStripeColor = "", + WireName = "电线", + WireTwisted = "", + ConnectorFrom = "C45-10/定制", + ConnectorFromERPNr = "42020100000386", + StripLengthFrom = "8 mm", + ConnectorTo = "RNB8-8/定制", + ConnectorToERPNr = "42020100000148", + StripLengthTo = "8 mm" + }, + new ReportModel + { + Project = "放卷2", + Document = "隔膜放卷_&G000111006-033_DQ", + CableName = "", + PartNumber = "黑色RV10.0/定制", + ManufacturerCompany = "", + Imprint = "EC5L2", + Length = "581.8 mm", + OutsideDiameter = "6.7 mm", + CoreDiameter = "10 mm2", + ERPNr = "42020100000222", + DisplayColor = "蓝色", + DisplayStripeColor = "白色", + WireName = "电线", + WireTwisted = "", + ConnectorFrom = "RNB8-8/定制", + ConnectorFromERPNr = "42020100000148", + StripLengthFrom = "8 mm", + ConnectorTo = "C45-10/定制", + ConnectorToERPNr = "42020100000386", + StripLengthTo = "8 mm" + }, + new ReportModel + { + Project = "放卷2", + Document = "隔膜放卷_&G000111006-033_DQ", + CableName = "", + PartNumber = "黑色RV10.0/定制", + ManufacturerCompany = "", + Imprint = "EC5L3", + Length = "584.1 mm", + OutsideDiameter = "6.7 mm", + CoreDiameter = "10 mm2", + ERPNr = "42020100000222", + DisplayColor = "黑色", + DisplayStripeColor = "", + WireName = "电线", + WireTwisted = "", + ConnectorFrom = "C45-10/定制", + ConnectorFromERPNr = "42020100000386", + StripLengthFrom = "8 mm", + ConnectorTo = "RNB8-8/定制", + ConnectorToERPNr = "42020100000148", + StripLengthTo = "8 mm" + } + }).Result; + Assert.IsTrue(result.Count == 3); + Assert.IsTrue(result.Where(it => it.Imprint == "EC5L1").First().WireColor == "LBU"); + Assert.IsTrue(result.Where(it => it.Imprint == "EC5L2").First().WireColor == "BUWH"); + Assert.IsTrue(result.Where(it => it.Imprint == "EC5L3").First().WireColor == "BK"); + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml index 1cac55f..26134e6 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml @@ -446,6 +446,7 @@ + diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs index eb3b87f..67bee0e 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs @@ -387,7 +387,6 @@ public partial class MainWindow : Window //flexDesigner. flexDesigner.SelectSet.OnSelectionChanged(); } - } } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ExcelHelper.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ExcelHelper.cs index f774097..aafafce 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ExcelHelper.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ExcelHelper.cs @@ -66,10 +66,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils // .ToList(); //} - public static dynamic GetNumberTube(string wireModel) + public static dynamic GetNumberTube(string tubeModel) { CheckAndGetCache(); - return _terminalMappingCache.Where(item => item.WireModelSpecification == wireModel) + return _terminalMappingCache.Where(item => item.TubeModel == tubeModel) .Select(item => new { item.TubeModel, diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs index dd0c43c..b610635 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs @@ -188,6 +188,11 @@ public partial class MainViewModel : INotifyPropertyChanged ); return Task.FromResult(reportDatas.ToList()); } + /// + /// 清理数据 + /// + /// + /// public async Task> StuffData(List data) { var datas = new ConcurrentBag(); @@ -205,13 +210,7 @@ public partial class MainViewModel : INotifyPropertyChanged var data = new StuffedDataModel(); - //if (!string.IsNullOrEmpty(item.PartNumber)) - //{ - // if (!item.PartNumber.Contains("-CE/")) - // { - // isAllCe = false; - // } - //} + if (!string.IsNullOrEmpty(item.Imprint) && item.Imprint.Contains("&")) { var splitImprint = item.Imprint.Split('&'); @@ -228,34 +227,21 @@ public partial class MainViewModel : INotifyPropertyChanged } data.Imprint = item.Imprint; data.WireColor = GetWireColorCode(item.DisplayColor, item.DisplayStripeColor); - //if (string.IsNullOrEmpty(data.WireColor)) - //{ - // data.IsError = true; - // data.CheckedMsg += "线色不符合规范\r\n"; - //} - data.WireModel = item.PartNumber; + + data.WireModel = item.PartNumber.Contains(":") ? item.PartNumber.Split(':')[0] : item.PartNumber; + data.WireCode = item.ERPNr; data.WireName = item.WireName; - //if (string.IsNullOrEmpty(data.WireCode)) - //{ - // data.IsError = true; - // data.CheckedMsg += "线材编码为空\r\n"; - //} - data.FrontTerminalModel = item.ConnectorFrom; + + data.FrontTerminalModel = item.ConnectorFrom.Contains(":") ? item.ConnectorFrom.Split(':')[0] : item.ConnectorFrom; data.FrontTerminalMaterialCode = item.ConnectorFromERPNr; - //if (string.IsNullOrEmpty(data.FrontTerminalMaterialCode)) - //{ - // data.IsError = true; - // data.CheckedMsg += "前端子物料编码为空\r\n"; - //} + data.FrontStripLength = item.StripLengthFrom; - data.RearTerminalModel = item.ConnectorTo; + + data.RearTerminalModel = item.ConnectorTo.Contains(":") ? item.ConnectorTo.Split(':')[0] : item.ConnectorTo; + data.RearTerminalMaterialCode = item.ConnectorToERPNr; - //if (string.IsNullOrEmpty(data.RearTerminalMaterialCode)) - //{ - // data.IsError = true; - // data.CheckedMsg = "后端子物料编码为空\r\n"; - //} + data.RearStripLength = item.StripLengthTo; //MID(输出报表!J2,1,FIND(" mm2",输出报表!J2)-1) @@ -286,7 +272,8 @@ public partial class MainViewModel : INotifyPropertyChanged { data.Insulation = new InsulationModel(); } - var numberTube = ExcelHelper.GetNumberTube(data.WireModel); + var numberTubeModel = GetNumberTubeSpecification(data.CrossSection, data.WireColor); + var numberTube = ExcelHelper.GetNumberTube(numberTubeModel); if (numberTube != null) { @@ -294,18 +281,6 @@ public partial class MainViewModel : INotifyPropertyChanged data.NumberTubeMaterialNo = numberTube.TubeMaterialCode; } - - - //if (datas.Any(it => it.Model == data.Model)) - //{ - - // var existsItem = datas.First(it => it.Model == data.Model); - // if (existsItem != null) - // { - // existsItem.Quantity += 1; - // } - //} - //else { if (data != null) datas.Add(data); @@ -325,21 +300,60 @@ public partial class MainViewModel : INotifyPropertyChanged return await Task.FromResult>([.. datas]); } /// - /// 获取颜色代号 - /// TODO : 改成从excel中读取基本资料 + /// 获取颜色代号 /// - /// - /// + /// L3 + /// M3 /// private static string GetWireColorCode(string displayColor, string displayStripeColor = null) { - + /* + =IF(AND(输出报表!L3="黄色" +输出报表!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" +)))))))))))))) + */ string colorCode; if (displayColor == "黄色" && displayStripeColor == "绿色") { return "GNYE"; } + else if (displayColor == "蓝色" && displayStripeColor == "白色") + { + return "BUWH"; + } + else if (displayColor == "浅蓝色") + { + return "LBU"; + } else { colorCode = displayColor switch @@ -361,6 +375,47 @@ public partial class MainViewModel : INotifyPropertyChanged } return colorCode; } + /// + /// 获取号码管规格 + /// + public string GetNumberTubeSpecification(string crossSection, string colorCode) + { + if (crossSection == "16") + { + 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/定制"; + } + else if (crossSection == "0.3" || crossSection == "0.5" || crossSection == "0.75" || crossSection == "1") + { + return "白色号码管φ2.5/定制"; + } + else if (crossSection == "1.5") + { + return "白色号码管φ3/定制"; + } + else if (crossSection == "2.5") + { + return "白色号码管φ4/定制"; + } + else if (crossSection == "4") + { + return "白色号码管φ5/定制"; + } + else if (crossSection == "6") + { + return "白色号码管φ6/定制"; + } + else if (crossSection == "10") + { + return "白色号码管φ8/定制"; + } + + return string.Empty; + } + public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName)