重构生成线缆型号的逻辑

对生成线缆型号的逻辑进行了重构和优化:
- 在 `MainViewModel.Check.cs` 文件中:
  - 注释掉了原有的直接拼接字符串生成线缆型号的代码。
  - 新增了调用 `GenWireModel` 方法来生成线缆型号的代码,并在调用时对线缆长度进行了处理。
- 在 `MainViewModel.cs` 文件中:
  - 注释掉了原有的直接拼接字符串生成线缆型号的代码。
  - 新增了调用 `GenWireModel` 方法来生成线缆型号的代码。
  - 新增了 `GenWireModel` 方法,该方法接收线缆颜色、截面积、线缆长度和线缆编号作为参数,并返回生成的线缆型号字符串。
This commit is contained in:
lihanbo 2024-11-08 17:13:24 +08:00
parent 5afa7c0892
commit c2dca12e99
2 changed files with 12 additions and 3 deletions

View File

@ -250,10 +250,12 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
} }
else else
{ {
var newModel = $"RV-{item.WireColor}-1x{item.CrossSection}-{item.WireLength + 5}-16×N2-{item.WireNumber}"; //var newModel = $"RV-{item.WireColor}-1x{item.CrossSection}-{item.WireLength + 5}-16×N2-{item.WireNumber}";
var newModel = GenWireModel(item.WireColor, item.CrossSection, $"{double.Parse(item.WireLength) + 5}_add_5", item.WireNumber);
if (StuffedData.Any(it => it.Model == newModel)) if (StuffedData.Any(it => it.Model == newModel))
{ {
var newModel2 = $"RV-{item.WireColor}-1x{item.CrossSection}-{item.WireLength + 10}-16×N2-{item.WireNumber}"; //var newModel2 = $"RV-{item.WireColor}-1x{item.CrossSection}-{item.WireLength + 10}-16×N2-{item.WireNumber}";
var newModel2 = GenWireModel(item.WireColor, item.CrossSection, $"{double.Parse(item.WireLength) + 10}_add_10", item.WireNumber);
if (StuffedData.Any(it => it.Model == newModel2)) if (StuffedData.Any(it => it.Model == newModel2))
SetItemError(item, $"{item.Model} 该型号存在重复!\r\n"); SetItemError(item, $"{item.Model} 该型号存在重复!\r\n");
else else

View File

@ -288,7 +288,9 @@ public partial class MainViewModel : INotifyPropertyChanged
//data.WireNumber = item.Imprint; //data.WireNumber = item.Imprint;
data.Quantity = 1; data.Quantity = 1;
//"RV-"&A2&"-"&"1×"&J2&"-"&L2&"-"&"16×N2"&"-"&M2 //"RV-"&A2&"-"&"1×"&J2&"-"&L2&"-"&"16×N2"&"-"&M2
data.Model = $"RV-{data.WireColor}-1×{data.CrossSection}-{data.WireLength}-16×N2-{data.WireNumber}"; //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);
//data.IsChecked = true; //data.IsChecked = true;
if (!string.IsNullOrEmpty(data.DiscolorationDesc)) if (!string.IsNullOrEmpty(data.DiscolorationDesc))
{ {
@ -543,4 +545,9 @@ public partial class MainViewModel : INotifyPropertyChanged
} }
} }
private string GenWireModel(string wireColor, string crossSection, string wireLength, string wireNumber)
{
return $@"RV-{wireColor}-1×{crossSection}-{wireLength}-16×N2-{wireNumber}";
}
} }