InvokeComCenter.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Variables;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using PTMedicalInsurance.Business;
  11. using System.Diagnostics;
  12. using PTMedicalInsurance.Forms;
  13. namespace PTMedicalInsurance.Helper
  14. {
  15. class InvokeComCenter : IInvokeCenter
  16. {
  17. string progID1 = "ybjk.interface";
  18. System.Type YinHaiComType;
  19. object YinHaiComInstance;
  20. //[STAThread]
  21. //static void Main()
  22. //{
  23. // //Application.EnableVisualStyles();
  24. // //Application.SetCompatibleTextRenderingDefault(false);
  25. // // 开始监控窗口
  26. // WindowMonitor.Start();
  27. // // 运行应用程序
  28. // //Application.Run();
  29. //}
  30. public int Business(string infno, ref string input, ref string output)
  31. {
  32. YinHaiComType = System.Type.GetTypeFromProgID(progID1);
  33. JObject jo = new JObject();
  34. jo.Add("transNo", infno);
  35. jo.Add("transType", "passwordCheck");
  36. jo.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmss"));
  37. jo.Add("businessType", Global.pat.card.ecBizType);
  38. jo.Add("data", JObject.Parse(input));
  39. string inpar = jo.ToString();
  40. try
  41. {
  42. //WindowMonitor.Start();
  43. // 创建Com的实例
  44. if (YinHaiComType != null)
  45. {
  46. //创建实例
  47. YinHaiComInstance = Activator.CreateInstance(YinHaiComType);
  48. //设置需要设置的参数值
  49. //设置需要设置的参数值
  50. object[] ParamArray = new object[3];
  51. ParamArray[0] = infno;
  52. ParamArray[1] = inpar;
  53. ParamArray[2] = "";
  54. ParameterModifier[] ParamMods = new ParameterModifier[1];
  55. ParamMods[0] = new ParameterModifier(3); // 初始化为接口参数的个数
  56. //ParamMods[0][0] = false;
  57. //ParamMods[0][1] = false;
  58. ParamMods[0][2] = true;
  59. YinHaiComType.InvokeMember("xjyb_call", // 接口函数名
  60. BindingFlags.Default | BindingFlags.InvokeMethod,
  61. null,
  62. YinHaiComInstance, // 调用的COM组件
  63. ParamArray, // 参数数组
  64. ParamMods, // 指定返回参数的ParameterModifier数组
  65. null,
  66. null);
  67. output = ParamArray[2].ToString();
  68. return 0;
  69. }
  70. else
  71. {
  72. output = "YinHaiComType加载失败!";
  73. return 1;
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. string outMes = ex.Message;
  79. if (ex.InnerException != null)
  80. {
  81. outMes += ex.InnerException.Message;
  82. }
  83. output = outMes;
  84. return -1;
  85. }
  86. finally
  87. {
  88. Global.writeLog("InvokeComCenter.Business", inpar, output);
  89. }
  90. }
  91. public int BusinessExt(string inputData, ref string outputData, ref string pErrMsg)
  92. {
  93. throw new NotImplementedException();
  94. }
  95. public int DownloadFile(string inputData, ref string outputData)
  96. {
  97. throw new NotImplementedException();
  98. }
  99. public int Init(ref string pErrMsg)
  100. {
  101. return 0;
  102. }
  103. public int UploadFile(string inputData, ref string outputData, ref string pErrMsg)
  104. {
  105. throw new NotImplementedException();
  106. }
  107. }
  108. }