BaseControl.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. namespace IntelligentControlForsx.MyControls.windturbine
  14. {
  15. public partial class BaseControl : UserControl
  16. {
  17. /// <summary>
  18. /// 风场编号
  19. /// </summary>
  20. public string STATIONID = "SBQ_FDC";
  21. /// <summary>
  22. /// 风机编号
  23. /// </summary>
  24. public string WINDTURBINEID = "SG01_01";
  25. /// <summary>
  26. /// 风机型号
  27. /// </summary>
  28. public string MODELID = "UP82_2";
  29. /// <summary>
  30. /// 数据是否刷新完毕
  31. /// </summary>
  32. public bool isRefreshOver = true;
  33. private static ILog logger = LogManager.GetLogger("AppInfoLog");
  34. public BaseControl()
  35. {
  36. InitializeComponent();
  37. }
  38. public virtual void Active(string stationId, string windturbineId, string modelId)
  39. {
  40. }
  41. public virtual void DeActive()
  42. {
  43. }
  44. public delegate void UpdateFormInfoDelegate();
  45. public void BindData()
  46. {
  47. UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(PointInfoBind);
  48. if (this.InvokeRequired)
  49. {
  50. this.BeginInvoke(del, new object[] { });
  51. }
  52. else
  53. {
  54. PointInfoBind();
  55. }
  56. }
  57. public void PointInfoBind()
  58. {
  59. IList<UniformCodeInfo> list = WindturbineInfoSvc.Instance.GetPointData();
  60. foreach (var data in list)
  61. {
  62. string controlName = "P" + data.PartIndex.Replace("part", "") + "_PointValue" + data.Index;
  63. try
  64. {
  65. object obj = this.GetType().GetField(controlName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
  66. | System.Reflection.BindingFlags.IgnoreCase).GetValue(this);
  67. if (obj is PointValueAI)
  68. {
  69. PointValueAI ai = (PointValueAI)obj;
  70. ai.BindData(data);
  71. }
  72. else if (obj is PointValueDI)
  73. {
  74. PointValueDI di = (PointValueDI)obj;
  75. di.BindData(data);
  76. }
  77. }
  78. catch (Exception ex)
  79. {
  80. logger.Error("绑定数据时,找不到控件:" + ex);
  81. }
  82. }
  83. }
  84. public void Refresh()
  85. {
  86. WindturbineInfoSvc infoSvc = WindturbineInfoSvc.Instance;
  87. infoSvc.RefreshPointValue(STATIONID, WINDTURBINEID, MODELID, this.GetType().Name);
  88. }
  89. }
  90. }