01.
int
strNumRows;
02.
string
strSQL;
03.
SqlConnection conn =
new
SqlConnection();
04.
{
05.
conn.ConnectionString = ConfigurationManager
06.
.ConnectionStrings[
"SPersonnelConnectionString"
].ConnectionString;
07.
{
08.
SqlCommand cmd =
new
SqlCommand();
09.
{
10.
cmd.Connection = conn;
11.
conn.Open();
12.
strSQL =
"SELECT COUNT(*) FROM Personnel WHERE ID_Pers = '"
+
this
.txtID_Pers.Text +
"' "
;
13.
14.
cmd =
new
SqlCommand(strSQL, conn);
15.
16.
strNumRows = Convert.ToInt32(cmd.ExecuteScalar());
17.
18.
if
(txtID_Pers.Text ==
""
)
19.
{
20.
this
.lbIDPers.Text =
"กรุณากรอกรหัสพนักงาน"
;
21.
lbIDPers.ForeColor = Color.Red;
22.
return
;
23.
}
24.
25.
if
(Session[
"ID_Pers"
] ==
this
.txtID_Pers.Text)
26.
{
27.
28.
29.
30.
if
(db.ID_Card2 ==
""
)
31.
{
32.
Response.Redirect(
"Default2.aspx"
);
33.
}
34.
else
if
(db.ID_Card3 ==
""
)
35.
{
36.
Response.Redirect(
"Default3.aspx"
);
37.
}
38.
else
if
(db.ID_Card5 ==
""
)
39.
{
40.
Response.Redirect(
"Default5.aspx"
);
41.
}
42.
else
if
(db.ID_Card4 ==
""
)
43.
{
44.
Response.Redirect(
"Default4.aspx"
);
45.
}
46.
else
47.
{
48.
Response.Redirect(
"Default6.aspx"
);
49.
}
50.
}
51.
52.
53.
54.
else
if
(strNumRows > 0)
55.
{
56.
this
.lbIDPers.Text =
"รหัสพนักงานนี้ได้ทำการบันทึกข้อมูลไปแล้ว กรุณาตรวจสอบ"
;
57.
lbIDPers.ForeColor = Color.Red;
58.
txtName.Enabled =
false
;
59.
txtID_Card.Enabled =
false
;
60.
txtdatStart.Enabled =
false
;
61.
txtID_Pers.Focus();
62.
}
63.
else
64.
{
65.
this
.lbIDPers.Text =
"รหัสพนักงานนี้ยังไม่ได้ทำการบันทึกข้อมุล"
;
66.
lbIDPers.ForeColor = Color.Green;
67.
txtName.Enabled =
true
;
68.
txtID_Card.Enabled =
true
;
69.
txtdatStart.Enabled =
true
;
70.
71.
txtName.BackColor =
default
(Color);
72.
txtID_Card.BackColor =
default
(Color);
73.
txtdatStart.BackColor =
default
(Color);
74.
txtName.Focus();
75.
}
76.
cmd.ExecuteNonQuery();
77.
conn.Close();
78.
79.
80.
}
81.
}
82.
}
83.
}