Click here to Skip to main content
15,880,469 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">
	//*********************************************************************
	//
	// CrossTab.aspx
	//
	// The CrossTab.aspx page shows quarterly breakdown of sales based on the region.
	// It also displays the totals for each region, the totals for each month within the quarter,
	// and the total for the whole quarter.
	//
	//*********************************************************************
	
	private double _eastern = 0;
	private double _western = 0;
	private double _southern = 0;
	private double _northern = 0;
	private double _totals = 0;
	protected string _styleSheet;

	private void Page_Load(object sender, System.EventArgs e)
	{
		if (!IsPostBack)
		{
			BindList();
		}

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

	//*********************************************************************
	//
	// The BindList method simply binds the Datalist with the four quarters
	//
	//*********************************************************************

	private void BindList()
	{
		QuartersList.DataSource = new int[4] { 1, 2, 3, 4 };
		QuartersList.DataBind();
	}

	//*********************************************************************
	//
	// The GetQuarterDetails method is set as the DataSource of the inner datagrid.
	// As the QuartsList is being data-bound, this populates the inner datagrids for the quarters.
	//
	//*********************************************************************

	protected CrossTabReportCollection GetQuarterDetails(int quarter)
	{
		return CrossTabReport.GetRegionSales(quarter, Convert.ToInt32(YearDropDownList.SelectedItem.Value));
	}

	//*********************************************************************
	//
	// The SumItems event handler is for the OnItemDataBound event of the datagrids for each quarter.
	// It adds running totals for each region for a particular quarter.
	// It also adds the sum totals fo the regions of the quarter as well.
	//
	//*********************************************************************

	protected void SumItems(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
	{
		// sum up the data in the columns as the datagrid is databinding
		if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
		{
			// get the sales value for eastern region
			double eastern = Convert.ToDouble(e.Item.Cells[1].Text);
			// add sales value to the running total
			_eastern += eastern;
			// format to display sales value as currency
			e.Item.Cells[1].Text = string.Format("{0:c}", eastern);

			double western = Convert.ToDouble(e.Item.Cells[2].Text);
			_western += western;
			e.Item.Cells[2].Text = string.Format("{0:c}", western);

			double southern = Convert.ToDouble(e.Item.Cells[3].Text);
			_southern += southern;
			e.Item.Cells[3].Text = string.Format("{0:c}", southern);
			
			double northern = Convert.ToDouble(e.Item.Cells[4].Text);
			_northern += northern;
			e.Item.Cells[4].Text = string.Format("{0:c}", northern);
			
			double totals = Convert.ToDouble(e.Item.Cells[5].Text);
			_totals += totals;
			e.Item.Cells[5].Text = string.Format("{0:c}", totals);
		}
		else if(e.Item.ItemType == ListItemType.Footer )
		{
			// display our summations in footer
			e.Item.Cells[0].Text = "Totals";
			e.Item.Cells[0].HorizontalAlign = HorizontalAlign.Left;
			e.Item.Cells[1].Text = string.Format("{0:c}", _eastern);
			e.Item.Cells[2].Text = string.Format("{0:c}", _western);
			e.Item.Cells[3].Text = string.Format("{0:c}", _southern);
			e.Item.Cells[4].Text = string.Format("{0:c}", _northern);
			e.Item.Cells[5].Text = string.Format("{0:c}", _totals);

			// reset the running totals for next datagrid
			_eastern = 0;
			_western = 0;
			_southern = 0;
			_northern = 0;
			_totals = 0;
		}
	}

	private void YearDropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
	{
		BindList();
	}
</script>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
	<head>
		<title>CrossTab</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="20" topmargin="20" marginheight="0" marginwidth="0">
		<form id="CrossTab" method="post" runat="server">
			Select Year:
			<asp:dropdownlist id="YearDropDownList" OnSelectedIndexChanged="YearDropDownList_SelectedIndexChanged" runat="server" autopostback="True">
				<asp:listitem value="1996">1996</asp:listitem>
				<asp:listitem value="1997">1997</asp:listitem>
				<asp:listitem value="1998">1998</asp:listitem>
			</asp:dropdownlist>
			<br>
			<br>

			<table cellpadding="0" cellspacing="0" width="635px" border="0">
				<tr>
					<td class="ReportTitle">CrossTab Report</td>
					<td align="right" width="50">
						<asp:hyperlink id="PrintButton" navigateurl="javascript:Print()" cssclass="printbutton" runat="server" visible="False">Print</asp:hyperlink></td>
				</tr>
			</table>

				<asp:datalist id="QuartersList" runat="server" cellspacing="0" cellpadding="0">
				<itemtemplate>
					<table border="0" cellpadding="3" cellspacing="0">
						<tr>
							<td colspan="2" class="textbold">
								Quarter
								<%# Container.DataItem %>
							</td>
						</tr>
						<tr>
							<td colspan="2"><img src="images/spacer.gif" height="5"></td>
						</tr>
						<tr>
							<td><img src="images/spacer.gif" width="30"></td>
							<td>
								<table border="0" cellpadding="0" cellspacing="0">
									<asp:datagrid id="DataGrid1" runat="server" width="600" AutoGenerateColumns="False" GridLines="None" ShowFooter="True" DataSource='<%# GetQuarterDetails((int)Container.DataItem) %>' OnItemDataBound="SumItems" CellPadding="3" CssClass="Content">
										<columns>
											<asp:templatecolumn headertext="Month" itemstyle-cssclass="ItemStyle" headerstyle-cssclass="HeaderStyle" footerstyle-cssclass="FooterStyle">
												<itemtemplate>
													<%# String.Format("{0:MMMM}",DataBinder.Eval(Container.DataItem, "OrderDate")) %>
												</itemtemplate>
											</asp:templatecolumn>
											<asp:boundcolumn datafield="Eastern" headertext="Eastern" itemstyle-cssclass="ItemStyleRight" headerstyle-cssclass="HeaderStyleRight" footerstyle-cssclass="FooterStyleRight"></asp:boundcolumn>
											<asp:boundcolumn datafield="Western" headertext="Western" itemstyle-cssclass="ItemStyleRight" headerstyle-cssclass="HeaderStyleRight" footerstyle-cssclass="FooterStyleRight"></asp:boundcolumn>
											<asp:boundcolumn datafield="Southern" headertext="Southern" itemstyle-cssclass="ItemStyleRight" headerstyle-cssclass="HeaderStyleRight" footerstyle-cssclass="FooterStyleRight"></asp:boundcolumn>
											<asp:boundcolumn datafield="Northern" headertext="Northern" itemstyle-cssclass="ItemStyleRight" headerstyle-cssclass="HeaderStyleRight" footerstyle-cssclass="FooterStyleRight"></asp:boundcolumn>
											<asp:boundcolumn datafield="Sales" headertext="Totals" itemstyle-cssclass="ItemStyleRightBold" headerstyle-cssclass="HeaderStyleRight" footerstyle-cssclass="FooterStyleRightBold"></asp:boundcolumn>
										</columns>
									</asp:datagrid>
								</table>
							</td>
						</tr>
						<tr>
							<td colspan="2"><img src="images/spacer.gif" height="10"></td>
						</tr>
					</table>
				</itemtemplate>
				<headerstyle cssclass="ReportTitle"></headerstyle>
			</asp:datalist>
		</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