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