제목 : 수정 페이지 클래스 작성 : /BasicCS/Modify.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>
    /// Modify에 대한 요약 설명입니다.
    /// </summary>
    public class Modify : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Label lblNum;
        protected System.Web.UI.WebControls.TextBox txtName;
        protected System.Web.UI.WebControls.TextBox txtEmail;
        protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
        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.TextBox txtPassword;
        protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
        protected System.Web.UI.WebControls.Button btnModify;
        protected System.Web.UI.WebControls.Label lblError;
        protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
        protected System.Web.UI.WebControls.TextBox txtHomepage;
        protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator2;
        protected System.Web.UI.WebControls.RadioButtonList rdoEncoding;
        protected System.Web.UI.WebControls.Button btnList;
        protected string strNum;//앞에서 넘겨져 온 번호 저장
        private void Page_Load(object sender, System.EventArgs e)
        {
            strNum = Request.QueryString["Num"];
            if(strNum == null)
            {
                Response.Redirect("./List.aspx");
            }
            if(!this.IsPostBack)
            {
                ReadData();//넘겨져 온 번호에 해당하는 글만 읽어서 각 레이블에 출력
            }
        }
        private void ReadData()
        {
            SqlConnection objCon = new SqlConnection();
            objCon.ConnectionString = ConfigurationSettings.AppSettings["CONNECTION_STRING"];
            objCon.Open();
            SqlCommand objCmd = new SqlCommand();
            objCmd.Connection = objCon;
            objCmd.CommandText = "procViewBasic";
            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();
        }
        #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.btnModify.Click += new System.EventHandler(this.btnModify_Click);
            this.btnList.Click += new System.EventHandler(this.btnList_Click);
            this.Load += new System.EventHandler(this.Page_Load);
        }
        #endregion
        private void btnModify_Click(object sender, System.EventArgs e)
        {
            SqlConnection objCon = new SqlConnection();
            objCon.ConnectionString = ConfigurationSettings.AppSettings["CONNECTION_STRING"];
            //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 = "procReadPasswordBasic";
            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 = "procUpdateBasic";
                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("./View.aspx?Num=" + strNum);//수정했던 글            
            }
            else
            {
                lblError.Text = "비밀번호가 틀립니다.";
            }
            objCon.Close();
        }
        private void btnList_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("./List.aspx");
        }
    }
}