コード例 #1
0
 private void pbDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (dgvService.Rows.Count > 0)
         {
             this.gbInfor.Text = "Deleting.....";
             // Thực hiện lệnh
             // Lấy thứ tự record hiện hành
             int r = dgvService.CurrentCell.RowIndex;
             // Lấy MaKH của record hiện hành
             string strService = dgvService.Rows[r].Cells[0].Value.ToString();
             // Viết câu lệnh SQL
             // Hiện thông báo xác nhận việc xóa mẫu tin
             // Khai báo biến traloi
             DialogResult traloi;
             // Hiện hộp thoại hỏi đáp
             traloi = MessageBox.Show("Are you sure?", "Delete row", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             // Kiểm tra có nhắp chọn nút Ok không?
             if (traloi == DialogResult.Yes)
             {
                 dbService.DeleteService(ref err, strService);
                 if (err == "")
                 {
                     // Thông báo
                     MessageBox.Show("Deleted successfuly!");
                     // Cập nhật lại DataGridView
                     LoadData();
                 }
                 else
                 {
                     this.gbInfor.Text = "Information";
                     // Thông báo
                     MessageBox.Show("Service is in use", "Deleted failed!");
                 }
             }
             else
             {
                 this.gbInfor.Text = "Information";
                 // Thông báo
                 MessageBox.Show("Deleted failed!");
             }
         }
     }
     catch (SqlException)
     {
         this.gbInfor.Text = "Information";
         MessageBox.Show("Deleted failed!");
     }
 }