using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BPASmart.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
using System.Collections.ObjectModel;
using System.Windows;
using Microsoft.Toolkit.Mvvm.Input;
using System.Reflection;
namespace BPASmart.Model
{
public class VariableInfo : AlarmSet
{
public VariableInfo(params object[] s)
{
CancelCommand = new RelayCommand(() => { IsOpen = false; });
ConfirmCommand = new RelayCommand(() => { IsOpen = false; });
}
public int ID { get { return _mID; } set { _mID = value; OnPropertyChanged(); } }
private int _mID;
///
/// 变量名
///
public string VarName
{
get { return _mVarName.Trim()?.Replace(" ", ""); }
set
{
_mVarName = value;
OnPropertyChanged();
DelegationNotifi.GetInstance.VarNameChanged?.Invoke(_mID);
}
}
private string _mVarName = string.Empty;
///
/// 地址
///
public string Address
{
get { return _mAddress.Trim()?.Replace(" ", "").ToUpper(); }
set
{
_mAddress = value;
OnPropertyChanged();
var address = AddressConvert.GetInstance.PlcConverter(GlobalVar.DeviceType, value);
if (address.Address.Length > 0) RealAddress = address.Address;
if (DataType.Length <= 0) DataType = address.DataType;
}
}
private string _mAddress = string.Empty;
///
/// 实际地址
///
public string RealAddress { get; set; }
///
/// 数据类型
///
public string DataType { get { return _mDataType; } set { _mDataType = value; OnPropertyChanged(); } }
private string _mDataType = string.Empty;
///
/// 是否启用报警
///
public bool IsEnableAlarm { get { return _mIsEnableAlarm; } set { _mIsEnableAlarm = value; OnPropertyChanged(); } }
private bool _mIsEnableAlarm;
///
/// 是否显示报警设置框
///
public bool IsOpen
{
get { return _mIsOpen; }
set
{
_mIsOpen = value;
OnPropertyChanged();
if (value)
{
if (DataType != "Bool")
{
AlarmType = EAlarmType.模拟量报警;
if (AnalogAlarmModels == null || AnalogAlarmModels.Count <= 0)
{
AnalogAlarmModels.Clear();
foreach (var item in Enum.GetNames(typeof(EAnalogAlarmType)))
{
if (AnalogAlarmModels.FirstOrDefault(p => p.AlarmTag == item) == null)
{
AnalogAlarmModels.Add(new AnalogAlarmModel()
{
AlarmTag = item,
SortTag = (EAnalogAlarmType)Enum.Parse(typeof(EAnalogAlarmType), item)
});
}
}
}
}
else
{
AlarmType = EAlarmType.离散量报警;
}
}
}
}
private bool _mIsOpen;
///
/// 当前值
///
[Newtonsoft.Json.JsonIgnore]
public string CurrentValue { get { return _mCurrentValue; } set { _mCurrentValue = value; OnPropertyChanged(); } }
private string _mCurrentValue = string.Empty;
///
/// 验证是否OK
///
public bool IsRedundant { get { return _mIsRedundant; } set { _mIsRedundant = value; OnPropertyChanged(); } }
private bool _mIsRedundant;
///
/// 报警设置框取消操作
///
[Newtonsoft.Json.JsonIgnore]
public RelayCommand CancelCommand { get; set; }
///
/// 报警设置框确认按钮
///
[Newtonsoft.Json.JsonIgnore]
public RelayCommand ConfirmCommand { get; set; }
}
}