/// <summary> /// Save a travel reservation without a hotel /// </summary> /// <param name="compra_reserva"></param> private void InsertReservaSinHotel(Compra_Reserva compra_reserva) { try { conn.Open(); cmd = new NpgsqlCommand("INSERT INTO reservas_compras(cedulafk, pais_origenfk, pais_destinofk, idpais_escalafk, duracion, precio_vuelo," + " fecha_inicio, fecha_final, adultos, ninos, habitaciones, id_hotelfk, id_vehiculofk, reser_comp, precio_vehiculo, precio_hotel)" + " VALUES (" + compra_reserva.id_usuario + "," + "" + compra_reserva.pais_origen_cod + "," + "" + compra_reserva.pais_destino_cod + "," + "" + compra_reserva.pais_escala + "," + "" + compra_reserva.duracion + "," + "" + compra_reserva.precio_vuelo + "," + "'" + compra_reserva.fecha_inicio + "'," + "'" + compra_reserva.fecha_final + "'," + "" + compra_reserva.adultos + "," + "" + compra_reserva.ninos + "," + "" + compra_reserva.habitaciones + "," + "" + compra_reserva.hotel_cod + "," + "" + compra_reserva.vehiculo_cod + "," + "false," + "" + compra_reserva.precio_vehiculo + "," + "" + compra_reserva.precio_hotel + ");", conn); cmd.ExecuteNonQuery(); conn.Close(); Bajar_Cantidades(compra_reserva); } catch (Exception ex) { conn.Close(); Console.WriteLine(ex.Message); } }
/// <summary> /// This method send the purchase or reservation to the database /// </summary> /// <param name="compra_reserva"></param> /// <returns>And it returns a boolean if it's saved</returns> public bool Agregar_Compra_Reserva(Compra_Reserva compra_reserva) { DB_Interfaz_Vuelo dB_Interfaz_Vuelo = new DB_Interfaz_Vuelo(); int total = 0; try { int vuelo = int.Parse(compra_reserva.precio_vuelo); total = total + vuelo; } catch (Exception ex) { } try { int hotel = int.Parse(compra_reserva.precio_hotel); total = total + hotel; } catch (Exception ex) { } try { int vehiculo = int.Parse(compra_reserva.precio_vehiculo); total = total + vehiculo; } catch (Exception ex) { } MessageBox.Show("El total es de: " + total); return(dB_Interfaz_Vuelo.Agregar_Compra_Reserva(compra_reserva)); }
/// <summary> /// Save a travel reservation with a hotel /// </summary> /// <param name="compra_reserva"></param> /// <returns></returns> public bool Agregar_Compra_Reserva(Compra_Reserva compra_reserva) { bool compra_reserv = false; try { if (compra_reserva.hotel_cod == "null") { if (compra_reserva.reserva_compra) { InsertCompraSinHotel(compra_reserva); } else { InsertReservaSinHotel(compra_reserva); } } else { if (compra_reserva.reserva_compra) { InsertCompraHotel(compra_reserva); } else { InsertReservaHotel(compra_reserva); } } compra_reserv = true; } catch (Exception ex) { Console.WriteLine(ex.Message); compra_reserv = false; } return(compra_reserv); }
/// <summary> /// Check if is a purchase or reservation and send to the database /// </summary> /// <param name="compra_reserva"></param> /// <returns>A boolean for know if it is a purchase or reservation</returns> private bool Comprar_Reservar(bool compra_reserva) { bool comprado_reservado = false; string datestart = dateTimePicker1.Value.ToString("yyyy-MM-dd"); DateTime fecha_ini = DateTime.Parse(datestart); string datefinal = dateTimePicker2.Value.ToString("yyyy-MM-dd"); DateTime fecha_fin = DateTime.Parse(datefinal); if (dataAeropuertos.SelectedRows.Count > 0 && chVuelo.Checked) { if (dataHoteles.SelectedRows.Count > 0 && chbHotel.Checked) { if (dataVehiculo.SelectedRows.Count > 0 && chbVehiculo.Checked) { hotel = (Hotel)dataHoteles.CurrentRow.DataBoundItem; aeropuerto = (Vuelo)dataAeropuertos.CurrentRow.DataBoundItem; vehiculo = (Vehiculos)dataVehiculo.CurrentRow.DataBoundItem; Compra_Reserva compra_reserva_ = new Compra_Reserva(0, usuario.getCedula, aeropuerto.pais_origen, aeropuerto.pais_destino, aeropuerto.escala, aeropuerto.duracion, aeropuerto.precio, fecha_ini, fecha_fin, (int)spAdultos.Value, (int)spNinos.Value, int.Parse(txtHabitaciones.Text), hotel.id_hotel, hotel.precio, vehiculo.id_vehiculo, vehiculo.precio, true, true, true, compra_reserva ); if (compra_reserva_.reserva_compra) { Puntuacion_Hotel ph = new Puntuacion_Hotel(compra_reserva_); ph.ShowDialog(); } Codigo_Interfaz_Vuelo civ = new Codigo_Interfaz_Vuelo(); comprado_reservado = civ.Agregar_Compra_Reserva(compra_reserva_); } else { hotel = (Hotel)dataHoteles.CurrentRow.DataBoundItem; aeropuerto = (Vuelo)dataAeropuertos.CurrentRow.DataBoundItem; Compra_Reserva compra_reserva_ = new Compra_Reserva(0, usuario.getCedula, aeropuerto.pais_origen, aeropuerto.pais_destino, aeropuerto.escala, aeropuerto.duracion, aeropuerto.precio, fecha_ini, fecha_fin, (int)spAdultos.Value, (int)spNinos.Value, int.Parse(txtHabitaciones.Text), hotel.id_hotel, hotel.precio, vehiculo.id_vehiculo, vehiculo.precio, true, true, false, compra_reserva ); if (compra_reserva_.reserva_compra) { Puntuacion_Hotel ph = new Puntuacion_Hotel(compra_reserva_); ph.ShowDialog(); } Codigo_Interfaz_Vuelo civ = new Codigo_Interfaz_Vuelo(); comprado_reservado = civ.Agregar_Compra_Reserva(compra_reserva_); } } else { if (dataVehiculo.SelectedRows.Count > 0 && chbVehiculo.Checked) { aeropuerto = (Vuelo)dataAeropuertos.CurrentRow.DataBoundItem; vehiculo = (Vehiculos)dataVehiculo.CurrentRow.DataBoundItem; Compra_Reserva compra_reserva_ = new Compra_Reserva(0, usuario.getCedula, aeropuerto.pais_origen, aeropuerto.pais_destino, aeropuerto.escala, aeropuerto.duracion, aeropuerto.precio, fecha_ini, fecha_fin, (int)spAdultos.Value, (int)spNinos.Value, int.Parse(txtHabitaciones.Text), hotel.id_hotel, hotel.precio, vehiculo.id_vehiculo, vehiculo.precio, true, false, true, compra_reserva ); Codigo_Interfaz_Vuelo civ = new Codigo_Interfaz_Vuelo(); comprado_reservado = civ.Agregar_Compra_Reserva(compra_reserva_); } else { aeropuerto = (Vuelo)dataAeropuertos.CurrentRow.DataBoundItem; Compra_Reserva compra_reserva_ = new Compra_Reserva(0, usuario.getCedula, aeropuerto.pais_origen, aeropuerto.pais_destino, aeropuerto.escala, aeropuerto.duracion, aeropuerto.precio, fecha_ini, fecha_fin, (int)spAdultos.Value, (int)spNinos.Value, int.Parse(txtHabitaciones.Text), hotel.id_hotel, hotel.precio, vehiculo.id_vehiculo, vehiculo.precio, true, false, false, compra_reserva ); Codigo_Interfaz_Vuelo civ = new Codigo_Interfaz_Vuelo(); comprado_reservado = civ.Agregar_Compra_Reserva(compra_reserva_); } } } else { if (dataHoteles.SelectedRows.Count > 0 && chbHotel.Checked) { if (dataVehiculo.SelectedRows.Count > 0 && chbVehiculo.Checked) { hotel = (Hotel)dataHoteles.CurrentRow.DataBoundItem; vehiculo = (Vehiculos)dataVehiculo.CurrentRow.DataBoundItem; Compra_Reserva compra_reserva_ = new Compra_Reserva(0, usuario.getCedula, aeropuerto.pais_origen, aeropuerto.pais_destino, aeropuerto.escala, aeropuerto.duracion, aeropuerto.precio, fecha_ini, fecha_fin, (int)spAdultos.Value, (int)spNinos.Value, int.Parse(txtHabitaciones.Text), hotel.id_hotel, hotel.precio, vehiculo.id_vehiculo, vehiculo.precio, false, true, true, compra_reserva ); if (compra_reserva_.reserva_compra) { Puntuacion_Hotel ph = new Puntuacion_Hotel(compra_reserva_); ph.ShowDialog(); } Codigo_Interfaz_Vuelo civ = new Codigo_Interfaz_Vuelo(); comprado_reservado = civ.Agregar_Compra_Reserva(compra_reserva_); } } else { if (dataVehiculo.SelectedRows.Count > 0 && chbVehiculo.Checked) { vehiculo = (Vehiculos)dataVehiculo.CurrentRow.DataBoundItem; Compra_Reserva compra_reserva_ = new Compra_Reserva(0, usuario.getCedula, aeropuerto.pais_origen, aeropuerto.pais_destino, aeropuerto.escala, aeropuerto.duracion, aeropuerto.precio, fecha_ini, fecha_fin, (int)spAdultos.Value, (int)spNinos.Value, int.Parse(txtHabitaciones.Text), hotel.id_hotel, hotel.precio, vehiculo.id_vehiculo, vehiculo.precio, false, false, true, compra_reserva ); Codigo_Interfaz_Vuelo civ = new Codigo_Interfaz_Vuelo(); comprado_reservado = civ.Agregar_Compra_Reserva(compra_reserva_); } else { MessageBox.Show("Seleccione algun vuelo o hotel o vehiculo"); } } } return(comprado_reservado); }
public Puntuacion_Hotel(Compra_Reserva cr) { InitializeComponent(); this.cr = cr; }