private void ctrl_btn_ok_Click(object sender, EventArgs e) { if (IsValidData()) //need to add validation { if (isAdd) //user clicks *ADD* button| true is just a placeholder { Exam newExam = new Exam(); newExam.Administrator = Exam.Administrator; this.PutExamData(newExam); try { Exam.ExamID = ExamDB.AddExam(newExam); //AddExam from ExamDb this.DialogResult = DialogResult.OK; MessageBox.Show("Add Successful!"); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else //user clicks *UPDATE* button { Exam newExam = new Exam(); newExam.ExamID = Exam.ExamID; this.PutExamData(newExam); try { //Return error if update failed if (!ExamDB.UpdateExam(Exam, newExam)) { MessageBox.Show("Another user has updated or " + "deleted that exam.", "Database Error"); this.DialogResult = DialogResult.Retry; } else //Set the new exam as the form's exam and show success message { Exam = newExam; this.DialogResult = DialogResult.OK; MessageBox.Show("Update Successful!"); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } this.Close(); } } }//end ok button click