블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

Category

Recent Post

Recent Comment

Archive

2009. 10. 8. 01:06 .Net Project/ASP.NET 3.5 Sp1
반응형
 Basic.Delete.aspx 디자인 모드



- 리스트 목록 List.aspx 에서 목록 선택하여 다음과 같이 이동 가능 하며,

- 이동 후에 수정 페이지 Modify.aspx 이동 하고, 삭제 Delete.aspx 로 페이지 이동 하면

- 다음과 같은 화면이 출력 "1번 글을 삭제 하시겠습니까??"

- 암호 텍스트 박스 입력후 암호 일치하면 삭제 완료 되며,

- 암호가 일치(불일치)할 경우에는 Lavel에 "패스워드가 일치 않습니다"라는 메시지 출력 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Delete.aspx.cs"
                                 Inherits="Basic_Delete" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                        "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>글 삭제: Delete</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="lblNum" runat="server" ForeColor="Red"></asp:Label>
                          번 글을 삭제 하겠습니까 <br />
   
    암호 :
    <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
    <asp:Button ID="btnDelete" runat="server" Text="삭제"
            OnClientClick="return confirm('정말로삭제??');"
                                 onclick="btnDelete_Click" />
    <asp:Button ID="btnCancel" runat="server" Text="취소" 
                                 onclick="btnCancel_Click" />
    
    <asp:Label ID="lblError" runat="server" Text="Label"></asp:Label>
   
    </div>
    </form>
</body>
</html>


 Basic.Delete.aspx.Cs 이벤트 컨트롤 관련 모드

using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Data.SqlClient;

public partial class Basic_Delete : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //넘겨져 온 번호 값 검사
        if (String.IsNullOrEmpty(Request["Num"]))
        {
            Response.Write("잘못된 요청입니다");
            Response.End();
        }
        else
        {
            //레이블에 넘겨져 온 번호 값 출력
            this.lblNum.Text = Request["Num"];
        }
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        if (IsPasswordCorrect())
        {
            SqlConnection con = new SqlConnection
                                  (ConfigurationManager.ConnectionStrings
                                   ["ConnectionString"].ConnectionString);
            con.Open();

            SqlCommand cmd = new SqlCommand("DeleteBasic", con);
            
            cmd.CommandType = CommandType.StoredProcedure;

            //파라미터:List.aspx에서 넘겨운 쿼리 스트링값
            cmd.Parameters.AddWithValue("@Num", Request["Num"]);
            cmd.Parameters.AddWithValue("@Password", txtPassword.Text);

            cmd.ExecuteNonQuery(); //삭제

            //삭제 후 리스트로 이동
            Response.Redirect("List.aspx");
        }
        else
     {
            this.lblError.Text = "암호가 틀립니다";   
     }
    }

    //번호와 암호가 맞으면 참을 반환, 그렇지 않으면 거짓을 반환
    private bool IsPasswordCorrect()
    {
        bool result = false;
        SqlConnection con = new SqlConnection
                             (ConfigurationManager.ConnectionStrings 
                              ["ConnectionString"].ConnectionString);
        con.Open();

        SqlCommand cmd = new SqlCommand(
            "Select *From Basic Where Num =
                                                   @Num And Password = @Password", con);

        cmd.Parameters.AddWithValue("@Num", Request["Num"]);
        cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
       
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read()) //데이터가 읽혀진다면, 번호와 암호가 맞음
        {
            result = true;

        }
        return result;

    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        //취소버튼 클릭시 뒤로(상세 보기 페이지로 이동)
        Response.Redirect("View.aspx?Num=" + Request["Num"]);
    }
}







반응형
posted by Magic_kit