DateTime end = Convert.ToDateTime(DateTime.Now.ToString("dd/MM/yyyy"));
series.Points.AddXY(selectedDate.ToString("dd/MM/yyyy"), linqSum.total);
double total = db.InfoLivraison.GroupBy(a => selectedDate).Sum(b => b.montantCommande);//en supposant que montantCommande soit un nombre
double total = db.InfoLivraison.GroupBy(a => selectedDate).Select(b => b.Sum(x => Convert.ToDouble(x.montantCommande)));
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic partial class InfoLivraison { public int ID { get; set; } public string Nom { get; set; } public string Prenom { get; set; } public string Email { get; set; } public string Telephone { get; set; } public string ModePay { get; set; } public string Info { get; set; } public string Offre { get; set; } public Nullable<int> SessionNB { get; set; } public string heure_command { get; set; } public string date_command { get; set; } public string adresse { get; set; } public string CP { get; set; } public string ville { get; set; } public string montantCommande { get; set; } public Nullable<System.DateTime> date_command2 { get; set; } }
public static DataTable ToDataTable<T>(List<T> items)
{
DataTable dataTable = new DataTable(typeof(T).Name);
//Get all the properties
PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo prop in Props)
{
//Setting column names as Property names
dataTable.Columns.Add(prop.Name);
}
foreach (T item in items)
{
var values = new object[Props.Length];
for (int i = 0; i < Props.Length; i++)
{
//inserting property values to datatable rows
values[i] = Props[i].GetValue(item, null);
}
dataTable.Rows.Add(values);
}
//put a breakpoint here and check datatable
return dataTable;
}
List<InfoLivraison> maListe = new List<InfoLivraison> { new InfoLivraison{ date_command2 = new DateTime(2017,10,01), montantCommande = "14"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,11), montantCommande = "14"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,11), montantCommande = "22"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,12), montantCommande = "15"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,13), montantCommande = "17"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,18), montantCommande = "32"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,18), montantCommande = "11"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,19), montantCommande = "39"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,19), montantCommande = "24"} }; var requete = (from info in maListe where info.date_command2 >= DateTime.Now.Date.AddDays(-7) && info.date_command2 <= DateTime.Now.Date group info by info.date_command2 into groupe select new { Date = groupe.Key, Total = groupe.Sum(x => Convert.ToDouble(x.montantCommande)) }).ToList(); foreach(var couple in requete) { series.Points.AddXY(couple.Date.ToString(), couple.Total); }
List<InfoLivraison> maListe = new List<InfoLivraison> { new InfoLivraison{ date_command2 = new DateTime(2017,10,01), montantCommande = "14"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,11), montantCommande = "14"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,11), montantCommande = "22"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,12), montantCommande = "15"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,13), montantCommande = "17"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,18), montantCommande = "32"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,18), montantCommande = "11"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,19), montantCommande = "39"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,19), montantCommande = "24"} }; Dictionary<string, double> requete = (from info in maListe where info.date_command2 >= DateTime.Now.Date.AddDays(-7) && info.date_command2 <= DateTime.Now.Date group info by info.date_command2 into groupe select new { Date = ((DateTime)groupe.Key).ToShortDateString(), Total = groupe.Sum(x => Convert.ToDouble(x.montantCommande)) }).ToDictionary(x => x.Date, x => x.Total); foreach(KeyValuePair<string,double> couple in requete) { series.Points.AddXY(couple.Key, couple.Value); }
List<InfoLivraison> maListe = new List<InfoLivraison> { new InfoLivraison{ date_command2 = new DateTime(2017,10,01), montantCommande = "14"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,11), montantCommande = "14"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,11), montantCommande = "22"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,12), montantCommande = "15"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,13), montantCommande = "17"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,18), montantCommande = "32"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,18), montantCommande = "11"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,19), montantCommande = "39"}, new InfoLivraison{ date_command2 = new DateTime(2017,10,19), montantCommande = "24"} }; foreach(IGrouping<DateTime?,InfoLivraison> couple in maListe.Where(info => info.date_command2 >= DateTime.Now.Date.AddDays(-7) && info.date_command2 <= DateTime.Now.Date).GroupBy(info => info.date_command2)) { series.Points.AddXY(((DateTime)couple.Key).ToShortDateString(), couple.Sum(x => Convert.ToDouble(x.montantCommande))); }
18 oct. 2017 à 18:39
Merci