现有一dll文件MyDll.dll,里边封装了一窗口FormA,现通过FormB调用MyDll.dll中的FormA窗口,传入参数并获取到FormA的返回值(通过FormA中的按钮触发,通过FormB中的委托方法实现返回值)
1.MyDll.dll文件中的FormA方法
定义委托方法和该委托的事件
public delegate void frmProcessDoubleClick(string selectdValue,string selectedLabel);
public event frmProcessDoubleClick ClickMethod;
窗体重构函数中增加参数获取FormB传的参数
方式一,string[]字符串数组
public MultiSelectForm(string[] args) { InitializeComponent(); MessageBox.Show(args[0]); }
方式二,定义通用类作为参数传值
public MultiSelectForm(LovFormExParameter args) { InitializeComponent(); var sql = args.sql; }
按钮调用事件返回值
ClickMethod(“1,2,3“, ”一,二,三“);
2.FormB中调用MyDll.dll中的FormA,并传入参数
if (File.Exists(Mes.Core.Config.ApplicationConfig.getProperty("ApplicationRootPath") + "\\" + "MyDll.dll")) { Assembly assembly = Assembly.LoadFrom(Mes.Core.Config.ApplicationConfig.getProperty("ApplicationRootPath") + "\\" + ”MyDll.dll“); //var MultiSelectType = assembly.GetTypes().FirstOrDefault(m => m.Name.Equals("FormA"));
//方式一:字符串数组传值 //string[] entity = new string[]{"123ujhfjojfofr","abc","sss"};
// var form = aa[2].GetConstructor(new Type[] { typeof(string[]) });
//方式二:通用类作为参数传值 MyClass entity= new MyClass(); enetity.Sql = @"select * from t where 1 = 1"; var asstype = assembly.GetType("MyDll.FormA"); var form = asstype.GetConstructor(new Type[] { typeof(MyClass) }); var func = asstype.GetEvents().FirstOrDefault(m => m.Name.Equals("ClickMethod")); var type = asstype.GetNestedType("frmProcessDoubleClick"); var del = Delegate.CreateDelegate(type, this, "MultiSelectReturn"); Form myForm = (Form)form.Invoke(new object[] { lfItem }); func.AddEventHandler(myForm, del); myForm.Owner = this; myForm.ShowDialog(); } else { MessageBox.Show("缺少MyDll.dll文件!请联系管理员解决"); }
MultiSelectReturn方法获取到返回值
private void MultiSelectReturn(string selectdValue, string selectedLabel) { MessageBox.Show(selectdValue + "::" + selectedLabel ); }
3.数据库中存储的时,为分隔符的编码,查询出,为分割符的名称
封装fn_split 函数,获取分隔符中的每个字符串
1 CREATE OR REPLACE FUNCTION fn_split (p_str IN VARCHAR2, p_delimiter IN VARCHAR2) 2 RETURN ty_str_split 3 --分割函数 4 -- 新建前要先建立ty_str_split 执行语句为:CREATE OR REPLACE TYPE ty_str_split IS TABLE OF VARCHAR2 (4000); 5 IS 6 j INT := 0; 7 i INT := 1; 8 len INT := 0; 9 len1 INT := 0; 10 str VARCHAR2 (4000); 11 str_split ty_str_split := ty_str_split (); 12 BEGIN 13 len := LENGTH (p_str); 14 len1 := LENGTH (p_delimiter); 15 WHILE j < len 16 LOOP 17 j := INSTR (p_str, p_delimiter, i); 18 IF j = 0 19 THEN 20 j := len; 21 str := SUBSTR (p_str, i); 22 str_split.EXTEND; 23 str_split (str_split.COUNT) := str; 24 IF i >= len 25 THEN 26 EXIT; 27 END IF; 28 ELSE 29 str := SUBSTR (p_str, i, j - i); 30 i := j + len1; 31 str_split.EXTEND; 32 str_split (str_split.COUNT) := str; 33 END IF; 34 END LOOP; 35 RETURN str_split; 36 END fn_split;
使用方法:
1 -- 使用方式 2 3 select * from table(fn_split('1,2',',')) 4 select COLUMN_VALUE from table(fn_split('1,2',',')) 5 6 -- 在存储过程中的使用 7 IS 8 S_AAC001 SPLIT_ARRAY := SPLIT_ARRAY(); 9 V_CALLBACK VARCHAR2(1000); 10 XCOUNT NUMBER; 11 BEGIN 12 V_CALLBACK := REPLACE(P_AAC001S, '"', ''); 13 S_AAC001 := F_SPLIT(V_CALLBACK, ','); 14 15 SELECT ((LENGTH(V_CALLBACK) - LENGTH(REPLACE(V_CALLBACK, ','))) / 16 LENGTH(',')) 17 INTO XCOUNT 18 FROM DUAL; 19 20 FOR I IN 0 .. XCOUNT - 1 LOOP 21 SELECT a 22 INTO a 23 FROM t_a 24 WHERE a = S_AAC001(I + 1); 25 END LOOP; 26 27 EXCEPTION 28 WHEN OTHERS THEN 29 --ROLLBACK; 30 PRM_APPCODE := -1; 31 PRM_ERRORMSG := '过程执行失败!错误信息:' || SQLERRM; 32 END;
标签:FormA,string,MyDll,dll,split,str,串口,WinForm From: https://www.cnblogs.com/jiangyuhu/p/18644019