添加异常处理并重构 MainViewModel.Check.cs
在 MainViewModel.Check.cs 文件中添加了多个 try-catch 块,以捕获异常并设置错误信息。重构了 ValidateItem、CheckWireErpNr 和 CheckRequiredFields 方法的代码逻辑,确保在不同情况下设置相应的错误信息。
This commit is contained in:
parent
c2dca12e99
commit
5bc1533d9b
|
@ -17,8 +17,15 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
|
|||
item.IsError = false;
|
||||
item.ErrorCount = 0;
|
||||
item.CheckedMsg = "";
|
||||
try
|
||||
{
|
||||
ValidateItem(item);
|
||||
|
||||
ValidateItem(item);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SetItemError(item, ex.Message);
|
||||
}
|
||||
|
||||
item.IsChecked = true;
|
||||
});
|
||||
|
@ -72,28 +79,36 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
|
|||
/// <param name="item"></param>
|
||||
public void CheckWireErpNr(StuffedDataModel item)
|
||||
{
|
||||
var wireInfos = ExcelHelper.GetWireInfo(item.WireModel);
|
||||
if (wireInfos != null && wireInfos.Count() == 1)
|
||||
try
|
||||
{
|
||||
var wireInfo = wireInfos.First();
|
||||
if (wireInfo != null)
|
||||
var wireInfos = ExcelHelper.GetWireInfo(item.WireModel);
|
||||
if (wireInfos != null && wireInfos.Count() == 1)
|
||||
{
|
||||
if (wireInfo.WireMaterialCode != item.WireCode)
|
||||
var wireInfo = wireInfos.First();
|
||||
if (wireInfo != null)
|
||||
{
|
||||
SetItemError(item, "线材料号错误!\r\n");
|
||||
if (wireInfo.WireMaterialCode != item.WireCode)
|
||||
{
|
||||
SetItemError(item, "线材料号错误!\r\n");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (wireInfos.Count() > 1)
|
||||
{
|
||||
SetItemError(item, "该型号线材存在重复编码!\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetItemError(item, "该型号线材不存在配对表中!\r\n");
|
||||
else if (wireInfos.Count() > 1)
|
||||
{
|
||||
SetItemError(item, "该型号线材存在重复编码!\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetItemError(item, "该型号线材不存在配对表中!\r\n");
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SetItemError(item, ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 检查号码管
|
||||
|
@ -112,25 +127,32 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
|
|||
/// <param name="item"></param>
|
||||
private void CheckRequiredFields(StuffedDataModel item)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item.RearTerminalMaterialCode))
|
||||
try
|
||||
{
|
||||
SetItemError(item, "后端子物料编码为空\r\n");
|
||||
if (string.IsNullOrEmpty(item.RearTerminalMaterialCode))
|
||||
{
|
||||
SetItemError(item, "后端子物料编码为空\r\n");
|
||||
}
|
||||
if (string.IsNullOrEmpty(item.FrontTerminalMaterialCode))
|
||||
{
|
||||
SetItemError(item, "前端子物料编码为空\r\n");
|
||||
}
|
||||
if (string.IsNullOrEmpty(item.WireColor))
|
||||
{
|
||||
SetItemError(item, "线色不符合规范\r\n");
|
||||
}
|
||||
if (string.IsNullOrEmpty(item.WireCode))
|
||||
{
|
||||
SetItemError(item, "线材编码为空\r\n");
|
||||
}
|
||||
if (string.IsNullOrEmpty(item.Imprint))
|
||||
{
|
||||
SetItemError(item, "印记(线号)内容为空\r\n");
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(item.FrontTerminalMaterialCode))
|
||||
catch (Exception ex)
|
||||
{
|
||||
SetItemError(item, "前端子物料编码为空\r\n");
|
||||
}
|
||||
if (string.IsNullOrEmpty(item.WireColor))
|
||||
{
|
||||
SetItemError(item, "线色不符合规范\r\n");
|
||||
}
|
||||
if (string.IsNullOrEmpty(item.WireCode))
|
||||
{
|
||||
SetItemError(item, "线材编码为空\r\n");
|
||||
}
|
||||
if (string.IsNullOrEmpty(item.Imprint))
|
||||
{
|
||||
SetItemError(item, "印记(线号)内容为空\r\n");
|
||||
SetItemError(item, ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue