|
<asp:SqlDataSource ID="SqlDataSource2"
SelectCommand="SD_Tut_GetMonthlyReport"
SelectCommandType="StoredProcedure"
ConnectionString="<%$ ConnectionStrings:SD_Tut_TrackerDB %>"
runat="server">
<SelectParameters>
<asp:QueryStringParameter
Name="ForYear" QueryStringField="forYear"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Unique Users and Page Views in the year:
<b><asp:Label ID="YearLabel1" runat="server" /></b><br /><br />
<asp:GridView ID="GridView2" DataSourceID="SqlDataSource2"
AutoGenerateColumns="false"
Width="700" runat="server">
<HeaderStyle BackColor="Beige" />
<Columns>
<asp:HyperLinkField HeaderText="Month"
DataNavigateUrlFields="Year,Month"
DataNavigateUrlFormatString=
"report.aspx?forYear={0}&forMonth={1}"
DataTextField="Month" />
<asp:BoundField HeaderText="Unique Users"
DataField="UniqueUsers" />
<asp:BoundField HeaderText="Page Views"
DataField="PageViews" />
</Columns>
</asp:GridView><br />

The last report displays the unique users and page views on a daily basis.
<asp:SqlDataSource ID="SqlDataSource3"
SelectCommand="SD_Tut_GetDailyReport"
SelectCommandType="StoredProcedure"
ConnectionString="<%$ ConnectionStrings:SD_Tut_TrackerDB %>"
runat="server">
<SelectParameters>
<asp:QueryStringParameter
Name="ForYear" QueryStringField="forYear"
Type="Int32" />
<asp:QueryStringParameter
Name="ForMonth" QueryStringField="forMonth"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Unique Users and Page Views in the month:
<b><asp:Label ID="MonthLabel" runat="server" />/<asp:Label
ID="YearLabel2" runat="server" /></b>
<br /><br />
<asp:GridView ID="GridView3" DataSourceID="SqlDataSource3"
Width="700" runat="server">
<HeaderStyle BackColor="Beige" />
</asp:GridView>
report.aspx.cs
We will now code the back-end class file for report.aspx page. Open Notepad and create a new text file. Copy and paste following text in it and then save it as "report.aspx.cs":
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Report : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource2.SelectParameters["ForYear"].DefaultValue =
DateTime.Now.Year.ToString();
SqlDataSource3.SelectParameters["ForYear"].DefaultValue =
DateTime.Now.Year.ToString();
SqlDataSource3.SelectParameters["ForMonth"].DefaultValue =
DateTime.Now.Month.ToString();
if (Request.QueryString["forYear"] == null)
{
YearLabel1.Text = DateTime.Now.Year.ToString();
YearLabel2.Text = YearLabel1.Text;
}
else
{
YearLabel1.Text = Request.QueryString["forYear"];
YearLabel2.Text = YearLabel1.Text;
}
if (Request.QueryString["forMonth"] == null)
MonthLabel.Text = DateTime.Now.Month.ToString();
else
MonthLabel.Text = Request.QueryString["forMonth"];
DateTimeLabel.Text = DateTime.Now.AddHours(
Convert.ToInt32(
ConfigurationManager.AppSettings[
"SD_Tut_TimeOffset"])).ToString();
}
}
Explanation
All this class does is to set few properties of the components used in the report.aspx page. If year and month values are not given in the query string, then it uses current year and month. Lastly, we set the date and time to be displayed on the report.aspx page after adding the time zone offset hours to it. That's all.
referringdomains.aspx
Having looked at how simple the code of report.aspx was, we'll quickly move through the remaining two ASP.NET pages which will generate reports. The first of these two is referringdomains.aspx. Open Notepad and create a new text file. Then copy following text and paste in it and then save it as "referringdomains.aspx" in the same folder where you kept report.aspx.
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="referringdomainsandurls.aspx.cs"
EnableViewState="false" Inherits="_ReferringDomainsAndURLs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Tracker Referring Domains Report</title>
<style>
body { font-family:Verdana; font-size:85%; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<a href="report.aspx">
<b style="font-size:large">
<asp:Label ID="HeaderLabel"
Text="<%$ AppSettings:SD_Tut_WebSiteName %>"
runat="server" /> Tracker Report</b></a><br />
(DateTimeAfterOffset: <asp:Label ID="DateTimeLabel"
runat="server" />)
<br /><br />
<div align="center"><a href="report.aspx">Main Page</a> ·
Referring Domains ·
<a href="referringurls.aspx">Referring URLs</a></div>
<br />
<asp:SqlDataSource ID="SqlDataSource1"
SelectCommand="SD_Tut_GetYearlyReportForReferringDomains"
SelectCommandType="StoredProcedure"
ConnectionString="<%$ ConnectionStrings:SD_Tut_TrackerDB %>"
runat="server"></asp:SqlDataSource>
<asp:GridView ID="GridView1" DataSourceID="SqlDataSource1"
AutoGenerateColumns="false" Width="700" runat="server">
<HeaderStyle BackColor="Beige" />
<Columns>
<asp:HyperLinkField HeaderText="Year"
DataNavigateUrlFields="Year"
DataNavigateUrlFormatString="referringdomains.aspx?forYear={0}"
DataTextField="Year" />
<asp:BoundField HeaderText="No. of Referring Domains"
DataField="NoOfReferringDomains" />
<asp:BoundField HeaderText="Referrers"
DataField="Referrers" />
</Columns>
</asp:GridView><br />
|