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

📄 index.aspx.cs

📁 基于asp.net的网上选课系统
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnlogin_Click(object sender, EventArgs e)
    {
        string id = txtID.Text;
        string pwd = txtPwd.Text;
        string str;
        //根据drpIdent的值判断登录用户的身份
        switch (drpIdent.SelectedValue)
            {
                //登录用户为学生
                case "Students":
                    {   
                        StuSQL stu = new StuSQL();
                        stu.Open();
                        //判断用户名与密码是否相符
                        int stuid = stu.StudentLogin(id, pwd);
                        //用户名与密码相符
                        if (stuid > 0)
                        {   //判断用户是否已经登录
                            int status=stu.StudentIfLogin(id);
                            //用户未登录
                            if (status!=0)
                            {
                                DataSet ds = new DataSet();
                                str = "select StudentName from Students where StudentID="+"'"+id+"'";
                                ds = stu.GetDataSet(str, "users");
                                //记录下用户的用户名,身份,ID号及密码
                                Session["username"] = ds.Tables["users"].Rows[0][0];
                                Session["userident"] = "student";
                                Session["userid"] = id;                                
                                Session["userpwd"] = pwd;
                                Response.Redirect("StuMain.aspx");
                            }
                            //用户已经登录
                            else
                                lblError.Text = "该用户已经登录!";
                        }
                        //用户名与密码不符
                        else
                        {
                            lblError.Text = "登录失败!用户名与密码不符,请重新输入!";
                        }
                        stu.Close();
                        break;
                    }
                //登录用户为教师
                case "Teachers":
                    {
                        TeaSQL tea = new TeaSQL();
                        tea.Open();
                        int teaid = tea.TeacherLogin(id, pwd);
                        if (teaid > 0)
                        {
                            int status = tea.TeacherIfLogin(id);
                            if (status != 0)
                            {   DataSet ds = new DataSet();
                                str = "select TeacherName from Teachers where TeacherID="+"'"+id+"'";
                                ds = tea.GetDataSet(str, "users");
                                Session["username"] = ds.Tables["users"].Rows[0][0];
                                Session["userident"] = "teacher";
                                Session["userid"] = id;
                                Session["userpwd"] = pwd;
                                Response.Redirect("TeaMain.aspx");
                            }
                            else
                                lblError.Text = "该用户已经登录!";
                        }
                        else
                        {
                            lblError.Text = "登录失败!用户名与密码不符,请重新输入!";
                        }
                        tea.Close();
                        break;
                    }
                //登录用户为管理员
                case "Admins":
                    {
                        AdminSQL admin = new AdminSQL();
                        admin.Open();
                        int adminid = admin.AdminLogin(id, pwd);
                        if (adminid > 0)
                        {
                            int status = admin.AdminIfLogin(id);
                            if (status != 0)
                            {   
                                 DataSet ds = new DataSet();
                                str = "select AdminName from Admins where AdminID="+"'"+id+"'";
                                ds = admin.GetDataSet(str, "users");
                                Session["username"] = ds.Tables["users"].Rows[0][0];
                                Session["userident"] = "admin";
                                Session["userid"] = id;
                                Session["userpwd"] = pwd;
                                Response.Redirect("AdminMain.aspx");
                            }
                            else
                                lblError.Text = "该用户已经登录!";
                        }
                        else
                        {
                            lblError.Text = "登录失败!用户名与密码不符,请重新输入!";
                        }
                        admin.Close();
                        break;
                    }
            }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        //ID号与密码值清空
        txtID.Text  = "";
        txtPwd.Text = "";
    }
}

⌨️ 快捷键说明

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