private void btnGravar_Click(object sender, EventArgs e) { RegistroAluno registro = new RegistroAluno(); int matricula = int.Parse(this.txtMat.Text); string nome = this.txtNome.Text; string curso = this.txtCursoGrava.Text; registro.setMatricula(matricula); registro.setNome(nome); registro.setCurso(curso); if (this.arquivo_texto.adicionarRegistros(registro)) { this.limparRegistro(); this.btnPesquisar.Enabled = true; } }
public Boolean adicionarRegistros(RegistroAluno registro) { try { int matricula = registro.getMatricula(); string nome = registro.getNome(); string curso = registro.getCurso(); this.output = new StreamWriter(File.Open(this.file_path, FileMode.Append)); this.output.Write("Matricula: " + matricula + "; Nome: " + nome + "; Curso: " + curso + "\n\n"); this.output.Close(); } catch (SystemException e) { MessageBox.Show("Entrada inválida. Por favor tente novamente!!! Detalhes do erro: " + e.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(true); }