开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 3741|回复: 3

DevExpress如何实现自定义求和

[复制链接]

0

精华

0

贡献

6

赞扬

帖子
31
软币
206
在线时间
9 小时
注册时间
2015-9-24
发表于 2015-9-24 10:49:50 | 显示全部楼层 |阅读模式
概述:DevExpress实现自定义求和的效果图及事例代码

自定义求和的效果图如下:

代码如下:

C#

[size=1em]
[size=1em]1

[size=1em]2

[size=1em]3

[size=1em]4

[size=1em]5

[size=1em]6

[size=1em]7

[size=1em]8

[size=1em]9

[size=1em]10

[size=1em]11

[size=1em]12

[size=1em]13

[size=1em]14

[size=1em]15

[size=1em]16

[size=1em]17

[size=1em]18

[size=1em]19

[size=1em]20

[size=1em]21

[size=1em]22

[size=1em]23

[size=1em]24

[size=1em]25

[size=1em]26

[size=1em]27

[size=1em]28

[size=1em]29

[size=1em]30

[size=1em][size=1em]using DevExpress.XtraPivotGrid;

[size=1em]fieldExtendedPrice.Caption = "Percentage of Orders over $500";
[size=1em]// Enable a custom summary calculation for the Extended Price field.
[size=1em]fieldExtendedPrice.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Custom;
[size=1em]// Specify the settings used to format values.
[size=1em]fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
[size=1em]fieldExtendedPrice.CellFormat.FormatString = "p";

[size=1em]int minSum = 500;

[size=1em]private void pivotGridControl1_CustomSummary(object sender,
[size=1em]  PivotGridCustomSummaryEventArgs e) {
[size=1em]   if(e.DataField != fieldExtendedPrice) return;
[size=1em]   // A variable which counts the number of orders whose sum exceeds $500.
[size=1em]   int order500Count = 0;
[size=1em]   // Get the record set corresponding to the current cell.
[size=1em]   PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();
[size=1em]   // Iterate through the records and count the orders.
[size=1em]   for(int i = 0; i < ds.RowCount; i++) {
[size=1em]      PivotDrillDownDataRow row = ds;
[size=1em]      // Get the order's total sum.
[size=1em]      decimal orderSum = (decimal)row[fieldExtendedPrice];
[size=1em]      if(orderSum >= minSum) order500Count ++;
[size=1em]   }
[size=1em]   // Calculate the percentage.
[size=1em]   if(ds.RowCount > 0) {
[size=1em]      e.CustomValue = (decimal)order500Count/ds.RowCount;
[size=1em]   }
[size=1em]}



VB

[size=1em]
[size=1em]1

[size=1em]2

[size=1em]3

[size=1em]4

[size=1em]5

[size=1em]6

[size=1em]7

[size=1em]8

[size=1em]9

[size=1em]10

[size=1em]11

[size=1em]12

[size=1em]13

[size=1em]14

[size=1em]15

[size=1em]16

[size=1em]17

[size=1em]18

[size=1em]19

[size=1em]20

[size=1em]21

[size=1em]22

[size=1em]23

[size=1em]24

[size=1em]25

[size=1em]26

[size=1em]27

[size=1em]28

[size=1em]29

[size=1em]30

[size=1em]31

[size=1em][size=1em]Imports DevExpress.XtraPivotGrid

[size=1em]fieldExtendedPrice.Caption = "Percentage of Orders over $500"
[size=1em]' Enable a custom summary calculation for the Extended Price field.
[size=1em]fieldExtendedPrice.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Custom
[size=1em]' Specify the settings used to format values.
[size=1em]fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
[size=1em]fieldExtendedPrice.CellFormat.FormatString = "p"

[size=1em]Dim minSum As Integer = 500

[size=1em]Private Sub PivotGridControl1_CustomSummary(ByVal sender As Object, _
[size=1em]  ByVal e As PivotGridCustomSummaryEventArgs) Handles PivotGridControl1.CustomSummary
[size=1em]   If Not e.DataField Is fieldExtendedPrice Then Return
[size=1em]   ' A variable which counts the number of orders whose sum exceeds $500.
[size=1em]   Dim order500Count As Integer = 0
[size=1em]   ' Get the record set corresponding to the current cell.
[size=1em]   Dim ds As PivotDrillDownDataSource = e.CreateDrillDownDataSource()
[size=1em]   ' Iterate through the records and count the orders.
[size=1em]   Dim i As Integer
[size=1em]   For i = 0 To ds.RowCount - 1
[size=1em]      Dim row As PivotDrillDownDataRow = ds(i)
[size=1em]      ' Get the order's total sum.
[size=1em]      Dim orderSum As Decimal = row(fieldExtendedPrice)
[size=1em]      If orderSum >= minSum Then order500Count = order500Count + 1
[size=1em]   Next
[size=1em]   ' Calculate the percentage.
[size=1em]   If ds.RowCount > 0 Then
[size=1em]      e.CustomValue = order500Count / ds.RowCount
[size=1em]   End If
[size=1em]End Sub

更多资讯






回复

使用道具 举报

0

精华

129

贡献

52

赞扬

帖子
247
软币
1806
在线时间
193 小时
注册时间
2014-5-13
发表于 2015-9-24 22:51:13 | 显示全部楼层
晕,这可怎么看啦
回复

使用道具 举报

0

精华

0

贡献

6

赞扬

帖子
31
软币
206
在线时间
9 小时
注册时间
2015-9-24
 楼主| 发表于 2015-9-25 09:39:17 | 显示全部楼层
bingw001 发表于 2015-9-24 22:51
晕,这可怎么看啦

呀,居然看不见了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using DevExpress.XtraPivotGrid;

fieldExtendedPrice.Caption = "Percentage of Orders over $500";
// Enable a custom summary calculation for the Extended Price field.
fieldExtendedPrice.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Custom;
// Specify the settings used to format values.
fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
fieldExtendedPrice.CellFormat.FormatString = "p";

int minSum = 500;

private void pivotGridControl1_CustomSummary(object sender,
  PivotGridCustomSummaryEventArgs e) {
   if(e.DataField != fieldExtendedPrice) return;
   // A variable which counts the number of orders whose sum exceeds $500.
   int order500Count = 0;
   // Get the record set corresponding to the current cell.
   PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();
   // Iterate through the records and count the orders.
   for(int i = 0; i < ds.RowCount; i++) {
      PivotDrillDownDataRow row = ds;
      // Get the order's total sum.
      decimal orderSum = (decimal)row[fieldExtendedPrice];
      if(orderSum >= minSum) order500Count ++;
   }
   // Calculate the percentage.
   if(ds.RowCount > 0) {
      e.CustomValue = (decimal)order500Count/ds.RowCount;
   }
}
VB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Imports DevExpress.XtraPivotGrid

fieldExtendedPrice.Caption = "Percentage of Orders over $500"
' Enable a custom summary calculation for the Extended Price field.
fieldExtendedPrice.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Custom
' Specify the settings used to format values.
fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
fieldExtendedPrice.CellFormat.FormatString = "p"

Dim minSum As Integer = 500

Private Sub PivotGridControl1_CustomSummary(ByVal sender As Object, _
  ByVal e As PivotGridCustomSummaryEventArgs) Handles PivotGridControl1.CustomSummary
   If Not e.DataField Is fieldExtendedPrice Then Return
   ' A variable which counts the number of orders whose sum exceeds $500.
   Dim order500Count As Integer = 0
   ' Get the record set corresponding to the current cell.
   Dim ds As PivotDrillDownDataSource = e.CreateDrillDownDataSource()
   ' Iterate through the records and count the orders.
   Dim i As Integer
   For i = 0 To ds.RowCount - 1
      Dim row As PivotDrillDownDataRow = ds(i)
      ' Get the order's total sum.
      Dim orderSum As Decimal = row(fieldExtendedPrice)
      If orderSum >= minSum Then order500Count = order500Count + 1
   Next
   ' Calculate the percentage.
   If ds.RowCount > 0 Then
      e.CustomValue = order500Count / ds.RowCount
   End If
End Sub
回复

使用道具 举报

0

精华

129

贡献

52

赞扬

帖子
247
软币
1806
在线时间
193 小时
注册时间
2014-5-13
发表于 2015-9-25 09:51:15 | 显示全部楼层
哇,谢谢楼主给修复了
回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-5-22 22:45

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表