757 lines
		
	
	
		
			36 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			757 lines
		
	
	
		
			36 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 DOrisPatient
 | |
|     {
 | |
|         #region 插入实体操作部份
 | |
|         /// <summary>
 | |
|         /// 插入
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="orisPatient">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
|         internal static int Insert(SqlCommand cmd, OrisPatient orisPatient)
 | |
|         {
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "insert into Oris_Patient (MdrecNo,ArchivesNo,Name,Sex,BirthDay,Age,Height,Weight,DepId,Illdistrict,SickBed,BloodType,RHBloodType,PatientKind,InHosDate,IdentityCard,Contacts,ContactsPhone,OperatorNo,OperatorName,OperateDate,PatientType,HisPatientId,VisitTimes,Address,Nation,Extend1,Extend2,Extend3,Extend4,Extend5) values (@MdrecNo,@ArchivesNo,@Name,@Sex,@BirthDay,@Age,@Height,@Weight,@DepId,@Illdistrict,@SickBed,@BloodType,@RHBloodType,@PatientKind,@InHosDate,@IdentityCard,@Contacts,@ContactsPhone,@OperatorNo,@OperatorName,@OperateDate,@PatientType,@HisPatientId,@VisitTimes,@Address,@Nation,@Extend1,@Extend2,@Extend3,@Extend4,@Extend5);select @@identity";
 | |
|             //从实体中取出值放入Command的参数列表
 | |
|             cmd.Parameters.Add(new SqlParameter("@MdrecNo", orisPatient.MdrecNo == null ? (object)DBNull.Value : (object)orisPatient.MdrecNo));
 | |
|             cmd.Parameters.Add(new SqlParameter("@ArchivesNo", orisPatient.ArchivesNo == null ? (object)DBNull.Value : (object)orisPatient.ArchivesNo));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Name", orisPatient.Name == null ? (object)DBNull.Value : (object)orisPatient.Name));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Sex", orisPatient.Sex == null ? (object)DBNull.Value : (object)orisPatient.Sex));
 | |
|             cmd.Parameters.Add(new SqlParameter("@BirthDay", orisPatient.BirthDay.HasValue ? (object)orisPatient.BirthDay.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Age", orisPatient.Age == null ? (object)DBNull.Value : (object)orisPatient.Age));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Height", orisPatient.Height == null ? (object)DBNull.Value : (object)orisPatient.Height));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Weight", orisPatient.Weight == null ? (object)DBNull.Value : (object)orisPatient.Weight));
 | |
|             cmd.Parameters.Add(new SqlParameter("@DepId", orisPatient.DepId.HasValue ? (object)orisPatient.DepId.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Illdistrict", orisPatient.Illdistrict == null ? (object)DBNull.Value : (object)orisPatient.Illdistrict));
 | |
|             cmd.Parameters.Add(new SqlParameter("@SickBed", orisPatient.SickBed == null ? (object)DBNull.Value : (object)orisPatient.SickBed));
 | |
|             cmd.Parameters.Add(new SqlParameter("@BloodType", orisPatient.BloodType == null ? (object)DBNull.Value : (object)orisPatient.BloodType));
 | |
|             cmd.Parameters.Add(new SqlParameter("@RHBloodType", orisPatient.RHBloodType == null ? (object)DBNull.Value : (object)orisPatient.RHBloodType));
 | |
|             cmd.Parameters.Add(new SqlParameter("@PatientKind", orisPatient.PatientKind == null ? (object)DBNull.Value : (object)orisPatient.PatientKind));
 | |
|             cmd.Parameters.Add(new SqlParameter("@InHosDate", orisPatient.InHosDate.HasValue ? (object)orisPatient.InHosDate.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@IdentityCard", orisPatient.IdentityCard == null ? (object)DBNull.Value : (object)orisPatient.IdentityCard));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Contacts", orisPatient.Contacts == null ? (object)DBNull.Value : (object)orisPatient.Contacts));
 | |
|             cmd.Parameters.Add(new SqlParameter("@ContactsPhone", orisPatient.ContactsPhone == null ? (object)DBNull.Value : (object)orisPatient.ContactsPhone));
 | |
|             cmd.Parameters.Add(new SqlParameter("@OperatorNo", orisPatient.OperatorNo == null ? (object)DBNull.Value : (object)orisPatient.OperatorNo));
 | |
|             cmd.Parameters.Add(new SqlParameter("@OperatorName", orisPatient.OperatorName == null ? (object)DBNull.Value : (object)orisPatient.OperatorName));
 | |
|             cmd.Parameters.Add(new SqlParameter("@OperateDate", orisPatient.OperateDate.HasValue ? (object)orisPatient.OperateDate.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@PatientType", orisPatient.PatientType == null ? (object)DBNull.Value : (object)orisPatient.PatientType));
 | |
|             cmd.Parameters.Add(new SqlParameter("@HisPatientId", orisPatient.HisPatientId == null ? (object)DBNull.Value : (object)orisPatient.HisPatientId));
 | |
|             cmd.Parameters.Add(new SqlParameter("@VisitTimes", orisPatient.VisitTimes == null ? (object)DBNull.Value : (object)orisPatient.VisitTimes));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Address", orisPatient.Address == null ? (object)DBNull.Value : (object)orisPatient.Address));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Nation", orisPatient.Nation == null ? (object)DBNull.Value : (object)orisPatient.Nation));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Extend1", orisPatient.Extend1 == null ? (object)DBNull.Value : (object)orisPatient.Extend1));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Extend2", orisPatient.Extend2 == null ? (object)DBNull.Value : (object)orisPatient.Extend2));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Extend3", orisPatient.Extend3 == null ? (object)DBNull.Value : (object)orisPatient.Extend3));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Extend4", orisPatient.Extend4 == null ? (object)DBNull.Value : (object)orisPatient.Extend4));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Extend5", orisPatient.Extend5 == null ? (object)DBNull.Value : (object)orisPatient.Extend5));
 | |
|             return Convert.ToInt32(cmd.ExecuteScalar());
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 不使用事务的插入方法
 | |
|         /// </summary>
 | |
|         /// <param name="orisPatient">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
|         internal static int Insert(OrisPatient orisPatient)
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return Insert(cmd, orisPatient);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 使用事务的插入方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="orisPatient">实体类对象</param>
 | |
|         /// <returns>标识列值或影响的记录行数</returns>
 | |
|         internal static int Insert(Connection connection, OrisPatient orisPatient)
 | |
|         {
 | |
|             return Insert(connection.Command, orisPatient);
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 删除实体操作
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 删除
 | |
|         /// </summary>
 | |
|         /// <param name="cmd">Command对象</param>
 | |
|         /// <param name="orisPatient">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         internal static int ExcuteDeleteCommand(SqlCommand cmd, OrisPatient orisPatient)
 | |
|         {
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "delete from Oris_Patient where Id=@Id";
 | |
|             //从实体中取出值放入Command的参数列表
 | |
|             cmd.Parameters.Add(new SqlParameter("@Id", orisPatient.Id));
 | |
|             return cmd.ExecuteNonQuery();
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 不使用事务的删除方法
 | |
|         /// </summary>
 | |
|         /// <param name="orisPatient">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         internal static int Delete(OrisPatient orisPatient)
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return ExcuteDeleteCommand(cmd, orisPatient);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 使用事务的删除方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="orisPatient">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         internal static int Delete(Connection connection, OrisPatient orisPatient)
 | |
|         {
 | |
|             return ExcuteDeleteCommand(connection.Command, orisPatient);
 | |
|         }
 | |
| 
 | |
|         /// <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 = SyntaxAnalyzer.ParseSql(oql, new OrisPatientMap());
 | |
|             if (filterString != string.Empty)
 | |
|             {
 | |
|                 filterString = " where " + filterString;
 | |
|             }
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "delete from Oris_Patient " + 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="orisPatient">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         internal static int ExcuteUpdateCommand(SqlCommand cmd, OrisPatient orisPatient)
 | |
|         {
 | |
|             cmd.CommandText = "update Oris_Patient set MdrecNo=@MdrecNo,ArchivesNo=@ArchivesNo,Name=@Name,Sex=@Sex,BirthDay=@BirthDay,Age=@Age,Height=@Height,Weight=@Weight,DepId=@DepId,Illdistrict=@Illdistrict,SickBed=@SickBed,BloodType=@BloodType,RHBloodType=@RHBloodType,PatientKind=@PatientKind,InHosDate=@InHosDate,IdentityCard=@IdentityCard,Contacts=@Contacts,ContactsPhone=@ContactsPhone,OperatorNo=@OperatorNo,OperatorName=@OperatorName,OperateDate=@OperateDate,PatientType=@PatientType  where Id=@Id";
 | |
|             //从实体中取出值放入Command的参数列表
 | |
|             cmd.Parameters.Add(new SqlParameter("@MdrecNo", orisPatient.MdrecNo == null ? (object)DBNull.Value : (object)orisPatient.MdrecNo));
 | |
|             cmd.Parameters.Add(new SqlParameter("@ArchivesNo", orisPatient.ArchivesNo == null ? (object)DBNull.Value : (object)orisPatient.ArchivesNo));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Name", orisPatient.Name == null ? (object)DBNull.Value : (object)orisPatient.Name));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Sex", orisPatient.Sex == null ? (object)DBNull.Value : (object)orisPatient.Sex));
 | |
|             cmd.Parameters.Add(new SqlParameter("@BirthDay", orisPatient.BirthDay.HasValue ? (object)orisPatient.BirthDay.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Age", orisPatient.Age == null ? (object)DBNull.Value : (object)orisPatient.Age));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Height", orisPatient.Height == null ? (object)DBNull.Value : (object)orisPatient.Height));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Weight", orisPatient.Weight == null ? (object)DBNull.Value : (object)orisPatient.Weight));
 | |
|             cmd.Parameters.Add(new SqlParameter("@DepId", orisPatient.DepId.HasValue ? (object)orisPatient.DepId.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Illdistrict", orisPatient.Illdistrict == null ? (object)DBNull.Value : (object)orisPatient.Illdistrict));
 | |
|             cmd.Parameters.Add(new SqlParameter("@SickBed", orisPatient.SickBed == null ? (object)DBNull.Value : (object)orisPatient.SickBed));
 | |
|             cmd.Parameters.Add(new SqlParameter("@BloodType", orisPatient.BloodType == null ? (object)DBNull.Value : (object)orisPatient.BloodType));
 | |
|             cmd.Parameters.Add(new SqlParameter("@RHBloodType", orisPatient.RHBloodType == null ? (object)DBNull.Value : (object)orisPatient.RHBloodType));
 | |
|             cmd.Parameters.Add(new SqlParameter("@PatientKind", orisPatient.PatientKind == null ? (object)DBNull.Value : (object)orisPatient.PatientKind));
 | |
|             cmd.Parameters.Add(new SqlParameter("@InHosDate", orisPatient.InHosDate.HasValue ? (object)orisPatient.InHosDate.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@IdentityCard", orisPatient.IdentityCard == null ? (object)DBNull.Value : (object)orisPatient.IdentityCard));
 | |
|             cmd.Parameters.Add(new SqlParameter("@Contacts", orisPatient.Contacts == null ? (object)DBNull.Value : (object)orisPatient.Contacts));
 | |
|             cmd.Parameters.Add(new SqlParameter("@ContactsPhone", orisPatient.ContactsPhone == null ? (object)DBNull.Value : (object)orisPatient.ContactsPhone));
 | |
|             cmd.Parameters.Add(new SqlParameter("@OperatorNo", orisPatient.OperatorNo == null ? (object)DBNull.Value : (object)orisPatient.OperatorNo));
 | |
|             cmd.Parameters.Add(new SqlParameter("@OperatorName", orisPatient.OperatorName == null ? (object)DBNull.Value : (object)orisPatient.OperatorName));
 | |
|             cmd.Parameters.Add(new SqlParameter("@OperateDate", orisPatient.OperateDate.HasValue ? (object)orisPatient.OperateDate.Value : (object)DBNull.Value));
 | |
|             cmd.Parameters.Add(new SqlParameter("@PatientType", orisPatient.PatientType == null ? (object)DBNull.Value : (object)orisPatient.PatientType)); 
 | |
|             cmd.Parameters.Add(new SqlParameter("@Id", orisPatient.Id));
 | |
|             return cmd.ExecuteNonQuery();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 不使用事务的更新方法
 | |
|         /// </summary>
 | |
|         /// <param name="orisPatient">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         internal static int Update(OrisPatient orisPatient)
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     return ExcuteUpdateCommand(cmd, orisPatient);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 使用事务的更新方法
 | |
|         /// </summary>
 | |
|         /// <param name="connection">实现共享Connection的对象</param>
 | |
|         /// <param name="orisPatient">实体类对象</param>
 | |
|         /// <returns>影响的记录行数</returns>
 | |
|         internal static int Update(Connection connection, OrisPatient orisPatient)
 | |
|         {
 | |
|             return ExcuteUpdateCommand(connection.Command, orisPatient);
 | |
|         }
 | |
|         /// <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 OrisPatientMap());
 | |
|             cmd.CommandText = "update Oris_Patient 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<OrisPatient> ExcuteSelectCommand(SqlCommand cmd, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             List<OrisPatient> orisPatientList = new List<OrisPatient>();
 | |
|             using (SqlDataReader dr = cmd.ExecuteReader())
 | |
|             {
 | |
|                 while (dr.Read())
 | |
|                 {
 | |
|                     OrisPatient orisPatient = DataReaderToEntity(dr);
 | |
|                     orisPatientList.Add(orisPatient);
 | |
|                 }
 | |
|             }
 | |
|             return orisPatientList;
 | |
|         }
 | |
|         /// <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<OrisPatient> ExcuteSelectCommand(SqlCommand cmd, string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             //解析过滤部份Sql语句
 | |
|             string filterString = SyntaxAnalyzer.ParseSql(oql, new OrisPatientMap());
 | |
|             if (filterString != string.Empty)
 | |
|             {
 | |
|                 if (filterString.Trim().ToLower().IndexOf("order ") != 0)
 | |
|                     filterString = " where " + filterString;
 | |
|             }
 | |
|             cmd.Parameters.Clear();
 | |
|             cmd.CommandText = "select * from Oris_Patient " + 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<OrisPatient> Select()
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     cmd.CommandText = "select * from Oris_Patient";
 | |
|                     return ExcuteSelectCommand(cmd, RecursiveType.Parent, 1);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 根据对象查询语句查询实体集合
 | |
|         /// </summary>
 | |
|         /// <param name="recursiveType">递归类型</param>
 | |
|         /// <param name="recursiveDepth">递归深度</param>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         internal static List<OrisPatient> Select(RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     cmd.CommandText = "select * from Oris_Patient";
 | |
|                     return ExcuteSelectCommand(cmd, recursiveType, recursiveDepth);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据对象查询语句查询实体集合
 | |
|         /// </summary>
 | |
|         /// <param name="oql">对象查询语句</param>
 | |
|         /// <param name="parameters">参数列表</param>
 | |
|         /// <returns>实体类对象集合</returns>
 | |
|         internal static List<OrisPatient> 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<OrisPatient> 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<OrisPatient> 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 OrisPatient ExcuteSelectSingleCommand(SqlCommand cmd, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             OrisPatient orisPatient = null;
 | |
|             using (SqlDataReader dr = cmd.ExecuteReader())
 | |
|             {
 | |
|                 if (dr.Read())
 | |
|                     orisPatient = DataReaderToEntity(dr);
 | |
|             }
 | |
|             if (orisPatient == null)
 | |
|                 return orisPatient;
 | |
|             return orisPatient;
 | |
|         }
 | |
|         /// <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 OrisPatient ExcuteSelectSingleCommand(SqlCommand cmd, string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             //解析过滤部份Sql语句
 | |
|             string filterString = SyntaxAnalyzer.ParseSql(oql, new OrisPatientMap());
 | |
|             if (filterString != string.Empty)
 | |
|             {
 | |
|                 filterString = " where " + filterString;
 | |
|             }
 | |
|             cmd.CommandText = "select * from Oris_Patient " + 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 OrisPatient 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 OrisPatient 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 OrisPatient 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 OrisPatient SelectSingle(SqlCommand cmd, int? id, RecursiveType recursiveType, int recursiveDepth)
 | |
|         {
 | |
|             cmd.Parameters.Clear();
 | |
|             if (id.HasValue)
 | |
|             {
 | |
|                 cmd.CommandText = "select * from Oris_Patient where Id=@pk";
 | |
|                 cmd.Parameters.Add(new SqlParameter("@pk", id.Value));
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 cmd.CommandText = "select * from Oris_Patient where Id is null";
 | |
|             }
 | |
|             return ExcuteSelectSingleCommand(cmd, recursiveType, recursiveDepth);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 按主键字段查询特定实体
 | |
|         /// </summary>
 | |
|         /// <param name="id">主键值</param>
 | |
|         /// <returns>实体类对象</returns>
 | |
|         internal static OrisPatient 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 OrisPatient 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 OrisPatient 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 OrisPatient DataReaderToEntity(SqlDataReader dr)
 | |
|         {
 | |
|             OrisPatient entity = new OrisPatient();
 | |
|             if (dr["Id"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Id = Convert.ToInt32(dr["Id"]);
 | |
|             }
 | |
|             if (dr["MdrecNo"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.MdrecNo = dr["MdrecNo"].ToString();
 | |
|             }
 | |
|             if (dr["ArchivesNo"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.ArchivesNo = dr["ArchivesNo"].ToString();
 | |
|             }
 | |
|             if (dr["Name"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Name = dr["Name"].ToString();
 | |
|             }
 | |
|             if (dr["Sex"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Sex = dr["Sex"].ToString();
 | |
|             }
 | |
|             if (dr["BirthDay"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.BirthDay = Convert.ToDateTime(dr["BirthDay"]);
 | |
|             }
 | |
|             if (dr["Age"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Age = dr["Age"].ToString();
 | |
|             }
 | |
|             if (dr["Height"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Height = dr["Height"].ToString();
 | |
|             }
 | |
|             if (dr["Weight"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Weight = dr["Weight"].ToString();
 | |
|             }
 | |
|             if (dr["DepId"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.DepId = Convert.ToInt32(dr["DepId"]);
 | |
|             }
 | |
|             if (dr["Illdistrict"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Illdistrict = dr["Illdistrict"].ToString();
 | |
|             }
 | |
|             if (dr["SickBed"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.SickBed = dr["SickBed"].ToString();
 | |
|             }
 | |
|             if (dr["BloodType"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.BloodType = dr["BloodType"].ToString();
 | |
|             }
 | |
|             if (dr["RHBloodType"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.RHBloodType = dr["RHBloodType"].ToString();
 | |
|             }
 | |
|             if (dr["PatientKind"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.PatientKind = dr["PatientKind"].ToString();
 | |
|             }
 | |
|             if (dr["InHosDate"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.InHosDate = Convert.ToDateTime(dr["InHosDate"]);
 | |
|             }
 | |
|             if (dr["IdentityCard"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.IdentityCard = dr["IdentityCard"].ToString();
 | |
|             }
 | |
|             if (dr["Contacts"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Contacts = dr["Contacts"].ToString();
 | |
|             }
 | |
|             if (dr["ContactsPhone"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.ContactsPhone = dr["ContactsPhone"].ToString();
 | |
|             }
 | |
|             if (dr["OperatorNo"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.OperatorNo = dr["OperatorNo"].ToString();
 | |
|             }
 | |
|             if (dr["OperatorName"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.OperatorName = dr["OperatorName"].ToString();
 | |
|             }
 | |
|             if (dr["OperateDate"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.OperateDate = Convert.ToDateTime(dr["OperateDate"]);
 | |
|             }
 | |
|             if (dr["PatientType"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.PatientType = dr["PatientType"].ToString();
 | |
|             }
 | |
|             if (dr["HisPatientId"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.HisPatientId = dr["HisPatientId"].ToString();
 | |
|             }
 | |
|             if (dr["VisitTimes"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.VisitTimes = dr["VisitTimes"].ToString();
 | |
|             }
 | |
|             if (dr["Address"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Address = dr["Address"].ToString();
 | |
|             }
 | |
|             if (dr["Nation"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Nation = dr["Nation"].ToString();
 | |
|             }
 | |
|             if (dr["Extend1"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Extend1 = dr["Extend1"].ToString();
 | |
|             }
 | |
|             if (dr["Extend2"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Extend2 = dr["Extend2"].ToString();
 | |
|             }
 | |
|             if (dr["Extend3"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Extend3 = dr["Extend3"].ToString();
 | |
|             }
 | |
|             if (dr["Extend4"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Extend4 = dr["Extend4"].ToString();
 | |
|             }
 | |
|             if (dr["Extend5"] != System.DBNull.Value)
 | |
|             {
 | |
|                 entity.Extend5 = dr["Extend5"].ToString();
 | |
|             }
 | |
|             return entity;
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 |