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 free
{
	/// <summary>
	/// Summary description for lianxiziliao.
	/// </summary>
	public class lianxiziliao : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox email;
		protected System.Web.UI.WebControls.TextBox qq;
		protected System.Web.UI.WebControls.TextBox icq;
		protected System.Web.UI.WebControls.TextBox tell;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.TextBox free;
		protected System.Data.SqlClient.SqlDataReader reader;
		SqlConnection myconn;
		SqlCommand mycom;
		protected System.Web.UI.WebControls.Label cuowu;
		string name;
	    
		private void Page_Load(object sender, System.EventArgs e)
		{
			try
			{
				name=Request.Cookies["free_huiyuan"].Value.ToString();
				
			}
			catch
			{
				Response.Redirect("error.aspx");
			}
			myconn=new SqlConnection(Session["str_connection"].ToString());
			if(!Page.IsPostBack)
			{
				bangding();
			}
		}


		private void bangding()
		{
			myconn.Open();
			string mysql="select * from huiyuan where yonghuming='"+name+"'";
			mycom=new SqlCommand(mysql,myconn);
			reader=mycom.ExecuteReader();
			string str1="",str2="",str3="",str4="",str5="";
			reader.Read();
			try
			{
				str1=reader["email"].ToString().Trim();
				str2=reader["qq"].ToString().Trim();
				str3=reader["icq"].ToString().Trim();
				str4=reader["dianhua"].ToString().Trim();
				str5=reader["gerenzhuye"].ToString().Trim();
			}
			catch
			{
				
			}
			email.Text=str1;
			qq.Text=str2;
			icq.Text=str3;
			tell.Text=str4;
			free.Text=str5;
			
			reader.Close();
			myconn.Close();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			if(email.Text=="")
			{
				Response.Write("<script>alert('出错啦：***电子邮件不能为空！')</script>");
			}
			else
			{
				string upstr;
				upstr="UPDATE huiyuan SET  qq=@qq, icq=@icq, email=@email, dianhua=@dianhua, gerenzhuye=@gerenzhuye WHERE yonghuming='"+name+"'";
				myconn.Open();
				SqlCommand mysqlcommand=new SqlCommand(upstr,myconn);
				mysqlcommand.Parameters.Add(new SqlParameter("@qq",SqlDbType.Char,15));
				mysqlcommand.Parameters["@qq"].Value=qq.Text.Trim();
				mysqlcommand.Parameters.Add(new SqlParameter("@icq",SqlDbType.Char,15));
				mysqlcommand.Parameters["@icq"].Value=icq.Text.Trim();
				mysqlcommand.Parameters.Add(new SqlParameter("@email",SqlDbType.Char,100));
				mysqlcommand.Parameters["@email"].Value=email.Text.Trim();
				mysqlcommand.Parameters.Add(new SqlParameter("@gerenzhuye",SqlDbType.Char,100));
				mysqlcommand.Parameters["@gerenzhuye"].Value=free.Text.Trim();
				mysqlcommand.Parameters.Add(new SqlParameter("@dianhua",SqlDbType.Char,20));
				mysqlcommand.Parameters["@dianhua"].Value=tell.Text.Trim();
				try
				{
					mysqlcommand.ExecuteNonQuery();
					Response.Write("<script>alert('恭喜：***资料修改成功！')</script>");
					
				}
				catch
				{
					Response.Write("<script>alert('错误：***资料修改失败！')</script>");
				}
				myconn.Close();

				bangding();
				
			}
		}
	}
}
