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

📄 login.aspx.cs

📁 asp.net连带c++技术开发
💻 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;
using System.IO;
using Server;

public partial class _Default : System.Web.UI.Page 
{   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.RadioButtonList1.SelectedIndex = 2;
        }
    }
    protected string userType;
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        //string strConn,string userId,string userPwd,string userType
        
        if (this.RadioButtonList1.SelectedValue == "教师")
        {
            userType = "教师";
        }
        else if (this.RadioButtonList1.SelectedValue == "学生")
        {
            userType = "学生";
        }
        else if (this.RadioButtonList1.SelectedValue == "管理员")
        {
            userType = "管理员";
        }
        else
        {
            userType = this.DropDownList1.SelectedItem.ToString();
        }
        if (UserLogin.Login(ConfigurationManager.AppSettings["strConn"].Trim(), this.txtID.Text, this.txtPwd.Text, userType))
        {
            ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('登录成功')</script>");
            switch (userType)
            {
                case "教师":

                    Session["usrID"] = this.txtID.Text.Trim();
                    Session["userType"] =userType;
                    Session["dept_id"] = GetDept();
                    Response.Redirect("~/Teacher/TeacherMain.aspx");
                    break;
                case "学生":
                    Session["usrID"] = this.txtID.Text.Trim();
                    Session["userType"] =userType ;
                    Session["dept_id"] = GetDept();
                    Response.Redirect("~/Student/StudentMain.aspx");
                    break;
                case "管理员":
                    Session["usrID"] = this.txtID.Text.Trim();
                    Session["userType"] = userType;
                    Response.Redirect("~/Admin/AdminMain.aspx");
                    break;
                default :
                    Session["usrID"] = this.txtID.Text.Trim();
                    Session["userType"] = userType;
                    Session["dept_id"] = this.DropDownList1.SelectedValue.ToString();
                    Response.Redirect("~/DeptAdmin/DeptAdminMain.aspx");
                    break;
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('登录失败')</script>");
        }

    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        this.txtID.Text = null;
        this.txtPwd.Text = null;
    }
    protected int GetDept()
    {
        SqlDataSource sds;
        string strCmd=null;
        switch (userType)
        {
            case "教师":
                strCmd = "SELECT [teach_dep_id] FROM [teacher_tb] where teach_id=";
                break;
            case "学生":
                strCmd = "select stud_dep_id from student_tb where stud_id=";
                break;

        }
       sds = new SqlDataSource(ConfigurationManager.AppSettings["strConn"].Trim(), strCmd  + this.txtID.Text.Trim());
       DataView dv = (DataView)sds.Select(DataSourceSelectArguments.Empty);
       return int.Parse(dv.Table.Rows[0][0].ToString());

    }
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.RadioButtonList1.SelectedValue == "系部")
        {
            SqlDataSource sds = new SqlDataSource(ConfigurationManager.AppSettings["strConn"].Trim(), "SELECT [dept_id],[dept_name] FROM [dept_tb]");
            this.DropDownList1.DataSource = sds;
            this.DropDownList1.DataTextField = "dept_name";
            this.DropDownList1.DataValueField  = "dept_id";
            this.DataBind();
            this.DropDownList1.Visible = true;
        }
        else
        {
            this.DropDownList1.Visible = false;
        }
        
    }
}

⌨️ 快捷键说明

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