01.
private
void
btSave_Click(
object
sender, EventArgs e)
02.
{
03.
if
(Program.checkMaskedBox(mkIDCard)) [color=green]
04.
{
05.
MessageBox.Show(
"กรุณากรอกข้อมูลหมายเลขบัตรประชาชนให้ถูกต้องด้วย!"
,
"คำเตือน"
, MessageBoxButtons.OK, MessageBoxIcon.Warning);
06.
return
;
07.
}
08.
if
(Program.checkTextBox(txtFName) || Program.checkTextBox(txtLName) || Program.checkTextBox(txtUserName) || Program.checkTextBox(txtPassword) || Program.checkTextBox(txtAddress)) [color=green]
09.
{
10.
MessageBox.Show(
"กรุณากรอกข้อมูลชื่อจริง,นามสกุล,UserName,Password,ที่อยู่ ให้ถูกต้องด้วย!"
,
"คำเตือน"
, MessageBoxButtons.OK, MessageBoxIcon.Warning);
11.
return
;
12.
}
13.
Program.clickButton(
"SAVE"
, btAdd, btSave, btEdit, btDelete, btCancel);
14.
if
(Program.checkDuplicate(
"SELECT IDCard FROM TBEmployee WHERE IDCard='"
+ IDCard +
"'"
))
15.
{
16.
string
sql =
"UPDATE TBEmployee SET "
+
17.
"IDCard='"
+ mkIDCard.Text.Trim() +
"',"
+
18.
"FName='"
+ txtFName.Text.Trim() +
"',"
+
19.
"LName='"
+ txtLName.Text.Trim() +
"',"
+
20.
"Gender='"
+ cbGender.Text.Trim() +
"',"
+
21.
"Phone='"
+ mkPhone.Text.Trim() +
"',"
+
22.
"Address='"
+ txtAddress.Text.Trim() +
"',"
+
23.
"EMail='"
+ txtEmail.Text.Trim() +
"',"
+
24.
"UserName='"
+ txtUserName.Text.Trim() +
"',"
+
25.
"Password='"
+ txtPassword.Text.Trim() +
"' "
+
26.
"WHERE IDCard='"
+ IDCard +
"'"
;
27.
using
(SqlCommand cm =
new
SqlCommand(sql, Program.cn))
28.
{
29.
if
(Program.connection())
30.
{
31.
try
32.
{
33.
cm.ExecuteNonQuery();
34.
}
35.
catch
(Exception ex)
36.
{
37.
MessageBox.Show(
"เกิดข้อผิดพลาดในส่วนของการแก้ไขข้อมูล เนื่องจาก "
+ ex.Message,
"เกิดปัญหา"
, MessageBoxButtons.OK, MessageBoxIcon.Error);
38.
return
;
39.
}
40.
}
41.
}
42.
MessageBox.Show(
"การแก้ไขข้อมูลเรียบร้อยแล้ว"
,
"สำเร็จ"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
43.
}
44.
else
45.
{
46.
string
sql =
"INSERT INTO TBEmployee(IDCard,FName,LName,Gender,Phone,Address,EMail,UserName,Password) "
+
47.
"VALUES('"
+ mkIDCard.Text.Trim() +
"','"
+ txtFName.Text.Trim() +
48.
"','"
+ txtLName.Text.Trim() +
"','"
+ cbGender.Text.Trim() +
49.
"','"
+ mkPhone.Text.Trim() +
"','"
+ txtAddress.Text.Trim() +
50.
"','"
+ txtEmail.Text.Trim() +
"','"
+ txtUserName.Text.Trim() +
51.
"','"
+ txtPassword.Text.Trim() +
"')"
;
52.
using
(SqlCommand cm =
new
SqlCommand(sql, Program.cn))
53.
{
54.
if
(Program.connection())
55.
{
56.
try
57.
{
58.
cm.ExecuteNonQuery();
59.
}
60.
catch
(Exception ex)
61.
{
62.
MessageBox.Show(
"เกิดข้อผิดพลาดในส่วนของการบันทึกข้อมูล เนื่องจาก "
+ ex.Message,
"เกิดปัญหา"
, MessageBoxButtons.OK, MessageBoxIcon.Error);
63.
return
;
64.
}
65.
}
66.
}
67.
MessageBox.Show(
"การบันทึกข้อมูลเรียบร้อยแล้ว"
,
"สำเร็จ"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
68.
}
69.
if
(checkAdmin())
70.
{
71.
showGridEmployee(
"SELECT * FROM TBEmployee ORDER BY IDCard"
);
72.
}
73.
else
74.
{
75.
showGridEmployee(
"SELECT * FROM TBEmployee WHERE IDCard='"
+ Program.emp_id +
"'"
);
76.
}
77.
clear();
78.
gbEmployee.Enabled =
false
;
79.
}