?? default.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.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
DBClass dbObj=new DBClass() ;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Random randobj = new Random();
//lbValidate.Text = randobj.Next(1000, 10000).ToString();
lbValidate.Text = new randomCode().RandomNum(4); //產生驗證碼
//利用GetConfigInfo方法獲取系統配置信息
GetConfigInfo();
}
}
//登錄按鈕
protected void imgbtnLoad_Click(object sender, ImageClickEventArgs e)
{
if (txtUserName.Text.Trim() == "" && txtPassWord.Text.Trim() == "")
{
Response.Write("<script>alert('對不起,請輸入用戶名和密碼!');location='javascript:history.go(-1)';</script>");
return;
}
else if (txtValidate.Text == "" || txtValidate.Text != lbValidate.Text)
{
Response.Write("<script>alert('驗證碼不正確');location='javascript:history.go(-1)';</script>");
return;
}
else
{
//利用GetUserInfo方法,判斷用戶是否正確登錄。
//如果正確登錄,則修改用戶表信息,并跳轉到Index.aspx頁
GetUserInfo(txtUserName.Text.Trim());
}
}
/// <summary>
/// 獲取系統配置信息
/// </summary>
public void GetConfigInfo()
{
Session["isOpen"] = "";
Session["isSearch"] = "";
SqlConnection myConn = dbObj.GetConnection();
SqlCommand myCmd = new SqlCommand("Proc_GetConfigInfo", myConn);
myCmd.CommandType = CommandType.StoredProcedure;
//執行過程
myConn.Open();
SqlDataReader rd = myCmd.ExecuteReader();
if (rd.Read())
{
Session["isOpen"]=rd["isOpen"];
Session["isSearch"] = rd["isSearch"];
}
else
{
Response.Write("<script>alert('對不起,系統發生未知錯誤,請重新登錄!');location='javascript:history.go(-1)';</script>");
}
rd.Close();
myCmd.Dispose();
myConn.Close();
}
/// <summary>
/// 獲取用戶登錄信息
/// </summary>
/// <param name="P_Str_userId">唯一標志</param>
public void GetUserInfo(string P_Str_userId)
{
Session["UID"] = "";
Session["Username"] = "";
Session["UserpowerID"] = "";
Session["Userpower"] = "";
Session["Admin"] = -1;
SqlConnection myConn = dbObj.GetConnection();
SqlCommand myCmd = new SqlCommand("Proc_GetUserInfo", myConn);
myCmd.CommandType = CommandType.StoredProcedure;
//添加參數
SqlParameter userId = new SqlParameter("@userid", SqlDbType.NVarChar, 50);
userId.Value = P_Str_userId;
myCmd.Parameters.Add(userId);
//執行過程
myConn.Open();
SqlDataReader rd = myCmd.ExecuteReader();
if (rd.Read())
{
if (txtPassWord.Text.Trim() != rd["userpass"].ToString())
{
Response.Write("<script>alert('對不起,您輸入的密碼不正確!');location='javascript:history.go(-1)';</script>");
}
else
if (((chkbtnPower.Checked == false) && (Convert.ToInt32(rd["userpower"].ToString()) == 1)) || ((chkbtnPower.Checked == true ) && (Convert.ToInt32(rd["userpower"].ToString()) == 0)))
{
Response.Write("<script>alert('對不起,您登錄的身份不對!');location='javascript:history.go(-1)';</script>");
}
else
{
Session["UID"] = rd["id"];
Session["Username"] = rd["userid"];
Session["UserpowerID"] = rd["userpower"];
if (chkbtnPower.Checked == true)
{
Session["Userpower"] = "管理員";
}
else
{
Session["Userpower"] = "教師";
}
if (Convert.ToInt32(rd["userpower"].ToString()) == 1)
{
Session["Admin"] = 1;
}
dbObj.UpdateUserInfo(Convert.ToString(Session["UID"]));
Response.Redirect("~/Frame/Index.aspx");
}
}
else
{
Response.Write("<script>alert('對不起,您輸入的用戶名不存在!');location='javascript:history.go(-1)';</script>");
}
rd.Close();
myCmd.Dispose();
myConn.Close();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -