|
- 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;
-
- /// <summary>
- /// 变量名
- /// </summary>
- public string VarName
- {
- get { return _mVarName.Trim()?.Replace(" ", ""); }
- set
- {
- _mVarName = value;
- OnPropertyChanged();
- DelegationNotifi.GetInstance.VarNameChanged?.Invoke(_mID);
- }
- }
- private string _mVarName = string.Empty;
-
- /// <summary>
- /// 地址
- /// </summary>
- 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;
-
- /// <summary>
- /// 实际地址
- /// </summary>
- public string RealAddress { get; set; }
-
- /// <summary>
- /// 数据类型
- /// </summary>
- public string DataType { get { return _mDataType; } set { _mDataType = value; OnPropertyChanged(); } }
- private string _mDataType = string.Empty;
-
- /// <summary>
- /// 是否启用报警
- /// </summary>
- public bool IsEnableAlarm { get { return _mIsEnableAlarm; } set { _mIsEnableAlarm = value; OnPropertyChanged(); } }
- private bool _mIsEnableAlarm;
-
- /// <summary>
- /// 是否显示报警设置框
- /// </summary>
- 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;
-
- /// <summary>
- /// 当前值
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public string CurrentValue { get { return _mCurrentValue; } set { _mCurrentValue = value; OnPropertyChanged(); } }
- private string _mCurrentValue = string.Empty;
-
- /// <summary>
- /// 验证是否OK
- /// </summary>
- public bool IsRedundant { get { return _mIsRedundant; } set { _mIsRedundant = value; OnPropertyChanged(); } }
- private bool _mIsRedundant;
-
- /// <summary>
- /// 报警设置框取消操作
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public RelayCommand CancelCommand { get; set; }
-
- /// <summary>
- /// 报警设置框确认按钮
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public RelayCommand ConfirmCommand { get; set; }
-
- }
- }
|