ObjectClass.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Windows.Forms;
  10. using System.Reflection;
  11. using System.Net;
  12. using System.Management;
  13. using System.IO;
  14. using System.Runtime.InteropServices;
  15. namespace BJShouXinYB_Demo
  16. {
  17. class MedOrdersShareClass
  18. {
  19. [DllImport("MedicareCom.dll", EntryPoint = "Open", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  20. static extern int Open(StringBuilder OutData);
  21. [DllImport("MedicareCom.dll", EntryPoint = "GetPersonInfo_Multimedia", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  22. static extern int GetPersonInfo_Multimedia(StringBuilder InData, StringBuilder OutData);
  23. [DllImport("MedicareCom.dll", EntryPoint = "GetPersonInfoNation_Multimedia", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  24. static extern int GetPersonInfoNation_Multimedia(StringBuilder InData, StringBuilder OutData);
  25. [DllImport("MedicareCom.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  26. static extern IntPtr NationEcTrans(StringBuilder strUrl, StringBuilder InData, StringBuilder OutData);
  27. public int GetMedOrdersShareObj(out System.Type OutComType, out object OutComInstance)
  28. {
  29. Object rtnObj = "";
  30. string progID = "EachCommunicationCom.Outpatient";
  31. System.Type ComType;
  32. object ComInstance;
  33. ComType = Type.GetTypeFromProgID(progID);
  34. // 创建Com的实例
  35. if (ComType != null)
  36. {
  37. //创建实例
  38. ComInstance = Activator.CreateInstance(ComType);
  39. OutComType = ComType;
  40. OutComInstance = ComInstance;
  41. return 0;
  42. }
  43. else
  44. {
  45. OutComType = null;
  46. OutComInstance = "";
  47. return -1;
  48. }
  49. }
  50. public void ConnectServer(System.Type ComType, object ComInstance, out string OutPut)
  51. {
  52. try
  53. {
  54. if (ComInstance == null)
  55. {
  56. OutPut = "实例不存在!";
  57. return;
  58. }
  59. //GlobalVariables.writeLog("入参infno:" + infno);
  60. //GlobalVariables.writeLog("入参input:" + input);
  61. //设置需要设置的参数值
  62. object[] ParamArray = new object[1];
  63. ParamArray[0] = "";
  64. //ParamArray[1] = input;
  65. ParameterModifier[] ParamMods = new ParameterModifier[1];
  66. ParamMods[0] = new ParameterModifier(1); // 初始化为接口参数的个数
  67. ParamMods[0][0] = true;
  68. ComType.InvokeMember("ConnectServer", // 接口函数名
  69. BindingFlags.Default | BindingFlags.InvokeMethod,
  70. null,
  71. ComInstance, // 调用的COM组件
  72. ParamArray, // 参数数组
  73. ParamMods, // 指定返回参数的ParameterModifier数组
  74. null,
  75. null);
  76. OutPut = ParamArray[0].ToString();
  77. MessageBox.Show("ConnectServer输出:" + OutPut);
  78. return;
  79. }
  80. catch (Exception ex)
  81. {
  82. OutPut = ex.Message;
  83. MessageBox.Show("COM加载异常!" + OutPut);
  84. return;
  85. }
  86. }
  87. public void MedOrdersShareObj(string FunName, string Input, System.Type ComType, object ComInstance, out string OutPut)
  88. {
  89. try
  90. {
  91. if (ComInstance == null)
  92. {
  93. OutPut = "实例不存在!";
  94. return;
  95. }
  96. //GlobalVariables.writeLog("入参infno:" + infno);
  97. //GlobalVariables.writeLog("入参input:" + input);
  98. //设置需要设置的参数值
  99. object[] ParamArray = new object[2];
  100. ParamArray[0] = Input;
  101. ParamArray[1] = Input;
  102. ParameterModifier[] ParamMods = new ParameterModifier[1];
  103. ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
  104. ParamMods[0][0] = true;
  105. ParamMods[0][1] = true;
  106. ComType.InvokeMember(FunName, // 接口函数名
  107. BindingFlags.Default | BindingFlags.InvokeMethod,
  108. null,
  109. ComInstance, // 调用的COM组件
  110. ParamArray, // 参数数组
  111. ParamMods, // 指定返回参数的ParameterModifier数组
  112. null,
  113. null);
  114. OutPut = ParamArray[1].ToString();
  115. return;
  116. }
  117. catch (Exception ex)
  118. {
  119. OutPut = ex.Message;
  120. MessageBox.Show("COM加载异常!" + OutPut);
  121. return;
  122. }
  123. }
  124. }
  125. class BussniessClass
  126. {
  127. public BussniessClass()
  128. {
  129. string progID = "MedicareCom.Outpatient";
  130. System.Type ComType;
  131. object ComInstance;
  132. ComType = Type.GetTypeFromProgID(progID);
  133. // 创建Com的实例
  134. if (ComType != null)
  135. {
  136. //创建实例
  137. ComInstance = Activator.CreateInstance(ComType);
  138. }
  139. }
  140. public void BussniessObj(string FunName, string input, out string output)
  141. {
  142. output = "";
  143. try
  144. {
  145. Type ComType = System.Type.GetTypeFromProgID("MedicareCom.Outpatient");
  146. if (ComType != null)
  147. {
  148. //创建实例,不能再次创建,否则会提示没有初始化
  149. object ComInstance = System.Activator.CreateInstance(ComType);
  150. if (ComInstance != null)
  151. {
  152. MessageBox.Show(("函数FunName:" + FunName + "\n"
  153. + "入参:" + input));
  154. }
  155. else
  156. {
  157. output = "实例不存在!";
  158. return;
  159. }
  160. //GlobalVariables.writeLog("入参infno:" + infno);
  161. //GlobalVariables.writeLog("入参input:" + input);
  162. //设置需要设置的参数值
  163. object[] ParamArray = new object[2];
  164. ParamArray[0] = input;
  165. ParamArray[1] = input;
  166. ParameterModifier[] ParamMods = new ParameterModifier[1];
  167. ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
  168. ParamMods[0][0] = true;
  169. ParamMods[0][1] = true;
  170. ComType.InvokeMember(FunName, // 接口函数名
  171. BindingFlags.Default | BindingFlags.InvokeMethod,
  172. null,
  173. ComInstance, // 调用的COM组件
  174. ParamArray, // 参数数组
  175. ParamMods, // 指定返回参数的ParameterModifier数组
  176. null,
  177. null);
  178. output = ParamArray[1].ToString();
  179. }
  180. else
  181. {
  182. output = "北京首信医保COM加载失败!";
  183. //MessageBox.Show("COM加载失败!");
  184. }
  185. }
  186. catch (Exception ex)
  187. {
  188. output = ex.Message;
  189. MessageBox.Show("COM加载异常!" + output);
  190. }
  191. }
  192. }
  193. class ReadCardClass
  194. {
  195. public int GetReadCardObj(out System.Type OutComType,out object OutComInstance)
  196. {
  197. Object rtnObj = "";
  198. string progID = "MedicareCom.Outpatient";
  199. System.Type ComType;
  200. object ComInstance;
  201. ComType = Type.GetTypeFromProgID(progID);
  202. // 创建Com的实例
  203. if (ComType != null)
  204. {
  205. //创建实例
  206. ComInstance = Activator.CreateInstance(ComType);
  207. OutComType = ComType;
  208. OutComInstance = ComInstance;
  209. return 0;
  210. }
  211. else
  212. {
  213. OutComType = null;
  214. OutComInstance = "";
  215. return -1;
  216. }
  217. }
  218. public void Open(System.Type ComType, object ComInstance,out string OutPut)
  219. {
  220. try
  221. {
  222. if (ComInstance == null)
  223. {
  224. OutPut = "实例不存在!";
  225. return;
  226. }
  227. //GlobalVariables.writeLog("入参infno:" + infno);
  228. //GlobalVariables.writeLog("入参input:" + input);
  229. //设置需要设置的参数值
  230. object[] ParamArray = new object[1];
  231. ParamArray[0] = "";
  232. //ParamArray[1] = input;
  233. ParameterModifier[] ParamMods = new ParameterModifier[1];
  234. ParamMods[0] = new ParameterModifier(1); // 初始化为接口参数的个数
  235. ParamMods[0][0] = true;
  236. ComType.InvokeMember("open", // 接口函数名
  237. BindingFlags.Default | BindingFlags.InvokeMethod,
  238. null,
  239. ComInstance, // 调用的COM组件
  240. ParamArray, // 参数数组
  241. ParamMods, // 指定返回参数的ParameterModifier数组
  242. null,
  243. null);
  244. OutPut = ParamArray[0].ToString();
  245. MessageBox.Show("Open输出:" + OutPut);
  246. return;
  247. }
  248. catch (Exception ex)
  249. {
  250. OutPut = ex.Message;
  251. MessageBox.Show("COM加载异常!" + OutPut);
  252. return;
  253. }
  254. }
  255. public void Close(System.Type ComType, object ComInstance, out string OutPut)
  256. {
  257. try
  258. {
  259. if (ComInstance == null)
  260. {
  261. OutPut = "实例不存在!";
  262. return;
  263. }
  264. //GlobalVariables.writeLog("入参infno:" + infno);
  265. //GlobalVariables.writeLog("入参input:" + input);
  266. //设置需要设置的参数值
  267. object[] ParamArray = new object[1];
  268. ParamArray[0] = "";
  269. //ParamArray[1] = input;
  270. ParameterModifier[] ParamMods = new ParameterModifier[1];
  271. ParamMods[0] = new ParameterModifier(1); // 初始化为接口参数的个数
  272. ParamMods[0][0] = true;
  273. ComType.InvokeMember("close", // 接口函数名
  274. BindingFlags.Default | BindingFlags.InvokeMethod,
  275. null,
  276. ComInstance, // 调用的COM组件
  277. ParamArray, // 参数数组
  278. ParamMods, // 指定返回参数的ParameterModifier数组
  279. null,
  280. null);
  281. OutPut = ParamArray[0].ToString();
  282. MessageBox.Show("Close输出:" + OutPut);
  283. return;
  284. }
  285. catch (Exception ex)
  286. {
  287. OutPut = ex.Message;
  288. MessageBox.Show("COM加载异常!" + OutPut);
  289. return;
  290. }
  291. }
  292. public void ReadCardObj(string FunName, string Input, System.Type ComType, object ComInstance, out string OutPut)
  293. {
  294. try
  295. {
  296. if (ComInstance == null)
  297. {
  298. OutPut = "实例不存在!";
  299. return;
  300. }
  301. //GlobalVariables.writeLog("入参infno:" + infno);
  302. //GlobalVariables.writeLog("入参input:" + input);
  303. //设置需要设置的参数值
  304. object[] ParamArray = new object[2];
  305. ParamArray[0] = Input;
  306. ParamArray[1] = Input;
  307. ParameterModifier[] ParamMods = new ParameterModifier[1];
  308. ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
  309. ParamMods[0][0] = true;
  310. ParamMods[0][1] = true;
  311. ComType.InvokeMember(FunName, // 接口函数名
  312. BindingFlags.Default | BindingFlags.InvokeMethod,
  313. null,
  314. ComInstance, // 调用的COM组件
  315. ParamArray, // 参数数组
  316. ParamMods, // 指定返回参数的ParameterModifier数组
  317. null,
  318. null);
  319. OutPut = ParamArray[1].ToString();
  320. return;
  321. }
  322. catch (Exception ex)
  323. {
  324. OutPut = ex.Message;
  325. MessageBox.Show("COM加载异常!" + OutPut);
  326. return;
  327. }
  328. }
  329. public void BussniessObj(string FunName, string input, out string output)
  330. {
  331. output = "";
  332. try
  333. {
  334. Type ComType = System.Type.GetTypeFromProgID("MedicareCom.Outpatient");
  335. if (ComType != null)
  336. {
  337. //创建实例,不能再次创建,否则会提示没有初始化
  338. object ComInstance = System.Activator.CreateInstance(ComType);
  339. if (ComInstance != null)
  340. {
  341. MessageBox.Show(("函数FunName:" + FunName + "\n"
  342. + "入参:" + input));
  343. }
  344. else
  345. {
  346. output = "实例不存在!";
  347. return;
  348. }
  349. //GlobalVariables.writeLog("入参infno:" + infno);
  350. //GlobalVariables.writeLog("入参input:" + input);
  351. //设置需要设置的参数值
  352. object[] ParamArray = new object[2];
  353. ParamArray[0] = input;
  354. ParamArray[1] = input;
  355. ParameterModifier[] ParamMods = new ParameterModifier[1];
  356. ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
  357. ParamMods[0][0] = true;
  358. ParamMods[0][1] = true;
  359. ComType.InvokeMember(FunName, // 接口函数名
  360. BindingFlags.Default | BindingFlags.InvokeMethod,
  361. null,
  362. ComInstance, // 调用的COM组件
  363. ParamArray, // 参数数组
  364. ParamMods, // 指定返回参数的ParameterModifier数组
  365. null,
  366. null);
  367. output = ParamArray[1].ToString();
  368. }
  369. else
  370. {
  371. output = "北京首信医保COM加载失败!";
  372. //MessageBox.Show("COM加载失败!");
  373. }
  374. }
  375. catch (Exception ex)
  376. {
  377. output = ex.Message;
  378. MessageBox.Show("COM加载异常!" + output);
  379. }
  380. }
  381. }
  382. }