using System;
using System.Collections.Generic;
namespace Stat.web.v
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>By juju：2011-10-26</remarks>
    public partial class STimeflux : Html.ReportPage
    {
        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 = base.Webid;
            //
            Model.WebSites websiteModel = base.Website;
            if (websiteModel.WebId > 0)
            {
                this.Page.Title = "时段分析 " + websiteModel.WebName;
                statModel.GatherID = websiteModel.GatherServerID;
                pageModel.PageIndex = base.PageIndex;
                statModel.StartTime = base.StartTime;
                statModel.EndTime = base.EndTime;
                //
                Show();
            }
            else
            {
                Response.Write("该站点不存在！");
                Response.End();
            }
        }
        /// <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();
        }
    }
}