NSS_Project1.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 NSS_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 NSS_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. ZmWindturbineInfoSvc.GetInfo(this.stationId, this.projectId);//("SBQ_FDC", "SBQ01_GC");
  72. IsRefreshDataOver = true;
  73. }
  74. public delegate void UpdateFormInfoDelegate();
  75. public void BindFormInvoke()
  76. {
  77. UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(FormDataBind);
  78. if (this.InvokeRequired)
  79. {
  80. this.BeginInvoke(del, new object[] { });
  81. }
  82. else
  83. {
  84. FormDataBind();
  85. }
  86. IsBindFormOver = true;
  87. }
  88. #region
  89. //key: 风机ID
  90. private Dictionary<string, WindturbineInfoControl> dicWindturbineInfoControl;
  91. private string projectId = "NSS01_GC";
  92. private string stationId = "NSS_FDC";
  93. private void Init()
  94. {
  95. dicWindturbineInfoControl = new Dictionary<string, WindturbineInfoControl>();
  96. foreach (var p in this.Controls)
  97. {
  98. if (p is WindturbineInfoControl)
  99. {
  100. WindturbineInfoControl wifo = p as WindturbineInfoControl;
  101. if (wifo != null && !String.IsNullOrWhiteSpace(wifo.WindturbineId) && !dicWindturbineInfoControl.ContainsKey(wifo.WindturbineId))
  102. {
  103. dicWindturbineInfoControl.Add(wifo.WindturbineId, wifo);
  104. }
  105. }
  106. }
  107. }
  108. private void FormDataBind()
  109. {
  110. try
  111. {
  112. if (!timer1.Enabled)
  113. {
  114. return;
  115. }
  116. ZmWindturbineInfo[] tmplist = new ZmWindturbineInfo[ZmWindturbineInfoSvc.infoList.Count];
  117. ZmWindturbineInfoSvc.infoList.CopyTo(tmplist, 0);
  118. IList<ZmWindturbineInfo> list = tmplist.Where(s => s.ProjectId == projectId && s.StationId == stationId).ToList();
  119. if (this.IsHandleCreated)
  120. {
  121. this.BeginInvoke((Action)delegate
  122. {
  123. for (int i = 0; i < list.Count; i++)
  124. {
  125. if (dicWindturbineInfoControl.ContainsKey(list[i].WindturbineId))
  126. {
  127. dicWindturbineInfoControl[list[i].WindturbineId].BindData(list[i].Power, list[i].WindSpeed, Convert.ToInt32(list[i].Status));
  128. }
  129. }
  130. }
  131. );
  132. }
  133. }
  134. catch
  135. { }
  136. }
  137. private void Windturbine_MyClick(object sender, EventArgs e)
  138. {
  139. try
  140. {
  141. WindturbineInfoControl icon = (WindturbineInfoControl)sender;
  142. if (icon != null)
  143. {
  144. navSvc.NavForWindturbine("pictureBoxParamters", icon.WindturbineId, stationId);
  145. }
  146. }
  147. catch (Exception ex)
  148. {
  149. MessageBox.Show(ex.Message);
  150. }
  151. }
  152. #endregion
  153. }
  154. }