CANIDPage.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using Uestc.Auto6.Dso.Core;
  12. using Uestc.Auto6.Dso.Core.Decode;
  13. using Uestc.Auto6.Dso.ComModel;
  14. using Uni_Trend.MSO7000X.Common.Helper;
  15. using Uni_Trend.MSO7000X.UserControls;
  16. using Uni_Trend.MSO7000X.UserControls.Style;
  17. using Uni_Trend.MSO7000X.Language;
  18. namespace Uestc.Auto6.Dso.Protocol.CAN
  19. {
  20. public partial class CANIDPage : UserControl,ITriggerSerialView
  21. {
  22. public CANIDPage()
  23. {
  24. InitializeComponent();
  25. Controls.Cast<Control>().ToList().ForEach(x => StyleManager.Instance.RegisterControl(x));
  26. StyleManager.Instance.RegisterControl(this);
  27. }
  28. protected override void OnLoad(EventArgs e)
  29. {
  30. base.OnLoad(e);
  31. InitView();
  32. }
  33. private void CANDataPage_Load(object sender, EventArgs e)
  34. {
  35. }
  36. public void UpdateView(string propertyName)
  37. {
  38. }
  39. void InitView()
  40. {
  41. this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance).Where(x => x.GetCustomAttribute<RowColAttribute>() != null && x.GetValue(this) is Control).Select(x =>
  42. {
  43. RowColAttribute attribute = x.GetCustomAttribute<RowColAttribute>();
  44. Control control = x.GetValue(this) as Control;
  45. return (attribute, control);
  46. }).GroupBy(x => x.attribute, (x => x.control)).ToList().ForEach(x =>
  47. {
  48. Control lable = x.First(x => x is UestcLabel);
  49. Control control = x.First(x => !(x is UestcLabel));
  50. lable.Left = Width / _ColnumCount * x.Key.Colnum;
  51. lable.Width = control.Width;
  52. lable.Height = lable.Font.Height;
  53. lable.Top = 10 + _RowHeight * x.Key.Row;
  54. control.Left = lable.Left;
  55. control.Top = lable.Bottom + 2;
  56. lable.Width = 120;
  57. control.Width = 120;
  58. });
  59. InitFrameType();
  60. SetIDStandard();
  61. SetStandardID();
  62. }
  63. private void InitFrameType()
  64. {
  65. this.CbxFrameType.DataSource = Presenter.FrameType.GetEnumList();
  66. this.CbxFrameType.ValueMember = "Value";
  67. this.CbxFrameType.DisplayMember = "Key";
  68. this.CbxFrameType.SelectedValueChanged += (_, _) =>
  69. {
  70. Presenter.FrameType = (ComModel.ProtocolCAN.FrameType)(ComModel.PulseCondition)this.CbxFrameType.SelectedValue;
  71. };
  72. this.CbxFrameType.SelectedValue = Presenter.FrameType;
  73. }
  74. #region 属性
  75. private FloatForm _FloatForm;
  76. private Int32 _RowHeight = 66;
  77. private Int32 _ColnumCount = 2;
  78. public CANTrigSerialPrsnt Presenter { get; set; }
  79. ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
  80. {
  81. get => Presenter;
  82. set => Presenter = (CANTrigSerialPrsnt)value;
  83. }
  84. protected new Boolean DesignMode
  85. {
  86. get
  87. {
  88. Boolean rtnflag = false;
  89. #if DEBUG
  90. rtnflag = DesignTimeHelper.InDesignMode(this);
  91. #endif
  92. return rtnflag;
  93. }
  94. }
  95. private CANTrigSerialPrsnt CANTrigSerialPrsnt => Presenter as CANTrigSerialPrsnt;
  96. #endregion 属性
  97. private void SetIDStandard()
  98. {
  99. this.RbgIDStandard.ButtonItems = Enum.GetValues<ProtocolCAN.IDStandard>().Select(x => new RadioButtonItem()
  100. {
  101. Tag = x,
  102. Text = x.GetDescription(),
  103. }).ToArray();
  104. this.RbgIDStandard.IndexChanged += (sender, args) =>
  105. {
  106. CANTrigSerialPrsnt.IDStandard = (ProtocolCAN.IDStandard)RbgIDStandard.ButtonItems[RbgIDStandard.ChoosedButtonIndex].Tag;
  107. };
  108. this.RbgIDStandard.ChoosedButtonIndex = Enum.GetValues<ProtocolCAN.IDStandard>().ToList().FindIndex(x => x == CANTrigSerialPrsnt.IDStandard);
  109. }
  110. private void SetStandardID()
  111. {
  112. this.BtnStandardID.Text = "0x" + Convert.ToString(Presenter.Data, 16).ToUpper().PadLeft(2, '0');
  113. this.BtnStandardID.Click += (_, _) =>
  114. {
  115. bool lastflag = true;
  116. if (this.FindForm() is FloatForm form)
  117. {
  118. lastflag = form.CanClose;
  119. form.CanClose = false;
  120. }
  121. if (_FloatForm != null && !_FloatForm.IsDisposed)
  122. _FloatForm?.Close();
  123. _FloatForm = new FloatForm();
  124. _FloatForm.BackColor = BackColor;
  125. _FloatForm.ForeColor = ForeColor;
  126. _FloatForm.Title = "设置标准ID";
  127. _FloatForm.Width = 380;
  128. _FloatForm.Height = 500 + _FloatForm.HeadHeight;
  129. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  130. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.StyleManager.Instance.RegisterControl(x));
  131. numberKeyboard.Top = _FloatForm.HeadHeight;
  132. numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
  133. numberKeyboard.Width = _FloatForm.Width;
  134. numberKeyboard.ForeColor = ForeColor;
  135. numberKeyboard.BackColor = BackColor;
  136. numberKeyboard.MaxValue = byte.MaxValue;
  137. numberKeyboard.MinValue = 0;
  138. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  139. numberKeyboard.Value = Presenter.Data;
  140. numberKeyboard.OkClick += (sender, args) =>
  141. {
  142. Presenter.Data = (byte)args.Data;
  143. _FloatForm.Close();
  144. };
  145. numberKeyboard.CancelClick += (_, _) => _FloatForm.Close();
  146. _FloatForm.Controls.Add(numberKeyboard);
  147. _FloatForm.FormClosing += (_, _) =>
  148. {
  149. if (this.FindForm() is FloatForm form)
  150. form.CanClose = lastflag;
  151. };
  152. EventBus.EventBroker.Instance.GetEvent<Uni_Trend.MSO7000X.Common.Structs.FormEventArgs>().Publish(this, new Uni_Trend.MSO7000X.Common.Structs.FormEventArgs()
  153. {
  154. Current = _FloatForm,
  155. Type = Uni_Trend.MSO7000X.Common.Structs.FormType.InfoForm,
  156. });
  157. };
  158. }
  159. private void SetRelation()
  160. {
  161. this.CbxFrameType.SelectedValue = Presenter.DataRelation;
  162. }
  163. }
  164. }