Exemple #1
0
 public CadastroWindow()
 {
     String[] vetor  = File.ReadAllLines("..\\..\\..\\Dados\\eleicoes.txt");
     String[] vetor2 = File.ReadAllLines("..\\..\\..\\Dados\\candidatos.txt");
     String[] vetor3 = File.ReadAllLines("..\\..\\..\\Dados\\eleitores.txt");
     for (int i = 0; i < vetor.Length; i++)
     {
         Eleicao aux = new Eleicao(vetor[i]);
         listaEleicao.Add(aux);
     }
     for (int i = 0; i < vetor2.Length; i++)
     {
         Candidato aux = new Candidato(vetor2[i], true);
         listaCandidato.Add(aux);
     }
     for (int i = 0; i < vetor3.Length; i++)
     {
         Eleitor aux3 = new Eleitor(vetor3[i]);
         listaEleitor.Add(aux3);
     }
     InitializeComponent();
 }
Exemple #2
0
 private void salvar3_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         // Instancia um Eleitor e trata seus dados para o arquivo.
         Eleicao ele = new Eleicao(countEleicao, textboxCargo.Text, textboxLocal.Text, int.Parse(textboxAno.Text));
         String  s   = ele.TratarDados();
         // Cria um vetor de linhas que já existem no arquivo
         String[] vetor = File.ReadAllLines("..\\..\\..\\Dados\\eleicoes.txt");
         // Sobrescreve as linhas no arquivo
         StreamWriter f = new StreamWriter("..\\..\\..\\Dados\\eleicoes.txt", false, Encoding.Default);
         for (int i = 0; i < vetor.Length; i++)
         {
             f.WriteLine(vetor[i]);
         }
         // Escreve a nova linha
         f.WriteLine(s.Remove(s.Length - 1));
         f.Close();
         listaEleicao.Add(ele);
         MessageBox.Show("Salvo!");
     }
     catch (FormatException) { MessageBox.Show("Clique em Novo e preenchas os campos."); }
 }