using System;
using System.Collections.Generic;
namespace Stat.web.v
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>By juju：2010-10-13</remarks>
    public partial class STimeflux : System.Web.UI.Page
    {
        Stat.Cache.IConfig config = Stat.Cache.CacheFatory.CreateConfig();
        /// <summary>
        /// 
        /// </summary>
        protected Model.StatInfo statModel = new Stat.Model.StatInfo();
        private Model.PageInfo pageModel = new Stat.Model.PageInfo(31);
        /// <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");
                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()
        {
            //数据
            List<Model.ViewDay> list = BLL.ViewDay.Get(statModel);
            this.LtrDayList.Text = Html.DayList.Get(list, pageModel.PageIndex, pageModel.PageSize, statModel.WebID);
            Response.Flush();
            //分页
            if (list.Count > 1)
            {
                string strUrlParm = "wid=" + statModel.WebID + "&st=" + statModel.StartTime.ToString("yyyy-MM-dd") + "&et=" + statModel.EndTime.AddDays(-1).ToString("yyyy-MM-dd");
                int _RecCount = Convert.ToInt32(statModel.EndTime.Subtract(statModel.StartTime).TotalDays);
                string strDayPageIndex = JPageIndex.GetIndex.Get(_RecCount, pageModel.PageIndex, pageModel.PageSize, strUrlParm, 1, 0, 1, 7);
                this.LtrDayPageIndex.Text = this.LtrDayRp_PageIndex.Text = strDayPageIndex;
                Response.Flush();
            }
            //报表
            if (statModel.EndTime.Subtract(statModel.StartTime).TotalDays > 4)
            {
                DateTime stReport = statModel.StartTime.AddDays((pageModel.PageIndex - 1) * pageModel.PageSize);
                stReport = stReport > statModel.EndTime ? statModel.EndTime : stReport;
                DateTime etReport = stReport.AddDays((pageModel.PageSize - 1));
                etReport = etReport > statModel.EndTime ? statModel.EndTime : etReport;
                //
                string subTitle = "(" + stReport.ToLongDateString() + "---" + etReport.ToLongDateString() + ")";
                string strXML = Stat.Report.Rp_3_Combi2DDY.GetXML_vDay(list, "日访问分布图表", subTitle, "P V", "U V", "PV", "UV", 0, pageModel.PageIndex, pageModel.PageSize);
                this.LtrRp_Day.Text = BLL.StatCharts.RenderChart("../StatCharts/MSCombiDY2D.swf", "", strXML, "chartDay", "99", "280", false, false);
                Response.Flush();
            }
            ShowHour();
        }
        void ShowHour()
        {
            int hourBreak = config.GetStatHourPostpone();
            //小时数据
            List<Model.ViewDay> list = BLL.ViewHour.Get24Hour(statModel, hourBreak);
            //报表
            string strSubTitle = "(" + statModel.StartTime.ToShortDateString() + "- -" + statModel.EndTime.ToShortDateString() + ")";

            string strHourXML = Stat.Report.Rp_3_MSLine.GetXML_vHour(list, "24小时访问分布图", strSubTitle, 0);
            this.LtrRp_Hour.Text = BLL.StatCharts.RenderChart("../StatCharts/MSLine.swf", "", strHourXML, "chartHour", "99", "280", false, false);
            Response.Flush();
            //Html
            this.LtrHourList.Text = Stat.Html.HourList.Get(list);
            Response.Flush();
        }
    }
}