TransIDPage.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 TransIDPage : 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 TransIDPage()
  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. InitBusNumber();
  57. InitDeviceNumber();
  58. InitFunctionNumber();
  59. InitTag();
  60. UpdateBusNumber();
  61. UpdateDeviceNumber();
  62. UpdateFunctionNumber();
  63. UpdateRelation();
  64. UpdateTag();
  65. }
  66. }
  67. private void InitBusNumber()
  68. {
  69. BtnBusNumber.Click += (_, _) =>
  70. {
  71. Boolean lastflag = true;
  72. if (this.FindForm() is FloatForm form)
  73. {
  74. lastflag = form.CanClose;
  75. form.CanClose = false;
  76. }
  77. FloatForm floatForm = new FloatForm();
  78. floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
  79. floatForm.BackColor = BackColor;
  80. floatForm.ForeColor = ForeColor;
  81. floatForm.Width = 380;
  82. floatForm.Height = 460 + floatForm.HeadHeight;
  83. floatForm.Title = "设置AT";
  84. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  85. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
  86. numberKeyboard.Top = floatForm.HeadHeight;
  87. numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
  88. numberKeyboard.Width = floatForm.Width;
  89. numberKeyboard.ForeColor = ForeColor;
  90. numberKeyboard.BackColor = BackColor;
  91. numberKeyboard.Value = Presenter.BusNumber;
  92. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  93. numberKeyboard.MinValue = Presenter.MinBusNumber;
  94. numberKeyboard.MaxValue = Presenter.MaxBusNumber;
  95. numberKeyboard.OkClick += (sender, args) =>
  96. {
  97. this.Presenter.BusNumber = (Byte)args.Data;
  98. floatForm?.Close();
  99. };
  100. numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
  101. floatForm.Controls.Add(numberKeyboard);
  102. DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
  103. floatForm.FormClosing += (_, _) =>
  104. {
  105. if (this.FindForm() is FloatForm form)
  106. form.CanClose = lastflag;
  107. };
  108. floatForm.ShowDialogByPosition();
  109. };
  110. }
  111. private void InitDeviceNumber()
  112. {
  113. BtnDeviceNumber.Click += (_, _) =>
  114. {
  115. Boolean lastflag = true;
  116. if (this.FindForm() is FloatForm form)
  117. {
  118. lastflag = form.CanClose;
  119. form.CanClose = false;
  120. }
  121. FloatForm floatForm = new FloatForm();
  122. floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
  123. floatForm.BackColor = BackColor;
  124. floatForm.ForeColor = ForeColor;
  125. floatForm.Width = 380;
  126. floatForm.Height = 460 + floatForm.HeadHeight;
  127. floatForm.Title = "设置AT";
  128. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  129. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
  130. numberKeyboard.Top = floatForm.HeadHeight;
  131. numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
  132. numberKeyboard.Width = floatForm.Width;
  133. numberKeyboard.ForeColor = ForeColor;
  134. numberKeyboard.BackColor = BackColor;
  135. numberKeyboard.Value = Presenter.DeviceNumber;
  136. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  137. numberKeyboard.MinValue = Presenter.MinDeviceNumber;
  138. numberKeyboard.MaxValue = Presenter.MaxDeviceNumber;
  139. numberKeyboard.OkClick += (sender, args) =>
  140. {
  141. this.Presenter.DeviceNumber = (Byte)args.Data;
  142. floatForm?.Close();
  143. };
  144. numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
  145. floatForm.Controls.Add(numberKeyboard);
  146. DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
  147. floatForm.FormClosing += (_, _) =>
  148. {
  149. if (this.FindForm() is FloatForm form)
  150. form.CanClose = lastflag;
  151. };
  152. floatForm.ShowDialogByPosition();
  153. };
  154. }
  155. private void InitTag()
  156. {
  157. BtnTag.Click += (_, _) =>
  158. {
  159. Boolean lastflag = true;
  160. if (this.FindForm() is FloatForm form)
  161. {
  162. lastflag = form.CanClose;
  163. form.CanClose = false;
  164. }
  165. FloatForm floatForm = new FloatForm();
  166. floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
  167. floatForm.BackColor = BackColor;
  168. floatForm.ForeColor = ForeColor;
  169. floatForm.Width = 380;
  170. floatForm.Height = 460 + floatForm.HeadHeight;
  171. floatForm.Title = "设置AT";
  172. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  173. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
  174. numberKeyboard.Top = floatForm.HeadHeight;
  175. numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
  176. numberKeyboard.Width = floatForm.Width;
  177. numberKeyboard.ForeColor = ForeColor;
  178. numberKeyboard.BackColor = BackColor;
  179. numberKeyboard.Value = Presenter.TagData;
  180. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  181. numberKeyboard.MinValue = Presenter.MinTagData;
  182. numberKeyboard.MaxValue = Presenter.MaxTagData;
  183. numberKeyboard.OkClick += (sender, args) =>
  184. {
  185. this.Presenter.TagData = (Byte)args.Data;
  186. floatForm?.Close();
  187. };
  188. numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
  189. floatForm.Controls.Add(numberKeyboard);
  190. DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
  191. floatForm.FormClosing += (_, _) =>
  192. {
  193. if (this.FindForm() is FloatForm form)
  194. form.CanClose = lastflag;
  195. };
  196. floatForm.ShowDialogByPosition();
  197. };
  198. }
  199. private void InitFunctionNumber()
  200. {
  201. BtnFunctionNumber.Click += (_, _) =>
  202. {
  203. Boolean lastflag = true;
  204. if (this.FindForm() is FloatForm form)
  205. {
  206. lastflag = form.CanClose;
  207. form.CanClose = false;
  208. }
  209. FloatForm floatForm = new FloatForm();
  210. floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
  211. floatForm.BackColor = BackColor;
  212. floatForm.ForeColor = ForeColor;
  213. floatForm.Width = 380;
  214. floatForm.Height = 460 + floatForm.HeadHeight;
  215. floatForm.Title = "设置AT";
  216. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  217. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
  218. numberKeyboard.Top = floatForm.HeadHeight;
  219. numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
  220. numberKeyboard.Width = floatForm.Width;
  221. numberKeyboard.ForeColor = ForeColor;
  222. numberKeyboard.BackColor = BackColor;
  223. numberKeyboard.Value = Presenter.FunctionNumber;
  224. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Hex;
  225. numberKeyboard.MinValue = Presenter.MinFunctionNumber;
  226. numberKeyboard.MaxValue = Presenter.MaxFunctionNumber;
  227. numberKeyboard.OkClick += (sender, args) =>
  228. {
  229. this.Presenter.FunctionNumber = (Byte)args.Data;
  230. floatForm?.Close();
  231. };
  232. numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
  233. floatForm.Controls.Add(numberKeyboard);
  234. DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
  235. floatForm.FormClosing += (_, _) =>
  236. {
  237. if (this.FindForm() is FloatForm form)
  238. form.CanClose = lastflag;
  239. };
  240. floatForm.ShowDialogByPosition();
  241. };
  242. }
  243. private void InitRelation()
  244. {
  245. this.CbxRelation.DataSource = Enum.GetValues<ProtocolPCIe.DataRelation>().Select(x =>
  246. {
  247. String key = String.Empty;
  248. key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
  249. if (String.IsNullOrEmpty(key))
  250. {
  251. key = x.ToString();
  252. }
  253. return new KeyValuePair<String, ProtocolPCIe.DataRelation>(key, x);
  254. }).ToList();
  255. this.CbxRelation.DisplayMember = "Key";
  256. this.CbxRelation.ValueMember = "Value";
  257. this.CbxRelation.SelectedValueChanged += (sender, args) =>
  258. {
  259. if (ParentForm == null)
  260. {
  261. }
  262. else
  263. {
  264. Presenter.DataRelation = (ProtocolPCIe.DataRelation)this.CbxRelation.SelectedValue;
  265. }
  266. };
  267. this.CbxRelation.SelectedValue = Presenter.DataRelation;
  268. }
  269. public void UpdateView(Object presenter, String propertyName)
  270. {
  271. if (String.IsNullOrEmpty(propertyName))
  272. {
  273. UpdateView();
  274. }
  275. else
  276. {
  277. this.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(x =>
  278. {
  279. UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
  280. return attribute != null && String.Equals(attribute.PropertyName, propertyName);
  281. }).ToList().ForEach(x => x.Invoke(this, null));
  282. }
  283. }
  284. private void UpdateView()
  285. {
  286. this.GetType().GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
  287. .Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x.Invoke(this, null));
  288. }
  289. [UpdateProperty(nameof(PCIeTrigSerialPrsnt.DataRelation))]
  290. private void UpdateRelation()
  291. {
  292. this.CbxRelation.SelectedValue = Presenter.DataRelation;
  293. }
  294. [UpdateProperty(nameof(PCIeTrigSerialPrsnt.TagData))]
  295. private void UpdateTag()
  296. {
  297. this.BtnTag.Text = $"0x{Convert.ToString(Presenter.TagData, 16).PadLeft(2, '0')}";
  298. }
  299. [UpdateProperty(nameof(PCIeTrigSerialPrsnt.BusNumber))]
  300. private void UpdateBusNumber()
  301. {
  302. this.BtnBusNumber.Text = $"0x{Convert.ToString(Presenter.BusNumber, 16).PadLeft(2, '0')}";
  303. }
  304. [UpdateProperty(nameof(PCIeTrigSerialPrsnt.DeviceNumber))]
  305. private void UpdateDeviceNumber()
  306. {
  307. this.BtnDeviceNumber.Text = $"0x{Convert.ToString(Presenter.DeviceNumber, 16).PadLeft(2, '0')}";
  308. }
  309. [UpdateProperty(nameof(PCIeTrigSerialPrsnt.FunctionNumber))]
  310. private void UpdateFunctionNumber()
  311. {
  312. this.BtnFunctionNumber.Text = $"0x{Convert.ToString(Presenter.FunctionNumber, 16).PadLeft(2, '0')}";
  313. }
  314. }
  315. }