CANDataPage.cs 10.0 KB

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