123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- 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.FlexRay
- {
- public partial class FlexRayIDPage : UserControl, ITriggerSerialView
- {
- #region 属性
- private FloatForm _FloatForm;
- public FlexRayTrigSerialPrsnt Presenter { get; set; }
- ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
- {
- get => Presenter;
- set => Presenter = (FlexRayTrigSerialPrsnt)value;
- }
- protected new Boolean DesignMode
- {
- get
- {
- Boolean rtnflag = false;
- #if DEBUG
- rtnflag = DesignTimeHelper.InDesignMode(this);
- #endif
- return rtnflag;
- }
- }
- #endregion 属性
-
- public FlexRayIDPage()
- {
- InitializeComponent();
- DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize);
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- InitView();
- }
- private void InitView()
- {
- InitIDRelation();
- InitIDData();
- UpdateView();
- }
- 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<UpdatePropertyAttribute>();
- 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<UpdatePropertyAttribute>() != null).ToList().ForEach(x =>
- {
- x?.Invoke(this, null);
- });
- this.Refresh();
- }
- #region 数据初始化
- private void InitIDRelation()
- {
- this.CbxIDRelation.DataSource = Enum.GetValues<ProtocolFlexRay.Realtion>().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, ProtocolFlexRay.Realtion>(key, x);
- }).ToList();
- this.CbxIDRelation.ValueMember = "Value";
- this.CbxIDRelation.DisplayMember = "Key";
- this.CbxIDRelation.SelectedValueChanged += (_, _) =>
- {
- Presenter.Relation = (ProtocolFlexRay.Realtion)CbxIDRelation.SelectedValue;
- };
- UpdateIDRelation();
- }
- private void InitIDData()
- {
- BtnIDData.Click += (_, _) =>
- {
- SetIDData();
- };
- UpdateIDData();
- }
- private void SetIDData()
- {
- bool 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<Control>().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 = Presenter.MaxID;
- numberKeyboard.MinValue = Presenter.MinID;
- numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
- numberKeyboard.Value = Presenter.ID;
- numberKeyboard.OkClick += (sender, args) =>
- {
- Presenter.ID = (UInt16)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.ShowDialogByPosition();
- }
- #endregion
- #region 更新数据
- [UpdateProperty(nameof(FlexRayTrigSerialPrsnt.Relation))]
- private void UpdateIDRelation()
- {
- this.CbxIDRelation.SelectedValue = Presenter.Relation;
- }
- [UpdateProperty(nameof(FlexRayTrigSerialPrsnt.ID))]
- private void UpdateIDData()
- {
- this.BtnIDData.Text = Convert.ToString(Presenter.ID, 16).ToUpper().PadLeft(2, '0') + "h";
- }
- #endregion
- }
- }
|