⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adminuseradd.aspx.cs

📁 学生寝室管理系统
💻 CS
字号:
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 adminuseradd : System.Web.UI.Page
{
    ArrayList year, month, day, year1;
    int i;
    SqlConnection cn;
    SqlDataAdapter da;
    SqlCommand cmd, cmd1, cmd2, cmd3, cmd4, cmd5;
    SqlDataReader dr1, dr2, dr, dr3, dr4, dr5;
    string strsql, strsql1, strsql2, strsql3, strsql4, strsql5, strsql6;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Label1.Text = this.txtname.Text.ToString();
        if (!Page.IsPostBack)
        {
            if (Session["adminname"] == null)
            {
                Response.Redirect("index.aspx");
            }
            else
            {
                year1 = new ArrayList();
                year = new ArrayList();
                month = new ArrayList();
                day = new ArrayList();

                for (i = 1999; i <= 2007; i++)
                    year1.Add(i.ToString());
                for (i = 1945; i <= 2007; i++)
                    year.Add(i.ToString());
                for (i = 1; i <= 12; i++)
                    month.Add(i.ToString());
                for (i = 1; i <= 31; i++)
                    day.Add(i.ToString());

                ddlyear.DataSource = year;
                ddlyear.DataBind();

                ddlmonth.DataSource = month;
                ddlmonth.DataBind();

                ddlday.DataSource = day;
                ddlday.DataBind();

                this.DropDownList1.DataSource = year1;
                this.DropDownList1.DataBind();

                this.DropDownList2.DataSource = month;
                this.DropDownList2.DataBind();

                this.DropDownList3.DataSource = day;
                this.DropDownList3.DataBind();


                cn = sqldata.createcon();
                cn.Open();
                strsql = "select ximing from ximing ";
                cmd = new SqlCommand(strsql, cn);
                dr = cmd.ExecuteReader();
                this.ddlximing.DataSource = dr;
                this.ddlximing.DataTextField = "ximing";
                this.ddlximing.DataBind();
                cn.Close();

                cn = sqldata.createcon();
                cn.Open();
                strsql6 = "select zhuanye from zhuanye ";
                cmd5 = new SqlCommand(strsql6, cn);
                dr5 = cmd5.ExecuteReader();
                this.ddlzhuanye.DataSource = dr5;
                this.ddlzhuanye.DataTextField = "zhuanye";
                this.ddlzhuanye.DataBind();

                this.ddlzhuanye.Items.Add("请选择您的专业名称");
                this.ddlzhuanye.SelectedIndex = this.ddlzhuanye.Items.Count - 1;



                this.ddlximing.Items.Add("请选择您的系别名称");
                this.ddlximing.SelectedIndex = this.ddlximing.Items.Count - 1;

                cn.Close();
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            this.Panel1.Visible = false;
            this.Panel2.Visible = true;

            cn = sqldata.createcon();
            cn.Open();
            strsql4 = "insert into users(userid,username,userpwd,usersex,userage,userminzu,userbirthday,useraddress,homephone,useremail,enterdate,userdepartment,userzhuanye,classname,teacher,shenfen)values('" + this.txtuserid.Text.ToString() + "','" + this.txtname.Text.ToString() + "','" + this.txtuserpwd.Text.ToString() + "','" + this.ddlsex.SelectedItem.Value.ToString() + "','" + this.txtage.Text.ToString() + "','" + this.ddlminzu.SelectedItem.Value.ToString() + "','" + ddlyear.SelectedItem.Value.ToString() + "-" + ddlmonth.SelectedItem.Value.ToString() + "-" + ddlday.SelectedItem.Value.ToString() + "','" + this.txtaddress.Text.ToString() + "','" + this.txtuserphone.Text.ToString() + "','" + txtuseremail.Text.ToString() + "','" + this.DropDownList1 .SelectedItem.Value.ToString() + "-" +this.DropDownList2 .SelectedItem.Value.ToString() + "-" +this.DropDownList3 .SelectedItem.Value.ToString() + "','" + this.ddlximing.SelectedItem.Value.ToString() + "','" + this.ddlzhuanye.SelectedItem.Value.ToString() + "','" + txtclassname.Text.ToString() + "','" + txtteacher.Text.ToString() + "','" + this.ddlhomeshenfen.SelectedItem.Value.ToString() + "')";
            cmd4 = new SqlCommand(strsql4, cn);
            cmd4.ExecuteNonQuery();
           
            this.HyperLink1.Visible = true;
            cn.Close();
        }
    }
    protected void ddlmonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        int[] numbers = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        if ((Convert.ToInt32(ddlyear.SelectedItem.Text.ToString()) % 4) == 0)
            numbers[1] = 29;

        day = new ArrayList();
        for (i = 1; i <= numbers[Convert.ToInt32(ddlmonth.SelectedItem.Text.ToString()) - 1]; i++)
            day.Add(i.ToString());
        ddlday.DataSource = day;
        ddlday.DataBind();
    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        string userid = args.Value;
        cn = sqldata.createcon();
        cn.Open();
        strsql = "select count(*)from users where userid='" + userid + "'";
        cmd = new SqlCommand(strsql, cn);
        int count = Convert.ToInt32(cmd.ExecuteScalar());
        if (count > 0)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
        cn.Close();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            cn = sqldata.createcon();
            cn.Open();
            string strsql5 = "insert into home(homesex,homeflood,homehao,homecount,homephone,uid,homediffenet)values('" + ddlhomesex.SelectedItem.Value.ToString() + "','" + this.ddlhomeflood.SelectedItem.Value.ToString() + "','" + txthomehaoma.Text.ToString() + "','" + ddlhomecount.SelectedItem.Value.ToString() + "','" + txthomephone.Text.ToString() + "','" + txtuserid.Text.ToString() + "','" + this.DropDownList4.SelectedItem.Value.ToString() + "')";
            cmd5 = new SqlCommand(strsql5, cn);
            cmd5.ExecuteNonQuery();
            cn.Close();
            this.Panel2.Visible = false;
            this.Panel3.Visible = true;
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        this.txtaddress.Text = "";
        this.txtage.Text = "";
        this.txtclassname.Text = "";
       
        this.txtname.Text = "";
        this.txtteacher.Text = "";
        this.txtuseremail.Text = "";
        this.txtuserid.Text = "";
        this.txtuserphone.Text = "";
        this.txtuserpwd.Text = "";
        this.txtuserpwdagina.Text = "";
        this.txtname.Focus();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        txthomehaoma.Text = "";
        txthomephone.Text = "";
        this.txthomehaoma.Focus();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -