using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;

namespace Stat.web.v
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Vpage : System.Web.UI.Page
    {
        /// <summary>
        /// 
        /// </summary>
        protected Model.SearchInfo searchModel = new Stat.Model.SearchInfo();
        Model.PageInfo pageModel = new Stat.Model.PageInfo(20);
        string strUrlParmar = "";
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            searchModel.WebID = Plugin.Common.Rq_Int("wid");
            //
            Stat.Security.ISecurity security = Stat.Security.DataFatory.CreateSecurity();
            security.CheckReportPower(searchModel.WebID);
            //
            IList<Model.WebSites> website = Stat.Cache.CacheFatory.CreateWebSite().Get(searchModel.WebID);
            if (website.Count > 0)
            {
                this.Page.Title = "受访页面分析 " + website[0].WebName; ;
                pageModel.PageIndex = Plugin.Common.Rq_Int("page");
                pageModel.PageIndex = pageModel.PageIndex < 1 ? 1 : pageModel.PageIndex;
                //
                searchModel.StartTime = Plugin.Common.Rq_DateTime("st");
                searchModel.EndTime = Plugin.Common.Rq_DateTime("et");
                DateTime dtNow = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                searchModel.EndTime = searchModel.EndTime > dtNow ? dtNow : searchModel.EndTime;
                searchModel.StartTime = searchModel.StartTime > searchModel.EndTime ? searchModel.EndTime : searchModel.StartTime;
                //
                searchModel.IP = Plugin.Common.Rq("ip");
                //
                searchModel.BrowserID = Plugin.Common.Rq_Int("bs");
                searchModel.OperatingSystemId = Plugin.Common.Rq_Int("sys");
                searchModel.ResolutionId = Plugin.Common.Rq_Int("rs");
                searchModel.LanguageId = Plugin.Common.Rq_Int("lg");
                searchModel.ColorDepthId = Plugin.Common.Rq_Int("cd");
                searchModel.View_Alone = Plugin.Common.Rq_Int("ru");
                searchModel.NetClrVersionId = Plugin.Common.Rq_Int("fw");
                searchModel.CoId = Plugin.Common.Rq_Int("co");
                searchModel.CtId = Plugin.Common.Rq_Int("ct");
                //
                searchModel.IsAlexa = HttpContext.Current.Request["ax"] == null ? -1 : Plugin.Common.Rq_Int("ax");
                searchModel.IsJava = HttpContext.Current.Request["ja"] == null ? -1 : Plugin.Common.Rq_Int("ja");
                //
                Show();
            }
        }

        /// <summary>
        /// 分析数据
        /// </summary>
        protected void Show()
        {
            strUrlParmar = Plugin.Common.GetVpageParmar(searchModel);
            ShowHtml(BLL.ViewOnClickPageIndex.GetList(ref pageModel, searchModel));
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="list"></param>
        protected void ShowHtml(List<Model.ViewOnClick> list)
        {
            this.LtrVpagetList.Text = Stat.Html.Vpage.Get(list, pageModel, searchModel.WebID, searchModel.IP, searchModel.StartTime, searchModel.EndTime);

            if (list != null && list.Count > 0)
            {
                string urlPar = "wid=" + searchModel.WebID + "&st=" + searchModel.StartTime + "&et=" + searchModel.EndTime.ToShortDateString() + "&ip=" + searchModel.IP;
                urlPar += Plugin.Common.GetVpageParmar(searchModel);
                this.LtrVpagePageIndex.Text = JPageIndex.GetIndex.Get(pageModel.RecordCount, pageModel.PageIndex, pageModel.PageSize, 0, 1, urlPar);

                Response.Flush();
            }
        }
    }
}