CANErrorPacketPage.cs 3.5 KB

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