698 lines
		
	
	
		
			30 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			698 lines
		
	
	
		
			30 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Data;
 | |
| using System.Data.SqlClient;
 | |
| using System.Collections; 
 | |
| using AIMSObjectQuery;
 | |
| using System.Collections.Generic;
 | |
| using DrawGraph;
 | |
| using AIMSModel;
 | |
| 
 | |
| namespace AIMSDAL
 | |
| {
 | |
|     public partial class DAnaseDataQualityRecord
 | |
| 	{
 | |
| 	    #region 插入实体操作部份
 | |
| 	    /// <summary>
 | |
|         /// 插入
 | |
|         /// </summary>
 | |
| 		/// <param name="cmd">Command对象</param>
 | |
|         /// <param name="anaseDataQualityRecord">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
| 		public static int Insert(SqlCommand cmd, AnaseDataQualityRecord anaseDataQualityRecord)
 | |
| 		{
 | |
| 		    cmd.Parameters.Clear();
 | |
| 			cmd.CommandText = "insert into AnaseDataQualityRecord (OperationRecordId,AdverseEventId,AdverseEvenLevel,AdverseEvenName,IsValid,OperatorId,OpeatorTime) values (@OperationRecordId,@AdverseEventId,@AdverseEvenLevel,@AdverseEvenName,@IsValid,@OperatorId,@OpeatorTime);select @@identity";
 | |
| 			//从实体中取出值放入Command的参数列表
 | |
| 			cmd.Parameters.Add(new SqlParameter("@OperationRecordId",anaseDataQualityRecord.OperationRecordId.HasValue?(object)anaseDataQualityRecord.OperationRecordId.Value:(object)DBNull.Value));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@AdverseEventId",anaseDataQualityRecord.AdverseEventId.HasValue?(object)anaseDataQualityRecord.AdverseEventId.Value:(object)DBNull.Value));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@AdverseEvenLevel",anaseDataQualityRecord.AdverseEvenLevel==null?(object)DBNull.Value:(object)anaseDataQualityRecord.AdverseEvenLevel));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@AdverseEvenName",anaseDataQualityRecord.AdverseEvenName==null?(object)DBNull.Value:(object)anaseDataQualityRecord.AdverseEvenName));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@IsValid",anaseDataQualityRecord.IsValid==null?(object)DBNull.Value:(object)anaseDataQualityRecord.IsValid));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@OperatorId",anaseDataQualityRecord.OperatorId.HasValue?(object)anaseDataQualityRecord.OperatorId.Value:(object)DBNull.Value));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@OpeatorTime",anaseDataQualityRecord.OpeatorTime.HasValue?(object)anaseDataQualityRecord.OpeatorTime.Value:(object)DBNull.Value));
 | |
| 			return Convert.ToInt32(cmd.ExecuteScalar());
 | |
| 		}
 | |
| 	    /// <summary>
 | |
|         /// 不使用事务的插入方法
 | |
|         /// </summary>
 | |
|         /// <param name="anaseDataQualityRecord">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
| 	    public static int Insert(AnaseDataQualityRecord anaseDataQualityRecord)
 | |
| 		{
 | |
| 			using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
 | |
| 			{
 | |
| 				conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return Insert(cmd, anaseDataQualityRecord);
 | |
|                 }
 | |
| 			}
 | |
| 		}
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 使用事务的插入方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="anaseDataQualityRecord">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
|         public static int Insert(Connection connection,AnaseDataQualityRecord anaseDataQualityRecord)
 | |
|         {
 | |
|             return Insert(connection.Command, anaseDataQualityRecord);
 | |
|         }
 | |
| 		#endregion
 | |
| 		
 | |
| 		#region 删除实体操作
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 删除
 | |
|         /// </summary>
 | |
| 		/// <param name="cmd">Command对象</param>
 | |
|         /// <param name="anaseDataQualityRecord">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
| 		public static int ExcuteDeleteCommand(SqlCommand cmd, AnaseDataQualityRecord anaseDataQualityRecord)
 | |
|         {
 | |
| 			cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "delete from AnaseDataQualityRecord where Id=@Id";
 | |
|             //从实体中取出值放入Command的参数列表
 | |
| 		    cmd.Parameters.Add(new SqlParameter("@Id", anaseDataQualityRecord.Id));
 | |
|             return cmd.ExecuteNonQuery();
 | |
|         }
 | |
| 		/// <summary>
 | |
|         /// 不使用事务的删除方法
 | |
|         /// </summary>
 | |
|         /// <param name="anaseDataQualityRecord">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Delete(AnaseDataQualityRecord anaseDataQualityRecord)
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return ExcuteDeleteCommand(cmd, anaseDataQualityRecord);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 		/// <summary>
 | |
|         /// 使用事务的删除方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="anaseDataQualityRecord">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Delete(Connection connection,AnaseDataQualityRecord anaseDataQualityRecord)
 | |
|         {
 | |
|             return  ExcuteDeleteCommand(connection.Command, anaseDataQualityRecord);
 | |
| 		}
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 执行删除命令
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int ExcuteDeleteCommand(SqlCommand cmd, string oql, ParameterList parameters)
 | |
|         {
 | |
|             //解析过滤部份Sql语句
 | |
|             string filterString = SyntaxAnalyzer.ParseSql(oql, new AnaseDataQualityRecordMap());
 | |
|             if (filterString != string.Empty)
 | |
|             {
 | |
|                 filterString = " where " + filterString;
 | |
|             }
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "delete from AnaseDataQualityRecord " + filterString;
 | |
|             //添加参数
 | |
|             if (parameters != null)
 | |
|             {
 | |
|                 foreach (string key in parameters.Keys)
 | |
|                 {
 | |
|                     cmd.Parameters.Add(new SqlParameter(key, parameters[key]));
 | |
|                 }
 | |
|             }
 | |
|             return cmd.ExecuteNonQuery();
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 不使用事务的删除方法
 | |
|         /// </summary>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         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);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 使用事务的删除方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Delete(Connection connection, string oql, ParameterList parameters)
 | |
|         {
 | |
|             return ExcuteDeleteCommand(connection.Command, oql, parameters);
 | |
|         }
 | |
| 		
 | |
| 		#endregion
 | |
| 		
 | |
| 		#region 更新实体操作
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 更新
 | |
|         /// </summary>
 | |
| 		/// <param name="cmd">Command对象</param>
 | |
|         /// <param name="anaseDataQualityRecord">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
| 		public static int ExcuteUpdateCommand(SqlCommand cmd, AnaseDataQualityRecord anaseDataQualityRecord)
 | |
| 		{
 | |
| 		    cmd.CommandText = "update AnaseDataQualityRecord set OperationRecordId=@OperationRecordId,AdverseEventId=@AdverseEventId,AdverseEvenLevel=@AdverseEvenLevel,AdverseEvenName=@AdverseEvenName,IsValid=@IsValid,OperatorId=@OperatorId,OpeatorTime=@OpeatorTime where Id=@Id";
 | |
| 			//从实体中取出值放入Command的参数列表
 | |
| 			cmd.Parameters.Add(new SqlParameter("@OperationRecordId",anaseDataQualityRecord.OperationRecordId.HasValue?(object)anaseDataQualityRecord.OperationRecordId.Value:(object)DBNull.Value));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@AdverseEventId",anaseDataQualityRecord.AdverseEventId.HasValue?(object)anaseDataQualityRecord.AdverseEventId.Value:(object)DBNull.Value));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@AdverseEvenLevel",anaseDataQualityRecord.AdverseEvenLevel==null?(object)DBNull.Value:(object)anaseDataQualityRecord.AdverseEvenLevel));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@AdverseEvenName",anaseDataQualityRecord.AdverseEvenName==null?(object)DBNull.Value:(object)anaseDataQualityRecord.AdverseEvenName));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@IsValid",anaseDataQualityRecord.IsValid==null?(object)DBNull.Value:(object)anaseDataQualityRecord.IsValid));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@OperatorId",anaseDataQualityRecord.OperatorId.HasValue?(object)anaseDataQualityRecord.OperatorId.Value:(object)DBNull.Value));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@OpeatorTime",anaseDataQualityRecord.OpeatorTime.HasValue?(object)anaseDataQualityRecord.OpeatorTime.Value:(object)DBNull.Value));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@Id", anaseDataQualityRecord.Id));
 | |
|             return cmd.ExecuteNonQuery();
 | |
| 		}
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 不使用事务的更新方法
 | |
|         /// </summary>
 | |
|         /// <param name="anaseDataQualityRecord">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
| 	    public static int Update(AnaseDataQualityRecord anaseDataQualityRecord)
 | |
| 		{
 | |
| 			using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
 | |
| 			{
 | |
| 				conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return ExcuteUpdateCommand(cmd, anaseDataQualityRecord);
 | |
|                 }
 | |
| 			}
 | |
| 		}
 | |
| 		/// <summary>
 | |
|         /// 使用事务的更新方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="anaseDataQualityRecord">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Update(Connection connection,AnaseDataQualityRecord anaseDataQualityRecord)
 | |
|         {
 | |
|             return ExcuteUpdateCommand(connection.Command, anaseDataQualityRecord);
 | |
| 		}
 | |
| 		/// <summary>
 | |
|         /// 执行更新命令
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int ExcuteUpdateCommand(SqlCommand cmd, string oql, ParameterList parameters)
 | |
|         {
 | |
|             //解析过滤部份Sql语句
 | |
|             string updateString = SyntaxAnalyzer.ParseSql(oql, new AnaseDataQualityRecordMap());
 | |
|             cmd.CommandText = "update AnaseDataQualityRecord 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();
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 不使用事务的更新方法
 | |
|         /// </summary>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         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);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 使用事务的更新方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Update(Connection connection, string oql, ParameterList parameters)
 | |
|         {
 | |
|             return ExcuteUpdateCommand(connection.Command, oql, parameters);
 | |
|         }
 | |
| 		#endregion
 | |
| 		
 | |
| 		#region 查询实体集合
 | |
| 		/// <summary>
 | |
|         /// 执行Command获取对象列表
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
| 		/// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体类对象列表</returns>
 | |
|         public static List<AnaseDataQualityRecord> ExcuteSelectCommand(SqlCommand cmd,RecursiveType recursiveType,int recursiveDepth)
 | |
|         {
 | |
|             List<AnaseDataQualityRecord> anaseDataQualityRecordList = new List<AnaseDataQualityRecord>();
 | |
|             using (SqlDataReader dr = cmd.ExecuteReader())
 | |
|             {
 | |
|                 while (dr.Read())
 | |
|                 {
 | |
|                     AnaseDataQualityRecord anaseDataQualityRecord = DataReaderToEntity(dr);
 | |
|                     anaseDataQualityRecordList.Add(anaseDataQualityRecord);
 | |
|                 }
 | |
|             }
 | |
| 			foreach(AnaseDataQualityRecord anaseDataQualityRecord in anaseDataQualityRecordList)
 | |
| 			{
 | |
| 				//由外键获取相关实体
 | |
| 				if(recursiveType==RecursiveType.Parent && recursiveDepth!=0)
 | |
| 				{
 | |
| 					anaseDataQualityRecord.AdverseEventRef = DAdverseEvent.SelectSingle(cmd,anaseDataQualityRecord.AdverseEventId,recursiveType,recursiveDepth-1);
 | |
| 					//anaseDataQualityRecord.OperationRecordRef = DOperationRecord.SelectSingle(cmd,anaseDataQualityRecord.OperationRecordId,recursiveType,recursiveDepth-1);
 | |
| 				}
 | |
| 			}
 | |
| 			return anaseDataQualityRecordList;
 | |
|         }
 | |
| 		/// <summary>
 | |
|         /// 该函数在父对象的子对象集合被访问时调用,用于获取该父对象的所有子对象
 | |
|         /// </summary>
 | |
|         /// <param name="fieldName">外键字段</param>
 | |
|         /// <param name="parent">父对象</param>
 | |
|         /// <returns>实体类对象列表</returns>
 | |
|         public static List<AnaseDataQualityRecord> InvokeByParentEntity(string fieldName,object parent)
 | |
| 		{
 | |
| 			using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
| 					return InvokeByParent(cmd, fieldName,parent,0);
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 该函数由父对象调用,用于获取该父对象的所有子对象
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="fieldName">外键字段</param>
 | |
|         /// <param name="parent">父对象</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体类对象列表</returns>
 | |
|         public static List<AnaseDataQualityRecord> InvokeByParent(SqlCommand cmd, string fieldName,object parent,int recursiveDepth)
 | |
| 		{
 | |
|             List<AnaseDataQualityRecord> anaseDataQualityRecordList = new List<AnaseDataQualityRecord>();
 | |
| 			cmd.Parameters.Clear();
 | |
| 			if (fieldName.Equals("AdverseEventId",StringComparison.CurrentCultureIgnoreCase))
 | |
|             {
 | |
|                 AdverseEvent adverseEvent = parent as AdverseEvent;
 | |
| 				if (adverseEvent.Id.HasValue)
 | |
| 				{
 | |
| 					cmd.CommandText = "select * from AnaseDataQualityRecord where AdverseEventId=@paraValue";
 | |
| 					cmd.Parameters.Add(new SqlParameter("@paraValue", adverseEvent.Id));
 | |
| 				}
 | |
| 				else
 | |
| 				{
 | |
| 					cmd.CommandText = "select * from AnaseDataQualityRecord where AdverseEventId is null";
 | |
| 				}
 | |
| 				using (SqlDataReader dr = cmd.ExecuteReader())
 | |
| 				{
 | |
| 					while (dr.Read())
 | |
| 					{
 | |
| 						AnaseDataQualityRecord childAnaseDataQualityRecord = DataReaderToEntity(dr);
 | |
| 						anaseDataQualityRecordList.Add(childAnaseDataQualityRecord);
 | |
| 					}
 | |
| 				}
 | |
| 				foreach (AnaseDataQualityRecord childAnaseDataQualityRecord in anaseDataQualityRecordList)
 | |
| 				{	
 | |
| 					childAnaseDataQualityRecord.AdverseEventRef=adverseEvent;
 | |
| 					//其它外键实体
 | |
| 					//childAnaseDataQualityRecord.OperationRecordRef = DOperationRecord.SelectSingle(cmd,childAnaseDataQualityRecord.OperationRecordId,RecursiveType.Parent,0);
 | |
| 				}
 | |
|             }
 | |
| 			cmd.Parameters.Clear();
 | |
| 			return anaseDataQualityRecordList;
 | |
|         }
 | |
| 		/// <summary>
 | |
|         /// 执行查询命令
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
| 		/// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         public static List<AnaseDataQualityRecord> ExcuteSelectCommand(SqlCommand cmd, string oql, ParameterList parameters,RecursiveType recursiveType,int recursiveDepth)
 | |
|         {
 | |
|             //解析过滤部份Sql语句
 | |
|             string filterString = SyntaxAnalyzer.ParseSql(oql, new AnaseDataQualityRecordMap());
 | |
|             if (filterString != string.Empty)
 | |
|             {
 | |
| 				if(filterString.Trim().ToLower().IndexOf("order ")!=0)
 | |
|                 	filterString = " where " + filterString;
 | |
|             }
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "select * from AnaseDataQualityRecord " + filterString;
 | |
|             //添加参数
 | |
|             if (parameters != null)
 | |
|             {
 | |
|                 foreach (string key in parameters.Keys)
 | |
|                 {
 | |
|                     cmd.Parameters.Add(new SqlParameter(key, parameters[key]));
 | |
|                 }
 | |
|             }
 | |
|             return ExcuteSelectCommand(cmd, recursiveType, recursiveDepth);
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 根据对象查询语句查询实体集合
 | |
|         /// </summary>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         public static List<AnaseDataQualityRecord> Select()
 | |
|         {
 | |
| 			using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     cmd.CommandText = "select * from AnaseDataQualityRecord";
 | |
|                     return ExcuteSelectCommand(cmd, RecursiveType.Parent, 1);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 		/// <summary>
 | |
|         /// 根据对象查询语句查询实体集合
 | |
|         /// </summary>
 | |
| 		/// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         public static List<AnaseDataQualityRecord> Select(RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
| 			using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     cmd.CommandText = "select * from AnaseDataQualityRecord";
 | |
|                     return ExcuteSelectCommand(cmd, recursiveType, recursiveDepth);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 根据对象查询语句查询实体集合
 | |
|         /// </summary>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         public static List<AnaseDataQualityRecord> 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);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 根据对象查询语句查询实体集合
 | |
|         /// </summary>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
| 		/// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         public static List<AnaseDataQualityRecord> 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);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 根据对象查询语句查询实体集合(启用事务)
 | |
|         /// </summary>
 | |
|         /// <param name="connection">连接对象</param>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
| 		/// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         public static List<AnaseDataQualityRecord> Select(Connection connection, string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             return ExcuteSelectCommand(connection.Command, oql, parameters,recursiveType, recursiveDepth);
 | |
|         }
 | |
| 		#endregion
 | |
| 		
 | |
| 		#region 查询单个实体
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 递归查询单个实体
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
| 		/// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体对象</returns>
 | |
| 		public static AnaseDataQualityRecord ExcuteSelectSingleCommand(SqlCommand cmd,RecursiveType recursiveType,int recursiveDepth)
 | |
| 		{
 | |
| 			AnaseDataQualityRecord anaseDataQualityRecord=null;
 | |
| 			using (SqlDataReader dr = cmd.ExecuteReader())
 | |
|             {
 | |
| 			    if(dr.Read())
 | |
| 				    anaseDataQualityRecord = DataReaderToEntity(dr);
 | |
| 			}
 | |
| 			if(anaseDataQualityRecord==null)
 | |
| 			    return anaseDataQualityRecord;
 | |
| 			//由外键获取相关实体
 | |
| 			if(recursiveType==RecursiveType.Parent && recursiveDepth!=0)
 | |
| 			{
 | |
| 	        	anaseDataQualityRecord.AdverseEventRef = DAdverseEvent.SelectSingle(cmd,anaseDataQualityRecord.AdverseEventId,recursiveType,recursiveDepth-1);
 | |
| 	        	//anaseDataQualityRecord.OperationRecordRef = DOperationRecord.SelectSingle(cmd,anaseDataQualityRecord.OperationRecordId,recursiveType,recursiveDepth-1);
 | |
| 			}
 | |
|             return anaseDataQualityRecord;
 | |
| 		}
 | |
| 		/// <summary>
 | |
|         /// 更据对象查询语句递归查询单个实体
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
| 		/// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体对象</returns>
 | |
|         public static AnaseDataQualityRecord ExcuteSelectSingleCommand(SqlCommand cmd, string oql, ParameterList parameters,RecursiveType recursiveType,int recursiveDepth)
 | |
|         {
 | |
|             //解析过滤部份Sql语句
 | |
|             string filterString = SyntaxAnalyzer.ParseSql(oql, new AnaseDataQualityRecordMap());
 | |
| 			if(filterString!=string.Empty)
 | |
| 			{
 | |
| 			    filterString=" where "+filterString;
 | |
| 			}
 | |
|             cmd.CommandText = "select * from AnaseDataQualityRecord " + 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);
 | |
|         }
 | |
| 				
 | |
| 		/// <summary>
 | |
|         /// 更据对象查询语句递归查询单个实体
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
| 		/// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体对象</returns>
 | |
|         public static AnaseDataQualityRecord 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);
 | |
|                 }   
 | |
|             } 
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 更据对象查询语句查询单个实体
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>实体对象</returns>
 | |
|         public static AnaseDataQualityRecord SelectSingle(string oql, ParameterList parameters)
 | |
|         {
 | |
|             return SelectSingle(oql,parameters,RecursiveType.Parent,1);
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 更据对象查询语句并启用事务查询单个实体
 | |
|         /// </summary>
 | |
|         /// <param name="connection">连接对象</param>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>实体对象</returns>
 | |
|         public static AnaseDataQualityRecord SelectSingle(Connection connection, string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             return ExcuteSelectSingleCommand(connection.Command, oql, parameters, recursiveType, recursiveDepth);
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 更据主键值递归查询单个实体
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="id">主键值</param>
 | |
| 		/// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体对象</returns>
 | |
|         public static AnaseDataQualityRecord SelectSingle(SqlCommand cmd, int? id,RecursiveType recursiveType,int recursiveDepth)
 | |
| 		{
 | |
| 		    cmd.Parameters.Clear();
 | |
| 			if(id.HasValue)
 | |
| 			{
 | |
| 		    	cmd.CommandText = "select * from AnaseDataQualityRecord where Id=@pk";
 | |
| 				cmd.Parameters.Add(new SqlParameter("@pk",id.Value));
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 			    cmd.CommandText = "select * from AnaseDataQualityRecord where Id is null";
 | |
| 			}
 | |
| 			return ExcuteSelectSingleCommand(cmd, recursiveType, recursiveDepth);
 | |
| 		}
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 按主键字段查询特定实体
 | |
|         /// </summary>
 | |
|         /// <param name="id">主键值</param>
 | |
|         /// <returns>实体类对象</returns>
 | |
|         public static AnaseDataQualityRecord SelectSingle(int? id)
 | |
|         {
 | |
|             using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return SelectSingle(cmd,id,RecursiveType.Parent,1);
 | |
|                 }   
 | |
|             } 
 | |
|         }
 | |
| 		/// <summary>
 | |
|         /// 按主键字段查询特定实体
 | |
|         /// </summary>
 | |
|         /// <param name="id">主键值</param>
 | |
| 		/// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体类对象</returns>
 | |
|         public static AnaseDataQualityRecord 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);
 | |
|                 }   
 | |
|             } 
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 使用事务并按主键字段查询特定实体
 | |
|         /// </summary>
 | |
| 		/// <param name="connection">连接对象</param>
 | |
|         /// <param name="id">主键值</param>
 | |
|         /// <returns>实体类对象</returns>
 | |
|         public static AnaseDataQualityRecord SelectSingle(Connection connection,int? id, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
| 			return SelectSingle(connection.Command, id, recursiveType, recursiveDepth);
 | |
|         }
 | |
| 		#endregion
 | |
| 		
 | |
| 				
 | |
| 		/// <summary>
 | |
|         /// 从DataReader中取出值生成实体对象
 | |
|         /// </summary>
 | |
|         /// <param name="searcher">查询对象</param>
 | |
|         /// <returns>过滤条件字符串</returns>
 | |
| 		private static AnaseDataQualityRecord DataReaderToEntity(SqlDataReader dr)
 | |
| 		{
 | |
| 		    AnaseDataQualityRecord entity = new AnaseDataQualityRecord ();
 | |
| 			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["AdverseEventId"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.AdverseEventId=Convert.ToInt32(dr["AdverseEventId"]);
 | |
| 			}
 | |
| 			if(dr["AdverseEvenLevel"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.AdverseEvenLevel=dr["AdverseEvenLevel"].ToString();
 | |
| 			}
 | |
| 			if(dr["AdverseEvenName"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.AdverseEvenName=dr["AdverseEvenName"].ToString();
 | |
| 			}
 | |
| 			if(dr["IsValid"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.IsValid=dr["IsValid"].ToString();
 | |
| 			}
 | |
| 			if(dr["OperatorId"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.OperatorId=Convert.ToInt32(dr["OperatorId"]);
 | |
| 			}
 | |
| 			if(dr["OpeatorTime"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.OpeatorTime=Convert.ToDateTime(dr["OpeatorTime"]);
 | |
| 			}
 | |
| 			return entity;
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 |