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 helper; Control.ControlCollection collection; Control.ControlCollection groupBox2Childs; ParameterInfo[] param; List outParams = new List(); object[] allParams; int icount = 0; public Form1() { InitializeComponent(); helper = new MESHelper(); collection = Methods.Controls; groupBox2Childs = Parameters.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) { hideControl(); for (int i = 0; i < collection.Count; i++) { if (((RadioButton)collection[i]).Checked) { //显示当前选中的方法的所有参数 //获取所有的参数 icount = 0; param = helper.GetType().GetMethod(collection[i].Name).GetParameters(); for (int j = 1; j < param.Length+1; j++) { //参数名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 = helper.GetType(); MethodInfo method = type.GetMethod(((RadioButton)collection[i]).Name); oResult = method.Invoke(helper, allParams).ToString(); } } //输出out出的信息 operateResult.AppendText("返回值:"+oResult+","); for (int i=0;i