123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747 |
- 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 PTMedicalInsurance.Variables;
- using PTMedicalInsurance.Helper;
- using Newtonsoft.Json.Linq;
- using Newtonsoft.Json;
- using System.Runtime.InteropServices;
- using MedicareComLib;
- namespace PTMedicalInsurance
- {
- public class ResourceHolder : IDisposable
- {
- private bool disposed = false;
- // 假设这是一个非托管资源
- private IntPtr unmanagedResource;
- public ResourceHolder()
- {
- // 获取非托管资源
- this.unmanagedResource = GetUnmanagedResource();
- }
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- protected virtual void Dispose(bool disposing)
- {
- if (!disposed)
- {
- if (disposing)
- {
- // 释放托管资源
- }
- // 释放非托管资源
- ReleaseUnmanagedResource(this.unmanagedResource);
- this.unmanagedResource = IntPtr.Zero;
- }
- disposed = true;
- }
- ~ResourceHolder()
- {
- Dispose(false);
- }
- // 假设的非托管资源获取方法
- private IntPtr GetUnmanagedResource()
- {
- // 获取非托管资源的代码
- return IntPtr.Zero;
- }
- // 假设的非托管资源释放方法
- private void ReleaseUnmanagedResource(IntPtr resource)
- {
- // 释放非托管资源的代码
- }
- }
- class SaveLogInData
- {
- /// <summary>
- /// 保存中心交易日志到数据库
- /// </summary>
- /// <param name="inParam"></param>
- /// <param name="outParam"></param>
- /// <param name="inParamPlain"></param>
- /// <param name="outParamPlain"></param>
- private void saveCenterLog(string inParam, string outParam, string inParamPlain, string outParamPlain)
- {
- dynamic joIris = new JObject();
- string sRtn = "";
- try
- {
- //解析postContent,插入医保交易日志表
- JArray jaParams = new JArray();
- JObject joParam = new JObject();
- joParam.Add("inParam", inParam);
- joParam.Add("outParam", outParam);
- joParam.Add("inParamPlain", inParamPlain);
- joParam.Add("outParamPlain", outParamPlain);
- joParam.Add("HospitalDr", Global.inf.hospitalDr);
- joParam.Add("InterfaceDr", Global.inf.interfaceDr);
- joParam.Add("updateUserID", Global.user.ID);
- joParam.Add("psn_no", Global.pat.psn_no);
- jaParams.Add(joParam);
- joIris.code = "09010021";
- joIris.Add("params", jaParams);
- InvokeHelper invoker = new InvokeHelper();
- sRtn = invoker.invokeInsuService(joIris.ToString(), "保存日志到数据库").ToString();
- }
- catch (Exception ex)
- {
- sRtn = JsonHelper.setExceptionJson(-100, "保存日志异常", ex.Message).ToString();
- Global.writeLog_Iris("保存日志异常:" + sRtn.ToString());
- }
- }
- }
- class ReadCardClass
- {
- OutpatientClass ShouXinObj = new OutpatientClass();
- //释放资源方法一
- public static void ReleaseComObject(object obj)
- {
- while ((Marshal.ReleaseComObject(obj)) > 0) ;
- }
- //释放资源方法二
- public static void ReleaseComObject2(object obj)
- {
- int result = 0;
- do
- {
- result = Marshal.ReleaseComObject(obj);
- } while (result > 0);
- // 将引用设置为null
- obj = null;
- }
- //释放资源方法三
- public static void ReleaseComObject3(object obj)
- {
- int result = 0;
- do
- {
- result = Marshal.FinalReleaseComObject(obj);
- } while (result > 0);
- // 将引用设置为null
- obj = null;
- }
- public class ResourceHolder : IDisposable
- {
- private bool disposed = false; // 用于跟踪资源是否已经被释放
- // 实现 IDisposable 接口
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this); // 防止垃圾回收器再次调用析构函数
- }
- protected virtual void Dispose(bool disposing)
- {
- if (!disposed)
- {
- if (disposing)
- {
- // 释放托管资源
- }
- // 释放非托管资源
- disposed = true;
- }
- }
- ~ResourceHolder()
- {
- Dispose(false);
- }
- // 其他对象方法
- }
- public int CreateBusinessObj(out System.Type OutComType,out object OutComInstance)
- {
- string rtn = "";
- string progID = "MedicareCom.Outpatient";
- OutComType = null;
- OutComInstance = "";
- try
- {
- OutComType = Type.GetTypeFromProgID(progID);
- // 创建Com的实例
- if (OutComType != null)
- {
- //创建实例
- OutComInstance = Activator.CreateInstance(OutComType);
- rtn = "成功";
- return 0;
- }
- else
- {
- rtn = "失败";
- return -1;
- }
- }
- catch (Exception ex)
- {
- rtn = "失败" + ",COM加载异常" + ex.Message;
- return -1;
- }
- finally
- {
- Global.writeLog("GetReadCardObj", "", "创建实例" + rtn);
- }
- }
- public void Open(System.Type ComType, object ComInstance,out string OutPut)
- {
- OutPut = "";
- try
- {
- if (ComInstance == null)
- {
- OutPut = "实例不存在!";
- return;
- }
- //设置需要设置的参数值
- 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("Com输出:" + OutPut);
- return;
- }
- catch (Exception ex)
- {
- OutPut = ex.Message;
- MessageBox.Show("COM加载异常!" + OutPut);
- return;
- }
- finally
- {
- Global.writeLog("Open", "", OutPut);
- //this.saveCenterLog("", OutPut, "", OutPut);
- }
- }
- public void Close(System.Type ComType, object ComInstance, out string OutPut)
- {
- 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("Com输出:" + OutPut);
- return;
- }
- catch (Exception ex)
- {
- OutPut = ex.Message;
- MessageBox.Show("COM加载异常!" + OutPut);
- return;
- }
- finally
- {
- Global.writeLog("Close", "", OutPut);
- // 释放资源
- (ComInstance as IDisposable)?.Dispose();
- GC.Collect();
- if (ComInstance is IDisposable disposable)
- {
- disposable.Dispose();
- }
- //GC.Collect();
- ////ReleaseComObject(ComInstance);
- ////ReleaseComObject2(ComInstance);
- //ReleaseComObject3(ComInstance);
- ////ReleaseComObject3(ComType);
- ComInstance = null;
- ComType = null;
- }
- }
- public void ReadCardObj(string FunName, string Input, System.Type ComType, object ComInstance, out string OutPut)
- {
- OutPut = "";
- try
- {
- if (ComInstance == null)
- {
- OutPut = "实例不存在!";
- return;
- }
- //设置需要设置的参数值
- 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;
- }
- finally
- {
- Global.writeLog(FunName, Input, OutPut);
- }
- }
- public void BussniessObj(string FunName, string Input, System.Type ComType, object ComInstance, out string OutPut)
- {
- OutPut = "";
- try
- {
- if (ComInstance == null)
- {
- OutPut = "实例不存在!";
- return;
- }
- //设置需要设置的参数值
- 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;
- }
- finally
- {
- Global.writeLog(FunName, Input, OutPut);
- this.saveCenterLog(Input, OutPut, Input, OutPut);
- }
- }
- public void Trade(System.Type ComType, object ComInstance, out string OutPut)
- {
- OutPut = "";
- try
- {
- if (ComInstance == null)
- {
- OutPut = "实例不存在!";
- return;
- }
- //设置需要设置的参数值
- 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("Trade", // 接口函数名
- BindingFlags.Default | BindingFlags.InvokeMethod,
- null,
- ComInstance, // 调用的COM组件
- ParamArray, // 参数数组
- ParamMods, // 指定返回参数的ParameterModifier数组
- null,
- null);
- OutPut = ParamArray[0].ToString();
- //MessageBox.Show("Com输出:" + OutPut);
- return;
- }
- catch (Exception ex)
- {
- OutPut = ex.Message;
- MessageBox.Show("COM加载异常!" + OutPut);
- return;
- }
- finally
- {
- Global.writeLog("Trade", "", OutPut);
- }
- }
- public void TradeAll(System.Type ComType, object ComInstance, out string OutPut)
- {
- OutPut = "";
- try
- {
- if (ComInstance == null)
- {
- OutPut = "实例不存在!";
- return;
- }
- //设置需要设置的参数值
- 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("TradeAll", // 接口函数名
- BindingFlags.Default | BindingFlags.InvokeMethod,
- null,
- ComInstance, // 调用的COM组件
- ParamArray, // 参数数组
- ParamMods, // 指定返回参数的ParameterModifier数组
- null,
- null);
- OutPut = ParamArray[0].ToString();
- return;
- }
- catch (Exception ex)
- {
- OutPut = ex.Message;
- MessageBox.Show("COM加载异常!" + OutPut);
- return;
- }
- finally
- {
- Global.writeLog("TradeAll", "", OutPut);
- //this.saveCenterLog("", OutPut, "", OutPut);
- }
- }
- public void Open(out string OutPut)
- {
- OutPut = "";
- try
- {
- ShouXinObj.Open(out OutPut);
- return;
- }
- catch (Exception ex)
- {
- OutPut = ex.Message;
- MessageBox.Show("Open加载异常!" + OutPut);
- return;
- }
- finally
- {
- Global.writeLog("Open", "", OutPut);
- //this.saveCenterLog("", OutPut, "", OutPut);
- }
- }
- public void Close(out string OutPut)
- {
- OutPut = "";
- try
- {
- ShouXinObj.Close(out OutPut);
- return;
- }
- catch (Exception ex)
- {
- OutPut = ex.Message;
- MessageBox.Show("Close加载异常!" + OutPut);
- return;
- }
- finally
- {
- ShouXinObj = null;
- Global.writeLog("Close", "", OutPut);
- //this.saveCenterLog("", OutPut, "", OutPut);
- }
- }
- public void GetPersonInfo(out string OutPut)
- {
- OutPut = "";
- try
- {
- ShouXinObj.GetPersonInfo(out OutPut);
- return;
- }
- catch (Exception ex)
- {
- OutPut = ex.Message;
- MessageBox.Show("GetPersonInfo加载异常!" + OutPut);
- return;
- }
- finally
- {
- Global.writeLog("GetPersonInfo", "", OutPut);
- //this.saveCenterLog("", OutPut, "", OutPut);
- }
- }
- /// <summary>
- /// 保存中心交易日志到数据库
- /// </summary>
- /// <param name="inParam"></param>
- /// <param name="outParam"></param>
- /// <param name="inParamPlain"></param>
- /// <param name="outParamPlain"></param>
- private void saveCenterLog(string inParam, string outParam, string inParamPlain, string outParamPlain)
- {
- dynamic joIris = new JObject();
- string sRtn = "";
- try
- {
- //解析postContent,插入医保交易日志表
- JArray jaParams = new JArray();
- JObject joParam = new JObject();
- joParam.Add("inParam", inParam);
- joParam.Add("outParam", outParam);
- joParam.Add("inParamPlain", inParamPlain);
- joParam.Add("outParamPlain", outParamPlain);
- joParam.Add("HospitalDr", Global.inf.hospitalDr);
- joParam.Add("InterfaceDr", Global.inf.interfaceDr);
- joParam.Add("updateUserID", Global.user.ID);
- joParam.Add("psn_no", Global.pat.psn_no);
- jaParams.Add(joParam);
- joIris.code = "09010021";
- joIris.Add("params", jaParams);
- InvokeHelper invoker = new InvokeHelper();
- sRtn = invoker.invokeInsuService(joIris.ToString(), "保存日志到数据库").ToString();
- }
- catch (Exception ex)
- {
- sRtn = JsonHelper.setExceptionJson(-100, "保存日志异常", ex.Message).ToString();
- Global.writeLog_Iris("保存日志异常:" + sRtn.ToString());
- }
- }
- }
- class MedOrdersShareClass
- {
- 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)
- {
- 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;
- }
- finally
- {
- Global.writeLog("ConnectServer", "", OutPut);
- }
- }
- public void MedOrdersShareObj(string FunName, string Input, System.Type ComType, object ComInstance, out string OutPut)
- {
- 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;
- }
- finally
- {
- Global.writeLog(FunName, Input, OutPut);
- }
- }
- }
- }
|