private void btnDelete_Click(object sender, EventArgs e) { StartDate = dtStartDate.Value; EndDate = dtEndDate.Value; var currentDate = DateTime.Now; int result = DateTime.Compare(currentDate, StartDate); int result2 = DateTime.Compare(currentDate, EndDate); if (result >= 1 && result2 <= 1) { MessageBox.Show(@"Election can't be deleted. Election on process", @"eVoting System", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { var deleted = AddNewElection.DeleteElection(txtElectionId.Text); MessageBox.Show(deleted > 0 ? @"Deleted successfully" : @"Error deleting successfully", @"eVoting System"); btnView_Click(null, null); } }