void leer_placa() { OpenFileDialog op = new OpenFileDialog(); string filename = "Carro.txt"; FileStream st = new FileStream(filename, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(st); while (reader.Peek() > -1) { Carros a = new Carros(); a.Placa = reader.ReadLine(); a.Marca = reader.ReadLine(); a.Modelo = reader.ReadLine(); a.Color = reader.ReadLine(); a.Precio_Km = Convert.ToDouble(reader.ReadLine()); carro.Add(a); } reader.Close(); comboBox2.DisplayMember = "Placa"; comboBox2.ValueMember = "Placa"; comboBox2.DataSource = null; comboBox2.DataSource = carro; comboBox2.Refresh(); }
void agregar() { Carros a = new Carros(); a.Placa = textBox1.Text; a.Marca = textBox2.Text; a.Modelo = textBox3.Text; a.Color = textBox4.Text; a.Precio_Km = Convert.ToDouble(textBox5.Text); }
private void button1_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text) && !string.IsNullOrEmpty(textBox3.Text) && !string.IsNullOrEmpty(textBox4.Text) && !string.IsNullOrEmpty(textBox5.Text)) { agregar(); repetidos(); Carros f = new Carros(); Total t = new Total(); if (a) { MessageBox.Show("La placa del vehiculo ya esta registrada, por favor vuelva a intentarlo"); textBox1.Clear(); } else { f.Placa = textBox1.Text; f.Marca = textBox2.Text; f.Modelo = textBox3.Text; f.Color = textBox4.Text; f.Precio_Km = Convert.ToInt32(textBox5.Text); carro.Add(f); MessageBox.Show("El vehiculo se ha registrado correctamente"); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox5.Clear(); escribir_vehiculo(); dataGridView1.DataSource = null; dataGridView1.DataSource = carro; dataGridView1.Refresh(); } } else { MessageBox.Show("¡ERROR!, Debe llenar todos los campos"); } a = false; c = 0; }
void leer_vehiculo() { OpenFileDialog op = new OpenFileDialog(); string filename = "Carro.txt"; FileStream st = new FileStream(filename, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(st); while (reader.Peek() > -1) { Carros a = new Carros(); a.Placa = reader.ReadLine(); a.Marca = reader.ReadLine(); a.Modelo = reader.ReadLine(); a.Color = reader.ReadLine(); a.Precio_Km = Convert.ToDouble(reader.ReadLine()); carro.Add(a); dataGridView1.DataSource = null; dataGridView1.DataSource = carro; dataGridView1.Refresh(); } reader.Close(); }