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.bbs
{
	/// <summary>
	/// Summary description for mimaxiugai.
	/// </summary>
	public class mimaxiugai : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
	    
		SqlConnection conn;
		SqlDataReader r;
		protected System.Web.UI.WebControls.TextBox yuanmima;
		protected System.Web.UI.WebControls.TextBox xinmima1;
		protected System.Web.UI.WebControls.TextBox xinmima2;
		string name;
		private void Page_Load(object sender, System.EventArgs e)
		{
			try
			{
				name=Request.Cookies["free_huiyuan"].Value.ToString();
				
			}
			catch
			{
				Response.Redirect("error.aspx");
			}
			conn=new SqlConnection(Session["str_connection"].ToString());
		}


		#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)
		{ 
			conn.Open();
			SqlCommand command=new SqlCommand("select mima from huiyuan where yonghuming='"+name+"'",conn);
			r=command.ExecuteReader();
			try
			{
				r.Read();
				if(yuanmima.Text.Trim()==r["mima"].ToString().Trim())
				{
					r.Close();
					if(xinmima1.Text.Trim()=="")
					{
						Response.Write("<script>alert('新密码不能为空!')</script>");
					}
					else if(xinmima1.Text.Trim()==xinmima2.Text.Trim()&&xinmima2.Text.Trim()!="" &&Page.IsValid)
					{
						command=new SqlCommand("update huiyuan set mima=@mima where yonghuming='"+name+"'",conn);
						command.Parameters.Add(new SqlParameter("@mima",SqlDbType.Char,15));
						command.Parameters["@mima"].Value=xinmima1.Text.Trim();
						command.ExecuteNonQuery();
						Response.Write("<script>alert('密码修改成功!')</script>");
						conn.Close();
					}
					else
					{
						Response.Write("<script>alert('新密码不一致!!')</script>");
					}
				}
				else
				{ 
		            Response.Write("<script>alert('旧密码不正确!')</script>");
				}
			}
			catch
			{
				 Response.Write("<script>alert('错误，你的输入有误!')</script>");
			}
			
			conn.Close();
		}
	}
}
