Click here to Skip to main content
15,891,375 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="System.Text" %>
<%@ Import Namespace="ASPNET.StarterKit.Reports.Components" %>

<script runat="server">
	//*********************************************************************
	//
	// Visual.aspx
	//
	// The Visual.aspx page shows Sales by Category in three different views: 
	// Pie Chart, Bar Graph, and Tabular view.
	//
	//*********************************************************************

	protected bool printVersion;
	protected string _styleSheet;

	private void Page_Load(object sender, System.EventArgs e)
	{
		printVersion = Request.QueryString["Print"]=="true";

		if (!IsPostBack)
		{
			if (Session["ViewSelectIndex"] != null)
				drpChartType.SelectedIndex = (int)Session["ViewSelectIndex"];

			// call event to display default view
			drpChartType_SelectedIndexChanged(this, new System.EventArgs());
		}

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

	//*********************************************************************
	//
	// The BindGrid method retrieves the list of sales by category
	// and then databinds them to the SalesByCategoryGrid
	//
	//*********************************************************************

	private void BindGrid(VisualReportCollection data)
	{
		SalesByCategoryGrid.Visible = true;
		SalesByCategoryGrid.DataSource = data;
		SalesByCategoryGrid.DataBind();
	}

	//*********************************************************************
	//
	// The drpChartType_SelectedIndexChanged event handler gets the sales data and changes the view.
	//
	//*********************************************************************

	private void drpChartType_SelectedIndexChanged(object sender, System.EventArgs e)
	{
		// retrieve the sales data 
		VisualReportCollection visualReport = VisualReport.GetCategorySales();
			
		if (drpChartType.SelectedItem.Value != "Table")
		{
			StringBuilder xValues = new StringBuilder();
			StringBuilder yValues = new StringBuilder();
			int rowCount = visualReport.Count;
			int i = 1;

			// convert data to comma delimited stringbuilders
			foreach (VisualReport dr in visualReport)
			{
				xValues.Append(dr.CategoryName);
				yValues.Append(dr.Sales);
				if (i < rowCount)
				{
					xValues.Append("|");
					yValues.Append("|");
				}
				i++;
			}

			// attach image generator to image
			ChartImage.ImageUrl = "ChartGenerator.aspx?" +
				"xValues=" + xValues.ToString() + 
				"&yValues=" + yValues.ToString() + 
				"&ChartType=" + drpChartType.SelectedItem.Value.ToLower()+
				"&Print=" + printVersion.ToString();
			
			ChartImage.Visible = true;
			SalesByCategoryGrid.Visible = false;
		}
		else
		{
			BindGrid(visualReport);
			ChartImage.Visible = false;
		}

		Session["ViewSelectIndex"] = drpChartType.SelectedIndex;
	}
</script>

<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
	<head>
		<title>Visual</title>
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
		<link href="<%= _styleSheet %>" type=text/css rel=stylesheet>
		<script src="scripts.js"></script>
	</head>
	<body class="Report" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
		<form id="Visual" method="post" runat="server">
			<table border="0" cellspacing="15" cellpadding="5" width="100%" id="Table1">
				<tr>
					<td colspan="1" class="ReportTitle">Sales By Category</td>
					<td align="right">
						<asp:hyperlink id="PrintButton" navigateurl="javascript:Print()" cssclass="printbutton" runat="server" visible="False">Print</asp:hyperlink>
					</td>

				</tr>
				<tr>
					<td colspan="2" class="Select">
						Select View:
						<asp:dropdownlist id="drpChartType" OnSelectedIndexChanged="drpChartType_SelectedIndexChanged" runat="server" autopostback="True">
							<asp:listitem value="Pie">Pie Chart</asp:listitem>
							<asp:listitem value="Bar">Bar Graph</asp:listitem>
							<asp:listitem value="Table">Table</asp:listitem>
						</asp:dropdownlist>
					</td>
				</tr>
				<tr>
					<td colspan="2" valign="top">
						<asp:datagrid id="SalesByCategoryGrid" runat="server" gridlines="Both" borderwidth="0" showfooter="True" autogeneratecolumns="False" width="300" cellpadding="3" cssclass="Content">
							<columns>
								<asp:boundcolumn datafield="CategoryName" headertext="Category">
									<headerstyle cssclass="HeaderStyle"></headerstyle>
									<itemstyle cssclass="ItemStyle"></itemstyle>
									<footerstyle cssclass="FooterStyle"></footerstyle>
								</asp:boundcolumn>
								<asp:boundcolumn datafield="Sales" headertext="Sales" dataformatstring="{0:c}">
									<headerstyle horizontalalign="Right" cssclass="HeaderStyleRight"></headerstyle>
									<itemstyle cssclass="ItemStyleRight"></itemstyle>
									<footerstyle cssclass="FooterStyleRight"></footerstyle>
								</asp:boundcolumn>
							</columns>
						</asp:datagrid>
						<asp:image id="ChartImage" runat="server" visible="False" borderwidth="0"></asp:image>
					</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