private void btnGuardar_Click(object sender, EventArgs e) { DateTime fechaSalida = dpFechaSalida.Value; DateTime fechaLlegadaEstimada = dpFechaLlegadaEstimada.Value; if (fechaSalida < fechaSistema || fechaLlegadaEstimada < fechaSistema) { MessageBox.Show("Las fechas de salida y de llegada estimada deben ser posteriores a la fecha de sistema."); }else{ Model.ViajeModel viaje = new Model.ViajeModel(rutaEncontrada.idRuta,aeronaveSeleccionada.matricula,fechaSalida, fechaLlegadaEstimada ,aeronaveSeleccionada.cantButacasPas,aeronaveSeleccionada.cantButacasVen,aeronaveSeleccionada.capacidadKg); int idViaje = viajeController.guardarViaje(viaje, rutaEncontrada, aeronaveSeleccionada); List<Model.ButacaModel> butacas = butacaController.buscarButacas(aeronaveSeleccionada.matricula); butacaController.guardarButacasViaje(idViaje, butacas); this.Close(); new AerolineasFRBA().Show(); } }
private void dgvVuelos_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { vueloElegido = (Model.ViajeModel)dgvVuelos.CurrentRow.DataBoundItem; compraModel.vueloElegido = vueloElegido; btnSeleccionar.Enabled = true; }
public List<Model.ViajeModel> buscarViajes(int idRuta, DateTime fechaViaje, int cantidadPax, int kg) { List<Model.ViajeModel> viajes = new List<Model.ViajeModel>(); Model.ViajeModel viaje = null; SqlConnection myConnection = null; try { myConnection = new SqlConnection(stringConexion); myConnection.Open(); SqlCommand command = null; var query = "select viajesDisp.viaje_id, "+ "viajesDisp.fecha_salida, "+ "viajesDisp.fecha_llegada_estimada, "+ "viajesDisp.origen, " + "viajesDisp.destino, "+ "viajesDisp.tipo_servicio, "+ "viajesDisp.aeronave_matricula, "+ "viajesDisp.cantPasillo, " + "viajesDisp.cantVentanilla, " + "viajesDisp.cantidad_kg_disponibles "+ "from (select v.viaje_id,v.fecha_salida, v.fecha_llegada, v.fecha_llegada_estimada, c1.nombre as origen, c2.nombre as destino, "+ "(select count(*) as cantidad_butacas_pasillo_disponibles "+ "from mondongo.viajes v1 "+ "inner join mondongo.butacas_viaje bv on v.viaje_id = bv.viaje_id "+ "inner join mondongo.butacas b on bv.butaca_id = b.butaca_id "+ "where b.butaca_tipo = 'PASILLO' "+ "and v1.viaje_id = v.viaje_id "+ "and bv.estado = 'L') as cantPasillo, "+ "(select count(*) as cantidad_butacas_ventanilla_disponibles "+ "from mondongo.viajes v2 "+ "inner join mondongo.butacas_viaje bv on v.viaje_id = bv.viaje_id "+ "inner join mondongo.butacas b on bv.butaca_id = b.butaca_id "+ "where b.butaca_tipo = 'VENTANILLA' "+ "and v2.viaje_id = v.viaje_id "+ "and bv.estado = 'L') as cantVentanilla, "+ "ts.tipo_servicio,v.aeronave_matricula, "+ "v.cantidad_kg_disponibles "+ "from mondongo.viajes v "+ "inner join mondongo.rutas r on r.id_ruta = v.viaje_ruta_id "+ "inner join mondongo.ciudades c1 on c1.id_ciudad = r.id_ciudad_origen "+ "inner join mondongo.ciudades c2 on c2.id_ciudad = r.id_ciudad_destino "+ "inner join MONDONGO.ruta_tipo_servicio rts on r.id_ruta=rts.id_ruta "+ "inner join mondongo.tipos_servicio ts on ts.id_tipo_servicio = rts.id_tipo_servicio "+ "where r.id_ruta = @idRuta "+ "and v.estado = 0 " + "and cantidad_kg_disponibles > @kg "+ "and Convert(date, fecha_salida) = @fechaViaje "+ "and Convert(date, fecha_salida) > @fechaSistema "+ ") as viajesDisp "+ "where viajesDisp.cantPasillo + viajesDisp.cantVentanilla > @cantidadPax "+ "order by viajesDisp.fecha_salida asc"; using (command = new SqlCommand(query, myConnection)) { command.Parameters.AddWithValue("@idRuta", idRuta); command.Parameters.AddWithValue("@fechaViaje", fechaViaje.Date); command.Parameters.AddWithValue("@cantidadPax", cantidadPax); command.Parameters.AddWithValue("@kg", kg); command.Parameters.AddWithValue("@fechaSistema", fechaSistema); } using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var idViaje = (int)(double)reader.GetDecimal(0); var fechaSalida = reader.GetDateTime(1); var fechaLlegadaEstimada = reader.GetDateTime(2); var ciudadOrigen = reader.GetString(3); var ciudadDestino = reader.GetString(4); var tipoServicio = reader.GetString(5); var aeronaveMatricula = reader.GetString(6); var cantidadButacasPasillo = reader.GetInt32(7); var cantidadButacasVentanilla = reader.GetInt32(8); var cantidadKgDisponibles = (int)(double)reader.GetDecimal(9); viaje = new Model.ViajeModel(idViaje, fechaSalida, fechaLlegadaEstimada, ciudadOrigen, ciudadDestino, tipoServicio, aeronaveMatricula, cantidadButacasPasillo, cantidadButacasVentanilla, cantidadKgDisponibles); viajes.Add(viaje); } } } catch (Exception ex) { MessageBox.Show("ERROR" + ex.Message); } finally { myConnection.Close(); } return viajes; }