private void agregar() { C_vehiculo Temp = new C_vehiculo(); bool existe = ingreso.Exists(v => v.Placa == txt_placa.Text); if (!(existe)) { Temp.Placa = txt_placa.Text; Temp.Marca = txt_marca.Text; Temp.Modelo = txt_modelo.Text; Temp.Color = txt_color.Text; Temp.Precio = Convert.ToInt32(txt_precio.Text); ingreso.Add(Temp); FileStream stream = new FileStream(@"..\..\IngresoVehiculo.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter writer = new StreamWriter(stream); foreach (var p in ingreso) { writer.WriteLine(p.Placa); writer.WriteLine(p.Marca); writer.WriteLine(p.Modelo); writer.WriteLine(p.Color); writer.WriteLine(p.Precio); } writer.Close(); } else { MessageBox.Show("Esta placa ya existe"); } }
private void Alquiler_Load(object sender, EventArgs e) { if (File.Exists(@"..\..\IngresoVehiculo.txt")) { FileStream stream = new FileStream(@"..\..\IngresoVehiculo.txt", FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream); while (reader.Peek() > -1) { C_vehiculo Temp = new C_vehiculo(); Temp.Placa = reader.ReadLine(); Temp.Marca = reader.ReadLine(); Temp.Modelo = reader.ReadLine(); Temp.Color = reader.ReadLine(); Temp.Precio = Convert.ToInt32(reader.ReadLine()); vehiculos.Add(Temp); } reader.Close(); } if (File.Exists(@"..\..\clientes.txt")) { FileStream stream = new FileStream(@"..\..\clientes.txt", FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream); while (reader.Peek() > -1) { C_cliente Temp = new C_cliente(); Temp.Nit = reader.ReadLine(); Temp.Placa = reader.ReadLine(); Temp.FechaAlquiler = Convert.ToDateTime(reader.ReadLine()); Temp.FechaDevolucion = Convert.ToDateTime(reader.ReadLine()); Temp.Kilometros = Convert.ToInt32(reader.ReadLine()); clientes.Add(Temp); } reader.Close(); dataGridView1.DataSource = null; dataGridView1.DataSource = clientes; dataGridView1.Refresh(); } comboBox_placa.ValueMember = "Placa"; comboBox_placa.DataSource = null; comboBox_placa.DataSource = vehiculos; }
private void cargar() { if (File.Exists(@"..\..\IngresoVehiculo.txt")) { FileStream stream = new FileStream(@"..\..\IngresoVehiculo.txt", FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream); while (reader.Peek() > -1) { C_vehiculo Temp = new C_vehiculo(); Temp.Placa = reader.ReadLine(); Temp.Marca = reader.ReadLine(); Temp.Modelo = reader.ReadLine(); Temp.Color = reader.ReadLine(); Temp.Precio = Convert.ToInt32(reader.ReadLine()); ingreso.Add(Temp); } reader.Close(); dataGridView1.DataSource = null; dataGridView1.DataSource = ingreso; dataGridView1.Refresh(); } }