123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- 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.SATA
- {
- public partial class DataPage : UserControl,Uestc.Auto6.Dso.Core.ITriggerSerialView
- {
- #region 属性定义
- protected new Boolean DesignMode
- {
- get
- {
- Boolean rtnflag = false;
- #if DEBUG
- rtnflag = DesignTimeHelper.InDesignMode(this);
- #endif
- return rtnflag;
- }
- }
- public SATATrigSerialPrsnt Presenter { get; set; }
- ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
- {
- get => Presenter;
- set => Presenter = (SATATrigSerialPrsnt)value;
- }
- #endregion 属性定义
- public DataPage()
- {
- InitializeComponent();
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- InitView();
- }
- private void InitView()
- {
- Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(this, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize);
- if (!DesignMode)
- {
- InitRelation();
- InitData();
- InitDataCount();
- UpdateData();
- UpdateDateLenght();
- UpdateRelation();
- }
- }
- private void InitRelation()
- {
- this.CbxRelation.DataSource = Enum.GetValues<ProtocolSATA.DataRelation>().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<String, ProtocolSATA.DataRelation>(key, x);
- }).ToList();
- this.CbxRelation.DisplayMember = "Key";
- this.CbxRelation.ValueMember = "Value";
- this.CbxRelation.SelectedValueChanged += (sender, args) =>
- {
- if (ParentForm == null)
- {
- }
- else
- {
- Presenter.Relation = (ProtocolSATA.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<Control>().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 = 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();
- };
- }
- private void InitDataCount()
- {
- BtnDataCount.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 = "设置AT";
- HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
- numberKeyboard.Controls.Cast<Control>().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.DataCount;
- numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
- numberKeyboard.MinValue = Presenter.MinDataCount;
- numberKeyboard.MaxValue = Presenter.MaxDataCount;
- numberKeyboard.OkClick += (sender, args) =>
- {
- this.Presenter.DataCount = (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<UpdatePropertyAttribute>();
- 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<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x.Invoke(this, null));
- }
- [UpdateProperty(nameof(SATATrigSerialPrsnt.DataCount))]
- private void UpdateDateLenght()
- {
- this.BtnDataCount.Text = Presenter.DataCount.ToString();
- }
- [UpdateProperty(nameof(SATATrigSerialPrsnt.Data))]
- private void UpdateData()
- {
- this.BtnData.Text = $"0x{Convert.ToString(Presenter.Data, 16).PadLeft(Presenter.DataCount * 2, '0')}";
- }
- [UpdateProperty(nameof(SATATrigSerialPrsnt.Relation))]
- private void UpdateRelation()
- {
- this.CbxRelation.SelectedValue = Presenter.Relation;
- }
- }
- }
|