using System; using System.Data; using System.Data.SqlClient; using System.Collections; using AIMSModel; using AIMSObjectQuery; using System.Collections.Generic; namespace AIMSDAL { public partial class DOperationGoodsBillRecord { #region 插入实体操作部份 /// /// 插入 /// /// Command对象 /// 实体类对象 /// 标识列值或影响的记录行数 public static int Insert(SqlCommand cmd, OperationGoodsBillRecord operationGoodsBillRecord) { cmd.Parameters.Clear(); cmd.CommandText = "insert into OperationGoodsBillRecord (OperationRecordId,ApplianceUseType,BloodType,Erythrocyte,Platelet,PlateletUnit,Plasma,Other,Autoblood,InfusionLocation,Liquid,TourniquetBeginTime,TourniquetEndTime,TourniquetLocation,Specimen,SpecimenNumber,ToFreeze,ToPathology,ToRoom,NotToTest,NegativePlateLocation,DoctorSign,Remark,InvasiveScreening,ScrubNurse,ScrubNurseSucceed,ScrubSucceedTime,TourNurse,TourNurseSucceed,TourSucceedTime,ColdDeposit) values (@OperationRecordId,@ApplianceUseType,@BloodType,@Erythrocyte,@Platelet,@PlateletUnit,@Plasma,@Other,@Autoblood,@InfusionLocation,@Liquid,@TourniquetBeginTime,@TourniquetEndTime,@TourniquetLocation,@Specimen,@SpecimenNumber,@ToFreeze,@ToPathology,@ToRoom,@NotToTest,@NegativePlateLocation,@DoctorSign,@Remark,@InvasiveScreening,@ScrubNurse,@ScrubNurseSucceed,@ScrubSucceedTime,@TourNurse,@TourNurseSucceed,@TourSucceedTime,@ColdDeposit);select @@identity"; //从实体中取出值放入Command的参数列表 cmd.Parameters.Add(new SqlParameter("@OperationRecordId",operationGoodsBillRecord.OperationRecordId.HasValue?(object)operationGoodsBillRecord.OperationRecordId.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@ApplianceUseType",operationGoodsBillRecord.ApplianceUseType==null?(object)DBNull.Value:(object)operationGoodsBillRecord.ApplianceUseType)); cmd.Parameters.Add(new SqlParameter("@BloodType",operationGoodsBillRecord.BloodType==null?(object)DBNull.Value:(object)operationGoodsBillRecord.BloodType)); cmd.Parameters.Add(new SqlParameter("@Erythrocyte",operationGoodsBillRecord.Erythrocyte==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Erythrocyte)); cmd.Parameters.Add(new SqlParameter("@Platelet",operationGoodsBillRecord.Platelet==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Platelet)); cmd.Parameters.Add(new SqlParameter("@PlateletUnit",operationGoodsBillRecord.PlateletUnit==null?(object)DBNull.Value:(object)operationGoodsBillRecord.PlateletUnit)); cmd.Parameters.Add(new SqlParameter("@Plasma",operationGoodsBillRecord.Plasma==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Plasma)); cmd.Parameters.Add(new SqlParameter("@Other",operationGoodsBillRecord.Other==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Other)); cmd.Parameters.Add(new SqlParameter("@Autoblood",operationGoodsBillRecord.Autoblood==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Autoblood)); cmd.Parameters.Add(new SqlParameter("@InfusionLocation",operationGoodsBillRecord.InfusionLocation==null?(object)DBNull.Value:(object)operationGoodsBillRecord.InfusionLocation)); cmd.Parameters.Add(new SqlParameter("@Liquid",operationGoodsBillRecord.Liquid==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Liquid)); cmd.Parameters.Add(new SqlParameter("@TourniquetBeginTime",operationGoodsBillRecord.TourniquetBeginTime.HasValue?(object)operationGoodsBillRecord.TourniquetBeginTime.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@TourniquetEndTime",operationGoodsBillRecord.TourniquetEndTime.HasValue?(object)operationGoodsBillRecord.TourniquetEndTime.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@TourniquetLocation",operationGoodsBillRecord.TourniquetLocation==null?(object)DBNull.Value:(object)operationGoodsBillRecord.TourniquetLocation)); cmd.Parameters.Add(new SqlParameter("@Specimen",operationGoodsBillRecord.Specimen.HasValue?(object)operationGoodsBillRecord.Specimen.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@SpecimenNumber",operationGoodsBillRecord.SpecimenNumber.HasValue?(object)operationGoodsBillRecord.SpecimenNumber.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@ToFreeze",operationGoodsBillRecord.ToFreeze.HasValue?(object)operationGoodsBillRecord.ToFreeze.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@ToPathology",operationGoodsBillRecord.ToPathology.HasValue?(object)operationGoodsBillRecord.ToPathology.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@ToRoom",operationGoodsBillRecord.ToRoom.HasValue?(object)operationGoodsBillRecord.ToRoom.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@NotToTest",operationGoodsBillRecord.NotToTest.HasValue?(object)operationGoodsBillRecord.NotToTest.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@NegativePlateLocation",operationGoodsBillRecord.NegativePlateLocation==null?(object)DBNull.Value:(object)operationGoodsBillRecord.NegativePlateLocation)); cmd.Parameters.Add(new SqlParameter("@DoctorSign",operationGoodsBillRecord.DoctorSign==null?(object)DBNull.Value:(object)operationGoodsBillRecord.DoctorSign)); cmd.Parameters.Add(new SqlParameter("@Remark",operationGoodsBillRecord.Remark==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Remark)); cmd.Parameters.Add(new SqlParameter("@InvasiveScreening",operationGoodsBillRecord.InvasiveScreening==null?(object)DBNull.Value:(object)operationGoodsBillRecord.InvasiveScreening)); cmd.Parameters.Add(new SqlParameter("@ScrubNurse",operationGoodsBillRecord.ScrubNurse==null?(object)DBNull.Value:(object)operationGoodsBillRecord.ScrubNurse)); cmd.Parameters.Add(new SqlParameter("@ScrubNurseSucceed",operationGoodsBillRecord.ScrubNurseSucceed==null?(object)DBNull.Value:(object)operationGoodsBillRecord.ScrubNurseSucceed)); cmd.Parameters.Add(new SqlParameter("@ScrubSucceedTime",operationGoodsBillRecord.ScrubSucceedTime==null?(object)DBNull.Value:(object)operationGoodsBillRecord.ScrubSucceedTime)); cmd.Parameters.Add(new SqlParameter("@TourNurse",operationGoodsBillRecord.TourNurse==null?(object)DBNull.Value:(object)operationGoodsBillRecord.TourNurse)); cmd.Parameters.Add(new SqlParameter("@TourNurseSucceed",operationGoodsBillRecord.TourNurseSucceed==null?(object)DBNull.Value:(object)operationGoodsBillRecord.TourNurseSucceed)); cmd.Parameters.Add(new SqlParameter("@TourSucceedTime",operationGoodsBillRecord.TourSucceedTime==null?(object)DBNull.Value:(object)operationGoodsBillRecord.TourSucceedTime)); cmd.Parameters.Add(new SqlParameter("@ColdDeposit",operationGoodsBillRecord.ColdDeposit==null?(object)DBNull.Value:(object)operationGoodsBillRecord.ColdDeposit)); return Convert.ToInt32(cmd.ExecuteScalar()); } /// /// 不使用事务的插入方法 /// /// 实体类对象 /// 标识列值或影响的记录行数 public static int Insert(OperationGoodsBillRecord operationGoodsBillRecord) { using(SqlConnection conn=new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { return Insert(cmd, operationGoodsBillRecord); } } } /// /// 使用事务的插入方法 /// /// 实现共享Connection的对象 /// 实体类对象 /// 标识列值或影响的记录行数 public static int Insert(Connection connection,OperationGoodsBillRecord operationGoodsBillRecord) { return Insert(connection.Command, operationGoodsBillRecord); } #endregion #region 删除实体操作 /// /// 删除 /// /// Command对象 /// 实体类对象 /// 影响的记录行数 public static int ExcuteDeleteCommand(SqlCommand cmd, OperationGoodsBillRecord operationGoodsBillRecord) { cmd.Parameters.Clear(); cmd.CommandText = "delete from OperationGoodsBillRecord where Id=@Id"; //从实体中取出值放入Command的参数列表 cmd.Parameters.Add(new SqlParameter("@Id", operationGoodsBillRecord.Id)); return cmd.ExecuteNonQuery(); } /// /// 不使用事务的删除方法 /// /// 实体类对象 /// 影响的记录行数 public static int Delete(OperationGoodsBillRecord operationGoodsBillRecord) { using (SqlConnection conn = new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { return ExcuteDeleteCommand(cmd, operationGoodsBillRecord); } } } /// /// 使用事务的删除方法 /// /// 实现共享Connection的对象 /// 实体类对象 /// 影响的记录行数 public static int Delete(Connection connection,OperationGoodsBillRecord operationGoodsBillRecord) { return ExcuteDeleteCommand(connection.Command, operationGoodsBillRecord); } /// /// 执行删除命令 /// /// Command对象 /// 对象查询语句 /// 参数列表 /// 影响的记录行数 public static int ExcuteDeleteCommand(SqlCommand cmd, string oql, ParameterList parameters) { //解析过滤部份Sql语句 string filterString = SyntaxAnalyzer.ParseSql(oql, new OperationGoodsBillRecordMap()); if (filterString != string.Empty) { filterString = " where " + filterString; } cmd.Parameters.Clear(); cmd.CommandText = "delete from OperationGoodsBillRecord " + filterString; //添加参数 if (parameters != null) { foreach (string key in parameters.Keys) { cmd.Parameters.Add(new SqlParameter(key, parameters[key])); } } return cmd.ExecuteNonQuery(); } /// /// 不使用事务的删除方法 /// /// 对象查询语句 /// 参数列表 /// 影响的记录行数 public static int Delete(string oql, ParameterList parameters) { using (SqlConnection conn = new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { return ExcuteDeleteCommand(cmd, oql, parameters); } } } /// /// 使用事务的删除方法 /// /// 实现共享Connection的对象 /// 对象查询语句 /// 参数列表 /// 影响的记录行数 public static int Delete(Connection connection, string oql, ParameterList parameters) { return ExcuteDeleteCommand(connection.Command, oql, parameters); } #endregion #region 更新实体操作 /// /// 更新 /// /// Command对象 /// 实体类对象 /// 影响的记录行数 public static int ExcuteUpdateCommand(SqlCommand cmd, OperationGoodsBillRecord operationGoodsBillRecord) { cmd.CommandText = "update OperationGoodsBillRecord set OperationRecordId=@OperationRecordId,ApplianceUseType=@ApplianceUseType,BloodType=@BloodType,Erythrocyte=@Erythrocyte,Platelet=@Platelet,PlateletUnit=@PlateletUnit,Plasma=@Plasma,Other=@Other,Autoblood=@Autoblood,InfusionLocation=@InfusionLocation,Liquid=@Liquid,TourniquetBeginTime=@TourniquetBeginTime,TourniquetEndTime=@TourniquetEndTime,TourniquetLocation=@TourniquetLocation,Specimen=@Specimen,SpecimenNumber=@SpecimenNumber,ToFreeze=@ToFreeze,ToPathology=@ToPathology,ToRoom=@ToRoom,NotToTest=@NotToTest,NegativePlateLocation=@NegativePlateLocation,DoctorSign=@DoctorSign,Remark=@Remark,InvasiveScreening=@InvasiveScreening,ScrubNurse=@ScrubNurse,ScrubNurseSucceed=@ScrubNurseSucceed,ScrubSucceedTime=@ScrubSucceedTime,TourNurse=@TourNurse,TourNurseSucceed=@TourNurseSucceed,TourSucceedTime=@TourSucceedTime,ColdDeposit=@ColdDeposit where Id=@Id"; //从实体中取出值放入Command的参数列表 cmd.Parameters.Add(new SqlParameter("@OperationRecordId",operationGoodsBillRecord.OperationRecordId.HasValue?(object)operationGoodsBillRecord.OperationRecordId.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@ApplianceUseType",operationGoodsBillRecord.ApplianceUseType==null?(object)DBNull.Value:(object)operationGoodsBillRecord.ApplianceUseType)); cmd.Parameters.Add(new SqlParameter("@BloodType",operationGoodsBillRecord.BloodType==null?(object)DBNull.Value:(object)operationGoodsBillRecord.BloodType)); cmd.Parameters.Add(new SqlParameter("@Erythrocyte",operationGoodsBillRecord.Erythrocyte==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Erythrocyte)); cmd.Parameters.Add(new SqlParameter("@Platelet",operationGoodsBillRecord.Platelet==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Platelet)); cmd.Parameters.Add(new SqlParameter("@PlateletUnit",operationGoodsBillRecord.PlateletUnit==null?(object)DBNull.Value:(object)operationGoodsBillRecord.PlateletUnit)); cmd.Parameters.Add(new SqlParameter("@Plasma",operationGoodsBillRecord.Plasma==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Plasma)); cmd.Parameters.Add(new SqlParameter("@Other",operationGoodsBillRecord.Other==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Other)); cmd.Parameters.Add(new SqlParameter("@Autoblood",operationGoodsBillRecord.Autoblood==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Autoblood)); cmd.Parameters.Add(new SqlParameter("@InfusionLocation",operationGoodsBillRecord.InfusionLocation==null?(object)DBNull.Value:(object)operationGoodsBillRecord.InfusionLocation)); cmd.Parameters.Add(new SqlParameter("@Liquid",operationGoodsBillRecord.Liquid==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Liquid)); cmd.Parameters.Add(new SqlParameter("@TourniquetBeginTime",operationGoodsBillRecord.TourniquetBeginTime.HasValue?(object)operationGoodsBillRecord.TourniquetBeginTime.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@TourniquetEndTime",operationGoodsBillRecord.TourniquetEndTime.HasValue?(object)operationGoodsBillRecord.TourniquetEndTime.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@TourniquetLocation",operationGoodsBillRecord.TourniquetLocation==null?(object)DBNull.Value:(object)operationGoodsBillRecord.TourniquetLocation)); cmd.Parameters.Add(new SqlParameter("@Specimen",operationGoodsBillRecord.Specimen.HasValue?(object)operationGoodsBillRecord.Specimen.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@SpecimenNumber",operationGoodsBillRecord.SpecimenNumber.HasValue?(object)operationGoodsBillRecord.SpecimenNumber.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@ToFreeze",operationGoodsBillRecord.ToFreeze.HasValue?(object)operationGoodsBillRecord.ToFreeze.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@ToPathology",operationGoodsBillRecord.ToPathology.HasValue?(object)operationGoodsBillRecord.ToPathology.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@ToRoom",operationGoodsBillRecord.ToRoom.HasValue?(object)operationGoodsBillRecord.ToRoom.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@NotToTest",operationGoodsBillRecord.NotToTest.HasValue?(object)operationGoodsBillRecord.NotToTest.Value:(object)DBNull.Value)); cmd.Parameters.Add(new SqlParameter("@NegativePlateLocation",operationGoodsBillRecord.NegativePlateLocation==null?(object)DBNull.Value:(object)operationGoodsBillRecord.NegativePlateLocation)); cmd.Parameters.Add(new SqlParameter("@DoctorSign",operationGoodsBillRecord.DoctorSign==null?(object)DBNull.Value:(object)operationGoodsBillRecord.DoctorSign)); cmd.Parameters.Add(new SqlParameter("@Remark",operationGoodsBillRecord.Remark==null?(object)DBNull.Value:(object)operationGoodsBillRecord.Remark)); cmd.Parameters.Add(new SqlParameter("@InvasiveScreening",operationGoodsBillRecord.InvasiveScreening==null?(object)DBNull.Value:(object)operationGoodsBillRecord.InvasiveScreening)); cmd.Parameters.Add(new SqlParameter("@ScrubNurse",operationGoodsBillRecord.ScrubNurse==null?(object)DBNull.Value:(object)operationGoodsBillRecord.ScrubNurse)); cmd.Parameters.Add(new SqlParameter("@ScrubNurseSucceed",operationGoodsBillRecord.ScrubNurseSucceed==null?(object)DBNull.Value:(object)operationGoodsBillRecord.ScrubNurseSucceed)); cmd.Parameters.Add(new SqlParameter("@ScrubSucceedTime",operationGoodsBillRecord.ScrubSucceedTime==null?(object)DBNull.Value:(object)operationGoodsBillRecord.ScrubSucceedTime)); cmd.Parameters.Add(new SqlParameter("@TourNurse",operationGoodsBillRecord.TourNurse==null?(object)DBNull.Value:(object)operationGoodsBillRecord.TourNurse)); cmd.Parameters.Add(new SqlParameter("@TourNurseSucceed",operationGoodsBillRecord.TourNurseSucceed==null?(object)DBNull.Value:(object)operationGoodsBillRecord.TourNurseSucceed)); cmd.Parameters.Add(new SqlParameter("@TourSucceedTime",operationGoodsBillRecord.TourSucceedTime==null?(object)DBNull.Value:(object)operationGoodsBillRecord.TourSucceedTime)); cmd.Parameters.Add(new SqlParameter("@ColdDeposit",operationGoodsBillRecord.ColdDeposit==null?(object)DBNull.Value:(object)operationGoodsBillRecord.ColdDeposit)); cmd.Parameters.Add(new SqlParameter("@Id", operationGoodsBillRecord.Id)); return cmd.ExecuteNonQuery(); } /// /// 不使用事务的更新方法 /// /// 实体类对象 /// 影响的记录行数 public static int Update(OperationGoodsBillRecord operationGoodsBillRecord) { using(SqlConnection conn=new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { return ExcuteUpdateCommand(cmd, operationGoodsBillRecord); } } } /// /// 使用事务的更新方法 /// /// 实现共享Connection的对象 /// 实体类对象 /// 影响的记录行数 public static int Update(Connection connection,OperationGoodsBillRecord operationGoodsBillRecord) { return ExcuteUpdateCommand(connection.Command, operationGoodsBillRecord); } /// /// 执行更新命令 /// /// Command对象 /// 对象查询语句 /// 参数列表 /// 影响的记录行数 public static int ExcuteUpdateCommand(SqlCommand cmd, string oql, ParameterList parameters) { //解析过滤部份Sql语句 string updateString = SyntaxAnalyzer.ParseSql(oql, new OperationGoodsBillRecordMap()); cmd.CommandText = "update OperationGoodsBillRecord set " + updateString; cmd.Parameters.Clear(); //添加参数 if (parameters != null) { foreach (string key in parameters.Keys) { cmd.Parameters.Add(new SqlParameter(key, parameters[key])); } } return cmd.ExecuteNonQuery(); } /// /// 不使用事务的更新方法 /// /// 对象查询语句 /// 参数列表 /// 影响的记录行数 public static int Update(string oql, ParameterList parameters) { using (SqlConnection conn = new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { return ExcuteUpdateCommand(cmd, oql, parameters); } } } /// /// 使用事务的更新方法 /// /// 实现共享Connection的对象 /// 对象查询语句 /// 参数列表 /// 影响的记录行数 public static int Update(Connection connection, string oql, ParameterList parameters) { return ExcuteUpdateCommand(connection.Command, oql, parameters); } #endregion #region 查询实体集合 /// /// 执行Command获取对象列表 /// /// Command对象 /// 递归类型 /// 递归深度 /// 实体类对象列表 public static List ExcuteSelectCommand(SqlCommand cmd,RecursiveType recursiveType,int recursiveDepth) { List operationGoodsBillRecordList = new List(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { OperationGoodsBillRecord operationGoodsBillRecord = DataReaderToEntity(dr); operationGoodsBillRecordList.Add(operationGoodsBillRecord); } } return operationGoodsBillRecordList; } /// /// 执行查询命令 /// /// Command对象 /// 对象查询语句 /// 参数列表 /// 递归类型 /// 递归深度 /// 实体类对象集合 public static List ExcuteSelectCommand(SqlCommand cmd, string oql, ParameterList parameters,RecursiveType recursiveType,int recursiveDepth) { //解析过滤部份Sql语句 string filterString = SyntaxAnalyzer.ParseSql(oql, new OperationGoodsBillRecordMap()); if (filterString != string.Empty) { if(filterString.Trim().ToLower().IndexOf("order ")!=0) filterString = " where " + filterString; } cmd.Parameters.Clear(); cmd.CommandText = "select * from OperationGoodsBillRecord " + filterString; //添加参数 if (parameters != null) { foreach (string key in parameters.Keys) { cmd.Parameters.Add(new SqlParameter(key, parameters[key])); } } return ExcuteSelectCommand(cmd, recursiveType, recursiveDepth); } /// /// 根据对象查询语句查询实体集合 /// /// 实体类对象集合 public static List Select() { using(SqlConnection conn=new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "select * from OperationGoodsBillRecord"; return ExcuteSelectCommand(cmd, RecursiveType.Parent, 1); } } } /// /// 根据对象查询语句查询实体集合 /// /// 递归类型 /// 递归深度 /// 实体类对象集合 public static List Select(RecursiveType recursiveType, int recursiveDepth) { using(SqlConnection conn=new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "select * from OperationGoodsBillRecord"; return ExcuteSelectCommand(cmd, recursiveType, recursiveDepth); } } } /// /// 根据对象查询语句查询实体集合 /// /// 对象查询语句 /// 参数列表 /// 实体类对象集合 public static List Select(string oql, ParameterList parameters) { using(SqlConnection conn=new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { return ExcuteSelectCommand(cmd, oql, parameters, RecursiveType.Parent, 1); } } } /// /// 根据对象查询语句查询实体集合 /// /// 对象查询语句 /// 参数列表 /// 递归类型 /// 递归深度 /// 实体类对象集合 public static List Select(string oql, ParameterList parameters,RecursiveType recursiveType, int recursiveDepth) { using(SqlConnection conn=new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { return ExcuteSelectCommand(cmd, oql, parameters, recursiveType, recursiveDepth); } } } /// /// 根据对象查询语句查询实体集合(启用事务) /// /// 连接对象 /// 对象查询语句 /// 参数列表 /// 递归类型 /// 递归深度 /// 实体类对象集合 public static List Select(Connection connection, string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth) { return ExcuteSelectCommand(connection.Command, oql, parameters,recursiveType, recursiveDepth); } #endregion #region 查询单个实体 /// /// 递归查询单个实体 /// /// Command对象 /// 递归类型 /// 递归深度 /// 实体对象 public static OperationGoodsBillRecord ExcuteSelectSingleCommand(SqlCommand cmd,RecursiveType recursiveType,int recursiveDepth) { OperationGoodsBillRecord operationGoodsBillRecord=null; using (SqlDataReader dr = cmd.ExecuteReader()) { if(dr.Read()) operationGoodsBillRecord = DataReaderToEntity(dr); } if(operationGoodsBillRecord==null) return operationGoodsBillRecord; return operationGoodsBillRecord; } /// /// 更据对象查询语句递归查询单个实体 /// /// Command对象 /// 对象查询语句 /// 参数列表 /// 递归类型 /// 递归深度 /// 实体对象 public static OperationGoodsBillRecord ExcuteSelectSingleCommand(SqlCommand cmd, string oql, ParameterList parameters,RecursiveType recursiveType,int recursiveDepth) { //解析过滤部份Sql语句 string filterString = SyntaxAnalyzer.ParseSql(oql, new OperationGoodsBillRecordMap()); if(filterString!=string.Empty) { filterString=" where "+filterString; } cmd.CommandText = "select * from OperationGoodsBillRecord " + filterString; cmd.Parameters.Clear(); //添加参数 if (parameters != null) { foreach (string key in parameters.Keys) { cmd.Parameters.Add(new SqlParameter(key, parameters[key])); } } return ExcuteSelectSingleCommand(cmd, recursiveType, recursiveDepth); } /// /// 更据对象查询语句递归查询单个实体 /// /// Command对象 /// 对象查询语句 /// 参数列表 /// 递归类型 /// 递归深度 /// 实体对象 public static OperationGoodsBillRecord SelectSingle(string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth) { using(SqlConnection conn=new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { return ExcuteSelectSingleCommand(cmd, oql, parameters, recursiveType, recursiveDepth); } } } /// /// 更据对象查询语句查询单个实体 /// /// Command对象 /// 对象查询语句 /// 参数列表 /// 实体对象 public static OperationGoodsBillRecord SelectSingle(string oql, ParameterList parameters) { return SelectSingle(oql,parameters,RecursiveType.Parent,1); } /// /// 更据对象查询语句并启用事务查询单个实体 /// /// 连接对象 /// 对象查询语句 /// 参数列表 /// 实体对象 public static OperationGoodsBillRecord SelectSingle(Connection connection, string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth) { return ExcuteSelectSingleCommand(connection.Command, oql, parameters, recursiveType, recursiveDepth); } /// /// 更据主键值递归查询单个实体 /// /// Command对象 /// 主键值 /// 递归类型 /// 递归深度 /// 实体对象 public static OperationGoodsBillRecord SelectSingle(SqlCommand cmd, int? id,RecursiveType recursiveType,int recursiveDepth) { cmd.Parameters.Clear(); if(id.HasValue) { cmd.CommandText = "select * from OperationGoodsBillRecord where Id=@pk"; cmd.Parameters.Add(new SqlParameter("@pk",id.Value)); } else { cmd.CommandText = "select * from OperationGoodsBillRecord where Id is null"; } return ExcuteSelectSingleCommand(cmd, recursiveType, recursiveDepth); } /// /// 按主键字段查询特定实体 /// /// 主键值 /// 实体类对象 public static OperationGoodsBillRecord SelectSingle(int? id) { using(SqlConnection conn=new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { return SelectSingle(cmd,id,RecursiveType.Parent,1); } } } /// /// 按主键字段查询特定实体 /// /// 主键值 /// 递归类型 /// 递归深度 /// 实体类对象 public static OperationGoodsBillRecord SelectSingle(int? id, RecursiveType recursiveType, int recursiveDepth) { using(SqlConnection conn=new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { return SelectSingle(cmd,id, recursiveType, recursiveDepth); } } } /// /// 使用事务并按主键字段查询特定实体 /// /// 连接对象 /// 主键值 /// 实体类对象 public static OperationGoodsBillRecord SelectSingle(Connection connection,int? id, RecursiveType recursiveType, int recursiveDepth) { return SelectSingle(connection.Command, id, recursiveType, recursiveDepth); } #endregion /// /// 从DataReader中取出值生成实体对象 /// /// 查询对象 /// 过滤条件字符串 private static OperationGoodsBillRecord DataReaderToEntity(SqlDataReader dr) { OperationGoodsBillRecord entity = new OperationGoodsBillRecord (); if(dr["Id"]!=System.DBNull.Value) { entity.Id=Convert.ToInt32(dr["Id"]); } if(dr["OperationRecordId"]!=System.DBNull.Value) { entity.OperationRecordId=Convert.ToInt32(dr["OperationRecordId"]); } if(dr["ApplianceUseType"]!=System.DBNull.Value) { entity.ApplianceUseType=dr["ApplianceUseType"].ToString(); } if(dr["BloodType"]!=System.DBNull.Value) { entity.BloodType=dr["BloodType"].ToString(); } if(dr["Erythrocyte"]!=System.DBNull.Value) { entity.Erythrocyte=dr["Erythrocyte"].ToString(); } if(dr["Platelet"]!=System.DBNull.Value) { entity.Platelet=dr["Platelet"].ToString(); } if(dr["PlateletUnit"]!=System.DBNull.Value) { entity.PlateletUnit=dr["PlateletUnit"].ToString(); } if(dr["Plasma"]!=System.DBNull.Value) { entity.Plasma=dr["Plasma"].ToString(); } if(dr["Other"]!=System.DBNull.Value) { entity.Other=dr["Other"].ToString(); } if(dr["Autoblood"]!=System.DBNull.Value) { entity.Autoblood=dr["Autoblood"].ToString(); } if(dr["InfusionLocation"]!=System.DBNull.Value) { entity.InfusionLocation=dr["InfusionLocation"].ToString(); } if(dr["Liquid"]!=System.DBNull.Value) { entity.Liquid=dr["Liquid"].ToString(); } if(dr["TourniquetBeginTime"]!=System.DBNull.Value) { entity.TourniquetBeginTime=Convert.ToDateTime(dr["TourniquetBeginTime"]); } if(dr["TourniquetEndTime"]!=System.DBNull.Value) { entity.TourniquetEndTime=Convert.ToDateTime(dr["TourniquetEndTime"]); } if(dr["TourniquetLocation"]!=System.DBNull.Value) { entity.TourniquetLocation=dr["TourniquetLocation"].ToString(); } if(dr["Specimen"]!=System.DBNull.Value) { entity.Specimen=Convert.ToInt32(dr["Specimen"]); } if(dr["SpecimenNumber"]!=System.DBNull.Value) { entity.SpecimenNumber=Convert.ToInt32(dr["SpecimenNumber"]); } if(dr["ToFreeze"]!=System.DBNull.Value) { entity.ToFreeze=Convert.ToInt32(dr["ToFreeze"]); } if(dr["ToPathology"]!=System.DBNull.Value) { entity.ToPathology=Convert.ToInt32(dr["ToPathology"]); } if(dr["ToRoom"]!=System.DBNull.Value) { entity.ToRoom=Convert.ToInt32(dr["ToRoom"]); } if(dr["NotToTest"]!=System.DBNull.Value) { entity.NotToTest=Convert.ToInt32(dr["NotToTest"]); } if(dr["NegativePlateLocation"]!=System.DBNull.Value) { entity.NegativePlateLocation=dr["NegativePlateLocation"].ToString(); } if(dr["DoctorSign"]!=System.DBNull.Value) { entity.DoctorSign=dr["DoctorSign"].ToString(); } if(dr["Remark"]!=System.DBNull.Value) { entity.Remark=dr["Remark"].ToString(); } if(dr["InvasiveScreening"]!=System.DBNull.Value) { entity.InvasiveScreening=dr["InvasiveScreening"].ToString(); } if(dr["ScrubNurse"]!=System.DBNull.Value) { entity.ScrubNurse=dr["ScrubNurse"].ToString(); } if(dr["ScrubNurseSucceed"]!=System.DBNull.Value) { entity.ScrubNurseSucceed=dr["ScrubNurseSucceed"].ToString(); } if(dr["ScrubSucceedTime"]!=System.DBNull.Value) { entity.ScrubSucceedTime=dr["ScrubSucceedTime"].ToString(); } if(dr["TourNurse"]!=System.DBNull.Value) { entity.TourNurse=dr["TourNurse"].ToString(); } if(dr["TourNurseSucceed"]!=System.DBNull.Value) { entity.TourNurseSucceed=dr["TourNurseSucceed"].ToString(); } if(dr["TourSucceedTime"]!=System.DBNull.Value) { entity.TourSucceedTime=dr["TourSucceedTime"].ToString(); } if(dr["ColdDeposit"]!=System.DBNull.Value) { entity.ColdDeposit=dr["ColdDeposit"].ToString(); } return entity; } } }