FlexRayDataPage.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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.FlexRay
  19. {
  20. public partial class FlexRayDataPage : UserControl, ITriggerSerialView
  21. {
  22. #region 属性
  23. public FlexRayTrigSerialPrsnt Presenter { get; set; }
  24. ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
  25. {
  26. get => Presenter;
  27. set => Presenter = (FlexRayTrigSerialPrsnt)value;
  28. }
  29. protected new Boolean DesignMode
  30. {
  31. get
  32. {
  33. Boolean rtnflag = false;
  34. #if DEBUG
  35. rtnflag = DesignTimeHelper.InDesignMode(this);
  36. #endif
  37. return rtnflag;
  38. }
  39. }
  40. #endregion 属性
  41. public FlexRayDataPage()
  42. {
  43. InitializeComponent();
  44. DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize);
  45. }
  46. protected override void OnLoad(EventArgs e)
  47. {
  48. base.OnLoad(e);
  49. InitView();
  50. }
  51. private void InitView()
  52. {
  53. InitDataRelation();
  54. InitDataL();
  55. InitDataH();
  56. InitDataLen();
  57. UpdateView();
  58. }
  59. private void InitDataLen()
  60. {
  61. BtnTrigDataLen.Value = Presenter.ByteCount + 1;
  62. BtnTrigDataLen.Interval = 1;
  63. BtnTrigDataLen.StringFormatFunc=(args)=>((Byte)args).ToString();
  64. BtnTrigDataLen.MaxValue = Presenter.MaxByteCount + 1;
  65. BtnTrigDataLen.MinValue = Presenter.MinByteCount + 1;
  66. BtnTrigDataLen.ValueChanged += (_, args) => Presenter.ByteCount = (Byte)(args.newValue-1);
  67. BtnTrigDataLen.EditValueChicked += (_, _) => SetDataLen();
  68. }
  69. private void SetDataLen()
  70. {
  71. Boolean lastflag = true;
  72. if (this.FindForm() is FloatForm form)
  73. {
  74. lastflag = form.CanClose;
  75. form.CanClose = false;
  76. }
  77. FloatForm floatForm = new FloatForm();
  78. floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
  79. floatForm.BackColor = BackColor;
  80. floatForm.ForeColor = ForeColor;
  81. floatForm.Width = 380;
  82. floatForm.Height = 460 + floatForm.HeadHeight;
  83. floatForm.Title = "设置触发数据长度";
  84. Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard numberKeyboard = new Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard();
  85. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, StyleFlag.FontSize));
  86. numberKeyboard.Top = floatForm.HeadHeight;
  87. numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
  88. numberKeyboard.Width = floatForm.Width;
  89. numberKeyboard.ForeColor = ForeColor;
  90. numberKeyboard.BackColor = BackColor;
  91. numberKeyboard.Value = Presenter.ByteCount+1;
  92. numberKeyboard.MinValue = Presenter.MinByteCount+1;
  93. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Dec;
  94. numberKeyboard.MaxValue = Presenter.MaxByteCount+1;
  95. numberKeyboard.OkClick += (sender, args) =>
  96. {
  97. Presenter.ByteCount = (Byte)(args.Data-1);
  98. floatForm?.Close();
  99. };
  100. numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
  101. floatForm.Controls.Add(numberKeyboard);
  102. DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
  103. floatForm.FormClosing += (_, _) =>
  104. {
  105. if (this.FindForm() is FloatForm form)
  106. form.CanClose = lastflag;
  107. };
  108. floatForm.ShowDialogByPosition();
  109. }
  110. public void UpdateView(Object presenter, String propertyName)
  111. {
  112. if (string.IsNullOrEmpty(propertyName))
  113. {
  114. UpdateView();
  115. return;
  116. }
  117. this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(x =>
  118. {
  119. UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
  120. return attribute != null && attribute.PropertyName == propertyName;
  121. }).FirstOrDefault()?.Invoke(this, null);
  122. }
  123. private void UpdateView()
  124. {
  125. this.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x =>
  126. {
  127. x?.Invoke(this, null);
  128. });
  129. this.Refresh();
  130. }
  131. #region 数据初始化
  132. private void InitDataRelation()
  133. {
  134. this.CbxDataRelation.DataSource = Enum.GetValues<ProtocolFlexRay.Realtion>().Select(x =>
  135. {
  136. String key = String.Empty;
  137. key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
  138. if (String.IsNullOrEmpty(key))
  139. {
  140. key = x.ToString();
  141. }
  142. return new KeyValuePair<String, ProtocolFlexRay.Realtion>(key, x);
  143. }).ToList();
  144. this.CbxDataRelation.ValueMember = "Value";
  145. this.CbxDataRelation.DisplayMember = "Key";
  146. this.CbxDataRelation.SelectedValueChanged += (_, _) =>
  147. {
  148. Presenter.Relation = (ProtocolFlexRay.Realtion)CbxDataRelation.SelectedValue;
  149. };
  150. UpdateDataRelation();
  151. }
  152. private void InitDataL()
  153. {
  154. BtnDataL.Click += (_, _) =>
  155. {
  156. SetDataL();
  157. };
  158. UpdateDataL();
  159. }
  160. private void InitDataH()
  161. {
  162. BtnDataH.Click += (_, _) =>
  163. {
  164. SetDataH();
  165. };
  166. UpdateDataH();
  167. }
  168. private void SetDataL()
  169. {
  170. Boolean lastflag = true;
  171. if (this.FindForm() is FloatForm form)
  172. {
  173. lastflag = form.CanClose;
  174. form.CanClose = false;
  175. }
  176. FloatForm floatForm = new FloatForm();
  177. floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
  178. floatForm.BackColor = BackColor;
  179. floatForm.ForeColor = ForeColor;
  180. floatForm.Width = 380;
  181. floatForm.Height = 460 + floatForm.HeadHeight;
  182. floatForm.Title = "设置Data";
  183. Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard numberKeyboard = new Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard();
  184. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, StyleFlag.FontSize));
  185. numberKeyboard.Top = floatForm.HeadHeight;
  186. numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
  187. numberKeyboard.Width = floatForm.Width;
  188. numberKeyboard.ForeColor = ForeColor;
  189. numberKeyboard.BackColor = BackColor;
  190. numberKeyboard.Value = Presenter.DataL;
  191. numberKeyboard.MinValue = Presenter.MinDataL;
  192. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  193. numberKeyboard.MaxValue =Presenter.MaxDataL;
  194. numberKeyboard.OkClick += (sender, args) =>
  195. {
  196. Presenter.DataL = (Int64)args.Data;
  197. floatForm?.Close();
  198. };
  199. numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
  200. floatForm.Controls.Add(numberKeyboard);
  201. DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
  202. floatForm.FormClosing += (_, _) =>
  203. {
  204. if (this.FindForm() is FloatForm form)
  205. form.CanClose = lastflag;
  206. };
  207. floatForm.ShowDialogByPosition();
  208. }
  209. private void SetDataH()
  210. {
  211. Boolean lastflag = true;
  212. if (this.FindForm() is FloatForm form)
  213. {
  214. lastflag = form.CanClose;
  215. form.CanClose = false;
  216. }
  217. FloatForm floatForm = new FloatForm();
  218. floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
  219. floatForm.BackColor = BackColor;
  220. floatForm.ForeColor = ForeColor;
  221. floatForm.Width = 380;
  222. floatForm.Height = 460 + floatForm.HeadHeight;
  223. floatForm.Title = "设置Data";
  224. Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard numberKeyboard = new Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard();
  225. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, StyleFlag.FontSize));
  226. numberKeyboard.Top = floatForm.HeadHeight;
  227. numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
  228. numberKeyboard.Width = floatForm.Width;
  229. numberKeyboard.ForeColor = ForeColor;
  230. numberKeyboard.BackColor = BackColor;
  231. numberKeyboard.Value = Presenter.DataH;
  232. numberKeyboard.MinValue = Presenter.MinDataH;
  233. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  234. numberKeyboard.MaxValue = Presenter.MaxDataH;
  235. numberKeyboard.OkClick += (sender, args) =>
  236. {
  237. Presenter.DataH = (Int64)args.Data;
  238. floatForm?.Close();
  239. };
  240. numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
  241. floatForm.Controls.Add(numberKeyboard);
  242. DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
  243. floatForm.FormClosing += (_, _) =>
  244. {
  245. if (this.FindForm() is FloatForm form)
  246. form.CanClose = lastflag;
  247. };
  248. floatForm.ShowDialogByPosition();
  249. }
  250. #endregion
  251. #region 更新数据
  252. [UpdateProperty(nameof(FlexRayTrigSerialPrsnt.Relation))]
  253. private void UpdateDataRelation()
  254. {
  255. this.CbxDataRelation.SelectedValue = Presenter.Relation;
  256. }
  257. [UpdateProperty(nameof(FlexRayTrigSerialPrsnt.DataL))]
  258. private void UpdateDataL()
  259. {
  260. this.BtnDataL.Text = Convert.ToString(Presenter.DataL, 16).ToUpper().PadLeft(2*(Presenter.ByteCount>=7?8:(Presenter.ByteCount+1)), '0') + "h";
  261. }
  262. [UpdateProperty(nameof(FlexRayTrigSerialPrsnt.DataH))]
  263. private void UpdateDataH()
  264. {
  265. if (Presenter.ByteCount > 7)
  266. {
  267. this.BtnDataH.Text = Convert.ToString(Presenter.DataH, 16).ToUpper().PadLeft(2 * (Presenter.ByteCount - 7), '0') + "h";
  268. }
  269. else
  270. {
  271. this.BtnDataH.Text = "00h";
  272. }
  273. }
  274. [UpdateProperty(nameof(FlexRayTrigSerialPrsnt.ByteCount))]
  275. private void UpdateDataLen()
  276. {
  277. this.BtnTrigDataLen.Value = Presenter.ByteCount+1;
  278. LblDataH.Visible = Presenter.ByteCount > 7;
  279. BtnDataH.Visible = LblDataH.Visible;
  280. UpdateDataH();
  281. UpdateDataL();
  282. }
  283. #endregion
  284. }
  285. }