1
using System;
2
using System.Data;
3
using System.Web.UI;
4
using Microsoft.Practices.EnterpriseLibrary.Data; //
5
6
public partial class Basic_ModifyControl : System.Web.UI.UserControl
7
...{
8
protected void Page_Load(object sender, EventArgs e)
9
...{
10
// 넘겨져 온 쿼리스트링 값 검사
11
if (String.IsNullOrEmpty(Request["Num"]))
12
...{
13
Response.Write("잘못된 요청입니다.");
14
Response.End();
15
}
16
else
17
...{
18
if (!Page.IsPostBack) // 반드시 처음 로드시에만 읽어온다.
19
...{
20
DisplayData(); // 출력 전담 메서드
21
}
22
}
23
}
24
private void DisplayData()
25
...{
26
using (IDataReader dr =
27
DatabaseFactory.CreateDatabase("ConnectionString").
28
ExecuteReader("ViewBasic", Request["Num"]))
29
...{
30
while (dr.Read())
31
...{
32
// 각각의 컨트롤에 예전 자료 출력
33
lblNum.Text = Request["Num"];
34
txtName.Text = dr["Name"].ToString();
35
txtEmail.Text = dr[2].ToString(); // 서수
36
txtHomepage.Text = dr["Homepage"].ToString();
37
txtTitle.Text = dr.GetString(3); // GetXXX()
38
txtContent.Text = dr["Content"].ToString();
39
// 예전에 선택했던 인코딩 지정 : 0, 1, 2 중 하나 인덱스
40
if (dr["Encoding"].ToString() == "HTML") ...{
41
lstEncoding.SelectedIndex = 1;
42
}
43
else if (dr["Encoding"].ToString() == "Mixed") ...{
44
lstEncoding.SelectedIndex = 2;
45
}
46
else ...{
47
lstEncoding.SelectedIndex = 0; // Text
48
}
49
}
50
}
51
}
52
protected void btnModify_Click(object sender, EventArgs e)
53
...{
54
// 데이터 수정
55
int result = DatabaseFactory.CreateDatabase(
56
"ConnectionString").ExecuteNonQuery(
57
"ModifyBasic",
58
txtName.Text, txtEmail.Text,
59
txtTitle.Text, Request.UserHostAddress,
60
txtContent.Text, lstEncoding.SelectedValue,
61
txtHomepage.Text, txtPassword.Text,
62
Request["Num"]
63
);
64
if (result == -1)
65
...{
66
lblError.Text = "잘못된 암호입니다.";
67
}
68
else
69
...{
70
btnList_Click(null, null); // 수정 후 리스트로 이동
71
}
72
}
73
protected void btnList_Click(object sender, EventArgs e)
74
...{
75
Response.Redirect("List.aspx"); // 리스트 페이지로 이동
76
}
77
}
78