CommonData.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.Serialization;
  6. using System.Xml.Serialization;
  7. namespace Aitex.Core.Util
  8. {
  9. /// <summary>
  10. /// Analog device data
  11. /// </summary>
  12. [DataContract]
  13. [Serializable]
  14. public class AnalogDeviceData
  15. {
  16. [DataMember]
  17. public string TechnicalName { get; set; }
  18. [DataMember]
  19. public string DeviceName { get; set; }
  20. [DataMember]
  21. public string DeviceId { get; set; }
  22. [DataMember]
  23. public string Unit { get; set; }
  24. [DataMember]
  25. public string Description { get; set; }
  26. /// <summary>
  27. /// 量程
  28. /// </summary>
  29. [DataMember]
  30. public double Scale { get; set; }
  31. /// <summary>
  32. /// 设定值
  33. /// </summary>
  34. [DataMember]
  35. public double SetPoint { get; set; }
  36. /// <summary>
  37. /// 实际反馈值
  38. /// </summary>
  39. [DataMember]
  40. public double FeedBack { get; set; }
  41. /// <summary>
  42. /// 默认值
  43. /// </summary>
  44. [DataMember]
  45. public double DefaultValue { get; set; }
  46. /// <summary>
  47. /// 是否有报警
  48. /// </summary>
  49. [DataMember]
  50. public bool IsWarning { get; set; }
  51. /// <summary>
  52. /// alarm或是erro时显示的信息
  53. /// </summary>
  54. [DataMember]
  55. public string ErroMessage { get; set; }
  56. private double _factor = 1.0;
  57. [DataMember]
  58. public double Factor { get { return _factor; } set { _factor = value; } }
  59. public override string ToString()
  60. {
  61. return FeedBack.ToString();
  62. }
  63. /// <summary>
  64. /// Default constructor.
  65. /// </summary>
  66. public AnalogDeviceData()
  67. {
  68. }
  69. /// <summary>
  70. /// Copy constructor of this object.
  71. /// </summary>
  72. /// <param name="deviceData"></param>
  73. public AnalogDeviceData(AnalogDeviceData deviceData)
  74. {
  75. TechnicalName = deviceData.TechnicalName;
  76. DeviceName = deviceData.DeviceName;
  77. DeviceId = deviceData.DeviceId;
  78. Unit = deviceData.Unit;
  79. Description = deviceData.Description;
  80. Scale = deviceData.Scale;
  81. SetPoint = deviceData.SetPoint;
  82. FeedBack = deviceData.FeedBack;
  83. DefaultValue = deviceData.DefaultValue;
  84. IsWarning = deviceData.IsWarning;
  85. ErroMessage = deviceData.ErroMessage;
  86. }
  87. }
  88. [Serializable]
  89. public class DataItem
  90. {
  91. public string DataName { get; set; }
  92. //public bool IsPreLoaded { get; set; }
  93. public List<DateTime> TimeStamp { get; set; }
  94. public List<float> RawData { get; set; }
  95. }
  96. /// <summary>
  97. /// 标识不需要数据库记录的数据类型
  98. /// </summary>
  99. [AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field)]
  100. public class DatabaseSaveIgnoreAttribute : Attribute { }
  101. public class ModuleStatusBackground
  102. {
  103. public const string Init = "Yellow";
  104. public const string Error = "OrangeRed";
  105. public const string Busy = "LawnGreen";
  106. public const string Idle = "White";
  107. public const string Offline = "Gray";
  108. public const string UnInstalled = "Gray";
  109. public static string GetStatusBackground(string status)
  110. {
  111. if (status != null)
  112. status = status.Trim().ToLower();
  113. switch (status)
  114. {
  115. case "error":
  116. return Error;
  117. case "idle":
  118. case "manual_idle":
  119. case "manual":
  120. return _dicCustom.ContainsKey(Idle) ? _dicCustom[Idle] : Idle;
  121. case "notconnect":
  122. case "init":
  123. return Init;
  124. case "offline":
  125. return Offline;
  126. case "notinstall":
  127. return UnInstalled;
  128. default:
  129. return Busy;
  130. }
  131. }
  132. private static Dictionary<string, string> _dicCustom = new Dictionary<string, string>();
  133. public static void CustomColor(string type, string color)
  134. {
  135. _dicCustom[type] = color;
  136. }
  137. }
  138. }