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