/// <summary> /// 将临时记录写入终表 /// </summary> /// <param name="tableName">表名</param> /// <param name="endocscopeSn">内镜编号</param> /// <param name="recordTime">The record time.</param> /// <returns> /// 写入是否成功 /// </returns> public bool RecordTraceData(string tableName, string endocscopeSn, string recordTime) { var endoTemp = new EndoscopeTemp(); SqlTransaction tran = null; object tempobj = null; // 验证isRead是否为null 如果为null说明数据是新数据,如果非null则说明该数据已经记录过 var sql = string.Format("select isRecord from endoscopeTemp where endoscopeSn='{0}'", endocscopeSn); tempobj = SqlHelper.ExecuteScalar(Global.ConnStr, CommandType.Text, sql); // 保证返回数据不为空 if (tempobj == null) { return false; } // 验证isRead是否为null,不为null记录数据失败 if (!string.IsNullOrEmpty(tempobj.ToString())) { return false; } try { // 读取endoscopeTemp数据 endoTemp = this.ReadRecordTemp(endocscopeSn); } catch (Exception ex) { // ReadRecordTemp内部已经记录异常,所以直接抛出 throw ex; } if (endoTemp == null) { return false; } using (var conn = new SqlConnection(Global.ConnStr)) { try { conn.Open(); tran = conn.BeginTransaction(); string insertsql; int result = 0; // 更新endoscopeTemp 的isRead 字段为非null sql = string.Format(@"update endoscopeTemp set isRecord='1' where endoscopeSn='{0}'", endocscopeSn); if (SqlHelper.ExecuteNonQuery(Global.ConnStr, CommandType.Text, sql) <= 0) { tran.Rollback(); return false; } } catch (Exception ex) { Global.Log("设置内镜已经记录标识失败", ex); tran.Rollback(); throw new Exception("设置内镜已经记录标识失败"); } int tmp = 0; try { // 插入endoscopeRecordInfo tmp = this.InsertToRecordInfo(endoTemp, tran); } catch (Exception ex) { tran.Rollback(); throw ex; } if (tmp <= 0) { tran.Rollback(); } // 查询endoscopeRecordInfo的id sql = string.Format("select MAX(id) from endoscopeRecordInfo where endoscopeSn='{0}'", endoTemp.EndoscopeSn); tempobj = SqlHelper.ExecuteScalar(tran, CommandType.Text, sql); int recordiinfoid = 0; if (!int.TryParse(tempobj.ToString(), out recordiinfoid)) { tran.Rollback(); return false; } // 查询上一个使用该镜子的病人 sql = string.Format("select top 1 patientNo from endoscopeRecord where endoscopeSn='{0}' order by id desc", endoTemp.EndoscopeSn); var patientnum = SqlHelper.ExecuteScalar(tran, CommandType.Text, sql); if (patientnum == null) { patientnum = string.Empty; } try { // 插入endoscopeRecord tmp = this.InsertToRecord(endoTemp, tran, recordiinfoid, patientnum); } catch (Exception ex) { throw ex; } if (tmp >= 0) { tran.Commit(); return true; } tran.Rollback(); } return false; }
/// <summary> /// Reads the record temporary. /// </summary> /// <param name="endoTemp">The endo temporary.</param> /// <param name="endocscopeSn">The endocscope sn.</param> private EndoscopeTemp ReadRecordTemp(string endocscopeSn) { EndoscopeTemp endoTemp = null; string sql = string.Format("select * from endoscopeTemp where endoscopeSn='{0}'", endocscopeSn); using (SqlDataReader reader = SqlHelper.ExecuteReader(Global.ConnStr, CommandType.Text, sql)) { if (!reader.HasRows) { return endoTemp; } while (reader.Read()) { try { endoTemp = new EndoscopeTemp(); endoTemp.EndoscopeSn = reader.SafeRead<string>("endoscopeSn"); endoTemp.EndoscopeSim = reader.SafeRead<string>("endoscopeSim"); endoTemp.RecordTime = DateTime.Now; endoTemp.BrushWashBegin = reader.SafeRead<TimeSpan>("brushWashBegin"); endoTemp.BrushWashEnd = reader.SafeRead<TimeSpan>("brushWashEnd"); endoTemp.FirstWashBegin = reader.SafeRead<TimeSpan>("firstWashBegin"); endoTemp.FirstWashEnd = reader.SafeRead<TimeSpan>("firstWashEnd"); endoTemp.EnzymeWashBegin = reader.SafeRead<TimeSpan>("enzymeWashBegin"); endoTemp.EnzymeWashEnd = reader.SafeRead<TimeSpan>("enzymeWashEnd"); endoTemp.CleanOutBegin = reader.SafeRead<TimeSpan>("cleanOutWashBegin"); endoTemp.CleanOutEnd = reader.SafeRead<TimeSpan>("cleanOutWashEnd"); endoTemp.DipInBegin = reader.SafeRead<TimeSpan>("dipInWashBegin"); endoTemp.DipInEnd = reader.SafeRead<TimeSpan>("dipInwashEnd"); endoTemp.LastWashBegin = reader.SafeRead<TimeSpan>("lastWashBegin"); endoTemp.LastWashEnd = reader.SafeRead<TimeSpan>("lastWashEnd"); endoTemp.DipInSecBegin = reader.SafeRead<TimeSpan>("dipInWashSecBegin"); endoTemp.DipInSecEnd = reader.SafeRead<TimeSpan>("dipInWashSecEnd"); endoTemp.LastWashSecBegin = reader.SafeRead<TimeSpan>("lastWashSecBegin"); endoTemp.LastWashSecEnd = reader.SafeRead<TimeSpan>("lastWashSecEnd"); endoTemp.Quality = reader.SafeRead<bool>("qualified"); endoTemp.WasherNo = reader.SafeRead<string>("washerNo"); endoTemp.WasherName = reader.SafeRead<string>("washerName"); endoTemp.CleanType = reader.SafeRead<string>("cleanType").Trim(); endoTemp.Disinfection = reader.SafeRead<bool>("disinfection"); endoTemp.WashDate = reader.SafeRead<DateTime>("washDate"); endoTemp.AutoCleanNo = reader.SafeRead<string>("autoCleanNo"); if (endoTemp.CleanType.Equals("1")) { endoTemp.TotalTime = (endoTemp.BrushWashEnd - endoTemp.BrushWashBegin + endoTemp.FirstWashEnd - endoTemp.FirstWashBegin + endoTemp.EnzymeWashEnd - endoTemp.EnzymeWashBegin + endoTemp.CleanOutEnd - endoTemp.CleanOutBegin + endoTemp.DipInEnd - endoTemp.DipInBegin + endoTemp.LastWashEnd - endoTemp.LastWashBegin).ToString(); } else { endoTemp.TotalTime = (endoTemp.DipInSecEnd - endoTemp.DipInSecBegin + endoTemp.LastWashSecEnd - endoTemp.LastWashSecBegin).ToString(); } } catch (Exception ex) { Global.Log("读取endoscopeTemp失败", ex); throw new Exception("读取endoscopeTemp失败"); } } } return endoTemp; }
/// <summary> /// 获得内镜信息 /// </summary> /// <param name="endoscopeSn">内镜编号</param> /// <returns> /// 内镜信息 /// </returns> public EndoscopeTemp GetNewCleanMsg(string endoscopeSn) { EndoscopeTemp endoscopeclean = null; var selectsql = "select * from endoscopeTemp where endoscopeSn=@endoscopeSn"; SqlParameter[] paras = { this.GetSqlParameter("@endoscopeSn",endoscopeSn,DbType.String) }; try { using (SqlDataReader reader = SqlHelper.ExecuteReader(Global.ConnStr, CommandType.Text, selectsql, paras)) { if (!reader.HasRows) { return endoscopeclean; } while (reader.Read()) { endoscopeclean = new EndoscopeTemp { EndoscopeSn = reader.SafeRead<string>("endoscopeSn"), EndoscopeSim = reader.SafeRead<string>("endoscopeSim"), CleanType = reader.SafeRead<string>("cleanType"), WasherNo = reader.SafeRead<string>("washerNo"), WasherName = reader.SafeRead<string>("washerName"), AutoCleanNo = reader.SafeRead<string>("autoCleanNo") }; endoscopeclean.WashDate = reader.SafeRead<DateTime>("washDate"); if (string.Equals(endoscopeclean.CleanType.Trim(), "1")) { endoscopeclean.BrushWashBegin = reader.SafeRead<TimeSpan>("brushWashBegin"); endoscopeclean.BrushWashEnd = reader.SafeRead<TimeSpan>("brushWashEnd"); endoscopeclean.FirstWashBegin = reader.SafeRead<TimeSpan>("firstWashBegin"); endoscopeclean.FirstWashEnd = reader.SafeRead<TimeSpan>("firstWashEnd"); endoscopeclean.EnzymeWashBegin = reader.SafeRead<TimeSpan>("enzymeWashBegin"); endoscopeclean.EnzymeWashEnd = reader.SafeRead<TimeSpan>("enzymeWashEnd"); endoscopeclean.CleanOutBegin = reader.SafeRead<TimeSpan>("cleanOutWashBegin"); endoscopeclean.CleanOutEnd = reader.SafeRead<TimeSpan>("cleanOutWashEnd"); endoscopeclean.DipInBegin = reader.SafeRead<TimeSpan>("dipInWashBegin"); endoscopeclean.DipInEnd = reader.SafeRead<TimeSpan>("dipInwashEnd"); endoscopeclean.LastWashBegin = reader.SafeRead<TimeSpan>("lastWashBegin"); endoscopeclean.LastWashEnd = reader.SafeRead<TimeSpan>("lastWashEnd"); } if (string.Equals(endoscopeclean.CleanType.Trim(), "2")) { endoscopeclean.DipInSecBegin = reader.SafeRead<TimeSpan>("dipInWashSecBegin"); endoscopeclean.DipInSecEnd = reader.SafeRead<TimeSpan>("dipInWashSecEnd"); endoscopeclean.LastWashSecBegin = reader.SafeRead<TimeSpan>("lastWashSecBegin"); endoscopeclean.LastWashSecEnd = reader.SafeRead<TimeSpan>("lastWashSecEnd"); } } } } catch (Exception ex) { Global.Log("获取最近清洗信息失败", ex); throw new Exception("获取最近清洗信息失败"); } return endoscopeclean; }
/// <summary> /// Inserts the automatic record information. /// </summary> /// <param name="endoTemp">The endo temporary.</param> /// <param name="tran">The tran.</param> /// <returns>成功true;失败false</returns> private int InsertToRecordInfo(EndoscopeTemp endoTemp, SqlTransaction tran) { int result = 0; // 插入endoscopeRecord var insertsql = @"insert into endoscopeRecordInfo ( endoscopeSn,endoscopeSim,recordTime,brushWashBegin,brushWashEnd, firstWashBegin,firstWashEnd,enzymeWashBegin,enzymeWashEnd,cleanOutWashBegin, cleanOutWashEnd,dipInWashBegin,dipInWashEnd,lastWashBegin,lastWashEnd, dipInWashSecBegin,dipInWashSecEnd,lastWashSecBegin,lastWashSecEnd) values( @endoSn,@endoSim,@recordTime,@bruWashB,@bruWashE, @firWashB,@firWashE,@enWashB,@enWashE,@cleanWashB, @cleanWashE,@dipWashB,@dipWashE,@lastWashB,@lastWashE, @dipWashSecB,@dipWashSecE,@lastWashSecB,@lastWashSecE)"; SqlParameter[] paras = new SqlParameter[] { this.GetSqlParameter("@endoSn",endoTemp.EndoscopeSn,DbType.String), this.GetSqlParameter("@endoSim",endoTemp.EndoscopeSim,DbType.String), this.GetSqlParameter("@recordTime",endoTemp.RecordTime,DbType.DateTime), this.GetSqlParameter("@bruWashB",endoTemp.BrushWashBegin, SqlDbType.Time), this.GetSqlParameter("@bruWashE",endoTemp.BrushWashEnd,SqlDbType.Time), this.GetSqlParameter("@firWashB",endoTemp.FirstWashBegin,SqlDbType.Time), this.GetSqlParameter("@firWashE",endoTemp.FirstWashEnd,SqlDbType.Time), this.GetSqlParameter("@enWashB",endoTemp.EnzymeWashBegin,SqlDbType.Time), this.GetSqlParameter("@enWashE",endoTemp.EnzymeWashEnd,SqlDbType.Time), this.GetSqlParameter("@cleanWashB",endoTemp.CleanOutBegin,SqlDbType.Time), this.GetSqlParameter("@cleanWashE",endoTemp.CleanOutEnd,SqlDbType.Time), this.GetSqlParameter("@dipWashB",endoTemp.DipInBegin,SqlDbType.Time), this.GetSqlParameter("@dipWashE",endoTemp.DipInEnd,SqlDbType.Time), this.GetSqlParameter("@lastWashB",endoTemp.LastWashBegin,SqlDbType.Time), this.GetSqlParameter("@lastWashE",endoTemp.LastWashEnd,SqlDbType.Time), this.GetSqlParameter("@dipWashSecB",endoTemp.DipInSecBegin,SqlDbType.Time), this.GetSqlParameter("@dipWashSecE",endoTemp.DipInSecEnd,SqlDbType.Time), this.GetSqlParameter("@lastWashSecB",endoTemp.LastWashSecBegin,SqlDbType.Time), this.GetSqlParameter("@lastWashSecE",endoTemp.LastWashSecEnd,SqlDbType.Time) }; try { // Insert record into RecordInfo with transaction result = SqlHelper.ExecuteNonQuery(tran, CommandType.Text, insertsql, paras); } catch (Exception ex) { Global.Log("插入endoscopeRecordInfo失败", ex); throw new Exception("插入endoscopeRecordInfo失败"); } return result; }
/// <summary> /// Inserts the automatic record. /// </summary> /// <param name="endoTemp">The endo temporary.</param> /// <param name="tran">The tran.</param> /// <param name="recordiinfoid">The recordiinfoid.</param> /// <param name="patientnum">The patientnum.</param> /// <returns>成功true;失败false</returns> private int InsertToRecord(EndoscopeTemp endoTemp, SqlTransaction tran, int recordiinfoid, object patientnum) { int result = 0; string insertsql = @"insert into endoscopeRecord ( endoscopeSn,endoscopeSim,washerNo,washerName,recordInfoId,recordTime, cleanType,disinfection,washDate,washTotalTime,washBeginTime,washEndTime, autoCleanNo,prePatientNo,qualified,isUpdated) values( @endoSn,@endoSim,@washerNo,@washerName,@recordInfoId,@recordTime,@cleanType, @disinfection,@washDate,@washTotalTime,@washBeginTime,@washEndTime,@autoCleanNo, @prePatientNo,@qualified,@isUpdated)"; SqlParameter[] insertparas = { this.GetSqlParameter("@endoSn",endoTemp.EndoscopeSn,DbType.String), this.GetSqlParameter("@endoSim",endoTemp.EndoscopeSim,DbType.String), this.GetSqlParameter("@washerNo",endoTemp.WasherNo,DbType.String), this.GetSqlParameter("@washerName",endoTemp.WasherName,DbType.String), this.GetSqlParameter("@recordInfoId",recordiinfoid.ToString(),DbType.String), this.GetSqlParameter("@recordTime",endoTemp.RecordTime,DbType.DateTime), this.GetSqlParameter("@cleanType",endoTemp.CleanType,DbType.String), this.GetSqlParameter("@disinfection",endoTemp.Disinfection,DbType.Boolean), this.GetSqlParameter("@washDate",endoTemp.WashDate,DbType.Date), this.GetSqlParameter("@washTotalTime",endoTemp.TotalTime,DbType.String), this.GetSqlParameter("@washBeginTime",endoTemp.CleanType == "1" ? endoTemp.BrushWashBegin : endoTemp.DipInSecBegin,SqlDbType.Time), this.GetSqlParameter("@washEndTime",endoTemp.CleanType == "1" ? endoTemp.LastWashEnd : endoTemp.LastWashSecEnd,SqlDbType.Time), this.GetSqlParameter("@autoCleanNo",endoTemp.AutoCleanNo,DbType.String), this.GetSqlParameter("@prePatientNo",patientnum,DbType.String), this.GetSqlParameter("@qualified",endoTemp.Quality,DbType.Boolean), this.GetSqlParameter("@isUpdated",0,DbType.Int32), }; try { // insert into Record with transaction result = SqlHelper.ExecuteNonQuery(tran, CommandType.Text, insertsql, insertparas); } catch (Exception ex) { Global.Log("插入endoscopeRecord失败", ex); throw new Exception("插入endoscopeRecord失败"); } return result; }
/// <summary> /// 显示清洗信息到界面 /// </summary> /// <param name="endoscopeClean">The endoscope clean.</param> public void ShowMessageToForm(EndoscopeTemp endoscopeClean) { this.ShowCleanLatestMessage(endoscopeClean); }
/// <summary> /// Datas the serv busi show clean latest message. /// </summary> /// <param name="endoscopeCleanTemp">The endoscope clean temporary.</param> private void DataServBusiShowCleanLatestMessage(EndoscopeTemp endoscopeCleanTemp) { Action<EndoscopeTemp> ac = SetMsg; try { ac(endoscopeCleanTemp); } catch (Exception ex) { FormHelper.RecordLogMsg(ex.Message); } }
/// <summary> /// 获取最新的一条记录 /// </summary> /// <param name="endoscope">内镜编号</param> /// <returns> /// 返回内镜信息 /// </returns> public EndoscopeTemp GetLatestCleanMSG(string endoscope) { var tmp = new EndoscopeTemp(); try { tmp = dataObject.GetNewCleanMsg(endoscope); } catch (Exception) { return tmp; } return tmp; }