终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

148 lignes
4.7 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using BPASmart.Model;
  9. using Microsoft.Toolkit.Mvvm.ComponentModel;
  10. using Newtonsoft.Json;
  11. using System.Collections.ObjectModel;
  12. using System.Windows;
  13. using Microsoft.Toolkit.Mvvm.Input;
  14. using System.Reflection;
  15. namespace BPASmart.Model
  16. {
  17. public class VariableInfo : AlarmSet
  18. {
  19. public VariableInfo(params object[] s)
  20. {
  21. CancelCommand = new RelayCommand(() => { IsOpen = false; });
  22. ConfirmCommand = new RelayCommand(() => { IsOpen = false; });
  23. }
  24. public int ID { get { return _mID; } set { _mID = value; OnPropertyChanged(); } }
  25. private int _mID;
  26. /// <summary>
  27. /// 变量名
  28. /// </summary>
  29. public string VarName
  30. {
  31. get { return _mVarName.Trim()?.Replace(" ", ""); }
  32. set
  33. {
  34. _mVarName = value;
  35. OnPropertyChanged();
  36. DelegationNotifi.GetInstance.VarNameChanged?.Invoke(_mID);
  37. }
  38. }
  39. private string _mVarName = string.Empty;
  40. /// <summary>
  41. /// 地址
  42. /// </summary>
  43. public string Address
  44. {
  45. get { return _mAddress.Trim()?.Replace(" ", "").ToUpper(); }
  46. set
  47. {
  48. _mAddress = value;
  49. OnPropertyChanged();
  50. var address = AddressConvert.GetInstance.PlcConverter(GlobalVar.DeviceType, value);
  51. if (address.Address.Length > 0) RealAddress = address.Address;
  52. if (DataType.Length <= 0) DataType = address.DataType;
  53. }
  54. }
  55. private string _mAddress = string.Empty;
  56. /// <summary>
  57. /// 实际地址
  58. /// </summary>
  59. public string RealAddress { get; set; }
  60. /// <summary>
  61. /// 数据类型
  62. /// </summary>
  63. public string DataType { get { return _mDataType; } set { _mDataType = value; OnPropertyChanged(); } }
  64. private string _mDataType = string.Empty;
  65. /// <summary>
  66. /// 是否启用报警
  67. /// </summary>
  68. public bool IsEnableAlarm { get { return _mIsEnableAlarm; } set { _mIsEnableAlarm = value; OnPropertyChanged(); } }
  69. private bool _mIsEnableAlarm;
  70. /// <summary>
  71. /// 是否显示报警设置框
  72. /// </summary>
  73. public bool IsOpen
  74. {
  75. get { return _mIsOpen; }
  76. set
  77. {
  78. _mIsOpen = value;
  79. OnPropertyChanged();
  80. if (value)
  81. {
  82. if (DataType != "Bool")
  83. {
  84. AlarmType = EAlarmType.模拟量报警;
  85. if (AnalogAlarmModels == null || AnalogAlarmModels.Count <= 0)
  86. {
  87. AnalogAlarmModels.Clear();
  88. foreach (var item in Enum.GetNames(typeof(EAnalogAlarmType)))
  89. {
  90. if (AnalogAlarmModels.FirstOrDefault(p => p.AlarmTag == item) == null)
  91. {
  92. AnalogAlarmModels.Add(new AnalogAlarmModel()
  93. {
  94. AlarmTag = item,
  95. SortTag = (EAnalogAlarmType)Enum.Parse(typeof(EAnalogAlarmType), item)
  96. });
  97. }
  98. }
  99. }
  100. }
  101. else
  102. {
  103. AlarmType = EAlarmType.离散量报警;
  104. }
  105. }
  106. }
  107. }
  108. private bool _mIsOpen;
  109. /// <summary>
  110. /// 当前值
  111. /// </summary>
  112. [Newtonsoft.Json.JsonIgnore]
  113. public string CurrentValue { get { return _mCurrentValue; } set { _mCurrentValue = value; OnPropertyChanged(); } }
  114. private string _mCurrentValue = string.Empty;
  115. /// <summary>
  116. /// 验证是否OK
  117. /// </summary>
  118. public bool IsRedundant { get { return _mIsRedundant; } set { _mIsRedundant = value; OnPropertyChanged(); } }
  119. private bool _mIsRedundant;
  120. /// <summary>
  121. /// 报警设置框取消操作
  122. /// </summary>
  123. [Newtonsoft.Json.JsonIgnore]
  124. public RelayCommand CancelCommand { get; set; }
  125. /// <summary>
  126. /// 报警设置框确认按钮
  127. /// </summary>
  128. [Newtonsoft.Json.JsonIgnore]
  129. public RelayCommand ConfirmCommand { get; set; }
  130. }
  131. }