private void buttonOk_Click(object sender, EventArgs e) { string errorMsg = ""; if (textBoxPassword.Text != textBoxPasswordConfirm.Text) errorMsg = "Senhas não conferem"; if (!String.IsNullOrEmpty(errorMsg)) { ShowError(errorMsg); return; } try { Student student = new Student(this.textBoxNome.Text, this.textBoxSobrenome.Text, this.dateTimePickerNascimento.Value, new Email(this.textBoxEmailStudent.Text), new Email(this.textBoxEmailParent.Text), Int32.Parse(this.textBoxPassword.Text)); ISession session = NHibernateHelper.OpenSession(); StudentDAO studentDAO = new StudentDAO(session); studentDAO.Add(student); bSaved = true; session.Close(); MessageBox.Show("Cadastro efetuado com sucesso!\n\nMatrícula: " + student.Id, "Cadastro"); this.Close(); } catch (Exception ex) //at least one field with error { ShowError(ex.Message); } }