Click here to Skip to main content
15,885,767 members
Articles / Web Development / ASP.NET

Conversion of Reporting Starter Kit to use Mono/MySQL

Rate me:
Please Sign up or sign in to vote.
3.69/5 (9 votes)
1 Oct 20053 min read 28.3K   411   32  
A porting of the ASP.NET reporting starter kit to use Mono, MySQL and Apache on a Linux system.
<%@ Page language="c#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="ASPNET.StarterKit.Reports.Components" %>
<script runat="server">
	//*********************************************************************
	//
	// SimpleReport.aspx
	//
	// This report lists all customer contacts information from the database
	// in a DataGrid control
	//
	//*********************************************************************
	
	protected string _styleSheet;
	
	private void Page_Load(object sender, System.EventArgs e)
	{
		if (!IsPostBack)
		{
			BindGrid();
		}

		// switches the style sheet based on printer friendly view or not
		if (Request.QueryString["Print"]=="true")
		{
			_styleSheet = "stylesPrint.css";
			PrintButton.Visible = true;
			PagingButton.Visible = true;
		}
		else 
		{
			_styleSheet = "styles.css";
		}
	}

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

	private void BindGrid()
	{
		SimpleReportCollection customerList = SimpleReport.GetCustomerContacts();
		SortGridData(customerList, SortField, SortAscending);
		CustomerGrid.DataSource = customerList;
		CustomerGrid.DataBind();
	}

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

	private void CustomerGrid_Sort(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
	{
		// change sort field
		SortField = (string)e.SortExpression;

		// re-bind to display new sorting
		BindGrid();
	}

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

	private void SortGridData(SimpleReportCollection list, string sortField, bool asc)
	{
		SimpleReportCollection.SimpleReportFields sortCol = SimpleReportCollection.SimpleReportFields.InitValue;

		switch(sortField)
		{
			case "City":
				sortCol = SimpleReportCollection.SimpleReportFields.City;
				break;
			case "CompanyName":
				sortCol = SimpleReportCollection.SimpleReportFields.CompanyName;
				break;
			case "ContactName":
				sortCol = SimpleReportCollection.SimpleReportFields.ContactName;
				break;
			case "ContactTitle":
				sortCol = SimpleReportCollection.SimpleReportFields.ContactTitle;
				break;
			case "Phone":
				sortCol = SimpleReportCollection.SimpleReportFields.Phone;
				break;
		}

		list.Sort(sortCol, asc);
	}

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

	private void CustomerGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
	{
		CustomerGrid.CurrentPageIndex = e.NewPageIndex;
		BindGrid();
	}

	//*******************************************************
	//
	// pagingButton_Click server event handler on this page is used
	// for changing paging property on CustomerGrid
	//
	//*******************************************************
	private void pagingButton_Click(object sender, System.EventArgs e)
	{
		CustomerGrid.AllowPaging = !CustomerGrid.AllowPaging;	
		BindGrid();

		PagingButton.Text = CustomerGrid.AllowPaging ? "Disable Paging" : "Enable Paging";
	}

	string SortField 
	{
		get 
		{
			object o = ViewState["SortField"];
			if (o == null) 
			{
				return String.Empty;
			}
			return (string)o;
		}
		set 
		{
			if (value == SortField) 
			{
				// same as current sort file, toggle sort direction
				SortAscending = !SortAscending;
			}
			ViewState["SortField"] = value;
		}
	}

	//*********************************************************************
	//
	// SortAscending property is tracked in ViewState
	//
	//*********************************************************************

	bool SortAscending 
	{
		get 
		{
			object o = ViewState["SortAscending"];

			if (o == null) 
			{
				return true;
			}
			return (bool)o;
		}
		set 
		{
			ViewState["SortAscending"] = value;
		}
	}

</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
	<head>
		<title>Simple Report</title>
		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
		<link href="<%= _styleSheet %>" type=text/css rel=stylesheet>
		<script src="scripts.js"></script>
	</head>
	<body class="Report" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
		<form id="Simple" method="post" runat="server">
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr height="20">
					<td colspan="3">
						<table border="0" cellpadding="0" cellspacing="0" width="100%">
							<tr>
								<td colspan="4"><img src="images/spacer.gif" width="50" height="20"></td>
							</tr>
							<tr>
								<td width="20"></td>
								<td class="ReportTitle">Customer Contacts</td>
								<td align="right">
								<asp:LinkButton id="PagingButton" runat="server" cssclass="printbutton" Visible="False" OnClick="pagingButton_Click">Disable Paging</asp:LinkButton>&nbsp;&nbsp; 
									&nbsp;
								<asp:hyperlink id="PrintButton" navigateurl="javascript:Print()" cssclass="printbutton" runat="server" visible="False">Print</asp:hyperlink></td>
								<td width="20"></td>
							</tr>
							<tr>
								<td colspan="4"><img src="images/spacer.gif" width="20" height="20"></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td width="20"></td>
					<td>
						<asp:datagrid id="CustomerGrid" OnPageIndexChanged="CustomerGrid_PageIndexChanged" OnSortCommand="CustomerGrid_Sort" AlternatingItemStyle-CssClass="Content" runat="server" AutoGenerateColumns="False" BorderWidth="0" GridLines="None" Width="100%" AllowSorting="True" AllowPaging="True" PageSize="20" CellPadding="5">
							<alternatingitemstyle cssclass="Content"></alternatingitemstyle>
							<columns>
								<asp:BoundColumn DataField="CompanyName" SortExpression="CompanyName" HeaderText="Company">
									<headerstyle cssclass="CategoryHeader"></headerstyle>
									<itemstyle cssclass="ItemStyle"></itemstyle>
								</asp:BoundColumn>
								<asp:BoundColumn DataField="ContactName" SortExpression="ContactName" HeaderText="Contact">
									<headerstyle cssclass="CategoryHeader"></headerstyle>
									<itemstyle cssclass="ItemStyle"></itemstyle>
								</asp:BoundColumn>
								<asp:BoundColumn DataField="ContactTitle" SortExpression="ContactTitle" HeaderText="Title">
									<headerstyle cssclass="CategoryHeader"></headerstyle>
									<itemstyle cssclass="ItemStyle"></itemstyle>
								</asp:BoundColumn>
								<asp:BoundColumn DataField="Phone" SortExpression="Phone" HeaderText="Telephone">
									<headerstyle cssclass="CategoryHeader"></headerstyle>
									<itemstyle cssclass="ItemStyle"></itemstyle>
								</asp:BoundColumn>
								<asp:BoundColumn DataField="City" SortExpression="City" HeaderText="City">
									<headerstyle cssclass="CategoryHeader"></headerstyle>
									<itemstyle cssclass="ItemStyle"></itemstyle>
								</asp:BoundColumn>
							</columns>
						</asp:datagrid>
					</td>
					<td width="20"></td>
				</tr>
			</table>
		</form>
	</body>
</html>

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
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions