?? login.aspx.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 + -