<%
'乘风多用户计数器 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_Count_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_Count_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_1">
<TR class="tr_2">
<TD>
<%
Session("CFCountTemp")=""
Sql="Select MyCounter,IpCounter,AddDate From CFCount_Count_Day where UserName='"&UserName&"' And Datediff(m,AddDate,'"&AddYear_2&"-"&AddMonth_2&"-1"&"')=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)'取得一个月的天数

For I=1 To H
ShowNum=0
IpNum=0
J=0

For J=0 To Ubound(Session("CFCountTemp"),2)
 If Day(Cdate(Session("CFCountTemp")(2,J)))=I Then
  ShowNum=Session("CFCountTemp")(0,J)
  IpNum=Session("CFCountTemp")(1,J)
 End If
Next

TitleStr=TitleStr&"<category label='"&I&"日' />"
IpStr=IpStr & "<set value='"&IpNum&"' />"
PvStr=PvStr & "<set value='"&ShowNum&"' />"

Next


%>
<OBJECT classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=750 height=450>
<PARAM NAME="FlashVars" VALUE="dataXML=<graph caption='天统计' subcaption='<%=AddYear_2%>年<%=AddMonth_2%>月' showFCMenuItem='0' lineThickness='1' showValues='0' formatNumberScale='0' anchorRadius='3'   divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='10' alternateHGridColor='#CCCC00' shadowAlpha='40' numvdivlines='5'  bgColor='cccccc,cccccc' bgAngle='270' bgAlpha='10,10' baseFontSize='12' bordercolor='ffffff'  rotateNames='1' slantLabels='1'><categories ><%=TitleStr%></categories><dataset seriesName='IP' color='1D8BD1' anchorBorderColor='1D8BD1' anchorBgColor='1D8BD1'><%=IpStr%></dataset><dataset seriesName='PV' color='F1683C' anchorBorderColor='F1683C' anchorBgColor='F1683C'><%=PvStr%></dataset></graph>">
<PARAM NAME="movie" VALUE="images/MSLine.swf">
<embed src="images/MSLine.swf" width="750" height="450" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" FlashVars="dataXML=<graph caption='天统计' subcaption='<%=AddYear_2%>年<%=AddMonth_2%>月' showFCMenuItem='0' lineThickness='1' showValues='0' formatNumberScale='0' anchorRadius='3'   divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='10' alternateHGridColor='#CCCC00' shadowAlpha='40' numvdivlines='5'  bgColor='cccccc,cccccc' bgAngle='270' bgAlpha='10,10' baseFontSize='12' bordercolor='ffffff'  rotateNames='1' slantLabels='1'><categories ><%=TitleStr%></categories><dataset seriesName='IP' color='1D8BD1' anchorBorderColor='1D8BD1' anchorBgColor='1D8BD1'><%=IpStr%></dataset><dataset seriesName='PV' color='F1683C' anchorBorderColor='F1683C' anchorBgColor='F1683C'><%=PvStr%></dataset></graph>"></embed>
</OBJECT>
</TD></TR>
<table>	


<table class="tb_4">
<tr>
    <td width="50%" valign="top">
	<table class="tb_3" width="98%">
<%
ShowTotal=0
IpTotal=0
Session("CFCountTemp")=""
MyDate=AddYear_1&"-"&AddMonth_1&"-1"
Sql="Select Sum(MyCounter),Sum(IpCounter) From CFCount_Count_Day where UserName='"&UserName&"' And Datediff(m,AddDate,'"&MyDate&"')=0"
Set Rs=Conn.Execute(Sql)
ShowTotal=Rs(0)
IpTotal=Rs(1)


Sql="Select MyCounter,IpCounter,AddDate From CFCount_Count_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="5"><%=AddYear_1%>年<%=AddMonth_1%>月报表</td>
        </tr>
        <tr class="tr_2"> 
          <td>&nbsp;</td>
          <td colspan="2">PV访问量</td>
          <td colspan="2">唯一IP</td>
        </tr>
        <tr class="tr_2"> 
          <td>&nbsp;</td>
          <td colspan="2">共<%=ShowTotal%>次,平均每天<%=Int(ShowTotal/H_2)%>次</td>
          <td colspan="2">共<%=IpTotal%>IP,平均每天<%=Int(IpTotal/H_2)%>IP</td>
        </tr>
        <tr class="tr_2"> 
          <td>日期</td>
          <td colspan="2">显示数量</td>
          <td colspan="2">IP数量</td>
        </tr>
<%
For I=1 To H
ShowNum=0
IpNum=0
J=0

For J=0 To Ubound(Session("CFCountTemp"),2)
 If Day(Cdate(Session("CFCountTemp")(2,J)))=I Then
  ShowNum=Session("CFCountTemp")(0,J)
  IpNum=Session("CFCountTemp")(1,J)
 End If
Next

%>
        <tr class="tr_2" title="<%=GetWeek(AddYear_1&"-"&AddMonth_1&"-"&I)%>"> 
          <td class="td_nowrap"><%=I%>日</td>
          <td><%=ShowNum%></td>
          <td class="td_1"><img src=images/bar_blue.gif width=<%=CInt(ShowNum/ShowTotal*60)%> height=10><%=MyRate(ShowNum,ShowTotal)%>%</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 valign="top">
	<table class="tb_3" width="98%">
<%
ShowTotal=0
IpTotal=0
Session("CFCountTemp")=""
MyDate=AddYear_2&"-"&AddMonth_2&"-1"
Sql="Select Sum(MyCounter),Sum(IpCounter) From CFCount_Count_Day where UserName='"&UserName&"' And Datediff(m,AddDate,'"&MyDate&"')=0"
Set Rs=Conn.Execute(Sql)
ShowTotal=Rs(0)
IpTotal=Rs(1)


Sql="Select MyCounter,IpCounter,AddDate From CFCount_Count_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="5"><%=AddYear_2%>年<%=AddMonth_2%>月报表</td>
        </tr>
        <tr class="tr_2"> 
          <td>&nbsp;</td>
          <td colspan="2">PV访问量</td>
          <td colspan="2">唯一IP</td>
        </tr>
        <tr class="tr_2"> 
          <td>&nbsp;</td>
          <td colspan="2">共<%=ShowTotal%>次,平均每天<%=Int(ShowTotal/H_2)%>次</td>
          <td colspan="2">共<%=IpTotal%>IP,平均每天<%=Int(IpTotal/H_2)%>IP</td>
        </tr>
        <tr class="tr_2"> 
          <td>日期</td>
          <td colspan="2">显示数量</td>
          <td colspan="2">IP数量</td>
        </tr>
<%
For I=1 To H
ShowNum=0
IpNum=0
J=0

For J=0 To Ubound(Session("CFCountTemp"),2)
 If Day(Cdate(Session("CFCountTemp")(2,J)))=I Then
  ShowNum=Session("CFCountTemp")(0,J)
  IpNum=Session("CFCountTemp")(1,J)
 End If
Next

%>
        <tr class="tr_2" title="<%=GetWeek(AddYear_2&"-"&AddMonth_2&"-"&I)%>"> 
          <td class="td_nowrap"><%=I%>日</td>
          <td><%=ShowNum%></td>
          <td class="td_1"><img src=images/bar_blue.gif width=<%=CInt(ShowNum/ShowTotal*60)%> height=10><%=MyRate(ShowNum,ShowTotal)%>%</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>