111 lines
3.4 KiB
C#
111 lines
3.4 KiB
C#
using SamplePre.Models;
|
|
using SamplePre.ProcessBll.BLL;
|
|
using SamplePre.ProcessBll.SampleSequence;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SamplePreSystem.UI.ViewModel.Monitor
|
|
{
|
|
public class UnitDetailViewModel : INotifyPropertyChanged
|
|
{
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
MonitorBll monitorBll = new MonitorBll();
|
|
|
|
CommunicationBll communicationBll = new CommunicationBll();
|
|
|
|
ActionMangerBll actionMangerBll = new ActionMangerBll();
|
|
|
|
string unitID;
|
|
public UnitDetailViewModel(string _unitID)
|
|
{
|
|
unitID = _unitID;
|
|
|
|
ShowActionInfo();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 动作状态信息
|
|
/// </summary>
|
|
private ObservableCollection<FaultInfo> faultInfos = new ObservableCollection<FaultInfo>();
|
|
|
|
public ObservableCollection<FaultInfo> FaultInfos
|
|
{
|
|
get { return faultInfos; }
|
|
set
|
|
{
|
|
faultInfos = value;
|
|
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 设置异常数据显示
|
|
/// </summary>
|
|
public void ShowActionInfo()
|
|
{
|
|
//读取下位机状态
|
|
ushort[] data1 = communicationBll.ReadSateData(100, 1000, 1000);
|
|
if (data1 == null || data1.Length <= 0) return;
|
|
|
|
//查询该单元中的动作
|
|
var sys_Actions = actionMangerBll.QuerySysAction();
|
|
sys_Actions = sys_Actions.Where(p => p.action_unit == unitID).ToList();
|
|
|
|
|
|
|
|
foreach (var sys_action in sys_Actions)
|
|
{
|
|
|
|
if (data1 != null && data1.Length > 0)
|
|
{
|
|
int state = data1[int.Parse(sys_action.plc_type)];
|
|
//state = 2;
|
|
if (state == 0)
|
|
{
|
|
FaultInfos.Add(new FaultInfo() { FaultName = sys_action.action_name, FaultDesc = "未连通", RunColor = WorkUnit.GetStateColor(state) });
|
|
}
|
|
if (state == 1)
|
|
{
|
|
FaultInfos.Add(new FaultInfo() { FaultName = sys_action.action_name, FaultDesc = "待机", RunColor = WorkUnit.GetStateColor(state) });
|
|
}
|
|
if (state == 2)
|
|
{
|
|
FaultInfos.Add(new FaultInfo() { FaultName = sys_action.action_name, FaultDesc = "运行", RunColor = WorkUnit.GetStateColor(state) });
|
|
}
|
|
if (state == 3)
|
|
{
|
|
FaultInfos.Add(new FaultInfo() { FaultName = sys_action.action_name, FaultDesc = "完成", RunColor = WorkUnit.GetStateColor(state) });
|
|
}
|
|
}
|
|
else
|
|
{
|
|
FaultInfos.Add(new FaultInfo() { FaultName = sys_action.action_name, FaultDesc = "待机", RunColor = WorkUnit.GetStateColor(0) });
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|