-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefault.aspx.vb
224 lines (200 loc) · 14.3 KB
/
Default.aspx.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
Imports System
Imports System.Collections.Generic
Imports DevExpress.Web.ASPxPivotGrid
Imports DevExpress.Data.PivotGrid
Imports DevExpress.XtraPivotGrid
Namespace SummaryDisplayMode
Public Partial Class DefaultForm
Inherits Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack AndAlso Not IsCallback Then SetSelectedConfiguration()
End Sub
Const SummaryDisplayTypeDataFieldID As String = "summaryDisplayTypeDataField"
Const SourceDataFieldID As String = "sourceDataField"
Friend Enum SummaryDisplayTypeGroup
Variation = 0
Percentage = 1
Rank = 2
End Enum
Private ReadOnly Property SelectedGroup As SummaryDisplayTypeGroup
Get
Return CType(rgSummaryDisplayTypeGroups.SelectedIndex, SummaryDisplayTypeGroup)
End Get
End Property
Private Property SourceDataFieldName As String
Get
Return cachedSourceDataFieldName.Value
End Get
Set(ByVal value As String)
cachedSourceDataFieldName.Value = value
End Set
End Property
Private ReadOnly Property SourceDataField As PivotGridField
Get
Return pivotGrid.Fields(SourceDataFieldID)
End Get
End Property
Private ReadOnly Property SummaryDisplayTypeDataField As PivotGridField
Get
Return pivotGrid.Fields(SummaryDisplayTypeDataFieldID)
End Get
End Property
Protected Sub rgSummaryDisplayTypeGroups_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
SetSelectedConfiguration()
End Sub
Private Sub SetSelectedConfiguration()
SetSelectedGroup()
SetSelectedSummaryDisplayType()
End Sub
Private Sub SetSelectedGroup()
ConfigurePivotGridLayout(SelectedGroup)
Dim isVariation As Boolean = SelectedGroup = SummaryDisplayTypeGroup.Variation
cbAllowCrossGroupVariation.Visible = isVariation
If SourceDataField IsNot Nothing Then cbShowRawValues.Checked = SourceDataField.Visible
ConfigureSummaryDisplayTypeComboBox(SelectedGroup)
End Sub
Private Sub ConfigurePivotGridLayout(ByVal typeGroup As SummaryDisplayTypeGroup)
pivotGrid.BeginUpdate()
Select Case typeGroup
Case SummaryDisplayTypeGroup.Variation
pivotGrid.DataSourceID = "SalesPersonsDataSource"
pivotGrid.Fields.Clear()
Dim fieldYear As PivotGridField = pivotGrid.Fields.AddDataSourceColumn("OrderDate", PivotArea.ColumnArea, PivotGroupInterval.DateYear)
fieldYear.Caption = "Year"
Dim fieldQuarter As PivotGridField = pivotGrid.Fields.AddDataSourceColumn("OrderDate", PivotArea.ColumnArea, PivotGroupInterval.DateQuarter)
fieldQuarter.ValueFormat.FormatString = "Qtr {0}"
fieldQuarter.ValueFormat.FormatType = DevExpress.Utils.FormatType.Custom
fieldQuarter.Caption = "Quarter"
Dim salesPersonField As PivotGridField = pivotGrid.Fields.AddDataSourceColumn("Sales Person", PivotArea.RowArea)
SourceDataFieldName = "OrderID"
Dim sourceDataField As PivotGridField = pivotGrid.Fields.AddDataSourceColumn(SourceDataFieldName, PivotArea.DataArea)
sourceDataField.SummaryType = PivotSummaryType.Count
sourceDataField.Caption = "Order Count"
sourceDataField.ID = SourceDataFieldID
Dim summaryDisplayTypeDataField As PivotGridField = pivotGrid.Fields.AddDataSourceColumn(SourceDataFieldName, PivotArea.DataArea)
summaryDisplayTypeDataField.SummaryType = sourceDataField.SummaryType
summaryDisplayTypeDataField.ID = SummaryDisplayTypeDataFieldID
Case SummaryDisplayTypeGroup.Percentage
pivotGrid.DataSourceID = "ProductReportsDataSource"
pivotGrid.Fields.Clear()
Dim fieldYear As PivotGridField = pivotGrid.Fields.AddDataSourceColumn("ShippedDate", PivotArea.ColumnArea, PivotGroupInterval.DateYear)
fieldYear.Caption = "Year"
Dim fieldMonth As PivotGridField = pivotGrid.Fields.AddDataSourceColumn("ShippedDate", PivotArea.ColumnArea, PivotGroupInterval.DateMonth)
fieldMonth.Caption = "Month"
Dim categoryNameField As PivotGridField = pivotGrid.Fields.AddDataSourceColumn("CategoryName", PivotArea.RowArea)
Dim productNameField As PivotGridField = pivotGrid.Fields.AddDataSourceColumn("ProductName", PivotArea.RowArea)
SourceDataFieldName = "ProductSales"
Dim sourceDataField As PivotGridField = pivotGrid.Fields.AddDataSourceColumn(SourceDataFieldName, PivotArea.DataArea)
sourceDataField.ID = SourceDataFieldID
Dim summaryDisplayTypeDataField As PivotGridField = pivotGrid.Fields.AddDataSourceColumn(SourceDataFieldName, PivotArea.DataArea)
summaryDisplayTypeDataField.ID = SummaryDisplayTypeDataFieldID
Case SummaryDisplayTypeGroup.Rank
pivotGrid.DataSourceID = "SalesPersonsDataSource"
pivotGrid.Fields.Clear()
Dim fieldYear As PivotGridField = pivotGrid.Fields.AddDataSourceColumn("OrderDate", PivotArea.ColumnArea, PivotGroupInterval.DateYear)
fieldYear.Caption = "Year"
Dim fieldQuarter As PivotGridField = pivotGrid.Fields.AddDataSourceColumn("OrderDate", PivotArea.ColumnArea, PivotGroupInterval.DateQuarter)
fieldQuarter.ValueFormat.FormatString = "Qtr {0}"
fieldQuarter.ValueFormat.FormatType = DevExpress.Utils.FormatType.Custom
fieldQuarter.Caption = "Quarter"
Dim countryField As PivotGridField = pivotGrid.Fields.AddDataSourceColumn("Country", PivotArea.RowArea)
Dim salesPersonField As PivotGridField = pivotGrid.Fields.AddDataSourceColumn("Sales Person", PivotArea.RowArea)
SourceDataFieldName = "Extended Price"
Dim sourceDataField As PivotGridField = pivotGrid.Fields.AddDataSourceColumn(SourceDataFieldName, PivotArea.DataArea)
sourceDataField.Caption = "Sales"
sourceDataField.ID = SourceDataFieldID
Dim summaryDisplayTypeDataField As PivotGridField = pivotGrid.Fields.AddDataSourceColumn(SourceDataFieldName, PivotArea.DataArea)
summaryDisplayTypeDataField.ID = SummaryDisplayTypeDataFieldID
End Select
pivotGrid.EndUpdate()
pivotGrid.DataBind()
End Sub
Private Sub ConfigureSummaryDisplayTypeComboBox(ByVal typeGroup As SummaryDisplayTypeGroup)
Dim types As List(Of PivotSummaryDisplayType) = New List(Of PivotSummaryDisplayType)()
Select Case typeGroup
Case SummaryDisplayTypeGroup.Variation
types.Add(PivotSummaryDisplayType.AbsoluteVariation)
types.Add(PivotSummaryDisplayType.PercentVariation)
Case SummaryDisplayTypeGroup.Percentage
types.Add(PivotSummaryDisplayType.PercentOfColumn)
types.Add(PivotSummaryDisplayType.PercentOfRow)
types.Add(PivotSummaryDisplayType.PercentOfColumnGrandTotal)
types.Add(PivotSummaryDisplayType.PercentOfRowGrandTotal)
types.Add(PivotSummaryDisplayType.PercentOfGrandTotal)
Case SummaryDisplayTypeGroup.Rank
types.Add(PivotSummaryDisplayType.RankInColumnLargestToSmallest)
types.Add(PivotSummaryDisplayType.RankInColumnSmallestToLargest)
types.Add(PivotSummaryDisplayType.RankInRowLargestToSmallest)
types.Add(PivotSummaryDisplayType.RankInRowSmallestToLargest)
End Select
ddlSummaryDisplayType.Items.Clear()
For Each type As PivotSummaryDisplayType In types
ddlSummaryDisplayType.Items.Add([Enum].GetName(GetType(PivotSummaryDisplayType), type), type)
Next
ddlSummaryDisplayType.SelectedIndex = 0
End Sub
Protected Sub cbShowRawValues_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
If Not Equals(SourceDataFieldName, Nothing) Then
SourceDataField.Visible = cbShowRawValues.Checked
If SourceDataField.Visible Then SourceDataField.AreaIndex = 0
End If
End Sub
Protected Sub cbAllowCrossGroupVariation_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
pivotGrid.OptionsData.AllowCrossGroupVariation = cbAllowCrossGroupVariation.Checked
End Sub
Protected Sub ddlSummaryDisplayType_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
SetSelectedSummaryDisplayType()
End Sub
Private Sub SetSelectedSummaryDisplayType()
If SummaryDisplayTypeDataField Is Nothing Then Return
Dim sourceBinding As DataSourceColumnBinding = New DataSourceColumnBinding(SourceDataFieldName)
Select Case ddlSummaryDisplayType.SelectedItem.Text
Case "AbsoluteVariation"
SummaryDisplayTypeDataField.DataBinding = New DifferenceBinding(sourceBinding, CalculationPartitioningCriteria.RowValue, CalculationDirection.DownThenAcross, DifferenceTarget.Previous, DifferenceType.Absolute)
SummaryDisplayTypeDataField.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
SummaryDisplayTypeDataField.CellFormat.FormatString = "n0"
Case "PercentVariation"
SummaryDisplayTypeDataField.DataBinding = New DifferenceBinding(sourceBinding, CalculationPartitioningCriteria.RowValue, CalculationDirection.DownThenAcross, DifferenceTarget.Previous, DifferenceType.Percentage)
SummaryDisplayTypeDataField.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
SummaryDisplayTypeDataField.CellFormat.FormatString = "p2"
Case "PercentOfColumn"
SummaryDisplayTypeDataField.DataBinding = New PercentOfTotalBinding(sourceBinding, CalculationPartitioningCriteria.ColumnValueAndRowParentValue)
SummaryDisplayTypeDataField.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
SummaryDisplayTypeDataField.CellFormat.FormatString = "p2"
Case "PercentOfRow"
SummaryDisplayTypeDataField.DataBinding = New PercentOfTotalBinding(sourceBinding, CalculationPartitioningCriteria.RowValueAndColumnParentValue)
SummaryDisplayTypeDataField.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
SummaryDisplayTypeDataField.CellFormat.FormatString = "p2"
Case "PercentOfColumnGrandTotal"
SummaryDisplayTypeDataField.DataBinding = New PercentOfTotalBinding(sourceBinding, CalculationPartitioningCriteria.ColumnValue)
SummaryDisplayTypeDataField.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
SummaryDisplayTypeDataField.CellFormat.FormatString = "p2"
Case "PercentOfRowGrandTotal"
SummaryDisplayTypeDataField.DataBinding = New PercentOfTotalBinding(sourceBinding, CalculationPartitioningCriteria.RowValue)
SummaryDisplayTypeDataField.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
SummaryDisplayTypeDataField.CellFormat.FormatString = "p2"
Case "PercentOfGrandTotal"
SummaryDisplayTypeDataField.DataBinding = New PercentOfTotalBinding(sourceBinding, CalculationPartitioningCriteria.None)
SummaryDisplayTypeDataField.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
SummaryDisplayTypeDataField.CellFormat.FormatString = "p2"
Case "RankInColumnLargestToSmallest"
SummaryDisplayTypeDataField.DataBinding = New RankBinding(sourceBinding, CalculationPartitioningCriteria.ColumnValue, RankType.Dense, PivotSortOrder.Descending)
SummaryDisplayTypeDataField.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
SummaryDisplayTypeDataField.CellFormat.FormatString = "n0"
Case "RankInColumnSmallestToLargest"
SummaryDisplayTypeDataField.DataBinding = New RankBinding(sourceBinding, CalculationPartitioningCriteria.ColumnValue, RankType.Dense, PivotSortOrder.Ascending)
SummaryDisplayTypeDataField.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
SummaryDisplayTypeDataField.CellFormat.FormatString = "n0"
Case "RankInRowLargestToSmallest"
SummaryDisplayTypeDataField.DataBinding = New RankBinding(sourceBinding, CalculationPartitioningCriteria.RowValue, RankType.Dense, PivotSortOrder.Descending)
SummaryDisplayTypeDataField.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
SummaryDisplayTypeDataField.CellFormat.FormatString = "n0"
Case "RankInRowSmallestToLargest"
SummaryDisplayTypeDataField.DataBinding = New RankBinding(sourceBinding, CalculationPartitioningCriteria.ColumnValue, RankType.Dense, PivotSortOrder.Ascending)
SummaryDisplayTypeDataField.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
SummaryDisplayTypeDataField.CellFormat.FormatString = "n0"
End Select
SummaryDisplayTypeDataField.Caption = String.Format("{0}", ddlSummaryDisplayType.SelectedItem.Text)
End Sub
End Class
End Namespace