Tools.cs 11 KB

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