private void btnSaveTask_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(txtTask.Text)) { errorProvider.SetError(txtTask, "Please enter task"); return; } else { errorProvider.SetError(txtTask, ""); } TaskPriority priority = (TaskPriority)cmbPriority.SelectedItem; var task = new Task() { Name = txtTask.Text, Description = txtDescription.Text, Priority = (int)priority, CreatedOn = DateTime.Now }; _taskService.Add(task); MessageBox.Show("Task has been added successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); this.RefreshDgv(); this.Clear(); } catch (Exception) { MessageBox.Show("An unexpected error occured. Please try again. If the problem continues, contact support.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }