using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
namespace Stat.web.v
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>By ： Juju 2010-12-11</remarks>
    public partial class SEngineList : System.Web.UI.Page
    {
        Model.PageInfo pageModel = new Stat.Model.PageInfo(10);
        /// <summary>
        /// 
        /// </summary>
        protected Model.SearchInfo searchModel = new Stat.Model.SearchInfo();
        /// <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") < 1 ? 1 : Plugin.Common.Rq_Int("page");
                searchModel.EngineID = Plugin.Common.Rq_Int("e");
                searchModel.KeyWord = Plugin.Common.Rq("k");
                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.EndTime = searchModel.EndTime.AddDays(1);
                Show();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        protected void Show()
        {
            List<Model.ViewOnClick> list = BLL.ViewOnClickPageIndex.GetEngineList(ref pageModel, searchModel);
            this.LtrEngineList.Text = Stat.Html.Engine.GetList(list, pageModel.PageIndex, pageModel.PageSize, searchModel.WebID, searchModel.StartTime.ToShortDateString(), searchModel.EndTime.ToShortDateString());
            Response.Flush();

            if (list != null && list.Count > 0)
            {
                string _Par = "wid=" + searchModel.WebID + "&st=" + searchModel.StartTime.ToShortDateString() + "&et=" + searchModel.EndTime.ToShortDateString() + "&e=" + searchModel.EngineID + "&k=" + searchModel.KeyWord;
                this.LtrEnginePageIndex.Text = JPageIndex.GetIndex.Get(pageModel.RecordCount, pageModel.PageIndex, pageModel.PageSize, _Par, 1, 0, 1, 5);
                Response.Flush();
            }
        }
    }
}