using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using System.Reflection; using System.Net; using System.Management; using System.IO; using System.Runtime.InteropServices; namespace BJShouXinYB_Demo { class MedOrdersShareClass { [DllImport("MedicareCom.dll", EntryPoint = "Open", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] static extern int Open(StringBuilder OutData); [DllImport("MedicareCom.dll", EntryPoint = "GetPersonInfo_Multimedia", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] static extern int GetPersonInfo_Multimedia(StringBuilder InData, StringBuilder OutData); [DllImport("MedicareCom.dll", EntryPoint = "GetPersonInfoNation_Multimedia", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] static extern int GetPersonInfoNation_Multimedia(StringBuilder InData, StringBuilder OutData); [DllImport("MedicareCom.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] static extern IntPtr NationEcTrans(StringBuilder strUrl, StringBuilder InData, StringBuilder OutData); public int GetMedOrdersShareObj(out System.Type OutComType, out object OutComInstance) { Object rtnObj = ""; string progID = "EachCommunicationCom.Outpatient"; System.Type ComType; object ComInstance; ComType = Type.GetTypeFromProgID(progID); // 创建Com的实例 if (ComType != null) { //创建实例 ComInstance = Activator.CreateInstance(ComType); OutComType = ComType; OutComInstance = ComInstance; return 0; } else { OutComType = null; OutComInstance = ""; return -1; } } public void ConnectServer(System.Type ComType, object ComInstance, out string OutPut) { try { if (ComInstance == null) { OutPut = "实例不存在!"; return; } //GlobalVariables.writeLog("入参infno:" + infno); //GlobalVariables.writeLog("入参input:" + input); //设置需要设置的参数值 object[] ParamArray = new object[1]; ParamArray[0] = ""; //ParamArray[1] = input; ParameterModifier[] ParamMods = new ParameterModifier[1]; ParamMods[0] = new ParameterModifier(1); // 初始化为接口参数的个数 ParamMods[0][0] = true; ComType.InvokeMember("ConnectServer", // 接口函数名 BindingFlags.Default | BindingFlags.InvokeMethod, null, ComInstance, // 调用的COM组件 ParamArray, // 参数数组 ParamMods, // 指定返回参数的ParameterModifier数组 null, null); OutPut = ParamArray[0].ToString(); MessageBox.Show("ConnectServer输出:" + OutPut); return; } catch (Exception ex) { OutPut = ex.Message; MessageBox.Show("COM加载异常!" + OutPut); return; } } public void MedOrdersShareObj(string FunName, string Input, System.Type ComType, object ComInstance, out string OutPut) { try { if (ComInstance == null) { OutPut = "实例不存在!"; return; } //GlobalVariables.writeLog("入参infno:" + infno); //GlobalVariables.writeLog("入参input:" + input); //设置需要设置的参数值 object[] ParamArray = new object[2]; ParamArray[0] = Input; ParamArray[1] = Input; ParameterModifier[] ParamMods = new ParameterModifier[1]; ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数 ParamMods[0][0] = true; ParamMods[0][1] = true; ComType.InvokeMember(FunName, // 接口函数名 BindingFlags.Default | BindingFlags.InvokeMethod, null, ComInstance, // 调用的COM组件 ParamArray, // 参数数组 ParamMods, // 指定返回参数的ParameterModifier数组 null, null); OutPut = ParamArray[1].ToString(); return; } catch (Exception ex) { OutPut = ex.Message; MessageBox.Show("COM加载异常!" + OutPut); return; } } } class BussniessClass { public BussniessClass() { string progID = "MedicareCom.Outpatient"; System.Type ComType; object ComInstance; ComType = Type.GetTypeFromProgID(progID); // 创建Com的实例 if (ComType != null) { //创建实例 ComInstance = Activator.CreateInstance(ComType); } } public void BussniessObj(string FunName, string input, out string output) { output = ""; try { Type ComType = System.Type.GetTypeFromProgID("MedicareCom.Outpatient"); if (ComType != null) { //创建实例,不能再次创建,否则会提示没有初始化 object ComInstance = System.Activator.CreateInstance(ComType); if (ComInstance != null) { MessageBox.Show(("函数FunName:" + FunName + "\n" + "入参:" + input)); } else { output = "实例不存在!"; return; } //GlobalVariables.writeLog("入参infno:" + infno); //GlobalVariables.writeLog("入参input:" + input); //设置需要设置的参数值 object[] ParamArray = new object[2]; ParamArray[0] = input; ParamArray[1] = input; ParameterModifier[] ParamMods = new ParameterModifier[1]; ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数 ParamMods[0][0] = true; ParamMods[0][1] = true; ComType.InvokeMember(FunName, // 接口函数名 BindingFlags.Default | BindingFlags.InvokeMethod, null, ComInstance, // 调用的COM组件 ParamArray, // 参数数组 ParamMods, // 指定返回参数的ParameterModifier数组 null, null); output = ParamArray[1].ToString(); } else { output = "北京首信医保COM加载失败!"; //MessageBox.Show("COM加载失败!"); } } catch (Exception ex) { output = ex.Message; MessageBox.Show("COM加载异常!" + output); } } } class ReadCardClass { public int GetReadCardObj(out System.Type OutComType,out object OutComInstance) { Object rtnObj = ""; string progID = "MedicareCom.Outpatient"; System.Type ComType; object ComInstance; ComType = Type.GetTypeFromProgID(progID); // 创建Com的实例 if (ComType != null) { //创建实例 ComInstance = Activator.CreateInstance(ComType); OutComType = ComType; OutComInstance = ComInstance; return 0; } else { OutComType = null; OutComInstance = ""; return -1; } } public void Open(System.Type ComType, object ComInstance,out string OutPut) { try { if (ComInstance == null) { OutPut = "实例不存在!"; return; } //GlobalVariables.writeLog("入参infno:" + infno); //GlobalVariables.writeLog("入参input:" + input); //设置需要设置的参数值 object[] ParamArray = new object[1]; ParamArray[0] = ""; //ParamArray[1] = input; ParameterModifier[] ParamMods = new ParameterModifier[1]; ParamMods[0] = new ParameterModifier(1); // 初始化为接口参数的个数 ParamMods[0][0] = true; ComType.InvokeMember("open", // 接口函数名 BindingFlags.Default | BindingFlags.InvokeMethod, null, ComInstance, // 调用的COM组件 ParamArray, // 参数数组 ParamMods, // 指定返回参数的ParameterModifier数组 null, null); OutPut = ParamArray[0].ToString(); MessageBox.Show("Open输出:" + OutPut); return; } catch (Exception ex) { OutPut = ex.Message; MessageBox.Show("COM加载异常!" + OutPut); return; } } public void Close(System.Type ComType, object ComInstance, out string OutPut) { try { if (ComInstance == null) { OutPut = "实例不存在!"; return; } //GlobalVariables.writeLog("入参infno:" + infno); //GlobalVariables.writeLog("入参input:" + input); //设置需要设置的参数值 object[] ParamArray = new object[1]; ParamArray[0] = ""; //ParamArray[1] = input; ParameterModifier[] ParamMods = new ParameterModifier[1]; ParamMods[0] = new ParameterModifier(1); // 初始化为接口参数的个数 ParamMods[0][0] = true; ComType.InvokeMember("close", // 接口函数名 BindingFlags.Default | BindingFlags.InvokeMethod, null, ComInstance, // 调用的COM组件 ParamArray, // 参数数组 ParamMods, // 指定返回参数的ParameterModifier数组 null, null); OutPut = ParamArray[0].ToString(); MessageBox.Show("Close输出:" + OutPut); return; } catch (Exception ex) { OutPut = ex.Message; MessageBox.Show("COM加载异常!" + OutPut); return; } } public void ReadCardObj(string FunName, string Input, System.Type ComType, object ComInstance, out string OutPut) { try { if (ComInstance == null) { OutPut = "实例不存在!"; return; } //GlobalVariables.writeLog("入参infno:" + infno); //GlobalVariables.writeLog("入参input:" + input); //设置需要设置的参数值 object[] ParamArray = new object[2]; ParamArray[0] = Input; ParamArray[1] = Input; ParameterModifier[] ParamMods = new ParameterModifier[1]; ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数 ParamMods[0][0] = true; ParamMods[0][1] = true; ComType.InvokeMember(FunName, // 接口函数名 BindingFlags.Default | BindingFlags.InvokeMethod, null, ComInstance, // 调用的COM组件 ParamArray, // 参数数组 ParamMods, // 指定返回参数的ParameterModifier数组 null, null); OutPut = ParamArray[1].ToString(); return; } catch (Exception ex) { OutPut = ex.Message; MessageBox.Show("COM加载异常!" + OutPut); return; } } public void BussniessObj(string FunName, string input, out string output) { output = ""; try { Type ComType = System.Type.GetTypeFromProgID("MedicareCom.Outpatient"); if (ComType != null) { //创建实例,不能再次创建,否则会提示没有初始化 object ComInstance = System.Activator.CreateInstance(ComType); if (ComInstance != null) { MessageBox.Show(("函数FunName:" + FunName + "\n" + "入参:" + input)); } else { output = "实例不存在!"; return; } //GlobalVariables.writeLog("入参infno:" + infno); //GlobalVariables.writeLog("入参input:" + input); //设置需要设置的参数值 object[] ParamArray = new object[2]; ParamArray[0] = input; ParamArray[1] = input; ParameterModifier[] ParamMods = new ParameterModifier[1]; ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数 ParamMods[0][0] = true; ParamMods[0][1] = true; ComType.InvokeMember(FunName, // 接口函数名 BindingFlags.Default | BindingFlags.InvokeMethod, null, ComInstance, // 调用的COM组件 ParamArray, // 参数数组 ParamMods, // 指定返回参数的ParameterModifier数组 null, null); output = ParamArray[1].ToString(); } else { output = "北京首信医保COM加载失败!"; //MessageBox.Show("COM加载失败!"); } } catch (Exception ex) { output = ex.Message; MessageBox.Show("COM加载异常!" + output); } } } }