Guest User

Untitled

a guest
Mar 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. 34543;PRIMEIRA PESSOA;230778;CASADO;BANCARIO
  2. 23543;SEGUNDA PESSOA;12051985;CASADO;ADMINISTRADOR DE EMPRESAS
  3. 36116;TERCEIRA PESSOA;04081954;DIVORCIADO;APOSENTADO/PENSIONISTA
  4. 52455;QUARTA PESSOA;16111987;CASADO;ARTESAO
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11.  
  12. namespace MeuPrimeiroLeitorDeArquivo
  13. {
  14. public class Cidadao
  15. {
  16. public int numeroRegistro { get; set; }
  17. public string nomeCompleto { get; set; }
  18. public string dataNascimento { get; set; }
  19. public string estadoCivil { get; set; }
  20. public string profissao { get; set; }
  21.  
  22. public Cidadao (int nrRegistro, string nmCompleto, string dtNasc, string estCivil, string prfs)
  23. {
  24. this.numeroRegistro = nrRegistro;
  25. this.nomeCompleto = nmCompleto;
  26. this.dataNascimento = dtNasc;
  27. this.estadoCivil = estCivil;
  28. this.profissao = prfs;
  29. }
  30. }
  31. }
  32.  
  33. using System;
  34. using System.Collections.Generic;
  35. using System.ComponentModel;
  36. using System.Data;
  37. using System.Drawing;
  38. using System.Linq;
  39. using System.Text;
  40. using System.Threading.Tasks;
  41. using System.Windows.Forms;
  42. using System.IO;
  43.  
  44. namespace MeuPrimeiroLeitorDeArquivo
  45. {
  46. public partial class FormPrincipal : Form
  47. {
  48. private List<Cidadao> cidadaos = new List<Cidadao>();
  49.  
  50. public FormPrincipal()
  51. {
  52. InitializeComponent();
  53. }
  54.  
  55. private void FormPrincipal_Load(object sender, EventArgs e)
  56. {
  57. List<Cidadao> cidadaos = new List<Cidadao>();
  58.  
  59. string arqTxt = @"C:eclipseteste1.txt";
  60.  
  61. if (File.Exists(arqTxt))
  62. {
  63. try
  64. {
  65. using (StreamReader sr = new StreamReader(arqTxt))
  66. {
  67. String linha;
  68. while((linha = sr.ReadLine()) != null)
  69. {
  70. int formNumeroRegistro;
  71. string formNomeCompleto;
  72. string formDataNascimento;
  73. string formEstadoCivil;
  74. string formProfissao;
  75.  
  76. string[] linhaExplodida = linha.Split(';');
  77.  
  78. formNumeroRegistro = Convert.ToInt32(linhaExplodida[0]);
  79. formNomeCompleto = linhaExplodida[1];
  80. formDataNascimento = linhaExplodida[2];
  81. formEstadoCivil = linhaExplodida[3];
  82. formProfissao = linhaExplodida[4];
  83.  
  84. Cidadao cidadao = new Cidadao(formNumeroRegistro, formNomeCompleto, formDataNascimento, formEstadoCivil, formProfissao);
  85.  
  86. cidadaos.Add(cidadao);
  87.  
  88. }
  89. }
  90.  
  91. if (cidadaos.Count > 0)
  92. {
  93. Cidadao pessoa1 = this.cidadaos[0];
  94. textNumeroRegistro = pessoa1.profissao;
  95. }
  96.  
  97. } catch (Exception ex)
  98. {
  99. MessageBox.Show(ex.Message);
  100. }
  101. } else
  102. {
  103. MessageBox.Show("Arquivo " + arqTxt + " não localizado");
  104. }
  105. }
  106. }
  107. }
Add Comment
Please, Sign In to add comment