using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class webmain_stat_stat : System.Web.UI.UserControl
{
    ////常用变量的定义
    //public Cls_Operation Operation = new Cls_Operation();
    //public string OutputStr;
    //private string style = null;
    //public string showstyle
    //{
    //    get { return this.style; }
    //    set { this.style = value; }
    //}

    protected void Page_Load(object sender, EventArgs e)
    {
        ////网页立即超时
        //Response.Expires = 0;

        ////检查Cookie是否存在
        //bool isEcho = false;
        //string sSerialNumber = Operation.GetRandNumber(3, "DATE");
        //HttpCookie readCookie = Request.Cookies["XL_SN"];
        //if (readCookie != null && readCookie.Values["SN"] != null)
        //{
        //    isEcho = true;
        //}
        //if (!isEcho)
        //{
        //    HttpCookie Cookie = new HttpCookie("XL_SN");
        //    Cookie.Expires = DateTime.Now.AddDays(0.01);
        //    Cookie.Values.Add("SN", sSerialNumber);
        //    Response.AppendCookie(Cookie);
        //}

        ////获取客户端数据
        //string sIp = Operation.GetIP();
        //string sArea = Operation.GetArea();
        //string sUrl = Operation.GetSourceUrl();
        //string vUrl = Operation.GetVisitUrl();
        //string sOs = Operation.GetOS();
        //string sBrowser = Operation.GetBrowser();
        //string sLanguage = Operation.GetLanguage();
        //string sResolution = Operation.GetResolution();
        //string sVisitdate = DateTime.Now.ToString();

        ////保存客户端数据
        //Operation.ExecSql_Child("Insert Into Stat_Details(S_SerialNumber,S_IP,S_Area,S_SourceUrl,S_VisitUrl,S_OS,S_Browser,S_Language,S_Resolution,S_VisitDate) Values('" + Request.Cookies["XL_SN"].Values["SN"] + "','" + sIp + "','" + sArea + "','" + sUrl + "','" + vUrl + "','" + sOs + "','" + sBrowser + "','" + sLanguage + "','" + sResolution + "','" + sVisitdate + "')");

        ////统计
        //int iOnline = Operation.GetRecordCount_Child("Select Count(Distinct S_IP) As Counts From Stat_Details Where S_VisitDate >= '" + DateTime.Now.AddMinutes(-15) + "'");
        //int iTodayPV = Operation.GetRecordCount_Child("Select Count(*) As Counts From Stat_Details Where Datediff(day, S_VisitDate, Getdate()) = 0");
        //int iYesterdayPV = Operation.GetRecordCount_Child("Select Count(*) As Counts From Stat_Details Where Datediff(day, S_VisitDate, Getdate()) = 1");
        //int iTotalPV = Operation.GetRecordCount_Child("Select Count(*) As Counts From Stat_Details");
        //int iTodayIP = Operation.GetRecordCount_Child("Select Count(Distinct S_IP) As Counts From Stat_Details Where Datediff(day, S_VisitDate, Getdate()) = 0");
        //int iYesterdayIP = Operation.GetRecordCount_Child("Select Count(Distinct S_SerialNumber) As Counts From Stat_Details Where Datediff(day, S_VisitDate, Getdate()) = 1");
        //int iTotalIP = Operation.GetRecordCount_Child("Select Count(Distinct S_IP) As Counts From Stat_Details");
        //int iTodayUV = Operation.GetRowsCount_Child("Select Count(Distinct S_SerialNumber) As Counts From Stat_Details Where Datediff(day, S_VisitDate, Getdate()) = 0 Group By S_IP Having S_IP = S_IP");
        //int iYesterdayUV = Operation.GetRowsCount_Child("Select Count(Distinct S_SerialNumber) As Counts From Stat_Details Where Datediff(day, S_VisitDate, Getdate()) = 1 Group By S_IP Having S_IP = S_IP");
        //int iTotalUV = Operation.GetRowsCount_Child("Select Count(Distinct S_SerialNumber) As Counts From Stat_Details Group By S_IP Having S_IP = S_IP");
        //int iDepth = Operation.GetColsCount_Child("Select Count(Distinct S_VisitUrl) As Counts From Stat_Details Group By S_IP,S_SerialNumber Having S_IP = S_IP And S_SerialNumber = S_SerialNumber And Count(S_VisitUrl) > 1");

        ////保存统计数据
        //int iDay = DateTime.Now.Day;
        //int iMonth = DateTime.Now.Month;
        //int iYear = DateTime.Now.Year;
        //if (Operation.GetRecordCount_Child("Select Count(*) As Counts From Stat_Analysis") == 0)
        //{
        //    Operation.ExecSql_Child("Insert Into Stat_Analysis(S_PV,S_UV,S_IP,S_Date) Values(" + iTodayPV + "," + iTodayUV + "," + iTodayIP + ",'" + DateTime.Now.ToShortDateString() + "')");
        //}
        //else
        //{
        //    DateTime dateTime = Convert.ToDateTime(Operation.GetRecord_Child("Select S_Date From Stat_Analysis Order By S_Id Desc"));
        //    int iGetDay = dateTime.Day;
        //    int iGetMonth = dateTime.Month;
        //    int iGetYear = dateTime.Year;
        //    if (iGetDay == iDay && iGetMonth == iMonth && iGetYear == iYear)
        //    {
        //        Operation.ExecSql_Child("Update Stat_Analysis Set S_PV=" + iTodayPV + ",S_UV=" + iTodayUV + ",S_IP=" + iTodayIP + ",S_Date='" + DateTime.Now.ToShortDateString() + "' Where Datediff(day, S_Date, Getdate()) = 0");
        //    }
        //    else
        //    {
        //        Operation.ExecSql_Child("Insert Into Stat_Analysis(S_PV,S_UV,S_IP,S_Date) Values(" + iTodayPV + "," + iTodayUV + "," + iTodayIP + ",'" + DateTime.Now.ToShortDateString() + "')");
        //    }
        //}

        ////输出数据
        //if (this.showstyle != "")
        //{
        //    string OutStr = null;
        //    switch (this.showstyle)
        //    {
        //        case "text":
        //            OutStr = "旺客统计 - 你是本站的第 " + iTotalPV.ToString() + " 位访客";
        //            break;
        //        case "text1":
        //            OutStr = "旺客统计 - 当前在线：" + iOnline.ToString() + "人";
        //            break;
        //        case "text2":
        //            OutStr = "旺客统计 | 昨日访问量：" + iYesterdayPV.ToString() + " | 今日访问量：" + iTodayPV.ToString() + " | 总访问量：" + iTotalPV.ToString() + " | 当前在线：" + iOnline.ToString() + "人";
        //            break;
        //        case "text3":
        //            OutStr = "旺客统计 | 今日IP[" + iTodayIP.ToString() + "] | 今日PV[" + iTodayPV.ToString() + "] | 昨日IP[" + iYesterdayIP.ToString() + "] | 昨日PV[" + iYesterdayPV.ToString() + "] | 当前在线[" + iOnline.ToString() + "]";
        //            break;
        //        case "text4":
        //            OutStr = "旺客统计 <br /> 今日IP：" + iTodayIP.ToString() + " <br /> 今日PV：" + iTodayPV.ToString() + " <br /> 昨日IP：" + iYesterdayIP.ToString() + " <br /> 昨日PV：" + iYesterdayPV.ToString() + " <br /> 当前在线：" + iOnline.ToString() + "人";
        //            break;
        //        case "flash":
        //            OutStr = "<embed src='/images/counter.swf?cgi=load=start&total=" + iTotalPV + "&yes=" + iYesterdayPV + "&today=" + iTodayPV + "&you=0&load=end' type='application/x-shockwave-flash' width='130' height='58'></embed>";
        //            break;
        //        default:
        //            OutStr = "";
        //            break;
        //    }
        //    this.OutputStr = OutStr;
        //}
    }
}
