private void newStudentToolStripMenuItem_Click(object sender, EventArgs e) { this.Hide(); AddStudent addStudent = new AddStudent(); addStudent.Show(); }
private void btnAddStudent_Click(object sender, EventArgs e) { XmlSerializer serialiser; XmlWriter xmlWriter; string filePath = string.Empty; string fname = txtFirstName.Text; string lname = txtSurname.Text; string email = txtEmail.Text; string phone = txtPhone.Text; string address1 = txtAdrline1.Text; string address2 = txtAdrline2.Text; string city = txtCity.Text; string county = comboBoxCounties.SelectedItem.ToString(); string course = comboCourses.SelectedItem.ToString(); string mobileRegularExpression = ConfigurationManager.AppSettings["MobRegEx"]; try { int studentNumber = int.Parse(txStudentNumber.Text); string level = ""; if (radioUnder.Checked) { level = "Undergraduate"; } else if (radioPost.Checked) { level = "Postgraduate"; } AddNewStudent addNewStudent = new AddNewStudent(fname, lname, email, phone, address1, address2, city, county, level, course, studentNumber); addNewStudent.AddStudentToDB(); saveFileDialog.InitialDirectory = "C:\\"; saveFileDialog.Filter = "xml files (*.xml)|*.xml"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { filePath = saveFileDialog.FileName; serialiser = new XmlSerializer(typeof(AddNewStudent)); xmlWriter = XmlWriter.Create(filePath); serialiser.Serialize(xmlWriter, addNewStudent); } else { MessageBox.Show("Student details not serialised!"); } MessageBox.Show("Student successfully added to database!"); this.Hide(); Menu menu1 = new Menu(); menu1.Show(); } catch (Exception) { MessageBox.Show("A student number must have 8 digits. Please enter a valid student number."); this.Hide(); AddStudent addStudent = new AddStudent(); addStudent.Show(); } }