QuicklyBuildModel/Login.aspx.cs[快速类建模型登录页面代码]

来源:互联网 发布:网络用语唔是什么意思 编辑:程序博客网 时间:2024/04/29 00:32

 

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace objLogin.QuicklyBuildModel
{
 /// <summary>
 /// LoginQuicklyModel 的摘要说明。(未定稿 最后更新6.28)
 /// </summary>
 public class LoginQuicklyModel : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Label Label1;
  protected System.Web.UI.WebControls.Label Label2;
  protected System.Web.UI.WebControls.TextBox tbUserName;
  protected System.Web.UI.WebControls.TextBox tbPassword;
  protected System.Web.UI.WebControls.Button btnLogin;
  protected System.Web.UI.WebControls.RequiredFieldValidator ValidatorToPassword;
  protected System.Web.UI.WebControls.RequiredFieldValidator ValidatorToUserName;
  /// <summary>
  /// 用户对象
  /// </summary>
  private User user;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  private void btnLogin_Click(object sender, System.EventArgs e)
  {
      this.user = new User(this.tbUserName.Text,this.tbPassword.Text);
   if(this.user.CheckLoginOK(true))
//   if(this.user.CheckLoginOK(false))
   {    

    WriteToSession();//理想当中应用this.user.InitSession();实现
    Response.Redirect("detail.aspx");
   }
   else
    ShowLoginFailMessage();
  }

  /// <summary>
  /// 将用户信息写入Session
  /// </summary>
  private void WriteToSession()
  {
   Session["UserName"] = this.user.UserName;
   Session["UserRank"] = 1;
  }

  /// <summary>
  /// 显示登录失败信息
  /// </summary>
  private void ShowLoginFailMessage()
  {
   Response.Write(this.user.GetCheckLoginFailMessage());
  }
 }
}

 

原创粉丝点击