FlexRayIDPage.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 FlexRayIDPage : UserControl, ITriggerSerialView
  21. {
  22. #region 属性
  23. private FloatForm _FloatForm;
  24. public FlexRayTrigSerialPrsnt Presenter { get; set; }
  25. ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
  26. {
  27. get => Presenter;
  28. set => Presenter = (FlexRayTrigSerialPrsnt)value;
  29. }
  30. protected new Boolean DesignMode
  31. {
  32. get
  33. {
  34. Boolean rtnflag = false;
  35. #if DEBUG
  36. rtnflag = DesignTimeHelper.InDesignMode(this);
  37. #endif
  38. return rtnflag;
  39. }
  40. }
  41. #endregion 属性
  42. public FlexRayIDPage()
  43. {
  44. InitializeComponent();
  45. DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize);
  46. }
  47. protected override void OnLoad(EventArgs e)
  48. {
  49. base.OnLoad(e);
  50. InitView();
  51. }
  52. private void InitView()
  53. {
  54. InitIDRelation();
  55. InitIDData();
  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).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.NonPublic | BindingFlags.Instance).Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x =>
  74. {
  75. x?.Invoke(this, null);
  76. });
  77. this.Refresh();
  78. }
  79. #region 数据初始化
  80. private void InitIDRelation()
  81. {
  82. this.CbxIDRelation.DataSource = Enum.GetValues<ProtocolFlexRay.Realtion>().Select(x =>
  83. {
  84. String key = String.Empty;
  85. key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
  86. if (String.IsNullOrEmpty(key))
  87. {
  88. key = x.ToString();
  89. }
  90. return new KeyValuePair<String, ProtocolFlexRay.Realtion>(key, x);
  91. }).ToList();
  92. this.CbxIDRelation.ValueMember = "Value";
  93. this.CbxIDRelation.DisplayMember = "Key";
  94. this.CbxIDRelation.SelectedValueChanged += (_, _) =>
  95. {
  96. Presenter.Relation = (ProtocolFlexRay.Realtion)CbxIDRelation.SelectedValue;
  97. };
  98. UpdateIDRelation();
  99. }
  100. private void InitIDData()
  101. {
  102. BtnIDData.Click += (_, _) =>
  103. {
  104. SetIDData();
  105. };
  106. UpdateIDData();
  107. }
  108. private void SetIDData()
  109. {
  110. bool lastflag = true;
  111. if (this.FindForm() is FloatForm form)
  112. {
  113. lastflag = form.CanClose;
  114. form.CanClose = false;
  115. }
  116. if (_FloatForm != null && !_FloatForm.IsDisposed)
  117. _FloatForm?.Close();
  118. _FloatForm = new FloatForm();
  119. _FloatForm.BackColor = BackColor;
  120. _FloatForm.ForeColor = ForeColor;
  121. _FloatForm.Title = "设置数据";
  122. _FloatForm.Width = 380;
  123. _FloatForm.Height = 500 + _FloatForm.HeadHeight;
  124. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  125. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, StyleFlag.FontSize));
  126. numberKeyboard.Top = _FloatForm.HeadHeight;
  127. numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
  128. numberKeyboard.Width = _FloatForm.Width;
  129. numberKeyboard.ForeColor = ForeColor;
  130. numberKeyboard.BackColor = BackColor;
  131. numberKeyboard.MaxValue = Presenter.MaxID;
  132. numberKeyboard.MinValue = Presenter.MinID;
  133. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  134. numberKeyboard.Value = Presenter.ID;
  135. numberKeyboard.OkClick += (sender, args) =>
  136. {
  137. Presenter.ID = (UInt16)args.Data;
  138. _FloatForm.Close();
  139. };
  140. numberKeyboard.CancelClick += (_, _) => _FloatForm.Close();
  141. _FloatForm.Controls.Add(numberKeyboard);
  142. DefaultStyleManager.Instance.RegisterControlRecursion(_FloatForm, StyleFlag.FontSize);
  143. _FloatForm.FormClosing += (_, _) =>
  144. {
  145. if (this.FindForm() is FloatForm form)
  146. form.CanClose = lastflag;
  147. };
  148. _FloatForm.ShowDialogByPosition();
  149. }
  150. #endregion
  151. #region 更新数据
  152. [UpdateProperty(nameof(FlexRayTrigSerialPrsnt.Relation))]
  153. private void UpdateIDRelation()
  154. {
  155. this.CbxIDRelation.SelectedValue = Presenter.Relation;
  156. }
  157. [UpdateProperty(nameof(FlexRayTrigSerialPrsnt.ID))]
  158. private void UpdateIDData()
  159. {
  160. this.BtnIDData.Text = Convert.ToString(Presenter.ID, 16).ToUpper().PadLeft(2, '0') + "h";
  161. }
  162. #endregion
  163. }
  164. }