MatrixDevice4.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. using IntelligentControlForsx.Service;
  12. using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
  13. namespace IntelligentControlForsx.MyControls
  14. {
  15. public partial class MatrixDevice4 : UserControl
  16. {
  17. public MatrixDevice4()
  18. {
  19. SetStyle(ControlStyles.UserPaint, true);
  20. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.  
  21. SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲  
  22. InitializeComponent();
  23. toolTip1.SetToolTip(this.btnTip, " ");
  24. SetStyle(ControlStyles.UserPaint, true);
  25. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.  
  26. SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲  
  27. }
  28. protected override void WndProc(ref Message m)
  29. {
  30. if (m.Msg == 0x0014) // 禁掉清除背景消息
  31. return;
  32. base.WndProc(ref m);
  33. }
  34. string deviceId;
  35. string deviceModel;
  36. string stationId;
  37. double windSpeed;
  38. double power;
  39. double status;
  40. bool isLock;
  41. long ts;
  42. [Browsable(true), Category("Data")]
  43. public string DeviceId
  44. {
  45. get
  46. {
  47. return deviceId;
  48. }
  49. set
  50. {
  51. deviceId = value;
  52. lblDeviceId.Text = value;
  53. }
  54. }
  55. [Browsable(true), Category("Data")]
  56. public double WindSpeed
  57. {
  58. get
  59. {
  60. return windSpeed;
  61. }
  62. set
  63. {
  64. windSpeed = value;
  65. lblWindSpeed.Text = Convert.ToDouble(value).ToString("0.00") + "m/s";
  66. }
  67. }
  68. [Browsable(true), Category("Data")]
  69. public double Power
  70. {
  71. get
  72. {
  73. return power;
  74. }
  75. set
  76. {
  77. power = value;
  78. lblPower.Text = Convert.ToDouble(value).ToString("0.00") + "kw";
  79. }
  80. }
  81. [Browsable(true), Category("Data")]
  82. public double Status
  83. {
  84. get
  85. {
  86. return status;
  87. }
  88. set
  89. {
  90. status = value;
  91. this.BackColor = getBackColor(value);
  92. this.pTop.BackColor = getBackColor(value);
  93. }
  94. }
  95. public bool IsLock
  96. {
  97. set
  98. {
  99. if (value)
  100. this.pBack.BackColor = Color.Yellow;
  101. else
  102. this.pBack.BackColor = pTop.BackColor;
  103. isLock = value;
  104. }
  105. get { return isLock; }
  106. }
  107. private double lokcValue;
  108. public double LockValue
  109. {
  110. get { return lokcValue; }
  111. set { lokcValue = value; }
  112. }
  113. public string DeviceModel
  114. {
  115. get
  116. {
  117. return deviceModel;
  118. }
  119. set
  120. {
  121. deviceModel = value;
  122. }
  123. }
  124. public string StationId
  125. {
  126. get
  127. {
  128. return stationId;
  129. }
  130. set
  131. {
  132. stationId = value;
  133. }
  134. }
  135. public long Ts
  136. {
  137. get
  138. {
  139. return ts;
  140. }
  141. set
  142. {
  143. ts = value;
  144. }
  145. }
  146. private Color getBackColor(double status)
  147. {
  148. int st = Convert.ToInt32(status);
  149. switch (st)
  150. {
  151. //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS
  152. case 0: //停机状态
  153. return Color.FromArgb(176, 151, 63);
  154. case 1: //上电状态
  155. return Color.FromArgb(177, 14, 126);
  156. case 2: //待机状态
  157. return Color.FromArgb(15, 141, 106);
  158. case 3: //启动状态
  159. return Color.FromArgb(14, 72, 91);
  160. case 4: //并网状态
  161. return Color.FromArgb(15, 135, 170);
  162. case 5: //故障状态
  163. return Color.FromArgb(170, 15, 59);
  164. case 6: //维护状态
  165. return Color.FromArgb(204, 83, 51);
  166. case 7: //离线状态
  167. return Color.FromArgb(134, 150, 165);
  168. default:
  169. return Color.Black;
  170. //风机六种状态: 限电5》运行1》待机0》维护4》故障2》离线3
  171. //case 5:
  172. //case 1:
  173. // return Color.FromArgb(0, 153, 204);
  174. //case 0:
  175. // return Color.FromArgb(51, 153, 51);
  176. //case 4:
  177. // return Color.FromArgb(255, 102, 0);
  178. //case 2:
  179. // return Color.FromArgb(204, 51, 51);
  180. //case 3:
  181. // return Color.FromArgb(153, 153, 153);
  182. //default:
  183. // return Color.FromArgb(153, 153, 153);
  184. }
  185. }
  186. public bool testShow(double status1, bool autoFilter, double minSpeed = 0, double maxSpeed = 0, double minPower = 0, double maxPower = 0)
  187. {
  188. bool result = true;
  189. if (status1 == 9)
  190. {
  191. if (autoFilter)
  192. {
  193. if (minSpeed != 0 || maxSpeed != 0)
  194. {
  195. if (minPower == 0 && maxPower == 0)
  196. {
  197. if (windSpeed >= minSpeed && windSpeed <= maxSpeed)
  198. result = true;
  199. else
  200. result = false;
  201. }
  202. else
  203. {
  204. if (windSpeed >= minSpeed && windSpeed <= maxSpeed &&
  205. power >= minPower && power <= maxPower)
  206. result = true;
  207. else
  208. result = false;
  209. }
  210. }
  211. else
  212. {
  213. if (power >= minPower && power <= maxPower)
  214. result = true;
  215. else
  216. result = false;
  217. }
  218. }
  219. }
  220. else if (status1 == status)
  221. {
  222. if (autoFilter)
  223. {
  224. if (windSpeed >= minSpeed && windSpeed <= maxSpeed &&
  225. power >= minPower && power <= maxPower)
  226. result = true;
  227. else
  228. result = false;
  229. }
  230. }
  231. else
  232. {
  233. result = false;
  234. }
  235. return result;
  236. }
  237. private Rectangle dragBoxFromMouseDown;
  238. private void lblDeviceId_MouseDown(object sender, MouseEventArgs e)
  239. {
  240. //记录鼠标按下位置,DragSize获取以鼠标按钮的按下点为中心的矩形的宽度和高度,在该矩形内不会开始拖动操作。
  241. Size dragSize = SystemInformation.DragSize;
  242. //创建一个矩形区域(正方形)。以鼠标按下电为中心,以DragSize为高和宽的矩形。
  243. dragBoxFromMouseDown = new Rectangle(new System.Drawing.Point(e.X - (dragSize.Width / 2),
  244. e.Y - (dragSize.Height / 2)), dragSize);
  245. }
  246. private void lblDeviceId_MouseMove(object sender, MouseEventArgs e)
  247. {
  248. //如果鼠标位置在拖动矩形之外(就可以开始拖动了)
  249. if (dragBoxFromMouseDown != Rectangle.Empty &&
  250. !dragBoxFromMouseDown.Contains(e.X, e.Y))
  251. {
  252. //传递ListBox选中项并触发DoDragDrop事件(这里可以是ListDragSoure触发,也可以是ListDragTarget)
  253. //DoDragDrop 方法确定当前光标位置下的控件。然后它将检查该控件是否是有效的放置目标。
  254. DragDropEffects dropEffect = this.DoDragDrop(this.deviceId, DragDropEffects.All | DragDropEffects.Link);
  255. //if (dropEffect == DragDropEffects.Move)
  256. //{
  257. //}
  258. }
  259. }
  260. private void toolTip1_Popup(object sender, PopupEventArgs e)
  261. {
  262. System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
  263. //messageBoxCS.Append(this.deviceId);
  264. //messageBoxCS.AppendLine();
  265. //messageBoxCS.AppendFormat("当前状态:{0}", getStatusName(this.status));
  266. //messageBoxCS.AppendLine();
  267. //messageBoxCS.AppendFormat("开始时间:{0}, 时长 {1}分钟。", getBeginTime(this.ts));
  268. //messageBoxCS.AppendLine();
  269. //messageBoxCS.AppendFormat("\r\n持续时长:{0}分钟", getTimeSpan(this.ts));
  270. //messageBoxCS.AppendLine();
  271. //MessageBox.Show(messageBoxCS.ToString());
  272. string hungString = "";
  273. if (this.lokcValue != 0.0)
  274. {
  275. hungString = "挂牌原因:";
  276. HungType type = (HungType)Convert.ToInt32(this.lokcValue);
  277. switch (type)
  278. {
  279. case HungType.CheckLock:
  280. hungString = hungString + "检修";
  281. break;
  282. case HungType.FaultLock:
  283. hungString = hungString + "故障维修";
  284. break;
  285. case HungType.StationCheckLock:
  286. hungString = hungString + "场内受累检修";
  287. break;
  288. case HungType.StationFaulLockt:
  289. hungString = hungString + "场内受累故障";
  290. break;
  291. case HungType.StationPowerLineLock:
  292. hungString = hungString + "场外受累电网";
  293. break;
  294. case HungType.StationWeatherLock:
  295. hungString = hungString + "场外受累天气";
  296. break;
  297. }
  298. }
  299. StringBuilder sb = new StringBuilder();
  300. string toolString1 = String.Format("开始时间:{0}, 时长 {1}分钟\r\n", getBeginTime(this.ts), getTimeSpan(this.ts));
  301. this.toolTip1.ToolTipTitle = toolString1 + Environment.NewLine + "\r\n " + hungString;
  302. }
  303. private string getStatusName(double status)
  304. {
  305. int st = Convert.ToInt32(status);
  306. switch (st)
  307. {
  308. //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS
  309. case 0: //停机状态
  310. return "停机";
  311. case 1: //上电状态
  312. return "上电";
  313. case 2: //待机状态
  314. return "待机";
  315. case 3: //启动状态
  316. return "启动";
  317. case 4: //并网状态
  318. return "并网";
  319. case 5: //故障状态
  320. return "故障";
  321. case 6: //维护状态
  322. return "维护";
  323. case 7: //离线状态
  324. return "离线";
  325. default:
  326. return "未知";
  327. }
  328. }
  329. private string getBeginTime(long ts)
  330. {
  331. if (ts < 10000)
  332. return "";
  333. DateTime dt = CommonMethod.ConvertIntDateTime(ts);
  334. return dt.ToString("yyyy-MM-dd hh:mm:ss");
  335. }
  336. private string getTimeSpan(long ts)
  337. {
  338. if (ts < 10000)
  339. return "";
  340. DateTime dt = CommonMethod.ConvertIntDateTime(ts);
  341. TimeSpan tts = DateTime.Now - dt;
  342. return (long)tts.TotalMinutes + "";
  343. }
  344. private void MatrixDevice3_MouseDoubleClick(object sender, MouseEventArgs e)
  345. {
  346. string windturbineId = CommonMethod.GetLongWindturbineId(this.deviceId);
  347. string powerStationId = this.stationId;
  348. MessageBox.Show("双击事件" + windturbineId + "||" + powerStationId);
  349. }
  350. private void lblDeviceId_MouseDoubleClick(object sender, MouseEventArgs e)
  351. {
  352. string windturbineId = CommonMethod.GetLongWindturbineId(this.deviceId);
  353. string powerStationId = this.stationId;
  354. NavService.Instance.NavForWindturbine("pictureBoxParamters", windturbineId, powerStationId);
  355. }
  356. private void lblWindSpeed_MouseDoubleClick(object sender, MouseEventArgs e)
  357. {
  358. string windturbineId = CommonMethod.GetLongWindturbineId(this.deviceId);
  359. string powerStationId = this.stationId;
  360. NavService.Instance.NavForWindturbine("pictureBoxParamters", windturbineId, powerStationId);
  361. }
  362. private void lblPower_MouseDoubleClick(object sender, MouseEventArgs e)
  363. {
  364. string windturbineId = CommonMethod.GetLongWindturbineId(this.deviceId);
  365. string powerStationId = this.stationId;
  366. NavService.Instance.NavForWindturbine("pictureBoxParamters", windturbineId, powerStationId);
  367. }
  368. private void pTop_MouseDoubleClick(object sender, MouseEventArgs e)
  369. {
  370. string windturbineId = CommonMethod.GetLongWindturbineId(this.deviceId);
  371. string powerStationId = this.stationId;
  372. NavService.Instance.NavForWindturbine("pictureBoxParamters", windturbineId, powerStationId);
  373. }
  374. }
  375. }