123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- using Newtonsoft.Json.Linq;
- using PTMedicalInsurance.Helper;
- using PTMedicalInsurance.Variables;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- namespace PTMedicalInsurance.Common
- {
- /// <summary>
- /// 银海安全控件
- /// </summary>
- class YinHaiSafeCtrl
- {
- string progID = "YinHai.CHS.InterfaceSCS";
- System.Type comType;
- object comInstance;
- /// <summary>
- /// 调用银海安全控件
- /// </summary>
- /// <param name="funNo"></param>
- /// <returns></returns>
- public int Prepare(string funNo,out string sSafeControlsRtnValue)
- {
- string pErrMsg = string.Empty;
- JObject joInput = JsonHelper.setYinHaiSafe(funNo);
- sSafeControlsRtnValue = string.Empty;
- Init();
- Call(funNo,joInput.ToString(), out sSafeControlsRtnValue);
- JObject joRtn = new JObject();
- joRtn = JObject.Parse(sSafeControlsRtnValue);
- int errorCode = int.Parse(joRtn["code"].ToString());
- string errorMessage = joRtn["message"].ToString();
- if (errorCode != 1)
- {
- sSafeControlsRtnValue = errorMessage;
- return -1;
- }
- else
- {
- JObject jodata = JObject.FromObject(joRtn["data"]);
- Global.writeLog("参保地:"+ Global.pat.insuplc_admdvs);
- Global.writeLog("读卡返回:" + jodata.ToString());
- // 如果存在则不使用读卡返回的信息
- if (string.IsNullOrEmpty(Global.pat.insuplc_admdvs))
- {
- Global.pat.insuplc_admdvs = jodata["insuplc_admdvs"].ToString();
- }
- Global.pat.mdtrtcertType = jodata["mdtrt_cert_type"].ToString();
- Global.pat.mdtrtcertNO = jodata["mdtrt_cert_no"].ToString();
- Global.pat.psn_type = jodata["psn_cert_type"].ToString();
- Global.pat.certNO = jodata["certno"].ToString();
- Global.pat.name = jodata["psn_name"].ToString();
- Global.pat.card.SN = jodata["card_sn"].ToString();
- Global.pat.card.Cardtoken = jodata["card_token"].ToString();
- sSafeControlsRtnValue = jodata.ToString();
- }
- return 0;
- }
- /// <summary>
- /// 调用银海控件进行打印
- /// </summary>
- /// <param name="input"></param>
- /// <param name="output"></param>
- public void YinHaiPrint(string input, out string output)
- {
- string errMsg = string.Empty;
- Init();
- Print(input, out output);
- }
- private int Init()
- {
- comType = System.Type.GetTypeFromProgID(progID);
- // 创建Com的实例
- if (comType != null)
- {
- Global.writeLog("开始COM组件Init");
- //创建实例
- comInstance = Activator.CreateInstance(comType);
- if (comInstance != null)
- {
- Global.writeLog("Init实例创建成功");
- }
- //设置需要设置的参数值
- object[] ParamArray = new object[2];
- ParamArray[0] = 0;
- ParamArray[1] = "";
- ParameterModifier[] ParamMods = new ParameterModifier[1];
- ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
- ParamMods[0][0] = true;
- ParamMods[0][1] = true; // 设置第二个参数为返回参数,调用含有ParameterModifier数组的重载函数
- comType.InvokeMember("yh_CHS_init", // 接口函数名
- BindingFlags.Default | BindingFlags.InvokeMethod,
- null,
- comInstance, // 调用的COM组件
- ParamArray, // 参数数组
- ParamMods, // 指定返回参数的ParameterModifier数组
- null,
- null);
- string Msg = "加载成功:" + ParamArray[1].ToString();
- Global.writeLog(Msg + "___" + ParamArray[0].ToString());
- return (int)ParamArray[0];
- }
- else
- {
- string Msg = "YinHaiComType加载失败!";
- Global.writeLog(Msg);
- return 1;
- }
- }
- private int Call(string infno, string inputData, out string outputData)
- {
- try
- {
- if (comType != null)
- {
- //创建实例,不能再次创建,否则会提示没有初始化
- if (comInstance != null)
- {
- Global.writeLog("实例创建成功,准备调用Call服务");
- }
- else
- {
- outputData = "实例不存在!";
- Global.writeLog("实例不存在");
- return -1;
- }
- //设置需要设置的参数值
- object[] ParamArray = new object[3];
- ParamArray[0] = infno;
- ParamArray[1] = inputData;
- ParamArray[2] = "";
- ParameterModifier[] ParamMods = new ParameterModifier[1];
- ParamMods[0] = new ParameterModifier(3); // 初始化为接口参数的个数
- ParamMods[0][2] = true;
- comType.InvokeMember("yh_CHS_call", // 接口函数名
- BindingFlags.Default | BindingFlags.InvokeMethod,
- null,
- comInstance, // 调用的COM组件
- ParamArray, // 参数数组
- ParamMods, // 指定返回参数的ParameterModifier数组
- null,
- null);
- outputData = ParamArray[2].ToString();
- Global.writeLog("Com输出:" + outputData);
- return 0;
- }
- else
- {
- outputData = "COM加载失败!";
- Global.writeLog("COM加载失败!");
- }
- }
- catch (Exception ex)
- {
- outputData = ex.Message;
- Global.writeLog("COM加载失败!" + outputData);
- }
- return -1;
- }
-
- /// <summary>
- /// 打印结算清单
- /// </summary>
- /// <param name="input"></param>
- /// <param name="output"></param>
- private void Print(string input, out string output)
- {
- if (comType != null)
- {
- //创建实例,不能再次创建,否则会提示没有初始化
- if (comInstance != null)
- {
- Global.writeLog("实例创建成功,准备调用Call服务");
- }
- else
- {
- output = "实例不存在!";
- Global.writeLog("实例不存在");
- return;
- }
- //设置需要设置的参数值
- object[] ParamArray = new object[2];
- ParamArray[0] = input;
- ParamArray[1] = "";
- ParameterModifier[] ParamMods = new ParameterModifier[1];
- ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
- ParamMods[0][1] = true;
- comType.InvokeMember("yh_CHS_print", // 接口函数名
- BindingFlags.Default | BindingFlags.InvokeMethod,
- null,
- comInstance, // 调用的COM组件
- ParamArray, // 参数数组
- ParamMods, // 指定返回参数的ParameterModifier数组
- null,
- null);
- output = ParamArray[1].ToString();
- }
- else
- {
- output = "COM加载失败!";
- Global.writeLog("COM加载失败!");
- }
- }
- public void Destroy(out string output)
- {
- // 创建Com的实例
- if (comType != null)
- {
- //创建实例
- comInstance = Activator.CreateInstance(comType);
- if (comInstance != null)
- {
- Global.writeLog("实例创建成功,准备调用Call服务");
- }
- else
- {
- output = "实例不存在!";
- Global.writeLog("实例不存在");
- return;
- }
- //设置需要设置的参数值
- object[] ParamArray = new object[0];
- ParameterModifier[] ParamMods = new ParameterModifier[0];
- ParamMods[0] = new ParameterModifier(0); // 初始化为接口参数的个数
- comType.InvokeMember("yh_CHS_destroy", // 接口函数名
- BindingFlags.Default | BindingFlags.InvokeMethod,
- null,
- comInstance, // 调用的COM组件
- ParamArray, // 参数数组
- ParamMods, // 指定返回参数的ParameterModifier数组
- null,
- null);
- output = "destroy成功!";
- }
- else
- {
- output = "COM加载失败!";
- Global.writeLog("COM加载失败!");
- }
- }
- }
- }
|