using System;
using System.Data;
using System.Data.SqlClient;
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;

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

    }
    protected void checkUserid_Click(object sender, EventArgs e)
    {
        string sql = "select * from [user] where userid='" + userid.Text + "'";
        SqlDataReader reader = DbManager.getReader(sql);
        if (reader.HasRows)
        {
            message.Visible = true;
            message.Text = "该帐号已存在，请更改！";
            userid.Text = "";
            userid.Focus();
        }
        else
        {
            message.ForeColor = System.Drawing.Color.Green;
            message.Visible = true;
            message.Text = "恭喜，该帐号可以使用！";
        }
        reader.Close();
    }
    protected void add_reg_Click(object sender, EventArgs e)
    {
        string addSql = "insert into [user](userid,username,password,sex,birthday,email,homeadd,lastlogin,blognum)" +
            "values('" + userid.Text + "','" + nickname.Text + "','" + pass.Text + "','" + sex.SelectedItem.Value + "','" + birth.Text + "','" +
            email.Text + "','" + homeurl.Text + "','" + DateTime.Now.ToString() + "',0)";
        if (DbManager.getNonQuery(addSql) > 0)
        {
            Session["userid"] = userid.Text;
            Session["username"] = nickname.Text;
            Session["lastlogin"] = DateTime.Now.ToString().Substring(0, 10);
            Session["login"] = "true";
            DbManager.closeConnection();
            Response.Write(function.redirect("Default.aspx", "注册成功，将自动转到主页！"));
        }
        else
        {
            Session["login"] = "no";
            DbManager.closeConnection();
            Response.Write(function.redirect("Default.aspx", "注册失败！请重试..."));
        }
    }
    protected void reset_Click(object sender, EventArgs e)
    {
        userid.Text = "";
        pass.Text = "";
        againPass.Text = "";
        nickname.Text = "";
        email.Text = "";
        birth.Text = "2003-12-20";
        homeurl.Text = "http://";
        message.Visible = false;
        userid.Focus();
    }
}
