public void Statistic(IList <PersonPlanStatisticData> source) { List <StatisticDataSource> datasources = new List <StatisticDataSource>(); List <NameValuePair <string> > statisticgroups = new List <NameValuePair <string> >(); IEnumerable <IGrouping <string, PersonPlanStatisticData> > conditions = source.GroupBy(r => r.AddressGuid); foreach (IGrouping <string, PersonPlanStatisticData> condition in conditions) { StatisticDataSource datasource = new StatisticDataSource(); PersonPlanStatisticData data = condition.FirstOrDefault(r => r.AddressGuid == condition.Key); datasource.GroupGuid = condition.Key; if (data != null) { datasource.Group = data.Address; } else { datasource.Group = ""; } IEnumerable <IGrouping <string, PersonPlanStatisticData> > groups = condition.GroupBy(r => r.Type); foreach (IGrouping <string, PersonPlanStatisticData> group in groups) { double count = group.Sum(n => n.Count); datasource[group.Key] = count; int groupcount = statisticgroups.Count(r => r.Name == group.Key); if (groupcount == 0) { NameValuePair <string> pair = new NameValuePair <string>() { Name = group.Key, Value = group.Key }; if (!statisticgroups.Contains(pair)) { statisticgroups.Add(pair); } } } datasources.Add(datasource); } this.statisticListControl.statisticGroup = statisticgroups; this.statisticListControl.StatisticItemsSource = datasources; SetChartItemsSource(source.ToList()); }
/// <summary> /// 返回人员统计列表 /// </summary> /// <param name="obj"></param> /// <returns></returns> public List <PersonPlanStatisticData> GetPersonPlanStats2017(string obj) { DataSet ds = DbHelperACE.Query(Getpersonstat2017); List <PersonPlanStatisticData> PersonPlanList = new List <PersonPlanStatisticData>(); DataRowCollection drs = ds.Tables[0].Rows; for (int i = 0; i < drs.Count; i++) { PersonPlanStatisticData item = new PersonPlanStatisticData(); item.AddressGuid = drs[i]["name"].ToString().Trim(); item.Address = drs[i]["name"].ToString().Trim(); item.Type = drs[i]["type"].ToString().Trim(); if (drs[i]["statisticcount"] != DBNull.Value) { item.Count = Double.Parse(drs[i]["statisticcount"].ToString().Trim()); } PersonPlanList.Add(item); } DataSet dshj = DbHelperACE.Query(GetpersonstatHJ2017); DataRowCollection drshj = dshj.Tables[0].Rows; for (int i = 0; i < drshj.Count; i++) { PersonPlanStatisticData item = new PersonPlanStatisticData(); item.AddressGuid = drshj[i]["name"].ToString().Trim(); item.Address = drshj[i]["name"].ToString().Trim(); item.Type = drshj[i]["type"].ToString().Trim(); if (drshj[i]["statisticcount"] != DBNull.Value) { item.Count = Double.Parse(drshj[i]["statisticcount"].ToString().Trim()); } PersonPlanList.Add(item); } return(PersonPlanList); }
/// <summary> /// 返回人员统计列表 /// </summary> /// <param name="obj"></param> /// <returns></returns> public List <PersonPlanStatisticData> GetPersonRPStatByDate(string fromDate, string toDate) { // SELECT nameid, name, INCIDENT as type, sum(FRACTION) as statisticcount FROM PersonRewardPunishInfo //where Format(RPTIME,"yyyy-mm-dd") <= "2012/10/12" //group by NAMEID, NAME, INCIDENT order by NAME, INCIDENT if (string.IsNullOrEmpty(fromDate) == false) { GetPersonRPStatByDateSql += " and Format(RPTIME,\"yyyy-mm-dd\") >= \'" + fromDate + "'"; } if (string.IsNullOrEmpty(toDate) == false) { GetPersonRPStatByDateSql += " and Format(RPTIME,\"yyyy-mm-dd\") <= \'" + toDate + "'"; } GetPersonRPStatByDateSql += " group by NAMEID, NAME, INCIDENT order by NAME, INCIDENT "; DataSet ds = DbHelperACE.Query(GetPersonRPStatByDateSql); List <PersonPlanStatisticData> PersonPlanList = new List <PersonPlanStatisticData>(); DataRowCollection drs = ds.Tables[0].Rows; for (int i = 0; i < drs.Count; i++) { PersonPlanStatisticData item = new PersonPlanStatisticData(); item.AddressGuid = drs[i]["nameid"].ToString().Trim(); item.Address = drs[i]["name"].ToString().Trim(); item.Type = drs[i]["type"].ToString().Trim(); if (drs[i]["statisticcount"] != DBNull.Value) { item.Count = Double.Parse(drs[i]["statisticcount"].ToString().Trim()); } PersonPlanList.Add(item); } // and Format(RPTIME,'yyyy - mm - dd') >= @fromDate //and Format(RPTIME,'yyyy - mm - dd') <= @toDate List <OleDbParameter> paramList = new List <OleDbParameter>(); OleDbParameter param = new OleDbParameter("@fromDate", OleDbType.LongVarWChar); param.Value = fromDate; paramList.Add(param); OleDbParameter toDateparam = new OleDbParameter("@toDate", OleDbType.LongVarWChar); toDateparam.Value = toDate; paramList.Add(toDateparam); DataSet dshj = DbHelperACE.Query(GetPersonRPStatByDateHJSql, paramList.ToArray()); DataRowCollection drshj = dshj.Tables[0].Rows; for (int i = 0; i < drshj.Count; i++) { PersonPlanStatisticData item = new PersonPlanStatisticData(); item.AddressGuid = drshj[i]["name"].ToString().Trim(); item.Address = drshj[i]["name"].ToString().Trim(); item.Type = drshj[i]["type"].ToString().Trim(); if (drshj[i]["statisticcount"] != DBNull.Value) { item.Count = Double.Parse(drshj[i]["statisticcount"].ToString().Trim()); } PersonPlanList.Add(item); } return(PersonPlanList); }