private void btnDelete_Click(object sender, EventArgs e) { //delete the package if (rdbPackage.Checked) { int row = this.dgvMainPage.CurrentCell.RowIndex; int col = 0; DialogResult result = MessageBox.Show("Do you want to delete " + dgvMainPage.SelectedRows[0].Cells[1].Value.ToString() + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { int pkgid = (int)dgvMainPage.Rows[row].Cells[col].Value; if (PackageDB.DeletePackage(pkgid)) { MessageBox.Show("Package was deleted"); SearchFor(); } else { MessageBox.Show("Failed deleting Package"); } } } }
private void btnDeletePkgClick_Click(object sender, EventArgs e) { // Return if no pacakge to delete if (comboBoxPkgName.SelectedIndex == -1) { return; } // Get the current package to delete. // If the nth index is selected in the combo box, the current package // is the nth entry in the "packages" list Package delPkg = packages[comboBoxPkgName.SelectedIndex]; // Confirm with the user before proceeding DialogResult dr = MessageBox.Show("Delete the selected package from the database?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { // Delete the package from the database (note: cascading deletes have been // implemented in the Travel Experts database) try { bool result = PackageDB.DeletePackage(delPkg); if (result) { MessageBox.Show("The package was successfully deleted", "Information"); LoadUIforPackages(); comboBoxPkgName.SelectedIndex = 0; } else { MessageBox.Show("Error deleting package from database", "Error"); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } }