제목 : 31.8.1. 회원 가입 : (관리자 전용) 회원 정보 변경 : UserView.ascx.cs
글번호:
|
|
205
|
작성자:
|
|
레드플러스
|
작성일:
|
|
2007/07/02 오후 6:14:00
|
조회수:
|
|
4979
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 UserViewControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
// 최고관리자만 회원 정보 관리
if (Page.User.Identity.Name.ToLower() != "administrator")
{
Response.Redirect("~/Login.aspx");
}
// UserManager.aspx에서 UID값으로 쿼리스트링이 넘어오면...
if (Request["UID"] != null)
{
if (!Page.IsPostBack) // 처음 로드할 때에만 사용자 정보 표시
{
DisplayData();
}
}
}
private void DisplayData()
{
SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings[
"ConnectionString"].ConnectionString);
objCon.Open();
SqlCommand objCmd = new SqlCommand(
"Select * From Users Where UID = @UID", objCon);
objCmd.Parameters.AddWithValue("@UID", Request["UID"]);
SqlDataReader objDr = objCmd.ExecuteReader();
while (objDr.Read()) {
txtDomainID.Text = objDr["DomainID"].ToString();
txtName.Text = objDr["Name"].ToString();
txtEmail.Text = objDr["Email"].ToString();
txtDescription.Text = objDr["Description"].ToString();
if (Convert.ToInt32(objDr["Blocked"]) == 0) {
this.optBlocked.Items[0].Selected = true;//사용 가능 체크
}
else {
this.optBlocked.Items[1].Selected = true;//잠금 체크
}
}
objDr.Close();
objCon.Close();
}
protected void btnModifyProfile_Click(object sender, EventArgs e)
{
//[1] 커넥션
SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
objCon.Open();
//[2] 커멘드
SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText = "UpdateUserAdmin";
objCmd.CommandType = CommandType.StoredProcedure;
//[3] 파라미터추가
objCmd.Parameters.AddWithValue("@DomainID", txtDomainID.Text);
objCmd.Parameters.AddWithValue("@Name", txtName.Text);
objCmd.Parameters.AddWithValue("@Password", txtNewPassword.Text);
objCmd.Parameters.AddWithValue("@Email", txtEmail.Text);
objCmd.Parameters.AddWithValue("@Description", txtDescription.Text);
objCmd.Parameters.AddWithValue("@Blocked", optBlocked.SelectedValue);
objCmd.Parameters.AddWithValue("@UID", Request["UID"]);
//[4] 실행
objCmd.ExecuteNonQuery();
//[5] 마무리
objCon.Close();
Response.Redirect("UserView.aspx?UID=" + Request["UID"]);
}
protected void btnDeleteUser_Click(object sender, EventArgs e)
{
//아이디 받기
string strDomainID = txtDomainID.Text.ToLower();
if (strDomainID == "administrator" ||
strDomainID == "guest" || strDomainID == "anonymous")
{
string strJs = @"
<script>
alert('해당사용자는 관리 목적의 사용자로 삭제할 수 없습니다.');
</script>
";
// 자바스크립트 실행 : 경고창 띄우기
Page.ClientScript.RegisterStartupScript(
this.GetType(), "gogo", strJs
);
}
else
{
DeleteProcess(); // 삭제 진행
}
}
private void DeleteProcess()
{
//[1] 커넥션
SqlConnection objCon = new SqlConnection();
objCon.ConnectionString =
ConfigurationManager.ConnectionStrings[
"ConnectionString"].ConnectionString;
objCon.Open();
//[2] 커멘드
SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText = "DeleteUser";
objCmd.CommandType = CommandType.StoredProcedure;
//[3] 파라미터추가
objCmd.Parameters.AddWithValue(
"@DomainID", txtDomainID.Text);
//[4] 실행
objCmd.ExecuteNonQuery();
//[5] 마무리
objCon.Close();
Response.Redirect("UserList.aspx");
}
}