Click here to Skip to main content
15,892,575 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
<html><head><link rel=stylesheet href=style.css></head><body><div class=SourcePanel style='font-size:12'><pre style='background-color:white'>
<font color= "blue">using</font> System;
<font color= "blue">using</font> System.Web.UI.WebControls;
<font color= "blue">using</font> System.Text;
<font color= "blue">using</font> ASPNET.StarterKit.Reports.Components;
<font color= "blue"></font>
<font color= "blue">namespace</font> ASPNET.StarterKit.Reports
<font color= "blue"></font>{
<font color= "green">    //*********************************************************************</font>
<font color= "green">    //</font>
<font color= "green">    // Visual.aspx</font>
<font color= "green">    //</font>
<font color= "green">    // The Visual.aspx page shows Sales by Category in three different views: </font>
<font color= "green">    // Pie Chart, Bar Graph, and Tabular view.</font>
<font color= "green">    //</font>
<font color= "green">    //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">    public class</font> Visual : System.Web.UI.Page
<font color= "blue">    </font>{
<font color= "blue">        protected </font>System.Web.UI.WebControls.DropDownList drpChartType;
<font color= "blue">        protected </font>System.Web.UI.WebControls.DataGrid SalesByCategoryGrid;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Image ChartImage;
<font color= "blue">        protected </font>System.Web.UI.WebControls.HyperLink PrintButton;
<font color= "blue">        protected </font>bool printVersion;
<font color= "blue">        protected </font>string _styleSheet;
<font color= "blue">    </font>
<font color= "blue">        private void</font> Page_Load(object sender, System.EventArgs e)
<font color= "blue">        </font>{
<font color= "blue">            </font>printVersion = Request.QueryString["Print"]=="true";
<font color= "blue"></font>
<font color= "blue"></font><font color= "blue">            if </font>(!IsPostBack)<font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue"></font><font color= "blue">                if </font>(Session["ViewSelectIndex"] != null)<font color= "blue"></font>
<font color= "blue">                    </font>drpChartType.SelectedIndex = (int)Session["ViewSelectIndex"];
<font color= "blue"></font>
<font color= "green">                // call event to display default view</font>
<font color= "blue">                </font>drpChartType_SelectedIndexChanged(this, new System.EventArgs());
<font color= "blue">            </font>}
<font color= "blue"></font>
<font color= "green">            // switches the style sheet based on printer friendly view or not</font>
<font color= "blue"></font><font color= "blue">            if </font>(printVersion)<font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue">                </font>_styleSheet = "stylesPrint.css";
<font color= "blue">                </font>PrintButton.Visible = true;
<font color= "blue">            </font>}
<font color= "blue"></font><font color= "blue">            else </font><font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue">                </font>_styleSheet = "styles.css";
<font color= "blue">            </font>}
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "blue">        </font>#region Web Form Designer generated code
<font color= "blue">        </font>override protected void OnInit(EventArgs e)
<font color= "blue">        </font>{
<font color= "green">            //</font>
<font color= "green">            // CODEGEN: This call is required by the ASP.NET Web Form Designer.</font>
<font color= "green">            //</font>
<font color= "blue">            </font>InitializeComponent();
<font color= "blue">            </font>base.OnInit(e);
<font color= "blue">        </font>}
<font color= "blue">        </font>
<font color= "green">        /// <summary></font>
<font color= "green">        /// Required method for Designer support - do not modify</font>
<font color= "green">        /// the contents of this method with the code editor.</font>
<font color= "green">        /// </summary></font>
<font color= "blue">        private void</font> InitializeComponent()
<font color= "blue">        </font>{    
<font color= "blue">            </font>this.drpChartType.SelectedIndexChanged += new System.EventHandler(this.drpChartType_SelectedIndexChanged);
<font color= "blue">            </font>this.Load += new System.EventHandler(this.Page_Load);
<font color= "blue"></font>
<font color= "blue">        </font>}
<font color= "blue">        </font>#endregion
<font color= "blue"></font>
<font color= "green">        //*********************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The BindGrid method retrieves the list of sales by category</font>
<font color= "green">        // and then databinds them to the SalesByCategoryGrid</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> BindGrid(VisualReportCollection data)
<font color= "blue">        </font>{
<font color= "blue">            </font>SalesByCategoryGrid.Visible = true;
<font color= "blue">            </font>SalesByCategoryGrid.DataSource = data;
<font color= "blue">            </font>SalesByCategoryGrid.DataBind();
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "green">        //*********************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The drpChartType_SelectedIndexChanged event handler gets the sales data and changes the view.</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> drpChartType_SelectedIndexChanged(object sender, System.EventArgs e)
<font color= "blue">        </font>{
<font color= "green">            // retrieve the sales data </font>
<font color= "blue">            </font>VisualReportCollection visualReport = VisualReport.GetCategorySales();
<font color= "blue">                </font>
<font color= "blue"></font><font color= "blue">            if </font>(drpChartType.SelectedItem.Value != "Table")<font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue">                </font>StringBuilder xValues = new StringBuilder();
<font color= "blue">                </font>StringBuilder yValues = new StringBuilder();
<font color= "blue">                </font>int rowCount = visualReport.Count;
<font color= "blue">                </font>int i = 1;
<font color= "blue"></font>
<font color= "green">                // convert data to comma delimited stringbuilders</font>
<font color= "blue">                </font>foreach (VisualReport dr in visualReport)
<font color= "blue">                </font>{
<font color= "blue">                    </font>xValues.Append(dr.CategoryName);
<font color= "blue">                    </font>yValues.Append(dr.Sales);
<font color= "blue"></font><font color= "blue">                    if </font>(i < rowCount)<font color= "blue"></font>
<font color= "blue">                    </font>{
<font color= "blue">                        </font>xValues.Append("|");
<font color= "blue">                        </font>yValues.Append("|");
<font color= "blue">                    </font>}
<font color= "blue">                    </font>i++;
<font color= "blue">                </font>}
<font color= "blue"></font>
<font color= "green">                // attach image generator to image</font>
<font color= "blue">                </font>ChartImage.ImageUrl = "ChartGenerator.aspx?" +
<font color= "blue">                    </font>"xValues=" + xValues.ToString() + 
<font color= "blue">                    </font>"&yValues=" + yValues.ToString() + 
<font color= "blue">                    </font>"&ChartType=" + drpChartType.SelectedItem.Value.ToLower()+
<font color= "blue">                    </font>"&Print=" + printVersion.ToString();
<font color= "blue">                </font>
<font color= "blue">                </font>ChartImage.Visible = true;
<font color= "blue">                </font>SalesByCategoryGrid.Visible = false;
<font color= "blue">            </font>}
<font color= "blue"></font><font color= "blue">            else</font><font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue">                </font>BindGrid(visualReport);
<font color= "blue">                </font>ChartImage.Visible = false;
<font color= "blue">            </font>}
<font color= "blue"></font>
<font color= "blue">            </font>Session["ViewSelectIndex"] = drpChartType.SelectedIndex;
<font color= "blue">        </font>}
<font color= "blue">    </font>}
<font color= "blue"></font>}
</pre>

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