WindturbineForm.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using EntityDataSet;
  13. using IntelligentControlForsx.MyControls.windturbine;
  14. using IntelligentControlForsx.Service;
  15. using IntelligentControlForsx.Service.WindturbineControl.Domain;
  16. using IntelligentControlForsx.Service.WindturbineInfo;
  17. using IntelligentControlForsx.Template;
  18. using log4net;
  19. using log4net.Util;
  20. using WisdomClient;
  21. using WisdomClient.data;
  22. namespace IntelligentControlForsx.ChildForms
  23. {
  24. public partial class WindturbineForm : TemplateForm
  25. {
  26. private static ILog logger = LogManager.GetLogger("AppInfoLog");
  27. /// <summary>
  28. /// 当前风电场
  29. /// </summary>
  30. private string nowStationId = "SBQ_FDC";
  31. //public string NowStationId
  32. //{
  33. // set
  34. // {
  35. // BindWindturbine(value);
  36. // //麻黄山MG01_01,石板泉SG01_01,青山QS01_01,牛首山NG01_01,香山XG01_01
  37. // switch (value)
  38. // {
  39. // case "SBQ_FDC":
  40. // nowWindturbineId = "SG01_01";
  41. // break;
  42. // case "MHS_FDC":
  43. // nowWindturbineId = "MG01_01";
  44. // break;
  45. // case "QS_FDC":
  46. // nowWindturbineId = "QS01_01";
  47. // break;
  48. // case "NSS_FDC":
  49. // nowWindturbineId = "NG01_01";
  50. // break;
  51. // case "XS_FDC":
  52. // nowWindturbineId = "XG01_01";
  53. // break;
  54. // }
  55. // nowStationId = value;
  56. // }
  57. // get { return nowStationId; }
  58. //}
  59. /// <summary>
  60. /// 当前风机
  61. /// </summary>
  62. private static string nowWindturbineId = "SG01_01";
  63. public void SetNowWindturbineId(string windturbineId, string stationId)
  64. {
  65. nowWindturbineId = windturbineId;
  66. string controlName = "lwn" + windturbineId;
  67. try
  68. {
  69. Control control = null;
  70. if (stationId == "SBQ_FDC")
  71. {
  72. control = this.pnlLeft_SBQ.Controls.Find(controlName, true)[0];
  73. pnlLeft_MHS.Hide();
  74. pnlLeft_NSS.Hide();
  75. pnlLeft_XS.Hide();
  76. pnlLeft_QS.Hide();
  77. pnlLeft_SBQ.Show();
  78. }
  79. if (stationId == "MHS_FDC")
  80. {
  81. control = this.pnlLeft_MHS.Controls.Find(controlName, true)[0];
  82. pnlLeft_MHS.Show();
  83. pnlLeft_NSS.Hide();
  84. pnlLeft_XS.Hide();
  85. pnlLeft_QS.Hide();
  86. pnlLeft_SBQ.Hide();
  87. }
  88. if (stationId == "NSS_FDC")
  89. {
  90. control = this.pnlLeft_NSS.Controls.Find(controlName, true)[0];
  91. pnlLeft_MHS.Hide();
  92. pnlLeft_NSS.Show();
  93. pnlLeft_XS.Hide();
  94. pnlLeft_QS.Hide();
  95. pnlLeft_SBQ.Hide();
  96. }
  97. if (stationId == "QS_FDC")
  98. {
  99. control = this.pnlLeft_QS.Controls.Find(controlName, true)[0];
  100. pnlLeft_MHS.Hide();
  101. pnlLeft_NSS.Hide();
  102. pnlLeft_XS.Hide();
  103. pnlLeft_QS.Show();
  104. pnlLeft_SBQ.Hide();
  105. }
  106. if (stationId == "XS_FDC")
  107. {
  108. control = this.pnlLeft_XS.Controls.Find(controlName, true)[0];
  109. pnlLeft_MHS.Hide();
  110. pnlLeft_NSS.Hide();
  111. pnlLeft_XS.Show();
  112. pnlLeft_QS.Hide();
  113. pnlLeft_SBQ.Hide();
  114. }
  115. LabelWindturbineName wn = (LabelWindturbineName)control;
  116. NowWindturbineControl = wn;
  117. lblWindturbineId.Text = windturbineId;
  118. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  119. {
  120. windturbine data = ctx.windturbine.Where(s => s.ID == windturbineId).FirstOrDefault();
  121. if (data != null)
  122. {
  123. lblWindturbineModel.Text = data.MODELID;
  124. modelId = data.MODELID;
  125. }
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. logger.Info(ex.Message);
  131. }
  132. }
  133. /// <summary>
  134. /// 当前风机型号
  135. /// </summary>
  136. private string modelId = "UP82_2";
  137. /// <summary>
  138. /// 当前所显示的页面
  139. /// </summary>
  140. private BaseControl nowControl = null;
  141. /// <summary>
  142. /// 当前风机控件
  143. /// </summary>
  144. private LabelWindturbineName nowWindturbineControl = null;
  145. public LabelWindturbineName NowWindturbineControl
  146. {
  147. set
  148. {
  149. if (value != nowWindturbineControl)
  150. {
  151. nowWindturbineControl.Style_UnFocus();
  152. value.Style_Focus();
  153. }
  154. nowWindturbineControl = value;
  155. }
  156. get { return nowWindturbineControl; }
  157. }
  158. /// <summary>
  159. /// 数据是否刷新完毕
  160. /// </summary>
  161. public bool isRefreshOver = true;
  162. /// <summary>
  163. /// 当前风场的风机编号集合
  164. /// </summary>
  165. private IList<string> windturbineList = new List<string>();
  166. public WindturbineForm()
  167. {
  168. InitializeComponent();
  169. defalutLable = new Label();
  170. #region 加载参数种类页
  171. BasicInfo basicInfo = new BasicInfo();
  172. basicInfo.Name = "basicInfo";
  173. basicInfo.Show();
  174. this.plInfo.Controls.Add(basicInfo);
  175. AlternatorInfo alternatorInfo = new AlternatorInfo();
  176. alternatorInfo.Name = "alternatorInfo";
  177. alternatorInfo.Hide();
  178. this.plInfo.Controls.Add(alternatorInfo);
  179. ChangePaddleInfo changePaddleInfo = new ChangePaddleInfo();
  180. changePaddleInfo.Name = "changePaddleInfo";
  181. changePaddleInfo.Hide();
  182. this.plInfo.Controls.Add(changePaddleInfo);
  183. GearBoxInfo gearBoxInfo = new GearBoxInfo();
  184. gearBoxInfo.Name = "gearBoxInfo";
  185. gearBoxInfo.Hide();
  186. this.plInfo.Controls.Add(gearBoxInfo);
  187. PressureInfo pressureInfo = new PressureInfo();
  188. pressureInfo.Name = "pressureInfo";
  189. pressureInfo.Hide();
  190. this.plInfo.Controls.Add(pressureInfo);
  191. RoomInfo roomInfo = new RoomInfo();
  192. roomInfo.Name = "roomInfo";
  193. roomInfo.Hide();
  194. this.plInfo.Controls.Add(roomInfo);
  195. YawInfo yawInfo = new YawInfo();
  196. yawInfo.Name = "yawInfo";
  197. yawInfo.Hide();
  198. this.plInfo.Controls.Add(yawInfo);
  199. OutInInfo outInInfo = new OutInInfo();
  200. outInInfo.Name = "outInInfo";
  201. outInInfo.Hide();
  202. this.plInfo.Controls.Add(outInInfo);
  203. FaultInfo2 faultInfo = new FaultInfo2();
  204. faultInfo.Name = "faultInfo";
  205. faultInfo.Hide();
  206. this.plInfo.Controls.Add(faultInfo);
  207. #endregion
  208. BindWindturbine(nowStationId);
  209. this.pnlLeft_MHS.Hide();
  210. this.pnlLeft_NSS.Hide();
  211. this.pnlLeft_XS.Hide();
  212. this.pnlLeft_QS.Hide();
  213. nowControl = basicInfo;
  214. lblBasic.BackColor = Color.FromArgb(10, 25, 47);
  215. lblBasic.Cursor = Cursors.Default;
  216. lblBasic.ForeColor = Color.White;
  217. defalutLable = lblBasic;
  218. lblStationName.Text = "石板泉风电场";
  219. if (nowWindturbineControl != null)
  220. nowWindturbineControl.Style_Focus();
  221. }
  222. public override void Active()
  223. {
  224. nowStationId = NavService.Instance.StationId;
  225. if (nowStationId == "0")
  226. nowStationId = "SBQ_FDC";
  227. if (nowStationId == "SBQ_FDC")
  228. {
  229. if (!nowWindturbineId.Contains("SG01_"))
  230. nowWindturbineId = "SG01_01";
  231. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  232. {
  233. windturbine data = ctx.windturbine.Where(s => s.ID == nowWindturbineId).FirstOrDefault();
  234. if (data != null)
  235. modelId = data.MODELID;
  236. }
  237. lblWindturbineId.Text = nowWindturbineId;
  238. lblWindturbineModel.Text = modelId;
  239. pnlLeft_MHS.Hide();
  240. pnlLeft_NSS.Hide();
  241. pnlLeft_XS.Hide();
  242. pnlLeft_QS.Hide();
  243. pnlLeft_SBQ.Show();
  244. lblStationName.Text = "石板泉风电场";
  245. for (int i = 0; i < this.pnlLeft_SBQ.Controls.Count; i++)
  246. {
  247. try
  248. {
  249. if (this.pnlLeft_SBQ.Controls[i] is LabelWindturbineName)
  250. {
  251. LabelWindturbineName lbl = (LabelWindturbineName)this.pnlLeft_SBQ.Controls[i];
  252. if (lbl.Name.Replace("lwn", "") == nowWindturbineId)
  253. NowWindturbineControl = lbl;
  254. }
  255. }
  256. catch (Exception)
  257. {
  258. throw;
  259. }
  260. }
  261. }
  262. else if (nowStationId == "XS_FDC")
  263. {
  264. if (!nowWindturbineId.Contains("XG01_"))
  265. nowWindturbineId = "XG01_01";
  266. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  267. {
  268. windturbine data = ctx.windturbine.Where(s => s.ID == nowWindturbineId).FirstOrDefault();
  269. if (data != null)
  270. modelId = data.MODELID;
  271. }
  272. lblWindturbineId.Text = nowWindturbineId;
  273. lblWindturbineModel.Text = modelId;
  274. pnlLeft_MHS.Hide();
  275. pnlLeft_NSS.Hide();
  276. pnlLeft_XS.Show();
  277. pnlLeft_QS.Hide();
  278. pnlLeft_SBQ.Hide();
  279. lblStationName.Text = "香山风电场";
  280. for (int i = 0; i < this.pnlLeft_XS.Controls.Count; i++)
  281. {
  282. try
  283. {
  284. if (this.pnlLeft_XS.Controls[i] is LabelWindturbineName)
  285. {
  286. LabelWindturbineName lbl = (LabelWindturbineName)this.pnlLeft_XS.Controls[i];
  287. if (lbl.Name.Replace("lwn", "") == nowWindturbineId)
  288. NowWindturbineControl = lbl;
  289. }
  290. }
  291. catch (Exception)
  292. {
  293. throw;
  294. }
  295. }
  296. }
  297. else if (nowStationId == "NSS_FDC")
  298. {
  299. if (!nowWindturbineId.Contains("NG01_"))
  300. nowWindturbineId = "NG01_01";
  301. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  302. {
  303. windturbine data = ctx.windturbine.Where(s => s.ID == nowWindturbineId).FirstOrDefault();
  304. if (data != null)
  305. modelId = data.MODELID;
  306. }
  307. lblWindturbineId.Text = nowWindturbineId;
  308. lblWindturbineModel.Text = modelId;
  309. pnlLeft_MHS.Hide();
  310. pnlLeft_NSS.Show();
  311. pnlLeft_XS.Hide();
  312. pnlLeft_QS.Hide();
  313. pnlLeft_SBQ.Hide();
  314. lblStationName.Text = "牛首山风电场";
  315. for (int i = 0; i < this.pnlLeft_NSS.Controls.Count; i++)
  316. {
  317. try
  318. {
  319. if (this.pnlLeft_NSS.Controls[i] is LabelWindturbineName)
  320. {
  321. LabelWindturbineName lbl = (LabelWindturbineName)this.pnlLeft_NSS.Controls[i];
  322. if (lbl.Name.Replace("lwn", "") == nowWindturbineId)
  323. NowWindturbineControl = lbl;
  324. }
  325. }
  326. catch (Exception)
  327. {
  328. throw;
  329. }
  330. }
  331. }
  332. else if (nowStationId == "MHS_FDC")
  333. {
  334. if (!nowWindturbineId.Contains("MG01_"))
  335. nowWindturbineId = "MG01_01";
  336. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  337. {
  338. windturbine data = ctx.windturbine.Where(s => s.ID == nowWindturbineId).FirstOrDefault();
  339. if (data != null)
  340. modelId = data.MODELID;
  341. }
  342. lblWindturbineId.Text = nowWindturbineId;
  343. lblWindturbineModel.Text = modelId;
  344. pnlLeft_MHS.Show();
  345. pnlLeft_NSS.Hide();
  346. pnlLeft_XS.Hide();
  347. pnlLeft_QS.Hide();
  348. pnlLeft_SBQ.Hide();
  349. lblStationName.Text = "麻黄山风电场";
  350. for (int i = 0; i < this.pnlLeft_MHS.Controls.Count; i++)
  351. {
  352. try
  353. {
  354. if (this.pnlLeft_MHS.Controls[i] is LabelWindturbineName)
  355. {
  356. LabelWindturbineName lbl = (LabelWindturbineName)this.pnlLeft_MHS.Controls[i];
  357. if (lbl.Name.Replace("lwn", "") == nowWindturbineId)
  358. NowWindturbineControl = lbl;
  359. }
  360. }
  361. catch (Exception)
  362. {
  363. throw;
  364. }
  365. }
  366. }
  367. else if (nowStationId == "QS_FDC")
  368. {
  369. if (!nowWindturbineId.Contains("QG01_"))
  370. nowWindturbineId = "QG01_01";
  371. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  372. {
  373. windturbine data = ctx.windturbine.Where(s => s.ID == nowWindturbineId).FirstOrDefault();
  374. if (data != null)
  375. modelId = data.MODELID;
  376. }
  377. lblWindturbineId.Text = nowWindturbineId;
  378. lblWindturbineModel.Text = modelId;
  379. pnlLeft_MHS.Hide();
  380. pnlLeft_NSS.Hide();
  381. pnlLeft_XS.Hide();
  382. pnlLeft_QS.Show();
  383. pnlLeft_SBQ.Hide();
  384. lblStationName.Text = "青山风电场";
  385. for (int i = 0; i < this.pnlLeft_QS.Controls.Count; i++)
  386. {
  387. try
  388. {
  389. if (this.pnlLeft_QS.Controls[i] is LabelWindturbineName)
  390. {
  391. LabelWindturbineName lbl = (LabelWindturbineName)this.pnlLeft_QS.Controls[i];
  392. if (lbl.Name.Replace("lwn", "") == nowWindturbineId)
  393. NowWindturbineControl = lbl;
  394. }
  395. }
  396. catch (Exception)
  397. {
  398. throw;
  399. }
  400. }
  401. }
  402. for (int i = 0; i < this.plInfo.Controls.Count; i++)
  403. {
  404. BaseControl c = (BaseControl)this.plInfo.Controls[i];
  405. c.WINDTURBINEID = nowWindturbineId;
  406. c.MODELID = modelId;
  407. c.STATIONID = nowStationId;
  408. }
  409. this.Show();
  410. timer1.Enabled = true;
  411. nowControl.Show();
  412. nowControl.Active(nowStationId, nowWindturbineId, modelId);
  413. }
  414. public override void DeActive()
  415. {
  416. //如果当前控件为非活跃状态,则控件中农的其他子控件都为非活动状态
  417. for (int i = 0; i < this.plInfo.Controls.Count; i++)
  418. {
  419. if (this.plInfo.Controls[i] is BaseControl)
  420. {
  421. BaseControl c = (BaseControl)this.plInfo.Controls[i];
  422. c.DeActive();
  423. }
  424. }
  425. timer1.Enabled = false;
  426. this.Hide();
  427. }
  428. private void lblTitle_Click(object sender, EventArgs e)
  429. {
  430. Label lable = (Label)sender;
  431. // MyClick(lable.Tag, e);
  432. DefaultLable = lable;
  433. Label l = (Label)sender;
  434. string infoName = "";
  435. switch (l.Name)
  436. {
  437. case "lblBasic":
  438. infoName = "basicInfo";
  439. break;
  440. case "lblAlternator":
  441. infoName = "alternatorInfo";
  442. break;
  443. case "lblGearBox":
  444. infoName = "gearBoxInfo";
  445. break;
  446. case "lblPropeller":
  447. infoName = "changePaddleInfo";
  448. break;
  449. case "lblPressure":
  450. infoName = "pressureInfo";
  451. break;
  452. case "lblRoom":
  453. infoName = "roomInfo";
  454. break;
  455. case "lblYaw":
  456. infoName = "yawInfo";
  457. break;
  458. case "lblFault":
  459. infoName = "faultInfo";
  460. break;
  461. case "lblOutIn":
  462. infoName = "outInInfo";
  463. break;
  464. }
  465. for (int i = 0; i < this.plInfo.Controls.Count; i++)
  466. {
  467. BaseControl c = (BaseControl)this.plInfo.Controls[i];
  468. Console.WriteLine(c.Name);
  469. if (c.Name == infoName)
  470. {
  471. c.Show();
  472. c.Active(nowStationId, nowWindturbineId, modelId);
  473. nowControl = c;
  474. }
  475. else
  476. {
  477. c.Hide();
  478. c.DeActive();
  479. }
  480. }
  481. }
  482. #region 组态种类动态效果(导航栏)及其事件
  483. Label defalutLable;
  484. [Browsable(true), Category("Appearance")]
  485. public Label DefaultLable
  486. {
  487. get
  488. {
  489. return defalutLable;
  490. }
  491. set
  492. {
  493. if (!this.DesignMode)
  494. {
  495. if (defalutLable.Name != null && defalutLable.Name.Trim() != "")
  496. {
  497. value.BackColor = Color.FromArgb(10, 25, 47);
  498. value.Cursor = Cursors.Default;
  499. value.ForeColor = Color.White;
  500. defalutLable.BackColor = Color.FromArgb(15, 45, 74);
  501. defalutLable.Cursor = System.Windows.Forms.Cursors.Hand;
  502. defalutLable.ForeColor = Color.FromArgb(48, 184, 250);
  503. }
  504. }
  505. defalutLable = value;
  506. }
  507. }
  508. private void lbl_MouseEnter(object sender, System.EventArgs e)
  509. {
  510. if (!this.DesignMode)
  511. {
  512. Label lable = (Label)sender;
  513. if (defalutLable.Name != lable.Name)
  514. {
  515. lable.BackColor = Color.FromArgb(10, 25, 47);
  516. lable.ForeColor = Color.White;
  517. }
  518. }
  519. }
  520. private void lbl_MouseLeave(object sender, System.EventArgs e)
  521. {
  522. if (!this.DesignMode)
  523. {
  524. Label lable = (Label)sender;
  525. if (defalutLable.Name != lable.Name)
  526. {
  527. lable.BackColor = Color.FromArgb(5, 45, 74);
  528. lable.ForeColor = Color.FromArgb(48, 184, 250);
  529. }
  530. }
  531. }
  532. #endregion
  533. /// <summary>
  534. /// 绑定风机tree
  535. /// </summary>
  536. /// <param name="stationCode"></param>
  537. private void BindWindturbine(string stationCode)
  538. {
  539. IList<string> windturbineIdList = new List<string>();
  540. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  541. {
  542. IList<windturbine> list = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID.Contains("FDC")).ToList();
  543. IList<windturbine> orderList_SBQ = list.Where(k => k.WINDPOWERSTATIONID == "SBQ_FDC").OrderByDescending(s => Convert.ToInt32(s.ID.Replace("SG01_", ""))).ToList();
  544. IList<windturbine> orderList_NSS = list.Where(k => k.WINDPOWERSTATIONID == "NSS_FDC").OrderByDescending(s => Convert.ToInt32(s.ID.Replace("NG01_", ""))).ToList();
  545. IList<windturbine> orderListMHS = list.Where(k => k.WINDPOWERSTATIONID == "MHS_FDC").OrderByDescending(s => Convert.ToInt32(s.ID.Replace("MG01_", ""))).ToList();
  546. IList<windturbine> orderListXS = list.Where(k => k.WINDPOWERSTATIONID == "XS_FDC").OrderByDescending(s => Convert.ToInt32(s.ID.Replace("XG01_", ""))).ToList();
  547. IList<windturbine> orderListQS = list.Where(k => k.WINDPOWERSTATIONID == "QS_FDC").OrderByDescending(s => Convert.ToInt32(s.ID.Replace("QG01_", ""))).ToList();
  548. for (int i = 0; i < orderList_SBQ.Count; i++)
  549. {
  550. LabelWindturbineName wn = new LabelWindturbineName();
  551. wn.Name = "lwn" + orderList_SBQ[i].ID;
  552. wn.WindturbineName = orderList_SBQ[i].ID;
  553. wn.Dock = DockStyle.Top;
  554. wn.MyClick += Windturbine_Click;
  555. pnlLeft_SBQ.Controls.Add(wn);
  556. windturbineIdList.Add(orderList_SBQ[i].ID);
  557. //首页加载时默认将石板泉第一台风机控件赋值给当前风机控件
  558. if (orderList_SBQ[i].ID == "SG01_01")
  559. nowWindturbineControl = wn;
  560. }
  561. for (int i = 0; i < orderList_NSS.Count; i++)
  562. {
  563. LabelWindturbineName wn = new LabelWindturbineName();
  564. wn.Name = "lwn" + orderList_NSS[i].ID;
  565. wn.WindturbineName = orderList_NSS[i].ID;
  566. wn.Dock = DockStyle.Top;
  567. wn.MyClick += Windturbine_Click;
  568. pnlLeft_NSS.Controls.Add(wn);
  569. windturbineIdList.Add(orderList_NSS[i].ID);
  570. }
  571. for (int i = 0; i < orderListMHS.Count; i++)
  572. {
  573. LabelWindturbineName wn = new LabelWindturbineName();
  574. wn.Name = "lwn" + orderListMHS[i].ID;
  575. wn.WindturbineName = orderListMHS[i].ID;
  576. wn.Dock = DockStyle.Top;
  577. wn.MyClick += Windturbine_Click;
  578. pnlLeft_MHS.Controls.Add(wn);
  579. windturbineIdList.Add(orderListMHS[i].ID);
  580. }
  581. for (int i = 0; i < orderListQS.Count; i++)
  582. {
  583. LabelWindturbineName wn = new LabelWindturbineName();
  584. wn.Name = "lwn" + orderListQS[i].ID;
  585. wn.WindturbineName = orderListQS[i].ID;
  586. wn.Dock = DockStyle.Top;
  587. wn.MyClick += Windturbine_Click;
  588. pnlLeft_QS.Controls.Add(wn);
  589. windturbineIdList.Add(orderListQS[i].ID);
  590. }
  591. for (int i = 0; i < orderListXS.Count; i++)
  592. {
  593. LabelWindturbineName wn = new LabelWindturbineName();
  594. wn.Name = "lwn" + orderListXS[i].ID;
  595. wn.WindturbineName = orderListXS[i].ID;
  596. wn.Dock = DockStyle.Top;
  597. wn.MyClick += Windturbine_Click;
  598. pnlLeft_XS.Controls.Add(wn);
  599. windturbineIdList.Add(orderListXS[i].ID);
  600. }
  601. }
  602. windturbineList = windturbineIdList;
  603. }
  604. private void Windturbine_Click(object sender, EventArgs e)
  605. {
  606. LabelWindturbineName lblControl = (LabelWindturbineName)sender;
  607. NowWindturbineControl = lblControl;
  608. nowWindturbineId = lblControl.WindturbineName;
  609. windturbine data = null;
  610. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  611. {
  612. data = ctx.windturbine.Where(s => s.ID == nowWindturbineId).FirstOrDefault();
  613. if (data != null)
  614. {
  615. lblWindturbineId.Text = data.ID;
  616. lblWindturbineModel.Text = data.MODELID;
  617. }
  618. }
  619. for (int i = 0; i < this.plInfo.Controls.Count; i++)
  620. {
  621. BaseControl c = (BaseControl)this.plInfo.Controls[i];
  622. c.WINDTURBINEID = nowWindturbineId;
  623. if (data != null)
  624. c.MODELID = data.MODELID;
  625. }
  626. if (nowControl is OutInInfo)
  627. {
  628. OutInInfo info = (OutInInfo)nowControl;
  629. if (data != null)
  630. info.LeftBind(data.WINDPOWERSTATIONID, data.ID, data.MODELID);
  631. }
  632. if (nowControl is FaultInfo2)
  633. {
  634. FaultInfo2 info = (FaultInfo2)nowControl;
  635. if (data != null)
  636. info.LeftBind(data.WINDPOWERSTATIONID, data.ID, data.MODELID);
  637. }
  638. }
  639. public override void SelectedStationChanged(string stationId)
  640. {
  641. nowStationId = stationId;
  642. #region
  643. if (stationId == "SBQ_FDC")
  644. {
  645. pnlLeft_MHS.Hide();
  646. pnlLeft_NSS.Hide();
  647. pnlLeft_XS.Hide();
  648. pnlLeft_QS.Hide();
  649. pnlLeft_SBQ.Show();
  650. }
  651. if (stationId == "NSS_FDC")
  652. {
  653. pnlLeft_MHS.Hide();
  654. pnlLeft_NSS.Show();
  655. pnlLeft_XS.Hide();
  656. pnlLeft_QS.Hide();
  657. pnlLeft_SBQ.Hide();
  658. }
  659. if (stationId == "MHS_FDC")
  660. {
  661. pnlLeft_MHS.Show();
  662. pnlLeft_NSS.Hide();
  663. pnlLeft_XS.Hide();
  664. pnlLeft_QS.Hide();
  665. pnlLeft_SBQ.Hide();
  666. }
  667. if (stationId == "QS_FDC")
  668. {
  669. pnlLeft_MHS.Hide();
  670. pnlLeft_NSS.Hide();
  671. pnlLeft_XS.Hide();
  672. pnlLeft_QS.Show();
  673. pnlLeft_SBQ.Hide();
  674. }
  675. if (stationId == "XS_FDC")
  676. {
  677. pnlLeft_MHS.Hide();
  678. pnlLeft_NSS.Hide();
  679. pnlLeft_XS.Show();
  680. pnlLeft_QS.Hide();
  681. pnlLeft_SBQ.Hide();
  682. }
  683. #endregion
  684. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  685. {
  686. windpowerstation station = ctx.windpowerstation.Where(s => s.ID == stationId).FirstOrDefault();
  687. if (station != null)
  688. lblStationName.Text = station.NAME;
  689. windturbine wb = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == stationId).FirstOrDefault();
  690. if (wb != null)
  691. {
  692. nowWindturbineId = wb.ID;
  693. modelId = wb.MODELID;
  694. lblWindturbineId.Text = wb.ID;
  695. lblWindturbineModel.Text = wb.MODELID;
  696. for (int i = 0; i < this.plInfo.Controls.Count; i++)
  697. {
  698. BaseControl c = (BaseControl)this.plInfo.Controls[i];
  699. c.WINDTURBINEID = nowWindturbineId;
  700. c.MODELID = wb.MODELID;
  701. c.STATIONID = stationId;
  702. }
  703. }
  704. }
  705. #region 左边风机焦点
  706. if (stationId == "SBQ_FDC")
  707. {
  708. for (int i = 0; i < this.pnlLeft_SBQ.Controls.Count; i++)
  709. {
  710. try
  711. {
  712. if (this.pnlLeft_SBQ.Controls[i] is LabelWindturbineName)
  713. {
  714. LabelWindturbineName lbl = (LabelWindturbineName)this.pnlLeft_SBQ.Controls[i];
  715. if (lbl.Name.Replace("lwn", "") == nowWindturbineId)
  716. NowWindturbineControl = lbl;
  717. }
  718. }
  719. catch (Exception)
  720. {
  721. throw;
  722. }
  723. }
  724. }
  725. if (stationId == "NSS_FDC")
  726. {
  727. for (int i = 0; i < this.pnlLeft_NSS.Controls.Count; i++)
  728. {
  729. try
  730. {
  731. if (this.pnlLeft_NSS.Controls[i] is LabelWindturbineName)
  732. {
  733. LabelWindturbineName lbl = (LabelWindturbineName)this.pnlLeft_NSS.Controls[i];
  734. if (lbl.Name.Replace("lwn", "") == nowWindturbineId)
  735. NowWindturbineControl = lbl;
  736. }
  737. }
  738. catch (Exception)
  739. {
  740. throw;
  741. }
  742. }
  743. }
  744. if (stationId == "MHS_FDC")
  745. {
  746. for (int i = 0; i < this.pnlLeft_MHS.Controls.Count; i++)
  747. {
  748. try
  749. {
  750. if (this.pnlLeft_MHS.Controls[i] is LabelWindturbineName)
  751. {
  752. LabelWindturbineName lbl = (LabelWindturbineName)this.pnlLeft_MHS.Controls[i];
  753. if (lbl.Name.Replace("lwn", "") == nowWindturbineId)
  754. NowWindturbineControl = lbl;
  755. }
  756. }
  757. catch (Exception)
  758. {
  759. throw;
  760. }
  761. }
  762. }
  763. if (stationId == "XS_FDC")
  764. {
  765. for (int i = 0; i < this.pnlLeft_XS.Controls.Count; i++)
  766. {
  767. try
  768. {
  769. if (this.pnlLeft_XS.Controls[i] is LabelWindturbineName)
  770. {
  771. LabelWindturbineName lbl = (LabelWindturbineName)this.pnlLeft_XS.Controls[i];
  772. if (lbl.Name.Replace("lwn", "") == nowWindturbineId)
  773. NowWindturbineControl = lbl;
  774. }
  775. }
  776. catch (Exception)
  777. {
  778. throw;
  779. }
  780. }
  781. }
  782. if (stationId == "QS_FDC")
  783. {
  784. for (int i = 0; i < this.pnlLeft_QS.Controls.Count; i++)
  785. {
  786. try
  787. {
  788. if (this.pnlLeft_QS.Controls[i] is LabelWindturbineName)
  789. {
  790. LabelWindturbineName lbl = (LabelWindturbineName)this.pnlLeft_QS.Controls[i];
  791. if (lbl.Name.Replace("lwn", "") == nowWindturbineId)
  792. NowWindturbineControl = lbl;
  793. }
  794. }
  795. catch (Exception)
  796. {
  797. throw;
  798. }
  799. }
  800. }
  801. #endregion
  802. }
  803. //主要为刷新风机状态
  804. private void timer1_Tick(object sender, EventArgs e)
  805. {
  806. #region 刷新时间
  807. DateTime time = DateTime.Now;
  808. string timeString = time.ToString("yyyy-MM-dd HH:mm:ss");
  809. lblTimeNow.Text = timeString;
  810. #endregion
  811. if (isRefreshOver)
  812. {
  813. isRefreshOver = false;
  814. //刷新数据线程
  815. Thread refreshThread = new Thread(new ParameterizedThreadStart(WindturbineStatusSvc.RefreshStatusSvc));
  816. IList<string> windturbineIdList = new List<string>();
  817. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  818. {
  819. windturbineIdList = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == nowStationId)
  820. .ToList()
  821. .Select(s => s.ID)
  822. .ToList();
  823. }
  824. refreshThread.Start(windturbineIdList);
  825. isRefreshOver = true;
  826. }
  827. //绑定数据线程
  828. Thread bindDataThread = new Thread(BindData);
  829. bindDataThread.Start();
  830. }
  831. public delegate void UpdateFormInfoDelegate();
  832. private void BindWindturbineStatus()
  833. {
  834. #region 刷新风机状态
  835. Dictionary<string, WindturbineStatus> dic = WindturbineStatusSvc.GetStatus();
  836. foreach (var item in dic)
  837. {
  838. try
  839. {
  840. string nowWindturbineId = lblWindturbineId.Text;
  841. if (nowWindturbineId == item.Key)
  842. {
  843. switch (item.Value)
  844. {
  845. case WindturbineStatus.Offline:
  846. lblStatus.BackColor = Color.FromArgb(134, 150, 165);
  847. lblStatus.Text = "离线";
  848. break;
  849. case WindturbineStatus.Start:
  850. lblStatus.BackColor = Color.FromArgb(14, 72, 91);
  851. lblStatus.Text = "启动";
  852. break;
  853. case WindturbineStatus.Fault:
  854. lblStatus.BackColor = Color.FromArgb(170, 15, 59);
  855. lblStatus.Text = "故障";
  856. break;
  857. case WindturbineStatus.Maintain:
  858. lblStatus.BackColor = Color.FromArgb(204, 83, 51);
  859. lblStatus.Text = "维护";
  860. break;
  861. case WindturbineStatus.Stop:
  862. lblStatus.BackColor = Color.FromArgb(176, 151, 63);
  863. lblStatus.Text = "停机";
  864. break;
  865. case WindturbineStatus.Online:
  866. lblStatus.BackColor = Color.FromArgb(15, 135, 170);
  867. lblStatus.Text = "并网";
  868. break;
  869. case WindturbineStatus.OnPower:
  870. lblStatus.BackColor = Color.FromArgb(177, 14, 126);
  871. lblStatus.Text = "上电";
  872. break;
  873. case WindturbineStatus.Standby:
  874. lblStatus.BackColor = Color.FromArgb(15, 141, 106);
  875. lblStatus.Text = "待机";
  876. break;
  877. default: break;
  878. }
  879. }
  880. if (nowStationId == "SBQ_FDC")
  881. {
  882. for (int i = 0; i < pnlLeft_SBQ.Controls.Count; i++)
  883. {
  884. string cname = "lwn" + item.Key;
  885. if (pnlLeft_SBQ.Controls[i] is LabelWindturbineName)
  886. {
  887. LabelWindturbineName lblwn = (LabelWindturbineName)pnlLeft_SBQ.Controls[i];
  888. if (lblwn.Name == cname)
  889. lblwn.Status = item.Value;
  890. }
  891. }
  892. }
  893. if (nowStationId == "MHS_FDC")
  894. {
  895. for (int i = 0; i < pnlLeft_MHS.Controls.Count; i++)
  896. {
  897. string cname = "lwn" + item.Key;
  898. if (pnlLeft_MHS.Controls[i] is LabelWindturbineName)
  899. {
  900. LabelWindturbineName lblwn = (LabelWindturbineName)pnlLeft_MHS.Controls[i];
  901. if (lblwn.Name == cname)
  902. lblwn.Status = item.Value;
  903. }
  904. }
  905. }
  906. if (nowStationId == "XS_FDC")
  907. {
  908. for (int i = 0; i < pnlLeft_XS.Controls.Count; i++)
  909. {
  910. string cname = "lwn" + item.Key;
  911. if (pnlLeft_XS.Controls[i] is LabelWindturbineName)
  912. {
  913. LabelWindturbineName lblwn = (LabelWindturbineName)pnlLeft_XS.Controls[i];
  914. if (lblwn.Name == cname)
  915. lblwn.Status = item.Value;
  916. }
  917. }
  918. }
  919. if (nowStationId == "NSS_FDC")
  920. {
  921. for (int i = 0; i < pnlLeft_NSS.Controls.Count; i++)
  922. {
  923. string cname = "lwn" + item.Key;
  924. if (pnlLeft_NSS.Controls[i] is LabelWindturbineName)
  925. {
  926. LabelWindturbineName lblwn = (LabelWindturbineName)pnlLeft_NSS.Controls[i];
  927. if (lblwn.Name == cname)
  928. lblwn.Status = item.Value;
  929. }
  930. }
  931. }
  932. if (nowStationId == "QS_FDC")
  933. {
  934. for (int i = 0; i < pnlLeft_QS.Controls.Count; i++)
  935. {
  936. string cname = "lwn" + item.Key;
  937. if (pnlLeft_QS.Controls[i] is LabelWindturbineName)
  938. {
  939. LabelWindturbineName lblwn = (LabelWindturbineName)pnlLeft_QS.Controls[i];
  940. if (lblwn.Name == cname)
  941. lblwn.Status = item.Value;
  942. }
  943. }
  944. }
  945. }
  946. catch (Exception ex)
  947. {
  948. logger.Info("找不到要绑定的控件:" + ex.Message);
  949. }
  950. }
  951. #endregion
  952. }
  953. public void BindData()
  954. {
  955. UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(BindWindturbineStatus);
  956. if (this.InvokeRequired)
  957. {
  958. this.BeginInvoke(del, new object[] { });
  959. }
  960. else
  961. {
  962. BindWindturbineStatus();
  963. }
  964. }
  965. }
  966. }