XXXXSetControl.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System.Reflection;
  2. using System.Windows.Forms;
  3. using Uestc.Auto6.Dso.Core;
  4. using Uestc.Auto6.Dso.Core.Decode;
  5. using Uestc.Auto6.Dso.ComModel;
  6. using Uni_Trend.MSO7000X.Language;
  7. using Uni_Trend.MSO7000X.Common.Helper;
  8. using Uni_Trend.MSO7000X.UserControls;
  9. namespace Uestc.Auto6.Dso.Protocol.XXXX
  10. {
  11. public partial class XXXXSetControl : UserControl, IProtocolView
  12. {
  13. #region 属性定义
  14. protected new Boolean DesignMode
  15. {
  16. get
  17. {
  18. Boolean rtnflag = false;
  19. #if DEBUG
  20. rtnflag = DesignTimeHelper.InDesignMode(this);
  21. #endif
  22. return rtnflag;
  23. }
  24. }
  25. public XXXXDecodePrsnt DestinDecodePrsnt
  26. {
  27. get => _DestinDecodePrsnt;
  28. set
  29. {
  30. if (_DestinDecodePrsnt != value)
  31. {
  32. _DestinDecodePrsnt = value;
  33. ///当有新的同步目标时,应先将目标中参数同步到本地<see cref="I2CDecodePsrnt"/>属性中
  34. if (_XXXXDecodePsrnt != null && value != null)
  35. {
  36. typeof(XXXXDecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x =>
  37. {
  38. x.SetValue(_XXXXDecodePsrnt, x.GetValue(value));
  39. });
  40. }
  41. }
  42. }
  43. }
  44. private XXXXDecodePrsnt _DestinDecodePrsnt;
  45. private XXXXDecodePrsnt _XXXXDecodePsrnt => Presenter as XXXXDecodePrsnt;
  46. public IProtocolPrsnt Presenter { get; set; }
  47. private FloatForm _FloatForm;
  48. #endregion 属性定义
  49. public XXXXSetControl()
  50. {
  51. InitializeComponent();
  52. }
  53. protected override void OnLoad(EventArgs e)
  54. {
  55. base.OnLoad(e);
  56. Init();
  57. }
  58. private void Init()
  59. {
  60. GetDestinPrsnt();
  61. }
  62. /// <summary>
  63. /// 获取需要同步的Prsnt
  64. /// 当<see cref="_XXXXDecodePsrnt"/>为<see cref="null"/>时表示不需要与其他Prsnt进行同步
  65. /// </summary>
  66. private void GetDestinPrsnt()
  67. {
  68. }
  69. /// <summary>
  70. /// 同步两个Prsnt
  71. /// </summary>
  72. /// <param name="propertyName">属性名称</param>
  73. private void DecodeSynchronization(String propertyName)
  74. {
  75. if (DestinDecodePrsnt == null)
  76. return;
  77. ///由于使用了<see cref="IXXXXDecodePrsnt.SDA"/>进行判断具体同步的目标
  78. ///因此<see cref="IXXXXDecodePrsnt.SDA"/>参数不进行同步
  79. if (propertyName == nameof(I2CDecodePrsnt.SDA))
  80. return;
  81. if (String.IsNullOrEmpty(propertyName))
  82. {
  83. typeof(I2CDecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x =>
  84. {
  85. x.SetValue(DestinDecodePrsnt, x.GetValue(XXXXDecodePsrnt));
  86. });
  87. }
  88. else
  89. {
  90. PropertyInfo propertyInfo = typeof(XXXXDecodePrsnt).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
  91. if (propertyInfo != null)
  92. propertyInfo.SetValue(DestinDecodePrsnt, propertyInfo.GetValue(XXXXDecodePsrnt));
  93. }
  94. }
  95. public void UpdateView(String propertyName)
  96. {
  97. DecodeSynchronization(propertyName);
  98. if (String.IsNullOrEmpty(propertyName))
  99. {
  100. UpdateView();
  101. return;
  102. }
  103. }
  104. private void UpdateView()
  105. {
  106. this.GetType().GetMethods().Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x?.Invoke(this, null));
  107. this.Refresh();
  108. }
  109. }
  110. }