123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- 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.PCIe
- {
- public partial class TransIDPage : UserControl,ITriggerSerialView
- {
- #region 属性定义
- protected new Boolean DesignMode
- {
- get
- {
- Boolean rtnflag = false;
- #if DEBUG
- rtnflag = DesignTimeHelper.InDesignMode(this);
- #endif
- return rtnflag;
- }
- }
- public PCIeTrigSerialPrsnt Presenter { get; set; }
- ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
- {
- get => Presenter;
- set => Presenter = (PCIeTrigSerialPrsnt)value;
- }
- #endregion 属性定义
- public TransIDPage()
- {
- 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();
- InitBusNumber();
- InitDeviceNumber();
- InitFunctionNumber();
- InitTag();
- UpdateBusNumber();
- UpdateDeviceNumber();
- UpdateFunctionNumber();
- UpdateRelation();
- UpdateTag();
- }
-
- }
- private void InitBusNumber()
- {
- BtnBusNumber.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.BusNumber;
- numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
- numberKeyboard.MinValue = Presenter.MinBusNumber;
- numberKeyboard.MaxValue = Presenter.MaxBusNumber;
- numberKeyboard.OkClick += (sender, args) =>
- {
- this.Presenter.BusNumber = (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();
- };
- }
- private void InitDeviceNumber()
- {
- BtnDeviceNumber.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.DeviceNumber;
- numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
- numberKeyboard.MinValue = Presenter.MinDeviceNumber;
- numberKeyboard.MaxValue = Presenter.MaxDeviceNumber;
- numberKeyboard.OkClick += (sender, args) =>
- {
- this.Presenter.DeviceNumber = (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();
- };
- }
- private void InitTag()
- {
- BtnTag.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.TagData;
- numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
- numberKeyboard.MinValue = Presenter.MinTagData;
- numberKeyboard.MaxValue = Presenter.MaxTagData;
- numberKeyboard.OkClick += (sender, args) =>
- {
- this.Presenter.TagData = (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();
- };
- }
- private void InitFunctionNumber()
- {
- BtnFunctionNumber.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.FunctionNumber;
- numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
- numberKeyboard.MinValue = Presenter.MinFunctionNumber;
- numberKeyboard.MaxValue = Presenter.MaxFunctionNumber;
- numberKeyboard.OkClick += (sender, args) =>
- {
- this.Presenter.FunctionNumber = (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();
- };
- }
- private void InitRelation()
- {
- this.CbxRelation.DataSource = Enum.GetValues<ProtocolPCIe.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, ProtocolPCIe.DataRelation>(key, x);
- }).ToList();
- this.CbxRelation.DisplayMember = "Key";
- this.CbxRelation.ValueMember = "Value";
- this.CbxRelation.SelectedValueChanged += (sender, args) =>
- {
- if (ParentForm == null)
- {
- }
- else
- {
- Presenter.DataRelation = (ProtocolPCIe.DataRelation)this.CbxRelation.SelectedValue;
- }
- };
- this.CbxRelation.SelectedValue = Presenter.DataRelation;
- }
- 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(PCIeTrigSerialPrsnt.DataRelation))]
- private void UpdateRelation()
- {
- this.CbxRelation.SelectedValue = Presenter.DataRelation;
- }
- [UpdateProperty(nameof(PCIeTrigSerialPrsnt.TagData))]
- private void UpdateTag()
- {
- this.BtnTag.Text = $"0x{Convert.ToString(Presenter.TagData, 16).PadLeft(2, '0')}";
- }
- [UpdateProperty(nameof(PCIeTrigSerialPrsnt.BusNumber))]
- private void UpdateBusNumber()
- {
- this.BtnBusNumber.Text = $"0x{Convert.ToString(Presenter.BusNumber, 16).PadLeft(2, '0')}";
- }
- [UpdateProperty(nameof(PCIeTrigSerialPrsnt.DeviceNumber))]
- private void UpdateDeviceNumber()
- {
- this.BtnDeviceNumber.Text = $"0x{Convert.ToString(Presenter.DeviceNumber, 16).PadLeft(2, '0')}";
- }
- [UpdateProperty(nameof(PCIeTrigSerialPrsnt.FunctionNumber))]
- private void UpdateFunctionNumber()
- {
- this.BtnFunctionNumber.Text = $"0x{Convert.ToString(Presenter.FunctionNumber, 16).PadLeft(2, '0')}";
- }
- }
- }
|