MatrixDevice3.cs 15 KB

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