using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;//
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace SampleCS.Reply
{
/// <summary>
/// Reply에 대한 요약 설명입니다.
/// </summary>
public class Reply : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.TextBox txtEmail;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.TextBox txtHomepage;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
protected System.Web.UI.WebControls.TextBox txtTitle;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
protected System.Web.UI.WebControls.TextBox txtContent;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
protected System.Web.UI.WebControls.RadioButtonList rdoEncoding;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator5;
protected System.Web.UI.WebControls.Button btnWrite;
protected System.Web.UI.WebControls.Button btnList;
protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
private void Page_Load(object sender, System.EventArgs e)
{
if(this.IsPostBack != true)
{
SqlConnection objCon = new SqlConnection();
objCon.ConnectionString = Application["CONNECTION_STRING"].ToString();
objCon.Open();
SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText = "Select * From Reply Where Num = " + Request.QueryString["Num"].ToString();
objCmd.CommandType = CommandType.Text;
SqlDataReader objDr = objCmd.ExecuteReader();
if(objDr.Read())
{
txtTitle.Text = "Re : " + objDr["Title"].ToString();
txtContent.Text = objDr["Content"].ToString();
txtContent.Text += "\n--------답변 하기--------\n";
}
objDr.Close();
objCon.Close();
}
}
#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.btnWrite.Click += new System.EventHandler(this.btnWrite_Click);
this.btnList.Click += new System.EventHandler(this.btnList_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnList_Click(object sender, System.EventArgs e)
{
Response.Redirect("List.aspx");
}
private void btnWrite_Click(object sender, System.EventArgs e)
{
int intRef = Convert.ToInt32(Request.QueryString["Ref"]);//
int intStep = Convert.ToInt32(Request.QueryString["Step"]);//
int intRefOrder = Convert.ToInt32(Request.QueryString["RefOrder"]);//
SqlConnection objCon = new SqlConnection();
objCon.ConnectionString = Application["CONNECTION_STRING"].ToString();
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 = "Update Reply Set RefOrder = RefOrder + 1" + " "
+ " Where Ref = " + intRef.ToString() + " And RefOrder > " + intRefOrder.ToString();
objCmd.CommandType = CommandType.Text;
objCmd.ExecuteNonQuery();
objCmd.CommandText = "procReplyReply";
objCmd.Parameters.Add("@Name", SqlDbType.VarChar, 25);
objCmd.Parameters.Add("@Email", SqlDbType.VarChar, 100);
objCmd.Parameters.Add("@Title", SqlDbType.VarChar, 150);
objCmd.Parameters.Add("@PostIP", SqlDbType.VarChar, 15);
objCmd.Parameters.Add("@Content", SqlDbType.Text);
objCmd.Parameters.Add("@Password", SqlDbType.VarChar, 20);
objCmd.Parameters.Add("@Encoding", SqlDbType.VarChar, 10);
objCmd.Parameters.Add("@Homepage", SqlDbType.VarChar, 100);
objCmd.Parameters.Add("@Ref", SqlDbType.Int);//Ref : 참조글 번호
objCmd.Parameters.Add("@Step", SqlDbType.Int);//Step : 들여쓰기
objCmd.Parameters.Add("@RefOrder", SqlDbType.Int);//RefOrder : 답글 순서
objCmd.Parameters["@Name"].Value = txtName.Text;
objCmd.Parameters["@Email"].Value = txtEmail.Text;
objCmd.Parameters["@Title"].Value = txtTitle.Text;
objCmd.Parameters["@PostIP"].Value = Request.UserHostAddress;
objCmd.Parameters["@Content"].Value = txtContent.Text;
objCmd.Parameters["@Password"].Value = txtPassword.Text;
objCmd.Parameters["@Encoding"].Value = rdoEncoding.SelectedItem.Text;
objCmd.Parameters["@Homepage"].Value = txtHomepage.Text;
objCmd.Parameters["@Ref"].Value = intRef;//답변글은 부모글의 Ref를 그대로 따라간다.
objCmd.Parameters["@Step"].Value = intStep + 1;
objCmd.Parameters["@RefOrder"].Value = intRefOrder +1;
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.ExecuteNonQuery();
objCon.Close();
Response.Redirect("./List.aspx");
}
}
}