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.OleDb;
using System.Xml;
using System.IO;
public partial class regiser_reg : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Panel1.Visible = true;
            this.Panel2.Visible = false;
            string url = Server.MapPath("info.xml").ToString();
            StreamReader sr = new StreamReader(url, System.Text.Encoding.GetEncoding("gb2312"));
            XmlDocument xd = new XmlDocument();
            xd.Load(sr);
            XmlNode xn = xd.SelectSingleNode("myinfo/meg");
            this.txt.Text = xn.InnerText;
            sr.Close();
        }
       
      
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (this.conval.IsValid)
        {            
            string OleDbstring = "insert into user_info(userName,trueName,userPwd,address,postcode,phone,email,Question,Answer)";
            string OleDb = OleDbstring + "values(@uid,@name,@pwd,@add,@post,@ph,@mail,@que,@ans)";
            OleDbConnection conn = DB.connstr();
            conn.Open();
            OleDbCommand insertcmd = new OleDbCommand(OleDb, conn);
            OleDbParameter sp = insertcmd.Parameters.Add("@uid",OleDbType.VarChar, 20);
            sp.Value = this.uidTxt.Text;
            sp = insertcmd.Parameters.Add("@name", OleDbType.VarChar, 8);
            sp.Value = this.relname.Text;
            sp = insertcmd.Parameters.Add("@pwd", OleDbType.VarChar, 20);
            sp.Value = this.pwdTxt.Text;
            sp = insertcmd.Parameters.Add("@add", OleDbType.VarChar,100);
            sp.Value = this.add.Text;
            sp = insertcmd.Parameters.Add("@post", OleDbType.VarChar, 6);
            sp.Value = this.post.Text;
            sp = insertcmd.Parameters.Add("@ph", OleDbType.VarChar, 20);
            sp.Value = this.phone.Text;
            sp = insertcmd.Parameters.Add("@mail", OleDbType.VarChar, 100);
            sp.Value = this.mail.Text;
            sp = insertcmd.Parameters.Add("@que", OleDbType.VarChar, 20);
            sp.Value = this.que.Text;
            sp = insertcmd.Parameters.Add("@ans", OleDbType.VarChar, 20);
            sp.Value = this.ans.Text;
            insertcmd.ExecuteNonQuery();
            conn.Close();
            Session["user"] = this.uidTxt.Text;
            Response.Redirect("userinfo.aspx");
        }
        
    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        string name=args.Value;
        OleDbConnection conn = DB.connstr();
        conn.Open();
        OleDbCommand chcmd = new OleDbCommand("select count(*) from user_info where userName='" + name + "'", conn);
        int num = Convert.ToInt32(chcmd.ExecuteScalar());
        if (num > 0)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
        conn.Close();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        this.Panel1.Visible = false;
        this.Panel2.Visible = true;
    }

}
