MatrixDevice2.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using IntelligentControlForsx.Common;
  11. namespace IntelligentControlForsx.MyControls
  12. {
  13. public partial class MatrixDevice2 : UserControl
  14. {
  15. public MatrixDevice2()
  16. {
  17. InitializeComponent();
  18. toolTip1.SetToolTip(this.btnTip, " ");
  19. }
  20. string deviceId;
  21. string deviceModel;
  22. string stationId;
  23. double windSpeed;
  24. double power;
  25. double status;
  26. long ts;
  27. [Browsable(true), Category("Data")]
  28. public string DeviceId
  29. {
  30. get
  31. {
  32. return deviceId;
  33. }
  34. set
  35. {
  36. deviceId = value;
  37. lblDeviceId.Text = value;
  38. }
  39. }
  40. [Browsable(true), Category("Data")]
  41. public double WindSpeed
  42. {
  43. get
  44. {
  45. return windSpeed;
  46. }
  47. set
  48. {
  49. windSpeed = value;
  50. lblWindSpeed.Text = Convert.ToDouble(value).ToString("0.00") + "m/s";
  51. }
  52. }
  53. [Browsable(true), Category("Data")]
  54. public double Power
  55. {
  56. get
  57. {
  58. return power;
  59. }
  60. set
  61. {
  62. power = value;
  63. lblPower.Text = Convert.ToDouble(value).ToString("0.00") + "KW";
  64. }
  65. }
  66. [Browsable(true), Category("Data")]
  67. public double Status
  68. {
  69. get
  70. {
  71. return status;
  72. }
  73. set
  74. {
  75. status = value;
  76. this.BackColor = getBackColor(value);
  77. }
  78. }
  79. public string DeviceModel
  80. {
  81. get
  82. {
  83. return deviceModel;
  84. }
  85. set
  86. {
  87. deviceModel = value;
  88. }
  89. }
  90. public string StationId
  91. {
  92. get
  93. {
  94. return stationId;
  95. }
  96. set
  97. {
  98. stationId = value;
  99. }
  100. }
  101. public long Ts
  102. {
  103. get
  104. {
  105. return ts;
  106. }
  107. set
  108. {
  109. ts = value;
  110. }
  111. }
  112. private Color getBackColor(double status)
  113. {
  114. int st = Convert.ToInt32(status);
  115. switch(st)
  116. {
  117. //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS
  118. case 0: //停机状态
  119. return Color.FromArgb(176, 151, 63);
  120. case 1: //上电状态
  121. return Color.FromArgb(177, 14, 126);
  122. case 2: //待机状态
  123. return Color.FromArgb(15, 141, 106);
  124. case 3: //启动状态
  125. return Color.FromArgb(14, 72, 91);
  126. case 4: //并网状态
  127. return Color.FromArgb(15, 135, 170);
  128. case 5: //故障状态
  129. return Color.FromArgb(170, 15, 59);
  130. case 6: //维护状态
  131. return Color.FromArgb(204, 83, 51);
  132. case 7: //离线状态
  133. return Color.FromArgb(134, 150, 165);
  134. default:
  135. return Color.Black;
  136. //风机六种状态: 限电5》运行1》待机0》维护4》故障2》离线3
  137. //case 5:
  138. //case 1:
  139. // return Color.FromArgb(0, 153, 204);
  140. //case 0:
  141. // return Color.FromArgb(51, 153, 51);
  142. //case 4:
  143. // return Color.FromArgb(255, 102, 0);
  144. //case 2:
  145. // return Color.FromArgb(204, 51, 51);
  146. //case 3:
  147. // return Color.FromArgb(153, 153, 153);
  148. //default:
  149. // return Color.FromArgb(153, 153, 153);
  150. }
  151. }
  152. public bool testShow(double status1, bool autoFilter, double minSpeed = 0, double maxSpeed =0, double minPower=0, double maxPower=0)
  153. {
  154. bool result = true;
  155. if (status1 == 9)
  156. {
  157. if (autoFilter)
  158. {
  159. if (minSpeed != 0 || maxSpeed != 0)
  160. {
  161. if (minPower == 0 && maxPower == 0)
  162. {
  163. if (windSpeed >= minSpeed && windSpeed <= maxSpeed)
  164. result = true;
  165. else
  166. result = false;
  167. }
  168. else
  169. {
  170. if (windSpeed >= minSpeed && windSpeed <= maxSpeed &&
  171. power >= minPower && power <= maxPower)
  172. result = true;
  173. else
  174. result = false;
  175. }
  176. }
  177. else
  178. {
  179. if (power >= minPower && power <= maxPower)
  180. result = true;
  181. else
  182. result = false;
  183. }
  184. }
  185. } else if (status1 == status)
  186. {
  187. if (autoFilter)
  188. {
  189. if (windSpeed >= minSpeed && windSpeed <= maxSpeed &&
  190. power >= minPower && power <= maxPower)
  191. result = true;
  192. else
  193. result = false;
  194. }
  195. } else
  196. {
  197. result = false;
  198. }
  199. return result;
  200. }
  201. private Rectangle dragBoxFromMouseDown;
  202. private void lblDeviceId_MouseDown(object sender, MouseEventArgs e)
  203. {
  204. //记录鼠标按下位置,DragSize获取以鼠标按钮的按下点为中心的矩形的宽度和高度,在该矩形内不会开始拖动操作。
  205. Size dragSize = SystemInformation.DragSize;
  206. //创建一个矩形区域(正方形)。以鼠标按下电为中心,以DragSize为高和宽的矩形。
  207. dragBoxFromMouseDown = new Rectangle(new System.Drawing.Point(e.X - (dragSize.Width / 2),
  208. e.Y - (dragSize.Height / 2)), dragSize);
  209. }
  210. private void lblDeviceId_MouseMove(object sender, MouseEventArgs e)
  211. {
  212. //如果鼠标位置在拖动矩形之外(就可以开始拖动了)
  213. if (dragBoxFromMouseDown != Rectangle.Empty &&
  214. !dragBoxFromMouseDown.Contains(e.X, e.Y))
  215. {
  216. //传递ListBox选中项并触发DoDragDrop事件(这里可以是ListDragSoure触发,也可以是ListDragTarget)
  217. //DoDragDrop 方法确定当前光标位置下的控件。然后它将检查该控件是否是有效的放置目标。
  218. DragDropEffects dropEffect = this.DoDragDrop(this.deviceId, DragDropEffects.All | DragDropEffects.Link);
  219. //if (dropEffect == DragDropEffects.Move)
  220. //{
  221. //}
  222. }
  223. }
  224. private void toolTip1_Popup(object sender, PopupEventArgs e)
  225. {
  226. System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
  227. //messageBoxCS.Append(this.deviceId);
  228. //messageBoxCS.AppendLine();
  229. //messageBoxCS.AppendFormat("当前状态:{0}", getStatusName(this.status));
  230. //messageBoxCS.AppendLine();
  231. //messageBoxCS.AppendFormat("开始时间:{0}, 时长 {1}分钟。", getBeginTime(this.ts));
  232. //messageBoxCS.AppendLine();
  233. //messageBoxCS.AppendFormat("\r\n持续时长:{0}分钟", getTimeSpan(this.ts));
  234. //messageBoxCS.AppendLine();
  235. //MessageBox.Show(messageBoxCS.ToString());
  236. this.toolTip1.ToolTipTitle = String.Format("开始时间:{0}, 时长 {1}分钟。", getBeginTime(this.ts), getTimeSpan(this.ts));
  237. }
  238. private string getStatusName(double status)
  239. {
  240. int st = Convert.ToInt32(status);
  241. switch (st)
  242. {
  243. //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS
  244. case 0: //停机状态
  245. return "停机";
  246. case 1: //上电状态
  247. return "上电";
  248. case 2: //待机状态
  249. return "待机";
  250. case 3: //启动状态
  251. return "启动";
  252. case 4: //并网状态
  253. return "并网";
  254. case 5: //故障状态
  255. return "故障";
  256. case 6: //维护状态
  257. return "维护";
  258. case 7: //离线状态
  259. return "离线";
  260. default:
  261. return "未知";
  262. }
  263. }
  264. private string getBeginTime(long ts)
  265. {
  266. if (ts < 10000)
  267. return "";
  268. DateTime dt = CommonMethod.ConvertIntDateTime(ts);
  269. return dt.ToString("yyyy-MM-dd hh:mm:ss");
  270. }
  271. private string getTimeSpan(long ts)
  272. {
  273. if (ts < 10000)
  274. return "";
  275. DateTime dt = CommonMethod.ConvertIntDateTime(ts);
  276. TimeSpan tts = DateTime.Now - dt;
  277. return (long)tts.TotalMinutes + "";
  278. }
  279. }
  280. }