using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
namespace CommonFunction
{
	/// <summary>
	/// detail 的摘要说明。
	/// </summary>
	public class detail : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.TextBox txtName;
		protected System.Web.UI.WebControls.Label label;
		protected System.Web.UI.WebControls.TextBox txtBirth;
		protected System.Web.UI.WebControls.TextBox txtAddr;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.TextBox txtCity;
		protected System.Web.UI.WebControls.Label Label2;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			//页面初试化时进行数据绑定
			if(!IsPostBack)
				DataGridDataBind();
		}

		private void DataGridDataBind()
		{
			//取得上一页面传递过来的参数值
			string AuthorID = Request["ID"].ToString();
			//定义数据连接对象,其中数据库连接字符串是在Web.Config文件中定义的
			SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionSqlServer"].ToString());
			//创建SQL命令对象
			SqlCommand cmd = new SqlCommand("select LastName,FirstName,BirthDate,Address,City from Employees where EmployeeID="+AuthorID,conn);
			//打开数据连接
			conn.Open();
			//创建数据读取器
			try
			{
				SqlDataReader dr = cmd.ExecuteReader();
				//如果取到数据
				if(dr.Read())
				{
					//显示取到的数据
					txtName.Text = dr["LastName"].ToString();
					txtBirth.Text = Convert.ToDateTime(dr["BirthDate"]).ToLongDateString();
					txtAddr.Text = dr["Address"].ToString();
					txtCity.Text = dr["City"].ToString();

				}
			}
			catch(Exception error)
			{
				Response.Write(error.ToString());
			}	
			finally
			{
				//关闭数据连接
				conn.Close();
			}
		}
		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}
