CANDataPage.cs 11 KB

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