private void btnDeleteTask_Click(object sender, EventArgs e) { Task task; dvgTasks.Rows[dvgTasks.CurrentCell.RowIndex].Selected = true; try { task = (Task)dvgTasks.SelectedRows[0].DataBoundItem; } catch (Exception) { MessageBox.Show("Please select Task"); return; } DialogResult dialogResult = MessageBox.Show("Do you want to delete that task", "Delete task", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { bool pass = broker.removeTask(task); if (pass) { MessageBox.Show("Task deleted successfully"); } else { MessageBox.Show("System can't delete task"); } refresh(); } else if (dialogResult == DialogResult.No) { return; } }
public bool removeTask(Task task) { try { DBBroker broker = new DBBroker(); return broker.removeTask(task); } catch (Exception) { throw; } }