Tools.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. using ADODB;
  2. using System;
  3. using System.Net;
  4. using System.Net.Sockets;
  5. using System.Windows.Forms;
  6. using ZLPlugin_MR.Model;
  7. namespace ZLPlugin_MR.Domain.Units
  8. {
  9. public class Tools
  10. {
  11. public static string GetHostIp()
  12. {
  13. string hostName = Dns.GetHostName();
  14. IPHostEntry ipHostInfo = Dns.GetHostEntry(hostName);
  15. IPAddress[] ipAddresses = ipHostInfo.AddressList;
  16. foreach (IPAddress ip in ipAddresses)
  17. {
  18. if (ip.AddressFamily == AddressFamily.InterNetwork)
  19. {
  20. Console.WriteLine("本机 IP 地址:" + ip);
  21. return ip.ToString();
  22. }
  23. }
  24. return hostName;
  25. }
  26. public static string FormatStr(string str)
  27. {
  28. return str.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  29. }
  30. public static string ReplaceString(string str)
  31. {
  32. return str.Replace("\\", "\\\\").Replace("\"", "\\\"");
  33. }
  34. public static Connection Connection;
  35. /// <summary>
  36. /// 查询
  37. /// </summary>
  38. /// <param name="sql"></param>
  39. /// <param name="rs"></param>
  40. public static void QueryTable(string sql, out Recordset rs)
  41. {
  42. rs = new Recordset();
  43. try
  44. {
  45. rs.Open(sql, Connection, CursorTypeEnum.adOpenKeyset, LockTypeEnum.adLockOptimistic, (int)CommandTypeEnum.adCmdText);
  46. }
  47. catch (Exception ex)
  48. {
  49. Log.Info(ex.Message, true);
  50. Log.Info("出错sql为:" + sql, true);
  51. }
  52. }
  53. public static int ExecuteSql(string sql)
  54. {
  55. int result = 1;
  56. try
  57. {
  58. object missing = System.Reflection.Missing.Value;
  59. Command Command = new Command();
  60. Command.ActiveConnection = Connection;
  61. Command.CommandText = sql;
  62. Command.Execute(out missing, ref missing, (int)CommandTypeEnum.adCmdText);
  63. }
  64. catch (Exception ex)
  65. {
  66. result = 0;
  67. Connection.Close();
  68. Log.Info(ex.Message, true);
  69. Log.Info(ex.StackTrace, true);
  70. }
  71. return result;
  72. }
  73. public static int ExecuteStoredProc(long 病人id, long 主医嘱id, string json, int lis, int pacs)
  74. {
  75. Log.Info(病人id +"|"+ 主医嘱id + "|" + json + "|" + lis+"33");
  76. int result = 1;
  77. try
  78. {
  79. int? isNull = null;
  80. object missing = System.Reflection.Missing.Value;
  81. Command command = new Command();
  82. //command.CommandTimeout = 200;
  83. //Connection.Open();
  84. // Connection.ConnectionString();
  85. command.ActiveConnection = Connection;
  86. Log.Info("111 Connection 111" + Connection.State);
  87. Log.Info("111 Connection 111" + command.State);
  88. command.CommandText = "Zl_医嘱作废_一张纸互认";
  89. command.CommandType = CommandTypeEnum.adCmdStoredProc;
  90. Log.Info("ExecuteStoredProc qq");
  91. Parameter par_br = command.CreateParameter("病人id_In", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 18, 病人id);
  92. Log.Info("ExecuteStoredProc 1199");
  93. command.Parameters.Append(par_br);
  94. Log.Info("ExecuteStoredProc ww");
  95. Parameter par_yz = command.CreateParameter("主医嘱id_In", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 18, 主医嘱id);
  96. command.Parameters.Append(par_yz);
  97. Log.Info("ExecuteStoredProc 444");
  98. // 创建CLOB参数
  99. Parameter par_json = command.CreateParameter("Json_In", DataTypeEnum.adLongVarChar, ParameterDirectionEnum.adParamInput, 3000, json);
  100. command.Parameters.Append(par_json);
  101. Log.Info("ExecuteStoredProc q");
  102. Parameter par_pacs = command.CreateParameter("检查消息_In", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 1, pacs == 1 ? 1 : isNull);
  103. command.Parameters.Append(par_pacs);
  104. Log.Info("ExecuteStoredProc w");
  105. Parameter par_lis = command.CreateParameter("检验消息_In", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 1, lis == 1 ? 1 : isNull);
  106. command.Parameters.Append(par_lis);
  107. Log.Info("ExecuteStoredProc e");
  108. Parameter par_state = command.CreateParameter("state", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamOutput, 1);
  109. command.Parameters.Append(par_state);
  110. Log.Info("ExecuteStoredProc r");
  111. Log.Info("ExecuteStoredProc 11");
  112. Recordset recordset = command.Execute(out missing, ref missing);// , (int)CommandTypeEnum.adCmdStoredProc
  113. Log.Info("ExecuteStoredProc");
  114. Log.Info((string)missing);
  115. }
  116. catch (Exception ex)
  117. {
  118. Log.Info(ex.Message);
  119. Log.Info(ex.StackTrace);
  120. Log.Info(ex.InnerException.ToString());
  121. result = 0;
  122. Connection.Close();
  123. }
  124. return result;
  125. }
  126. /// <summary>
  127. /// 得到json,无子数组
  128. /// </summary>
  129. /// <param name="rd"></param>
  130. /// <returns></returns>
  131. public static string GetJsonData(Recordset rd)
  132. {
  133. string value = "{";
  134. for (var i = 0; i < rd.RecordCount; i++)
  135. {
  136. for (var j = 0; j < rd.Fields.Count; j++)
  137. {
  138. object obj = rd.Fields[j].Value;
  139. string val = obj.ToString().Trim();
  140. if (val == "")
  141. {
  142. value += "\"" + rd.Fields[j].Name + "\":null,";
  143. }
  144. else
  145. {
  146. value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
  147. }
  148. }
  149. rd.MoveNext();
  150. }
  151. value = value.Substring(0, value.Length - 1);
  152. value += "}";
  153. return value;
  154. }
  155. /// <summary>
  156. /// 得到保存前的医嘱json
  157. /// </summary>
  158. /// <param name="rd"></param>
  159. /// <returns></returns>
  160. public static string GetAdviceSaveData(Recordset rd)
  161. {
  162. string value = "";
  163. if (rd.RecordCount > 0)
  164. {
  165. value = "[";
  166. for (var i = 0; i < rd.RecordCount; i++)
  167. {
  168. value += "{";
  169. for (var j = 0; j < rd.Fields.Count; j++)
  170. {
  171. object obj = rd.Fields[j].Value;
  172. string val = obj.ToString().Trim();
  173. if (val == "")
  174. {
  175. value += "\"" + rd.Fields[j].Name + "\":null,";
  176. }
  177. else
  178. {
  179. value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
  180. }
  181. }
  182. value = value.Substring(0, value.Length - 1);
  183. value += "},";
  184. rd.MoveNext();
  185. }
  186. value = value.Substring(0, value.Length - 1);
  187. value += "]";
  188. }
  189. return value;
  190. }
  191. public static string RecordsetToJson(Recordset rd)
  192. {
  193. string value = "";
  194. if (rd.RecordCount > 0)
  195. {
  196. //value = "[";
  197. for (var i = 0; i < rd.RecordCount; i++)
  198. {
  199. value += "{";
  200. for (var j = 0; j < rd.Fields.Count; j++)
  201. {
  202. value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
  203. //object obj = rd.Fields[j].Value;
  204. //string val = obj.ToString().Trim();
  205. //if (val == "")
  206. //{
  207. // value += "\"" + rd.Fields[j].Name + "\":null,";
  208. //}
  209. //else
  210. //{
  211. // value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
  212. //}
  213. }
  214. value = value.Substring(0, value.Length - 1);
  215. value += "},";
  216. //rd.MoveNext();
  217. }
  218. value = value.Substring(0, value.Length - 1);
  219. //value += "]";
  220. }
  221. return value;
  222. }
  223. /// <summary>
  224. /// 防止卡顿,程序等待
  225. /// </summary>
  226. /// <param name="mm"></param>
  227. public static void Delay(int mm, int sate = 1)
  228. {
  229. DateTime current = DateTime.Now;
  230. while (current.AddMilliseconds(mm) > DateTime.Now)
  231. {
  232. if (!string.IsNullOrWhiteSpace(SocketClient.Message))
  233. {
  234. return;
  235. }
  236. if (sate == 1)
  237. {
  238. Application.DoEvents();
  239. }
  240. }
  241. }
  242. public static bool MutualRecognition(Results result, out string message)
  243. {
  244. message = "";
  245. if (result.ResultText[0].State == "0")
  246. {
  247. return true;
  248. }
  249. else//互认
  250. {
  251. var LIS = result.ResultText[0].LIS;
  252. var PACS = result.ResultText[0].PACS;
  253. if (LIS != null && PACS == null)
  254. {
  255. message = "已互认检验结果[";
  256. for (int i = 0; i < result.ResultText[0].LIS.Count; i++)
  257. {
  258. message += result.ResultText[0].LIS[i].ReportName + ",";
  259. }
  260. message = message.Substring(0, message.Length - 1);
  261. message += "],不允许重复检验,请删除或调整相关项目后再保存!";
  262. }
  263. else if (PACS != null && LIS == null)
  264. {
  265. message = "已互认检查结果[";
  266. for (int i = 0; i < result.ResultText[0].PACS.Count; i++)
  267. {
  268. message += result.ResultText[0].PACS[i].ItemName + ",";
  269. }
  270. message = message.Substring(0, message.Length - 1);
  271. message += "],不允许重复检查,请删除或调整相关项目后再保存!";
  272. }
  273. else if (PACS != null && LIS != null)
  274. {
  275. message = "已互认检验结果[";
  276. for (int i = 0; i < result.ResultText[0].LIS.Count; i++)
  277. {
  278. message += result.ResultText[0].LIS[i].ReportName + ",";
  279. }
  280. message = message.Substring(0, message.Length - 1);
  281. message += "],检查结果[";
  282. for (int i = 0; i < result.ResultText[0].PACS.Count; i++)
  283. {
  284. message += result.ResultText[0].PACS[i].ItemName + ",";
  285. }
  286. message = message.Substring(0, message.Length - 1);
  287. message += "],不允许重复检验检查,请删除或调整相关项目后再保存!";
  288. }
  289. return false;
  290. }
  291. }
  292. }
  293. }