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 SKeyword : System.Web.UI.Page
    {
        /// <summary>
        /// 
        /// </summary>
        protected Model.StatInfo statModel = new Stat.Model.StatInfo();
        Model.PageInfo pageModel = new Stat.Model.PageInfo(50);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            statModel.WebID = Plugin.Common.Rq_Int("wid");
            //
            Stat.Security.ISecurity security = Stat.Security.DataFatory.CreateSecurity();
            security.CheckReportPower(statModel.WebID);
            //
            IList<Model.WebSites> website = Stat.Cache.CacheFatory.CreateWebSite().Get(statModel.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;

                statModel.StartTime = Plugin.Common.Rq_DateTime("st");
                statModel.EndTime = Plugin.Common.Rq_DateTime("et");
                statModel.EngineId = Plugin.Common.Rq_Int("e");
                statModel.EngineKeyWord = Plugin.Common.Rq("k");
                //
                DateTime dtNow = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                statModel.EndTime = statModel.EndTime > dtNow ? dtNow : statModel.EndTime;
                statModel.StartTime = statModel.StartTime > statModel.EndTime ? statModel.EndTime : statModel.StartTime;
                //
                Show();
            }
        }
        /// <summary>
        /// 获取数据
        /// </summary>
        protected void Show()
        {
            ShowHtml(BLL.ViewKeyword.Get(statModel));
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="list">数据</param>
        protected void ShowHtml(IList<Model.StatItem> list)
        {
            this.LtrKeyList.Text = Stat.Html.Engine.GetKey(list, pageModel.PageIndex, pageModel.PageSize, statModel.WebID, statModel.EngineId, statModel.StartTime.ToShortDateString(), statModel.EndTime.ToShortDateString());
            Response.Flush();
            if (list != null && list.Count > 1)
            {
                string urlPar = "wid=" + statModel.WebID + "&st=" + statModel.StartTime.ToShortDateString() + "&et=" + statModel.EndTime.ToShortDateString() + "&e=" + statModel.EngineId + "&k=" + statModel.EngineKeyWord;
                this.LtrKeywordPageIndex.Text = JPageIndex.GetIndex.Get(list.Count, pageModel.PageIndex, pageModel.PageSize, urlPar, 1, 0, 1, 7);
                Response.Flush();
            }
        }
    }
}