SBQ_Project1.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 SBQ_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 SBQ_Project1()
  30. {
  31. InitializeComponent();
  32. navSvc = NavService.Instance;
  33. IsRefreshDataOver = false;
  34. Thread t1 = new Thread(RefreshData);
  35. t1.IsBackground = true;
  36. t1.Start();
  37. FormDataBind();
  38. IsBindFormOver = false;
  39. Thread t = new Thread(BindFormInvoke);
  40. t.IsBackground = true;
  41. t.Start();
  42. }
  43. public override void Active()
  44. {
  45. timer1.Enabled = true;
  46. }
  47. public override void DeActive()
  48. {
  49. timer1.Enabled = false;
  50. }
  51. private void timer1_Tick(object sender, EventArgs e)
  52. {
  53. if (IsRefreshDataOver)
  54. {
  55. IsRefreshDataOver = false;
  56. Thread t = new Thread(RefreshData);
  57. t.IsBackground = true;
  58. t.Start();
  59. }
  60. if (IsBindFormOver)
  61. {
  62. IsBindFormOver = false;
  63. Thread t = new Thread(BindFormInvoke);
  64. t.IsBackground = true;
  65. t.Start();
  66. }
  67. }
  68. private void RefreshData()
  69. {
  70. ZmWindturbineInfoSvc.GetInfo("SBQ_FDC", "SBQ01_GC");
  71. IsRefreshDataOver = true;
  72. }
  73. public delegate void UpdateFormInfoDelegate();
  74. public void BindFormInvoke()
  75. {
  76. UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(FormDataBind);
  77. if (this.InvokeRequired)
  78. {
  79. this.BeginInvoke(del, new object[] { });
  80. }
  81. else
  82. {
  83. FormDataBind();
  84. }
  85. IsBindFormOver = true;
  86. }
  87. private void FormDataBind()
  88. {
  89. try
  90. {
  91. if (!timer1.Enabled)
  92. {
  93. return;
  94. }
  95. ZmWindturbineInfo[] tmplist = new ZmWindturbineInfo[ZmWindturbineInfoSvc.infoList.Count];
  96. ZmWindturbineInfoSvc.infoList.CopyTo(tmplist, 0);
  97. IList<ZmWindturbineInfo> list = tmplist.Where(s => s.ProjectId == "SBQ01_GC" && s.StationId == "SBQ_FDC").ToList();
  98. for (int i = 0; i < list.Count; i++)
  99. {
  100. string controlName = "wf" + list[i].WindturbineId.Replace("SG01_", "");
  101. Control ct = this.Controls.Find(controlName, true).FirstOrDefault();
  102. if (ct != null)
  103. {
  104. try
  105. {
  106. if (ct is WindturbineInfoControl)
  107. {
  108. WindturbineInfoControl wc = (WindturbineInfoControl)ct;
  109. wc.BindData(list[i].Power, list[i].WindSpeed, Convert.ToInt32(list[i].Status));
  110. }
  111. }
  112. catch (Exception ex)
  113. {
  114. logger.Info("寻找控件或控件转换失败" + ex.Message);
  115. }
  116. }
  117. }
  118. }
  119. catch { }
  120. }
  121. private void Windturbine_MyClick(object sender, EventArgs e)
  122. {
  123. try
  124. {
  125. WindturbineInfoControl icon = (WindturbineInfoControl)sender;
  126. if (icon != null)
  127. {
  128. string windturbineId = "SG01_" + icon.WindturbineName.Replace("号", "").Trim();
  129. navSvc.NavForWindturbine("pictureBoxParamters", windturbineId, "SBQ_FDC");
  130. }
  131. }
  132. catch (Exception ex)
  133. {
  134. MessageBox.Show(ex.Message);
  135. }
  136. }
  137. }
  138. }