private void OkButton__Click(object sender, EventArgs e) { Student student = null; Teacher teacher = null; Person person = null; Globals.people.Remove(this.formPerson.email); if (this.typeComboBox.SelectedIndex == 0) { student = new Student(); person = student; } else { teacher = new Teacher(); person = teacher; } person.name = this.nameText.Text; person.email = this.emailText.Text; person.age = Convert.ToInt32(this.ageText.Text); person.LicenseId = Convert.ToInt32(this.licText.Text); person.homePageURL = this.homepageTextBox.Text; person.dateOfBirth = this.birthDateTimePicker.Value; person.photoPath = this.photoPictureBox.ImageLocation; if (this.herRadioButton.Checked) { person.eGender = genderPronoun.her; } if (this.himRadioButton.Checked) { person.eGender = genderPronoun.him; } if (this.themRadioButton.Checked) { person.eGender = genderPronoun.them; } // if( person is Student ) if (person.GetType() == typeof(Student)) { student.gpa = Convert.ToDouble(this.gpaText.Text); if (this.froshRadioButton.Checked) { student.eCollegeYear = collegeYear.freshman; } if (this.sophRadioButton.Checked) { student.eCollegeYear = collegeYear.sophomore; } if (this.juniorRadioButton.Checked) { student.eCollegeYear = collegeYear.junior; } if (this.seniorRadioButton.Checked) { student.eCollegeYear = collegeYear.senior; } } else { teacher.specialty = specText.Text; } Globals.people[person.email] = person; if (this.Owner != null) { this.Owner.Enabled = true; this.Owner.Focus(); try { IListView iListView = (IListView)this.Owner; iListView.PaintListView(person.email); } catch { } } formPerson = person; this.Hide(); //this.Close(); //this.Dispose(); }
private void OkButton__Click(object sender, EventArgs e) { Student student = null; Teacher teacher = null; Person person = null; Globals.people.Remove(this.formPerson.email); ICourseList iCourseList = (ICourseList)formPerson; if (this.typeComboBox.SelectedIndex == 0) { student = new Student(); student.courseCodes = iCourseList.CourseList; person = student; } else { teacher = new Teacher(); teacher.courseCodes = iCourseList.CourseList; person = teacher; } person.name = this.nameText.Text; person.email = this.emailText.Text; person.age = Convert.ToInt32(this.ageText.Text); person.LicenseId = Convert.ToInt32(this.licText.Text); person.homePageURL = this.homepageTextBox.Text; person.dateOfBirth = this.birthDateTimePicker.Value; person.photoPath = this.photoPictureBox.ImageLocation; if (this.herRadioButton.Checked) { person.eGender = genderPronoun.her; } if (this.himRadioButton.Checked) { person.eGender = genderPronoun.him; } if (this.themRadioButton.Checked) { person.eGender = genderPronoun.them; } if (person.GetType() == typeof(Student)) { student.gpa = Convert.ToDouble(this.gpaText.Text); if (this.froshRadioButton.Checked) { student.eCollegeYear = collegeYear.freshman; } if (this.sophRadioButton.Checked) { student.eCollegeYear = collegeYear.sophomore; } if (this.juniorRadioButton.Checked) { student.eCollegeYear = collegeYear.junior; } if (this.seniorRadioButton.Checked) { student.eCollegeYear = collegeYear.senior; } } else { teacher.specialty = this.specText.Text; } Globals.people[person.email] = person; if (this.Owner != null) { // enable the parent form this.Owner.Enabled = true; // and set it into focus to process mouse and keyboard events this.Owner.Focus(); try { // repaint the parent form's ListView control with the edited person at the top of the screen IListView iListView = (IListView)this.Owner; iListView.PaintListView(person.email); } catch { } } // set the public class formPerson variable to the updated person object // for access to the updated details outside of the class formPerson = person; // hide the form instead of closing it so that the form persists in memory this.Hide(); // close and dispose of this instance of the PersonEdit Form // note that these must come at the end since they clear and release the form data //this.Close(); //this.Dispose(); }