DataPage.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.ComModel;
  12. using Uestc.Auto6.Dso.Core;
  13. using Uestc.Auto6.Dso.Core.Decode;
  14. using Uni_Trend.MSO7000X.Common.Helper;
  15. using Uni_Trend.MSO7000X.Language;
  16. using Uni_Trend.MSO7000X.UserControls;
  17. using Uni_Trend.MSO7000X.UserControls.Style;
  18. namespace Uestc.Auto6.Dso.Protocol.PCIe
  19. {
  20. public partial class DataPage : UserControl,ITriggerSerialView
  21. {
  22. #region 属性定义
  23. protected new Boolean DesignMode
  24. {
  25. get
  26. {
  27. Boolean rtnflag = false;
  28. #if DEBUG
  29. rtnflag = DesignTimeHelper.InDesignMode(this);
  30. #endif
  31. return rtnflag;
  32. }
  33. }
  34. public PCIeTrigSerialPrsnt Presenter { get; set; }
  35. ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
  36. {
  37. get => Presenter;
  38. set => Presenter = (PCIeTrigSerialPrsnt)value;
  39. }
  40. #endregion 属性定义
  41. public DataPage()
  42. {
  43. InitializeComponent();
  44. }
  45. protected override void OnLoad(EventArgs e)
  46. {
  47. base.OnLoad(e);
  48. InitView();
  49. }
  50. private void InitView()
  51. {
  52. Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(this, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize);
  53. if (!DesignMode)
  54. {
  55. InitRelation();
  56. InitData();
  57. InitDataCount();
  58. UpdateData();
  59. UpdateDateLenght();
  60. UpdateRelation();
  61. }
  62. }
  63. private void InitRelation()
  64. {
  65. this.CbxRelation.DataSource = Enum.GetValues<ProtocolPCIe.DataRelation>().Select(x =>
  66. {
  67. String key = String.Empty;
  68. key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
  69. if (String.IsNullOrEmpty(key))
  70. {
  71. key = x.ToString();
  72. }
  73. return new KeyValuePair<String, ProtocolPCIe.DataRelation>(key, x);
  74. }).ToList();
  75. this.CbxRelation.DisplayMember = "Key";
  76. this.CbxRelation.ValueMember = "Value";
  77. this.CbxRelation.SelectedValueChanged += (sender, args) =>
  78. {
  79. if (ParentForm == null)
  80. {
  81. }
  82. else
  83. {
  84. Presenter.DataRelation = (ProtocolPCIe.DataRelation)this.CbxRelation.SelectedValue;
  85. }
  86. };
  87. this.CbxRelation.SelectedValue = Presenter.DataRelation;
  88. }
  89. private void InitData()
  90. {
  91. BtnData.Click += (_, _) =>
  92. {
  93. Boolean lastflag = true;
  94. if (this.FindForm() is FloatForm form)
  95. {
  96. lastflag = form.CanClose;
  97. form.CanClose = false;
  98. }
  99. FloatForm floatForm = new FloatForm();
  100. floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
  101. floatForm.BackColor = BackColor;
  102. floatForm.ForeColor = ForeColor;
  103. floatForm.Width = 380;
  104. floatForm.Height = 460 + floatForm.HeadHeight;
  105. floatForm.Title = "设置AT";
  106. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  107. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
  108. numberKeyboard.Top = floatForm.HeadHeight;
  109. numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
  110. numberKeyboard.Width = floatForm.Width;
  111. numberKeyboard.ForeColor = ForeColor;
  112. numberKeyboard.BackColor = BackColor;
  113. numberKeyboard.Value = Presenter.Data;
  114. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  115. numberKeyboard.MinValue = Presenter.MinData;
  116. numberKeyboard.MaxValue = Presenter.MaxData;
  117. numberKeyboard.OkClick += (sender, args) =>
  118. {
  119. this.Presenter.Data = args.Data;
  120. floatForm?.Close();
  121. };
  122. numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
  123. floatForm.Controls.Add(numberKeyboard);
  124. DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
  125. floatForm.FormClosing += (_, _) =>
  126. {
  127. if (this.FindForm() is FloatForm form)
  128. form.CanClose = lastflag;
  129. };
  130. floatForm.ShowDialogByPosition();
  131. };
  132. }
  133. private void InitDataCount()
  134. {
  135. BtnDataCount.Click += (_, _) =>
  136. {
  137. Boolean lastflag = true;
  138. if (this.FindForm() is FloatForm form)
  139. {
  140. lastflag = form.CanClose;
  141. form.CanClose = false;
  142. }
  143. FloatForm floatForm = new FloatForm();
  144. floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
  145. floatForm.BackColor = BackColor;
  146. floatForm.ForeColor = ForeColor;
  147. floatForm.Width = 380;
  148. floatForm.Height = 460 + floatForm.HeadHeight;
  149. floatForm.Title = "设置AT";
  150. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  151. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.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.Value = Presenter.DataLenght;
  158. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  159. numberKeyboard.MinValue = Presenter.MinDataLenght;
  160. numberKeyboard.MaxValue = Presenter.MaxDataLenght;
  161. numberKeyboard.OkClick += (sender, args) =>
  162. {
  163. this.Presenter.DataLenght = (Byte)args.Data;
  164. floatForm?.Close();
  165. };
  166. numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
  167. floatForm.Controls.Add(numberKeyboard);
  168. DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
  169. floatForm.FormClosing += (_, _) =>
  170. {
  171. if (this.FindForm() is FloatForm form)
  172. form.CanClose = lastflag;
  173. };
  174. floatForm.ShowDialogByPosition();
  175. };
  176. }
  177. public void UpdateView(Object presenter, String propertyName)
  178. {
  179. if (String.IsNullOrEmpty(propertyName))
  180. {
  181. UpdateView();
  182. }
  183. else
  184. {
  185. this.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(x =>
  186. {
  187. UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
  188. return attribute != null && String.Equals(attribute.PropertyName, propertyName);
  189. }).ToList().ForEach(x => x.Invoke(this, null));
  190. }
  191. }
  192. private void UpdateView()
  193. {
  194. this.GetType().GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
  195. .Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x.Invoke(this, null));
  196. }
  197. [UpdateProperty(nameof(PCIeTrigSerialPrsnt.DataLenght))]
  198. private void UpdateDateLenght()
  199. {
  200. this.BtnDataCount.Text = Presenter.DataLenght.ToString();
  201. }
  202. [UpdateProperty(nameof(PCIeTrigSerialPrsnt.Data))]
  203. private void UpdateData()
  204. {
  205. this.BtnData.Text = $"0x{Convert.ToString(Presenter.Data, 16).PadLeft(Presenter.DataLenght * 2, '0')}";
  206. }
  207. [UpdateProperty(nameof(PCIeTrigSerialPrsnt.DataRelation))]
  208. private void UpdateRelation()
  209. {
  210. this.CbxRelation.SelectedValue = Presenter.DataRelation;
  211. }
  212. }
  213. }