HomeForm.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. using System.Threading;
  2. using System.Windows.Forms.VisualStyles;
  3. using IntelligentControlForsx.Code;
  4. using IntelligentControlForsx.MyControls;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Drawing.Drawing2D;
  11. using System.Text;
  12. using System.Windows.Forms;
  13. using IntelligentControlForsx.Service;
  14. using IntelligentControlForsx.Service.HomeFormInfo;
  15. using IntelligentControlForsx.Service.HomeFormInfo.Domain;
  16. namespace IntelligentControlForsx.ChildForms
  17. {
  18. public partial class HomeForm : IntelligentControlForsx.Template.TemplateForm
  19. {
  20. public override void Active()
  21. {
  22. this.Show();
  23. isUpdateOver = false;
  24. Thread th = new Thread(UpdateThread);
  25. th.Start();
  26. timer2.Enabled = true;
  27. timer1.Enabled = true;
  28. }
  29. public override void DeActive()
  30. {
  31. this.Hide();
  32. timer2.Enabled = false;
  33. timer1.Enabled = false;
  34. }
  35. private bool isUpdateOver = true;
  36. public HomeForm()
  37. {
  38. InitializeComponent();
  39. plSBQ.MyMouseEnter += panelLabel_MouseEnter;
  40. plSBQ.MyMouseLeave += panelLabel_MouseLeave;
  41. plNSS.MyMouseEnter += panelLabel_MouseEnter;
  42. plNSS.MyMouseLeave += panelLabel_MouseLeave;
  43. plQS.MyMouseEnter += panelLabel_MouseEnter;
  44. plQS.MyMouseLeave += panelLabel_MouseLeave;
  45. plMHS.MyMouseEnter += panelLabel_MouseEnter;
  46. plMHS.MyMouseLeave += panelLabel_MouseLeave;
  47. plXS.MyMouseEnter += panelLabel_MouseEnter;
  48. plXS.MyMouseLeave += panelLabel_MouseLeave;
  49. SFI_MHS.Hide();
  50. SFI_NSS.Hide();
  51. SFI_QS.Hide();
  52. SFI_SBQ.Hide();
  53. SFI_XS.Hide();
  54. wpf_MHS.WindPowerId = "MHS_FDC";
  55. wpf_MHS.MyClick += WPF_StationClick;
  56. wpf_NSS.WindPowerId = "NSS_FDC";
  57. wpf_NSS.MyClick += WPF_StationClick;
  58. wpf_SBQ.WindPowerId = "SBQ_FDC";
  59. wpf_SBQ.MyClick += WPF_StationClick;
  60. wpf_XS.WindPowerId = "XS_FDC";
  61. wpf_XS.MyClick += WPF_StationClick;
  62. wpf_QS.WindPowerId = "QS_FDC";
  63. wpf_QS.MyClick += WPF_StationClick;
  64. #region 日发电能量绑定测试
  65. IList<Info> list = new List<Info>();
  66. Info info1 = new Info();
  67. info1.Power = 21233;
  68. info1.Station = "麻黄山";
  69. Info info2 = new Info();
  70. info2.Power = 12333;
  71. info2.Station = "石板泉";
  72. Info info3 = new Info();
  73. info3.Power = 9333;
  74. info3.Station = "牛首山";
  75. Info info4 = new Info();
  76. info4.Power = 9333;
  77. info4.Station = "牛首山";
  78. Info info5 = new Info();
  79. info5.Power = 9333;
  80. info5.Station = "牛首山";
  81. Info info6 = new Info();
  82. info6.Power = 9333;
  83. info6.Station = "牛首山";
  84. Info info7 = new Info();
  85. info7.Power = 9333;
  86. info7.Station = "牛首山";
  87. Info info8 = new Info();
  88. info8.Power = 9333;
  89. info8.Station = "牛首山";
  90. list.Add(info1);
  91. list.Add(info2);
  92. list.Add(info3);
  93. list.Add(info4);
  94. list.Add(info5);
  95. list.Add(info6);
  96. list.Add(info7);
  97. list.Add(info8);
  98. datePowerStat.DataBind(list);
  99. #endregion
  100. }
  101. private void HomeForm_Paint(object sender, PaintEventArgs e)
  102. {
  103. Graphics g = e.Graphics;
  104. Color aColor = System.Drawing.Color.FromArgb(((int)(((byte)(8)))), ((int)(((byte)(13)))), ((int)(((byte)(33)))));
  105. Color bColor = System.Drawing.Color.FromArgb(((int)(((byte)(13)))), ((int)(((byte)(67)))), ((int)(((byte)(139)))));
  106. Brush b = new LinearGradientBrush(this.ClientRectangle, aColor, bColor, LinearGradientMode.Vertical);
  107. g.FillRectangle(b, this.ClientRectangle);
  108. }
  109. void WPF_StationClick(object sender, EventArgs e)
  110. {
  111. WpfWindturbine pl = (WpfWindturbine)sender;
  112. NavService.Instance.StationId = pl.WindPowerId;
  113. NavService.Instance.Nav("ZMForm", (MainWindow)this.Parent.Parent);
  114. //MessageBox.Show(pl.WindPowerId);
  115. }
  116. private void panelLabel_MouseEnter(object sender, EventArgs e)
  117. {
  118. string s = sender.ToString();
  119. if (sender.ToString() == "plSBQ")
  120. {
  121. SFI_SBQ.Show();
  122. }
  123. else if (sender.ToString() == "plNSS")
  124. {
  125. SFI_NSS.Show();
  126. }
  127. else if (sender.ToString() == "plQS")
  128. {
  129. SFI_QS.Show();
  130. }
  131. else if (sender.ToString() == "plMHS")
  132. {
  133. SFI_MHS.Show();
  134. }
  135. else if (sender.ToString() == "plXS")
  136. {
  137. SFI_XS.Show();
  138. }
  139. }
  140. private void panelLabel_MouseLeave(object sender, EventArgs e)
  141. {
  142. if (sender.ToString() == "plSBQ")
  143. {
  144. SFI_SBQ.Hide();
  145. }
  146. else if (sender.ToString() == "plNSS")
  147. {
  148. SFI_NSS.Hide();
  149. }
  150. else if (sender.ToString() == "plQS")
  151. {
  152. SFI_QS.Hide();
  153. }
  154. else if (sender.ToString() == "plMHS")
  155. {
  156. SFI_MHS.Hide();
  157. }
  158. else if (sender.ToString() == "plXS")
  159. {
  160. SFI_XS.Hide();
  161. }
  162. }
  163. private void timer1_Tick(object sender, EventArgs e)
  164. {
  165. this.DateLabel.Text = DateTime.Now.ToString();
  166. }
  167. private void timer2_Tick(object sender, EventArgs e)
  168. {
  169. if (isUpdateOver)
  170. {
  171. isUpdateOver = false;
  172. Thread updateThread = new Thread(UpdateThread);
  173. updateThread.Start();
  174. }
  175. }
  176. private delegate void UpdateFormDataDelegate(LeftInfo leftInfo, CenterInfo centerInfo, RightInfo rightInfo);
  177. private void UpdateThread()
  178. {
  179. HomeFormInfoSvc svc = HomeFormInfoSvc.Instance;
  180. LeftInfo leftInfo = svc.GetLeftInfo();
  181. CenterInfo centerInfo = svc.GetCenterInfo();
  182. RightInfo rightInfo = svc.GetRightInfo();
  183. UpdateFormDataDelegate del = new UpdateFormDataDelegate(UpdateFormData);
  184. this.BeginInvoke(del, leftInfo, centerInfo, rightInfo);
  185. }
  186. private void UpdateFormData(LeftInfo leftInfo, CenterInfo centerInfo, RightInfo rightInfo)
  187. {
  188. try
  189. {
  190. BindDataLeft(leftInfo);
  191. BindDataCenter(centerInfo);
  192. BindDataRight(rightInfo);
  193. isUpdateOver = true;
  194. }
  195. catch (Exception e)
  196. {
  197. MessageBox.Show("数据更新失败,请检查网络或联系维护人员");
  198. }
  199. }
  200. private void BindDataLeft(LeftInfo info)
  201. {
  202. wlblPowerAll.LableText = info.PowerAll;
  203. wlblPowerDay.LableText = info.PowerByDay;
  204. wlblPowerDay.BindData(info.PowerByDay, "station", "-1", "RFDLB", "日发电量");
  205. wlblPowerMonth.BindData(info.PowerByMonth, "station", "-1", "YFDLB", "月发电量");
  206. wlblPowerYear.BindData(info.PowerByYear, "station", "-1", "NFDL", "年发电量");
  207. wlblUseHourByMonth.LableText = info.UseHourByMounth;
  208. wlblUseHourByYear.LableText = info.UseHourByYear;
  209. wlblSpeedNowByStation.BindData(info.WindSpeedNow, "station", "-1", "SSFS", "实时风速");
  210. wlblPowerNowByStation.BindData(info.PowerNow, "station", "-1", "SSZGL", "实时总功率");
  211. wlblLinkCount.LableText = info.LinkCount;
  212. wlblRunCount.LableText = info.RunCount;
  213. wlblStandByCount.LableText = info.StandByCount;
  214. wlblFaultCount.LableText = info.FaultCount;
  215. wlblMaintainCount.LableText = info.MaintainCount;
  216. wlblLimitCount.LableText = info.StopCount;
  217. wlblOfflineCount.LableText = info.OfflineCount;
  218. }
  219. private void BindDataCenter(CenterInfo info)
  220. {
  221. SFI_SBQ.Power = info.SBQ_PowerByNow;
  222. SFI_SBQ.Speed = info.SBQ_Speed;
  223. SFI_SBQ.UnitLable = "m/s";
  224. SFI_SBQ.WindSpeedOrLightLable = "实时风速";
  225. SFI_SBQ.PowerCount = info.SBQ_PowerByDay;
  226. wpf_SBQ.State = GetWindturbineStatus(info.SBQ_Status);
  227. SFI_MHS.Power = info.SBQ_PowerByNow;
  228. SFI_MHS.Speed = info.MHS_Speed;
  229. SFI_MHS.UnitLable = "m/s";
  230. SFI_MHS.WindSpeedOrLightLable = "实时风速";
  231. SFI_MHS.PowerCount = info.MHS_PowerByDay;
  232. wpf_MHS.State = GetWindturbineStatus(info.MHS_Status);
  233. SFI_QS.Power = info.SBQ_PowerByNow;
  234. SFI_QS.Speed = info.QS_Speed;
  235. SFI_QS.UnitLable = "m/s";
  236. SFI_QS.WindSpeedOrLightLable = "实时风速";
  237. SFI_QS.PowerCount = info.QS_PowerByDay;
  238. wpf_QS.State = GetWindturbineStatus(info.QS_Status);
  239. SFI_NSS.Power = info.SBQ_PowerByNow;
  240. SFI_NSS.Speed = info.NSS_Speed;
  241. SFI_NSS.UnitLable = "m/s";
  242. SFI_NSS.WindSpeedOrLightLable = "实时风速";
  243. SFI_NSS.PowerCount = info.NSS_PowerByDay;
  244. wpf_NSS.State = GetWindturbineStatus(info.NSS_Status);
  245. SFI_XS.Power = info.SBQ_PowerByNow;
  246. SFI_XS.Speed = info.XS_Speed;
  247. SFI_XS.UnitLable = "m/s";
  248. SFI_XS.WindSpeedOrLightLable = "实时风速";
  249. SFI_XS.PowerCount = info.XS_PowerByDay;
  250. wpf_XS.State = GetWindturbineStatus(info.XS_Status);
  251. }
  252. private void BindDataRight(RightInfo info)
  253. {
  254. historyLine.BuildChart(info.DateTimeArray, info.SpeedArray, info.PowerArray);
  255. datePowerStat.DataBind(info.InfoList);
  256. webfontLable16.LableText = info.SafetyDayCount;
  257. }
  258. private int GetWindturbineStatus(Status status)
  259. {
  260. int? statusValue = null;
  261. switch (status)
  262. {
  263. case Status.Run:
  264. statusValue = 1;
  265. break;
  266. case Status.StandBy:
  267. statusValue = 0;
  268. break;
  269. case Status.Falut:
  270. statusValue = 2;
  271. break;
  272. case Status.Maintain:
  273. statusValue = 4;
  274. break;
  275. case Status.Limit:
  276. statusValue = 5;
  277. break;
  278. case Status.Offline:
  279. statusValue = 3;
  280. break;
  281. default: break;
  282. }
  283. if (statusValue.HasValue)
  284. return statusValue.Value;
  285. else
  286. return 0;
  287. }
  288. }
  289. }