1 using System;
 2
using System;
 2 using System.Data;
 3
using System.Data;
 3 using System.Web.UI;
 4
using System.Web.UI;
 4 using Microsoft.Practices.EnterpriseLibrary.Data;
 5
using Microsoft.Practices.EnterpriseLibrary.Data;
 5 6
 6 public partial class Basic_ViewControl : System.Web.UI.UserControl
 7
public partial class Basic_ViewControl : System.Web.UI.UserControl
 7
 ...{
 8
...{
 8 protected void Page_Load(object sender, EventArgs e)
 9
    protected void Page_Load(object sender, EventArgs e)
 9
 ...{
10
    ...{
10 // 넘겨져 온 쿼리스트링 값 검사
11
        // 넘겨져 온 쿼리스트링 값 검사
11 if (String.IsNullOrEmpty(Request["Num"]))
12
        if (String.IsNullOrEmpty(Request["Num"]))
12
 ...{
13
        ...{
13 Response.Write("잘못된 요청입니다.");
14
            Response.Write("잘못된 요청입니다.");
14 Response.End();
15
            Response.End();
15 }
16
        }
16 else
17
        else
17
 ...{
18
        ...{
18 if (!Page.IsPostBack)
19
            if (!Page.IsPostBack)
19
 ...{
20
            ...{
20 DisplayData(); // 출력 전담 메서드    
21
                DisplayData(); // 출력 전담 메서드    
21 }
22
            }
22 }
23
        }
23 }
24
    }
24 private void DisplayData()
25
    private void DisplayData()
25
 ...{
26
    ...{
26 using (IDataReader dr = 
27
        using (IDataReader dr = 
27 DatabaseFactory.CreateDatabase("ConnectionString")
28
            DatabaseFactory.CreateDatabase("ConnectionString")
28 .ExecuteReader("ViewBasic", Request["Num"]))
29
            .ExecuteReader("ViewBasic", Request["Num"]))
29
 ...{
30
        ...{
30 while (dr.Read())
31
            while (dr.Read())
31
 ...{
32
            ...{
32
 각각의 컨트롤에 바인딩#region 각각의 컨트롤에 바인딩
33
                각각의 컨트롤에 바인딩#region 각각의 컨트롤에 바인딩
33 lblNum.Text = dr["Num"].ToString();
34
                lblNum.Text = dr["Num"].ToString();
34 lblTitle.Text = dr["Title"].ToString();
35
                lblTitle.Text = dr["Title"].ToString();
35 lblName.Text = dr["Name"].ToString();
36
                lblName.Text = dr["Name"].ToString();
36 lblEmail.Text = dr["Email"].ToString();
37
                lblEmail.Text = dr["Email"].ToString();
37 lblHomepage.Text = dr["Homepage"].ToString();
38
                lblHomepage.Text = dr["Homepage"].ToString();
38 lblPostDate.Text = dr["PostDate"].ToString();
39
                lblPostDate.Text = dr["PostDate"].ToString();
39 lblReadCount.Text = dr["ReadCount"].ToString();
40
                lblReadCount.Text = dr["ReadCount"].ToString();
40 lblPostIP.Text = dr["PostIP"].ToString(); 
41
                lblPostIP.Text = dr["PostIP"].ToString(); 
41 #endregion
42
                #endregion
42
 인코딩 방식에 따른 컨텐츠 출력#region 인코딩 방식에 따른 컨텐츠 출력
43
                인코딩 방식에 따른 컨텐츠 출력#region 인코딩 방식에 따른 컨텐츠 출력
43 string strEncoding = dr["Encoding"].ToString();
44
                string strEncoding = dr["Encoding"].ToString();
44 if (strEncoding == "Text") // 태그 실행 방지/소스 그대로
45
                if (strEncoding == "Text") // 태그 실행 방지/소스 그대로
45
 ...{
46
                ...{
46 lblContent.Text =
47
                    lblContent.Text =
47 dr["Content"].ToString().Replace(
48
                        dr["Content"].ToString().Replace(
48 "&", "&").Replace(
49
                            "&", "&").Replace(
49 "<", "<").Replace(
50
                                "<", "<").Replace(
50 ">", ">").Replace(
51
                                    ">", ">").Replace(
51 "\r\n", "<br />").Replace(
52
                                        "\r\n", "<br />").Replace(
52 "\t",
53
                                            "\t",
53 "    ");
54
                                        "    ");
54 }
55
                }
55 else if (strEncoding == "Mixed") // 태그 실행
56
                else if (strEncoding == "Mixed") // 태그 실행
56
 ...{
57
                ...{
57 lblContent.Text = dr["Content"].ToString().
58
                    lblContent.Text = dr["Content"].ToString().
58 Replace("\r\n", "<br />");
59
                        Replace("\r\n", "<br />");
59 }
60
                }
60 else // HTML로 표시
61
                else // HTML로 표시
61
 ...{
62
                ...{
62 lblContent.Text = dr["Content"].ToString();
63
                    lblContent.Text = dr["Content"].ToString();
63 } 
64
                } 
64 #endregion
65
                #endregion
65 }                
66
            }                
66 }
67
        }
67 }
68
    }
68 protected void btnList_Click(object sender, EventArgs e)
69
    protected void btnList_Click(object sender, EventArgs e)
69
 ...{
70
    ...{
70 Response.Redirect("./List.aspx");
71
        Response.Redirect("./List.aspx");
71 }
72
    }
72 protected void btnModify_Click(object sender, EventArgs e)
73
    protected void btnModify_Click(object sender, EventArgs e)
73
 ...{
74
    ...{
74 Response.Redirect("./Modify.aspx?Num=" + Request["Num"]);
75
        Response.Redirect("./Modify.aspx?Num=" + Request["Num"]);
75 }
76
    }
76 protected void btnDelete_Click(object sender, EventArgs e)
77
    protected void btnDelete_Click(object sender, EventArgs e)
77
 ...{
78
    ...{
78 Response.Redirect("./Delete.aspx?Num=" + Request["Num"]);
79
        Response.Redirect("./Delete.aspx?Num=" + Request["Num"]);
79 }
80
    }
80 }
81
}
81