제목 : 31.6. 회원 가입 : 회원 정보 수정 및 탈퇴 페이지 : UserInfor.ascx.cs
    
    
        
            
                | 글번호: |  | 198 | 
            
                | 작성자: |  | 레드플러스 | 
            
                | 작성일: |  | 2007/06/25 오후 6:25:00 | 
            
            
                | 조회수: |  | 8417 | 
            
        
     
 
    
	
	
    
	using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;//
public partial class UserInforControl : System.Web.UI.UserControl
{
  protected void Page_Load(object sender, EventArgs e)
  {
    // 로그인되었는지 안 되었는지 확인
    if (Page.User.Identity.IsAuthenticated) // 참이면 로그인
    {
      if (!Page.IsPostBack) // 수정 기능이 있을 때에는 반드시 처음로드
      {
        DisplayData(); // 출력 전담 메서드 
      }    
    }
    else
    {
      Response.Redirect("~/Login.aspx"); // 로그인 페이지로 강제 이동
    }
  }
  // 상세 패턴
  private void DisplayData()
  {
    SqlConnection objCon = new SqlConnection(
      ConfigurationManager.ConnectionStrings[
        "ConnectionString"].ConnectionString);
    objCon.Open();
    SqlCommand objCmd = new SqlCommand("GetUser", objCon);
    objCmd.CommandType = CommandType.StoredProcedure;
    objCmd.Parameters.AddWithValue(
      "DomainID", Page.User.Identity.Name);
    SqlDataReader objDr = objCmd.ExecuteReader();
    if (objDr.Read())
    {
      this.lblUserID.Text = Page.User.Identity.Name;
      this.lblUserName.Text = objDr["Name"].ToString();
      this.txtEmail.Text = objDr["Email"].ToString();
      this.txtDescription.Text = objDr["Description"].ToString();
    }
    objDr.Close();
    objCon.Close();
  }
  protected void btnChangePassword_Click(object sender, EventArgs e)
  {
    SqlConnection objCon = new SqlConnection(
      ConfigurationManager.ConnectionStrings[
        "ConnectionString"].ConnectionString);
    objCon.Open();
    SqlCommand objCmd = new SqlCommand("ChangePassword", objCon);
    objCmd.CommandType = CommandType.StoredProcedure;
    objCmd.Parameters.AddWithValue(
      "@OriginalPassword", txtPassword.Text);
    objCmd.Parameters.AddWithValue(
      "@NewPassword", txtPasswordNew.Text);
    objCmd.Parameters.AddWithValue(
      "@DomainID", Page.User.Identity.Name);
    int result = objCmd.ExecuteNonQuery();// 업데이트 : 1 그렇지 않으면 0 반환
    objCon.Close();
    if (result > 0)
    {
      // 현재 페이지 다시 로드
      Response.Redirect(Request.ServerVariables["SCRIPT_NAME"]);  
    }
    else
    {
      Response.Write("암호가 틀립니다.");
    }
  }
  protected void btnChangeProfile_Click(object sender, EventArgs e)
  {
    SqlConnection objCon = new SqlConnection(
      ConfigurationManager.ConnectionStrings[
        "ConnectionString"].ConnectionString);
    objCon.Open();
    SqlCommand objCmd = new SqlCommand("UpdateUser", objCon);
    objCmd.CommandType = CommandType.StoredProcedure;
    objCmd.Parameters.AddWithValue("@Email", txtEmail.Text);
    objCmd.Parameters.AddWithValue("@Description", txtDescription.Text);
    objCmd.Parameters.AddWithValue("@DomainID", Page.User.Identity.Name);
    int result = Convert.ToInt32(objCmd.ExecuteScalar());
    objCon.Close();
    if (result > 0)
    {
      // 현재 페이지 다시 로드
      Response.Redirect(Request.ServerVariables["SCRIPT_NAME"]);
    }
    else
    {
      Response.Write("프로필 정보가 업데이트되지 못했습니다.");
    }
  }
  // 회원 탈퇴
  protected void btnDelete_Click(object sender, EventArgs e)
  {
    SqlConnection objCon = new SqlConnection(
      ConfigurationManager.ConnectionStrings[
        "ConnectionString"].ConnectionString);
    objCon.Open();
    SqlCommand objCmd = new SqlCommand("DeleteUser", objCon);
    objCmd.CommandType = CommandType.StoredProcedure;
    objCmd.Parameters.AddWithValue(
      "@DomainID", Page.User.Identity.Name);
    objCmd.ExecuteNonQuery();// 삭제
    objCon.Close();
    FormsAuthentication.SignOut();//현재 접속자 자동 로그아웃
    Response.Redirect("~/"); // 루트로 이동
  }
}
    
	
    
    
 
    
    
    
    
    
    
    
    
    
    
    
     
    
        