NRZDataPage.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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.NRZ
  19. {
  20. [System.ComponentModel.ToolboxItem(false)]
  21. public partial class NRZDataPage : UserControl, ITriggerSerialView
  22. {
  23. #region 属性定义
  24. protected new Boolean DesignMode
  25. {
  26. get
  27. {
  28. Boolean rtnflag = false;
  29. #if DEBUG
  30. rtnflag = DesignTimeHelper.InDesignMode(this);
  31. #endif
  32. return rtnflag;
  33. }
  34. }
  35. public NRZTrigSerialPrsnt Presenter { get; set; }
  36. ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
  37. {
  38. get => Presenter;
  39. set => Presenter = (NRZTrigSerialPrsnt)value;
  40. }
  41. #endregion 属性定义
  42. public NRZDataPage()
  43. {
  44. InitializeComponent();
  45. }
  46. private void InitView()
  47. {
  48. Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(this, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize);
  49. }
  50. protected override void OnLoad(EventArgs e)
  51. {
  52. base.OnLoad(e);
  53. InitView();
  54. Init();
  55. }
  56. private void Init()
  57. {
  58. InitData();
  59. InitRelation();
  60. UpdateView();
  61. }
  62. private void InitRelation()
  63. {
  64. this.CbxRelation.DataSource = Presenter.Relation.GetEnumList();
  65. this.CbxRelation.DisplayMember = "Key";
  66. this.CbxRelation.ValueMember = "Value";
  67. this.CbxRelation.SelectedValueChanged += (sender, args) =>
  68. {
  69. if (ParentForm == null)
  70. {
  71. }
  72. else
  73. {
  74. Presenter.Relation = (ProtocolNRZ.DataRelation)this.CbxRelation.SelectedValue;
  75. }
  76. };
  77. this.CbxRelation.SelectedValue = Presenter.Relation;
  78. }
  79. private void InitData()
  80. {
  81. BtnData.Click += (_, _) =>
  82. {
  83. Boolean lastflag = true;
  84. if (this.FindForm() is FloatForm form)
  85. {
  86. lastflag = form.CanClose;
  87. form.CanClose = false;
  88. }
  89. FloatForm floatForm = new FloatForm();
  90. floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
  91. floatForm.BackColor = BackColor;
  92. floatForm.ForeColor = ForeColor;
  93. floatForm.Width = 380;
  94. floatForm.Height = 460 + floatForm.HeadHeight;
  95. floatForm.Title = "设置Data";
  96. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  97. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
  98. numberKeyboard.Top = floatForm.HeadHeight;
  99. numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
  100. numberKeyboard.Width = floatForm.Width;
  101. numberKeyboard.ForeColor = ForeColor;
  102. numberKeyboard.BackColor = BackColor;
  103. numberKeyboard.Value = Presenter.Data;
  104. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  105. numberKeyboard.MinValue = Presenter.MinData;
  106. numberKeyboard.MaxValue = Presenter.MaxData;
  107. numberKeyboard.OkClick += (sender, args) =>
  108. {
  109. this.Presenter.Data = (Byte)args.Data;
  110. floatForm?.Close();
  111. };
  112. numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
  113. floatForm.Controls.Add(numberKeyboard);
  114. DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
  115. floatForm.FormClosing += (_, _) =>
  116. {
  117. if (this.FindForm() is FloatForm form)
  118. form.CanClose = lastflag;
  119. };
  120. floatForm.ShowDialogByPosition();
  121. };
  122. }
  123. public void UpdateView(Object presenter, String propertyName)
  124. {
  125. if (String.IsNullOrEmpty(propertyName))
  126. {
  127. UpdateView();
  128. }
  129. else
  130. {
  131. this.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(x =>
  132. {
  133. UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
  134. return attribute != null && String.Equals(attribute.PropertyName, propertyName);
  135. }).ToList().ForEach(x => x.Invoke(this, null));
  136. }
  137. }
  138. private void UpdateView()
  139. {
  140. this.GetType().GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
  141. .Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x.Invoke(this, null));
  142. }
  143. [UpdateProperty(nameof(NRZTrigSerialPrsnt.Data))]
  144. private void UpdateData()
  145. {
  146. this.BtnData.Text = $"{Presenter.Data:X2}";
  147. }
  148. [UpdateProperty(nameof(NRZTrigSerialPrsnt.Relation))]
  149. private void UpdateRelation()
  150. {
  151. this.CbxRelation.SelectedValue = Presenter.Relation;
  152. }
  153. }
  154. }