Click here to Skip to main content
11,720,557 members (72,507 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
Add your own
alternative version

Race to Linux - Race 3: Reports Starter Kit using Mono SqlServer/Firebird

, 30 Sep 2005 41.9K 306 15
Reports Starter Kit port to Linux using Mono
RaceToLinuxRace3_src.zip
RaceToLinuxRace3_src
bin
ASPNET.StarterKit.Reports.dll
FirebirdSql.Data.Firebird.dll
Components
BLL
DAL
docs
images
1x1.gif
crosstabnestedcontrols.png
crosstabtotals.png
customers.gif
drilldownnestedcontrols.png
employees.gif
getorderdetails.gif
getorders.gif
hierarchicalpaging.gif
hierarchicalreport.gif
hierarchicalschema.gif
hierarchicalsorting.gif
masterdetaildetails.png
masterdetailsummary.png
masterdetailtables.png
querysample.gif
querysample2.gif
simpleoverview.png
simplesp.png
tabdetail.png
tabheader.gif
tabheader.png
tabnestedcontrols.png
tabularcolorcode.png
tabularextendedprice.png
tabularsorting.png
textshot.gif
viscategorysales.gif
viscategorysales.png
vischartstructure.png
xtabsql.png
global.asax
images
asp.net-reports.gif
background.gif
crosstab.gif
drilldown.gif
grid_background.gif
hierarchical.gif
logo-neg.gif
logo.gif
masterdetail.gif
masterdetails.gif
report-table-bg.gif
simple.gif
spacer.gif
tabular.gif
textalternate.gif
textreport.gif
visual.gif
ReportsCSVS.csproj.webinfo
SourceViewer
1x1.gif
crosstab.src
drilldown.src
grid_background.gif
hierarchical.src
masterdetail.src
simple.src
tabular.src
textreport.src
visual.src
REPORTS.BKP
using System;
using System.Web.UI.WebControls;
using ASPNET.StarterKit.Reports.Components;

namespace ASPNET.StarterKit.Reports
{
	//********************************************************************************
	//
	// 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.
	//
	//********************************************************************************

	public class MasterDetail : System.Web.UI.Page
	{
		private const string _masterDetailYear = "master_detail_year";
		private const string _masterDetailQuarter = "master_detail_quarter";
		protected System.Web.UI.WebControls.DropDownList YearDropDownList;
		protected System.Web.UI.WebControls.DropDownList QuarterDropDownList;
		protected System.Web.UI.WebControls.DataGrid SummaryDataGrid;
		protected System.Web.UI.WebControls.DataGrid DetailsDataGrid;
		protected System.Web.UI.WebControls.Label SummaryLabel;
		protected System.Web.UI.WebControls.Label DetailsLabel;
		protected System.Web.UI.WebControls.HyperLink PrintButton;

		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";
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.YearDropDownList.SelectedIndexChanged += new System.EventHandler(this.YearDropDownList_SelectedIndexChanged);
			this.QuarterDropDownList.SelectedIndexChanged += new System.EventHandler(this.QuarterDropDownList_SelectedIndexChanged);
			this.SummaryDataGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.SumItems);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		//********************************************************************************
		//
		// 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);
		}
	}
}

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

Share

About the Author

idepaula
Web Developer
Uruguay Uruguay
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150901.1 | Last Updated 1 Oct 2005
Article Copyright 2005 by idepaula
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid