ASP.NET 프로젝트 강의실

시삽: 레드플러스 님 
게시판 이동:
 제목 : Modify.aspx.cs
글번호: 167
작성자: 레드플러스
작성일: 2005/03/10 오후 8:07:46
조회수: 2429
파일: Modify.aspx(1).cs (5 KB) / 전송수: 1556
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;

namespace SampleCS.Upload
{
    /// <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 = Application["CONNECTION_STRING"].ToString();
            objCon.Open();

            SqlCommand objCmd = new SqlCommand();
            objCmd.Connection = objCon;
            objCmd.CommandText = "procViewUpload";
            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 = Application["CONNECTION_STRING"].ToString();
            objCon.Open();

            string strName = txtName.Text.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;");
            string strTitle = txtTitle.Text.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;");

            SqlCommand objCmd = new SqlCommand();
            objCmd.Connection = objCon;
            objCmd.CommandText = "procReadPassword";
            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 = "procUpdateUpload";

                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");
        }
    }
}








 
이전 글   다음 글 삭제 수정 답변 글쓰기 리스트

(댓글을 남기려면 로그인이 필요합니다.)

관련 아티클 리스트
  제       목 파일 작성자 작성일 조회
이전글 6. 답변형 게시판(ReplyCS, ReplyVB) - 레드플러스 2004-01-05 3447
  5. 자료실 게시판 작성 프로젝트(C#) - 레드플러스 2004-01-05 4069
  1. 자료실 게시판 테이블 구조 자료실게시판구조.jpg(69 KB) 레드플러스 2004-01-08 3295
  입력 Write.jpg(132 KB) 레드플러스 2005-03-10 2622
  출력 List.jpg(175 KB) 레드플러스 2005-03-10 2644
  상세 View.jpg(93 KB) 레드플러스 2005-03-10 2558
  수정 Modify.jpg(109 KB) 레드플러스 2005-03-10 2540
  삭제 Delete.jpg(45 KB) 레드플러스 2005-03-10 2535
  검색 Search.jpg(152 KB) 레드플러스 2005-03-10 2479
  공통 스타일 시트 : Upload.css - 레드플러스 2005-09-05 2607
  파일업로드 연습 : UploadTest.aspx UploadTest.aspx(1 KB) 레드플러스 2005-09-05 2711
  파일업로드 연습 : UploadTest.aspx.cs UploadTest.aspx.cs(2 KB) 레드플러스 2005-09-05 2881
  파일업로드 연습(파일명 중복 처리) : UploadTest.aspx.cs - 레드플러스 2005-09-06 3631
  2. 입력 페이지 설계 - 레드플러스 2004-06-20 2549
  Write.aspx Write(1).aspx(6 KB) 레드플러스 2005-03-10 2728
  Write.aspx.cs Write.aspx(1).cs(6 KB) 레드플러스 2005-03-10 2547
  3. 출력 페이지 설계 - 레드플러스 2004-06-20 2555
  List.aspx List(3).aspx(3 KB) 레드플러스 2005-03-10 2874
  List.aspx.cs List.aspx(1).cs(2 KB) 레드플러스 2005-03-10 2539
  4. 세부 출력 페이지 설계 - 레드플러스 2004-06-20 2503
  View.aspx View(1).aspx(4 KB) 레드플러스 2005-03-10 6051
  View.aspx.cs View.aspx(1).cs(4 KB) 레드플러스 2005-03-10 2413
  5. 수정 페이지 설계 - 레드플러스 2004-06-20 2529
  Modify.aspx Modify(1).aspx(5 KB) 레드플러스 2005-03-10 2476
현재글 Modify.aspx.cs Modify.aspx(1).cs(5 KB) 레드플러스 2005-03-10 2429
  6. 삭제 페이지 설계 - 레드플러스 2004-06-20 2370
  Delete.aspx Delete(1).aspx(1 KB) 레드플러스 2005-03-10 2409
  Delete.aspx.cs Delete.aspx(1).cs(3 KB) 레드플러스 2005-03-10 2426
  7. 검색 페이지 설계 - 레드플러스 2005-03-10 2364
  Search.aspx Search(1).aspx(2 KB) 레드플러스 2005-03-10 2458
  Search.aspx.cs Search.aspx(1).cs(2 KB) 레드플러스 2005-03-10 2340
  8. 강제 다운로드 페이지 구현 - 레드플러스 2005-03-10 2162
  Down.aspx.cs Down.aspx.cs(2 KB) 레드플러스 2005-03-10 2141
  자료실 게시판 프로젝트 소스 Upload.zip(60 KB) 레드플러스 2005-09-06 2067
다음글 4. 기본형 게시판 작성 프로젝트(C#) - 레드플러스 2004-01-04 3133
 
손님 사용자 Anonymous (손님)
로그인 Home