123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- 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.CAN
- {
- public partial class CANDataPage : UserControl,ITriggerSerialView
- {
- public CANDataPage()
- {
- InitializeComponent();
- Controls.Cast<Control>().ToList().ForEach(x => StyleManager.Instance.RegisterControl(x));
- StyleManager.Instance.RegisterControl(this);
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- InitView();
- }
- private void CANDataPage_Load(object sender, EventArgs e)
- {
-
- }
- private void InitView()
- {
- this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance).Where(x => x.GetCustomAttribute<RowColAttribute>() != null && x.GetValue(this) is Control).Select(x =>
- {
- RowColAttribute attribute = x.GetCustomAttribute<RowColAttribute>();
- Control control = x.GetValue(this) as Control;
- return (attribute, control);
- }).GroupBy(x => x.attribute, (x => x.control)).ToList().ForEach(x =>
- {
- Control lable = x.First(x => x is UestcLabel);
- Control control = x.First(x => !(x is UestcLabel));
- lable.Left = Width / _ColnumCount * x.Key.Colnum;
- lable.Width = control.Width;
- lable.Height = lable.Font.Height;
- lable.Top = 10 + _RowHeight * x.Key.Row;
- control.Left = lable.Left;
- control.Top = lable.Bottom + 2;
- lable.Width = 120;
- control.Width = 120;
- });
- SetDataByteCount();
- SetData();
- SetDataByteIndex();
- InitRelation();
- }
- private void InitRelation()
- {
- this.CbxRelation.DataSource = Presenter.DataRelation.GetEnumList();
- this.CbxRelation.ValueMember = "Value";
- this.CbxRelation.DisplayMember = "Key";
- this.CbxRelation.SelectedValueChanged += (_, _) =>
- {
- Presenter.DataRelation = (ComModel.ProtocolCAN.DataRelation)(ComModel.PulseCondition)this.CbxRelation.SelectedValue;
- };
- this.CbxRelation.SelectedValue = Presenter.DataRelation;
- }
- #region 属性
- private FloatForm _FloatForm;
- private Int32 _RowHeight = 66;
- private Int32 _ColnumCount = 2;
- public CANTrigSerialPrsnt Presenter { get; set; }
- ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
- {
- get => Presenter;
- set => Presenter = (CANTrigSerialPrsnt)value;
- }
- protected new Boolean DesignMode
- {
- get
- {
- Boolean rtnflag = false;
- #if DEBUG
- rtnflag = DesignTimeHelper.InDesignMode(this);
- #endif
- return rtnflag;
- }
- }
- #endregion 属性
- public void UpdateView(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().Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x?.Invoke(this, null));
- this.Refresh();
- }
- #region UpdateFunction
- [UpdateProperty(nameof(CANTrigSerialPrsnt.ByteCount))]
- private void SetDataByteCount()
- {
- this.BtnByteCount.Text = Presenter.ByteCount.ToString();
- this.BtnByteCount.Click += (_, _) =>
- {
- 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.StyleManager.Instance.RegisterControl(x));
- numberKeyboard.Top = _FloatForm.HeadHeight;
- numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
- numberKeyboard.Width = _FloatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.MaxValue = Presenter.ByteCount - 1;
- numberKeyboard.MinValue = 0;
- numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Dec;
- numberKeyboard.Value = Presenter.ByteCount;
- numberKeyboard.OkClick += (sender, args) =>
- {
- Presenter.ByteCount = (int)args.Data;
- _FloatForm.Close();
- };
- numberKeyboard.CancelClick += (_, _) => _FloatForm.Close();
- _FloatForm.Controls.Add(numberKeyboard);
- _FloatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- EventBus.EventBroker.Instance.GetEvent<Uni_Trend.MSO7000X.Common.Structs.FormEventArgs>().Publish(this, new Uni_Trend.MSO7000X.Common.Structs.FormEventArgs()
- {
- Current = _FloatForm,
- Type = Uni_Trend.MSO7000X.Common.Structs.FormType.InfoForm,
- });
- };
- }
- [UpdateProperty(nameof(CANTrigSerialPrsnt.Data))]
- private void SetData()
- {
- this.BtnData.Text = "0x" + Convert.ToString(Presenter.Data, 16).ToUpper().PadLeft(2, '0');
- this.BtnData.Click += (_, _) =>
- {
- 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.StyleManager.Instance.RegisterControl(x));
- 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);
- _FloatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- EventBus.EventBroker.Instance.GetEvent<Uni_Trend.MSO7000X.Common.Structs.FormEventArgs>().Publish(this, new Uni_Trend.MSO7000X.Common.Structs.FormEventArgs()
- {
- Current = _FloatForm,
- Type = Uni_Trend.MSO7000X.Common.Structs.FormType.InfoForm,
- });
- };
- }
- [UpdateProperty(nameof(CANTrigSerialPrsnt.ByteIndex))]
- private void SetDataByteIndex()
- {
- this.BtnByteIndex.Text = Presenter.ByteIndex.ToString();
- this.BtnByteIndex.Click += (_, _) =>
- {
- 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.StyleManager.Instance.RegisterControl(x));
- numberKeyboard.Top = _FloatForm.HeadHeight;
- numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
- numberKeyboard.Width = _FloatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.MaxValue = Presenter.ByteCount - 1;
- numberKeyboard.MinValue = 0;
- numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Dec;
- numberKeyboard.Value = Presenter.ByteIndex;
- numberKeyboard.OkClick += (sender, args) =>
- {
- Presenter.ByteIndex = (int)args.Data;
- _FloatForm.Close();
- };
- numberKeyboard.CancelClick += (_, _) => _FloatForm.Close();
- _FloatForm.Controls.Add(numberKeyboard);
- _FloatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- EventBus.EventBroker.Instance.GetEvent<Uni_Trend.MSO7000X.Common.Structs.FormEventArgs>().Publish(this, new Uni_Trend.MSO7000X.Common.Structs.FormEventArgs()
- {
- Current = _FloatForm,
- Type = Uni_Trend.MSO7000X.Common.Structs.FormType.InfoForm,
- });
- };
- }
- [UpdateProperty(nameof(CANTrigSerialPrsnt.DataRelation))]
- private void SetRelation()
- {
- this.CbxRelation.SelectedValue = Presenter.DataRelation;
- }
- #endregion UpdateFunction
- }
- }
|