SBQ_Project3.cs 4.3 KB

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