/// <summary> /// Selects an ordered list of the most sold products by the new Software /// </summary> /// <returns> List<ProductosMasVendidos> </returns> public List <ProductosMasVendidos> getAllProductosMasVendidosPorNuevoSoftware() { List <ProductosMasVendidos> listProductos = new List <ProductosMasVendidos>(); string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { string statement = " Select T.Nombre AS NOMBRE_DEL_MEDICAMENTO , SUM(T.Cantidad) AS TOTAL_VENDIDO" + " FROM" + " (" + " SELECT Nombre, Cantidad" + " FROM MEDICAMENTOS_POR_PEDIDO JOIN MEDICAMENTO ON Codigo = CodigoMedicamento" + " UNION ALL" + " SELECT Nombre, Cantidad" + " FROM MEDICAMENTOS_POR_RECETA JOIN MEDICAMENTO ON Codigo = CodigoMedicamento" + " ) AS T" + " GROUP BY (T.Nombre)" + " ORDER BY(TOTAL_VENDIDO) DESC" ; SqlCommand cmd = new SqlCommand(statement, con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) //si existe en la base de datos { ProductosMasVendidos producto = new ProductosMasVendidos(); producto.NombreMedicamento = rdr["NOMBRE_DEL_MEDICAMENTO"].ToString(); producto.CantidadVendida = rdr["TOTAL_VENDIDO"].ToString(); listProductos.Add(producto); } } return(listProductos); }
/// <summary> /// Selects an ordered list of the most sold products by each company /// </summary> /// <param name="Empresa"> The company where ProductosMasMvendidos belongs </param> /// <returns> List<ProductosMasVendidos> </returns> public List <ProductosMasVendidos> getProductosMasVendidosPorEmpresa(string Empresa) { List <ProductosMasVendidos> listProductos = new List <ProductosMasVendidos>(); string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { string statement = "Select T.Nombre AS NOMBRE_DEL_MEDICAMENTO , SUM(T.Cantidad) AS TOTAL_VENDIDO" + " FROM" + " (" + " SELECT Nombre, Cantidad, Empresa FROM" + " PEDIDO AS P JOIN MEDICAMENTOS_POR_PEDIDO AS MP ON MP.NoFactura = P.NoFactura" + " JOIN MEDICAMENTO AS M ON M.Codigo = MP.CodigoMedicamento" + " UNION ALL" + " SELECT Nombre, Cantidad, Empresa FROM" + " PEDIDO AS P JOIN RECETA AS R ON P.NoFactura = R.NoFactura" + " JOIN MEDICAMENTOS_POR_RECETA AS MP ON R.NoReceta = MP.NoReceta" + " JOIN MEDICAMENTO AS M ON M.Codigo = MP.CodigoMedicamento" + " UNION ALL" + " SELECT Nombre, Cantidad, Empresa FROM" + " PEDIDO AS P JOIN MEDICAMENTOS_POR_PEDIDO_FISICO AS MPF ON P.NoFactura = MPF.NoFactura" + " JOIN MEDICAMENTO ON Codigo = CodigoMedicamento" + " ) AS T" + " WHERE Empresa = '" + Empresa + "'" + " GROUP BY (T.Nombre)" + " ORDER BY(TOTAL_VENDIDO) DESC" ; SqlCommand cmd = new SqlCommand(statement, con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) //si existe en la base de datos { ProductosMasVendidos producto = new ProductosMasVendidos(); producto.NombreMedicamento = rdr["NOMBRE_DEL_MEDICAMENTO"].ToString(); producto.CantidadVendida = rdr["TOTAL_VENDIDO"].ToString(); listProductos.Add(producto); } } return(listProductos); }
private void ProductosMasVendidosbutton_Click(object sender, EventArgs e) { Form productosMasVendidos = new ProductosMasVendidos(); productosMasVendidos.Show(); }