📄 tj_ip.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace counter
{
/// <summary>
/// tj_ip 的摘要说明。
/// </summary>
public class tj_ip : System.Web.UI.Page
{
public static DataView dv;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
DataSet myds = new DataSet();
myds = counter.SQLConn.ExecuteSqlForDataSet("select * from CounterInfo");
dv=myds.Tables[0].DefaultView;
if(Session["master"]==null) Session["master"]="";
if(Session["whatcan"]==null) Session["whatcan"]=dv[0].Row["whatcan"].ToString();
if(Session["master"].ToString() != "master" && int.Parse(Session["whatcan"].ToString()) < 2) Response.Redirect("help.aspx?id=004&error=您没有查看IP统计的权限。");
}
public string show_ip_data()
{
string strshow_ip_data_msg="";
string strtheip;
string strvallip;
string strsvip="";
int lsbf;
DataSet myds1 = new DataSet();
DataView dv1=new DataView();
myds1=counter.SQLConn.ExecuteSqlForDataSet("select vip,count(id) as allip from CounterView group by vip order by count(id) DESC");
dv1=myds1.Tables[0].DefaultView;
dv1.Table.AcceptChanges();
int intmaxallip=0;
int intsumallip=0;
for(int i=0;i<dv1.Count;i++)
{
if(int.Parse(dv1[i].Row["allip"].ToString())>intmaxallip) intmaxallip=int.Parse(dv1[i].Row["allip"].ToString());
intsumallip+=int.Parse(dv1[i].Row["allip"].ToString());
}
//防止除数为0出错
if (intmaxallip==0) intmaxallip=1;
if (intsumallip==0) intsumallip=1;
int j=0;
for (int i=0;i<dv1.Count;i++)
{
strtheip=dv1[i].Row["vip"].ToString();
strvallip=dv1[i].Row["allip"].ToString();
int intthelen=strtheip.Length;
if (intthelen ==0)
{
strtheip="main.aspx";
strsvip="通过收藏或直接输入网址访问";
}
if (intthelen >0 && intthelen<=33)
{
strsvip=strtheip;
}
if (intthelen >=34)
{
strsvip=strtheip.Substring(0,33)+"...";
}
strshow_ip_data_msg+="<tr><td width='120' align=right><a title='"+strtheip+",访问"+strvallip+"次,";
//计算访问量的百分数,精确到小数后1位,小于零的在前面加字母0
lsbf=(int)(int.Parse(strvallip.ToString())*1000/intsumallip)/10;
strshow_ip_data_msg+=lsbf+"%'>"+strsvip+"</a> </td>";
strshow_ip_data_msg+="<td width='230' background='images/tu_back_2.gif' align=left>";
strshow_ip_data_msg+="<img style='BORDER-left: #000000 1px solid;' src='images/tu.gif'";
strshow_ip_data_msg+=" width='"+(int)(float.Parse(strvallip.ToString())/intmaxallip*183)+"' height='9' alt='"+strtheip+",访问"+strvallip+"次,";
strshow_ip_data_msg+=lsbf+"%'> "+strvallip+"</td></tr>";
j++;
if(j>=40) break;
}
dv1.Dispose();
return strshow_ip_data_msg;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -