Tools.cs 12 KB

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