using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

using HISClinic.DataModel;
using HISClinic.DataServices.Database;

namespace HISClinic.DataServices
{
	/// <summary>
	/// User 的摘要说明。
	/// </summary>
	public class UserMapper
	{
		private const string PARAM_UserID="@UserID";
		private const string PARAM_LoginName="@LoginName";
		private const string PARAM_Password="@Password";

		public UserMapper()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}

		/// <summary>
		/// 根据登录名得到用户信息
		/// </summary>
		/// <param name="loginName">登录名</param>
		/// <returns></returns>
		public UsersEx FindUser(string loginName)
		{
			UsersEx usersEx=new UsersEx();
			SqlParameter[] parameters={
										  new SqlParameter(PARAM_LoginName,loginName)										  
									  };
			using(SqlConnection conn=HISDBConfig.GetConnection())
			{
				SqlHelper.FillDataset(conn,CommandType.StoredProcedure,"ut_FindUserByLoginName",usersEx,
					new string[] {UsersEx.t_UserDataTableEx.TableName_User},parameters);
			}
			return usersEx;
		}

		/// <summary>
		/// 通过UserID获取密码
		/// </summary>
		/// <param name="userID"></param>
		/// <returns></returns>
		public byte[] GetPassword(int userID)
		{
			SqlParameter[] parameters={
										  new SqlParameter(PARAM_UserID,userID)										  
									  };
			object Password;

			using(SqlConnection conn=HISDBConfig.GetConnection())
			{				
				Password=SqlHelper.ExecuteScalar(conn,CommandType.StoredProcedure,"ut_GetPassword",parameters);								
			}	
			return (byte[])Password;
		}	
	
		/// <summary>
		/// DoctorMapper 的摘要说明。
		/// </summary>
		public class Doctor
		{
			private const string PARAM_DoctorID="@DoctorID";

			public Doctor()
			{
				//
				// TODO: 在此处添加构造函数逻辑
				//
			}
			/// <summary>
			/// 获取医生信息
			/// </summary>
			/// <returns></returns>
			public DoctorsEx GetDoctor()
			{
				DoctorsEx doctorsEx=new DoctorsEx();
		    
				using(SqlConnection conn=HISDBConfig.GetNewConection())
				{
					SqlHelper.FillDataset(conn,"ut_GetDoctor",doctorsEx,new string[] {DoctorsEx.t_DoctorDataTableEx.TableName_Doctor},null);
				}
				return doctorsEx;
			}

			/// <summary>
			/// 根据DoctorID获取医生信息
			/// </summary>
			/// <param name="DoctorID"></param>
			/// <returns></returns>
			public DoctorsEx GetDoctor(int doctorID)
			{
				DoctorsEx doctorsEx=new DoctorsEx();
		    
				SqlParameter[] parameters={new SqlParameter(PARAM_DoctorID,doctorID)};
				using(SqlConnection conn=HISDBConfig.GetNewConection())
				{
					SqlHelper.FillDataset(conn,"ut_GetDoctorByDoctorID",doctorsEx,new string[] {DoctorsEx.t_DoctorDataTableEx.TableName_Doctor},parameters);
				}
				return doctorsEx;
			}
		}
	}
}
