|
Imports System
Imports System.Web.UI.WebControls
Imports ASPNET.StarterKit.Reports.Components
Namespace ASPNET.StarterKit.Reports
'*********************************************************************
'
' CrossTab.aspx
'
' The CrossTab.aspx page shows quarterly breakdown of sales based on the region.
' It also displays the totals for each region, the totals for each month within the quarter,
' and the total for the whole quarter.
'
'*********************************************************************
Public Class CrossTab
Inherits System.Web.UI.Page
Protected PrintButton As System.Web.UI.WebControls.HyperLink
Protected QuartersList As System.Web.UI.WebControls.DataList
Protected WithEvents YearDropDownList As System.Web.UI.WebControls.DropDownList
Private _eastern As Double = 0
Private _western As Double = 0
Private _southern As Double = 0
Private _northern As Double = 0
Private _totals As Double = 0
Protected _styleSheet As String
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
BindList()
End If
' switches the style sheet based on printer friendly view or not
If Request.QueryString("Print") = "true" Then
_styleSheet = "stylesPrint.css"
PrintButton.Visible = True
Else
_styleSheet = "styles.css"
End If
End Sub 'Page_Load
'*********************************************************************
'
' The BindList method simply binds the Datalist with the four quarters
'
'*********************************************************************
Private Sub BindList()
QuartersList.DataSource = New Integer(3) {1, 2, 3, 4}
QuartersList.DataBind()
End Sub 'BindList
'*********************************************************************
'
' The GetQuarterDetails method is set as the DataSource of the inner datagrid.
' As the QuartsList is being data-bound, this populates the inner datagrids for the quarters.
'
'*********************************************************************
Protected Function GetQuarterDetails(ByVal quarter As Integer) As CrossTabReportCollection
Return CrossTabReport.GetRegionSales(quarter, Convert.ToInt32(YearDropDownList.SelectedItem.Value))
End Function 'GetQuarterDetails
'*********************************************************************
'
' The SumItems event handler is for the OnItemDataBound event of the datagrids for each quarter.
' It adds running totals for each region for a particular quarter.
' It also adds the sum totals fo the regions of the quarter as well.
'
'*********************************************************************
Protected Sub SumItems(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
' sum up the data in the columns as the datagrid is databinding
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
' get the sales value for eastern region
Dim eastern As Double = Convert.ToDouble(e.Item.Cells(1).Text)
' add sales value to the running total
_eastern += eastern
' format to display sales value as currency
e.Item.Cells(1).Text = String.Format("{0:c}", eastern)
Dim western As Double = Convert.ToDouble(e.Item.Cells(2).Text)
_western += western
e.Item.Cells(2).Text = String.Format("{0:c}", western)
Dim southern As Double = Convert.ToDouble(e.Item.Cells(3).Text)
_southern += southern
e.Item.Cells(3).Text = String.Format("{0:c}", southern)
Dim northern As Double = Convert.ToDouble(e.Item.Cells(4).Text)
_northern += northern
e.Item.Cells(4).Text = String.Format("{0:c}", northern)
Dim totals As Double = Convert.ToDouble(e.Item.Cells(5).Text)
_totals += totals
e.Item.Cells(5).Text = String.Format("{0:c}", totals)
Else
If e.Item.ItemType = ListItemType.Footer Then
' display our summations in footer
e.Item.Cells(0).Text = "Totals"
e.Item.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Item.Cells(1).Text = String.Format("{0:c}", _eastern)
e.Item.Cells(2).Text = String.Format("{0:c}", _western)
e.Item.Cells(3).Text = String.Format("{0:c}", _southern)
e.Item.Cells(4).Text = String.Format("{0:c}", _northern)
e.Item.Cells(5).Text = String.Format("{0:c}", _totals)
' reset the running totals for next datagrid
_eastern = 0
_western = 0
_southern = 0
_northern = 0
_totals = 0
End If
End If
End Sub 'SumItems
Private Sub YearDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles YearDropDownList.SelectedIndexChanged
BindList()
End Sub 'YearDropDownList_SelectedIndexChanged
End Class 'CrossTab
End Namespace 'ASPNET.StarterKit.Reports
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here