www.pudn.com > xyl.rar > UserLogin.ascx.cs
namespace Com991205
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
///
/// Summary description for UserLogin.
///
public class UserLogin :Com991205.UserModuleControl
{
protected System.Web.UI.WebControls.TextBox UserName;
protected System.Web.UI.WebControls.TextBox Password;
protected System.Web.UI.WebControls.ImageButton SigninBtn;
protected System.Web.UI.WebControls.ImageButton GuestLoginBtn;
protected System.Web.UI.WebControls.Label Message;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.SigninBtn.Click += new System.Web.UI.ImageClickEventHandler(this.SigninBtn_Click);
this.GuestLoginBtn.Click += new System.Web.UI.ImageClickEventHandler(this.GuestLoginBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void SigninBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
String userId = "";
if((UserName.Text.Trim() != "")&&(Password.Text.Trim() != ""))
{
UserDB user = new UserDB();
SqlDataReader recu = user.GetUserLogin(UserName.Text.Trim(),UserDB.Encrypt(Password.Text.Trim()));
if(recu.Read())
{
userId = recu["UserID"].ToString();
}
recu.Close();
if((userId != null)&&(userId != ""))
{
Session["UserID"] = userId;
Session["UserName"] = UserName.Text.Trim();
UserInfoOrContDB userInfo = new UserInfoOrContDB();
//更新用户登陆后的信息
userInfo.UpdateUserInfo(Int32.Parse(userId));
//返回到初始页面
Response.Redirect(Request.ApplicationPath);
}
else
{
UserName.Text = "";
Password.Text = "";
Response.Write("");
}
}
else
{
Response.Write("");
}
}
private void GuestLoginBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
//游客登陆
Session["UserID"] = "0";
Session["UserName"] = "Guest";
//返回到初始页面
Response.Redirect(Request.ApplicationPath);
}
}
}