using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; 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.Ethernet { public partial class TrigDataPage : UserControl, ITriggerSerialView { #region 属性 private FloatForm _FloatForm; private Int32 _RowHeight = 56; private Int32 _ColnumCount = 2; public EthernetTrigSerialPrsnt Presenter { get; set; } ITriggerPrsnt IView.Presenter { get => Presenter; set => Presenter = (EthernetTrigSerialPrsnt)value; } protected new Boolean DesignMode { get { Boolean rtnflag = false; #if DEBUG rtnflag = DesignTimeHelper.InDesignMode(this); #endif return rtnflag; } } #endregion 属性 public TrigDataPage() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); InitView(); UpdateView(); DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize); } private void InitView() { InitData(); InitRelation(); } private void InitRelation() { this.CbxRelation.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.CbxRelation.ValueMember = "Value"; this.CbxRelation.DisplayMember = "Key"; this.CbxRelation.SelectedValueChanged += (_, _) => { Presenter.Relation = (ComModel.ProtocolEthernet.DataRelation)this.CbxRelation.SelectedValue; }; this.CbxRelation.SelectedValue = Presenter.Relation; } 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.Instance| BindingFlags.NonPublic).Where(x => x.GetCustomAttribute() != null).ToList().ForEach(x => x?.Invoke(this, null)); this.Refresh(); } private void InitData() { this.BtnData.Click += (_, _) => { Boolean lastflag = true; if (this.FindForm() is FloatForm form) { lastflag = form.CanClose; form.CanClose = false; } if (_FloatForm != null && !_FloatForm.IsDisposed) _FloatForm?.Close(); _FloatForm = new FloatForm(); _FloatForm.BackColor = BackColor; _FloatForm.ForeColor = ForeColor; _FloatForm.Title = "设置数据"; _FloatForm.Width = 380; _FloatForm.Height = 500 + _FloatForm.HeadHeight; HexNumberKeyboard numberKeyboard = new HexNumberKeyboard(); numberKeyboard.Controls.Cast().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, StyleFlag.FontSize)); numberKeyboard.Top = _FloatForm.HeadHeight; numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight; numberKeyboard.Width = _FloatForm.Width; numberKeyboard.ForeColor = ForeColor; numberKeyboard.BackColor = BackColor; numberKeyboard.MaxValue = Byte.MaxValue; numberKeyboard.MinValue = 0; numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex; numberKeyboard.Value = Presenter.Data; numberKeyboard.OkClick += (sender, args) => { Presenter.Data = (Byte)args.Data; _FloatForm.Close(); }; numberKeyboard.CancelClick += (_, _) => _FloatForm.Close(); _FloatForm.Controls.Add(numberKeyboard); DefaultStyleManager.Instance.RegisterControlRecursion(_FloatForm, StyleFlag.FontSize); _FloatForm.FormClosing += (_, _) => { if (this.FindForm() is FloatForm form) form.CanClose = lastflag; }; _FloatForm.ShowByPosition(); }; UpdateData(); } [UpdateProperty(nameof(EthernetTrigSerialPrsnt.Data))] private void UpdateData() { this.BtnData.Text = $"{Presenter.Data:X2}"; } [UpdateProperty(nameof(EthernetTrigSerialPrsnt.Relation))] private void UpdateRelation() { this.CbxRelation.SelectedValue = Presenter.Relation; } } }