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
} |