ObjectClass.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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 PTMedicalInsurance.Variables;
  15. using PTMedicalInsurance.Helper;
  16. using Newtonsoft.Json.Linq;
  17. using Newtonsoft.Json;
  18. using System.Runtime.InteropServices;
  19. using MedicareComLib;
  20. namespace PTMedicalInsurance
  21. {
  22. public class ResourceHolder : IDisposable
  23. {
  24. private bool disposed = false;
  25. // 假设这是一个非托管资源
  26. private IntPtr unmanagedResource;
  27. public ResourceHolder()
  28. {
  29. // 获取非托管资源
  30. this.unmanagedResource = GetUnmanagedResource();
  31. }
  32. public void Dispose()
  33. {
  34. Dispose(true);
  35. GC.SuppressFinalize(this);
  36. }
  37. protected virtual void Dispose(bool disposing)
  38. {
  39. if (!disposed)
  40. {
  41. if (disposing)
  42. {
  43. // 释放托管资源
  44. }
  45. // 释放非托管资源
  46. ReleaseUnmanagedResource(this.unmanagedResource);
  47. this.unmanagedResource = IntPtr.Zero;
  48. }
  49. disposed = true;
  50. }
  51. ~ResourceHolder()
  52. {
  53. Dispose(false);
  54. }
  55. // 假设的非托管资源获取方法
  56. private IntPtr GetUnmanagedResource()
  57. {
  58. // 获取非托管资源的代码
  59. return IntPtr.Zero;
  60. }
  61. // 假设的非托管资源释放方法
  62. private void ReleaseUnmanagedResource(IntPtr resource)
  63. {
  64. // 释放非托管资源的代码
  65. }
  66. }
  67. class SaveLogInData
  68. {
  69. /// <summary>
  70. /// 保存中心交易日志到数据库
  71. /// </summary>
  72. /// <param name="inParam"></param>
  73. /// <param name="outParam"></param>
  74. /// <param name="inParamPlain"></param>
  75. /// <param name="outParamPlain"></param>
  76. private void saveCenterLog(string inParam, string outParam, string inParamPlain, string outParamPlain)
  77. {
  78. dynamic joIris = new JObject();
  79. string sRtn = "";
  80. try
  81. {
  82. //解析postContent,插入医保交易日志表
  83. JArray jaParams = new JArray();
  84. JObject joParam = new JObject();
  85. joParam.Add("inParam", inParam);
  86. joParam.Add("outParam", outParam);
  87. joParam.Add("inParamPlain", inParamPlain);
  88. joParam.Add("outParamPlain", outParamPlain);
  89. joParam.Add("HospitalDr", Global.inf.hospitalDr);
  90. joParam.Add("InterfaceDr", Global.inf.interfaceDr);
  91. joParam.Add("updateUserID", Global.user.ID);
  92. joParam.Add("psn_no", Global.pat.psn_no);
  93. jaParams.Add(joParam);
  94. joIris.code = "09010021";
  95. joIris.Add("params", jaParams);
  96. InvokeHelper invoker = new InvokeHelper();
  97. sRtn = invoker.invokeInsuService(joIris.ToString(), "保存日志到数据库").ToString();
  98. }
  99. catch (Exception ex)
  100. {
  101. sRtn = JsonHelper.setExceptionJson(-100, "保存日志异常", ex.Message).ToString();
  102. Global.writeLog_Iris("保存日志异常:" + sRtn.ToString());
  103. }
  104. }
  105. }
  106. class ReadCardClass
  107. {
  108. OutpatientClass ShouXinObj = new OutpatientClass();
  109. //释放资源方法一
  110. public static void ReleaseComObject(object obj)
  111. {
  112. while ((Marshal.ReleaseComObject(obj)) > 0) ;
  113. }
  114. //释放资源方法二
  115. public static void ReleaseComObject2(object obj)
  116. {
  117. int result = 0;
  118. do
  119. {
  120. result = Marshal.ReleaseComObject(obj);
  121. } while (result > 0);
  122. // 将引用设置为null
  123. obj = null;
  124. }
  125. //释放资源方法三
  126. public static void ReleaseComObject3(object obj)
  127. {
  128. int result = 0;
  129. do
  130. {
  131. result = Marshal.FinalReleaseComObject(obj);
  132. } while (result > 0);
  133. // 将引用设置为null
  134. obj = null;
  135. }
  136. public class ResourceHolder : IDisposable
  137. {
  138. private bool disposed = false; // 用于跟踪资源是否已经被释放
  139. // 实现 IDisposable 接口
  140. public void Dispose()
  141. {
  142. Dispose(true);
  143. GC.SuppressFinalize(this); // 防止垃圾回收器再次调用析构函数
  144. }
  145. protected virtual void Dispose(bool disposing)
  146. {
  147. if (!disposed)
  148. {
  149. if (disposing)
  150. {
  151. // 释放托管资源
  152. }
  153. // 释放非托管资源
  154. disposed = true;
  155. }
  156. }
  157. ~ResourceHolder()
  158. {
  159. Dispose(false);
  160. }
  161. // 其他对象方法
  162. }
  163. public int CreateBusinessObj(out System.Type OutComType,out object OutComInstance)
  164. {
  165. string rtn = "";
  166. string progID = "MedicareCom.Outpatient";
  167. OutComType = null;
  168. OutComInstance = "";
  169. try
  170. {
  171. OutComType = Type.GetTypeFromProgID(progID);
  172. // 创建Com的实例
  173. if (OutComType != null)
  174. {
  175. //创建实例
  176. OutComInstance = Activator.CreateInstance(OutComType);
  177. rtn = "成功";
  178. return 0;
  179. }
  180. else
  181. {
  182. rtn = "失败";
  183. return -1;
  184. }
  185. }
  186. catch (Exception ex)
  187. {
  188. rtn = "失败" + ",COM加载异常" + ex.Message;
  189. return -1;
  190. }
  191. finally
  192. {
  193. Global.writeLog("GetReadCardObj", "", "创建实例" + rtn);
  194. }
  195. }
  196. public void Open(System.Type ComType, object ComInstance,out string OutPut)
  197. {
  198. OutPut = "";
  199. try
  200. {
  201. if (ComInstance == null)
  202. {
  203. OutPut = "实例不存在!";
  204. return;
  205. }
  206. //设置需要设置的参数值
  207. object[] ParamArray = new object[1];
  208. ParamArray[0] = "";
  209. //ParamArray[1] = input;
  210. ParameterModifier[] ParamMods = new ParameterModifier[1];
  211. ParamMods[0] = new ParameterModifier(1); // 初始化为接口参数的个数
  212. ParamMods[0][0] = true;
  213. ComType.InvokeMember("open", // 接口函数名
  214. BindingFlags.Default | BindingFlags.InvokeMethod,
  215. null,
  216. ComInstance, // 调用的COM组件
  217. ParamArray, // 参数数组
  218. ParamMods, // 指定返回参数的ParameterModifier数组
  219. null,
  220. null);
  221. OutPut = ParamArray[0].ToString();
  222. //MessageBox.Show("Com输出:" + OutPut);
  223. return;
  224. }
  225. catch (Exception ex)
  226. {
  227. OutPut = ex.Message;
  228. MessageBox.Show("COM加载异常!" + OutPut);
  229. return;
  230. }
  231. finally
  232. {
  233. Global.writeLog("Open", "", OutPut);
  234. //this.saveCenterLog("", OutPut, "", OutPut);
  235. }
  236. }
  237. public void Close(System.Type ComType, object ComInstance, out string OutPut)
  238. {
  239. OutPut = "";
  240. try
  241. {
  242. if (ComInstance == null)
  243. {
  244. OutPut = "实例不存在!";
  245. return;
  246. }
  247. //GlobalVariables.writeLog("入参infno:" + infno);
  248. //GlobalVariables.writeLog("入参input:" + input);
  249. //设置需要设置的参数值
  250. object[] ParamArray = new object[1];
  251. ParamArray[0] = "";
  252. //ParamArray[1] = input;
  253. ParameterModifier[] ParamMods = new ParameterModifier[1];
  254. ParamMods[0] = new ParameterModifier(1); // 初始化为接口参数的个数
  255. ParamMods[0][0] = true;
  256. ComType.InvokeMember("close", // 接口函数名
  257. BindingFlags.Default | BindingFlags.InvokeMethod,
  258. null,
  259. ComInstance, // 调用的COM组件
  260. ParamArray, // 参数数组
  261. ParamMods, // 指定返回参数的ParameterModifier数组
  262. null,
  263. null);
  264. OutPut = ParamArray[0].ToString();
  265. //MessageBox.Show("Com输出:" + OutPut);
  266. return;
  267. }
  268. catch (Exception ex)
  269. {
  270. OutPut = ex.Message;
  271. MessageBox.Show("COM加载异常!" + OutPut);
  272. return;
  273. }
  274. finally
  275. {
  276. Global.writeLog("Close", "", OutPut);
  277. // 释放资源
  278. (ComInstance as IDisposable)?.Dispose();
  279. GC.Collect();
  280. if (ComInstance is IDisposable disposable)
  281. {
  282. disposable.Dispose();
  283. }
  284. //GC.Collect();
  285. ////ReleaseComObject(ComInstance);
  286. ////ReleaseComObject2(ComInstance);
  287. //ReleaseComObject3(ComInstance);
  288. ////ReleaseComObject3(ComType);
  289. ComInstance = null;
  290. ComType = null;
  291. }
  292. }
  293. public void ReadCardObj(string FunName, string Input, System.Type ComType, object ComInstance, out string OutPut)
  294. {
  295. OutPut = "";
  296. try
  297. {
  298. if (ComInstance == null)
  299. {
  300. OutPut = "实例不存在!";
  301. return;
  302. }
  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. finally
  329. {
  330. Global.writeLog(FunName, Input, OutPut);
  331. }
  332. }
  333. public void BussniessObj(string FunName, string Input, System.Type ComType, object ComInstance, out string OutPut)
  334. {
  335. OutPut = "";
  336. try
  337. {
  338. if (ComInstance == null)
  339. {
  340. OutPut = "实例不存在!";
  341. return;
  342. }
  343. //设置需要设置的参数值
  344. object[] ParamArray = new object[2];
  345. ParamArray[0] = Input;
  346. ParamArray[1] = Input;
  347. ParameterModifier[] ParamMods = new ParameterModifier[1];
  348. ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
  349. ParamMods[0][0] = true;
  350. ParamMods[0][1] = true;
  351. ComType.InvokeMember(FunName, // 接口函数名
  352. BindingFlags.Default | BindingFlags.InvokeMethod,
  353. null,
  354. ComInstance, // 调用的COM组件
  355. ParamArray, // 参数数组
  356. ParamMods, // 指定返回参数的ParameterModifier数组
  357. null,
  358. null);
  359. OutPut = ParamArray[1].ToString();
  360. return;
  361. }
  362. catch (Exception ex)
  363. {
  364. OutPut = ex.Message;
  365. MessageBox.Show("COM加载异常!" + OutPut);
  366. return;
  367. }
  368. finally
  369. {
  370. Global.writeLog(FunName, Input, OutPut);
  371. this.saveCenterLog(Input, OutPut, Input, OutPut);
  372. }
  373. }
  374. public void Trade(System.Type ComType, object ComInstance, out string OutPut)
  375. {
  376. OutPut = "";
  377. try
  378. {
  379. if (ComInstance == null)
  380. {
  381. OutPut = "实例不存在!";
  382. return;
  383. }
  384. //设置需要设置的参数值
  385. object[] ParamArray = new object[1];
  386. ParamArray[0] = "";
  387. //ParamArray[1] = input;
  388. ParameterModifier[] ParamMods = new ParameterModifier[1];
  389. ParamMods[0] = new ParameterModifier(1); // 初始化为接口参数的个数
  390. ParamMods[0][0] = true;
  391. ComType.InvokeMember("Trade", // 接口函数名
  392. BindingFlags.Default | BindingFlags.InvokeMethod,
  393. null,
  394. ComInstance, // 调用的COM组件
  395. ParamArray, // 参数数组
  396. ParamMods, // 指定返回参数的ParameterModifier数组
  397. null,
  398. null);
  399. OutPut = ParamArray[0].ToString();
  400. //MessageBox.Show("Com输出:" + OutPut);
  401. return;
  402. }
  403. catch (Exception ex)
  404. {
  405. OutPut = ex.Message;
  406. MessageBox.Show("COM加载异常!" + OutPut);
  407. return;
  408. }
  409. finally
  410. {
  411. Global.writeLog("Trade", "", OutPut);
  412. }
  413. }
  414. public void TradeAll(System.Type ComType, object ComInstance, out string OutPut)
  415. {
  416. OutPut = "";
  417. try
  418. {
  419. if (ComInstance == null)
  420. {
  421. OutPut = "实例不存在!";
  422. return;
  423. }
  424. //设置需要设置的参数值
  425. object[] ParamArray = new object[1];
  426. ParamArray[0] = "";
  427. //ParamArray[1] = input;
  428. ParameterModifier[] ParamMods = new ParameterModifier[1];
  429. ParamMods[0] = new ParameterModifier(1); // 初始化为接口参数的个数
  430. ParamMods[0][0] = true;
  431. ComType.InvokeMember("TradeAll", // 接口函数名
  432. BindingFlags.Default | BindingFlags.InvokeMethod,
  433. null,
  434. ComInstance, // 调用的COM组件
  435. ParamArray, // 参数数组
  436. ParamMods, // 指定返回参数的ParameterModifier数组
  437. null,
  438. null);
  439. OutPut = ParamArray[0].ToString();
  440. return;
  441. }
  442. catch (Exception ex)
  443. {
  444. OutPut = ex.Message;
  445. MessageBox.Show("COM加载异常!" + OutPut);
  446. return;
  447. }
  448. finally
  449. {
  450. Global.writeLog("TradeAll", "", OutPut);
  451. //this.saveCenterLog("", OutPut, "", OutPut);
  452. }
  453. }
  454. public void Open(out string OutPut)
  455. {
  456. OutPut = "";
  457. try
  458. {
  459. ShouXinObj.Open(out OutPut);
  460. return;
  461. }
  462. catch (Exception ex)
  463. {
  464. OutPut = ex.Message;
  465. MessageBox.Show("Open加载异常!" + OutPut);
  466. return;
  467. }
  468. finally
  469. {
  470. Global.writeLog("Open", "", OutPut);
  471. //this.saveCenterLog("", OutPut, "", OutPut);
  472. }
  473. }
  474. public void Close(out string OutPut)
  475. {
  476. OutPut = "";
  477. try
  478. {
  479. ShouXinObj.Close(out OutPut);
  480. return;
  481. }
  482. catch (Exception ex)
  483. {
  484. OutPut = ex.Message;
  485. MessageBox.Show("Close加载异常!" + OutPut);
  486. return;
  487. }
  488. finally
  489. {
  490. ShouXinObj = null;
  491. Global.writeLog("Close", "", OutPut);
  492. //this.saveCenterLog("", OutPut, "", OutPut);
  493. }
  494. }
  495. public void GetPersonInfo(out string OutPut)
  496. {
  497. OutPut = "";
  498. try
  499. {
  500. ShouXinObj.GetPersonInfo(out OutPut);
  501. return;
  502. }
  503. catch (Exception ex)
  504. {
  505. OutPut = ex.Message;
  506. MessageBox.Show("GetPersonInfo加载异常!" + OutPut);
  507. return;
  508. }
  509. finally
  510. {
  511. Global.writeLog("GetPersonInfo", "", OutPut);
  512. //this.saveCenterLog("", OutPut, "", OutPut);
  513. }
  514. }
  515. /// <summary>
  516. /// 保存中心交易日志到数据库
  517. /// </summary>
  518. /// <param name="inParam"></param>
  519. /// <param name="outParam"></param>
  520. /// <param name="inParamPlain"></param>
  521. /// <param name="outParamPlain"></param>
  522. private void saveCenterLog(string inParam, string outParam, string inParamPlain, string outParamPlain)
  523. {
  524. dynamic joIris = new JObject();
  525. string sRtn = "";
  526. try
  527. {
  528. //解析postContent,插入医保交易日志表
  529. JArray jaParams = new JArray();
  530. JObject joParam = new JObject();
  531. joParam.Add("inParam", inParam);
  532. joParam.Add("outParam", outParam);
  533. joParam.Add("inParamPlain", inParamPlain);
  534. joParam.Add("outParamPlain", outParamPlain);
  535. joParam.Add("HospitalDr", Global.inf.hospitalDr);
  536. joParam.Add("InterfaceDr", Global.inf.interfaceDr);
  537. joParam.Add("updateUserID", Global.user.ID);
  538. joParam.Add("psn_no", Global.pat.psn_no);
  539. jaParams.Add(joParam);
  540. joIris.code = "09010021";
  541. joIris.Add("params", jaParams);
  542. InvokeHelper invoker = new InvokeHelper();
  543. sRtn = invoker.invokeInsuService(joIris.ToString(), "保存日志到数据库").ToString();
  544. }
  545. catch (Exception ex)
  546. {
  547. sRtn = JsonHelper.setExceptionJson(-100, "保存日志异常", ex.Message).ToString();
  548. Global.writeLog_Iris("保存日志异常:" + sRtn.ToString());
  549. }
  550. }
  551. }
  552. class MedOrdersShareClass
  553. {
  554. public int GetMedOrdersShareObj(out System.Type OutComType, out object OutComInstance)
  555. {
  556. Object rtnObj = "";
  557. string progID = "EachCommunicationCom.Outpatient";
  558. System.Type ComType;
  559. object ComInstance;
  560. ComType = Type.GetTypeFromProgID(progID);
  561. // 创建Com的实例
  562. if (ComType != null)
  563. {
  564. //创建实例
  565. ComInstance = Activator.CreateInstance(ComType);
  566. OutComType = ComType;
  567. OutComInstance = ComInstance;
  568. return 0;
  569. }
  570. else
  571. {
  572. OutComType = null;
  573. OutComInstance = "";
  574. return -1;
  575. }
  576. }
  577. public void ConnectServer(System.Type ComType, object ComInstance, out string OutPut)
  578. {
  579. OutPut = "";
  580. try
  581. {
  582. if (ComInstance == null)
  583. {
  584. OutPut = "实例不存在!";
  585. return;
  586. }
  587. //GlobalVariables.writeLog("入参infno:" + infno);
  588. //GlobalVariables.writeLog("入参input:" + input);
  589. //设置需要设置的参数值
  590. object[] ParamArray = new object[1];
  591. ParamArray[0] = "";
  592. //ParamArray[1] = input;
  593. ParameterModifier[] ParamMods = new ParameterModifier[1];
  594. ParamMods[0] = new ParameterModifier(1); // 初始化为接口参数的个数
  595. ParamMods[0][0] = true;
  596. ComType.InvokeMember("ConnectServer", // 接口函数名
  597. BindingFlags.Default | BindingFlags.InvokeMethod,
  598. null,
  599. ComInstance, // 调用的COM组件
  600. ParamArray, // 参数数组
  601. ParamMods, // 指定返回参数的ParameterModifier数组
  602. null,
  603. null);
  604. OutPut = ParamArray[0].ToString();
  605. //MessageBox.Show("ConnectServer输出:" + OutPut);
  606. return;
  607. }
  608. catch (Exception ex)
  609. {
  610. OutPut = ex.Message;
  611. //MessageBox.Show("COM加载异常!" + OutPut);
  612. return;
  613. }
  614. finally
  615. {
  616. Global.writeLog("ConnectServer", "", OutPut);
  617. }
  618. }
  619. public void MedOrdersShareObj(string FunName, string Input, System.Type ComType, object ComInstance, out string OutPut)
  620. {
  621. OutPut = "";
  622. try
  623. {
  624. if (ComInstance == null)
  625. {
  626. OutPut = "实例不存在!";
  627. return;
  628. }
  629. //GlobalVariables.writeLog("入参infno:" + infno);
  630. //GlobalVariables.writeLog("入参input:" + input);
  631. //设置需要设置的参数值
  632. object[] ParamArray = new object[2];
  633. ParamArray[0] = Input;
  634. ParamArray[1] = Input;
  635. ParameterModifier[] ParamMods = new ParameterModifier[1];
  636. ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
  637. ParamMods[0][0] = true;
  638. ParamMods[0][1] = true;
  639. ComType.InvokeMember(FunName, // 接口函数名
  640. BindingFlags.Default | BindingFlags.InvokeMethod,
  641. null,
  642. ComInstance, // 调用的COM组件
  643. ParamArray, // 参数数组
  644. ParamMods, // 指定返回参数的ParameterModifier数组
  645. null,
  646. null);
  647. OutPut = ParamArray[1].ToString();
  648. return;
  649. }
  650. catch (Exception ex)
  651. {
  652. OutPut = ex.Message;
  653. MessageBox.Show("COM加载异常!" + OutPut);
  654. return;
  655. }
  656. finally
  657. {
  658. Global.writeLog(FunName, Input, OutPut);
  659. }
  660. }
  661. }
  662. }