public List<Model.ListadoDestinoModel> listarDestinosConMasPasajesCancelados(int año, int semestre) { List<Model.ListadoDestinoModel> destinos = new List<Model.ListadoDestinoModel>(); Model.ListadoDestinoModel destino = null; SqlConnection myConnection = null; try { myConnection = new SqlConnection(stringConexion); myConnection.Open(); SqlCommand command = null; var query = "select top 5 c.nombre as destino, count(*) as cantidad "+ "from mondongo.devoluciones_pasajes d " + "inner join mondongo.pasajes p on p.pasaje_id = d.id_pasaje "+ "inner join mondongo.viajes vi on vi.viaje_id = p.pasaje_viaje_id "+ "inner join mondongo.rutas r on r.id_ruta = vi.viaje_ruta_id "+ "inner join mondongo.ciudades c on c.id_ciudad = r.id_ciudad_destino "+ "where (case when month(d.fecha_devolucion) between 1 and 6 then 1 else 2 end) = @semestre "+ "and year(d.fecha_devolucion) = @año "+ "group by c.nombre "+ "order by cantidad desc"; using (command = new SqlCommand(query, myConnection)) { command.Parameters.AddWithValue("@año", año); command.Parameters.AddWithValue("@semestre", semestre); } using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var destinoNombre = reader.GetString(0); var destinoCantidad = reader.GetInt32(1); destino = new Model.ListadoDestinoModel(destinoNombre, destinoCantidad); destinos.Add(destino); } } } catch (Exception ex) { MessageBox.Show("ERROR" + ex.Message); } finally { myConnection.Close(); } return destinos; }
public List<Model.ListadoDestinoModel> listarDestinosMasVendidos(int año, int semestre) { List<Model.ListadoDestinoModel> destinos = new List<Model.ListadoDestinoModel>(); Model.ListadoDestinoModel destino = null; SqlConnection myConnection = null; try { myConnection = new SqlConnection(stringConexion); myConnection.Open(); SqlCommand command = null; String query = "select top 5 c.nombre, count(c.nombre) as cantidad, (case when month(ve.venta_fecha_compra) between 1 and 6 then 1 else 2 end) as semestre "+ "from mondongo.pasajes p "+ "inner join mondongo.ventas ve on ve.venta_pnr = p.pasaje_venta_pnr "+ "inner join mondongo.viajes vi on vi.viaje_id = p.pasaje_viaje_id "+ "inner join mondongo.rutas r on vi.viaje_ruta_id = r.id_ruta "+ "inner join mondongo.ciudades c on c.id_ciudad = r.id_ciudad_destino "+ "group by c.nombre, (case when month(ve.venta_fecha_compra) between 1 and 6 then 1 else 2 end),year(ve.venta_Fecha_compra) "+ "having (case when month(ve.venta_fecha_compra) between 1 and 6 then 1 else 2 end) = @semestre and year(ve.venta_Fecha_compra) = @año " + "order by count(c.nombre) desc"; using (command = new SqlCommand(query, myConnection)) { command.Parameters.AddWithValue("@año", año); command.Parameters.AddWithValue("@semestre", semestre); } using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var destinoNombre = reader.GetString(0); var destinoCantidad = reader.GetInt32(1); destino = new Model.ListadoDestinoModel(destinoNombre, destinoCantidad); destinos.Add(destino); } } } catch (Exception ex) { MessageBox.Show("ERROR" + ex.Message); } finally { myConnection.Close(); } return destinos; }
public List<Model.ListadoDestinoModel> listarDestinosConAeronavesMasVacias(int año, int semestre) { List<Model.ListadoDestinoModel> destinos = new List<Model.ListadoDestinoModel>(); Model.ListadoDestinoModel destino = null; SqlConnection myConnection = null; try { myConnection = new SqlConnection(stringConexion); myConnection.Open(); SqlCommand command = null; String query = "select top 5 c.nombre, sum(libres.cantidad) as sin_vender "+ "from "+ "(select bv.viaje_id, count(bv.butaca_id) as cantidad "+ "from mondongo.butacas_viaje bv "+ "inner join mondongo.butacas b on b.butaca_id = bv.butaca_id "+ "where bv.estado = 'L' "+ "group by bv.viaje_id,bv.estado) libres "+ "inner join mondongo.viajes v on v.viaje_id = libres.viaje_id "+ "inner join mondongo.rutas r on r.id_ruta = v.viaje_ruta_id "+ "inner join mondongo.ciudades c on c.id_ciudad = r.id_ciudad_destino "+ "group by c.nombre,(case when month(v.fecha_salida) between 1 and 6 then 1 else 2 end),year(v.fecha_salida) "+ "having (case when month(v.fecha_salida) between 1 and 6 then 1 else 2 end) = @semestre and year(v.fecha_salida) = @año "+ "order by sin_vender desc"; using (command = new SqlCommand(query, myConnection)) { command.Parameters.AddWithValue("@año", año); command.Parameters.AddWithValue("@semestre", semestre); } using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var destinoNombre = reader.GetString(0); var destinoCantidad = reader.GetInt32(1); destino = new Model.ListadoDestinoModel(destinoNombre, destinoCantidad); destinos.Add(destino); } } } catch (Exception ex) { MessageBox.Show("ERROR" + ex.Message); } finally { myConnection.Close(); } return destinos; }