Click here to Skip to main content
15,896,278 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.4K   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">
	//********************************************************************************
	//
	// MasterDetail.aspx
	//
	// The MasterDetail.aspx page shows a basic way to filter and group related data (in
	// chis case, filtering by year, and grouping by quarters).  This is accomplished by
	// showing two different datagrids, each bound by separate stored procedures.
	//
	//********************************************************************************
	
	private const string _masterDetailYear = "master_detail_year";
	private const string _masterDetailQuarter = "master_detail_quarter";
	private double _salesTotal;
	protected string _styleSheet;

	private void Page_Load(object sender, System.EventArgs e)
	{
		_salesTotal = 0;
		if (!IsPostBack)
		{
			if (YearDropDownList.Items.FindByValue(Convert.ToString(Session[_masterDetailYear])) != null)
				YearDropDownList.Items.FindByValue(Convert.ToString(Session[_masterDetailYear])).Selected = true;
			if (QuarterDropDownList.Items.FindByValue(Convert.ToString(Session[_masterDetailQuarter])) != null)
				QuarterDropDownList.Items.FindByValue(Convert.ToString(Session[_masterDetailQuarter])).Selected = true;

			BindSummary();
			BindDetails();
		}

		// 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 BindSummary method retrieves the OrderSummary for a given year, and
	// then databinds the results to the SummaryDataGrid.
	//
	//********************************************************************************

	private void BindSummary()
	{
		SummaryLabel.Text = YearDropDownList.SelectedItem.Text + " Summary";
		SummaryDataGrid.DataSource = GetSales(Convert.ToInt32(YearDropDownList.SelectedItem.Value));
		SummaryDataGrid.DataBind();
	}

	//********************************************************************************
	//
	// The BindDetails method retrieves the OrderDetails for a given year and quarter, and
	// then databinds the results to the DetailsDataGrid.
	//
	//********************************************************************************
	
	private void BindDetails()
	{
		DetailsLabel.Text = YearDropDownList.SelectedItem.Text;
		if (QuarterDropDownList.SelectedItem.Value == "0")
			DetailsLabel.Text += " (All Quarters) Details";
		else
			DetailsLabel.Text += " (Quarter " + QuarterDropDownList.SelectedItem.Text + ") Details";

		DetailsDataGrid.DataSource = GetSalesDetails(Convert.ToInt32(YearDropDownList.SelectedItem.Value), Convert.ToInt32(QuarterDropDownList.SelectedItem.Value));
		DetailsDataGrid.DataBind();
	}

	//********************************************************************************
	//
	// The GetSales uses the MasterDetail BLL component to query the database to retrieve
	// the summary of sales for a given year.
	//
	//********************************************************************************

	protected MasterDetailReportCollection GetSales(int year)
	{
		return MasterDetailReport.GetSummary(year);
	}

	//********************************************************************************
	//
	// The GetSalesDetails uses the MasterDetail BLL component to query the database to
	// retrieve the details of sales for a given year and quarter.
	//
	//********************************************************************************
	
	protected MasterDetailReportCollection GetSalesDetails(int year, int quarter)
	{
		return MasterDetailReport.GetDetails(year, quarter);
	}

	//********************************************************************************
	//
	// DropDownList event handlers for the Year and Quarter DropDownLists.  They make
	// calls to rebind the DetailsDataGrid (and if applicable) the SummaryDataGrid.
	//
	//********************************************************************************

	private void YearDropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
	{
		Session[_masterDetailYear] = YearDropDownList.SelectedItem.Value;
		BindSummary();
		BindDetails();
	}

	private void QuarterDropDownList_SelectedIndexChanged(object sender, System.EventArgs e) 
	{
		Session[_masterDetailQuarter] = QuarterDropDownList.SelectedItem.Value;
		BindDetails();
	} 

	//********************************************************************************
	//
	// The SumItems event handler is called after the masterDataGrid has been databound.
	// It iterates thru the list to calculate the sum of sales, and then adds the
	// results (as HTML) to the datagrid table.
	//
	//********************************************************************************

	private void SumItems(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
	{
		if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
		{
			CalcTotal( e.Item.Cells[2].Text );
			e.Item.Cells[2].Text = string.Format("{0:c}", Convert.ToDouble(e.Item.Cells[2].Text));
		}
		else if (e.Item.ItemType == ListItemType.Footer )
		{
			e.Item.Cells[0].Text="Sales Total";
			e.Item.Cells[2].Text = string.Format("{0:c}", _salesTotal);
		}
	}

	private void CalcTotal(string _price)
	{
		_salesTotal += Double.Parse(_price);
	}
</script>

<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
	<head>
		<title>Master Detail</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="17" topmargin="17" marginwidth="0" marginheight="0">
		<form id="MasterDetail" method="post" runat="server">
			<table cellspacing="0" cellpadding="3" width="400px" border="0">
				<tr>
					<td class="ReportTitle" width="350">Master Detail 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>
				<tr>
					<td colspan="2"><img height="10" src="images/spacer.gif"></td>
				</tr>
				<tr>
					<td colspan="2" class="Select">
						<table cellspacing="3" cellpadding="0" border="0">
							<tr>
								<td class="bold">
									Select Year:
								</td>
								<td align="right">
									<asp:dropdownlist id="YearDropDownList" OnSelectedIndexChanged="YearDropDownList_SelectedIndexChanged" runat="server" autopostback="True" width="56">
										<asp:listitem value="1996">1996</asp:listitem>
										<asp:listitem value="1997">1997</asp:listitem>
										<asp:listitem value="1998">1998</asp:listitem>
									</asp:dropdownlist>
								</td>
							</tr>
							<tr>
								<td class="bold">
									Select Quarter:
								</td>
								<td align="right">
									<asp:dropdownlist id="QuarterDropDownList" OnSelectedIndexChanged="QuarterDropDownList_SelectedIndexChanged" runat="server" autopostback="True" width="56px">
										<asp:listitem value="0">All</asp:listitem>
										<asp:listitem value="1">1</asp:listitem>
										<asp:listitem value="2">2</asp:listitem>
										<asp:listitem value="3">3</asp:listitem>
										<asp:listitem value="4">4</asp:listitem>
									</asp:dropdownlist>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td colspan="2"><img height="10" src="images/spacer.gif"></td>
				</tr>
				<tr>
					<td colspan="2" class="textbold"><asp:label id="SummaryLabel" runat="server"></asp:label></td>
				</tr>
				<tr>
					<td colspan="2"><img height="10" src="images/spacer.gif"></td>
				</tr>
				<tr>
					<td colspan="2"><asp:datagrid id="SummaryDataGrid" OnItemDataBound="SumItems" runat="server" cssclass="content" borderwidth="0" cellpadding="3" showfooter="True" width="400" gridlines="Horizontal" autogeneratecolumns="False">
							<columns>
								<asp:boundcolumn datafield="Quarter" headertext="Quarter" itemstyle-cssclass="ItemStyle" headerstyle-cssclass="HeaderStyle" footerstyle-cssclass="FooterStyle"></asp:boundcolumn>
								<asp:boundcolumn datafield="OrdersShipped" headertext="Orders Shipped" itemstyle-cssclass="ItemStyleRight" headerstyle-cssclass="HeaderStyleRight" footerstyle-cssclass="FooterStyleRight"></asp:boundcolumn>
								<asp:boundcolumn datafield="Sales" headertext="Sales" itemstyle-cssclass="ItemStyleRight" headerstyle-cssclass="HeaderStyleRight" footerstyle-cssclass="FooterStyleRight"></asp:boundcolumn>
							</columns>
						</asp:datagrid></td>
				</tr>
				<tr>
					<td colspan="2"><img height="10" src="images/spacer.gif"></td>
				</tr>
				<tr>
					<td colspan="2" class="textbold"><asp:label id="DetailsLabel" runat="server"></asp:label></td>
				</tr>
				<tr>
					<td colspan="2"><img height="10" src="images/spacer.gif"></td>
				</tr>
				<tr>
					<td colspan="2"><asp:datagrid id="DetailsDataGrid" runat="server" cssclass="content" borderwidth="0" cellpadding="3" width="400" gridlines="Horizontal" autogeneratecolumns="False" showfooter="True">
							<columns>
								<asp:boundcolumn datafield="OrderID" headertext="Order ID" itemstyle-cssclass="ItemStyle" headerstyle-cssclass="HeaderStyle" footerstyle-cssclass="FooterStyle"></asp:boundcolumn>
								<asp:boundcolumn datafield="OrderDate" headertext="Orders Date" dataformatstring="{0:d}" itemstyle-cssclass="ItemStyleRight" headerstyle-cssclass="HeaderStyleRight" footerstyle-cssclass="FooterStyleRight"></asp:boundcolumn>
								<asp:boundcolumn datafield="Sales" headertext="Sales" dataformatstring="{0:c}" itemstyle-cssclass="ItemStyleRight" headerstyle-cssclass="HeaderStyleRight" footerstyle-cssclass="FooterStyleRight"></asp:boundcolumn>
							</columns>
						</asp:datagrid></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