TrigDataPage.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Windows.Forms;
  7. using Uestc.Auto6.Dso.ComModel;
  8. using Uestc.Auto6.Dso.Core;
  9. using Uestc.Auto6.Dso.Core.Decode;
  10. using Uni_Trend.MSO7000X.Common.Helper;
  11. using Uni_Trend.MSO7000X.Language;
  12. using Uni_Trend.MSO7000X.UserControls;
  13. using Uni_Trend.MSO7000X.UserControls.Style;
  14. namespace Uestc.Auto6.Dso.Protocol.Ethernet
  15. {
  16. public partial class TrigDataPage : UserControl, ITriggerSerialView
  17. {
  18. #region 属性
  19. private FloatForm _FloatForm;
  20. private Int32 _RowHeight = 56;
  21. private Int32 _ColnumCount = 2;
  22. public EthernetTrigSerialPrsnt Presenter { get; set; }
  23. ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
  24. {
  25. get => Presenter;
  26. set => Presenter = (EthernetTrigSerialPrsnt)value;
  27. }
  28. protected new Boolean DesignMode
  29. {
  30. get
  31. {
  32. Boolean rtnflag = false;
  33. #if DEBUG
  34. rtnflag = DesignTimeHelper.InDesignMode(this);
  35. #endif
  36. return rtnflag;
  37. }
  38. }
  39. #endregion 属性
  40. public TrigDataPage()
  41. {
  42. InitializeComponent();
  43. }
  44. protected override void OnLoad(EventArgs e)
  45. {
  46. base.OnLoad(e);
  47. InitView();
  48. UpdateView();
  49. DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize);
  50. }
  51. private void InitView()
  52. {
  53. InitData();
  54. InitRelation();
  55. }
  56. private void InitRelation()
  57. {
  58. this.CbxRelation.DataSource = Enum.GetValues<ProtocolEthernet.DataRelation>().Select(x =>
  59. {
  60. String key = String.Empty;
  61. key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
  62. if (String.IsNullOrEmpty(key))
  63. {
  64. key = x.ToString();
  65. }
  66. return new KeyValuePair<String, ProtocolEthernet.DataRelation>(key, x);
  67. }).ToList();
  68. this.CbxRelation.ValueMember = "Value";
  69. this.CbxRelation.DisplayMember = "Key";
  70. this.CbxRelation.SelectedValueChanged += (_, _) =>
  71. {
  72. Presenter.Relation = (ComModel.ProtocolEthernet.DataRelation)this.CbxRelation.SelectedValue;
  73. };
  74. this.CbxRelation.SelectedValue = Presenter.Relation;
  75. }
  76. public void UpdateView(Object presenter, String propertyName)
  77. {
  78. if (String.IsNullOrEmpty(propertyName))
  79. {
  80. UpdateView();
  81. return;
  82. }
  83. this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(x =>
  84. {
  85. UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
  86. return attribute != null && attribute.PropertyName == propertyName;
  87. }).FirstOrDefault()?.Invoke(this, null);
  88. }
  89. private void UpdateView()
  90. {
  91. this.GetType().GetMethods(BindingFlags.Public| BindingFlags.Instance| BindingFlags.NonPublic).Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x?.Invoke(this, null));
  92. this.Refresh();
  93. }
  94. private void InitData()
  95. {
  96. this.BtnData.Click += (_, _) =>
  97. {
  98. Boolean lastflag = true;
  99. if (this.FindForm() is FloatForm form)
  100. {
  101. lastflag = form.CanClose;
  102. form.CanClose = false;
  103. }
  104. if (_FloatForm != null && !_FloatForm.IsDisposed)
  105. _FloatForm?.Close();
  106. _FloatForm = new FloatForm();
  107. _FloatForm.BackColor = BackColor;
  108. _FloatForm.ForeColor = ForeColor;
  109. _FloatForm.Title = "设置数据";
  110. _FloatForm.Width = 380;
  111. _FloatForm.Height = 500 + _FloatForm.HeadHeight;
  112. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  113. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, StyleFlag.FontSize));
  114. numberKeyboard.Top = _FloatForm.HeadHeight;
  115. numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
  116. numberKeyboard.Width = _FloatForm.Width;
  117. numberKeyboard.ForeColor = ForeColor;
  118. numberKeyboard.BackColor = BackColor;
  119. numberKeyboard.MaxValue = Byte.MaxValue;
  120. numberKeyboard.MinValue = 0;
  121. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  122. numberKeyboard.Value = Presenter.Data;
  123. numberKeyboard.OkClick += (sender, args) =>
  124. {
  125. Presenter.Data = (Byte)args.Data;
  126. _FloatForm.Close();
  127. };
  128. numberKeyboard.CancelClick += (_, _) => _FloatForm.Close();
  129. _FloatForm.Controls.Add(numberKeyboard);
  130. DefaultStyleManager.Instance.RegisterControlRecursion(_FloatForm, StyleFlag.FontSize);
  131. _FloatForm.FormClosing += (_, _) =>
  132. {
  133. if (this.FindForm() is FloatForm form)
  134. form.CanClose = lastflag;
  135. };
  136. _FloatForm.ShowByPosition();
  137. };
  138. UpdateData();
  139. }
  140. [UpdateProperty(nameof(EthernetTrigSerialPrsnt.Data))]
  141. private void UpdateData()
  142. {
  143. this.BtnData.Text = $"{Presenter.Data:X2}";
  144. }
  145. [UpdateProperty(nameof(EthernetTrigSerialPrsnt.Relation))]
  146. private void UpdateRelation()
  147. {
  148. this.CbxRelation.SelectedValue = Presenter.Relation;
  149. }
  150. }
  151. }