메인으로
list 페이지를 사용하였고 검색페이지는 list 페이지와 기능이 완벽하게 동일함으로 스킵하였습니다.
페이지코딩
순서는 list => write => view => update => delete 입니다.
[list.aspx]
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data.SqlClient;
using
System.Configuration;
using
System.Data;
using
System.Data.OleDb;
namespace
Board
{
public partial class list : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
boardGrid_Bind();
}
protected void WriteButton_Click(object sender, EventArgs e)
{
Response.Redirect("write.aspx");
}
protected void boardGrid_Bind()
{
OleDbDataAdapter adapter = null;
OleDbConnection conn;
string conStr = "Provider=MSDAORA;data source=ONJ;User
ID=scott;Password=tiger";
conn = new OleDbConnection(conStr);
conn.Open();
string sqlString = "select * from board ORDER BY wNo DESC";
adapter = new OleDbDataAdapter(sqlString, conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
ListGrid.DataSource = ds;
ListGrid.DataBind();
conn.Close();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
OleDbDataAdapter adapter = null;
OleDbConnection conn;
string conStr = "Provider=MSDAORA;data source=ONJ;User
ID=scott;Password=tiger";
conn = new OleDbConnection(conStr);
conn.Open();
//값이 있을 때만 검색
if (txtSearchString.Text.Trim() != "")
{
string where = "";
if (listSearch.SelectedItem.Value != "wName")
{
where = string.Format(
" where {0} like '%{1}%'",
listSearch.SelectedItem.Value,
txtSearchString.Text
);
}
else
{
where = string.Format(
" where wName like '%{0}%' or wContent like '%{0}%' or wTitle like
'%{0}%'",
txtSearchString.Text
);
}
string sqlString = "select wNo, wTitle, wContent, wName, wDate, wEmail
from board "+where+" ORDER BY wNo DESC";
adapter = new OleDbDataAdapter(sqlString, conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
ListGrid.DataSource = ds;
ListGrid.DataBind();
conn.Close();
}
}
}
}
[write]
namespace
Board
{
public partial class wrtie : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//글목록 페이지ㅣ 이동
protected void btnList_Click(object sender, EventArgs e)
{
Response.Redirect("list.aspx");
}
//저장 글저장
protected void btnSave_Click(object sender, EventArgs e)
{
OleDbConnection conn;
string conStr = "Provider=MSDAORA;data source=ONJ;User
ID=scott;Password=tiger";
conn = new OleDbConnection(conStr);
conn.Open();
OleDbCommand cmd = new OleDbCommand("insert into board(wNo,
wName,wEmail,wTitle,wContent,wPwd, wDate ) values(boa_seq.nextval,'" +
this.txtName.Text +
"','" + this.txtEmail.Text + "','" + this.txtTitle.Text + "','" +
this.txtContent.Text + "','" + this.txtPwd.Text + "',sysdate)");
cmd.Connection = conn;
cmd.ExecuteNonQuery();
conn.Close();
Response.Redirect("list.aspx");
}
}
}
[view]
namespace
Board
{
public partial class view : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
OleDbConnection conn;
string conStr = "Provider=MSDAORA;data source=ONJ;User
ID=scott;Password=tiger";
conn = new OleDbConnection(conStr);
conn.Open();
OleDbCommand command = conn.CreateCommand();
command.CommandText = "select wNo, wTitle, wContent, wName, wDate,
wEmail, wPwd from board where wNo = " + Request["wNo"];
OleDbDataReader orareader = command.ExecuteReader();//SELECT
쿼리실행
if (orareader.HasRows)
{
if (orareader.Read())
{
this.lblCount.Text =
orareader["wDate"].ToString();
this.lblPasswod.Text = "*****";
this.linkName.Text =
orareader["wName"].ToString();
this.lblTitle.Text =
orareader["wTitle"].ToString();
this.lblContent.Text =
orareader["wContent"].ToString();
}
}
conn.Close();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
// 글목록으로 이동
protected void btnList_Click(object sender, EventArgs e)
{
Response.Redirect("list.aspx");
}
protected void btnDelete_Click(object sender, EventArgs e)
{
//Response.Redirect("delete.aspx");
Response.Redirect(string.Format("delete.aspx?wNo={0}",
Request.QueryString["wNo"]));
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
//Response.Redirect("update.aspx");
Response.Redirect(string.Format("update.aspx?wNo={0}",
Request.QueryString["wNo"]));
}
}
}
[update]
namespace
Board
{
public partial class update : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
OleDbConnection conn;
string conStr = "Provider=MSDAORA;data source=ONJ;User
ID=scott;Password=tiger";
conn = new OleDbConnection(conStr);
conn.Open();
OleDbCommand command = conn.CreateCommand();
command.CommandText = "select wNo, wTitle, wContent, wName, wDate,
wEmail, wPwd from board where wNo = " + Request["wNo"];
OleDbDataReader orareader = command.ExecuteReader();//SELECT
쿼리실행
if (orareader.HasRows)
{
if (orareader.Read())
{
this.txtEmail.Text =
orareader["wEmail"].ToString();
this.txtName.Text =
orareader["wName"].ToString();
this.txtTitle.Text =
orareader["wTitle"].ToString();
this.txtContent.Text =
orareader["wContent"].ToString();
}
}
conn.Close();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
// 글목록으로 이동
protected void btnList_Click(object sender, EventArgs e)
{
Response.Redirect("list.aspx");
}
// 취소
protected void btnCancel_Click(object sender, EventArgs e)
{
}
// 수정
protected void btnSave_Click(object sender, EventArgs e)
{
OleDbConnection conn;
string conStr = "Provider=MSDAORA;data source=ONJ;User
ID=scott;Password=tiger";
conn = new OleDbConnection(conStr);
conn.Open();
OleDbCommand command = conn.CreateCommand();
command.CommandText = "select wPwd from board where wNo = " +
Request["wNo"];
string wPwd = command.ExecuteScalar().ToString();//wpwd 컬럼의 선택된 값을 string
형태로 불러온다.
//불러온 비밀번호가 맞는지 확인후 삭제 쿼리 실행
if (this.txtPwd.Text == wPwd)
{
command.CommandText = "update board set wName ='" + txtPwd.Text + "' ,
wEmail='" + txtEmail.Text + "', wTitle='" + txtTitle.Text + "', wContent='" +
txtContent.Text + "' , wDate = sysdate where wNo= " +
Request["wNo"];
command.ExecuteNonQuery();
Clientscript.RegisterStartupscript(typeof(Page), "alert", "<script
language=Javascript>alert('수정이 완료되었습니다!!!');</script>");
Response.Redirect("list.aspx");
}
else Clientscript.RegisterStartupscript(typeof(Page), "alert", "<script
language=Javascript>alert('비밀번호도 모릅니까? 다시해!');</script>");
conn.Close();
}
}
}
[delete]
namespace
Board
{
public partial class delete : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
// 글목록
protected void btnList_Click(object sender, EventArgs e)
{
Response.Redirect("list.aspx");
}
// 취소
protected void btnCancel_Click(object sender, EventArgs e)
{
}
// 삭제처리
protected void btnDelete_Click(object sender, EventArgs e)
{
OleDbConnection conn;
string conStr = "Provider=MSDAORA;data source=ONJ;User
ID=scott;Password=tiger";
conn = new OleDbConnection(conStr);
conn.Open();
OleDbCommand command = conn.CreateCommand();
command.CommandText = "select wPwd from board where wNo = " +
Request["wNo"];
string wPwd = command.ExecuteScalar().ToString();//wpwd 컬럼의 선택된 값을 string
형태로 불러온다.
//불러온 비밀번호가 맞는지 확인후 삭제 쿼리 실행
if (this.txtPwd.Text == wPwd)
{
command.CommandText = "delete from board where wNo=" +
Request["wNo"];
command.ExecuteNonQuery();
Clientscript.RegisterStartupscript(typeof(Page), "alert","<script
language=Javascript>alert('삭제되었다!!! 영원히!!');</script>");
Response.Redirect("list.aspx");
}
else Clientscript.RegisterStartupscript(typeof(Page), "alert", "<script
language=Javascript>alert('비밀번호도 모릅니까? 다시해!');</script>");
conn.Close();
}
}
}
댓글 없음:
댓글 쓰기