MHS_Project2.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using IntelligentControlForsx.Service;
  12. using IntelligentControlForsx.Service.ZM;
  13. using IntelligentControlForsx.Service.ZM.Domain;
  14. using log4net;
  15. namespace IntelligentControlForsx.MyControls.zm.map
  16. {
  17. public partial class MHS_Project2 : MapControl
  18. {
  19. private static ILog logger = LogManager.GetLogger("AppInfoLog");
  20. /// <summary>
  21. /// 数据访问是否结束
  22. /// </summary>
  23. private bool IsRefreshDataOver = true;
  24. /// <summary>
  25. /// 绑定页面是否结束
  26. /// </summary>
  27. private bool IsBindFormOver = true;
  28. private NavService navSvc;
  29. public MHS_Project2()
  30. {
  31. InitializeComponent();
  32. Init();//WXW
  33. navSvc = NavService.Instance;
  34. }
  35. public override void Active()
  36. {
  37. timer1.Enabled = true;
  38. }
  39. public override void DeActive()
  40. {
  41. timer1.Enabled = false;
  42. }
  43. private void timer1_Tick(object sender, EventArgs e)
  44. {
  45. if (IsRefreshDataOver)
  46. {
  47. IsRefreshDataOver = false;
  48. Thread t = new Thread(RefreshData);
  49. t.IsBackground = true;
  50. t.Start();
  51. }
  52. if (IsBindFormOver)
  53. {
  54. IsBindFormOver = false;
  55. Thread t = new Thread(BindFormInvoke);
  56. t.IsBackground = true;
  57. t.Start();
  58. }
  59. }
  60. private void RefreshData()
  61. {
  62. ZmWindturbineInfoSvc.GetInfo(this.stationId, this.projectId); //("SBQ_FDC", "SBQ02_GC");
  63. IsRefreshDataOver = true;
  64. }
  65. public delegate void UpdateFormInfoDelegate();
  66. public void BindFormInvoke()
  67. {
  68. UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(FormDataBind);
  69. if (this.InvokeRequired)
  70. {
  71. this.BeginInvoke(del, new object[] { });
  72. }
  73. else
  74. {
  75. FormDataBind();
  76. }
  77. IsBindFormOver = true;
  78. }
  79. #region
  80. //key: 风机ID
  81. private Dictionary<string, WindturbineInfoControl> dicWindturbineInfoControl;
  82. private string projectId = "MHS02_GC";
  83. private string stationId = "MHS_FDC";
  84. private void Init()
  85. {
  86. dicWindturbineInfoControl = new Dictionary<string, WindturbineInfoControl>();
  87. foreach (var p in this.Controls)
  88. {
  89. if (p is WindturbineInfoControl)
  90. {
  91. WindturbineInfoControl wifo = p as WindturbineInfoControl;
  92. if (wifo != null && !String.IsNullOrWhiteSpace(wifo.WindturbineId) && !dicWindturbineInfoControl.ContainsKey(wifo.WindturbineId))
  93. {
  94. dicWindturbineInfoControl.Add(wifo.WindturbineId, wifo);
  95. }
  96. }
  97. }
  98. }
  99. private void FormDataBind()
  100. {
  101. try
  102. {
  103. if (!timer1.Enabled)
  104. {
  105. return;
  106. }
  107. ZmWindturbineInfo[] tmplist = new ZmWindturbineInfo[ZmWindturbineInfoSvc.infoList.Count];
  108. ZmWindturbineInfoSvc.infoList.CopyTo(tmplist, 0);
  109. IList<ZmWindturbineInfo> list = tmplist.Where(s => s.ProjectId == projectId && s.StationId == stationId).ToList();
  110. if (this.IsHandleCreated)
  111. {
  112. this.BeginInvoke((Action)delegate
  113. {
  114. for (int i = 0; i < list.Count; i++)
  115. {
  116. if (dicWindturbineInfoControl.ContainsKey(list[i].WindturbineId))
  117. {
  118. dicWindturbineInfoControl[list[i].WindturbineId].BindData(list[i].Power, list[i].WindSpeed, Convert.ToInt32(list[i].Status));
  119. }
  120. }
  121. }
  122. );
  123. }
  124. }
  125. catch
  126. { }
  127. }
  128. private void Windturbine_MyClick(object sender, EventArgs e)
  129. {
  130. try
  131. {
  132. WindturbineInfoControl icon = (WindturbineInfoControl)sender;
  133. if (icon != null)
  134. {
  135. navSvc.NavForWindturbine("pictureBoxParamters", icon.WindturbineId, stationId);
  136. }
  137. }
  138. catch (Exception ex)
  139. {
  140. MessageBox.Show(ex.Message);
  141. }
  142. }
  143. #endregion
  144. }
  145. }