01.
private
void
tsDelete_Click(
object
sender, EventArgs e)
02.
{
03.
if
(txteqmnum.Text.Trim() ==
""
)
04.
{
05.
MessageBox.Show(
"กรุณาป้อนรหัสผู้จำหน่ายก่อน !!!"
,
"ผลการตรวจสอบ"
, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
06.
txteqmnum.Focus();
07.
return
;
08.
}
09.
10.
if
(MessageBox.Show(
"คุณต้องการลบข้อมูลผู้จำหน่าย ใช่หรือไม่?"
,
"คำยืนยัน"
, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
11.
{
12.
tr = Conn.BeginTransaction();
13.
try
14.
{
15.
sb.Remove(0, sb.Length);
16.
sb.Append(
"DELETE FROM Equipment"
);
17.
sb.Append(
" WHERE (eqmnum=@eqmnum)"
);
18.
string
sqlDelete;
19.
sqlDelete = sb.ToString();
20.
21.
com.CommandText = sqlDelete;
22.
com.CommandType = CommandType.Text;
23.
com.Connection = Conn;
24.
com.Transaction = tr;
25.
com.Parameters.Clear();
26.
com.Parameters.Add(
"@eqmnum"
, SqlDbType.VarChar).Value = txteqmnum.Text.Trim();
27.
28.
int
result;
29.
result = com.ExecuteNonQuery();
30.
if
(result == 0)
31.
{
32.
tr.Rollback();
33.
MessageBox.Show(
"ชื่อรหัสผู้จำหน่ายที่คุณป้อน ไม่ถูกต้อง !!!"
,
"ผลการทำงาน"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
34.
txteqmnum.SelectAll();
35.
}
36.
else
37.
{
38.
tr.Commit();
39.
MessageBox.Show(
"ลบรายการผู้จำหน่ายเรียบร้อยแล้ว !!!"
,
"ผลการทำงาน"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
40.
41.
ClearEqm();
42.
ShowdgvEqmList();
43.
}
44.
}
45.
catch
(Exception ex)
46.
{
47.
tr.Rollback();
48.
MessageBox.Show(
"เกิดข้อผิดพลาด เนื่องจาก "
+ ex.Message,
"ผลการทำงาน"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
49.
}
50.
}
51.
ClearEqm();
52.
txteqmnum.Focus();
53.
}