using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; 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.CAN { [System.ComponentModel.ToolboxItem(false)] public partial class CANIDPage : UserControl, ITriggerSerialView { #region 属性 private FloatForm _FloatForm; public CANTrigSerialPrsnt Presenter { get; set; } ITriggerPrsnt IView.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 CANIDPage() { InitializeComponent(); DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); InitView(); } 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(); return attribute != null && attribute.PropertyName == propertyName; }).FirstOrDefault()?.Invoke(this, null); } private void UpdateView() { this.GetType().GetMethods( BindingFlags.Public| BindingFlags.Instance| BindingFlags.NonPublic).Where(x => x.GetCustomAttribute() != null).ToList().ForEach(x => x?.Invoke(this, null)); this.Refresh(); } private void InitView() { SetIDStandard(); SetStandardID(); SetFrameType(); SetExtendID(); UpdateView(); } #region 数据初始化 private void SetIDStandard() { this.CbxIDStandard.DataSource = Presenter.IDStandard.GetEnumList(); this.CbxIDStandard.ValueMember = "Value"; this.CbxIDStandard.DisplayMember = "Key"; this.CbxIDStandard.SelectedValueChanged += (sender, args) => { Presenter.IDStandard = (ProtocolCAN.IDStandard)this.CbxIDStandard.SelectedValue; }; } [UpdateProperty(nameof(Core.Decode.CANTrigSerialPrsnt.IDStandard))] private void UpdataIDStandard() { this.CbxIDStandard.SelectedValue = Presenter.IDStandard; BtnExtendID.Visible = (Presenter.IDStandard == ProtocolCAN.IDStandard.Extended); LblExtendID.Visible = BtnExtendID.Visible; BtnStandardID.Visible = !BtnExtendID.Visible; LblStandardID.Visible = !LblExtendID.Visible; LblExtendID.Left = LblStandardID.Left; BtnExtendID.Left = LblExtendID.Left; } private void SetStandardID() { this.BtnStandardID.Click += (_, _) => { Boolean 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().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 = (Int64)(Math.Pow(2,11)-1); numberKeyboard.MinValue = 0; numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex; numberKeyboard.Value = Presenter.StandardID; DefaultStyleManager.Instance.RegisterControlRecursion(_FloatForm, StyleFlag.FontSize); numberKeyboard.OkClick += (sender, args) => { Presenter.StandardID = (Int32)args.Data; _FloatForm.Close(); }; numberKeyboard.CancelClick += (_, _) => _FloatForm.Close(); _FloatForm.Controls.Add(numberKeyboard); _FloatForm.FormClosing += (_, _) => { if (this.FindForm() is FloatForm form) form.CanClose = lastflag; }; _FloatForm.ShowDialogByPosition(); }; } [UpdateProperty(nameof(Core.Decode.CANTrigSerialPrsnt.StandardID))] private void UpdateStandardID() { this.BtnStandardID.Text = Convert.ToString(Presenter.StandardID, 16).ToUpper().PadLeft(2, '0')+"h"; } private void SetExtendID() { this.BtnExtendID.Click += (_, _) => { Boolean 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().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 = (Int64)(Math.Pow(2,18)-1); numberKeyboard.MinValue = 0; numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex; DefaultStyleManager.Instance.RegisterControlRecursion(_FloatForm, StyleFlag.FontSize); numberKeyboard.Value = Presenter.ExtendedID; numberKeyboard.OkClick += (sender, args) => { Presenter.ExtendedID = (Int32)args.Data; _FloatForm.Close(); }; numberKeyboard.CancelClick += (_, _) => _FloatForm.Close(); _FloatForm.Controls.Add(numberKeyboard); _FloatForm.FormClosing += (_, _) => { if (this.FindForm() is FloatForm form) form.CanClose = lastflag; }; _FloatForm.ShowDialogByPosition(); }; } [UpdateProperty(nameof(Core.Decode.CANTrigSerialPrsnt.ExtendedID))] private void UpdateExtendID() { this.BtnExtendID.Text = Convert.ToString(Presenter.ExtendedID, 16).ToUpper().PadLeft(3, '0')+"h"; } private void SetFrameType() { CbxIDFrameDirection.DataSource = Enum.GetValues().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(key, x); }).ToList(); CbxIDFrameDirection.ValueMember = "Value"; CbxIDFrameDirection.DisplayMember = "Key"; CbxIDFrameDirection.SelectedValueChanged += (sender, args) => { Presenter.IDFrameDirection = (ProtocolCAN.IDFrameDirection)CbxIDFrameDirection.SelectedValue; }; } [UpdateProperty(nameof(Core.Decode.CANTrigSerialPrsnt.IDFrameDirection))] private void UpdateIDFrameDirection() { this.CbxIDFrameDirection.SelectedValue = Presenter.IDFrameDirection; } #endregion } }