private void btnAdd_Click(object sender, EventArgs e) { try { var foundCourse = courseCRUD.FindCourse(txtTitle.Text); if (!foundCourse) { var departmnet = cbDepartment.SelectedItem as Department; var course = new Course(); course.Title = txtTitle.Text; course.CreditHours = int.Parse(txtCreditHours.Text); course.DepartmentId = departmnet.DepartmentId; var result = courseCRUD.AddCourse(course); if (result) { MessageBox.Show("Successfully added '" + txtTitle.Text + "' as new Course.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearTextBoxes(); } } else { MessageBox.Show("Course already exists!", "Note", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }