TCPage.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 TCPage : 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 TCPage()
  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. InitTC();
  57. UpdateRelation();
  58. UpdateTC();
  59. }
  60. }
  61. private void InitRelation()
  62. {
  63. this.CbxRelation.DataSource = Enum.GetValues<ProtocolPCIe.DataRelation>().Select(x =>
  64. {
  65. String key = String.Empty;
  66. key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
  67. if (String.IsNullOrEmpty(key))
  68. {
  69. key = x.ToString();
  70. }
  71. return new KeyValuePair<String, ProtocolPCIe.DataRelation>(key, x);
  72. }).ToList();
  73. this.CbxRelation.DisplayMember = "Key";
  74. this.CbxRelation.ValueMember = "Value";
  75. this.CbxRelation.SelectedValueChanged += (sender, args) =>
  76. {
  77. if (ParentForm == null)
  78. {
  79. }
  80. else
  81. {
  82. Presenter.DataRelation = (ProtocolPCIe.DataRelation)this.CbxRelation.SelectedValue;
  83. }
  84. };
  85. this.CbxRelation.SelectedValue = Presenter.DataRelation;
  86. }
  87. private void InitTC()
  88. {
  89. BtnTC.Click += (_, _) =>
  90. {
  91. Boolean lastflag = true;
  92. if (this.FindForm() is FloatForm form)
  93. {
  94. lastflag = form.CanClose;
  95. form.CanClose = false;
  96. }
  97. FloatForm floatForm = new FloatForm();
  98. floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
  99. floatForm.BackColor = BackColor;
  100. floatForm.ForeColor = ForeColor;
  101. floatForm.Width = 380;
  102. floatForm.Height = 460 + floatForm.HeadHeight;
  103. floatForm.Title = "设置TC数据";
  104. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  105. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
  106. numberKeyboard.Top = floatForm.HeadHeight;
  107. numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
  108. numberKeyboard.Width = floatForm.Width;
  109. numberKeyboard.ForeColor = ForeColor;
  110. numberKeyboard.BackColor = BackColor;
  111. numberKeyboard.Value = Presenter.TCData;
  112. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  113. numberKeyboard.MinValue = Presenter.MinTCData;
  114. numberKeyboard.MaxValue = Presenter.MaxTCData;
  115. numberKeyboard.OkClick += (sender, args) =>
  116. {
  117. this.Presenter.TCData = (Byte)args.Data;
  118. floatForm?.Close();
  119. };
  120. numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
  121. floatForm.Controls.Add(numberKeyboard);
  122. DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
  123. floatForm.FormClosing += (_, _) =>
  124. {
  125. if (this.FindForm() is FloatForm form)
  126. form.CanClose = lastflag;
  127. };
  128. floatForm.ShowDialogByPosition();
  129. };
  130. }
  131. public void UpdateView(Object presenter, String propertyName)
  132. {
  133. if (String.IsNullOrEmpty(propertyName))
  134. {
  135. UpdateView();
  136. }
  137. else
  138. {
  139. this.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(x =>
  140. {
  141. UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
  142. return attribute != null && String.Equals(attribute.PropertyName, propertyName);
  143. }).ToList().ForEach(x => x.Invoke(this, null));
  144. }
  145. }
  146. private void UpdateView()
  147. {
  148. this.GetType().GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
  149. .Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x.Invoke(this, null));
  150. }
  151. [UpdateProperty(nameof(PCIeTrigSerialPrsnt.TCData))]
  152. private void UpdateTC()
  153. {
  154. this.BtnTC.Text = "0x" + Convert.ToString(Presenter.TCData, 16).PadLeft(2, '0');
  155. }
  156. [UpdateProperty(nameof(PCIeTrigSerialPrsnt.DataRelation))]
  157. private void UpdateRelation()
  158. {
  159. this.CbxRelation.SelectedValue = Presenter.DataRelation;
  160. }
  161. }
  162. }