Form1.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using BenQGuru.eMES.DLLService;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace UAS_DLLTest
  13. {
  14. public partial class Form1 : Form
  15. {
  16. MESHelper helper;
  17. Control.ControlCollection collection;
  18. Control.ControlCollection groupBox2Childs;
  19. ParameterInfo[] param;
  20. List<string> outParams = new List<string>();
  21. object[] allParams;
  22. int icount = 0;
  23. public Form1()
  24. {
  25. InitializeComponent();
  26. helper = new MESHelper();
  27. collection = Methods.Controls;
  28. groupBox2Childs = Parameters.Controls;
  29. //监听多个radiobutton的状态
  30. for (int i = 0; i < collection.Count; i++)
  31. {
  32. if (collection[i] is RadioButton)
  33. {
  34. ((RadioButton)collection[i]).CheckedChanged+= new EventHandler(radioButton_checkChanged);
  35. }
  36. }
  37. }
  38. private void radioButton_checkChanged(object sender, EventArgs e)
  39. {
  40. hideControl();
  41. for (int i = 0; i < collection.Count; i++)
  42. {
  43. if (((RadioButton)collection[i]).Checked) {
  44. //显示当前选中的方法的所有参数
  45. //获取所有的参数
  46. icount = 0;
  47. param = helper.GetType().GetMethod(collection[i].Name).GetParameters();
  48. for (int j = 1; j < param.Length+1; j++)
  49. {
  50. //参数名i开头的才需要显示
  51. if (!param[j - 1].Name.StartsWith("o"))
  52. {
  53. icount += 1;
  54. //设置显示参数
  55. for (int k = 0; k < groupBox2Childs.Count; k++)
  56. {
  57. if (groupBox2Childs[k].Name == "label" + j)
  58. {
  59. groupBox2Childs[k].Text = param[j - 1].Name;
  60. groupBox2Childs[k].Visible = true;
  61. }
  62. else if (groupBox2Childs[k].Name == "textBox" + j)
  63. {
  64. groupBox2Childs[k].Visible = true;
  65. }
  66. }
  67. }
  68. }
  69. allParams = new object[param.Length];
  70. }
  71. }
  72. }
  73. private void confirm_Click(object sender, EventArgs e)
  74. {
  75. //拿到所有已经填写的参数
  76. for (int i = 0; i < groupBox2Childs.Count; i++)
  77. {
  78. for (int j = 1; j < allParams.Length; j++)
  79. {
  80. if (j > icount)
  81. {
  82. allParams[j - 1] = new string(new char[] { });
  83. }
  84. else
  85. {
  86. if (groupBox2Childs[i].Name == "textBox" + j)
  87. {
  88. if (param[j - 1].ParameterType.ToString()!= "System.String[]")
  89. {
  90. allParams[j - 1] = ((TextBox)groupBox2Childs[i]).Text;
  91. }
  92. else
  93. {
  94. allParams[j - 1] = ((TextBox)groupBox2Childs[i]).Text.Split(',');
  95. }
  96. }
  97. }
  98. }
  99. }
  100. //将out类型的参数放进去
  101. string oResult = "";
  102. //拿到需要触发的方法名
  103. for (int i = 0; i < collection.Count; i++) {
  104. if (((RadioButton)collection[i]).Checked)
  105. {
  106. Type type = helper.GetType();
  107. MethodInfo method = type.GetMethod(((RadioButton)collection[i]).Name);
  108. oResult = method.Invoke(helper, allParams).ToString();
  109. }
  110. }
  111. //输出out出的信息
  112. operateResult.AppendText("返回值:"+oResult+",");
  113. for (int i=0;i<param.Length;i++) {
  114. if (param[i].Name.StartsWith("o")) {
  115. operateResult.AppendText(param[i].Name + ":" + allParams[i]+",");
  116. }
  117. }
  118. operateResult.AppendText("\n");
  119. }
  120. private void Form1_Load(object sender, EventArgs e)
  121. {
  122. hideControl();
  123. }
  124. private void clear_Click(object sender, EventArgs e)
  125. {
  126. //清除信息
  127. if (clearPara.Checked) {
  128. for (int i=0;i<groupBox2Childs.Count;i++) {
  129. if (groupBox2Childs[i] is TextBox) {
  130. ((TextBox)groupBox2Childs[i]).Text = "";
  131. }
  132. }
  133. }
  134. //清除日志
  135. if (clearResult.Checked) {
  136. operateResult.Clear();
  137. }
  138. }
  139. private void hideControl()
  140. {
  141. //设置groupBox2中所有的label和textbox不可见
  142. for (int i = 0; i < groupBox2Childs.Count; i++)
  143. {
  144. if ((groupBox2Childs[i] is Label) || (groupBox2Childs[i] is TextBox))
  145. {
  146. groupBox2Childs[i].Visible = false;
  147. }
  148. }
  149. }
  150. }
  151. }