더북(TheBook)

3. BoardEditorFormControl.ascx.cs 파일을 열고 다음과 같이 코드를 작성한다.

▼  ~/DotNetNote/Controls/BoardEditorFormControl.ascx.cs

using DotNetNote.Models;
using Dul;
using System;
using System.IO;

namespace MemoEngine.DotNetNote.Controls
{
  public partial class BoardEditorFormControl : System.Web.UI.UserControl
  {
      /// <summary>
      /// 공통 속성
      /// </summary>
      public BoardWriteFormType FormType { get; set; }
      
      private string _Id;// 앞(리스트)에서 넘어온 번호 저장
      
      private string _BaseDir = String.Empty;// 파일 업로드 폴더
      private string _FileName = String.Empty;// 파일명 저장 필드
      private int _FileSize = 0;// 파일 크기 저장 필드
      
      protected void Page_Load(object sender, EventArgs e)
      {
          _Id = Request.QueryString[“Id”];
          
          if (!Page.IsPostBack) // 처음 로드할 때만 바인딩
          {
              switch (FormType)
              {
                  case BoardWriteFormType.Write:
                      lblTitleDescription.Text =
                          “글 쓰기 - 다음 필드들을 채워주세요.”;
                      break;
                  case BoardWriteFormType.Modify:
                      lblTitleDescription.Text =
                          “글 수정 - 아래 항목을 수정하세요.”;
                      DisplayDataForModify();
                      break;
                  case BoardWriteFormType.Reply:
                      lblTitleDescription.Text =
                          “글 답변 - 다음 필드들을 채워주세요.”;
                      DisplayDataForReply();
                      break;
              }
          }
      }
      
      private void DisplayDataForModify()
      {
          // 넘어온 Id 값에 해당하는 레코드를 하나 읽어서 Note 클래스에 바인딩
          var note = (new NoteRepository()).GetNoteById(Convert.ToInt32(_Id));
          
          txtName.Text = note.Name;
          txtEmail.Text = note.Email;
          txtHomepage.Text = note.Homepage;
          txtTitle.Text = note.Title;
          txtContent.Text = note.Content;
          
          // 인코딩 방식에 따른 데이터 출력
          string strEncoding = note.Encoding;
          if (strEncoding == “Text”) // Text : 소스 그대로 표현
          {
              rdoEncoding.SelectedIndex = 0;
          }
          else if (strEncoding == “Mixed”) // Mixed : 엔터 처리만
          {
              rdoEncoding.SelectedIndex = 2;
          }
          else // HTML : HTML 형식으로 출력
          {
              rdoEncoding.SelectedIndex = 1;
          }
          
          // 첨부된 파일명 및 파일 크기 기록
          if (note.FileName.Length > 1)
          {
              ViewState[“FileName”] = note.FileName;
              ViewState[“FileSize”] = note.FileSize;
              
              pnlFile.Height = 50;
              lblFileNamePrevious.Visible = true;
              lblFileNamePrevious.Text =
                  $“기존에 업로드된 파일명: {note.FileName}”;
          }
          else
          {
              ViewState[“FileName”] = ””;
              ViewState[“FileSize”] = 0;
          }
      }
      
      private void DisplayDataForReply()
      {
          // 넘어온 Id 값에 해당하는 레코드를 하나 읽어서 Note 클래스에 바인딩
          var note = (new NoteRepository()).GetNoteById(Convert.ToInt32(_Id));
          
          txtTitle.Text = $“Re : {note.Title}”;
          txtContent.Text =
              $“\n\nOn {note.PostDate}, ‘{note.Name}’ wrote:\n———-\n>“
              + $”{note.Content.Replace(”<span class=“n”>n”, “<span class=“n”>n

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.