|
using System;
using System.Web.UI.WebControls;
using System.Text;
using ASPNET.StarterKit.Reports.Components;
namespace ASPNET.StarterKit.Reports
{
//*********************************************************************
//
// Visual.aspx
//
// The Visual.aspx page shows Sales by Category in three different views:
// Pie Chart, Bar Graph, and Tabular view.
//
//*********************************************************************
public class Visual : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList drpChartType;
protected System.Web.UI.WebControls.DataGrid SalesByCategoryGrid;
protected System.Web.UI.WebControls.Image ChartImage;
protected System.Web.UI.WebControls.HyperLink PrintButton;
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";
}
}
#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.drpChartType.SelectedIndexChanged += new System.EventHandler(this.drpChartType_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
//*********************************************************************
//
// 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
{
System.Console.WriteLine("Table");
BindGrid(visualReport);
ChartImage.Visible = false;
}
Session["ViewSelectIndex"] = drpChartType.SelectedIndex;
}
}
}
|
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.
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
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.