using System;
using System.Collections.Generic;
namespace Stat.web.v
{


    /// <summary>
    /// 
    /// </summary>
    public partial class Main1 : Html.ReportPage
    {
        /// <summary>
        /// 
        /// </summary>
        public Stat.Model.WebSites website;


        Stat.Cache.IConfig config = Stat.Cache.CacheFatory.CreateConfig();
        /// <summary>
        /// 今日数据
        /// </summary>
        protected Model.ViewDay tdViewModel = new Stat.Model.ViewDay();
        /// <summary>
        /// 昨日数据
        /// </summary>
        protected Model.ViewDay ydViewModel = new Stat.Model.ViewDay();
        /// <summary>
        /// 统计概况
        /// </summary>
        protected Model.ViewTop ViewTop = new Stat.Model.ViewTop();
        /// <summary>
        /// 统计参数
        /// </summary>
        protected Model.StatInfo statModel = new Stat.Model.StatInfo();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            statModel.WebID = base.Webid;
            website = base.Website;
            if (!IsPostBack)
            {
                GetSiteInfo();
                this.Page.Title = base.Website.WebName + " 统计概况";
                //
                GetGuaiKuang();//概况
                ShowHourReport();

            }
        }

        /// <summary>
        /// 获取站点详细信息
        /// </summary>
        void GetSiteInfo()
        {
            //所在采集服务器
            statModel.GatherID = base.Website.GatherServerID;
            if (base.Website.WebId < 1) { Plugin.Common.Alert_Top("您查看的站点不存在！", "../"); Response.End(); }
        }

        void GetGuaiKuang()
        {
            //概况
            if (BLL.ViewTop.Get(statModel.WebID).Count > 0) { ViewTop = BLL.ViewTop.Get(statModel.WebID)[0]; }
            //天数
            ViewTop.DaySum = DateTime.Now.Subtract(base.Website.AddTime).Days;
            ViewTop.DaySum = ViewTop.DaySum == 0 ? 1 : ViewTop.DaySum;
            //昨日 
            ydViewModel = GetYesterdayData();
            ////今日
            tdViewModel = GetTodayData();
        }
        /// <summary>
        /// 获取今日数据
        /// </summary>
        /// <returns></returns>
        private Model.ViewDay GetTodayData()
        {
            statModel.StartTime = statModel.EndTime = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            statModel.EndTime = statModel.EndTime.AddDays(1);
            //
            List<Model.ViewDay> tdList = BLL.ViewDay.Get(statModel);
            if (tdList != null && tdList.Count > 0) { return tdList[0]; }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获取昨日数据
        /// </summary>
        /// <returns></returns>
        private Model.ViewDay GetYesterdayData()
        {
            statModel.StartTime = statModel.EndTime = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToShortDateString());
            statModel.EndTime = statModel.EndTime.AddDays(1);

            List<Model.ViewDay> ydList = BLL.ViewDay.Get(statModel);
            if (ydList != null && ydList.Count > 0) { return ydList[0]; }
            else { return null; }

        }
        private void ShowHourReport()
        {
            int hourCount = -24;//最近小时数
            //时间
            DateTime stHour = Convert.ToDateTime(DateTime.Now.AddHours(hourCount).ToLongDateString()).AddHours(DateTime.Now.AddHours(hourCount).Hour);
            DateTime etHour = Convert.ToDateTime(DateTime.Now.ToLongDateString()).AddHours(DateTime.Now.Hour);
            //
            string strXML = Stat.Report.Rp_3_SLine.GetXML_vHour(BLL.ViewHour.GetConnect(statModel.WebID, stHour, etHour), "最近" + etHour.Subtract(stHour).TotalHours + "小时PV趋势图", stHour.ToString() + "--" + etHour.ToString(), "小时", "PV", 15000, "PV", 0);
            this.Near24H.Text = BLL.StatCharts.RenderChart("../StatCharts/Line.swf", "", strXML, "chart3", "99", "280", false, false);
        }
    }
}