using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class register : System.Web.UI.Page
{
    DataBaseLayer db = new DataBaseLayer();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Submit_Click(object sender, EventArgs e)
    {
        if (CheckBox1.Checked)
        {
            Register1.Enabled = true;
        }
        else
        {
            Register1.Enabled = false;
        }
    }
    protected void Register1_Click(object sender, EventArgs e)
    {
        if (UserName.Text != "" && Password.Text != "" && PasswordConfirm.Text != "" && Email.Text != "")
        {


            SqlParameter[] prams ={
                    db.ParamBuilder("@UserName",UserName.Text.Trim(),SqlDbType.VarChar),
                    db.ParamBuilder("@Password",md5Password(Password.Text.Trim()),SqlDbType.VarChar),
                    db.ParamBuilder("@Email",Email.Text.Trim(),SqlDbType.VarChar)
                };
            try
            {
                db.ExecuteNonQuery("Pr_Mp4_Register", prams);
                Response.Write("<script>alert(\"注册成功！正在跳转，请等待、、、\")</script>");
                Response.Write("<meta http-equiv='refresh' content='1;url=mp4.aspx'>");
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
                //Response.Write("<script>alert(\"注册失败！\")</script>");
            }
        }
        else
        {
            Response.Write("<script>alert(\"请您填写注册信息！\")</script>");
        }
    }
    protected void CheckUserName_Click(object sender, EventArgs e)
    {
        if (UserName.Text != "")
        {
            SqlParameter[] prams ={
                db.ParamBuilder("@UserName",UserName.Text.Trim(),SqlDbType.VarChar)
        };
            int count1 = db.ReturnExecuteNonQuery("Pr_Mp4_checkUserName", prams);
            if (count1 >= 1)
            {
                Response.Write("<script>alert(\"此用户名已被注册!\")</script>");
            }
            else
            {
                Response.Write("<script>alert(\"此用户名可用!\")</script>");
            }
        }
        else
        {
            Response.Write("<script>alert(\"请输入用户名！\")</script>");
        }
    }
    public string md5Password(string password)
    {
        string sPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
        return sPassword;
    }
}
