SSMPage.cs 6.1 KB

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