/// <summary> /// Add the user to the database /// </summary> /// <param name="sender">The object that raised the event</param> /// <param name="e">The event arguments</param> /// <returns>true if Add was successful, else false</returns> /// <history> /// <Created 18 April 2014>Arun Gopinath && Jeff Bunce</Created> /// <Modified 20 April 2014>Arun Gopinath && Jeff Bunce /// <notes>Changed void return to bool, to indicate succeess or failure</notes> /// </Modified> /// </history> private bool AddUser(object sender, EventArgs e) { bool addSuccess = true; string fName = txtNewStudentFirstName.Text.Trim(); string lName = txtNewStudentLastName.Text.Trim(); string screenName = txtNewStudentScreenName.Text.Trim(); string password = txtNewStudentPassword.Text.Trim(); string passwordVerify = txtNewStudentVerifyPassword.Text.Trim(); string grade = txtNewStudentGrade.Text.Trim(); DateTime?DOB = dtpAddStudentDOB.Value; //Validate the input if (IsNewUserInputValid() == false) { MessageBox.Show("Invaild data detected. Please correct the errors and try again.", "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); addSuccess = false; } else { Student newStudent = new Student(mmControl, Guid.NewGuid().ToString(), fName, lName, screenName, password, DOB, grade); mmControl.AddNewStudent(newStudent); MessageBox.Show("Student Added.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(addSuccess); }
/// <summary> /// Adds the new User to the System /// </summary> /// <param name="sender">The object that raised the event</param> /// <param name="e">The event arguments</param> /// <history> /// <Created 17 April 2014>Arun Gopinath && Jeff Bunce</Created> /// <Modified 18 April 2014></Modified> /// </history> private void ButtonAddUserClicked(object sender, EventArgs e) { string fName = txtNewStudentFirstName.Text.Trim(); string lName = txtNewStudentLastName.Text.Trim(); string screenName = txtNewStudentScreenName.Text.Trim(); string password = txtNewStudentPassword.Text.Trim(); string passwordVerify = txtNewStudentVerifyPassword.Text.Trim(); string grade = txtNewStudentGrade.Text.Trim(); DateTime?DOB = dtpAddStudentDOB.Value; bool[] isValid = new bool[7]; isValid[0] = true; isValid[1] = validName(txtNewStudentFirstName); isValid[2] = validName(txtNewStudentLastName); isValid[3] = validScreenName(txtNewStudentScreenName); isValid[4] = validPassword(txtNewStudentPassword, txtNewStudentVerifyPassword); isValid[5] = validGrade(txtNewStudentGrade); isValid[6] = validDate(dtpAddStudentDOB); foreach (bool b in isValid) { if (!b) { isValid[0] = false; } } if (!isValid[0]) { MessageBox.Show("Invaild data detected. Please correct the errors and try again.", "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { Student newStudent = new Student(MMControl, Guid.NewGuid().ToString(), fName, lName, screenName, password, DOB, grade); MMControl.AddNewStudent(newStudent); } // this.Close (); }