示例#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();
 }
示例#2
0
 private void salvar1_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         // Instancia um Eleitor e trata seus dados para o arquivo.
         Eleitor eleitor = new Eleitor(count, textboxNome1.Text, int.Parse(textboxNumero1.Text), int.Parse(textboxCPF1.Text), (textboxZona.Text));
         String  s       = eleitor.TratarDados();
         // Cria um vetor de linhas que já existem no arquivo
         String[] vetor = File.ReadAllLines("..\\..\\..\\Dados\\eleitores.txt");
         // Sobrescreve as linhas no arquivo
         StreamWriter f = new StreamWriter("..\\..\\..\\Dados\\eleitores.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();
         listaEleitor.Add(eleitor);
         MessageBox.Show("Salvo!");
     }
     catch (FormatException) { MessageBox.Show("Clique em Novo e preenchas os campos."); }
 }