Tools.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. if (rd.Fields[j].Name== "附项")
  146. {
  147. value += "\"" + rd.Fields[j].Name + "\":null,";
  148. }
  149. else
  150. {
  151. value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
  152. }
  153. }
  154. }
  155. value = value.Substring(0, value.Length - 1);
  156. value += "},";
  157. rd.MoveNext();
  158. }
  159. value = value.Substring(0, value.Length - 1);
  160. value += "]";
  161. }
  162. return value;
  163. }
  164. public static string RecordsetToJson(Recordset rd)
  165. {
  166. string value = "";
  167. if (rd.RecordCount > 0)
  168. {
  169. //value = "[";
  170. for (var i = 0; i < rd.RecordCount; i++)
  171. {
  172. value += "{";
  173. for (var j = 0; j < rd.Fields.Count; j++)
  174. {
  175. value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
  176. //object obj = rd.Fields[j].Value;
  177. //string val = obj.ToString().Trim();
  178. //if (val == "")
  179. //{
  180. // value += "\"" + rd.Fields[j].Name + "\":null,";
  181. //}
  182. //else
  183. //{
  184. // value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
  185. //}
  186. }
  187. value = value.Substring(0, value.Length - 1);
  188. value += "},";
  189. //rd.MoveNext();
  190. }
  191. value = value.Substring(0, value.Length - 1);
  192. //value += "]";
  193. }
  194. return value;
  195. }
  196. /// <summary>
  197. /// 防止卡顿,程序等待
  198. /// </summary>
  199. /// <param name="mm"></param>
  200. public static void Delay(int mm, int sate = 1)
  201. {
  202. DateTime current = DateTime.Now;
  203. while (current.AddMilliseconds(mm) > DateTime.Now)
  204. {
  205. if (!string.IsNullOrWhiteSpace(SocketClient.Message))
  206. {
  207. return;
  208. }
  209. if (sate == 1)
  210. {
  211. Application.DoEvents();
  212. }
  213. }
  214. }
  215. public static bool MutualRecognition(Results result, out string message)
  216. {
  217. message = "";
  218. if (result.ResultText[0].State == "0")
  219. {
  220. return true;
  221. }
  222. else//互认
  223. {
  224. var LIS = result.ResultText[0].LIS;
  225. var PACS = result.ResultText[0].PACS;
  226. if (LIS != null && PACS == null)
  227. {
  228. message = "已互认检验结果[";
  229. for (int i = 0; i < result.ResultText[0].LIS.Count; i++)
  230. {
  231. message += result.ResultText[0].LIS[i].ReportName + ",";
  232. }
  233. message = message.Substring(0, message.Length - 1);
  234. message += "],不允许重复检验,请删除或调整相关项目后再保存!";
  235. }
  236. else if (PACS != null && LIS == null)
  237. {
  238. message = "已互认检查结果[";
  239. for (int i = 0; i < result.ResultText[0].PACS.Count; i++)
  240. {
  241. message += result.ResultText[0].PACS[i].ItemName + ",";
  242. }
  243. message = message.Substring(0, message.Length - 1);
  244. message += "],不允许重复检查,请删除或调整相关项目后再保存!";
  245. }
  246. else if (PACS != null && LIS != null)
  247. {
  248. message = "已互认检验结果[";
  249. for (int i = 0; i < result.ResultText[0].LIS.Count; i++)
  250. {
  251. message += result.ResultText[0].LIS[i].ReportName + ",";
  252. }
  253. message = message.Substring(0, message.Length - 1);
  254. message += "],检查结果[";
  255. for (int i = 0; i < result.ResultText[0].PACS.Count; i++)
  256. {
  257. message += result.ResultText[0].PACS[i].ItemName + ",";
  258. }
  259. message = message.Substring(0, message.Length - 1);
  260. message += "],不允许重复检验检查,请删除或调整相关项目后再保存!";
  261. }
  262. return false;
  263. }
  264. }
  265. }
  266. }