InvokeDllCenter.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Variables;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace PTMedicalInsurance.Helper
  12. {
  13. class InvokeDllCenter : IInvokeCenter
  14. {
  15. public int Business(string inputData, ref string outputData, ref string pErrMsg)
  16. {
  17. pErrMsg = "";
  18. outputData = "";
  19. try
  20. {
  21. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  22. //调用业务函数
  23. StringBuilder sbOut = new StringBuilder(40960);
  24. int pRtn = BusinessHandle(inputData, sbOut);
  25. outputData = sbOut.ToString();
  26. return pRtn;
  27. }
  28. catch (Exception ex)
  29. {
  30. pErrMsg = "invokeByDLL.BusinessHandle 异常:" + ex.Message;
  31. return -1;
  32. }
  33. //finally
  34. //{
  35. // Global.writeLog("invokeByDLL.BusinessHandle医保动态库通用业务函数", inputData, outputData);
  36. //}
  37. }
  38. public int BusinessExt(string inputData, ref string outputData, ref string pErrMsg)
  39. {
  40. pErrMsg = "";
  41. outputData = "";
  42. try
  43. {
  44. //inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  45. StringBuilder errmsgSb = new StringBuilder(4096);
  46. StringBuilder outSb = new StringBuilder(40960);
  47. StringBuilder sbHospitalNO = new StringBuilder(Global.inf.hospitalNO);
  48. StringBuilder sbCreditID = new StringBuilder(Global.inf.CreditID);
  49. StringBuilder sbBusinessID = new StringBuilder(Global.inf.BusinessID);
  50. StringBuilder sbInput = new StringBuilder(inputData);
  51. //调用业务函数
  52. int pRtn = 0; // BusinessHandleW(sbHospitalNO, sbCreditID, sbBusinessID, sbInput, outSb, errmsgSb);
  53. if (pRtn != 0)
  54. {
  55. outputData = outSb.ToString();
  56. pErrMsg = errmsgSb.ToString();
  57. return -1;
  58. }
  59. else
  60. {
  61. outputData = outSb.ToString();
  62. return 0;
  63. }
  64. }
  65. catch (Exception ex)
  66. {
  67. pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
  68. return -1;
  69. }
  70. //finally
  71. //{
  72. // Global.writeLog("CreditID12", Global.inf.CreditID, Global.inf.BusinessID);
  73. // Global.writeLog("invokeInitByDLL.BusinessHandleW医保动态库通用业务函数", inputData, outputData);
  74. //}
  75. }
  76. public int DownloadFile(string inputData, ref string outputData)
  77. {
  78. outputData = "";
  79. string error = string.Empty; int errorCode = 0;
  80. try
  81. {
  82. JObject jsonInParam = JObject.Parse(inputData);
  83. string fileName = (string)jsonInParam["input"]["fsDownloadIn"]["filename"];
  84. string filePath = Global.curEvt.path + "\\YBDLOAD\\" + fileName;
  85. //如果不存在目录,则创建目录
  86. if (!Directory.Exists(Global.curEvt.path + "\\YBDLOAD"))
  87. {
  88. //创建文件夹
  89. DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\YBDLOAD");
  90. }
  91. if (File.Exists(filePath))
  92. {
  93. File.Delete(filePath);
  94. }
  95. int iRes = Business(inputData, ref outputData,ref error);
  96. Global.writeLog($"DLL下载文件返回:[{iRes}],ERROR:{error}",inputData,outputData);
  97. if (iRes == 0)
  98. {
  99. dynamic joReturn = new JObject();
  100. joReturn.errorCode = errorCode;
  101. joReturn.errorMessage = error;
  102. joReturn.filePath = filePath;
  103. outputData = joReturn.ToString();
  104. }
  105. else
  106. {
  107. errorCode = -100;
  108. dynamic joReturn = new JObject();
  109. joReturn.errorCode = errorCode;
  110. joReturn.errorMessage = error;
  111. outputData = joReturn.ToString();
  112. return -1;
  113. }
  114. }
  115. catch (Exception ex)
  116. {
  117. errorCode = -100;
  118. error = ex.Message;
  119. dynamic joReturn = new JObject();
  120. joReturn.errorCode = errorCode;
  121. joReturn.errorMessage = error;
  122. outputData = joReturn.ToString();
  123. return -1;
  124. }
  125. finally
  126. {
  127. Global.writeLog("DownloadCenterFile" + "(" + Global.curEvt.URL + ")", inputData, outputData);
  128. }
  129. return 0;
  130. }
  131. public int Init(ref string pErrMsg)
  132. {
  133. int pRtn = -1;
  134. pErrMsg = "";
  135. JObject joRtn = new JObject();
  136. try
  137. {
  138. StringBuilder sbOut = new StringBuilder(40960);
  139. pRtn = Init(sbOut);
  140. pErrMsg = sbOut.ToString();
  141. return pRtn;
  142. }
  143. catch (Exception ex)
  144. {
  145. pErrMsg = "invokeInitByDLL.Init 异常:" + ex.Message;
  146. return -1;
  147. }
  148. //finally
  149. //{
  150. // Global.writeLog("InvokeInitByDLL(" + Global.inf.centerURL + ")", Global.inf.CreditID + ":" + Global.inf.BusinessID, pRtn.ToString() + pErrMsg);
  151. //}
  152. }
  153. public int UploadFile(string inputData, ref string outputData, ref string pErrMsg)
  154. {
  155. pErrMsg = "";
  156. outputData = "";
  157. JObject joRtn = new JObject();
  158. try
  159. {
  160. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  161. StringBuilder errmsgSb = new StringBuilder(4096);
  162. StringBuilder outSb = new StringBuilder(40960);
  163. //调用业务函数
  164. int pRtn = 0; // UploadFile(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, Global.inf.fileName, inputData, outSb, errmsgSb);
  165. if (pRtn != 0)
  166. {
  167. outputData = outSb.ToString();
  168. pErrMsg = errmsgSb.ToString();
  169. return -1;
  170. }
  171. else
  172. {
  173. outputData = outSb.ToString();
  174. return 0;
  175. }
  176. }
  177. catch (Exception ex)
  178. {
  179. pErrMsg = "invokeUploadFileByDLL.UploadFile 异常:" + ex.Message;
  180. return -1;
  181. }
  182. finally
  183. {
  184. Global.writeLog("invokeUploadFileByDLL.UploadFile医保动态库上传业务函数", inputData, outputData);
  185. }
  186. }
  187. /// <summary>
  188. /// 初始化函数
  189. /// </summary>
  190. /// <param name="pErrMsg"></param>
  191. /// <returns></returns>
  192. [DllImport("SiInterface_hsf.dll", EntryPoint = "INIT", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  193. static extern int Init(StringBuilder pErrMsg);
  194. /// <summary>
  195. /// 通用业务函数
  196. /// </summary>
  197. /// <param name="inputData"></param>
  198. /// <param name="outputData"></param>
  199. /// <returns></returns>
  200. [DllImport("SiInterface_hsf.dll", EntryPoint = "BUSINESS_HANDLE", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  201. static extern int BusinessHandle(string inputData, StringBuilder outputData);
  202. }
  203. }