zoukankan      html  css  js  c++  java
  • C# Datatable group by 查询

     操作Datatable  group by  查询

                    //获取统计图形数据
                    var dicleft = new Dictionary<string, DataTable>();
                    var query = from t in dataTableList[0].AsEnumerable()
                                group t by new { mname = t.Field<string>("COL_MATERIAL_NAME") } into m
                                select new
                                {
                                    MaterialName = m.Key.mname,
                                    value = m.ToList()
                                };
                    foreach (var item in query)
                    {
                        var dtmax = new DataTable();
                        dtmax.Columns.Add("XValue");
                        dtmax.Columns.Add("YValue");
                        var dtmin = dtmax.Copy();
                        var dtavg = dtmax.Copy();
                        var dtup = dtmax.Copy();
                        var dtdown = dtmax.Copy();
    
                        foreach (DataRow dritem in item.value)
                        {
                            DataRow dr = dtmax.NewRow();
                            dr["XValue"] = dritem["COL_DATEMONTH"];
                            dr["YValue"] = dritem["COL_MAXVALUE"];
                            dtmax.Rows.Add(dr);
                            dr = dtmin.NewRow();
                            dr["XValue"] = dritem["COL_DATEMONTH"];
                            dr["YValue"] = dritem["COL_MINVALUE"];
                            dtmin.Rows.Add(dr);
                            dr = dtavg.NewRow();
                            dr["XValue"] = dritem["COL_DATEMONTH"];
                            dr["YValue"] = dritem["COL_AVGVALUE"];
                            dtavg.Rows.Add(dr);
                            dr = dtup.NewRow();
                            dr["XValue"] = dritem["COL_DATEMONTH"];
                            dr["YValue"] = dritem["COL_UPVALUE"];
                            dtup.Rows.Add(dr);
                            dr = dtdown.NewRow();
                            dr["XValue"] = dritem["COL_DATEMONTH"];
                            dr["YValue"] = dritem["COL_DOWNVALUE"];
                            dtdown.Rows.Add(dr);
                        }
                        dicleft.Add(item.MaterialName + "-最高值", dtmax);
                        dicleft.Add(item.MaterialName + "-最低值", dtmin);
                        dicleft.Add(item.MaterialName + "-平均值", dtavg);
                        dicleft.Add(item.MaterialName + "-内控上限", dtup);
                        dicleft.Add(item.MaterialName + "-内控下限", dtdown);
                    }
                    chartEntity = QMBasicData.AnalyticSeriesData(dicleft, "", new Dictionary<string, DataTable>(), "",
                        ChartTypeEnum.Line);
  • 相关阅读:
    模板库
    LCT小结
    BZOJ1502: [NOI2005]月下柠檬树
    技术资料分享
    ORM介紹及ORM優點、缺點
    依賴注入入門——Unity(二)
    面向切面編程入門(一)
    依賴注入入門——Unity(一)
    WCF、.Net Remoting、Web Service概念及区别
    深入设计模式(四)——建造者模式
  • 原文地址:https://www.cnblogs.com/yisheng/p/5421940.html
Copyright © 2011-2022 走看看