using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace Stat.Html
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>Juju 2011-11-2</remarks>
    public class ReportPage : System.Web.UI.Page, IHttpHandler, IRequiresSessionState
    {

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            //安全检查
            Stat.Security.ISecurity security = Stat.Security.DataFatory.CreateSecurity();
            security.CheckReportPower(Webid);
        }

        public ReportPage()
        {
            if (this.EndTime.Subtract(this.StartTime).TotalDays > 30)
            {
                Response.Write("请不要手动修改地址栏参数，2个时间差不能够大于30天!");
                Response.End();
            }

        }
        /// <summary>
        /// 搜索引擎ID
        /// </summary>
        public int EngineId { get { return Plugin.Common.Rq_Int("e"); } }
        /// <summary>
        /// 搜索关键字
        /// </summary>
        public string Keyword { get { return Plugin.Common.Rq("k"); } }
        /// <summary>
        /// 站点ID
        /// </summary>
        public int Webid { get { return Plugin.Common.Rq_Int("wid"); } }
        /// <summary>
        /// 查询IP
        /// </summary>
        public string ParmIp { get { return Plugin.Common.Rq("ip"); } }
        /// <summary>
        /// 浏览器ID
        /// </summary>
        public int ParmBrowserID { get { return Plugin.Common.Rq_Int("bs"); } }
        /// <summary>
        /// 操作系统ID
        /// </summary>
        public int ParmOperatingSystemId { get { return Plugin.Common.Rq_Int("sys"); } }
        /// <summary>
        /// 分辨率Id
        /// </summary>
        public int ParmResolutionId { get { return Plugin.Common.Rq_Int("rs"); } }
        /// <summary>
        /// 语言ID
        /// </summary>
        public int ParmLanguageId { get { return Plugin.Common.Rq_Int("lg"); } }
        /// <summary>
        /// 颜色质量
        /// </summary>
        public int ParmColorDepthId { get { return Plugin.Common.Rq_Int("cd"); } }
        /// <summary>
        /// 来访次数
        /// </summary>
        public int ParmVisitNumber { get { return Plugin.Common.Rq_Int("ru"); } }
        /// <summary>
        /// NetClrVersion版本
        /// </summary>
        public int ParmNetClrVersionId { get { return Plugin.Common.Rq_Int("fw"); } }
        /// <summary>
        /// 栏目ID
        /// </summary>
        public int ParmCoId { get { return Plugin.Common.Rq_Int("co"); } }
        /// <summary>
        /// 
        /// </summary>
        public int ParmCtId { get { return Plugin.Common.Rq_Int("ct"); } }
        /// <summary>
        /// 是否安装了Alexa
        /// </summary>
        public int ParmIsAlexa { get { return HttpContext.Current.Request["ax"] == null ? -1 : Plugin.Common.Rq_Int("ax"); } }
        /// <summary>
        /// 是否支持Java脚本
        /// </summary>
        public int ParmIsJava { get { return HttpContext.Current.Request["ja"] == null ? -1 : Plugin.Common.Rq_Int("ja"); } }

        /// <summary>
        /// 当前页面索引
        /// </summary>
        public int PageIndex
        {
            get
            {
                int pageIndex = Plugin.Common.Rq_Int("page");
                return pageIndex > 0 ? pageIndex : 1;
            }
        }
        /// <summary>
        /// 开始时间（默认今日开始时刻）
        /// </summary>
        public DateTime StartTime
        {
            get
            {
                DateTime st = Plugin.Common.Rq_DateTime("st");
                if (st < DateTime.Parse("2000-1-1 00:00:00"))
                    return Convert.ToDateTime(DateTime.Now.ToShortDateString());
                return st > EndTime ? EndTime : st;
            }
        }
        /// <summary>
        /// 结束时间（最大值 明日开始时刻）（默认明日开始时刻）
        /// </summary>
        public DateTime EndTime
        {
            get
            {
                DateTime et = Plugin.Common.Rq_DateTime("et");
                DateTime dtNow = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString());
                if (et < DateTime.Parse("2000-1-1 00:00:00"))
                    return dtNow;
                return et > dtNow ? dtNow : et;

            }
        }
        /// <summary>
        /// 站点信息
        /// </summary>
        public Model.WebSites Website
        {
            get
            {
                Model.WebSites site = Stat.Cache.CacheFatory.CreateWebSite().Get(Webid);
                if (site != null)
                    return site;
                else
                    return new Model.WebSites();
            }

        }

    }
}
