|
Imports System
Imports System.Web.UI.WebControls
Imports ASPNET.StarterKit.Reports.Components
Namespace ASPNET.StarterKit.Reports
'********************************************************************************
'
' MasterDetail.aspx
'
' The MasterDetail.aspx page shows a basic way to filter and group related data (in
' chis case, filtering by year, and grouping by quarters). This is accomplished by
' showing two different datagrids, each bound by separate stored procedures.
'
'********************************************************************************
Public Class MasterDetail
Inherits System.Web.UI.Page
Protected WithEvents YearDropDownList As System.Web.UI.WebControls.DropDownList
Protected WithEvents QuarterDropDownList As System.Web.UI.WebControls.DropDownList
Protected WithEvents SummaryDataGrid As System.Web.UI.WebControls.DataGrid
Protected DetailsDataGrid As System.Web.UI.WebControls.DataGrid
Protected SummaryLabel As System.Web.UI.WebControls.Label
Protected DetailsLabel As System.Web.UI.WebControls.Label
Private _salesTotal As Double
Protected _styleSheet As String
Private Const _masterDetailYear As String = "master_detail_year"
Private Const _masterDetailQuarter As String = "master_detail_quarter"
Protected PrintButton As System.Web.UI.WebControls.HyperLink
#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
_salesTotal = 0
If Not IsPostBack Then
If Not (YearDropDownList.Items.FindByValue(Convert.ToString(Session(_masterDetailYear))) Is Nothing) Then
YearDropDownList.Items.FindByValue(Convert.ToString(Session(_masterDetailYear))).Selected = True
End If
If Not (QuarterDropDownList.Items.FindByValue(Convert.ToString(Session(_masterDetailQuarter))) Is Nothing) Then
QuarterDropDownList.Items.FindByValue(Convert.ToString(Session(_masterDetailQuarter))).Selected = True
End If
BindSummary()
BindDetails()
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 BindSummary method retrieves the OrderSummary for a given year, and
' then databinds the results to the SummaryDataGrid.
'
'********************************************************************************
Private Sub BindSummary()
SummaryLabel.Text = YearDropDownList.SelectedItem.Text + " Summary"
SummaryDataGrid.DataSource = GetSales(Convert.ToInt32(YearDropDownList.SelectedItem.Value))
SummaryDataGrid.DataBind()
End Sub 'BindSummary
'********************************************************************************
'
' The BindDetails method retrieves the OrderDetails for a given year and quarter, and
' then databinds the results to the DetailsDataGrid.
'
'********************************************************************************
Private Sub BindDetails()
DetailsLabel.Text = YearDropDownList.SelectedItem.Text
If QuarterDropDownList.SelectedItem.Value = "0" Then
DetailsLabel.Text += " (All Quarters) Details"
Else
DetailsLabel.Text += " (Quarter " + QuarterDropDownList.SelectedItem.Text + ") Details"
End If
DetailsDataGrid.DataSource = GetSalesDetails(Convert.ToInt32(YearDropDownList.SelectedItem.Value), Convert.ToInt32(QuarterDropDownList.SelectedItem.Value))
DetailsDataGrid.DataBind()
End Sub 'BindDetails
'********************************************************************************
'
' The GetSales uses the MasterDetail BLL component to query the database to retrieve
' the summary of sales for a given year.
'
'********************************************************************************
Protected Function GetSales(ByVal year As Integer) As MasterDetailReportCollection
Return MasterDetailReport.GetSummary(year)
End Function 'GetSales
'********************************************************************************
'
' The GetSalesDetails uses the MasterDetail BLL component to query the database to
' retrieve the details of sales for a given year and quarter.
'
'********************************************************************************
Protected Function GetSalesDetails(ByVal year As Integer, ByVal quarter As Integer) As MasterDetailReportCollection
Return MasterDetailReport.GetDetails(year, quarter)
End Function 'GetSalesDetails
'********************************************************************************
'
' DropDownList event handlers for the Year and Quarter DropDownLists. They make
' calls to rebind the DetailsDataGrid (and if applicable) the SummaryDataGrid.
'
'********************************************************************************
Private Sub YearDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles YearDropDownList.SelectedIndexChanged
Session(_masterDetailYear) = YearDropDownList.SelectedItem.Value
BindSummary()
BindDetails()
End Sub 'YearDropDownList_SelectedIndexChanged
Private Sub QuarterDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles QuarterDropDownList.SelectedIndexChanged
Session(_masterDetailQuarter) = QuarterDropDownList.SelectedItem.Value
BindDetails()
End Sub 'QuarterDropDownList_SelectedIndexChanged
'********************************************************************************
'
' The SumItems event handler is called after the masterDataGrid has been databound.
' It iterates thru the list to calculate the sum of sales, and then adds the
' results (as HTML) to the datagrid table.
'
'********************************************************************************
Private Sub SumItems(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles SummaryDataGrid.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
CalcTotal(e.Item.Cells(2).Text)
e.Item.Cells(2).Text = String.Format("{0:c}", Convert.ToDouble(e.Item.Cells(2).Text))
Else
If e.Item.ItemType = ListItemType.Footer Then
e.Item.Cells(0).Text = "Sales Total"
e.Item.Cells(2).Text = String.Format("{0:c}", _salesTotal)
End If
End If
End Sub 'SumItems
Private Sub CalcTotal(ByVal _price As String)
_salesTotal += [Double].Parse(_price)
End Sub 'CalcTotal
End Class 'MasterDetail
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