Click here to Skip to main content
15,886,067 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">    ' SimpleReport.aspx</font>
<font color= "green">    '</font>
<font color= "green">    ' This report lists all customer contacts information from the database</font>
<font color= "green">    ' in a DataGrid control</font>
<font color= "green">    '</font>
<font color= "green">    '*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">    Public Class</font> Simple
<font color= "blue">        Inherits</font> System.Web.UI.Page
<font color= "blue">        Protected </font>WithEvents <font color= "blue"></font>CustomerGrid As System.Web.UI.WebControls.DataGrid
<font color= "blue">        Protected </font>PrintButton <font color= "blue">As </font>System.Web.UI.WebControls.HyperLink
<font color= "blue">        Protected </font>WithEvents <font color= "blue"></font>PagingButton As System.Web.UI.WebControls.LinkButton
<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= "blue">        Private Sub</font> Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
<font color= "blue"></font><font color= "blue">            If </font>Not IsPostBack <font color= "blue">Then</font>
<font color= "blue">                </font>BindGrid()
<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>PagingButton.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 a collection of simple report items</font>
<font color= "green">        ' and databinds it to the CustomerGrid</font>
<font color= "green">        '</font>
<font color= "green">        '*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> BindGrid()
<font color= "blue">            Dim </font>customerList <font color= "blue">As </font>SimpleReportCollection = SimpleReport.GetCustomerContacts()
<font color= "blue">            </font>SortGridData(customerList, SortField, SortAscending)
<font color= "blue">            </font>CustomerGrid.DataSource = customerList
<font color= "blue">            </font>CustomerGrid.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 SortGrid event handler changes the sortfield for the Customer grid </font>
<font color= "green">        ' and re-binds it.</font>
<font color= "green">        '</font>
<font color= "green">        '*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> CustomerGrid_Sort(ByVal [source] As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles CustomerGrid.SortCommand
<font color= "green">            ' change sort field</font>
<font color= "blue">            </font>SortField <font color= "blue"></font>= CStr(e.SortExpression)
<font color= "blue"></font>
<font color= "green">            ' re-bind to display new sorting</font>
<font color= "blue">            </font>BindGrid()
<font color= "blue">        End Sub</font><font color= "green"> 'CustomerGrid_Sort</font>
<font color= "blue"></font>
<font color= "green">        '*******************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' SortGridData methods sorts the datagrid based on which</font>
<font color= "green">        ' sort field is being selected.  Also does reverse sorting based on the boolean.</font>
<font color= "green">        '</font>
<font color= "green">        '*******************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> SortGridData(ByVal list As SimpleReportCollection, ByVal sortField As String, ByVal asc As Boolean)
<font color= "blue">            Dim </font>sortCol <font color= "blue">As </font>SimpleReportCollection.SimpleReportFields = SimpleReportCollection.SimpleReportFields.InitValue
<font color= "blue"></font>
<font color= "blue">            Select Case</font> sortField
<font color= "blue">                Case</font> "City"
<font color= "blue">                    </font>sortCol <font color= "blue"></font>= SimpleReportCollection.SimpleReportFields.City
<font color= "blue">                Case</font> "CompanyName"
<font color= "blue">                    </font>sortCol <font color= "blue"></font>= SimpleReportCollection.SimpleReportFields.CompanyName
<font color= "blue">                Case</font> "ContactName"
<font color= "blue">                    </font>sortCol <font color= "blue"></font>= SimpleReportCollection.SimpleReportFields.ContactName
<font color= "blue">                Case</font> "ContactTitle"
<font color= "blue">                    </font>sortCol <font color= "blue"></font>= SimpleReportCollection.SimpleReportFields.ContactTitle
<font color= "blue">                Case</font> "Phone"
<font color= "blue">                    </font>sortCol <font color= "blue"></font>= SimpleReportCollection.SimpleReportFields.Phone
<font color= "blue">            End Select</font>
<font color= "blue"></font>
<font color= "blue">            </font>list.Sort(sortCol, asc)
<font color= "blue">        End Sub</font><font color= "green"> 'SortGridData</font>
<font color= "blue"></font>
<font color= "green">        '*******************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' CustomerGrid_PageIndexChanged server event handler on this page is used</font>
<font color= "green">        ' for changing page index</font>
<font color= "green">        '</font>
<font color= "green">        '*******************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> CustomerGrid_PageIndexChanged(ByVal [source] As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles CustomerGrid.PageIndexChanged
<font color= "blue">            </font>CustomerGrid.CurrentPageIndex = e.NewPageIndex
<font color= "blue">            </font>BindGrid()
<font color= "blue">        End Sub</font><font color= "green"> 'CustomerGrid_PageIndexChanged</font>
<font color= "blue"></font>
<font color= "green">        '*******************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' PagingButton_Click server event handler on this page is used</font>
<font color= "green">        ' for changing paging property on CustomerGrid</font>
<font color= "green">        '</font>
<font color= "green">        '*******************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> PagingButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PagingButton.Click
<font color= "blue">            </font>CustomerGrid.AllowPaging = Not (CustomerGrid.AllowPaging)
<font color= "blue">            </font>BindGrid()
<font color= "blue"></font>
<font color= "blue">            </font>PagingButton.Text = IIf(CustomerGrid.AllowPaging, "Disable Paging", "Enable Paging")
<font color= "blue">        End Sub</font><font color= "green"> 'PagingButton_Click</font>
<font color= "blue"></font>
<font color= "blue">        Property</font> SortField() As String
<font color= "blue">            Get</font>
<font color= "blue">                Dim </font>o <font color= "blue">As </font>Object = ViewState("SortField")
<font color= "blue"></font><font color= "blue">                If </font>o Is Nothing <font color= "blue">Then</font>
<font color= "blue">                    </font>Return <font color= "blue"></font>[String].Empty
<font color= "blue"></font><font color= "blue">                End If</font><font color= "blue"></font>
<font color= "blue">                </font>Return <font color= "blue"></font>CStr(o)
<font color= "blue">            End Get</font>
<font color= "blue">            </font>Set(ByVal Value As String)
<font color= "blue"></font><font color= "blue">                If </font>Value = SortField <font color= "blue">Then</font>
<font color= "green">                    ' same as current sort file, toggle sort direction</font>
<font color= "blue">                    </font>SortAscending <font color= "blue"></font>= Not SortAscending
<font color= "blue"></font><font color= "blue">                End If</font><font color= "blue"></font>
<font color= "blue">                </font>ViewState("SortField") = Value
<font color= "blue">            End Set</font>
<font color= "blue">        End Property</font>
<font color= "blue"></font>
<font color= "green">        '*********************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' SortAscending property is tracked in ViewState</font>
<font color= "green">        '</font>
<font color= "green">        '*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Property</font> SortAscending() As Boolean
<font color= "blue">            Get</font>
<font color= "blue">                Dim </font>o <font color= "blue">As </font>Object = ViewState("SortAscending")
<font color= "blue"></font>
<font color= "blue"></font><font color= "blue">                If </font>o Is Nothing <font color= "blue">Then</font>
<font color= "blue">                    </font>Return <font color= "blue"></font>True
<font color= "blue"></font><font color= "blue">                End If</font><font color= "blue"></font>
<font color= "blue">                </font>Return <font color= "blue"></font>CBool(o)
<font color= "blue">            End Get</font>
<font color= "blue">            </font>Set(ByVal Value As Boolean)
<font color= "blue">                </font>ViewState("SortAscending") = Value
<font color= "blue">            End Set</font>
<font color= "blue">        End Property</font>
<font color= "blue"></font>
<font color= "blue"></font><font color= "blue">    End Class</font><font color= "blue"></font><font color= "green"> 'Simple </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