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

📄 user regist.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;

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

        if (!IsPostBack)
        {
            BindYear();
            BindMonth();
            BindDay(0,0);
        }
        Session["Logined1"] = false; 
    }
    protected void BindYear()
    {
        this.DropDownList_Year.Items.Clear();
        int year = System.DateTime.Now.Year;
        ListItem tempItem1 = new ListItem("--请选择--");
        this.DropDownList_Year.Items.Add(tempItem1);

        for (int i = 0; i <= 60; i++)
        {
            ListItem tempItem = new ListItem();
            tempItem.Text = tempItem.Value = (year - i).ToString();
            this.DropDownList_Year.Items.Add(tempItem);
        }
        tempItem1 = new ListItem("--其它--");
        this.DropDownList_Year.Items.Add(tempItem1);
    }

    protected void BindMonth()
    {
        this.DropDownList_Month.Items.Clear();
        ListItem tempItem1 = new ListItem("--请选择--");
        this.DropDownList_Month.Items.Add(tempItem1);
        for (int i = 1; i <= 12; i++)
        {
            ListItem tempItem = new ListItem();
            tempItem.Text = tempItem.Value = i.ToString();
            this.DropDownList_Month.Items.Add(tempItem);
        }
    }

    protected void BindDay(int month,int year)
    {
        int EndDay = 31;
        switch (month)
        {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                EndDay = 31;
                break;
            case 2:
                if((year%4==0 && year %100!=0) ||year%400==0)
                EndDay = 29;
                else
                EndDay = 28;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                EndDay = 30;
                break;
            default:
                EndDay = 31;
                break;
        }

        this.DropDownList_Day.Items.Clear();
        ListItem tempItem1 = new ListItem("--请选择--");
        this.DropDownList_Day.Items.Add(tempItem1);
        for (int i = 1; i <= EndDay; i++)
        {
            ListItem tempItem = new ListItem();
            tempItem.Text = tempItem.Value = i.ToString();
            this.DropDownList_Day.Items.Add(tempItem);
        }
    }
    protected void DropDownList_Year_SelectedIndexChanged(object sender, EventArgs e)
    {
        //BindDay(Month,Year);
    }
    protected void DropDownList_Month_SelectedIndexChanged(object sender, EventArgs e)
    {
        int Month = 0;
        int Year = 0;
        try
        {
            Month = int.Parse(this.DropDownList_Month.SelectedValue); 
            Year = int.Parse(this.DropDownList_Year.SelectedValue);
        }
        catch (Exception ex)
        {
            this.Label_Msg.Text = this.DropDownList_Month.SelectedValue.ToString();
            this.Label_Msg.Text += ex.Message.ToString();

        }
        BindDay(Month,Year);
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (this.CheckBox1.Checked)
            this.CheckBox1.ForeColor = System.Drawing.Color.Purple;
        this.CheckBoxList1.Visible = this.CheckBox1.Checked;
    }
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        if (this.CheckBox2.Checked)
            this.CheckBox2.ForeColor = System.Drawing.Color.Purple;
        this.CheckBoxList2.Visible = this.CheckBox2.Checked;
    }
    


    protected void Button_examine_Click(object sender, EventArgs e)
    {
        string Msg = "";
        Msg += "<br>尊敬的" + TextBox_UserName.Text;
        Msg += "<br>您的生日:" + DropDownList_Year.SelectedValue + "年" + DropDownList_Month.SelectedValue + "月" + DropDownList_Day.SelectedValue + "日";
        Msg += "<br>" + "您的体育爱好:";
        foreach (ListItem Litem in this.CheckBoxList1.Items)
        {
            if (Litem.Selected)
                Msg += Litem.Text + "  ";
        }
        Msg += "<br>" + "您的读书爱好:";
        foreach (ListItem Litem in this.CheckBoxList2.Items)
        {
            if (Litem.Selected)
                Msg += Litem.Text + "  ";
        }
        this.Label_Msg.Text = Msg.Replace("/n", "<br>");
    
        this.Button_examine.Enabled=false;
    }


    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if (this.TextBox_UserName.Text.IndexOf("-") > 0 || this.TextBox_Pass1.Text.IndexOf("'") > 0)
        {
            this.Label_Msg.Text = "用户名中有非法字符";
            return;
        }

        string Condition = " where UserName='" + this.TextBox_UserName.Text + "' and UserPass='" + this.TextBox_Pass1.Text + "'";
        DataSet Dset = new DataBase().BindGrid("User_Info", "*", Condition, "");

        if (Dset == null || Dset.Tables[0].Rows.Count < 1)
        {
            //登录失败
            this.Label_Msg.Text = "管理员用户名或者密码有误";
        }
        else
        {
            //登录成功

            Session["Logined"] = true; Session["Logined1"] = true;
            Dset.Tables[0].Rows[0]["UserName"].ToString();
            Dset.Tables[0].Rows[0]["UserPass"].ToString();
            this.Label_Msg.Text = new DataBase().DeleteData("User_Info", Condition) + "成功注销!";
            this.TextBox_UserName.Text = "";
            this.TextBox_Pass1.Text = "";
           // Response.Write("<meta http-equiv=refresh ; content='2;URL=QueryGrade.aspx'>");
        }
    }



    protected void Button1_Click(object sender, EventArgs e)
    {

        this.Label_Msg.Visible = true;
        if (this.DropDownList_Year.SelectedItem.ToString() == "--请选择--" || this.DropDownList_Month.SelectedItem.ToString() == "--请选择--" || this.DropDownList_Day.SelectedItem.ToString() == "--请选择--")
        {
            this.Label_Msg.Text = "请先选择全年、月、日!";
            this.Label_Msg.ForeColor = System.Drawing.Color.SteelBlue;
        }
        else
        {
            Session["Logined1"] = true; Session["UserName"] = this.TextBox_UserName.Text; Session["UserType"] = 2;
            DataBase DbOper = new DataBase();

            //insert into GuestBook (UserName,GuestTitle,GuestContent,GuestTime) values('youke','test','test','2008-5-1')

            string InsertStr = "";
            string Mes = "";
            InsertStr += "(UserName,UserPass) ";
            InsertStr += "values('";
            InsertStr += this.TextBox_UserName.Text + "','";
            InsertStr += this.TextBox_Pass1.Text + "')";
            Mes = DbOper.InsertData("Register", InsertStr);
            this.Label_Msg.Text = "注册成功!";
            this.Button_examine.Enabled = true;
            Response.Write("<meta http-equiv=refresh ; content='2;URL=QueryGrade.aspx'>");

        }
    }
}

⌨️ 快捷键说明

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