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"]);
}
} |