private void button1_Click(object sender, EventArgs e) { CInventario tempal = new CInventario(); //GUARDAR EN ARCHIVO DE TEXTO tempal.Producto = textBox1.Text; tempal.Precio = textBox2.Text; tempal.Cantidad = textBox3.Text; inve.Add(tempal); string fileName = "Productos.txt"; FileStream stream = new FileStream(fileName, FileMode.Append, FileAccess.Write); StreamWriter writer = new StreamWriter(stream); for (int i = 0; i < inve.Count; i++) { writer.WriteLine(inve[i].Producto); writer.WriteLine(inve[i].Precio); writer.WriteLine(inve[i].Cantidad); } //Cerrar el archivo writer.Close(); MessageBox.Show("Datos Guardados Correctamente"); textBox1.Text = (""); textBox2.Text = (""); textBox3.Text = (""); }
private void button6_Click(object sender, EventArgs e) { string fileName = @"C: \Users\Darwin Rodrigo\Desktop\programacion u\progra 3\PROYECTO PROGRA\PROYECTO PROGRA\bin\Debug\Productos.txt"; FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream); //Se cargan los datos del archivo a la lista de clientes while (reader.Peek() > -1) { //Leer los datos y guardarlos en un temporal CInventario tempal = new CInventario(); //GUARDAR EN ARCHIVO DE TEXTO tempal.Producto = reader.ReadLine(); tempal.Precio = reader.ReadLine(); tempal.Cantidad = reader.ReadLine(); //Agregar a la lista el temporal inve.Add(tempal); } reader.Close(); //Se recorre la lista de clientes for (int i = 0; i < inve.Count; i++) { //Si se el dato a buscar es igual al dato de la lista mostrarlo en los textbox if (inve[i].Producto == textBox1.Text) { textBox1.Text = inve[i].Producto; textBox2.Text = inve[i].Precio; textBox3.Text = inve[i].Cantidad; //Guardar en que posicion se encontrĂ³ el dato para utilizarla mas adelante al momento de modificar posicionmodificar = i; } } }