⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 count.aspx.cs

📁 数据库设计2.页面的设计与开发3.小结第8章在线考试系统 161 实例分析 161 1. 系统设计2.系统功能预览知识要点 167 制作步骤 168 1 ... 利用简单的HTML代码与脚本 融合而成
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Dundas.Charting.WebControl;

namespace SimplexShop.Count
{
	/// <summary>
	/// Count 的摘要说明。
	/// </summary>
	public class Count : System.Web.UI.Page
	{
		protected Dundas.Charting.WebControl.Chart Chart1;
		private DateTime StartTime;
		private DateTime EndTime;
		private OleDbConnection myConnection;
		protected System.Web.UI.WebControls.Label lblTittle;
		protected System.Web.UI.HtmlControls.HtmlTableCell CellDetail;
		protected Dundas.Charting.WebControl.Chart Chart2;
		protected System.Web.UI.WebControls.DataGrid dg20List;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			StartTime = DateTime.Now.AddDays(-30);
			EndTime = DateTime.Now;
			myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("data/count15.mdb"));

			if(!IsPostBack)
			{
				BindCount(); 
			}

		}

		private void BindCount()
		{   
			if(Request.QueryString["act"] == null )
			{
				//简要数据
				this.lblTittle.Text="简要数据";
				this.Chart1.Visible=false;
				BindDetail();
			}
			else
			{
				switch(Request.QueryString["act"].ToString())
				{
						//简要数据
					case "main":
						this.lblTittle.Text="简要数据";
						this.Chart1.Visible=false;
						BindDetail();
						break;
						//系统/浏览器统计
					case "osexp":
						this.lblTittle.Text="系统/浏览器统计";
						this.Chart1.Visible=true;
						BindOsexp();
						break;
						//来源统计
					case "referer":
						this.lblTittle.Text="来源统计";
						this.Chart1.Visible=false;
						this.Chart2.Visible=true;
						BindReferer();
						break;
						//24小时统计
					case "hour":
						this.lblTittle.Text="24小时统计";
						this.Chart1.Visible=true;
						BindHour();
						break;
						//日统计
					case "day":
						this.lblTittle.Text="日统计";
						this.Chart1.Visible=true;
						BindDay();
						break;
						//月统计
					case "month":
						this.lblTittle.Text="月统计";
						this.Chart1.Visible=true;
						BindMonth();
						break;
						//地区统计
					case "where":
						this.lblTittle.Text="地区统计";
						this.Chart1.Visible=false;
						this.Chart2.Visible=true;
						BindWhere();
						break;
						//来访者信息列表
					case "last20":
						this.lblTittle.Text="来访者信息列表";
						this.Chart1.Visible=false;
						this.dg20List.Visible=true;
						BindLast20();
						break;
						//其它情况
					default:
						this.lblTittle.Text="简要数据";
						this.Chart1.Visible=false;
						BindDetail();
						break;
				}
			}
		}
 

		private void BindDetail()
		{
			string vSql = "select WebName,WebUrl,WebExp,WebEmail,WebMaster,WebCountTime from WebInfo";
		    DataRow vDr=GetDr(vSql);

			string WebName = vDr["WebName"].ToString();
			string WebUrl = vDr["WebUrl"].ToString();
			string WebExp = vDr["WebExp"].ToString();
			string WebEmail = vDr["WebEmail"].ToString();
			string WebMaster = vDr["WebMaster"].ToString();
			DateTime WebCountTime = (DateTime)vDr["WebCountTime"];
			vDr=null;
		 
 
			//统计总人数
			vSql = "select Sum(cCMC) as vCount from cM";
			vDr = GetDr(vSql);
			int vCount=Convert.ToInt32(vDr["vCount"].ToString());
			vDr=null;

			//统计今日访问量和计算今日访问量预测
			int vCha=DateTime.Now.Hour+1;
			vSql = "select cTDC from cD where cDay ="+DateTime.Now.Date.Day.ToString();
			vDr = GetDr(vSql);
			decimal vToday = Convert.ToDecimal(vDr["cTDC"].ToString());
			int vYToday = (int)Math.Round(vToday/vCha*24);
			vDr=null;

			//统计天数和平均日访问量
			TimeSpan vCDateTimeSpan = DateTime.Now.Date-WebCountTime.Date;
			int vCDate =(int)vCDateTimeSpan.TotalDays;
			int  vAveCount=0; 
			if(vCDate == 0)
			{
				vAveCount = 0;
				}
			else
			{
				vAveCount = (int)Math.Round((vCount-vToday)/vCDate);
				}
			
			//年访问量和月访问量
			vSql = "select cTMC from cM where cMonth="+DateTime.Now.Date.Month.ToString();
			vDr = GetDr(vSql);
			int vMCount =(int)vDr["cTMC"];
			vDr=null;

			vSql = "select refurbish from flux where id=1";
			vDr = GetDr(vSql);
			float vref = (float)vDr["refurbish"];
			vDr=null;
	 
			string str = "<br><table width=90% border=0 cellpadding=2><tr><td>网站名称:</td><td>"+WebName+"</td><td>网站地址:</td><td><a href="+WebUrl+" target=_blank>"+WebUrl+"</a></td></tr><tr><td>网站管理员:</td><td>"+WebMaster+"</td><td>网站信箱:</td><td><a href='mailto:"+WebEmail+"'>"+WebEmail+"</a></td></tr><tr><td width=14% height=22 valign=top>网站介绍:</td><td colspan=3>"+WebExp+"</td></tr><tr><td colspan=4><hr size=1 noshade></td></tr><tr><td>总访问人数:</td><td width=41% >"+vCount+"</td><td width=14% >开始统计日期:</td><td width=31% >"+WebCountTime.Date.ToLongDateString()+"</td></tr><tr><td>今日访问量:</td><td>"+vToday+"</td><td>本月访问量:</td><td>"+vMCount+"</td></tr><tr><td>统计天数:</td><td>"+vCDate+"</td><td>平均日访问量:</td><td>"+vAveCount+"</td></tr><td nowrap>整站页面刷新:</td><td>"+vref+"</td><td nowrap>预计本日访问量:</td><td>"+vYToday+"</td></tr></table>";
			this.CellDetail.InnerHtml=str;
		}

		/// <summary>
		/// 系统/浏览器统计
		/// </summary>
		private void BindOsexp()
		{
			/*
			 *小技巧:当你不知道一个变量如何负值时可以用"= new" 来提示你,但之后一定要去了"new".
			*/
			//系统统计,注意数据绑定的方法 
			//为Series["Default"]设置画图区
			Chart1.Series["Default"].ChartArea = "Chart Area 1";
			Chart1.Series["Default"].LegendText="操作系统统计";
			Chart1.ChartAreas["Chart Area 1"].AxisX.Interval=1;
			Chart1.Series["Default"].XValueType=ChartValueTypes.String;
 
		
			string vSql = "select cO.cOS,cO.cCOC from cO order by cO.cCOC asc";
 
			// create a database command on the connection using query    
			OleDbCommand myCommand = new OleDbCommand(vSql, myConnection);

			// open the connection    
			myConnection.Open();

			// create a database reader    
			OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

			// since the reader implements IEnumerable, pass the reader directly into
			//   the DataBind method with the name of the Column selected in the query    
			Chart1.Series["Default"].Points.DataBindXY(myReader, "cOS", myReader, "cCOC");

			// close the reader and the connection
			myReader.Close();


			//浏览器统计
			//为Series["Series2"]设置画图区
			Chart1.Series["Series2"].ChartArea = "Chart Area 2";
			Chart1.Series["Series2"].LegendText="浏览器统计";
			Chart1.Series["Series2"].XValueType=ChartValueTypes.String;
			Chart1.ChartAreas["Chart Area 2"].AxisX.Interval=1;
			
			string vSql2 = "select cE.cExplorer,cE.cCEC from cE order by cE.cCEC asc";
			// create a database command on the connection using query    
			OleDbCommand myCommand2 = new OleDbCommand(vSql2, myConnection);

			// open the connection    
			myConnection.Open();

			// create a database reader    
			OleDbDataReader myReader2 = myCommand2.ExecuteReader(CommandBehavior.CloseConnection);

			// since the reader implements IEnumerable, pass the reader directly into
			//   the DataBind method with the name of the Column selected in the query    
			Chart1.Series["Series2"].Points.DataBindXY(myReader2, "cExplorer", myReader2, "cCEC");

			// close the reader and the connection
			myReader2.Close();
		}

		/// <summary>
		/// 来源统计
		/// </summary>
		private void BindReferer()
		{
			//系统统计,注意数据绑定的方法 
			//为Series["Default"]设置画图区
			Chart2.Series["Default"].ChartArea = "Chart Area 1";
			Chart2.Series["Default"].LegendText="前20位来源统计";		
			Chart2.Series["Default"].XValueType=ChartValueTypes.String;
			Chart2.Series["Default"].YValueType=ChartValueTypes.Double;
			Chart2.ChartAreas["Chart Area 1"].AxisX.Interval=1;
			 
		

		
			string vSql = "select top 20 cR.cReferer,cR.cCRC from cR order by cR.cCRC desc";
 
			// create a database command on the connection using query    
			OleDbCommand myCommand = new OleDbCommand(vSql, myConnection);

			// open the connection    
			myConnection.Open();

			// create a database reader    
			OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

			// since the reader implements IEnumerable, pass the reader directly into
			//   the DataBind method with the name of the Column selected in the query    
			Chart2.Series["Default"].Points.DataBind(
				myReader, 
				"cReferer", 
                 "cCRC", 
				"Label=cCRC");



			// close the reader and the connection
			myReader.Close();
 
		}

		/// <summary>
		/// 24小时统计
		/// </summary>
		private void BindHour()
		{
		 
			//update 
			string strUpdate="update cH set cTHC=0,HMD=now() where DATEDIFF('h',HMD,Now()) > 23 ";  
			OleDbCommand myCommandUpdate = new OleDbCommand(strUpdate, myConnection);
			myConnection.Open();
			myCommandUpdate.ExecuteNonQuery();
			myConnection.Close();

			// 过去24小时统计  
			string vSql = "select cHour,cTHC from cH order by cHour asc";
 
			DataSet ds=GetDs(vSql);
			DataRow dr;
			int j=DateTime.Now.Hour;
			int k=DateTime.Now.Hour;
			for(int i=0;i<24;i++)
			{   
				dr=ds.Tables[0].Rows[k];
                Chart1.Series["Default"].Points.AddXY(DateTime.Now.Date.AddHours(j),Convert.ToDouble(dr["cTHC"].ToString()));
				j--;
				k--;
				if(k<0)
				{
				  k=23;
				}
			 
			}
 
			//为Series["Default"]设置画图区
			Chart1.Series["Default"].ChartArea = "Chart Area 1";
			Chart1.Series["Default"].LegendText="过去24小时统计";
			Chart1.ChartAreas["Chart Area 1"].AxisX.LabelStyle.Format="t";//X轴设置为短时间形式
			SetAxisInterval(Chart1.ChartAreas["Chart Area 1"].AxisX,1,DateTimeIntervalType.Hours);
//			Chart1.ChartAreas["Chart Area 1"].AxisX.Interval=1;
//			Chart1.ChartAreas["Chart Area 1"].AxisY.Interval=1;


 
			//所有24小时的统计
			//绑定数据
			string vSqlAll = "select cH.cHour,cH.cCHC  from cH  order by cHour asc";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -