Click here to Skip to main content
15,883,705 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 52.6K   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> 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">    // MasterDetail.aspx</font>
<font color= "green">    //</font>
<font color= "green">    // The MasterDetail.aspx page shows a basic way to filter and group related data (in</font>
<font color= "green">    // chis case, filtering by year, and grouping by quarters).  This is accomplished by</font>
<font color= "green">    // showing two different datagrids, each bound by separate stored procedures.</font>
<font color= "green">    //</font>
<font color= "green">    //********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">    public class</font> MasterDetail : System.Web.UI.Page
<font color= "blue">    </font>{
<font color= "blue">        private const </font>string _masterDetailYear = "master_detail_year";
<font color= "blue">        private const </font>string _masterDetailQuarter = "master_detail_quarter";
<font color= "blue">        protected </font>System.Web.UI.WebControls.DropDownList YearDropDownList;
<font color= "blue">        protected </font>System.Web.UI.WebControls.DropDownList QuarterDropDownList;
<font color= "blue">        protected </font>System.Web.UI.WebControls.DataGrid SummaryDataGrid;
<font color= "blue">        protected </font>System.Web.UI.WebControls.DataGrid DetailsDataGrid;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Label SummaryLabel;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Label DetailsLabel;
<font color= "blue">        protected </font>System.Web.UI.WebControls.HyperLink PrintButton;
<font color= "blue"></font>
<font color= "blue">        private </font>double _salesTotal;
<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>_salesTotal = 0;
<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>(YearDropDownList.Items.FindByValue(Convert.ToString(Session[_masterDetailYear])) != null)<font color= "blue"></font>
<font color= "blue">                    </font>YearDropDownList.Items.FindByValue(Convert.ToString(Session[_masterDetailYear])).Selected = true;
<font color= "blue"></font><font color= "blue">                if </font>(QuarterDropDownList.Items.FindByValue(Convert.ToString(Session[_masterDetailQuarter])) != null)<font color= "blue"></font>
<font color= "blue">                    </font>QuarterDropDownList.Items.FindByValue(Convert.ToString(Session[_masterDetailQuarter])).Selected = true;
<font color= "blue"></font>
<font color= "blue">                </font>BindSummary();
<font color= "blue">                </font>BindDetails();
<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>(Request.QueryString["Print"]=="true")<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.YearDropDownList.SelectedIndexChanged += new System.EventHandler(this.YearDropDownList_SelectedIndexChanged);
<font color= "blue">            </font>this.QuarterDropDownList.SelectedIndexChanged += new System.EventHandler(this.QuarterDropDownList_SelectedIndexChanged);
<font color= "blue">            </font>this.SummaryDataGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.SumItems);
<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 BindSummary method retrieves the OrderSummary for a given year, and</font>
<font color= "green">        // then databinds the results to the SummaryDataGrid.</font>
<font color= "green">        //</font>
<font color= "green">        //********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> BindSummary()
<font color= "blue">        </font>{
<font color= "blue">            </font>SummaryLabel.Text = YearDropDownList.SelectedItem.Text + " Summary";
<font color= "blue">            </font>SummaryDataGrid.DataSource = GetSales(Convert.ToInt32(YearDropDownList.SelectedItem.Value));
<font color= "blue">            </font>SummaryDataGrid.DataBind();
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "green">        //********************************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The BindDetails method retrieves the OrderDetails for a given year and quarter, and</font>
<font color= "green">        // then databinds the results to the DetailsDataGrid.</font>
<font color= "green">        //</font>
<font color= "green">        //********************************************************************************</font>
<font color= "blue">        </font>
<font color= "blue">        private void</font> BindDetails()
<font color= "blue">        </font>{
<font color= "blue">            </font>DetailsLabel.Text = YearDropDownList.SelectedItem.Text;
<font color= "blue"></font><font color= "blue">            if </font>(QuarterDropDownList.SelectedItem.Value == "0")<font color= "blue"></font>
<font color= "blue">                </font>DetailsLabel.Text += " (All Quarters) Details";
<font color= "blue"></font><font color= "blue">            else</font><font color= "blue"></font>
<font color= "blue">                </font>DetailsLabel.Text += " (Quarter " + QuarterDropDownList.SelectedItem.Text + ") Details";
<font color= "blue"></font>
<font color= "blue">            </font>DetailsDataGrid.DataSource = GetSalesDetails(Convert.ToInt32(YearDropDownList.SelectedItem.Value), Convert.ToInt32(QuarterDropDownList.SelectedItem.Value));
<font color= "blue">            </font>DetailsDataGrid.DataBind();
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "green">        //********************************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The GetSales uses the MasterDetail BLL component to query the database to retrieve</font>
<font color= "green">        // the summary of sales for a given year.</font>
<font color= "green">        //</font>
<font color= "green">        //********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        protected </font>MasterDetailReportCollection GetSales(int year)
<font color= "blue">        </font>{
<font color= "blue">            return</font> MasterDetailReport.GetSummary(year);
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "green">        //********************************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The GetSalesDetails uses the MasterDetail BLL component to query the database to</font>
<font color= "green">        // retrieve the details of sales for a given year and quarter.</font>
<font color= "green">        //</font>
<font color= "green">        //********************************************************************************</font>
<font color= "blue">        </font>
<font color= "blue">        protected </font>MasterDetailReportCollection GetSalesDetails(int year, int quarter)
<font color= "blue">        </font>{
<font color= "blue">            return</font> MasterDetailReport.GetDetails(year, quarter);
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "green">        //********************************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // DropDownList event handlers for the Year and Quarter DropDownLists.  They make</font>
<font color= "green">        // calls to rebind the DetailsDataGrid (and if applicable) the SummaryDataGrid.</font>
<font color= "green">        //</font>
<font color= "green">        //********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> YearDropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
<font color= "blue">        </font>{
<font color= "blue">            </font>Session[_masterDetailYear] = YearDropDownList.SelectedItem.Value;
<font color= "blue">            </font>BindSummary();
<font color= "blue">            </font>BindDetails();
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "blue">        private void</font> QuarterDropDownList_SelectedIndexChanged(object sender, System.EventArgs e) 
<font color= "blue">        </font>{
<font color= "blue">            </font>Session[_masterDetailQuarter] = QuarterDropDownList.SelectedItem.Value;
<font color= "blue">            </font>BindDetails();
<font color= "blue">        </font>} 
<font color= "blue"></font>
<font color= "green">        //********************************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The SumItems event handler is called after the masterDataGrid has been databound.</font>
<font color= "green">        // It iterates thru the list to calculate the sum of sales, and then adds the</font>
<font color= "green">        // results (as HTML) to the datagrid table.</font>
<font color= "green">        //</font>
<font color= "green">        //********************************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> SumItems(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
<font color= "blue">        </font>{
<font color= "blue"></font><font color= "blue">            if </font>(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)<font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue">                </font>CalcTotal( e.Item.Cells[2].Text );
<font color= "blue">                </font>e.Item.Cells[2].Text = string.Format("{0:c}", Convert.ToDouble(e.Item.Cells[2].Text));
<font color= "blue">            </font>}
<font color= "blue"></font><font color= "blue">            else if </font>(e.Item.ItemType == ListItemType.Footer )<font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue">                </font>e.Item.Cells[0].Text="Sales Total";
<font color= "blue">                </font>e.Item.Cells[2].Text = string.Format("{0:c}", _salesTotal);
<font color= "blue">            </font>}
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "blue">        private void</font> CalcTotal(string _price)
<font color= "blue">        </font>{
<font color= "blue">            </font>_salesTotal += Double.Parse(_price);
<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