Click here to Skip to main content
15,884,472 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> System.Text
<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= "blue">    Public Class</font> Visual
<font color= "blue">        Inherits</font> System.Web.UI.Page
<font color= "blue">        Protected </font>WithEvents <font color= "blue"></font>drpChartType As System.Web.UI.WebControls.DropDownList
<font color= "blue">        Protected </font>SalesByCategoryGrid <font color= "blue">As </font>System.Web.UI.WebControls.DataGrid
<font color= "blue">        Protected </font>ChartImage <font color= "blue">As </font>System.Web.UI.WebControls.Image
<font color= "blue">        Protected </font>PrintButton <font color= "blue">As </font>System.Web.UI.WebControls.HyperLink
<font color= "blue">        Protected </font>printVersion <font color= "blue">As </font>Boolean
<font color= "blue">        Protected </font>_styleSheet <font color= "blue">As </font>String
<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= "green">        '*********************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' Visual.aspx</font>
<font color= "green">        '</font>
<font color= "green">        ' The Visual.aspx page shows Sales by Category in three different views: </font>
<font color= "green">        ' Pie Chart, Bar Graph, and Tabular view.</font>
<font color= "green">        '</font>
<font color= "green">        '*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
<font color= "blue">            </font>printVersion <font color= "blue"></font>= Request.QueryString("Print") = "true"
<font color= "blue"></font>
<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 (Session("ViewSelectIndex") Is Nothing) <font color= "blue">Then</font>
<font color= "blue">                    </font>drpChartType.SelectedIndex = CInt(Session("ViewSelectIndex"))
<font color= "blue"></font><font color= "blue">                End If</font><font color= "blue"></font>
<font color= "green">                ' call event to display default view</font>
<font color= "blue">                </font>drpChartType_SelectedIndexChanged(Me, New System.EventArgs())
<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>printVersion <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= "green">        '*********************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' The BindGrid method retrieves the list of sales by category</font>
<font color= "green">        ' and then databinds them to the SalesByCategoryGrid</font>
<font color= "green">        '</font>
<font color= "green">        '*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> BindGrid(ByVal data As VisualReportCollection)
<font color= "blue">            </font>SalesByCategoryGrid.Visible = True
<font color= "blue">            </font>SalesByCategoryGrid.DataSource = data
<font color= "blue">            </font>SalesByCategoryGrid.DataBind()
<font color= "blue">        End Sub</font><font color= "green"> 'BindGrid</font>
<font color= "blue"></font>
<font color= "green">        '*********************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' The drpChartType_SelectedIndexChanged event handler gets the sales data and changes the view.</font>
<font color= "green">        '</font>
<font color= "green">        '*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> drpChartType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles drpChartType.SelectedIndexChanged
<font color= "green">            ' retrieve the sales data </font>
<font color= "blue">            Dim </font>visualReportObj <font color= "blue">As </font>VisualReportCollection = VisualReport.GetCategorySales()
<font color= "blue"></font>
<font color= "blue"></font><font color= "blue">            If </font>drpChartType.SelectedItem.Value <> "Table" <font color= "blue">Then</font>
<font color= "blue">                Dim </font>xValues <font color= "blue">As </font>New StringBuilder()
<font color= "blue">                Dim </font>yValues <font color= "blue">As </font>New StringBuilder()
<font color= "blue">                Dim </font>rowCount <font color= "blue">As </font>Integer = visualReportObj.Count
<font color= "blue">                Dim </font>i <font color= "blue">As </font>Integer = 1
<font color= "blue"></font>
<font color= "green">                ' convert data to comma delimited stringbuilders</font>
<font color= "blue">                Dim </font>dr <font color= "blue">As </font>VisualReport
<font color= "blue">                For Each</font> dr In visualReportObj
<font color= "blue">                    </font>xValues.Append(dr.CategoryName)
<font color= "blue">                    </font>yValues.Append(dr.Sales)
<font color= "blue"></font><font color= "blue">                    If </font>i < rowCount <font color= "blue">Then</font>
<font color= "blue">                        </font>xValues.Append("|")
<font color= "blue">                        </font>yValues.Append("|")
<font color= "blue"></font><font color= "blue">                    End If</font><font color= "blue"></font>
<font color= "blue">                    </font>i <font color= "blue"></font>+= 1
<font color= "blue">                Next</font> dr
<font color= "blue"></font>
<font color= "green">                ' attach image generator to image</font>
<font color= "blue">                </font>ChartImage.ImageUrl = "ChartGenerator.aspx?" + "xValues=" + xValues.ToString() + "&yValues=" + yValues.ToString() + "&ChartType=" + drpChartType.SelectedItem.Value.ToLower() + "&Print=" + printVersion.ToString()
<font color= "blue"></font>
<font color= "blue">                </font>ChartImage.Visible = True
<font color= "blue">                </font>SalesByCategoryGrid.Visible = False
<font color= "blue"></font><font color= "blue">            Else</font><font color= "blue"></font>
<font color= "blue">                </font>BindGrid(visualReportObj)
<font color= "blue">                </font>ChartImage.Visible = False
<font color= "blue"></font><font color= "blue">            End If</font><font color= "blue"></font>
<font color= "blue"></font>
<font color= "blue">            </font>Session("ViewSelectIndex") = drpChartType.SelectedIndex
<font color= "blue">        End Sub</font><font color= "green"> 'drpChartType_SelectedIndexChanged</font>
<font color= "blue"></font><font color= "blue">    End Class</font><font color= "blue"></font><font color= "green"> 'Visual</font>
<font color= "blue"></font><font color= "blue">End Namespace</font><font color= "blue"></font><font color= "green"> 'ASPNET.StarterKit.Reports</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