重命名StuffData方法参数并重构GetNumberTubeSpecification

重命名StuffData方法的参数和变量名称,改进并行处理和数据添加逻辑。重构GetNumberTubeSpecification方法,使用double.TryParse转换crossSection并返回相应规格。
This commit is contained in:
lihanbo 2024-11-07 17:44:28 +08:00
parent 65970751b3
commit ed520cd26b
1 changed files with 50 additions and 37 deletions

View File

@ -193,16 +193,17 @@ public partial class MainViewModel : INotifyPropertyChanged
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public async Task<List<StuffedDataModel>> StuffData(List<ReportModel> data)
public async Task<List<StuffedDataModel>> StuffData(List<ReportModel> datas)
{
var datas = new ConcurrentBag<StuffedDataModel>();
var
stuffedDatas = new ConcurrentBag<StuffedDataModel>();
//var isAllCe = true;
//var isL1 = false;
//var isL2 = false;
//var isL3 = false;
//var isPe = false;
//foreach (var item in Data)
data.AsParallel().WithDegreeOfParallelism(8).ForAll(item =>
datas.AsParallel().WithDegreeOfParallelism(8).ForAll(item =>
{
try
{
@ -282,7 +283,7 @@ public partial class MainViewModel : INotifyPropertyChanged
{
if (data != null)
datas.Add(data);
stuffedDatas.Add(data);
}
}
catch (Exception ex)
@ -296,7 +297,7 @@ public partial class MainViewModel : INotifyPropertyChanged
//IsUseDiscoloration = isL1 && isL2 && isL3 && isPe;
//Trace.WriteLine($"isAllCE: {isAllCe}");
//Trace.WriteLine($"isSDIProject: {isL1 && isL2 && isL3 && isPe}");
return await Task.FromResult<List<StuffedDataModel>>([.. datas]);
return await Task.FromResult<List<StuffedDataModel>>([.. stuffedDatas]);
}
/// <summary>
/// 获取颜色代号
@ -379,38 +380,50 @@ public partial class MainViewModel : INotifyPropertyChanged
/// </summary>
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定制";
}
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定制";
}
return string.Empty;
}