SDIPage.cs 6.0 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 SDIPage : 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 SDIPage()
  40. {
  41. InitializeComponent();
  42. }
  43. protected override void OnLoad(EventArgs e)
  44. {
  45. base.OnLoad(e);
  46. InitView();
  47. }
  48. private void InitView()
  49. {
  50. DefaultStyleManager.Instance.RegisterControlRecursion(this, StyleFlag.FontSize);
  51. InitSDI();
  52. InitDataRelation();
  53. // UpdateView();
  54. }
  55. public void UpdateView(Object presenter, String propertyName)
  56. {
  57. if (String.IsNullOrEmpty(propertyName))
  58. {
  59. UpdateView();
  60. return;
  61. }
  62. this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).Where(x =>
  63. {
  64. UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
  65. return attribute != null && attribute.PropertyName == propertyName;
  66. }).FirstOrDefault()?.Invoke(this, null);
  67. }
  68. private void UpdateView()
  69. {
  70. this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x?.Invoke(this, null));
  71. this.Refresh();
  72. }
  73. #region 数据初始化
  74. private void InitSDI()
  75. {
  76. BtnSDI.Click += (_, _) =>
  77. {
  78. SetSDI();
  79. };
  80. UpdateSDI();
  81. }
  82. private void InitDataRelation()
  83. {
  84. this.CbxDataRelation.DataSource = Enum.GetValues<ProtocolARINC429.DataRelation>().Select(x =>
  85. {
  86. String key = String.Empty;
  87. key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
  88. if (String.IsNullOrEmpty(key))
  89. {
  90. key = x.ToString();
  91. }
  92. return new KeyValuePair<String, ProtocolARINC429.DataRelation>(key, x);
  93. }).ToList();
  94. this.CbxDataRelation.ValueMember = "Value";
  95. this.CbxDataRelation.DisplayMember = "Key";
  96. this.CbxDataRelation.SelectedValueChanged += (_, _) =>
  97. {
  98. Presenter.DataRelation = (ProtocolARINC429.DataRelation)CbxDataRelation.SelectedValue;
  99. };
  100. UpdateDataRelation();
  101. }
  102. private void SetSDI()
  103. {
  104. Boolean lastflag = true;
  105. if (this.FindForm() is FloatForm form)
  106. {
  107. lastflag = form.CanClose;
  108. form.CanClose = false;
  109. }
  110. if (_FloatForm != null && !_FloatForm.IsDisposed)
  111. _FloatForm?.Close();
  112. _FloatForm = new FloatForm();
  113. _FloatForm.BackColor = BackColor;
  114. _FloatForm.ForeColor = ForeColor;
  115. _FloatForm.Title = "设置数据";
  116. _FloatForm.Width = 380;
  117. _FloatForm.Height = 500 + _FloatForm.HeadHeight;
  118. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  119. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, StyleFlag.FontSize));
  120. numberKeyboard.Top = _FloatForm.HeadHeight;
  121. numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
  122. numberKeyboard.Width = _FloatForm.Width;
  123. numberKeyboard.ForeColor = ForeColor;
  124. numberKeyboard.BackColor = BackColor;
  125. numberKeyboard.MaxValue = Byte.MaxValue;
  126. numberKeyboard.MinValue = 0;
  127. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  128. DefaultStyleManager.Instance.RegisterControlRecursion(_FloatForm, StyleFlag.FontSize);
  129. numberKeyboard.Value = Presenter.SDI;
  130. numberKeyboard.OkClick += (sender, args) =>
  131. {
  132. Presenter.SDI = (Byte)args.Data;
  133. _FloatForm.Close();
  134. };
  135. numberKeyboard.CancelClick += (_, _) => _FloatForm.Close();
  136. _FloatForm.Controls.Add(numberKeyboard);
  137. _FloatForm.FormClosing += (_, _) =>
  138. {
  139. if (this.FindForm() is FloatForm form)
  140. form.CanClose = lastflag;
  141. };
  142. _FloatForm.ShowDialogByPosition();
  143. }
  144. #endregion 数据初始化
  145. [UpdateProperty(nameof(ARINC429TrigSerialPrsnt.SDI))]
  146. private void UpdateSDI()
  147. {
  148. this.BtnSDI.Text = $"0x{Presenter.SDI:X2}";
  149. }
  150. [UpdateProperty(nameof(ARINC429TrigSerialPrsnt.DataRelation))]
  151. private void UpdateDataRelation()
  152. {
  153. this.CbxDataRelation.SelectedValue = Presenter.DataRelation;
  154. }
  155. }
  156. }