ASP.NET 기초 강의실

시삽: 레드플러스 님 
게시판 이동:
 제목 : 31.6. 회원 가입 : 회원 정보 수정 및 탈퇴 페이지 : UserInfor.ascx.cs
글번호: 198
작성자: 레드플러스
작성일: 2007/06/25 오후 6:25:00
조회수: 6985
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("~/"); // 루트로 이동
  }
}
 
이전 글   다음 글 삭제 수정 답변 글쓰기 리스트


관련 아티클 리스트
  제       목 파일 작성자 작성일 조회
이전글 32. 자주 사용되는 메서드를 클래스라이브러리 프로젝트로 포함 - 레드플러스 2007-06-26 5564
  31. 회원 가입 - 레드플러스 2007-06-22 6937
  31.1. 회원 가입 관련 테이블, 뷰, 저장 프로시저 구문 - 레드플러스 2007-06-22 7618
  31.2. ~/Web.config - 레드플러스 2007-06-22 7013
  31.2.3. DAAB : Microsoft.ApplicationBlocks.Data... Microsoft.ApplicationBlocks.Data(1).dll(32 KB) 레드플러스 2007-07-11 5414
  31.3. 회원 가입 페이지 : ~/Register.ascx - 레드플러스 2007-06-22 5792
  31.3.1. 회원 가입 페이지 : ~/Register.ascx.cs - 레드플러스 2007-06-22 5662
  31.4. 회원 가입 : 로그인 페이지 : Login.ascx - 레드플러스 2007-06-22 5551
  31.4. 회원 가입 : 로그인 페이지 : Login.ascx.cs - 레드플러스 2007-06-22 6284
  31.5. 회원 가입 : 회원 정보 표시 : LoginInfor.ascx - 레드플러스 2007-06-22 6175
  31.5.1. 회원 가입 : 회원 정보 표시 : LoginInfor.ascx.cs - 레드플러스 2007-06-22 4749
  31.6. 회원 가입 : 회원 정보 수정 및 탈퇴 페이지 : UserInfor.asc... - 레드플러스 2007-06-25 6910
현재글 31.6. 회원 가입 : 회원 정보 수정 및 탈퇴 페이지 : UserInfor.asc... - 레드플러스 2007-06-25 6985
  31.7. (관리자 전용) 회원 전체 리스트 출력 : UserList.ascx - 레드플러스 2007-06-29 4720
  31.7.1. (관리자 전용) 회원 전체 리스트 출력 : UserList.ascx.c... - 레드플러스 2007-06-29 4895
  31.8. 회원 가입 : (관리자 전용) 회원 정보 변경 : UserView.ascx... - 레드플러스 2007-07-02 9306
  31.8.1. 회원 가입 : (관리자 전용) 회원 정보 변경 : UserView.as... - 레드플러스 2007-07-02 4631
  31.9. 회원 가입 : 로그인 환영 메시지 페이지 : Greetings.ascx - 레드플러스 2007-07-04 5697
  31.9.1. 회원 가입 : 로그인 환영 메시지 페이지 : Greetings.ascx... - 레드플러스 2007-07-04 4802
  31.10. 회원 가입 : (관리자)회원에게 그룹 권한 설정 : UserViewAdd... - 레드플러스 2007-07-05 4683
  31.10.1. 회원 가입 : (관리자)회원에게 그룹 권한 설정 : UserViewA... - 레드플러스 2007-07-05 4624
  31.11. NewGroup.ascx : 새로운 그룹(Roles) 추가 - 레드플러스 2007-07-06 4453
  31.11.1. NewGroup.ascx.cs : 새로운 그룹(Roles) 추가 - 레드플러스 2007-07-06 4436
  31.12. GroupList.ascx : 전체 그룹(Roles) 리스트 : 컨트롤 ... - 레드플러스 2007-07-06 4965
  31.13. 그룹 상세 정보 보기 : GroupView.ascx?UID={0} - 레드플러스 2007-07-10 4828
  31.13.1. 그룹 상세 정보 보기 : GroupView.ascx.cs - 레드플러스 2007-07-10 5064
다음글 30. 기본형 게시판 만들기(3계층으로 분리하지 않음) - 레드플러스 2007-06-18 8147
 
손님 사용자 Anonymous (손님)
로그인 Home