Login5.aspx.cs
上传用户:gooyliu
上传日期:2018-09-29
资源大小:5816k
文件大小:3k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using BusinessLogicLayer;
  11. using DataAccessLayer;
  12. public partial class _Default : System.Web.UI.Page 
  13. {
  14.     
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.         this.txtUserID.Focus();
  18.         
  19.         if (!IsPostBack)
  20.         {
  21.             if (!Object.Equals(Request.Cookies["UserID"], null))
  22.             {
  23.                 HttpCookie readcookie = Request.Cookies["UserID"];
  24.                 this.txtUserID.Text = readcookie.Value;
  25.             }
  26.         }
  27.     }
  28.     //登录按钮事件
  29.     protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e)
  30.     {
  31.        
  32.         Users user = new Users();                          //创建Users对象user
  33.         string pwdMd5 = txtPwd.Text.ToString().Trim ();
  34.         
  35.             if (user.CheckPassword(txtUserID.Text.Trim())) //根据用户编号查询用户密码
  36.             {
  37.                 if (user.UserPassword == pwdMd5)           //输入密码与用户密码相同
  38.                 {
  39.                     Session["userID"] = txtUserID.Text.Trim();
  40.                     if (user.RoleID == 1)                  //如果该用户是系统管理员
  41.                     {
  42.                         ;//存储用户编号
  43.                         Response.Redirect("sysAdmin/AdminMain.aspx");//转向总管理员操作界面
  44.                     }
  45.                     else if (user.RoleID == 2)//用户是系统操作员
  46.                     {
  47.                         Response.Redirect("sysOperator/LendBook.aspx");//转向借书还书界面
  48.                     }
  49.                     if (user.RoleID == 3)//用户是读者
  50.                     {
  51.                         Response.Redirect("Reader/ReaderDefault.aspx");
  52.                     }
  53.                 }
  54.                 else//密码错误,给出提示
  55.                 {
  56.                     lblMessage.Text = "您输入的密码错误!";
  57.                 }
  58.             }
  59.             else//用户不存在,给出提示
  60.             {
  61.                 lblMessage.Text = "该用户不存在!";
  62.             }
  63.  //       }
  64.    }
  65.     //protected void ChangeCode_Click(object sender, EventArgs e)
  66.     //{
  67.     //}
  68.     private void CreateCookie()
  69.     {
  70.         HttpCookie cookie = new HttpCookie("UserID");
  71.         if (this.cbxRemeberUser.Checked)
  72.         {
  73.             cookie.Value = this.txtUserID.Text;
  74.         }
  75.         cookie.Expires = DateTime.MaxValue;
  76.         Response.AppendCookie(cookie);
  77.     } 
  78. }