<%
'乘风多用户计数器 Sql版
'作者QQ：178575
'作者EMail：yliangcf@163.com
'作者网站：http://www.qqcf.com
'详细简介：http://www.qqcf.com/cfcount.htm
'上面有程序在线演示，安装演示，使用疑难解答，最新版本下载等内容
'因为这些内容可能时常更新，就没有放在程序里，请自己上网站上查看
'有完整版本的演示
%>
<%
AddYear_1=ChkStr(Request("AddYear_1"),2)
AddMonth_1=ChkStr(Request("AddMonth_1"),2)
AddYear_2=ChkStr(Request("AddYear_2"),2)
AddMonth_2=ChkStr(Request("AddMonth_2"),2)

If AddYear_1="" And AddMonth_1="" Or AddYear_2="" And AddMonth_2="" Then
 AddYear_2=Year(Now)
 AddMonth_2=Month(Now)
 
 MyDate=DateAdd("m",-1,Now)

 AddYear_1=Year(MyDate)
 AddMonth_1=Month(MyDate)
End If
%>

<form name="form2" method="post" action="?Action=<%=Action%>" onSubmit="return monthcheck();">
<table class="tb_1"><tr>
    <td>选择查询月份
<Select  name="addyear_1" size="1">
<option>请选择年份</option>
<%Sql="Select AddYear From CFCount_Alexa_Month Where UserName='"&UserName&"' Group By AddYear Order By AddYear Desc"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.open Sql,Conn,1,1

While Not Rs.Eof 
 Response.Write "<option value='"&Rs("AddYear")&"'"
 If Cstr(AddYear_1)=Cstr(Rs("AddYear")) Then Response.Write " selected"
 Response.Write ">"&Rs("AddYear")&"年</option>"  
Rs.MoveNext
Wend  
%>
        </select>

<Select  name="addmonth_1" size="1">
<option>请选择月份</option>
<%
For I = 1 To 12
 Response.Write "<option value='"&I&"'"
 If Cstr(AddMonth_1)=Cstr(I) Then Response.Write " selected"
 Response.Write ">"&I&"月</option>"
Next
%>
        </select>
-
<Select  name="addyear_2" size="1">
<option>请选择年份</option>
<%Sql="Select AddYear From CFCount_Alexa_Month Where UserName='"&UserName&"' Group By AddYear Order By AddYear Desc"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.open Sql,Conn,1,1

While Not Rs.Eof 
 Response.Write "<option value='"&Rs("AddYear")&"'"
 If Cstr(AddYear_2)=Cstr(Rs("AddYear")) Then Response.Write " selected"
 Response.Write ">"&Rs("AddYear")&"年</option>"  
Rs.MoveNext
Wend  
%>
        </select>

<Select  name="addmonth_2" size="1">
<option>请选择月份</option>
<%
For I = 1 To 12
 Response.Write "<option value='"&I&"'"
 If Cstr(AddMonth_2)=Cstr(I) Then Response.Write " selected"
 Response.Write ">"&I&"月</option>"
Next
%>
        </select>    
      
        <input type="submit" name="Submit3" value="查询">(可同时选择两个月份对比查询)
      </td>
  </tr>
</table></form>
  
<table class="tb_4">
<tr>
    <td width="50%" valign="top">
	<table class="tb_3" width="98%">
        <%
IpTotal=0
Session("CFCountTemp")=""
MyDate=AddYear_1&"-"&AddMonth_1&"-1"
Sql="Select Sum(IpCounter) From CFCount_Alexa_Day where UserName='"&UserName&"' And Datediff(m,AddDate,'"&MyDate&"')=0"
Set Rs=Conn.Execute(Sql)
IpTotal=Rs(0)


Sql="Select IpCounter,AddDate From CFCount_Alexa_Day where UserName='"&UserName&"' And Datediff(m,AddDate,'"&MyDate&"')=0"
Set Rs=Conn.Execute(Sql)
If Not Rs.eof Then
  Session("CFCountTemp")=Rs.GetRows(-1)
End If

Date_1=Cdate(AddYear_1&"-"&AddMonth_1&"-1")
Date_2=DateAdd("m",1,Date_1)

H=DateDiff("d",Date_1,Date_2)'取得一个月的天数
H_2=H

If Cstr(AddYear_1)=CStr(Year(Date)) And Cstr(AddMonth_1)=CStr(Month(Date)) Then H_2=Day(now)
%>
	<tr class="tr_1">
          <td colspan="3"><%=AddYear_1%>年<%=AddMonth_1%>月Alexa报表</td>
        </tr>
        <tr class="tr_2"> 
          <td>&nbsp;</td>
          <td colspan="2">唯一IP</td>
        </tr>
        <tr class="tr_2"> 
          <td>&nbsp;</td>
          <td colspan="2">共&nbsp;<%=IpTotal%>&nbsp;IP,平均每天&nbsp;<%=Int(IpTotal/H_2)%>&nbsp;IP</td>
        </tr>
        <tr class="tr_2"> 
          <td>日期</td>
          <td colspan="2">IP数量</td>
        </tr>
<%
I=0
For I=1 To H
ShowNum=0
IpNum=0
J=0
For J=0 To Ubound(Session("CFCountTemp"),2)
 If Day(Cdate(Session("CFCountTemp")(1,J)))=I Then
  IpNum=Session("CFCountTemp")(0,J)
 End If
Next
%>
        <tr class="tr_2" title="<%=GetWeek(AddYear_1&"-"&AddMonth_1&"-"&I)%>"> 
          <td><%=I%>日</td>
          <td><%=IpNum%></td>
          <td class="td_1"><img src=images/bar_green.gif width=<%=CInt(IpNum/IpTotal*60)%> height=10><%=MyRate(IpNum,IpTotal)%>%</td>
        </tr>
        <%
Next%>
      </table></td>
     <td width="50%" valign="top">	<table class="tb_3" width="98%">


        <%
IpTotal=0
Session("CFCountTemp")=""
MyDate=AddYear_2&"-"&AddMonth_2&"-1"
Sql="Select Sum(IpCounter) From CFCount_Alexa_Day where UserName='"&UserName&"' And Datediff(m,AddDate,'"&MyDate&"')=0"
Set Rs=Conn.Execute(Sql)
IpTotal=Rs(0)


Sql="Select IpCounter,AddDate From CFCount_Alexa_Day where UserName='"&UserName&"' And Datediff(m,AddDate,'"&MyDate&"')=0"
Set Rs=Conn.Execute(Sql)
If Not Rs.eof Then
  Session("CFCountTemp")=Rs.GetRows(-1)
End If

Date_1=Cdate(AddYear_2&"-"&AddMonth_2&"-1")
Date_2=DateAdd("m",1,Date_1)

H=DateDiff("d",Date_1,Date_2)'取得一个月的天数
H_2 = H

If Cstr(AddYear_2)=CStr(Year(Date)) And Cstr(AddMonth_2)=CStr(Month(Date)) Then H_2=Day(now)
%>
	<tr class="tr_1">
          <td colspan="3"><%=AddYear_2%>年<%=AddMonth_2%>月Alexa报表</td>
        </tr>
        <tr class="tr_2"> 
          <td>&nbsp;</td>
          <td colspan="2">唯一IP</td>
        </tr>
        <tr class="tr_2"> 
          <td>&nbsp;</td>
          <td colspan="2">共&nbsp;<%=IpTotal%>&nbsp;IP,平均每天&nbsp;<%=Int(IpTotal/H_2)%>&nbsp;IP</td>
        </tr>
        <tr class="tr_2"> 
          <td>日期</td>
          <td colspan="2">IP数量</td>
        </tr>
        <%
I=0
For I=1 To H
ShowNum=0
IpNum=0
J=0
For J=0 To Ubound(Session("CFCountTemp"),2)
 If Day(Cdate(Session("CFCountTemp")(1,J)))=I Then
  IpNum=Session("CFCountTemp")(0,J)
 End If
Next
%>
        <tr  class="tr_2" title="<%=GetWeek(AddYear_2&"-"&AddMonth_2&"-"&I)%>"> 
          <td><%=I%>日</td>
          <td><%=IpNum%></td>
          <td class="td_1"><img src=images/bar_green.gif width=<%=CInt(IpNum/IpTotal*60)%> height=10><%=MyRate(IpNum,IpTotal)%>%</td>
        </tr>
        <%
Next%>
      </table></td>
  </tr>
</table>