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.Core; using Uestc.Auto6.Dso.Core.Decode; using Uestc.Auto6.Dso.ComModel; using Uni_Trend.MSO7000X.Common.Helper; using Uni_Trend.MSO7000X.UserControls; using Uni_Trend.MSO7000X.UserControls.Style; using Uni_Trend.MSO7000X.Language; namespace Uestc.Auto6.Dso.Protocol.AudioBus { public partial class AudioBusDataRelationPage : UserControl, ITriggerSerialView { #region 属性 public AudioBusTrigSerialPrsnt Presenter { get; set; } ITriggerPrsnt IView.Presenter { get => Presenter; set => Presenter = (AudioBusTrigSerialPrsnt)value; } protected new Boolean DesignMode { get { Boolean rtnflag = false; #if DEBUG rtnflag = DesignTimeHelper.InDesignMode(this); #endif return rtnflag; } } #endregion 属性 public AudioBusDataRelationPage() { InitializeComponent(); DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); InitView(); } private void InitView() { InitDataRelation(); InitData(); UpdateView(); } private void InitData() { this.BtnData.Click += (_, _) => SetData(); } private void SetData() { Boolean lastflag = true; if (this.FindForm() is FloatForm form) { lastflag = form.CanClose; form.CanClose = false; } FloatForm floatForm = new FloatForm(); floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm(); floatForm.BackColor = BackColor; floatForm.ForeColor = ForeColor; floatForm.Width = 380; floatForm.Height = 460 + floatForm.HeadHeight; floatForm.Title = "设置Data"; Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard numberKeyboard = new Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard(); numberKeyboard.Controls.Cast().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControl(x)); numberKeyboard.Top = floatForm.HeadHeight; numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight; numberKeyboard.Width = floatForm.Width; numberKeyboard.ForeColor = ForeColor; numberKeyboard.BackColor = BackColor; numberKeyboard.Value = Presenter.Data; numberKeyboard.MinValue = 0; numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex; numberKeyboard.MaxValue = UInt32.MaxValue; numberKeyboard.OkClick += (sender, args) => { Presenter.Data = (UInt32)args.Data; floatForm?.Close(); }; numberKeyboard.CancelClick += (sender, args) => floatForm?.Close(); floatForm.Controls.Add(numberKeyboard); floatForm.FormClosing += (_, _) => { if (this.FindForm() is FloatForm form) form.CanClose = lastflag; }; floatForm.ShowDialogByPosition(); } public void UpdateView(Object presenter, String propertyName) { if (string.IsNullOrEmpty(propertyName)) { UpdateView(); return; } this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).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.NonPublic | BindingFlags.Instance).Where(x => x.GetCustomAttribute() != null).ToList().ForEach(x => { x?.Invoke(this, null); }); this.Refresh(); } #region 数据初始化 private void InitDataRelation() { this.CbxDataRelation.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.CbxDataRelation.ValueMember = "Value"; this.CbxDataRelation.DisplayMember = "Key"; this.CbxDataRelation.SelectedValueChanged += (_, _) => { Presenter.DataRelation = (ProtocolAudioBus.DataRelation)CbxDataRelation.SelectedValue; }; UpdateDataRelation(); } #endregion #region 更新数据 [UpdateProperty(nameof(AudioBusTrigSerialPrsnt.DataRelation))] private void UpdateDataRelation() { this.CbxDataRelation.SelectedValue = Presenter.DataRelation; } [UpdateProperty(nameof(AudioBusTrigSerialPrsnt.Data))] private void UpdateData() { this.BtnData.Text = $"0x{Presenter.Data:X8}"; } #endregion } }