제목 : 삭제 페이지 클래스 작성 : /BasicCS/Delete.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
namespace BasicCSVS
{
/// <summary>
/// Delete에 대한 요약 설명입니다.
/// </summary>
public class Delete : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblNum;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.Button btnDelete;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Button btnCancel;
protected string strNum;//
private void Page_Load(object sender, System.EventArgs e)
{
strNum = Request.QueryString["Num"];
if(strNum == null)
Response.Redirect("./List.aspx");
if(!IsPostBack)
{
lblNum.Text = strNum;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 이 호출은 ASP.NET Web Form 디자이너에 필요합니다.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnDelete_Click(object sender, System.EventArgs e)
{
SqlConnection objCon = new SqlConnection();
objCon.ConnectionString = ConfigurationSettings.AppSettings["CONNECTION_STRING"];
objCon.Open();
SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText = "procReadPasswordBasic";
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.Parameters.Add("@Num", SqlDbType.Int);
objCmd.Parameters["@Num"].Value = int.Parse(strNum);
string strPassword = objCmd.ExecuteScalar().ToString();
if(strPassword == txtPassword.Text.ToString())
{
objCmd.CommandText = "procDeleteBasic";
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.ExecuteNonQuery();
objCon.Close();
Response.Redirect("./List.aspx");
}
else
{
lblMessage.Text = "비밀번호가 틀립니다.";
}
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
Response.Redirect("./View.aspx?Num=" + strNum);
}
}
}