블로그 이미지
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 29 30 31

Category

Recent Post

Recent Comment

Archive

2009. 11. 2. 14:26 .Net Project/ASP.NET 3.5 Sp1
반응형
 Delete.aspx

 <!-- BoardDelete.aspx -->

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

<!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>글 삭제</title>

  <script language="javascript">
  function ConfirmDelete()
  {
   var varFlag = false;
   if(window.confirm("현재 글을 삭제하시겠습니까?"))
   {
    varFlag = true;
   }
   else
   {
    varFlag = false;
   }
   return varFlag;
  }
  </script>

  <link href="../DotNetNote/DotNetNote.css"
    rel="stylesheet" type="text/css" />
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <h3>완성형 게시판</h3>
      <font style="font-size: 9pt; color: #ff0000">
        글&nbsp;삭제 - 글을 삭제하려면 글 작성시에 기록하였던
        비밀번호가 필요합니다.</font>
      <hr width="100%" size="1" />
      <p align="center">
        <asp:Label ID="lblNum" runat="server"
          ForeColor="Red"></asp:Label>
      번 글을 지우시겠습니까?
      <p align="center">
        비밀번호 :
        <asp:TextBox ID="txtPassword" runat="server"
          BorderStyle="Groove" TextMode="Password"></asp:TextBox>
        <asp:Button ID="btnDelete" runat="server"
          BorderStyle="Groove" Text="지우기"
          OnClick="btnDelete_Click"></asp:Button>&nbsp;
        <asp:Button ID="btnCancel" runat="server"
          BorderStyle="Groove" Text="취소"
          OnClick="btnCancel_Click"></asp:Button></p>
      <p align="center">
        <asp:Label ID="lblMessage" runat="server"
          ForeColor="Red" /></p>
    </div>
  </form>
</body>
</html>


 Delete.aspx.Cs

 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;
using System.IO;

/// <summary>
/// BoardDelete : 완성형(DotNetNote) 게시판의 삭제 페이지
/// </summary>
public partial class DotNetNote_BoardDelete : System.Web.UI.Page
{
  #region Private Member Variables
  private string strNum = "";//글 번호
  private string strPassword = "";//비밀번호
  private string strFileName = "";//파일명
  private string strAnswerNum;//답변글 번호
  #endregion

  #region Event Handlers
  //넘겨져 온 번호에 해당하는 글 삭제 메시지
  protected void Page_Load(object sender, System.EventArgs e)
  {
    // 아래 코드는 ClientOnClick과 같은 역할을 하는 코드임
    this.btnDelete.Attributes["OnClick"] = "return ConfirmDelete();";
    strNum = Request.QueryString["Num"];
    if (strNum == null)
      Response.Redirect("./BoardList.aspx");
    if (!IsPostBack)
    {
      lblNum.Text = strNum;
    }
  }

  //글 삭제 처리
  protected void btnDelete_Click(object sender, System.EventArgs e)
  {
    SqlConnection objCon = new SqlConnection();
    objCon.ConnectionString = ConfigurationManager.ConnectionStrings[
      "ConnectionString"].ConnectionString;
    objCon.Open();

    SqlCommand objCmd = new SqlCommand();
    objCmd.Connection = objCon;

    objCmd.CommandText = "ViewDotNetNote";//
    objCmd.CommandType = CommandType.StoredProcedure;
    objCmd.Parameters.Add("@Num", SqlDbType.Int);
    objCmd.Parameters["@Num"].Value = int.Parse(strNum);

    SqlDataReader objDr = objCmd.ExecuteReader();
    if (objDr.Read())
    {
      strPassword = objDr["Password"].ToString();
      strFileName = objDr["FileName"].ToString();
      strAnswerNum = objDr["AnswerNum"].ToString();
    }
    objDr.Close();

    if (strPassword == txtPassword.Text.ToString())
    {
      //업로드 된 파일 삭제
      string strBaseDir = Server.MapPath("./MyFiles");
      FileInfo objFi = new FileInfo(
        Path.Combine(strBaseDir, strFileName));
      if (objFi.Exists)
      {
        objFi.Delete();
      }

      objCmd.CommandText = "DeleteDotNetNote";
      objCmd.CommandType = CommandType.StoredProcedure;
      objCmd.ExecuteNonQuery();
      objCon.Close();

      Response.Redirect("./BoardList.aspx");
    }
    else
    {
      lblMessage.Text = "비밀번호가 틀립니다.";
    }
  }

  //글 삭제 취소 버튼 링크
  protected void btnCancel_Click(object sender, System.EventArgs e)
  {
    Response.Redirect("./BoardView.aspx?Num=" + strNum);
  }
  #endregion
}





반응형
posted by Magic_kit