632 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			632 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Data;
 | |
| using System.Data.SqlClient;
 | |
| using System.Collections;
 | |
| using AIMSModel;
 | |
| using AIMSObjectQuery;
 | |
| using System.Collections.Generic;
 | |
| using HelperDB;
 | |
| 
 | |
| namespace AIMSDAL
 | |
| {
 | |
|     public partial class DNoticeContent
 | |
| 	{
 | |
|         #region 插入实体操作部份
 | |
|         /// <summary>
 | |
|         /// 插入
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="noticeContent">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
|         public static int Insert(SqlCommand cmd, NoticeContent noticeContent)
 | |
|         {
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "insert into NoticeContent (Contents,ReleaseTime,ReleaseCount,OperatorId,OperatorTime,SendType,SystemType) values (@Contents,@ReleaseTime,@ReleaseCount,@OperatorId,@OperatorTime,@SendType,@SystemType);select @@identity";
 | |
|             //从实体中取出值放入Command的参数列表
 | |
|             cmd.Parameters.Add(new SqlParameter("@Contents", noticeContent.Contents == null ? (object)DBNull.Value : (object)noticeContent.Contents));
 | |
|             cmd.Parameters.Add(new SqlParameter("@ReleaseTime", noticeContent.ReleaseTime.HasValue ? (object)noticeContent.ReleaseTime.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@ReleaseCount", noticeContent.ReleaseCount.HasValue ? (object)noticeContent.ReleaseCount.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@OperatorId", noticeContent.OperatorId.HasValue ? (object)noticeContent.OperatorId.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@OperatorTime", noticeContent.OperatorTime.HasValue ? (object)noticeContent.OperatorTime.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@SendType", noticeContent.SendType.HasValue ? (object)noticeContent.SendType.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@SystemType", noticeContent.SystemType.HasValue ? (object)noticeContent.SystemType.Value : (object)DBNull.Value));
 | |
|             return Convert.ToInt32(cmd.ExecuteScalar());
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 不使用事务的插入方法
 | |
|         /// </summary>
 | |
|         /// <param name="noticeContent">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
|         public static int Insert(NoticeContent noticeContent)
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return Insert(cmd, noticeContent);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 使用事务的插入方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="noticeContent">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
|         public static int Insert(Connection connection, NoticeContent noticeContent)
 | |
|         {
 | |
|             return Insert(connection.Command, noticeContent);
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 删除实体操作
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 删除
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="noticeContent">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int ExcuteDeleteCommand(SqlCommand cmd, NoticeContent noticeContent)
 | |
|         {
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "delete from NoticeContent where Id=@Id";
 | |
|             //从实体中取出值放入Command的参数列表
 | |
|             cmd.Parameters.Add(new SqlParameter("@Id", noticeContent.Id));
 | |
|             return cmd.ExecuteNonQuery();
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 不使用事务的删除方法
 | |
|         /// </summary>
 | |
|         /// <param name="noticeContent">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Delete(NoticeContent noticeContent)
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return ExcuteDeleteCommand(cmd, noticeContent);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 使用事务的删除方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="noticeContent">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Delete(Connection connection, NoticeContent noticeContent)
 | |
|         {
 | |
|             return ExcuteDeleteCommand(connection.Command, noticeContent);
 | |
|         }
 | |
| 
 | |
|         /// <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 NoticeContentMap());
 | |
|             if (filterString != string.Empty)
 | |
|             {
 | |
|                 filterString = " where " + filterString;
 | |
|             }
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "delete from NoticeContent " + 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="noticeContent">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int ExcuteUpdateCommand(SqlCommand cmd, NoticeContent noticeContent)
 | |
|         {
 | |
|             cmd.CommandText = "update NoticeContent set Contents=@Contents,ReleaseTime=@ReleaseTime,ReleaseCount=@ReleaseCount,OperatorId=@OperatorId,OperatorTime=@OperatorTime,SendType=@SendType,SystemType=@SystemType where Id=@Id";
 | |
|             //从实体中取出值放入Command的参数列表
 | |
|             cmd.Parameters.Add(new SqlParameter("@Contents", noticeContent.Contents == null ? (object)DBNull.Value : (object)noticeContent.Contents));
 | |
|             cmd.Parameters.Add(new SqlParameter("@ReleaseTime", noticeContent.ReleaseTime.HasValue ? (object)noticeContent.ReleaseTime.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@ReleaseCount", noticeContent.ReleaseCount.HasValue ? (object)noticeContent.ReleaseCount.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@OperatorId", noticeContent.OperatorId.HasValue ? (object)noticeContent.OperatorId.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@OperatorTime", noticeContent.OperatorTime.HasValue ? (object)noticeContent.OperatorTime.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@SendType", noticeContent.SendType.HasValue ? (object)noticeContent.SendType.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@SystemType", noticeContent.SystemType.HasValue ? (object)noticeContent.SystemType.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Id", noticeContent.Id));
 | |
|             return cmd.ExecuteNonQuery();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 不使用事务的更新方法
 | |
|         /// </summary>
 | |
|         /// <param name="noticeContent">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Update(NoticeContent noticeContent)
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return ExcuteUpdateCommand(cmd, noticeContent);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 使用事务的更新方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="noticeContent">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         public static int Update(Connection connection, NoticeContent noticeContent)
 | |
|         {
 | |
|             return ExcuteUpdateCommand(connection.Command, noticeContent);
 | |
|         }
 | |
|         /// <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 NoticeContentMap());
 | |
|             cmd.CommandText = "update NoticeContent 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<NoticeContent> ExcuteSelectCommand(SqlCommand cmd, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             List<NoticeContent> noticeContentList = new List<NoticeContent>();
 | |
|             using (SqlDataReader dr = cmd.ExecuteReader())
 | |
|             {
 | |
|                 while (dr.Read())
 | |
|                 {
 | |
|                     NoticeContent noticeContent = DataReaderToEntity(dr);
 | |
|                     noticeContentList.Add(noticeContent);
 | |
|                 }
 | |
|             }
 | |
|             return noticeContentList;
 | |
|         }
 | |
|         /// <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<NoticeContent> ExcuteSelectCommand(SqlCommand cmd, string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             //解析过滤部份Sql语句
 | |
|             string filterString = SyntaxAnalyzer.ParseSql(oql, new NoticeContentMap());
 | |
|             if (filterString != string.Empty)
 | |
|             {
 | |
|                 if (filterString.Trim().ToLower().IndexOf("order ") != 0)
 | |
|                     filterString = " where " + filterString;
 | |
|             }
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "select * from NoticeContent " + 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<NoticeContent> Select()
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     cmd.CommandText = "select * from NoticeContent";
 | |
|                     return ExcuteSelectCommand(cmd, RecursiveType.Parent, 1);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 根据对象查询语句查询实体集合
 | |
|         /// </summary>
 | |
|         /// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         public static List<NoticeContent> Select(RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     cmd.CommandText = "select * from NoticeContent";
 | |
|                     return ExcuteSelectCommand(cmd, recursiveType, recursiveDepth);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据对象查询语句查询实体集合
 | |
|         /// </summary>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         public static List<NoticeContent> 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<NoticeContent> 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<NoticeContent> 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 NoticeContent ExcuteSelectSingleCommand(SqlCommand cmd, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             NoticeContent noticeContent = null;
 | |
|             using (SqlDataReader dr = cmd.ExecuteReader())
 | |
|             {
 | |
|                 if (dr.Read())
 | |
|                     noticeContent = DataReaderToEntity(dr);
 | |
|             }
 | |
|             if (noticeContent == null)
 | |
|                 return noticeContent;
 | |
|             return noticeContent;
 | |
|         }
 | |
|         /// <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 NoticeContent ExcuteSelectSingleCommand(SqlCommand cmd, string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             //解析过滤部份Sql语句
 | |
|             string filterString = SyntaxAnalyzer.ParseSql(oql, new NoticeContentMap());
 | |
|             if (filterString != string.Empty)
 | |
|             {
 | |
|                 filterString = " where " + filterString;
 | |
|             }
 | |
|             cmd.CommandText = "select * from NoticeContent " + 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 NoticeContent 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 NoticeContent 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 NoticeContent 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 NoticeContent SelectSingle(SqlCommand cmd, int? id, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             cmd.Parameters.Clear();
 | |
|             if (id.HasValue)
 | |
|             {
 | |
|                 cmd.CommandText = "select * from NoticeContent where Id=@pk";
 | |
|                 cmd.Parameters.Add(new SqlParameter("@pk", id.Value));
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 cmd.CommandText = "select * from NoticeContent where Id is null";
 | |
|             }
 | |
|             return ExcuteSelectSingleCommand(cmd, recursiveType, recursiveDepth);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 按主键字段查询特定实体
 | |
|         /// </summary>
 | |
|         /// <param name="id">主键值</param>
 | |
|         /// <returns>实体类对象</returns>
 | |
|         public static NoticeContent 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 NoticeContent 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 NoticeContent 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 NoticeContent DataReaderToEntity(SqlDataReader dr)
 | |
|         {
 | |
|             NoticeContent entity = new NoticeContent();
 | |
|             if (dr["Id"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Id = Convert.ToInt32(dr["Id"]);
 | |
|             }
 | |
|             if (dr["Contents"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Contents = dr["Contents"].ToString();
 | |
|             }
 | |
|             if (dr["ReleaseTime"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.ReleaseTime = Convert.ToInt32(dr["ReleaseTime"]);
 | |
|             }
 | |
|             if (dr["ReleaseCount"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.ReleaseCount = Convert.ToInt32(dr["ReleaseCount"]);
 | |
|             }
 | |
|             if (dr["OperatorId"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.OperatorId = Convert.ToInt32(dr["OperatorId"]);
 | |
|             }
 | |
|             if (dr["OperatorTime"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.OperatorTime = Convert.ToDateTime(dr["OperatorTime"]);
 | |
|             }
 | |
|             if (dr["SendType"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.SendType = Convert.ToInt32(dr["SendType"]);
 | |
|             }
 | |
|             if (dr["SystemType"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.SystemType = Convert.ToInt32(dr["SystemType"]);
 | |
|             }
 | |
|             return entity;
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 查询NoticeContent的内容
 | |
|         /// </summary>
 | |
|         /// <returns></returns>
 | |
|         public static DataTable GetNoticeContent(DateTime time)
 | |
|         {
 | |
|             DataTable dt = DBHelper.GetDataTable("select * from NoticeContent where OperatorTime>'" + time + "' order by OperatorTime desc ");
 | |
|             return dt;
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 |