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