ColaReport - Demo 5
 Home
 FAQ
 Examples
 Documentation
 Download
 Feedback
 Support
  demo5.aspx.cs       Return to Demo 5       Return to Examples

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using ColaReport;

namespace ColaReportDemo
{
	/// <summary>
	/// Demonstrates:
	/// Creating a running total column.
	/// </summary>
	public class demo5 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lblReport;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			Report oReport;
			CellColumn oCol; 
			Group oGroup;
			DataSet dsRpt;
			string sQuery;

			OleDbConnection oConn;
			OleDbDataAdapter daRpt;

			// Get connection string
			oConn = new OleDbConnection (ConfigurationSettings.AppSettings["gsConn"]);
			
			//We later create a "group" on CustomerName.
			//It is therefore important to order by CustomerName here.
			sQuery = "SELECT i.InvoiceDate, c.CustomerName, i.InvoiceId, i.InvoiceTotal" +
				" FROM Customer c, Invoice i" +
				" WHERE c.customerid = i.customerid" +
				" ORDER BY i.InvoiceDate, i.InvoiceId";

			daRpt = new OleDbDataAdapter (sQuery, oConn);
			dsRpt = new DataSet();
			daRpt.Fill(dsRpt);

			// Define Report 
			oReport = new Report ();

			oReport.Style.Add ("font-family", "Verdana");
			oReport.HeaderRowAttributes.Attributes["bgcolor"] = "#efefdf";

			oReport.FirstPageHeader.Text = "<h2>Demo: demo5.aspx</h2>";
			oReport.FirstPageHeader.Style.Add ("font-family", "Verdana");
			oReport.PageHeader.Text = "<h3>Demo: demo5.aspx</h3>";
			oReport.PageHeader.Style.Add ("font-family", "Verdana");
	
			oCol = oReport.CreateCellColumn ("InvoiceDate", "Invoice Date"); 
			oCol.StringFormat = "{0:d}";
			oCol.Wrap = false;

			oCol = oReport.CreateCellColumn ("CustomerName", "Customer Name");
			oCol.Wrap = false;
			oCol = oReport.CreateCellColumn ("InvoiceId", "Invoice Number"); 
			oCol.Attributes["align"] = "right";
 
			oCol = oReport.CreateCellColumn ("InvoiceTotal", "Invoice Total"); 
			oCol.SumColumn = true; //display totals for this column
			oCol.Attributes["align"] = "right";
			oCol.StringFormat = "{0:c}"; //currency format

			oCol = oReport.CreateRunningTotalColumn 
				("RunningTotal", "Running Total", "InvoiceTotal", 0);

			oCol.Attributes["align"] = "right";
			oCol.StringFormat = "{0:c}"; //currency format
			
			// Create a group for the grand totals
			oGroup = oReport.CreateTotalGroup (true);
			oGroup.Cells["InvoiceDate"].Text = "Total";
			oGroup.Cells["InvoiceDate"].StringFormat = "";
			oGroup.Cells["InvoiceDate"].Style.Add("font-weight", "bold");
			oGroup.Cells["InvoiceTotal"].Style.Add("font-weight", "bold");
			oGroup.Cells["RunningTotal"].Style.Add("font-weight", "bold");
			oGroup.BackColor = System.Drawing.Color.FromArgb (249,249,200);
			oGroup.BlankLineAfterGroup = false;

			//Group data by InvoiceDate
			oGroup = oReport.CreateGroup ("InvoiceDate", true);
			oGroup.Cells["InvoiceDate"].StringFormat = "{0:d} Subtotal";
			oGroup.Cells["InvoiceDate"].Style.Add("font-weight", "bold");

			//Bind dataset
			oReport.Bind (dsRpt);

			//Set label text to report output
			lblReport.Text = oReport.Execute();
		}
	}
}
      
Copyright © 2003