CANIDPage.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Windows.Forms;
  7. using Uestc.Auto6.Dso.ComModel;
  8. using Uestc.Auto6.Dso.Core;
  9. using Uestc.Auto6.Dso.Core.Decode;
  10. using Uni_Trend.MSO7000X.Common.Helper;
  11. using Uni_Trend.MSO7000X.Language;
  12. using Uni_Trend.MSO7000X.UserControls;
  13. using Uni_Trend.MSO7000X.UserControls.Style;
  14. namespace Uestc.Auto6.Dso.Protocol.CAN
  15. {
  16. [System.ComponentModel.ToolboxItem(false)]
  17. public partial class CANIDPage : UserControl, ITriggerSerialView
  18. {
  19. #region 属性
  20. private FloatForm _FloatForm;
  21. public CANTrigSerialPrsnt Presenter { get; set; }
  22. ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
  23. {
  24. get => Presenter;
  25. set => Presenter = (CANTrigSerialPrsnt)value;
  26. }
  27. protected new Boolean DesignMode
  28. {
  29. get
  30. {
  31. Boolean rtnflag = false;
  32. #if DEBUG
  33. rtnflag = DesignTimeHelper.InDesignMode(this);
  34. #endif
  35. return rtnflag;
  36. }
  37. }
  38. #endregion 属性
  39. public CANIDPage()
  40. {
  41. InitializeComponent();
  42. DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize);
  43. }
  44. protected override void OnLoad(EventArgs e)
  45. {
  46. base.OnLoad(e);
  47. InitView();
  48. }
  49. public void UpdateView(Object presenter, String propertyName)
  50. {
  51. if (String.IsNullOrEmpty(propertyName))
  52. {
  53. UpdateView();
  54. return;
  55. }
  56. this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(x =>
  57. {
  58. UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
  59. return attribute != null && attribute.PropertyName == propertyName;
  60. }).FirstOrDefault()?.Invoke(this, null);
  61. }
  62. private void UpdateView()
  63. {
  64. this.GetType().GetMethods( BindingFlags.Public| BindingFlags.Instance| BindingFlags.NonPublic).Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x?.Invoke(this, null));
  65. this.Refresh();
  66. }
  67. private void InitView()
  68. {
  69. SetIDStandard();
  70. SetStandardID();
  71. SetFrameType();
  72. SetExtendID();
  73. UpdateView();
  74. }
  75. #region 数据初始化
  76. private void SetIDStandard()
  77. {
  78. this.CbxIDStandard.DataSource = Presenter.IDStandard.GetEnumList();
  79. this.CbxIDStandard.ValueMember = "Value";
  80. this.CbxIDStandard.DisplayMember = "Key";
  81. this.CbxIDStandard.SelectedValueChanged += (sender, args) =>
  82. {
  83. Presenter.IDStandard = (ProtocolCAN.IDStandard)this.CbxIDStandard.SelectedValue;
  84. };
  85. }
  86. [UpdateProperty(nameof(Core.Decode.CANTrigSerialPrsnt.IDStandard))]
  87. private void UpdataIDStandard()
  88. {
  89. this.CbxIDStandard.SelectedValue = Presenter.IDStandard;
  90. BtnExtendID.Visible = (Presenter.IDStandard == ProtocolCAN.IDStandard.Extended);
  91. LblExtendID.Visible = BtnExtendID.Visible;
  92. BtnStandardID.Visible = !BtnExtendID.Visible;
  93. LblStandardID.Visible = !LblExtendID.Visible;
  94. LblExtendID.Left = LblStandardID.Left;
  95. BtnExtendID.Left = LblExtendID.Left;
  96. }
  97. private void SetStandardID()
  98. {
  99. this.BtnStandardID.Click += (_, _) =>
  100. {
  101. Boolean lastflag = true;
  102. if (this.FindForm() is FloatForm form)
  103. {
  104. lastflag = form.CanClose;
  105. form.CanClose = false;
  106. }
  107. if (_FloatForm != null && !_FloatForm.IsDisposed)
  108. _FloatForm?.Close();
  109. _FloatForm = new FloatForm();
  110. _FloatForm.BackColor = BackColor;
  111. _FloatForm.ForeColor = ForeColor;
  112. _FloatForm.Title = "设置标准ID";
  113. _FloatForm.Width = 380;
  114. _FloatForm.Height = 500 + _FloatForm.HeadHeight;
  115. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  116. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x,StyleFlag.FontSize));
  117. numberKeyboard.Top = _FloatForm.HeadHeight;
  118. numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
  119. numberKeyboard.Width = _FloatForm.Width;
  120. numberKeyboard.ForeColor = ForeColor;
  121. numberKeyboard.BackColor = BackColor;
  122. numberKeyboard.MaxValue = (Int64)(Math.Pow(2,11)-1);
  123. numberKeyboard.MinValue = 0;
  124. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  125. numberKeyboard.Value = Presenter.StandardID;
  126. DefaultStyleManager.Instance.RegisterControlRecursion(_FloatForm, StyleFlag.FontSize);
  127. numberKeyboard.OkClick += (sender, args) =>
  128. {
  129. Presenter.StandardID = (Int32)args.Data;
  130. _FloatForm.Close();
  131. };
  132. numberKeyboard.CancelClick += (_, _) => _FloatForm.Close();
  133. _FloatForm.Controls.Add(numberKeyboard);
  134. _FloatForm.FormClosing += (_, _) =>
  135. {
  136. if (this.FindForm() is FloatForm form)
  137. form.CanClose = lastflag;
  138. };
  139. _FloatForm.ShowDialogByPosition();
  140. };
  141. }
  142. [UpdateProperty(nameof(Core.Decode.CANTrigSerialPrsnt.StandardID))]
  143. private void UpdateStandardID()
  144. {
  145. this.BtnStandardID.Text = Convert.ToString(Presenter.StandardID, 16).ToUpper().PadLeft(2, '0')+"h";
  146. }
  147. private void SetExtendID()
  148. {
  149. this.BtnExtendID.Click += (_, _) =>
  150. {
  151. Boolean lastflag = true;
  152. if (this.FindForm() is FloatForm form)
  153. {
  154. lastflag = form.CanClose;
  155. form.CanClose = false;
  156. }
  157. if (_FloatForm != null && !_FloatForm.IsDisposed)
  158. _FloatForm?.Close();
  159. _FloatForm = new FloatForm();
  160. _FloatForm.BackColor = BackColor;
  161. _FloatForm.ForeColor = ForeColor;
  162. _FloatForm.Title = "设置扩展ID";
  163. _FloatForm.Width = 380;
  164. _FloatForm.Height = 500 + _FloatForm.HeadHeight;
  165. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  166. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x,StyleFlag.FontSize));
  167. numberKeyboard.Top = _FloatForm.HeadHeight;
  168. numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
  169. numberKeyboard.Width = _FloatForm.Width;
  170. numberKeyboard.ForeColor = ForeColor;
  171. numberKeyboard.BackColor = BackColor;
  172. numberKeyboard.MaxValue = (Int64)(Math.Pow(2,18)-1);
  173. numberKeyboard.MinValue = 0;
  174. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  175. DefaultStyleManager.Instance.RegisterControlRecursion(_FloatForm, StyleFlag.FontSize);
  176. numberKeyboard.Value = Presenter.ExtendedID;
  177. numberKeyboard.OkClick += (sender, args) =>
  178. {
  179. Presenter.ExtendedID = (Int32)args.Data;
  180. _FloatForm.Close();
  181. };
  182. numberKeyboard.CancelClick += (_, _) => _FloatForm.Close();
  183. _FloatForm.Controls.Add(numberKeyboard);
  184. _FloatForm.FormClosing += (_, _) =>
  185. {
  186. if (this.FindForm() is FloatForm form)
  187. form.CanClose = lastflag;
  188. };
  189. _FloatForm.ShowDialogByPosition();
  190. };
  191. }
  192. [UpdateProperty(nameof(Core.Decode.CANTrigSerialPrsnt.ExtendedID))]
  193. private void UpdateExtendID()
  194. {
  195. this.BtnExtendID.Text = Convert.ToString(Presenter.ExtendedID, 16).ToUpper().PadLeft(3, '0')+"h";
  196. }
  197. private void SetFrameType()
  198. {
  199. CbxIDFrameDirection.DataSource = Enum.GetValues<ProtocolCAN.IDFrameDirection>().Select(x =>
  200. {
  201. String key = String.Empty;
  202. key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
  203. if (String.IsNullOrEmpty(key))
  204. {
  205. key = x.ToString();
  206. }
  207. return new KeyValuePair<String, ProtocolCAN.IDFrameDirection>(key, x);
  208. }).ToList();
  209. CbxIDFrameDirection.ValueMember = "Value";
  210. CbxIDFrameDirection.DisplayMember = "Key";
  211. CbxIDFrameDirection.SelectedValueChanged += (sender, args) =>
  212. {
  213. Presenter.IDFrameDirection = (ProtocolCAN.IDFrameDirection)CbxIDFrameDirection.SelectedValue;
  214. };
  215. }
  216. [UpdateProperty(nameof(Core.Decode.CANTrigSerialPrsnt.IDFrameDirection))]
  217. private void UpdateIDFrameDirection()
  218. {
  219. this.CbxIDFrameDirection.SelectedValue = Presenter.IDFrameDirection;
  220. }
  221. #endregion
  222. }
  223. }