GetGroupDictionary依據(jù)某個(gè)單列對(duì)某一列進(jìn)行統(tǒng)計(jì),結(jié)果以字典的形式返回。 我們可以指定返回字典的Key、Value的數(shù)據(jù)類型。 這個(gè)函數(shù)的功能類似于GroupBy函數(shù),只是這里只針對(duì)一列字段進(jìn)行統(tǒng)計(jì),并且返回的是一個(gè)字典而已。
語(yǔ)法:
GetGroupDictionary<TKey,TValue>(groupColName,agreegateColName,aggregateType)
參數(shù)說(shuō)明
名稱 | 說(shuō)明 |
groupColName | 必填項(xiàng),字符串類型,分組依據(jù)列名稱。這里也只能輸入一個(gè)列名。 |
agreegateColName | 必填項(xiàng),字符串類型,需要統(tǒng)計(jì)的列名稱。這里只可以輸入一個(gè)統(tǒng)計(jì)列。如果需要統(tǒng)計(jì)多列的,請(qǐng)使用PivotDataTable。 |
aggregateType | 可選項(xiàng),AggregateTypeEnum類型枚舉,統(tǒng)計(jì)的類型。默認(rèn)值為Sum。 |
我們還是針對(duì)這樣的數(shù)據(jù)進(jìn)行測(cè)試。
Vb.Net |
Dim tbl As SmGrid=Proj.CurrentSmGrid '獲取求和字典 Dim dic As Dictionary(Of String,Integer)=tbl.DataTableHelp.GetGroupDictionary(Of String,Integer)("產(chǎn)品","數(shù)量",AggregateTypeEnum.Sum) '遍歷字典并顯示 For Each item As KeyValuePair(Of String,Integer)In dic Proj.MsgDebug.Add(item.Key+"|"+item.Value.ToString()) Next '獲取計(jì)數(shù)字典 dic=tbl.DataTableHelp.GetGroupDictionary(Of String,Integer)("產(chǎn)品","數(shù)量",AggregateTypeEnum.Count) '遍歷字典并顯示 For Each item As KeyValuePair(Of String,Integer)In dic Proj.MsgDebug.Add(item.Key+"|"+item.Value.ToString()) Next '返回結(jié)果:產(chǎn)品01|214646 '返回結(jié)果:產(chǎn)品02|222197 '返回結(jié)果:產(chǎn)品03|216428 '返回結(jié)果:產(chǎn)品04|217996 '返回結(jié)果:產(chǎn)品05|229748 '返回結(jié)果:產(chǎn)品01|380 '返回結(jié)果:產(chǎn)品02|395 '返回結(jié)果:產(chǎn)品03|388 '返回結(jié)果:產(chǎn)品04|418 '返回結(jié)果:產(chǎn)品05|419 |
C# |
SmGrid tbl = Proj.CurrentSmGrid; // 獲取求和字典 Dictionary<string, int> dic = tbl.DataTableHelp.GetGroupDictionary<string, int>("產(chǎn)品", "數(shù)量", AggregateTypeEnum.Sum); // 遍歷字典并顯示 foreach (KeyValuePair<string, int> item in dic) Proj.MsgDebug.Add(item.Key + "|" + item.Value.ToString()); // 獲取計(jì)數(shù)字典 dic = tbl.DataTableHelp.GetGroupDictionary<string, int>("產(chǎn)品", "數(shù)量", AggregateTypeEnum.Count); // 遍歷字典并顯示 foreach (KeyValuePair<string, int> item in dic) Proj.MsgDebug.Add(item.Key + "|" + item.Value.ToString()); //返回結(jié)果:產(chǎn)品01|214646 //返回結(jié)果:產(chǎn)品02|222197 //返回結(jié)果:產(chǎn)品03|216428 //返回結(jié)果:產(chǎn)品04|217996 //返回結(jié)果:產(chǎn)品05|229748 //返回結(jié)果:產(chǎn)品01|380 //返回結(jié)果:產(chǎn)品02|395 //返回結(jié)果:產(chǎn)品03|388 //返回結(jié)果:產(chǎn)品04|418 //返回結(jié)果:產(chǎn)品05|419 |