FlexRayIndicatorPage.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using Uestc.Auto6.Dso.Core;
  12. using Uestc.Auto6.Dso.Core.Decode;
  13. using Uestc.Auto6.Dso.ComModel;
  14. using Uni_Trend.MSO7000X.Common.Helper;
  15. using Uni_Trend.MSO7000X.UserControls;
  16. using Uni_Trend.MSO7000X.UserControls.Style;
  17. using Uni_Trend.MSO7000X.Language;
  18. namespace Uestc.Auto6.Dso.Protocol.FlexRay
  19. {
  20. public partial class FlexRayIndicatorPage : UserControl, ITriggerSerialView
  21. {
  22. #region 属性
  23. public FlexRayTrigSerialPrsnt Presenter { get; set; }
  24. ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
  25. {
  26. get => Presenter;
  27. set => Presenter = (FlexRayTrigSerialPrsnt)value;
  28. }
  29. protected new Boolean DesignMode
  30. {
  31. get
  32. {
  33. Boolean rtnflag = false;
  34. #if DEBUG
  35. rtnflag = DesignTimeHelper.InDesignMode(this);
  36. #endif
  37. return rtnflag;
  38. }
  39. }
  40. #endregion 属性
  41. public FlexRayIndicatorPage()
  42. {
  43. InitializeComponent();
  44. }
  45. protected override void OnLoad(EventArgs e)
  46. {
  47. base.OnLoad(e);
  48. Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize);
  49. InitView();
  50. }
  51. private void InitView()
  52. {
  53. InitIndicator();
  54. UpdateView();
  55. }
  56. public void UpdateView(Object presenter, String propertyName)
  57. {
  58. if (String.IsNullOrEmpty(propertyName))
  59. {
  60. UpdateView();
  61. return;
  62. }
  63. this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(x =>
  64. {
  65. UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
  66. return attribute != null && attribute.PropertyName == propertyName;
  67. }).FirstOrDefault()?.Invoke(this, null);
  68. }
  69. private void UpdateView()
  70. {
  71. this.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x =>
  72. {
  73. x?.Invoke(this, null);
  74. });
  75. this.Refresh();
  76. }
  77. private void InitIndicator()
  78. {
  79. this.CbxIndicatorRelation.DataSource = Enum.GetValues<ProtocolFlexRay.Indicator>().Select(x =>
  80. {
  81. String key = String.Empty;
  82. key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
  83. if (String.IsNullOrEmpty(key))
  84. {
  85. key = x.ToString();
  86. }
  87. return new KeyValuePair<String, ProtocolFlexRay.Indicator>(key, x);
  88. }).ToList();
  89. this.CbxIndicatorRelation.ValueMember = "Value";
  90. this.CbxIndicatorRelation.DisplayMember = "Key";
  91. this.CbxIndicatorRelation.SelectedValueChanged += (_, _) =>
  92. {
  93. Presenter.Indicator = (ProtocolFlexRay.Indicator)CbxIndicatorRelation.SelectedValue;
  94. };
  95. UpdateIndicator();
  96. }
  97. [UpdateProperty(nameof(FlexRayTrigSerialPrsnt.Indicator))]
  98. private void UpdateIndicator()
  99. {
  100. this.CbxIndicatorRelation.SelectedValue = Presenter.Indicator;
  101. }
  102. }
  103. }