using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Uestc.Auto6.Dso.ComModel; using Uestc.Auto6.Dso.Core; using Uestc.Auto6.Dso.Core.Decode; using Uni_Trend.MSO7000X.Common.Helper; using Uni_Trend.MSO7000X.Language; using Uni_Trend.MSO7000X.UserControls.Style; namespace Uestc.Auto6.Dso.Protocol.CAN { public partial class CANErrorPacketPage : UserControl,ITriggerSerialView { #region 属性 public CANTrigSerialPrsnt Presenter { get; set; } ITriggerPrsnt IView.Presenter { get => Presenter; set => Presenter = (CANTrigSerialPrsnt)value; } protected new Boolean DesignMode { get { Boolean rtnflag = false; #if DEBUG rtnflag = DesignTimeHelper.InDesignMode(this); #endif return rtnflag; } } #endregion 属性 public CANErrorPacketPage() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); Init(); } private void Init() { DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize); InitErrorPacketType(); UpdateErrorPacketType(); } private void InitErrorPacketType() { this.CbxErrorPacketType.DataSource = Enum.GetValues().Select(x => { String key = String.Empty; key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString()); if (String.IsNullOrEmpty(key)) { key = x.ToString(); } return new KeyValuePair(key, x); }).ToList(); this.CbxErrorPacketType.ValueMember = "Value"; this.CbxErrorPacketType.DisplayMember = "Key"; this.CbxErrorPacketType.SelectedValueChanged += (_, _) => { Presenter.ErrorPacketType = (ComModel.ProtocolCAN.ErrorPacketType)this.CbxErrorPacketType.SelectedValue; }; } [UpdateProperty(nameof(CANTrigSerialPrsnt.ErrorPacketType))] private void UpdateErrorPacketType() { this.CbxErrorPacketType.SelectedValue = Presenter.ErrorPacketType; } public void UpdateView(Object presenter, String propertyName) { if (String.IsNullOrEmpty(propertyName)) { UpdateView(); return; } this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).Where(x => { UpdatePropertyAttribute attribute = x.GetCustomAttribute(); return attribute != null && attribute.PropertyName == propertyName; }).FirstOrDefault()?.Invoke(this, null); } private void UpdateView() { this.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic).Where(x => x.GetCustomAttribute() != null).ToList().ForEach(x => x?.Invoke(this, null)); this.Refresh(); } } }