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;

namespace yn165.admin
{
	/// <summary>
	/// ad_edituser 的摘要说明。
	/// </summary>
	public class ad_edituser : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox pass;
		protected System.Web.UI.WebControls.TextBox question;
		protected System.Web.UI.WebControls.TextBox reply;
		protected System.Web.UI.WebControls.TextBox name;
		protected System.Web.UI.WebControls.TextBox ename;
		protected System.Web.UI.WebControls.TextBox unit;
		protected System.Web.UI.WebControls.TextBox eunit;
		protected System.Web.UI.WebControls.TextBox unit_py;
		protected System.Web.UI.WebControls.TextBox unit_abr;
		protected System.Web.UI.WebControls.TextBox province;
		protected System.Web.UI.WebControls.TextBox city;
		protected System.Web.UI.WebControls.TextBox ecity;
		protected System.Web.UI.WebControls.TextBox address;
		protected System.Web.UI.WebControls.TextBox eaddress;
		protected System.Web.UI.WebControls.TextBox post;
		protected System.Web.UI.WebControls.TextBox mobile;
		protected System.Web.UI.WebControls.TextBox tel;
		protected System.Web.UI.WebControls.TextBox fax;
		protected System.Web.UI.WebControls.TextBox email;
		protected System.Web.UI.WebControls.TextBox slevel;
		protected System.Web.UI.WebControls.TextBox reg_date;
		protected System.Web.UI.WebControls.TextBox account;
		protected System.Web.UI.WebControls.RadioButton male;
		protected System.Web.UI.WebControls.RadioButton female;
		protected System.Web.UI.WebControls.ImageButton ImageButton1;
			
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
			{
				SqlConnection conn = new SqlConnection("server=211.155.254.117;database=yn165;uid=yn165;pwd=159753");
				conn.Open();
				string sql = "select * from user_reg where id = " + Request["id"].ToString();
				SqlCommand cmd = new SqlCommand(sql,conn);
				SqlDataReader reader = cmd.ExecuteReader();
				if (reader.Read())
				{
					this.account.Text=reader.GetValue(1).ToString();
					this.pass.Text=reader.GetValue(2).ToString();
					this.question.Text=reader.GetValue(3).ToString();
					this.reply.Text=reader.GetValue(4).ToString();
					this.name.Text=reader.GetValue(5).ToString();
					this.ename.Text=reader.GetValue(6).ToString();
					this.unit.Text=reader.GetValue(7).ToString();
					this.eunit.Text=reader.GetValue(8).ToString();
					this.unit_py.Text=reader.GetValue(9).ToString();
					this.unit_abr.Text=reader.GetValue(10).ToString();
					if (reader.GetValue(11).ToString()=="先生")
					{
						this.male.Checked=true;
					}
					else
					{
						this.female.Checked=true;
					}
						
					this.province.Text=reader.GetValue(12).ToString();
					this.city.Text=reader.GetValue(13).ToString();
					this.ecity.Text=reader.GetValue(14).ToString();
					this.address.Text=reader.GetValue(15).ToString();
					this.eaddress.Text=reader.GetValue(16).ToString();
					this.post.Text=reader.GetValue(17).ToString();
					this.mobile.Text=reader.GetValue(18).ToString();
					this.tel.Text=reader.GetValue(19).ToString();
					this.fax.Text=reader.GetValue(20).ToString();
					this.email.Text=reader.GetValue(21).ToString();
					this.slevel.Text=reader.GetValue(22).ToString();
					this.reg_date.Text=reader.GetValue(23).ToString();
				}
				reader.Close();
				cmd.Dispose();
				conn.Close();
			}
		
			
			// 在此处放置用户代码以初始化页面
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN：该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			string sql,tel,fax,sex="";
			if (male.Checked==true) 
			{
				sex="先生";
			}
			else
			{
				sex="女士";
			}
			tel=this.tel.Text;
			fax=this.fax.Text;
			SqlConnection conn = new SqlConnection("server=211.155.254.117;database=yn165;uid=yn165;pwd=159753");
			
			
			sql = "update user_reg set name='" + name.Text + "', password='" + this.pass.Text + "',question='" + this.question.Text + "', reply='" + this.reply.Text + "', account='" + account.Text +   "', ename='" + ename.Text + "', unit='" + unit.Text + "', eunit='" + eunit.Text +  "', unit_py='" + unit_py.Text + "', unit_abr='" + unit_abr.Text + 
				"', sex='" + sex + "', province='" + province.Text + "', city='" + city.Text + "', ecity='" + ecity.Text + "', address='" + address.Text + "', eaddress='" + eaddress.Text + "', post='" + post.Text + "', mobile='" +mobile.Text + 
				"', tel='" + tel + "', fax='" + fax + "', email='" + email.Text + "', slevel='" + this.slevel.Text + "', reg_date='" + reg_date.Text +  "' where id=" + Request["id"].ToString();
		
			SqlCommand  cmd = new SqlCommand(sql,conn);
			cmd.Connection.Open();
			cmd.ExecuteNonQuery();
			cmd.Dispose();
			conn.Close();
			Response.Redirect("001.aspx");


		
		}
	}
}
