123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- 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 CANIDPage : UserControl,ITriggerSerialView
- {
- public CANIDPage()
- {
- 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)
- {
- }
- public void UpdateView(string propertyName)
- {
- }
- 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;
- });
- InitFrameType();
- SetIDStandard();
- SetStandardID();
- }
- private void InitFrameType()
- {
- this.CbxFrameType.DataSource = Presenter.FrameType.GetEnumList();
- this.CbxFrameType.ValueMember = "Value";
- this.CbxFrameType.DisplayMember = "Key";
- this.CbxFrameType.SelectedValueChanged += (_, _) =>
- {
- Presenter.FrameType = (ComModel.ProtocolCAN.FrameType)(ComModel.PulseCondition)this.CbxFrameType.SelectedValue;
- };
- this.CbxFrameType.SelectedValue = Presenter.FrameType;
- }
- #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;
- }
- }
- private CANTrigSerialPrsnt CANTrigSerialPrsnt => Presenter as CANTrigSerialPrsnt;
- #endregion 属性
- private void SetIDStandard()
- {
- this.RbgIDStandard.ButtonItems = Enum.GetValues<ProtocolCAN.IDStandard>().Select(x => new RadioButtonItem()
- {
- Tag = x,
- Text = x.GetDescription(),
- }).ToArray();
- this.RbgIDStandard.IndexChanged += (sender, args) =>
- {
- CANTrigSerialPrsnt.IDStandard = (ProtocolCAN.IDStandard)RbgIDStandard.ButtonItems[RbgIDStandard.ChoosedButtonIndex].Tag;
- };
- this.RbgIDStandard.ChoosedButtonIndex = Enum.GetValues<ProtocolCAN.IDStandard>().ToList().FindIndex(x => x == CANTrigSerialPrsnt.IDStandard);
- }
- private void SetStandardID()
- {
- this.BtnStandardID.Text = "0x" + Convert.ToString(Presenter.Data, 16).ToUpper().PadLeft(2, '0');
- this.BtnStandardID.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 = "设置标准ID";
- _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,
- });
- };
- }
- private void SetRelation()
- {
- this.CbxFrameType.SelectedValue = Presenter.DataRelation;
- }
- }
- }
|