123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- using ADODB;
- using System;
- using System.Windows.Forms;
- using ZLPlugin_MR.Model;
- namespace ZLPlugin_MR.Domain.Units
- {
- public class Tools
- {
- 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;
- /// <summary>
- /// 查询
- /// </summary>
- /// <param name="sql"></param>
- /// <param name="rs"></param>
- 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;
- }
- /// <summary>
- /// 得到json,无子数组
- /// </summary>
- /// <param name="rd"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 得到保存前的医嘱json
- /// </summary>
- /// <param name="rd"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 防止卡顿,程序等待
- /// </summary>
- /// <param name="mm"></param>
- 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;
- }
- }
- }
- }
|