Click here to Skip to main content
15,896,278 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 38K   19  
Porting and deploying the report starter kit to Linux (RH7.3/Tomcat5.0.28/Grasshoper1.61)
Imports System
Imports System.Web.UI.WebControls
Imports ASPNET.StarterKit.Reports.Components

Namespace ASPNET.StarterKit.Reports

    '*********************************************************************
    '
    ' SimpleReport.aspx
    '
    ' This report lists all customer contacts information from the database
    ' in a DataGrid control
    '
    '*********************************************************************

    Public Class Simple
        Inherits System.Web.UI.Page
        Protected WithEvents CustomerGrid As System.Web.UI.WebControls.DataGrid
        Protected PrintButton As System.Web.UI.WebControls.HyperLink
        Protected WithEvents PagingButton As System.Web.UI.WebControls.LinkButton
        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
                BindGrid()
            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
                PagingButton.Visible = True
            Else
                _styleSheet = "styles.css"
            End If
        End Sub 'Page_Load

        '*********************************************************************
        '
        ' The BindGrid method retrieves a collection of simple report items
        ' and databinds it to the CustomerGrid
        '
        '*********************************************************************

        Private Sub BindGrid()
            Dim customerList As SimpleReportCollection = SimpleReport.GetCustomerContacts()
            SortGridData(customerList, SortField, SortAscending)
            CustomerGrid.DataSource = customerList
            CustomerGrid.DataBind()
        End Sub 'BindGrid

        '*********************************************************************
        '
        ' The SortGrid event handler changes the sortfield for the Customer grid 
        ' and re-binds it.
        '
        '*********************************************************************

        Private Sub CustomerGrid_Sort(ByVal [source] As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles CustomerGrid.SortCommand
            ' change sort field
            SortField = CStr(e.SortExpression)

            ' re-bind to display new sorting
            BindGrid()
        End Sub 'CustomerGrid_Sort

        '*******************************************************
        '
        ' SortGridData methods sorts the datagrid based on which
        ' sort field is being selected.  Also does reverse sorting based on the boolean.
        '
        '*******************************************************

        Private Sub SortGridData(ByVal list As SimpleReportCollection, ByVal sortField As String, ByVal asc As Boolean)
            Dim sortCol As SimpleReportCollection.SimpleReportFields = SimpleReportCollection.SimpleReportFields.InitValue

            Select Case sortField
                Case "City"
                    sortCol = SimpleReportCollection.SimpleReportFields.City
                Case "CompanyName"
                    sortCol = SimpleReportCollection.SimpleReportFields.CompanyName
                Case "ContactName"
                    sortCol = SimpleReportCollection.SimpleReportFields.ContactName
                Case "ContactTitle"
                    sortCol = SimpleReportCollection.SimpleReportFields.ContactTitle
                Case "Phone"
                    sortCol = SimpleReportCollection.SimpleReportFields.Phone
            End Select

            list.Sort(sortCol, asc)
        End Sub 'SortGridData

        '*******************************************************
        '
        ' CustomerGrid_PageIndexChanged server event handler on this page is used
        ' for changing page index
        '
        '*******************************************************

        Private Sub CustomerGrid_PageIndexChanged(ByVal [source] As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles CustomerGrid.PageIndexChanged
            CustomerGrid.CurrentPageIndex = e.NewPageIndex
            BindGrid()
        End Sub 'CustomerGrid_PageIndexChanged

        '*******************************************************
        '
        ' PagingButton_Click server event handler on this page is used
        ' for changing paging property on CustomerGrid
        '
        '*******************************************************

        Private Sub PagingButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PagingButton.Click
            CustomerGrid.AllowPaging = Not (CustomerGrid.AllowPaging)
            BindGrid()

            PagingButton.Text = IIf(CustomerGrid.AllowPaging, "Disable Paging", "Enable Paging")
        End Sub 'PagingButton_Click

        Property SortField() As String
            Get
                Dim o As Object = ViewState("SortField")
                If o Is Nothing Then
                    Return [String].Empty
                End If
                Return CStr(o)
            End Get
            Set(ByVal Value As String)
                If Value = SortField Then
                    ' same as current sort file, toggle sort direction
                    SortAscending = Not SortAscending
                End If
                ViewState("SortField") = Value
            End Set
        End Property

        '*********************************************************************
        '
        ' SortAscending property is tracked in ViewState
        '
        '*********************************************************************

        Property SortAscending() As Boolean
            Get
                Dim o As Object = ViewState("SortAscending")

                If o Is Nothing Then
                    Return True
                End If
                Return CBool(o)
            End Get
            Set(ByVal Value As Boolean)
                ViewState("SortAscending") = Value
            End Set
        End Property

    End Class 'Simple 
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.

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