Tools.cs 10 KB

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