public List <StatArticles> GetStatArticles(string dateDebut, string dateFin, string numeroEmplacement) { Connexion connexion = new Connexion(); string query = ""; if (dateFin == "" && dateDebut == "") { query = "select reference_article, count(*) as total from detail_commande join commande on commande.id_commande=detail_commande.id_commande where emplacement ='" + numeroEmplacement + "' group by reference_article"; } else { query = "select reference_article, count(*) as total from detail_commande join commande on commande.id_commande=detail_commande.id_commande where emplacement ='" + numeroEmplacement + "' and date_commande<='" + dateFin + "' and date_commande>='" + dateDebut + "' group by reference_article"; } MySqlCommand command = new MySqlCommand(query, connexion.GetConnection()); MySqlDataReader dataReader; //Creation d'une liste List <StatArticles> reponse = new List <StatArticles>(); AccesSageDAO accesSageDAO = new AccesSageDAO(); try { //Ouverture connexion if (connexion.OpenConnection() == true) { //Excecution de la commande dataReader = command.ExecuteReader(); //Lecture des donnees et stockage dans la liste while (dataReader.Read()) { StatArticles stat = new StatArticles(); Article article = accesSageDAO.GetArticleByReferences(dataReader["reference_article"].ToString()); stat.Article = article; stat.Quantite = Int32.Parse(dataReader["total"].ToString()); reponse.Add(stat); } dataReader.Close(); } //return return(reponse); } catch (Exception exception) { throw exception; } finally { if (command != null) { command.Dispose(); } if (connexion.GetConnection() != null) { connexion.GetConnection().Close(); } } }
public JsonResult GetStatistiquesByEmplacement(string dateDebut, string dateFin, string numeroEmplacements) { try { StatArticles stat = new StatArticles(); List <StatArticles> liste = stat.GetStatArticles(dateDebut, dateFin, numeroEmplacements); return(Json(liste)); } catch (Exception exception) { return(Json(exception.Message)); } }