123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- using BenQGuru.eMES.DLLService;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace UAS_DLLTest
- {
- public partial class Form1 : Form
- {
- MESHelper l;
- Control.ControlCollection collection;
- Control.ControlCollection groupBox2Childs;
- ParameterInfo[] param;
- List<string> outParams = new List<string>();
- object[] allParams;
- int icount = 0;
- public Form1()
- {
- InitializeComponent();
- l = new MESHelper();
- collection = groupBoxwithborder1.Controls;
- groupBox2Childs = groupBoxwithborder2.Controls;
- //监听多个radiobutton的状态
- for (int i = 0; i < collection.Count; i++)
- {
- if (collection[i] is RadioButton)
- {
- ((RadioButton)collection[i]).CheckedChanged+= new EventHandler(radioButton_checkChanged);
- }
- }
- }
- private void radioButton_checkChanged(object sender, EventArgs e)
- {
- for (int i = 0; i < collection.Count; i++)
- {
- if (((RadioButton)collection[i]).Checked) {
- //显示当前选中的方法的所有参数
- //获取所有的参数
- icount = 0;
- param = l.GetType().GetMethod(collection[i].Name).GetParameters();
- for (int j = 1; j < param.Length+1; j++)
- {
- Console.WriteLine("参数名:"+param[j-1].Name);
- //参数名i开头的才需要显示
- if (!param[j - 1].Name.StartsWith("o"))
- {
- icount += 1;
- //设置显示参数
- for (int k = 0; k < groupBox2Childs.Count; k++)
- {
- if (groupBox2Childs[k].Name == "label" + j)
- {
- groupBox2Childs[k].Text = param[j - 1].Name;
- groupBox2Childs[k].Visible = true;
- }
- else if (groupBox2Childs[k].Name == "textBox" + j)
- {
- groupBox2Childs[k].Visible = true;
- }
- }
- }
- }
- allParams = new object[param.Length];
- }
- }
- }
- private void confirm_Click(object sender, EventArgs e)
- {
- //拿到所有已经填写的参数
- for (int i = 0; i < groupBox2Childs.Count; i++)
- {
- for (int j = 1; j < allParams.Length; j++)
- {
- if (j > icount)
- {
- allParams[j - 1] = new string(new char[] { });
- }
- else
- {
- if (groupBox2Childs[i].Name == "textBox" + j)
- {
- if (param[j - 1].ParameterType.ToString()!= "System.String[]")
- {
- allParams[j - 1] = ((TextBox)groupBox2Childs[i]).Text;
- }
- else
- {
- allParams[j - 1] = ((TextBox)groupBox2Childs[i]).Text.Split(',');
- }
- }
- }
- }
- }
- //将out类型的参数放进去
- string oResult = "";
- //拿到需要触发的方法名
- for (int i = 0; i < collection.Count; i++) {
- if (((RadioButton)collection[i]).Checked)
- {
- Type type = l.GetType();
- MethodInfo method = type.GetMethod(((RadioButton)collection[i]).Name);
- var result=method.Invoke(l, allParams);
- oResult = result.ToString();
- }
- }
- //输出out出的信息
- operateResult.AppendText("返回值:"+oResult+",");
- for (int i=0;i<param.Length;i++) {
- if (param[i].Name.StartsWith("o")) {
- operateResult.AppendText(param[i].Name + ":" + allParams[i]+",");
- }
- }
- operateResult.AppendText("\n");
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- //设置groupBox2中所有的label和textbox不可见
- for (int i = 0; i < groupBox2Childs.Count; i++)
- {
- if ((groupBox2Childs[i] is Label)||(groupBox2Childs[i] is TextBox)) {
- groupBox2Childs[i].Visible = false;
- }
- }
- }
- private void clear_Click(object sender, EventArgs e)
- {
- //清除信息
- if (clearPara.Checked) {
- for (int i=0;i<groupBox2Childs.Count;i++) {
- if (groupBox2Childs[i] is TextBox) {
- ((TextBox)groupBox2Childs[i]).Text = "";
- }
- }
- }
- //清除日志
- if (clearResult.Checked) {
- operateResult.Clear();
- }
- }
- }
- }
|