using ADODB; using System; using System.Net; using System.Net.Sockets; using System.Windows.Forms; using ZLPlugin_MR.Model; namespace ZLPlugin_MR.Domain.Units { public class Tools { public static string GetHostIp() { string hostName = Dns.GetHostName(); IPHostEntry ipHostInfo = Dns.GetHostEntry(hostName); IPAddress[] ipAddresses = ipHostInfo.AddressList; foreach (IPAddress ip in ipAddresses) { if (ip.AddressFamily == AddressFamily.InterNetwork) { Console.WriteLine("本机 IP 地址:" + ip); return ip.ToString(); } } return hostName; } public static string FormatStr(string str) { return str.Replace("\n", "").Replace("\t", "").Replace("\r", ""); } public static string ReplaceString(string str) { return str.Replace("\\", "\\\\").Replace("\"", "\\\""); } public static Connection Connection; /// /// 查询 /// /// /// public static void QueryTable(string sql, out Recordset rs) { rs = new Recordset(); try { rs.Open(sql, Connection, CursorTypeEnum.adOpenKeyset, LockTypeEnum.adLockOptimistic, (int)CommandTypeEnum.adCmdText); } catch (Exception ex) { Log.Info(ex.Message, true); Log.Info("出错sql为:" + sql, true); } } public static int ExecuteSql(string sql) { int result = 1; try { object missing = System.Reflection.Missing.Value; Command Command = new Command(); Command.ActiveConnection = Connection; Command.CommandText = sql; Command.Execute(out missing, ref missing, (int)CommandTypeEnum.adCmdText); } catch (Exception ex) { result = 0; Connection.Close(); Log.Info(ex.Message, true); Log.Info(ex.StackTrace, true); } return result; } public static int ExecuteStoredProc(long 病人id, long 主医嘱id, string json, int lis, int pacs) { Log.Info(病人id +"|"+ 主医嘱id + "|" + json + "|" + lis+"33"); int result = 1; try { int? isNull = null; object missing = System.Reflection.Missing.Value; Command command = new Command(); //command.CommandTimeout = 200; //Connection.Open(); // Connection.ConnectionString(); command.ActiveConnection = Connection; Log.Info("111 Connection 111" + Connection.State); Log.Info("111 Connection 111" + command.State); command.CommandText = "Zl_医嘱作废_一张纸互认"; command.CommandType = CommandTypeEnum.adCmdStoredProc; Log.Info("ExecuteStoredProc qq"); Parameter par_br = command.CreateParameter("病人id_In", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 18, 病人id); Log.Info("ExecuteStoredProc 1199"); command.Parameters.Append(par_br); Log.Info("ExecuteStoredProc ww"); Parameter par_yz = command.CreateParameter("主医嘱id_In", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 18, 主医嘱id); command.Parameters.Append(par_yz); Log.Info("ExecuteStoredProc 444"); // 创建CLOB参数 Parameter par_json = command.CreateParameter("Json_In", DataTypeEnum.adLongVarChar, ParameterDirectionEnum.adParamInput, 3000, json); command.Parameters.Append(par_json); Log.Info("ExecuteStoredProc q"); Parameter par_pacs = command.CreateParameter("检查消息_In", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 1, pacs == 1 ? 1 : isNull); command.Parameters.Append(par_pacs); Log.Info("ExecuteStoredProc w"); Parameter par_lis = command.CreateParameter("检验消息_In", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 1, lis == 1 ? 1 : isNull); command.Parameters.Append(par_lis); Log.Info("ExecuteStoredProc e"); Parameter par_state = command.CreateParameter("state", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamOutput, 1); command.Parameters.Append(par_state); Log.Info("ExecuteStoredProc r"); Log.Info("ExecuteStoredProc 11"); Recordset recordset = command.Execute(out missing, ref missing);// , (int)CommandTypeEnum.adCmdStoredProc Log.Info("ExecuteStoredProc"); Log.Info((string)missing); } catch (Exception ex) { Log.Info(ex.Message); Log.Info(ex.StackTrace); Log.Info(ex.InnerException.ToString()); result = 0; Connection.Close(); } return result; } /// /// 得到json,无子数组 /// /// /// public static string GetJsonData(Recordset rd) { string value = "{"; for (var i = 0; i < rd.RecordCount; i++) { for (var j = 0; j < rd.Fields.Count; j++) { object obj = rd.Fields[j].Value; string val = obj.ToString().Trim(); if (val == "") { value += "\"" + rd.Fields[j].Name + "\":null,"; } else { value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\","; } } rd.MoveNext(); } value = value.Substring(0, value.Length - 1); value += "}"; return value; } /// /// 得到保存前的医嘱json /// /// /// public static string GetAdviceSaveData(Recordset rd) { string value = ""; if (rd.RecordCount > 0) { value = "["; for (var i = 0; i < rd.RecordCount; i++) { value += "{"; for (var j = 0; j < rd.Fields.Count; j++) { object obj = rd.Fields[j].Value; string val = obj.ToString().Trim(); if (val == "") { value += "\"" + rd.Fields[j].Name + "\":null,"; } else { value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\","; } } value = value.Substring(0, value.Length - 1); value += "},"; rd.MoveNext(); } value = value.Substring(0, value.Length - 1); value += "]"; } return value; } public static string RecordsetToJson(Recordset rd) { string value = ""; if (rd.RecordCount > 0) { //value = "["; for (var i = 0; i < rd.RecordCount; i++) { value += "{"; for (var j = 0; j < rd.Fields.Count; j++) { value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\","; //object obj = rd.Fields[j].Value; //string val = obj.ToString().Trim(); //if (val == "") //{ // value += "\"" + rd.Fields[j].Name + "\":null,"; //} //else //{ // value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\","; //} } value = value.Substring(0, value.Length - 1); value += "},"; //rd.MoveNext(); } value = value.Substring(0, value.Length - 1); //value += "]"; } return value; } /// /// 防止卡顿,程序等待 /// /// public static void Delay(int mm, int sate = 1) { DateTime current = DateTime.Now; while (current.AddMilliseconds(mm) > DateTime.Now) { if (!string.IsNullOrWhiteSpace(SocketClient.Message)) { return; } if (sate == 1) { Application.DoEvents(); } } } public static bool MutualRecognition(Results result, out string message) { message = ""; if (result.ResultText[0].State == "0") { return true; } else//互认 { var LIS = result.ResultText[0].LIS; var PACS = result.ResultText[0].PACS; if (LIS != null && PACS == null) { message = "已互认检验结果["; for (int i = 0; i < result.ResultText[0].LIS.Count; i++) { message += result.ResultText[0].LIS[i].ReportName + ","; } message = message.Substring(0, message.Length - 1); message += "],不允许重复检验,请删除或调整相关项目后再保存!"; } else if (PACS != null && LIS == null) { message = "已互认检查结果["; for (int i = 0; i < result.ResultText[0].PACS.Count; i++) { message += result.ResultText[0].PACS[i].ItemName + ","; } message = message.Substring(0, message.Length - 1); message += "],不允许重复检查,请删除或调整相关项目后再保存!"; } else if (PACS != null && LIS != null) { message = "已互认检验结果["; for (int i = 0; i < result.ResultText[0].LIS.Count; i++) { message += result.ResultText[0].LIS[i].ReportName + ","; } message = message.Substring(0, message.Length - 1); message += "],检查结果["; for (int i = 0; i < result.ResultText[0].PACS.Count; i++) { message += result.ResultText[0].PACS[i].ItemName + ","; } message = message.Substring(0, message.Length - 1); message += "],不允许重复检验检查,请删除或调整相关项目后再保存!"; } return false; } } } }