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

.net编程

开发平台:

C#

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