温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:简单网站计数器统(单用户)源码
当前文件:
SimpleWebStat/StatByBrowser.aspx.cs[1K,2009-6-12 11:54:10],打开代码结构图
SimpleWebStat/StatByBrowser.aspx.cs[1K,2009-6-12 11:54:10],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
13
public partial class StatByBrowser : System.Web.UI.Page 14
{ 15
protected int total = 0; 16
protected void Page_Load(object sender,EventArgs e) 17
{ 18
if(!Page.IsPostBack) 19
{ ///绑定控件的数据 20
BindVisitData(); 21
} 22
} 23
private void BindVisitData() 24
{ ///从数据库获取访问日志 25
IVisitor visit = new Visitor(); 26
SqlDataReader dr = visit.GetVisitors(); 27
///创建数组 28
ArrayList statList = new ArrayList(); 29
///读取数据 30
while(dr.Read()) 31
{ ///统计每种浏览器的访问量 32
AddStatByBrowser(dr,ref statList); 33
total++; 34
} 35
dr.Close(); 36
if(total > 0) 37
{ 38
for(int i = 0; i < statList.Count; i++) 39
{ ///计算每种浏览器访问量的百分比 40
((VisitStat)statList[i]).Percent = (int)((double)((VisitStat)statList[i]).Number * 100) / total; 41
} 42
} 43
///绑定数据 44
StatView.DataSource = statList; 45
StatView.DataBind(); 46
} 47
48
private void AddStatByBrowser(SqlDataReader dr,ref ArrayList statList) 49
{ ///获取浏览器的名称 50
string browserName = dr["Browser"].ToString(); 51
int i = 0; 52
for(i = 0; i < statList.Count; i++) 53
{ ///如果此浏览器已经统计,在数量加一 54
if(((VisitStat)statList[i]).Name == browserName) 55
{ 56
((VisitStat)statList[i]).Number++; 57
break; 58
} 59
} 60
///如果此浏览器没有被统计,则创建新的统计对象 61
if(i == statList.Count) 62
{ 63
VisitStat stat = new VisitStat(); 64
stat.Name = browserName; 65
stat.Number = 1; 66
stat.Percent = 0; 67
statList.Add(stat); 68
} 69
} 70
} 71






}
}