OutInInfo.cs 5.2 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.WindturbineInfo;
  12. using log4net;
  13. using log4net.Util;
  14. using WisdomClient;
  15. using WisdomClient.data;
  16. namespace IntelligentControlForsx.MyControls.windturbine
  17. {
  18. /// <summary>
  19. /// 输入输出
  20. /// </summary>
  21. public partial class OutInInfo : BaseControl
  22. {
  23. private static ILog logger = LogManager.GetLogger("AppInfoLog");
  24. private string partNow = "";
  25. Dictionary<string, IList<UniformCodeInfo>> infoDic = new Dictionary<string, IList<UniformCodeInfo>>();
  26. private string stationIdNow = "";
  27. private string windturbineIdNow = "";
  28. private string modelIdNow = "";
  29. public OutInInfo()
  30. {
  31. InitializeComponent();
  32. LeftBind(STATIONID, WINDTURBINEID, MODELID);
  33. }
  34. public override void Active(string stationId, string windturbineId, string modelId)
  35. {
  36. STATIONID = stationId;
  37. WINDTURBINEID = windturbineId;
  38. stationIdNow = stationId;
  39. windturbineIdNow = windturbineId;
  40. modelIdNow = modelId;
  41. partNow = "part1";
  42. timer1.Enabled = true;
  43. Refresh();
  44. }
  45. public override void DeActive()
  46. {
  47. timer1.Enabled = false;
  48. }
  49. private void timer1_Tick(object sender, EventArgs e)
  50. {
  51. if (isRefreshOver)
  52. {
  53. isRefreshOver = false;
  54. //刷新数据线程
  55. Thread refreshThread = new Thread(RefreshData);
  56. refreshThread.Start();
  57. isRefreshOver = true;
  58. }
  59. //绑定数据线程
  60. Thread bindDataThread = new Thread(RefreshFormData);
  61. bindDataThread.Start();
  62. }
  63. private void RefreshData()
  64. {
  65. WindturbineInfoSvc infoSvc = WindturbineInfoSvc.Instance;
  66. if (infoDic.ContainsKey(partNow))
  67. infoSvc.RefreshPointValue(infoDic[partNow], windturbineIdNow);
  68. }
  69. private delegate void BindFormInfoDelegate();
  70. private void RefreshFormData()
  71. {
  72. BindFormInfoDelegate del = new BindFormInfoDelegate(BindFormData);
  73. if (this.InvokeRequired)
  74. {
  75. this.BeginInvoke(del, new object[] { });
  76. }
  77. else
  78. {
  79. BindFormData();
  80. }
  81. }
  82. private void BindFormData()
  83. {
  84. IList<UniformCodeInfo> list = WindturbineInfoSvc.Instance.GetPointData();
  85. for (int i = 0; i < plInfo.Controls.Count; i++)
  86. {
  87. if (plInfo.Controls[i] is OutInLine)
  88. {
  89. OutInLine ol = (OutInLine)plInfo.Controls[i];
  90. UniformCodeInfo info = list.Where(s => s.PlcName == ol.Name).FirstOrDefault();
  91. if (info != null)
  92. {
  93. ol.PointValue = info.PointValue;
  94. }
  95. }
  96. }
  97. }
  98. public void LeftBind(string stationId, string windturbineId, string model)
  99. {
  100. windturbineIdNow = windturbineId;
  101. modelIdNow = model;
  102. stationIdNow = stationId;
  103. plType.Controls.Clear();
  104. IList<UniformCodeInfo> list = UniformCodeInfoSvc.GetUniformCode(stationId, model, "OutIn");
  105. Dictionary<string, IList<UniformCodeInfo>> dic = new Dictionary<string, IList<UniformCodeInfo>>();
  106. for (int i = 0; i < list.Count; i++)
  107. {
  108. IList<UniformCodeInfo> dicList = new List<UniformCodeInfo>();
  109. if (!dic.ContainsKey(list[i].PartIndex))
  110. {
  111. dicList.Add(list[i]);
  112. dic.Add(list[i].PartIndex, dicList);
  113. }
  114. else
  115. {
  116. dicList = dic[list[i].PartIndex];
  117. dicList.Add(list[i]);
  118. }
  119. }
  120. foreach (var item in dic)
  121. {
  122. LabelName ln = new LabelName();
  123. if (item.Value.Count > 0)
  124. ln.LblName = item.Value[0].PartName;
  125. ln.Name = item.Key;
  126. ln.Dock = DockStyle.Top;
  127. ln.MyClick += Type_Clikc;
  128. plType.Controls.Add(ln);
  129. }
  130. infoDic = dic;
  131. }
  132. private void Type_Clikc(object sender, EventArgs e)
  133. {
  134. partNow = sender.ToString();
  135. plInfo.Controls.Clear();
  136. string typeName = sender.ToString();
  137. IList<UniformCodeInfo> list = infoDic[typeName];
  138. for (int i = 0; i < list.Count; i++)
  139. {
  140. OutInLine ln = new OutInLine();
  141. ln.Name = list[i].PlcName;
  142. ln.PointName = list[i].Name;
  143. ln.PLCName = list[i].PlcName;
  144. ln.Dock = DockStyle.Top;
  145. plInfo.Controls.Add(ln);
  146. }
  147. }
  148. }
  149. }