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>
/// BoardModify : 완성형(DotNetNote) 게시판의 수정 페이지
/// </summary>
public partial class DotNetNote_BoardModify : System.Web.UI.Page
{
#region Private Member Variables
protected string strNum;//앞에서 넘겨져 온 번호 저장
#endregion
#region Event Handlers
//넘겨져 온 번호에 해당하는 데이터 로드
protected void Page_Load(object sender, System.EventArgs e)
{
strNum = Request.QueryString["Num"];
if (strNum == null)
{
Response.Redirect("./BoardList.aspx");
}
if (!this.IsPostBack)
{
ReadData();//넘겨져 온 번호에 해당하는 글만 읽어서 각 레이블에 출력
}
}
//글 수정 처리
protected void btnModify_Click(object sender, System.EventArgs e)
{
SqlConnection objCon = new SqlConnection();
objCon.ConnectionString = ConfigurationManager.ConnectionStrings[
"ConnectionString"].ConnectionString;
objCon.Open();
string strName = txtName.Text.Replace("&", "&").Replace(
"<", "<").Replace(">", ">");
string strTitle = txtTitle.Text.Replace("&", "&").Replace(
"<", "<").Replace(">", ">");
SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText = "ReadPasswordDotNetNote";
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.Parameters.Add("@Num", SqlDbType.Int);
objCmd.Parameters["@Num"].Value = int.Parse(strNum);
string strPassword = objCmd.ExecuteScalar().ToString();
objCmd.Parameters.Clear();
if (strPassword == txtPassword.Text.ToString())
{
objCmd.CommandText = "ModifyDotNetNote";
objCmd.Parameters.Add("@Name", SqlDbType.VarChar, 25);
objCmd.Parameters.Add("@Email", SqlDbType.VarChar, 100);
objCmd.Parameters.Add("@Title", SqlDbType.VarChar, 150);
objCmd.Parameters.Add("@ModifyIP", SqlDbType.VarChar, 15);
objCmd.Parameters.Add("@ModifyDate", SqlDbType.DateTime);
objCmd.Parameters.Add("@Content", SqlDbType.Text);
objCmd.Parameters.Add("@Encoding", SqlDbType.VarChar, 10);
objCmd.Parameters.Add("@Homepage", SqlDbType.VarChar, 100);
objCmd.Parameters.Add("@Num", SqlDbType.Int);
objCmd.Parameters["@Name"].Value = strName;
objCmd.Parameters["@Email"].Value = txtEmail.Text;
objCmd.Parameters["@Title"].Value = strTitle;
objCmd.Parameters["@ModifyIP"].Value = Request.UserHostAddress;
objCmd.Parameters["@ModifyDate"].Value = DateTime.Now;//수정일
objCmd.Parameters["@Content"].Value = txtContent.Text;
objCmd.Parameters["@Encoding"].Value =
rdoEncoding.SelectedItem.Text;
objCmd.Parameters["@Homepage"].Value = txtHomepage.Text;
objCmd.Parameters["@Num"].Value = strNum;
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.ExecuteNonQuery();
Response.Redirect("./BoardView.aspx?Num=" + strNum);//수정했던 글
}
else
{
lblError.Text = "비밀번호가 틀립니다.";
}
objCon.Close();
}
//글 리스트 이동 버튼
protected void btnList_Click(object sender, System.EventArgs e)
{
Response.Redirect("./BoardList.aspx");
}
#endregion
#region Private Methods
//각 레이블에 데이터 로드
private void ReadData()
{
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);
objCmd.ExecuteNonQuery();
SqlDataReader objDr = objCmd.ExecuteReader();
if (objDr.Read())
{
lblNum.Text = strNum;
txtName.Text = objDr["Name"].ToString();//이름
txtEmail.Text = objDr["Email"].ToString();
txtHomepage.Text = objDr["Homepage"].ToString();
txtTitle.Text = objDr["Title"].ToString();
txtContent.Text = objDr["Content"].ToString();
}
objDr.Close();
objCon.Close();
}
#endregion
} |