using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.Data.Sql;


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


            if (!Page.IsPostBack)
            {
                string sql = "select * from student ";
                DataTable dt = DataAccess.GetDataTable(sql);

                GridViewNew.DataSource = dt;
                GridViewNew.DataBind();
            }

        }

        private void bindTime()
        {

            for (int i = 2015; i < 2030; i++)
            {

            }
        }
        private void Bindall(string code)
        {
            string sql = "select * from student where stid='" + code + "'";
            DataTable dt = DataAccess.GetDataTable(sql);

            GridViewNew.DataSource = dt;
            GridViewNew.DataBind();
        }
        private void bindBANJI()
        {
            //string Sql = "select * from banji";
            //DataTable dt = DataAccess.GetDataTable(Sql);
            //DropDownListBan.DataTextField = "banname";
            //DropDownListBan.DataValueField = "ban";
            //DropDownListBan.DataSource = dt;
            //DropDownListBan.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string stid = TextBoxid.Text;
            string name = TextBoxName.Text;
            string Tel = TextBoxTel.Text;
            string email = TextBoxEmail.Text;

            //string banzhuren = DropDownList1.SelectedValue;
            //string banname = DropDownList1.SelectedItem.Text;
            string pw1 = TextBoxPWD.Text;
            string pw2 = TextBoxPwd2.Text;
            string sex = RadioButtonList1.SelectedValue;
            string sql2 = "select count(*) from student where  stid='" + stid + "'";
            int k = int.Parse(DataAccess.RunSqlReturn(sql2));
            if (k > 0)
            {
                DataAccess.Message(this, "登录号有重复，请更换一个登陆号!");
            }

            if (pw1 == pw2)
            {
                string sql = "insert into student([stid],[stname],[tel],[pwd],[email],[sex]) values('" + stid + "','" + name + "','" + Tel + "','" + pw1 + "','" + email + "','" + sex + "')";
                try
                {
                    DataAccess.ExecuteCmd(sql);
                    Session["user"] = stid;

                }
                catch
                {
                    DataAccess.Message(this, "操作失败!");
                }
                finally
                {
                    Bindall(stid);
                    //DataAccess.Message1(this, "操作成功!", ".../login.aspx");
                    Label1.Visible = true;
                }


            }
        }
    }
}