Asp.net源码专业站
首页->聊天计数->简单网站计数器统(单用户)源码>>StatByBrowser.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:简单网站计数器统(单用户)源码
当前文件:文件类型 SimpleWebStat/StatByBrowser.aspx.cs[1K,2009-6-12 11:54:10]打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.Data.SqlClient; 12 13public 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
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:简单网站计数器统(单用户)源码
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146