// add button event handler private void addButton_Click(object sender, EventArgs e) { string badFieldName = null; // variable for bad field name string adviceString = null; // variable for advice string if (!haveValidFirstName) { badFieldName = "First Name"; adviceString = "Enter First Name"; } else if (!haveValidLastName) { badFieldName = "Last Name"; adviceString = "Enter Last Name"; } else if (!haveValidAcademicDepartment) { badFieldName = "Department"; adviceString = "Enter Department"; } else if (!haveValidEmailAddress) { badFieldName = "Email Address"; adviceString = "Enter Email Address"; } else if (!haveValidSnailMailAddress) { badFieldName = "Mail Address"; adviceString = "Enter Mailing Address"; } else if (!haveValidGraduationYear) { badFieldName = "Graduation Year"; adviceString = "Enter Graduation Year"; } if (badFieldName != null) { MessageBox.Show($"Invalid {badFieldName}.\n{adviceString}", "Data Entry Error"); return; } // assign student contact object StudentContact = new StudentContact(emailAddressTextBox.Text.Trim(), snailMailAddressTextBox.Text.Trim()); DialogResult = DialogResult.OK; }
// constructor using from file string to create a new student public Student(string fromFile) : base(fromFile) { char[] delimiters = { '|', ',' }; string[] tokens = fromFile.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); contact = new StudentContact(tokens[4], tokens[5]); graduationYear = int.Parse(tokens[6]); if (tokens.Length > 6) { for (int i = 7; i < tokens.Length; i++) { CourseList.Add(tokens[i]); } } }
//private List<string> courseList; // constructors public Student(string fname, string lname, string department, StudentContact contact, string type, int year, List <string> courses) : base(fname, lname, department, type) { this.contact = (!StudentContact.isNull(contact)) ? contact : throw new ArgumentException("Null value is unaccepted"); graduationYear = (isValidGraduationYear(year)) ? year : throw new ArgumentException("Graduation year is invalided"); if (courses == null) { courses = new List <string> { " " }; } else { CourseList = courses; } }
// function to check is an object is null public static bool isNull(StudentContact contact) { return((contact == null) ? true : false); }