My idea is to create a system to insert new employees through the CadastrarFuncionario()
method, putting the properties of the class ( ID, nome, CPF
) inside a file named officials.txt.
With the logic used by me, the values are inserted successfully into the file. However, if I want to register a new employee after registering one, the data is overwritten and not added after jumping a line.
Here's my code:
public static void CadastrarFuncionario()
{
using (var fileStream = new FileStream(String.Format(@"C:\Files\funcionarios.txt"), FileMode.OpenOrCreate))
using (var streamWriter = new StreamWriter(fileStream))
{
Funcionario f = new Funcionario();
Console.WriteLine("ID: ");
f.id = int.Parse(Console.ReadLine());
Console.WriteLine("Nome: ");
f.nome = Console.ReadLine();
Console.WriteLine("CPF: ");
f.cpf = int.Parse(Console.ReadLine());
streamWriter.WriteLine("ID: " + f.id);
streamWriter.WriteLine("Nome: " + f.nome);
streamWriter.WriteLine("CPF: " + f.cpf);
streamWriter.WriteLine("");
}
}