/// <summary>
        /// Inserts new lecturer and subject after validating all data is correct
        /// </summary>
        private void btnAddLecturerAndSub_Click(object sender, EventArgs e)
        {
            var item =
                SubjectList.FirstOrDefault(
                    o => o.SubjectName.Equals(tbNewSubName.Text, StringComparison.OrdinalIgnoreCase));

            if (!CheckLecturerBlanks() || string.IsNullOrWhiteSpace(tbNewSubName.Text))
            {
                MessageBox.Show("Please Ensure All Lecturer Fields And A New Subject Name Are Filled In.");
            }
            else if (item != null)
            {
                MessageBox.Show("This Subject Name Already Exists, Please Change It And Try Again.");
            }
            else
            {
                Lecturer l = new Lecturer();
                {
                    l.LecturerID  = tbNewLecturerId.Text;
                    l.FirstName   = tbNEwLecturerFname.Text;
                    l.LastName    = tbNewLecturerLname.Text;
                    l.Email       = tbNewLecturerEmail.Text;
                    l.Phone       = tbNewLecturerPhoneNo.Text;
                    l.Address     = tbNewLecturerAddress.Text;
                    l.DateEntered = DateTime.Now;
                }

                Subject sub = new Subject();
                {
                    sub.SubjectName = tbNewSubName.Text;
                    sub.SubjectID   = tbNewSubID.Text;
                    sub.LecturerID  = tbNewLecturerId.Text;
                }

                if (!_db.InsertLecturer(l))
                {
                    MessageBox.Show("Neither Lecturer or Subject Added Because The Following Error Occurred: " + "\n" +
                                    _db.ErrorMessage);
                    ResetLecturer();
                    ResetSubject();
                }
                else
                {
                    int count = _db.InsertNewSubject(sub);

                    if (count == -1) //An error has occurred
                    {
                        MessageBox.Show("Lecturer Added." + "\n" + "\n" + "New Subject Not Added Because The Following Error Occurred: " +
                                        _db.ErrorMessage); //warn of error
                        ResetLecturer();
                        ResetSubject();
                    }
                    else
                    {
                        MessageBox.Show("New Lecturer and Subject Added.");
                        ResetLecturer();
                        ResetSubject();
                    }
                }
            }
        }
Exemplo n.º 2
0
 partial void UpdateLecturer(Lecturer instance);
Exemplo n.º 3
0
 partial void DeleteLecturer(Lecturer instance);
Exemplo n.º 4
0
 partial void InsertLecturer(Lecturer instance);