01.
private
void
insertOrUpdate()
02.
{
03.
if
(txtName.Text ==
""
)
04.
{
05.
MessageBox.Show(
"กรุณากรอกข้อมูลให้ครบ"
,
"Warning"
);
06.
return
;
07.
}
08.
string
sql =
""
;
09.
if
(txtID.Text ==
""
)
10.
sql =
"INSERT INTO Receipet(CustName,Tel,Dates,Time,Field,Hours) VALUES(@name,@tel,@date,@time,@field,@hours)"
;
11.
else
12.
sql =
"UPDATE Receipet SET CustName = @name,Tel = @tel,Dates = @date,Time = @time,Field = @field,Hours = @hours "
+
"WHERE CustID = "
13.
+ txtID.Text;
14.
_cmd =
new
OleDbCommand(sql, _conn);
15.
_cmd.Parameters.AddWithValue(
"name"
, txtName.Text);
16.
_cmd.Parameters.AddWithValue(
"tel"
, txtTel.Text);
17.
_cmd.Parameters.AddWithValue(
"date"
, txtDate.Text);
18.
_cmd.Parameters.AddWithValue(
"time"
, txtTime.Text);
19.
_cmd.Parameters.AddWithValue(
"field"
, txtField.Text);
20.
_cmd.Parameters.AddWithValue(
"hours"
, txtHours.Text);
21.
int
affectedRow = _cmd.ExecuteNonQuery();
22.
if
(affectedRow < 1)
23.
MessageBox.Show(
"เกิดข้อผิดพลาดในการบันทึกข้อมูล"
,
"Warning"
);
24.
else
25.
{
26.
MessageBox.Show(
"ข้อมูลถูกจัดเก็บแล้ว"
,
"Result"
);
27.
28.
string
name = txtName.Text;
29.
30.
readData();
31.
fillListBox();
32.
clearBindings();
33.
34.
int
idx = lstRec.FindStringExact(name);
35.
if
(idx > -1)
36.
lstRec.SetSelected(idx,
true
);
37.
}
38.
}