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_ModifyControl : System.Web.UI.UserControl
 7
public partial class Basic_ModifyControl : 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 // 각각의 컨트롤에 예전 자료 출력
33
                // 각각의 컨트롤에 예전 자료 출력
33 lblNum.Text = Request["Num"];
34
                lblNum.Text = Request["Num"];
34 txtName.Text = dr["Name"].ToString();
35
                txtName.Text = dr["Name"].ToString();
35 txtEmail.Text = dr[2].ToString(); // 서수
36
                txtEmail.Text = dr[2].ToString(); // 서수
36 txtHomepage.Text = dr["Homepage"].ToString();
37
                txtHomepage.Text = dr["Homepage"].ToString();
37 txtTitle.Text = dr.GetString(3); // GetXXX() 
38
                txtTitle.Text = dr.GetString(3); // GetXXX() 
38 txtContent.Text = dr["Content"].ToString();
39
                txtContent.Text = dr["Content"].ToString();
39 // 예전에 선택했던 인코딩 지정 : 0, 1, 2 중 하나 인덱스
40
                // 예전에 선택했던 인코딩 지정 : 0, 1, 2 중 하나 인덱스
40
 if (dr["Encoding"].ToString() == "HTML") ...{
41
                if (dr["Encoding"].ToString() == "HTML") ...{
41 lstEncoding.SelectedIndex = 1;    
42
                    lstEncoding.SelectedIndex = 1;    
42 }
43
                }
43
 else if (dr["Encoding"].ToString() == "Mixed") ...{
44
                else if (dr["Encoding"].ToString() == "Mixed") ...{
44 lstEncoding.SelectedIndex = 2;    
45
                    lstEncoding.SelectedIndex = 2;    
45 }
46
                }
46
 else ...{
47
                else ...{
47 lstEncoding.SelectedIndex = 0; // Text
48
                    lstEncoding.SelectedIndex = 0; // Text
48 }
49
                }
49 }
50
            }
50 }
51
        }
51 }
52
    }
52 protected void btnModify_Click(object sender, EventArgs e)
53
    protected void btnModify_Click(object sender, EventArgs e)
53
 ...{
54
    ...{
54 // 데이터 수정 
55
        // 데이터 수정 
55 int result = DatabaseFactory.CreateDatabase(
56
        int result = DatabaseFactory.CreateDatabase(
56 "ConnectionString").ExecuteNonQuery(
57
            "ConnectionString").ExecuteNonQuery(
57 "ModifyBasic",
58
            "ModifyBasic",
58 txtName.Text, txtEmail.Text,
59
            txtName.Text, txtEmail.Text,
59 txtTitle.Text, Request.UserHostAddress,
60
            txtTitle.Text, Request.UserHostAddress,
60 txtContent.Text, lstEncoding.SelectedValue, 
61
            txtContent.Text, lstEncoding.SelectedValue, 
61 txtHomepage.Text, txtPassword.Text, 
62
            txtHomepage.Text, txtPassword.Text, 
62 Request["Num"]
63
            Request["Num"]
63 );
64
        );
64 if (result == -1)
65
        if (result == -1)
65
 ...{
66
        ...{
66 lblError.Text = "잘못된 암호입니다.";        
67
            lblError.Text = "잘못된 암호입니다.";        
67 }
68
        }
68 else
69
        else
69
 ...{
70
        ...{
70 btnList_Click(null, null); // 수정 후 리스트로 이동
71
            btnList_Click(null, null); // 수정 후 리스트로 이동
71 }
72
        }
72 }
73
    }
73 protected void btnList_Click(object sender, EventArgs e)
74
    protected void btnList_Click(object sender, EventArgs e)
74
 ...{
75
    ...{
75 Response.Redirect("List.aspx"); // 리스트 페이지로 이동
76
        Response.Redirect("List.aspx"); // 리스트 페이지로 이동
76 }
77
    }
77 }
78
}
78