Click here to Skip to main content
15,886,851 members
Articles / Containers / Virtual Machine

ASP.NET Report Kit Grasshoper (Race to Linux)

Rate me:
Please Sign up or sign in to vote.
2.38/5 (5 votes)
2 Oct 20057 min read 37.9K   19  
Porting and deploying the report starter kit to Linux (RH7.3/Tomcat5.0.28/Grasshoper1.61)
<html><head><link rel=stylesheet href=style.css></head><body><div class=SourcePanel style='font-size:12'><pre style='background-color:white'>
<font color= "blue">Imports</font> System
<font color= "blue">Imports</font> System.Web.UI.WebControls
<font color= "blue">Imports</font> ASPNET.StarterKit.Reports.Components
<font color= "blue"></font>
<font color= "blue">Namespace</font> ASPNET.StarterKit.Reports
<font color= "blue"></font>
<font color= "green">    '********************************************************************************</font>
<font color= "green">    '</font>
<font color= "green">    ' MasterDetail.aspx</font>
<font color= "green">    '</font>
<font color= "green">    ' The MasterDetail.aspx page shows a basic way to filter and group related data (in</font>
<font color= "green">    ' chis case, filtering by year, and grouping by quarters).  This is accomplished by</font>
<font color= "green">    ' showing two different datagrids, each bound by separate stored procedures.</font>
<font color= "green">    '</font>
<font color= "green">    '********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">    Public Class</font> MasterDetail
<font color= "blue">        Inherits</font> System.Web.UI.Page
<font color= "blue">        Protected </font>WithEvents <font color= "blue"></font>YearDropDownList As System.Web.UI.WebControls.DropDownList
<font color= "blue">        Protected </font>WithEvents <font color= "blue"></font>QuarterDropDownList As System.Web.UI.WebControls.DropDownList
<font color= "blue">        Protected </font>WithEvents <font color= "blue"></font>SummaryDataGrid As System.Web.UI.WebControls.DataGrid
<font color= "blue">        Protected </font>DetailsDataGrid <font color= "blue">As </font>System.Web.UI.WebControls.DataGrid
<font color= "blue">        Protected </font>SummaryLabel <font color= "blue">As </font>System.Web.UI.WebControls.Label
<font color= "blue">        Protected </font>DetailsLabel <font color= "blue">As </font>System.Web.UI.WebControls.Label
<font color= "blue"></font>
<font color= "blue">        Private </font>_salesTotal <font color= "blue">As </font>Double
<font color= "blue">        Protected </font>_styleSheet <font color= "blue">As </font>String
<font color= "blue"></font>
<font color= "blue">        Private Const </font>_masterDetailYear <font color= "blue">As </font>String = "master_detail_year"
<font color= "blue">        Private Const </font>_masterDetailQuarter <font color= "blue">As </font>String = "master_detail_quarter"
<font color= "blue">        Protected </font>PrintButton <font color= "blue">As </font>System.Web.UI.WebControls.HyperLink
<font color= "blue"></font>
<font color= "blue"></font>#Region " Web Form Designer Generated Code "
<font color= "blue"></font>
<font color= "green">        'This call is required by the Web Form Designer.</font>
<font color= "blue">        </font><System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
<font color= "blue"></font>
<font color= "blue">        End Sub</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
<font color= "green">            'CODEGEN: This method call is required by the Web Form Designer</font>
<font color= "green">            'Do not modify it using the code editor.</font>
<font color= "blue">            </font>InitializeComponent()
<font color= "blue">        End Sub</font>
<font color= "blue"></font>
<font color= "blue"></font>#End Region
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
<font color= "blue">            </font>_salesTotal <font color= "blue"></font>= 0
<font color= "blue"></font><font color= "blue">            If </font>Not IsPostBack <font color= "blue">Then</font>
<font color= "blue"></font><font color= "blue">                If </font>Not (YearDropDownList.Items.FindByValue(Convert.ToString(Session(_masterDetailYear))) Is Nothing) <font color= "blue">Then</font>
<font color= "blue">                    </font>YearDropDownList.Items.FindByValue(Convert.ToString(Session(_masterDetailYear))).Selected = True
<font color= "blue"></font><font color= "blue">                End If</font><font color= "blue"></font>
<font color= "blue"></font><font color= "blue">                If </font>Not (QuarterDropDownList.Items.FindByValue(Convert.ToString(Session(_masterDetailQuarter))) Is Nothing) <font color= "blue">Then</font>
<font color= "blue">                    </font>QuarterDropDownList.Items.FindByValue(Convert.ToString(Session(_masterDetailQuarter))).Selected = True
<font color= "blue"></font><font color= "blue">                End If</font><font color= "blue"></font>
<font color= "blue">                </font>BindSummary()
<font color= "blue">                </font>BindDetails()
<font color= "blue"></font><font color= "blue">            End If</font><font color= "blue"></font>
<font color= "blue"></font>
<font color= "green">            ' switches the style sheet based on printer friendly view or not</font>
<font color= "blue"></font><font color= "blue">            If </font>Request.QueryString("Print") = "true" <font color= "blue">Then</font>
<font color= "blue">                </font>_styleSheet <font color= "blue"></font>= "stylesPrint.css"
<font color= "blue">                </font>PrintButton.Visible = True
<font color= "blue"></font><font color= "blue">            Else</font><font color= "blue"></font>
<font color= "blue">                </font>_styleSheet <font color= "blue"></font>= "styles.css"
<font color= "blue"></font><font color= "blue">            End If</font><font color= "blue"></font>
<font color= "blue">        End Sub</font><font color= "green"> 'Page_Load</font>
<font color= "blue"></font>
<font color= "blue"></font>
<font color= "green">        '********************************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' The BindSummary method retrieves the OrderSummary for a given year, and</font>
<font color= "green">        ' then databinds the results to the SummaryDataGrid.</font>
<font color= "green">        '</font>
<font color= "green">        '********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> BindSummary()
<font color= "blue">            </font>SummaryLabel.Text = YearDropDownList.SelectedItem.Text + " Summary"
<font color= "blue">            </font>SummaryDataGrid.DataSource = GetSales(Convert.ToInt32(YearDropDownList.SelectedItem.Value))
<font color= "blue">            </font>SummaryDataGrid.DataBind()
<font color= "blue">        End Sub</font><font color= "green"> 'BindSummary</font>
<font color= "blue"></font>
<font color= "blue"></font>
<font color= "green">        '********************************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' The BindDetails method retrieves the OrderDetails for a given year and quarter, and</font>
<font color= "green">        ' then databinds the results to the DetailsDataGrid.</font>
<font color= "green">        '</font>
<font color= "green">        '********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> BindDetails()
<font color= "blue">            </font>DetailsLabel.Text = YearDropDownList.SelectedItem.Text
<font color= "blue"></font><font color= "blue">            If </font>QuarterDropDownList.SelectedItem.Value = "0" <font color= "blue">Then</font>
<font color= "blue">                </font>DetailsLabel.Text += " (All Quarters) Details"
<font color= "blue"></font><font color= "blue">            Else</font><font color= "blue"></font>
<font color= "blue">                </font>DetailsLabel.Text += " (Quarter " + QuarterDropDownList.SelectedItem.Text + ") Details"
<font color= "blue"></font><font color= "blue">            End If</font><font color= "blue"></font>
<font color= "blue">            </font>DetailsDataGrid.DataSource = GetSalesDetails(Convert.ToInt32(YearDropDownList.SelectedItem.Value), Convert.ToInt32(QuarterDropDownList.SelectedItem.Value))
<font color= "blue">            </font>DetailsDataGrid.DataBind()
<font color= "blue">        End Sub</font><font color= "green"> 'BindDetails</font>
<font color= "blue"></font>
<font color= "green">        '********************************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' The GetSales uses the MasterDetail BLL component to query the database to retrieve</font>
<font color= "green">        ' the summary of sales for a given year.</font>
<font color= "green">        '</font>
<font color= "green">        '********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Protected Function</font> GetSales(ByVal year As Integer) As MasterDetailReportCollection
<font color= "blue">            </font>Return <font color= "blue"></font>MasterDetailReport.GetSummary(year)
<font color= "blue"></font><font color= "blue">        End Function</font><font color= "blue"></font><font color= "green"> 'GetSales</font>
<font color= "blue"></font>
<font color= "green">        '********************************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' The GetSalesDetails uses the MasterDetail BLL component to query the database to</font>
<font color= "green">        ' retrieve the details of sales for a given year and quarter.</font>
<font color= "green">        '</font>
<font color= "green">        '********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Protected Function</font> GetSalesDetails(ByVal year As Integer, ByVal quarter As Integer) As MasterDetailReportCollection
<font color= "blue">            </font>Return <font color= "blue"></font>MasterDetailReport.GetDetails(year, quarter)
<font color= "blue"></font><font color= "blue">        End Function</font><font color= "blue"></font><font color= "green"> 'GetSalesDetails</font>
<font color= "blue"></font>
<font color= "green">        '********************************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' DropDownList event handlers for the Year and Quarter DropDownLists.  They make</font>
<font color= "green">        ' calls to rebind the DetailsDataGrid (and if applicable) the SummaryDataGrid.</font>
<font color= "green">        '</font>
<font color= "green">        '********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> YearDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles YearDropDownList.SelectedIndexChanged
<font color= "blue">            </font>Session(_masterDetailYear) = YearDropDownList.SelectedItem.Value
<font color= "blue">            </font>BindSummary()
<font color= "blue">            </font>BindDetails()
<font color= "blue">        End Sub</font><font color= "green"> 'YearDropDownList_SelectedIndexChanged</font>
<font color= "blue"></font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> QuarterDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles QuarterDropDownList.SelectedIndexChanged
<font color= "blue">            </font>Session(_masterDetailQuarter) = QuarterDropDownList.SelectedItem.Value
<font color= "blue">            </font>BindDetails()
<font color= "blue">        End Sub</font><font color= "green"> 'QuarterDropDownList_SelectedIndexChanged</font>
<font color= "blue"></font>
<font color= "green">        '********************************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' The SumItems event handler is called after the masterDataGrid has been databound.</font>
<font color= "green">        ' It iterates thru the list to calculate the sum of sales, and then adds the</font>
<font color= "green">        ' results (as HTML) to the datagrid table.</font>
<font color= "green">        '</font>
<font color= "green">        '********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> SumItems(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles SummaryDataGrid.ItemDataBound
<font color= "blue"></font><font color= "blue">            If </font>e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem <font color= "blue">Then</font>
<font color= "blue">                </font>CalcTotal(e.Item.Cells(2).Text)
<font color= "blue">                </font>e.Item.Cells(2).Text = String.Format("{0:c}", Convert.ToDouble(e.Item.Cells(2).Text))
<font color= "blue"></font><font color= "blue">            Else</font><font color= "blue"></font>
<font color= "blue"></font><font color= "blue">                If </font>e.Item.ItemType = ListItemType.Footer <font color= "blue">Then</font>
<font color= "blue">                    </font>e.Item.Cells(0).Text = "Sales Total"
<font color= "blue">                    </font>e.Item.Cells(2).Text = String.Format("{0:c}", _salesTotal)
<font color= "blue"></font><font color= "blue">                End If</font><font color= "blue"></font>
<font color= "blue"></font><font color= "blue">            End If</font><font color= "blue"></font>
<font color= "blue">        End Sub</font><font color= "green"> 'SumItems</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> CalcTotal(ByVal _price As String)
<font color= "blue">            </font>_salesTotal <font color= "blue"></font>+= [Double].Parse(_price)
<font color= "blue">        End Sub</font><font color= "green"> 'CalcTotal</font>
<font color= "blue"></font><font color= "blue">    End Class</font><font color= "blue"></font><font color= "green"> 'MasterDetail</font>
<font color= "blue"></font><font color= "blue">End Namespace</font><font color= "blue"></font><font color= "green"> 'ASPNET.StarterKit.Reports</font>
<font color= "blue"></font>
</pre>

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.

License

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


Written By
Software Developer (Senior)
United States United States
I love to code! Working in C# is my passion, visit my github

Comments and Discussions