블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Category

Recent Post

Recent Comment

Archive

2009. 11. 2. 14:24 .Net Project/ASP.NET 3.5 Sp1
반응형
 Modify.aspx

 


<!-- BoardModify.aspx -->

<%@ Page Language="C#" AutoEventWireup="true"
  CodeFile="BoardModify.aspx.cs"
  Inherits="DotNetNote_BoardModify" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>글 수정</title>
  <link href="../DotNetNote/DotNetNote.css"
    rel="stylesheet" type="text/css" />
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <h3>
        완성형 게시판</h3>
      <font style="font-size: 9pt; color: #ff0000">
        글&nbsp;수정 - 아래 항목을 수정하세요.</font>
      <hr width="100%" size="1" />
      <table id="Table1" style="border-collapse: collapse"
        bordercolor="black" cellspacing="0"
        rules="none" width="600" align="center"
        bgcolor="white">
        <tr>
          <td align="right" width="100" bgcolor="#efefef">
            번&nbsp; 호
          </td>
          <td width="500">
            <asp:Label ID="lblNum" runat="server"></asp:Label>
          </td>
        </tr>
        <tr>
          <td align="right" width="100" bgcolor="#efefef">
            *이&nbsp; 름
          </td>
          <td width="500">
            <asp:TextBox ID="txtName" runat="server"
              BorderWidth="1px" BorderStyle="Solid"
              MaxLength="10" Width="250px"></asp:TextBox>
            <asp:RequiredFieldValidator ID="valName"
              runat="server" ControlToValidate="txtName"
              Display="None" ErrorMessage="이름을 작성하세요."
              SetFocusOnError="True"></asp:RequiredFieldValidator><font
                face="굴림">&nbsp;</font></td>
        </tr>
        <tr>
          <td align="right" bgcolor="#efefef">
            E-mail
          </td>
          <td>
            <asp:TextBox ID="txtEmail" runat="server"
              BorderWidth="1px" BorderStyle="Solid"
              MaxLength="80" Width="300px"></asp:TextBox>
              <asp:RegularExpressionValidator
                ID="valEmail" runat="server"
                ValidationExpression=
                "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                Display="None" ControlToValidate="txtEmail"
                ErrorMessage="* 메일형식이 올바르지 않습니다">
                </asp:RegularExpressionValidator></td>
        </tr>
        <tr>
          <td align="right" bgcolor="#efefef">
            Homepage
          </td>
          <td>
            <asp:TextBox ID="txtHomepage" runat="server"
              BorderWidth="1px" BorderStyle="Solid"
              MaxLength="80" Width="300px"></asp:TextBox>
              <asp:RegularExpressionValidator
                ID="valHomepage" runat="server"
                ValidationExpression=
                "http://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;=]*)?"
                Display="None" ControlToValidate="txtHomepage"
                ErrorMessage="* 홈페이지 형식이 올바르지 않습니다">
                </asp:RegularExpressionValidator></td>
        </tr>
        <tr>
          <td align="right" bgcolor="#efefef">
            *제&nbsp; 목
          </td>
          <td>
            <asp:TextBox ID="txtTitle" runat="server"
              BorderWidth="1px" BorderStyle="Solid"
              MaxLength="30" Width="480px"></asp:TextBox><font
                face="굴림">&nbsp;</font>
            <asp:RequiredFieldValidator ID="valTitle"
              runat="server" Display="None"
              ControlToValidate="txtTitle"
              ErrorMessage="* 제목을 기입해 주세요">
              </asp:RequiredFieldValidator></td>
        </tr>
        <tr>
          <td align="right" bgcolor="#efefef">
            *내&nbsp; 용
          </td>
          <td>
            <asp:TextBox ID="txtContent" runat="server"
              BorderWidth="1px" BorderStyle="Solid"
              Width="480px" TextMode="MultiLine"
              Rows="10"></asp:TextBox><br />
            <asp:RequiredFieldValidator ID="valContent"
              runat="server" Display="None"
              ControlToValidate="txtContent"
              ErrorMessage="* 내용을 기입해 주세요"
              SetFocusOnError="True">
              </asp:RequiredFieldValidator>
          </td>
        </tr>
        <tr>
          <td align="right" bgcolor="#efefef">
            *인코딩
          </td>
          <td>
            <font face="굴림">
              <asp:RadioButtonList ID="rdoEncoding"
                runat="server" RepeatDirection="Horizontal">
                <asp:ListItem Value="Text" Selected="True">Text</asp:ListItem>
                <asp:ListItem Value="HTML">HTML</asp:ListItem>
                <asp:ListItem Value="Mixed">Mixed</asp:ListItem>
              </asp:RadioButtonList></font></td>
        </tr>
        <tr>
          <td align="right" bgcolor="#efefef">
            *비밀번호
          </td>
          <td>
            <asp:TextBox ID="txtPassword" runat="server"
              BorderWidth="1px" BorderStyle="Solid"
              MaxLength="20" Width="250px"
              TextMode="Password" EnableViewState="False">
              </asp:TextBox>&nbsp;
            <asp:RequiredFieldValidator ID="valPassword"
              runat="server" Display="None"
              ControlToValidate="txtPassword"
              ErrorMessage="* 비밀번호를 기입해 주세요"
              SetFocusOnError="True"></asp:RequiredFieldValidator>
              </td>
        </tr>
      </table>
      <p align="center">
        <asp:Button ID="btnModify" runat="server"
          BorderWidth="1px" BorderStyle="Solid"
          Width="80px" BorderColor="Gray"
          Text="변경내용저장" OnClick="btnModify_Click">
        </asp:Button><font face="굴림">&nbsp;
        </font>
        <asp:Button ID="btnList" runat="server"
          BorderWidth="1px" BorderStyle="Groove"
          Width="80px" BorderColor="Gray"
          Text="리스트" CausesValidation="False"
          OnClick="btnList_Click"></asp:Button></p>
      <p align="center">
        <asp:Label ID="lblError" runat="server"
          EnableViewState="False" ForeColor="Red"></asp:Label></p>
      <p align="center">
        <asp:ValidationSummary ID="ValidationSummary1"
          runat="server" ShowMessageBox="True"
          ShowSummary="False" DisplayMode="List">
        </asp:ValidationSummary>
      </p>
    </div>
  </form>
</body>
</html>


 Modify.aspx.Cs

 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("&", "&amp;").Replace(
      "<", "&lt;").Replace(">", "&gt;");
    string strTitle = txtTitle.Text.Replace("&", "&amp;").Replace(
      "<", "&lt;").Replace(">", "&gt;");

    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
}




반응형
posted by Magic_kit