639 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			639 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 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 DInstrumentRegistration
 | |
| 	{
 | |
| 	    #region 插入实体操作部份
 | |
| 	    /// <summary>
 | |
|         /// 插入
 | |
|         /// </summary>
 | |
| 		/// <param name="cmd">Command对象</param>
 | |
|         /// <param name="instrumentRegistration">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
| 		public static int Insert(SqlCommand cmd, InstrumentRegistration instrumentRegistration)
 | |
| 		{
 | |
| 		    cmd.Parameters.Clear();
 | |
| 			cmd.CommandText = "insert into InstrumentRegistration (Name,Numbers,Performance,Intact,OperatorName,OperatorTime,Remark,IsClean) values (@Name,@Numbers,@Performance,@Intact,@OperatorName,@OperatorTime,@Remark,@IsClean)";
 | |
| 			//从实体中取出值放入Command的参数列表
 | |
| 			cmd.Parameters.Add(new SqlParameter("@Name",instrumentRegistration.Name==null?(object)DBNull.Value:(object)instrumentRegistration.Name));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@Numbers",instrumentRegistration.Numbers==null?(object)DBNull.Value:(object)instrumentRegistration.Numbers));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@Performance",instrumentRegistration.Performance==null?(object)DBNull.Value:(object)instrumentRegistration.Performance));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@Intact",instrumentRegistration.Intact==null?(object)DBNull.Value:(object)instrumentRegistration.Intact));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@OperatorName",instrumentRegistration.OperatorName==null?(object)DBNull.Value:(object)instrumentRegistration.OperatorName));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@OperatorTime",instrumentRegistration.OperatorTime.HasValue?(object)instrumentRegistration.OperatorTime.Value:(object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Remark", instrumentRegistration.Remark == null ? (object)DBNull.Value : (object)instrumentRegistration.Remark));
 | |
|             cmd.Parameters.Add(new SqlParameter("@IsClean", instrumentRegistration.IsClean == null ? (object)DBNull.Value : (object)instrumentRegistration.IsClean));
 | |
|             return cmd.ExecuteNonQuery();
 | |
| 		}
 | |
| 	    /// <summary>
 | |
|         /// 不使用事务的插入方法
 | |
|         /// </summary>
 | |
|         /// <param name="instrumentRegistration">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
| 	    public static int Insert(InstrumentRegistration instrumentRegistration)
 | |
| 		{
 | |
| 			using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
 | |
| 			{
 | |
| 				conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return Insert(cmd, instrumentRegistration);
 | |
|                 }
 | |
| 			}
 | |
| 		}
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 使用事务的插入方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="instrumentRegistration">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
|         public static int Insert(Connection connection,InstrumentRegistration instrumentRegistration)
 | |
|         {
 | |
|             return Insert(connection.Command, instrumentRegistration);
 | |
|         }
 | |
| 		#endregion
 | |
| 		
 | |
| 		#region 删除实体操作
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 删除
 | |
|         /// </summary>
 | |
| 		/// <param name="cmd">Command对象</param>
 | |
|         /// <param name="instrumentRegistration">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
| 		public static int ExcuteDeleteCommand(SqlCommand cmd, InstrumentRegistration instrumentRegistration)
 | |
|         {
 | |
| 			cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "delete from InstrumentRegistration where Id=@Id";
 | |
|             //从实体中取出值放入Command的参数列表
 | |
| 		    cmd.Parameters.Add(new SqlParameter("@Id", instrumentRegistration.Id));
 | |
|             return cmd.ExecuteNonQuery();
 | |
|         }
 | |
| 		/// <summary>
 | |
|         /// 不使用事务的删除方法
 | |
|         /// </summary>
 | |
|         /// <param name="instrumentRegistration">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Delete(InstrumentRegistration instrumentRegistration)
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return ExcuteDeleteCommand(cmd, instrumentRegistration);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 		/// <summary>
 | |
|         /// 使用事务的删除方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="instrumentRegistration">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Delete(Connection connection,InstrumentRegistration instrumentRegistration)
 | |
|         {
 | |
|             return  ExcuteDeleteCommand(connection.Command, instrumentRegistration);
 | |
| 		}
 | |
| 		
 | |
| 		/// <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 InstrumentRegistrationMap());
 | |
|             if (filterString != string.Empty)
 | |
|             {
 | |
|                 filterString = " where " + filterString;
 | |
|             }
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "delete from InstrumentRegistration " + 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="instrumentRegistration">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
| 		public static int ExcuteUpdateCommand(SqlCommand cmd, InstrumentRegistration instrumentRegistration)
 | |
| 		{
 | |
| 		    cmd.CommandText = "update InstrumentRegistration set Name=@Name,Numbers=@Numbers,Performance=@Performance,Intact=@Intact,OperatorName=@OperatorName,OperatorTime=@OperatorTime,Remark=@Remark,IsClean=@IsClean where Id=@Id";
 | |
| 			//从实体中取出值放入Command的参数列表
 | |
| 			cmd.Parameters.Add(new SqlParameter("@Name",instrumentRegistration.Name==null?(object)DBNull.Value:(object)instrumentRegistration.Name));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@Numbers",instrumentRegistration.Numbers==null?(object)DBNull.Value:(object)instrumentRegistration.Numbers));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@Performance",instrumentRegistration.Performance==null?(object)DBNull.Value:(object)instrumentRegistration.Performance));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@Intact",instrumentRegistration.Intact==null?(object)DBNull.Value:(object)instrumentRegistration.Intact));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@OperatorName",instrumentRegistration.OperatorName==null?(object)DBNull.Value:(object)instrumentRegistration.OperatorName));
 | |
| 			cmd.Parameters.Add(new SqlParameter("@OperatorTime",instrumentRegistration.OperatorTime.HasValue?(object)instrumentRegistration.OperatorTime.Value:(object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Remark", instrumentRegistration.Remark == null ? (object)DBNull.Value : (object)instrumentRegistration.Remark));
 | |
|             cmd.Parameters.Add(new SqlParameter("@IsClean", instrumentRegistration.IsClean == null ? (object)DBNull.Value : (object)instrumentRegistration.IsClean));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Id", instrumentRegistration.Id));
 | |
|             return cmd.ExecuteNonQuery();
 | |
| 		}
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 不使用事务的更新方法
 | |
|         /// </summary>
 | |
|         /// <param name="instrumentRegistration">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
| 	    public static int Update(InstrumentRegistration instrumentRegistration)
 | |
| 		{
 | |
| 			using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
 | |
| 			{
 | |
| 				conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return ExcuteUpdateCommand(cmd, instrumentRegistration);
 | |
|                 }
 | |
| 			}
 | |
| 		}
 | |
| 		/// <summary>
 | |
|         /// 使用事务的更新方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="instrumentRegistration">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Update(Connection connection,InstrumentRegistration instrumentRegistration)
 | |
|         {
 | |
|             return ExcuteUpdateCommand(connection.Command, instrumentRegistration);
 | |
| 		}
 | |
| 		/// <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 InstrumentRegistrationMap());
 | |
|             cmd.CommandText = "update InstrumentRegistration 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<InstrumentRegistration> ExcuteSelectCommand(SqlCommand cmd,RecursiveType recursiveType,int recursiveDepth)
 | |
|         {
 | |
|             List<InstrumentRegistration> instrumentRegistrationList = new List<InstrumentRegistration>();
 | |
|             using (SqlDataReader dr = cmd.ExecuteReader())
 | |
|             {
 | |
|                 while (dr.Read())
 | |
|                 {
 | |
|                     InstrumentRegistration instrumentRegistration = DataReaderToEntity(dr);
 | |
|                     instrumentRegistrationList.Add(instrumentRegistration);
 | |
|                 }
 | |
|             }
 | |
| 			return instrumentRegistrationList;
 | |
|         }
 | |
| 		/// <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<InstrumentRegistration> ExcuteSelectCommand(SqlCommand cmd, string oql, ParameterList parameters,RecursiveType recursiveType,int recursiveDepth)
 | |
|         {
 | |
|             //解析过滤部份Sql语句
 | |
|             string filterString = SyntaxAnalyzer.ParseSql(oql, new InstrumentRegistrationMap());
 | |
|             if (filterString != string.Empty)
 | |
|             {
 | |
| 				if(filterString.Trim().ToLower().IndexOf("order ")!=0)
 | |
|                 	filterString = " where " + filterString;
 | |
|             }
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "select * from InstrumentRegistration " + 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<InstrumentRegistration> Select()
 | |
|         {
 | |
| 			using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     cmd.CommandText = "select * from InstrumentRegistration";
 | |
|                     return ExcuteSelectCommand(cmd, RecursiveType.Parent, 1);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 		/// <summary>
 | |
|         /// 根据对象查询语句查询实体集合
 | |
|         /// </summary>
 | |
| 		/// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         public static List<InstrumentRegistration> Select(RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
| 			using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     cmd.CommandText = "select * from InstrumentRegistration";
 | |
|                     return ExcuteSelectCommand(cmd, recursiveType, recursiveDepth);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 根据对象查询语句查询实体集合
 | |
|         /// </summary>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         public static List<InstrumentRegistration> 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<InstrumentRegistration> 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<InstrumentRegistration> 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 InstrumentRegistration ExcuteSelectSingleCommand(SqlCommand cmd,RecursiveType recursiveType,int recursiveDepth)
 | |
| 		{
 | |
| 			InstrumentRegistration instrumentRegistration=null;
 | |
| 			using (SqlDataReader dr = cmd.ExecuteReader())
 | |
|             {
 | |
| 			    if(dr.Read())
 | |
| 				    instrumentRegistration = DataReaderToEntity(dr);
 | |
| 			}
 | |
| 			if(instrumentRegistration==null)
 | |
| 			    return instrumentRegistration;
 | |
|             return instrumentRegistration;
 | |
| 		}
 | |
| 		/// <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 InstrumentRegistration ExcuteSelectSingleCommand(SqlCommand cmd, string oql, ParameterList parameters,RecursiveType recursiveType,int recursiveDepth)
 | |
|         {
 | |
|             //解析过滤部份Sql语句
 | |
|             string filterString = SyntaxAnalyzer.ParseSql(oql, new InstrumentRegistrationMap());
 | |
| 			if(filterString!=string.Empty)
 | |
| 			{
 | |
| 			    filterString=" where "+filterString;
 | |
| 			}
 | |
|             cmd.CommandText = "select * from InstrumentRegistration " + 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 InstrumentRegistration 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 InstrumentRegistration 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 InstrumentRegistration 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 InstrumentRegistration SelectSingle(SqlCommand cmd, int? id,RecursiveType recursiveType,int recursiveDepth)
 | |
| 		{
 | |
| 		    cmd.Parameters.Clear();
 | |
| 			if(id.HasValue)
 | |
| 			{
 | |
| 		    	cmd.CommandText = "select * from InstrumentRegistration where Id=@pk";
 | |
| 				cmd.Parameters.Add(new SqlParameter("@pk",id.Value));
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 			    cmd.CommandText = "select * from InstrumentRegistration where Id is null";
 | |
| 			}
 | |
| 			return ExcuteSelectSingleCommand(cmd, recursiveType, recursiveDepth);
 | |
| 		}
 | |
| 		
 | |
| 		/// <summary>
 | |
|         /// 按主键字段查询特定实体
 | |
|         /// </summary>
 | |
|         /// <param name="id">主键值</param>
 | |
|         /// <returns>实体类对象</returns>
 | |
|         public static InstrumentRegistration 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 InstrumentRegistration 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 InstrumentRegistration 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 InstrumentRegistration DataReaderToEntity(SqlDataReader dr)
 | |
| 		{
 | |
| 		    InstrumentRegistration entity = new InstrumentRegistration ();
 | |
| 			if(dr["Id"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.Id=Convert.ToInt32(dr["Id"]);
 | |
| 			}
 | |
| 			if(dr["Name"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.Name=dr["Name"].ToString();
 | |
| 			}
 | |
| 			if(dr["Numbers"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.Numbers=dr["Numbers"].ToString();
 | |
| 			}
 | |
| 			if(dr["Performance"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.Performance=dr["Performance"].ToString();
 | |
| 			}
 | |
| 			if(dr["Intact"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.Intact=dr["Intact"].ToString();
 | |
| 			}
 | |
| 			if(dr["OperatorName"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.OperatorName=dr["OperatorName"].ToString();
 | |
| 			}
 | |
| 			if(dr["OperatorTime"]!=System.DBNull.Value)
 | |
| 			{
 | |
| 			    entity.OperatorTime=Convert.ToDateTime(dr["OperatorTime"]);
 | |
| 			}
 | |
|             if (dr["Remark"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Remark = dr["Remark"].ToString();
 | |
|             }
 | |
|             try
 | |
|             {
 | |
|                 if (dr["IsClean"] != System.DBNull.Value)
 | |
|                 {
 | |
|                     entity.IsClean = dr["IsClean"].ToString();
 | |
|                     if (string.IsNullOrEmpty(entity.IsClean))
 | |
|                         entity.IsClean = "";
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     entity.IsClean = "";
 | |
|                 }
 | |
| 
 | |
|             }
 | |
|             catch { }
 | |
|             return entity;
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 |