using System; using System.ComponentModel; using System.Data; using System.Linq; using System.Reflection; using System.Windows.Forms; 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 { [ToolboxItem(false)] public partial class CANDataPage : 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 CANDataPage() { InitializeComponent(); DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); InitView(); } private void InitView() { InitData(); InitByteIndex(); InitByteCount(); InitRelation(); UpdateView(); } public void UpdateView(Object presenter, String propertyName) { if (String.IsNullOrEmpty(propertyName)) { UpdateView(); return; } this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).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(); } #region 数据初始化 [UpdateProperty(nameof(CANTrigSerialPrsnt.ByteCount))] private void SetDataByteCount() { this.BtnByteCount.Text = Presenter.ByteCount.ToString(); } private void InitByteCount() { this.BtnByteCount.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 = "设置字节号"; _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.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 = (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(CANTrigSerialPrsnt.Data))] private void SetData() { this.BtnData.Text =Convert.ToString(Presenter.Data, 16).ToUpper().PadLeft(2, '0')+"h"; } private void InitData() { this.BtnData.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 = "设置数据"; _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.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; }; _FloatForm.ShowDialogByPosition(); }; } [UpdateProperty(nameof(CANTrigSerialPrsnt.ByteIndex))] private void SetDataByteIndex() { this.BtnByteIndex.Text = Presenter.ByteIndex.ToString(); } private void InitByteIndex() { this.BtnByteIndex.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 = "设置字节号"; _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.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 = (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(); }; } 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)this.CbxRelation.SelectedValue; }; } [UpdateProperty(nameof(CANTrigSerialPrsnt.DataRelation))] private void UpdateRelation() { this.CbxRelation.SelectedValue = Presenter.DataRelation; } #endregion 数据初始化 } }