Sic08/SicUI/Models/PMs/PMMfcTestViewModel.cs

147 lines
4.5 KiB
C#
Raw Normal View History

using Aitex.Core.Common.DeviceData;
using Aitex.Core.Util;
using MECF.Framework.Common.Aitex.Core.Common.DeviceData.IoDevice;
2023-06-28 17:26:01 +08:00
using MECF.Framework.Common.DataCenter;
using MECF.Framework.Common.OperationCenter;
using MECF.Framework.UI.Client.ClientBase;
using Newtonsoft.Json;
using OpenSEMI.ClientBase;
using System;
using System.Collections.Generic;
2023-06-28 17:26:01 +08:00
using System.Collections.ObjectModel;
using System.Globalization;
2023-06-28 17:26:01 +08:00
using System.IO.Ports;
using System.Linq;
2023-06-28 17:26:01 +08:00
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace SicUI.Models.PMs
{
public class PMMfcTestViewModel : SicModuleUIViewModelBase, ISupportMultipleSystem
{
public List<ControlNameData> ValueTestList { get; set; }
private string _strValueTestList;
[Subscription("MfcTest.ValueTestList")]
public string StrValueTestList
{
get { return _strValueTestList; }
set
{
if (_strValueTestList != value && value != null)
ValueTestList = JsonConvert.DeserializeObject<List<ControlNameData>>(value);
_strValueTestList = value;
}
}
public List<ControlNameData> PCTestList { get; set; }
private string _strPCTestList;
[Subscription("MfcTest.PCTestList")]
public string StrPCTestList
{
get { return _strPCTestList; }
set
{
if (_strPCTestList != value && value != null)
PCTestList = JsonConvert.DeserializeObject<List<ControlNameData>>(value);
_strPCTestList = value;
}
}
private string useMfcName;
/// <summary>
/// Combobox下拉框选择项
/// </summary>
2023-06-28 17:26:01 +08:00
public MfcTestData SelectedMfc { get; set; }
2023-06-28 17:26:01 +08:00
private List<MfcTestData> mfcTestList;
public List<MfcTestData> MfcTestList
{
get
2023-06-28 17:26:01 +08:00
{
if (useMfcName is not null && mfcTestList is not null && SelectedMfc is null)//整个列表刷新后SelectedMfc会为Null,这里需要重新赋值
2023-06-28 17:26:01 +08:00
{
mfcTestList.ForEach(t =>
{
if (useMfcName is not null && useMfcName == t.MfcName)
SelectedMfc = t;
});
}
return mfcTestList;
}
set
{
2023-06-28 17:26:01 +08:00
if (value is not null && SelectedMfc is null)//第一次打开时,给选择列表初始值
SelectedMfc = value[0];
mfcTestList = value;
}
}
private string _strMfcTestList;
[Subscription("MfcTest.MfcTestList")]
public string StrMfcTestList
{
get { return _strMfcTestList; }
set
{
if (_strMfcTestList != value && value != null)
MfcTestList = JsonConvert.DeserializeObject<List<MfcTestData>>(value);//整个界面MFC的测试结果
_strMfcTestList = value;
}
}
2023-06-28 17:26:01 +08:00
public void MfcStart()
{
useMfcName = SelectedMfc.MfcName;
2023-06-28 17:26:01 +08:00
InvokeClient.Instance.Service.DoOperation($"{SystemName}.MfcValueTest", SelectedMfc.MfcName);
}
public void DeleteMfcTest()
{
var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.Cancel, DialogType.CONFIRM,
"Are you sure delect all test data");
if (selection == DialogButton.Yes)
InvokeClient.Instance.Service.DoOperation($"{SystemName}.MfcTest.DeleteMfcTest");
}
}
/// <summary>
/// 输入数值检测
/// </summary>
class ColorConverter_IsTestOK : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || value.ToString().Length == 0)
return new SolidColorBrush(Colors.Gray);
if (value.ToString() == "OK")
return new SolidColorBrush(Colors.Green);
else if (value.ToString() == "NG")
return new SolidColorBrush(Colors.MediumVioletRed);
else
return new SolidColorBrush(Colors.Gray);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}