Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Diagnostics;
- namespace Agenda
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- //Declaro mis variables
- Contacto[] ContactArr = new Contacto[10];
- string[] InfoContacto = new string[5];
- int i=0;
- int b = 10;
- private void BtnAgregar_Click(object sender, EventArgs e)
- {
- //Acá creé un arreglo que contenga todos los datos de los textbox
- InfoContacto[0] = TxtNombre.Text;
- InfoContacto[1] = TxtTel.Text;
- InfoContacto[2] = TxtDireccion.Text;
- InfoContacto[3] = TxtCelular.Text;
- InfoContacto[4] = TxtCorreo.Text;
- //Luego hago que esos datos "entren" en un nuevo contacto
- ContactArr[i] = new Contacto(InfoContacto[0], InfoContacto[1], InfoContacto[2], InfoContacto[3], InfoContacto[4]);
- //Acá creo un arreglo con 10 contactos más
- if (i < b)
- {
- i++;
- }
- else
- {
- b += 10;
- }
- //Creo un Text writer que me escriba lo que le digo en el doc que le especifico
- TextWriter YoEscribo = new StreamWriter(@"C:\Users\Sofía\Documents\Escuela\LAD\Primer Semestre\Programación\Agenda\Texto.txt");
- //Aquí me escribe las informaciones de mi contacto
- YoEscribo.WriteLine("Nombre: "+InfoContacto[0]);
- YoEscribo.WriteLine("Teléfono: "+InfoContacto[1]);
- YoEscribo.WriteLine("Dirección: "+InfoContacto[2]);
- YoEscribo.WriteLine("Celular: "+InfoContacto[3]);
- YoEscribo.WriteLine("E-mail: "+InfoContacto[4]);
- // Debería ser esto pero no funciona :YoEscribo.WriteLine(ContactArr[i]);
- YoEscribo.Close();
- Process.Start(@"C:\Users\Sofía\Documents\Escuela\LAD\Primer Semestre\Programación\Agenda\Texto.txt");
- }
- private void BtnBuscar_Click(object sender, EventArgs e)
- { //Creo un File Stream
- //Indico el doc text existente que quiero abrir, y le indico que lo que queiro es leer y escribir sobre ese archivo.
- FileStream LeoTexto = File.Open("Texto.txt", FileMode.Open, FileAccess.ReadWrite);
- //Creo un StreamReader: Using en este caso me sirve para evitar errores?? no capté :P
- //Esto me sirve para leer las líneas de mi documento de texto
- using (StreamReader YoLeo = new StreamReader("Texto.txt"))
- {
- }
- LeoTexto.Close();
- }
- private void Cerrar_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Se guardaron tus contactos");
- Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement