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; using Uni_Trend.MSO7000X.UserControls.Style; namespace Uestc.Auto6.Dso.Protocol.NRZ { [System.ComponentModel.ToolboxItem(false)] public partial class NRZDataPage : UserControl, ITriggerSerialView { #region 属性定义 protected new Boolean DesignMode { get { Boolean rtnflag = false; #if DEBUG rtnflag = DesignTimeHelper.InDesignMode(this); #endif return rtnflag; } } public NRZTrigSerialPrsnt Presenter { get; set; } ITriggerPrsnt IView.Presenter { get => Presenter; set => Presenter = (NRZTrigSerialPrsnt)value; } #endregion 属性定义 public NRZDataPage() { InitializeComponent(); } private void InitView() { Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(this, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); InitView(); Init(); } private void Init() { InitData(); InitRelation(); UpdateView(); } private void InitRelation() { this.CbxRelation.DataSource = Presenter.Relation.GetEnumList(); this.CbxRelation.DisplayMember = "Key"; this.CbxRelation.ValueMember = "Value"; this.CbxRelation.SelectedValueChanged += (sender, args) => { if (ParentForm == null) { } else { Presenter.Relation = (ProtocolNRZ.DataRelation)this.CbxRelation.SelectedValue; } }; this.CbxRelation.SelectedValue = Presenter.Relation; } private void InitData() { BtnData.Click += (_, _) => { 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"; HexNumberKeyboard numberKeyboard = new HexNumberKeyboard(); numberKeyboard.Controls.Cast().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize)); 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.ValueType = HexNumberKeyboard.HexValueType.Hex; numberKeyboard.MinValue = Presenter.MinData; numberKeyboard.MaxValue = Presenter.MaxData; numberKeyboard.OkClick += (sender, args) => { this.Presenter.Data = (Byte)args.Data; floatForm?.Close(); }; numberKeyboard.CancelClick += (sender, args) => floatForm?.Close(); floatForm.Controls.Add(numberKeyboard); DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize); 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(); } else { this.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(x => { UpdatePropertyAttribute attribute = x.GetCustomAttribute(); return attribute != null && String.Equals(attribute.PropertyName, propertyName); }).ToList().ForEach(x => x.Invoke(this, null)); } } private void UpdateView() { this.GetType().GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) .Where(x => x.GetCustomAttribute() != null).ToList().ForEach(x => x.Invoke(this, null)); } [UpdateProperty(nameof(NRZTrigSerialPrsnt.Data))] private void UpdateData() { this.BtnData.Text = $"{Presenter.Data:X2}"; } [UpdateProperty(nameof(NRZTrigSerialPrsnt.Relation))] private void UpdateRelation() { this.CbxRelation.SelectedValue = Presenter.Relation; } } }