Click here to Skip to main content
15,892,537 members
Articles / Web Development / ASP.NET

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

Rate me:
Please Sign up or sign in to vote.
2.33/5 (2 votes)
30 Sep 20052 min read 53K   328   15  
Reports Starter Kit port to Linux using Mono
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using ASPNET.StarterKit.Chart;

namespace ASPNET.StarterKit.Reports
{
	/// <summary>
	/// Summary description for ChartGenerator.
	/// </summary>
	public class ChartGenerator : System.Web.UI.Page
	{
		private void Page_Load(object sender, System.EventArgs e)
		{
			// This is a quick check for referrer server name against host server
			// For best security practice in a deployed application, an authenticating mechanism should be in placed.
			// Image should only be rendered for authenticated users only.
			//if (Request.UrlReferrer != null &&((Request.UrlReferrer.Host.ToLower() == Environment.UserDomainName.ToLower()) 
			//	|| Request.UrlReferrer.Host.ToLower() == "localhost"))
			//{ 

				// set return type to png image format
				Response.ContentType = "image/png";

				string xValues, yValues, chartType, print;
				bool boolPrint;

				// Get input parameters from query string
				chartType = Request.QueryString["chartType"];
				xValues = Request.QueryString["xValues"];
				yValues = Request.QueryString["yValues"];
				print = Request.QueryString["Print"];

				if (chartType == null)
					chartType = "";

				// check for printing option 
				if (print == null)
					boolPrint = false;
				else
				{
					try
					{
						boolPrint = Convert.ToBoolean(print);
					}
					catch
					{
						boolPrint = false;
					}
				}

				if (xValues != null && yValues != null)
				{
					Color bgColor;

					if (boolPrint)
						bgColor = Color.White;
					else
						bgColor = Color.FromArgb(255,253,244);

					Bitmap StockBitMap;
					MemoryStream memStream = new MemoryStream();

					switch (chartType)
					{
						case "bar":

							BarGraph bar = new BarGraph(bgColor);
						
							bar.VerticalLabel = "$";
							bar.VerticalTickCount = 5;
							bar.ShowLegend = true;
							bar.ShowData = false;
							bar.Height = 400;
							bar.Width = 700;

							bar.CollectDataPoints(xValues.Split("|".ToCharArray()), yValues.Split("|".ToCharArray()));
							StockBitMap = bar.Draw();
							break;
						default:

							PieChart pc = new PieChart(bgColor);
	
							pc.CollectDataPoints(xValues.Split("|".ToCharArray()),yValues.Split("|".ToCharArray()));

							StockBitMap = pc.Draw();

							break;
					}

					// Render BitMap Stream Back To Client

					StockBitMap.Save(memStream, ImageFormat.Png);
					memStream.WriteTo(Response.OutputStream);
				}
			//}
		}

		#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.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}

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
Uruguay Uruguay
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions