namespace Home.Member
{
using System;
using System.Configuration;//
using System.Data.SqlClient;//
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class Login1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Panel Panel2;
protected System.Web.UI.WebControls.Label lblUserName;
protected System.Web.UI.WebControls.TextBox txtUserID;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.LinkButton btnLogin;
protected System.Web.UI.WebControls.LinkButton btnRegister;
protected System.Web.UI.WebControls.LinkButton btnLogout;
protected System.Web.UI.WebControls.Label lblUserID;
// ÃʱâÈ
private void Page_Load(object sender, System.EventArgs e)
{
if(Session["UserID"] == null
|| Session["UserID"].ToString() == "")//·Î±×ÀÎ ÇÏÁö ¾ÊÀ½
{
this.Panel1.Visible = true;
this.Panel2.Visible = false;
}
else
{
this.Panel1.Visible = false;
this.Panel2.Visible = true;
this.lblUserName.Text = Session["UserName"].ToString();
this.lblUserID.Text = Session["UserID"].ToString();
}
}
// ·Î±×ÀÎ
private void btnLogin_Click(object sender, System.EventArgs e)
{
string strUserID = this.txtUserID.Text;//¾ÆÀ̵ð
string strPassword = this.txtPassword.Text;//ºñ¹Ð¹øÈ£
SqlConnection objCon = new SqlConnection(
ConfigurationSettings.AppSettings["ConnectionString"]);
objCon.Open();
SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText =
"Select * From Users Where UserID = '"
+ strUserID + "' And Password = '" + strPassword + "'";
objCmd.CommandType = CommandType.Text;
SqlDataReader objDr = objCmd.ExecuteReader();
if(objDr.Read()){
Session["UserID"] = objDr["UserID"];
Session["UserName"] = objDr["UserName"];
this.Panel1.Visible = false;
this.Panel2.Visible = true;
this.lblUserName.Text = Session["UserName"].ToString();
this.lblUserID.Text = Session["UserID"].ToString();
}
else{
string strMsg =
"";
Page.RegisterClientScriptBlock("no", strMsg);
}
objCon.Close();
}
// ȸ¿ø °¡ÀÔ
private void btnRegister_Click(object sender, System.EventArgs e)
{
Response.Redirect("/Home/Member/Register.aspx");
}
// ·Î±×¾Æ¿ô
private void btnLogout_Click(object sender, System.EventArgs e)
{
Session.Abandon();//¼¼¼Ç ³¯¸®±â
this.Panel1.Visible = true;
this.Panel2.Visible = false;
}
#region Web Form µðÀÚÀ̳ʿ¡¼ »ý¼ºÇÑ ÄÚµå
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: ÀÌ È£ÃâÀº ASP.NET Web Form µðÀÚÀ̳ʿ¡ ÇÊ¿äÇÕ´Ï´Ù.
//
InitializeComponent();
base.OnInit(e);
}
///
/// µðÀÚÀÌ³Ê Áö¿ø¿¡ ÇÊ¿äÇÑ ¸Þ¼µåÀÔ´Ï´Ù. ÀÌ ¸Þ¼µåÀÇ ³»¿ëÀ»
/// ÄÚµå ÆíÁý±â·Î ¼öÁ¤ÇÏÁö ¸¶½Ê½Ã¿À.
///
private void InitializeComponent()
{
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
this.btnRegister.Click += new System.EventHandler(this.btnRegister_Click);
this.btnLogout.Click += new System.EventHandler(this.btnLogout_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}