MHS_Project1.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_Project1 : 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_Project1()
  30. {
  31. InitializeComponent();
  32. Init();
  33. navSvc = NavService.Instance;
  34. IsRefreshDataOver = false;
  35. Thread t1 = new Thread(RefreshData);
  36. t1.IsBackground = true;
  37. t1.Start();
  38. FormDataBind();
  39. IsBindFormOver = false;
  40. Thread t = new Thread(BindFormInvoke);
  41. t.IsBackground = true;
  42. t.Start();
  43. }
  44. public override void Active()
  45. {
  46. timer1.Enabled = true;
  47. }
  48. public override void DeActive()
  49. {
  50. timer1.Enabled = false;
  51. }
  52. private void timer1_Tick(object sender, EventArgs e)
  53. {
  54. if (IsRefreshDataOver)
  55. {
  56. IsRefreshDataOver = false;
  57. Thread t = new Thread(RefreshData);
  58. t.IsBackground = true;
  59. t.Start();
  60. }
  61. if (IsBindFormOver)
  62. {
  63. IsBindFormOver = false;
  64. Thread t = new Thread(BindFormInvoke);
  65. t.IsBackground = true;
  66. t.Start();
  67. }
  68. }
  69. private void RefreshData()
  70. {
  71. // MHS_FDC MHS01_GC
  72. ZmWindturbineInfoSvc.GetInfo(this.stationId, this.projectId); //("MHS_FDC", "MHS01_GC");
  73. IsRefreshDataOver = true;
  74. }
  75. public delegate void UpdateFormInfoDelegate();
  76. public void BindFormInvoke()
  77. {
  78. UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(FormDataBind);
  79. if (this.InvokeRequired)
  80. {
  81. this.BeginInvoke(del, new object[] { });
  82. }
  83. else
  84. {
  85. FormDataBind();
  86. }
  87. IsBindFormOver = true;
  88. }
  89. #region
  90. //key: 风机ID
  91. private Dictionary<string, WindturbineInfoControl> dicWindturbineInfoControl;
  92. private string projectId = "MHS01_GC";
  93. private string stationId = "MHS_FDC";
  94. private void Init()
  95. {
  96. dicWindturbineInfoControl = new Dictionary<string, WindturbineInfoControl>();
  97. foreach (var p in this.Controls)
  98. {
  99. if(p is WindturbineInfoControl)
  100. {
  101. WindturbineInfoControl wifo = p as WindturbineInfoControl;
  102. if (wifo != null && !String.IsNullOrWhiteSpace(wifo.WindturbineId) && !dicWindturbineInfoControl.ContainsKey(wifo.WindturbineId))
  103. {
  104. dicWindturbineInfoControl.Add(wifo.WindturbineId, wifo);
  105. }
  106. }
  107. }
  108. }
  109. private void FormDataBind()
  110. {
  111. try
  112. {
  113. if (!timer1.Enabled)
  114. {
  115. return;
  116. }
  117. ZmWindturbineInfo[] tmplist = new ZmWindturbineInfo[ZmWindturbineInfoSvc.infoList.Count];
  118. ZmWindturbineInfoSvc.infoList.CopyTo(tmplist, 0);
  119. IList<ZmWindturbineInfo> list = tmplist.Where(s => s.ProjectId == projectId && s.StationId == stationId).ToList();
  120. if (this.IsHandleCreated)
  121. {
  122. this.BeginInvoke((Action)delegate
  123. {
  124. for (int i = 0; i < list.Count; i++)
  125. {
  126. if (dicWindturbineInfoControl.ContainsKey(list[i].WindturbineId))
  127. {
  128. dicWindturbineInfoControl[list[i].WindturbineId].BindData(list[i].Power, list[i].WindSpeed, Convert.ToInt32(list[i].Status));
  129. }
  130. }
  131. }
  132. );
  133. }
  134. }
  135. catch
  136. { }
  137. }
  138. private void Windturbine_MyClick(object sender, EventArgs e)
  139. {
  140. try
  141. {
  142. WindturbineInfoControl icon = (WindturbineInfoControl)sender;
  143. if (icon != null)
  144. {
  145. navSvc.NavForWindturbine("pictureBoxParamters", icon.WindturbineId, stationId);
  146. }
  147. }
  148. catch (Exception ex)
  149. {
  150. MessageBox.Show(ex.Message);
  151. }
  152. }
  153. #endregion
  154. }
  155. }