public List <Mas_vendidos> get_masvendidos(string Fecha1, string Fecha2) { string query = ""; if (Fecha1 == Fecha2) { query = "select sum(tbadetticket.cantidad) as cantidad, tbadetticket.descripcion, tbaproductos.codigo from tbadetticket inner join tbaproductos on tbadetticket.id_producto=tbaproductos.id inner join tbatickets on tbadetticket.id_ticket=tbatickets.id where DATE_FORMAT(tbatickets.fecha,'%Y-%m-%d')='" + Fecha1 + "' GROUP by tbadetticket.id_producto order by cantidad DESC limit 5"; } else { query = "select sum(tbadetticket.cantidad) as cantidad, tbadetticket.descripcion, tbaproductos.codigo from tbadetticket inner join tbaproductos on tbadetticket.id_producto=tbaproductos.id inner join tbatickets on tbadetticket.id_ticket=tbatickets.id where DATE_FORMAT(tbatickets.fecha,'%Y-%m-%d') BETWEEN '" + Fecha1 + "' and '" + Fecha2 + "' GROUP by tbadetticket.id_producto order by cantidad DESC limit 5"; } MySqlDataReader data = runQuery(query); List <Mas_vendidos> result = new List <Mas_vendidos>(); if (data.HasRows) { while (data.Read()) { Mas_vendidos item = Build_vendidos(data); result.Add(item); } } return(result); }
private Mas_vendidos Build_vendidos(MySqlDataReader data) { Mas_vendidos item = new Mas_vendidos( data.GetString("codigo"), data.GetString("descripcion"), data.GetDouble("cantidad") ); return(item); }