Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Diagnostics;
  11.  
  12.  
  13. namespace Agenda
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         //Declaro mis variables
  23.  
  24.        Contacto[] ContactArr = new Contacto[10];
  25.        string[] InfoContacto = new string[5];
  26.  
  27.        int i=0;
  28.        int b = 10;
  29.        
  30.  
  31.  
  32.        
  33.         private void BtnAgregar_Click(object sender, EventArgs e)
  34.         {
  35.  
  36.             //Acá creé un arreglo que contenga todos los datos de los textbox
  37.             InfoContacto[0] = TxtNombre.Text;
  38.             InfoContacto[1] = TxtTel.Text;
  39.             InfoContacto[2] = TxtDireccion.Text;
  40.             InfoContacto[3] = TxtCelular.Text;
  41.             InfoContacto[4] = TxtCorreo.Text;
  42.  
  43.             //Luego hago que esos datos "entren" en un nuevo contacto
  44.  
  45.             ContactArr[i] = new Contacto(InfoContacto[0], InfoContacto[1], InfoContacto[2], InfoContacto[3], InfoContacto[4]);
  46.  
  47.             //Acá creo un arreglo con 10 contactos más
  48.             if (i < b)
  49.             {
  50.                 i++;
  51.             }
  52.             else
  53.             {
  54.                 b += 10;
  55.            
  56.             }
  57.  
  58.             //Creo un Text writer que me escriba lo que le digo en el doc que le especifico
  59.             TextWriter YoEscribo = new StreamWriter(@"C:\Users\Sofía\Documents\Escuela\LAD\Primer Semestre\Programación\Agenda\Texto.txt");
  60.  
  61.             //Aquí me escribe las informaciones de mi contacto
  62.            
  63.             YoEscribo.WriteLine("Nombre: "+InfoContacto[0]);
  64.             YoEscribo.WriteLine("Teléfono: "+InfoContacto[1]);
  65.             YoEscribo.WriteLine("Dirección: "+InfoContacto[2]);
  66.             YoEscribo.WriteLine("Celular: "+InfoContacto[3]);
  67.             YoEscribo.WriteLine("E-mail: "+InfoContacto[4]);
  68.  
  69.             // Debería ser esto pero no funciona :YoEscribo.WriteLine(ContactArr[i]);
  70.  
  71.  
  72.             YoEscribo.Close();
  73.  
  74.  
  75.             Process.Start(@"C:\Users\Sofía\Documents\Escuela\LAD\Primer Semestre\Programación\Agenda\Texto.txt");
  76.            
  77.         }
  78.  
  79.         private void BtnBuscar_Click(object sender, EventArgs e)
  80.         { //Creo un File Stream
  81.             //Indico el doc text existente que quiero abrir, y le indico que lo que queiro es leer y escribir sobre ese archivo.
  82.  
  83.             FileStream LeoTexto = File.Open("Texto.txt", FileMode.Open, FileAccess.ReadWrite);
  84.  
  85.             //Creo un StreamReader: Using en este caso me sirve para evitar errores?? no capté :P
  86.             //Esto me sirve para leer las líneas de mi documento de texto
  87.  
  88.             using (StreamReader YoLeo = new StreamReader("Texto.txt"))
  89.             {
  90.  
  91.  
  92.  
  93.             }
  94.            
  95.            
  96.             LeoTexto.Close();
  97.  
  98.         }
  99.  
  100.  
  101.         private void Cerrar_Click(object sender, EventArgs e)
  102.         {
  103.  
  104.  
  105.  
  106.  
  107.             MessageBox.Show("Se guardaron tus contactos");
  108.             Close();
  109.  
  110.            
  111.         }
  112.      
  113.  
  114.        
  115.  
  116.      
  117.  
  118.        
  119.  
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement