using System;
using System.Collections.Generic;


namespace Stat.web.v
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Main1 : System.Web.UI.Page
    {
        Stat.Cache.IConfig config = Stat.Cache.CacheFatory.CreateConfig();
        Stat.Cache.IWebSite statWebSite = Stat.Cache.CacheFatory.CreateWebSite();
        /// <summary>
        /// 站点信息
        /// </summary>
        protected IList<Stat.Model.WebSites> website;
        /// <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 = Plugin.Common.Rq_Int("wid");
            Stat.Security.ISecurity security = Stat.Security.DataFatory.CreateSecurity();
            security.CheckReportPower(statModel.WebID);
            if (!IsPostBack)
            {
                GetSiteInfo();
                this.Page.Title = website[0].WebName + " 统计概况";
                GetGuaiKuang();//概况
                ShowHourReport();
                
            }
        }

        /// <summary>
        /// 获取站点详细信息
        /// </summary>
        void GetSiteInfo()
        {
            website = statWebSite.Get(statModel.WebID);
            if (website.Count == 0)
            {
                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(website[0].AddTime).Days;
            ViewTop.DaySum = ViewTop.DaySum == 0 ? 1 : ViewTop.DaySum;
            //昨日
            Model.StatInfo ydModel = new Stat.Model.StatInfo();
            ydModel.WebID = statModel.WebID;
            ydModel.StartTime = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToShortDateString());
            ydModel.EndTime = ydModel.StartTime.AddDays(1);
            List<Model.ViewDay> ydList = BLL.ViewDay.Get(ydModel);
            if (ydList != null && ydList.Count > 0) { ydViewModel = ydList[0]; }
            //今日
            statModel.StartTime = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            statModel.EndTime = statModel.StartTime.AddDays(1);
            List<Model.ViewDay> tdList = BLL.ViewDay.Get(statModel);
            if (tdList != null && tdList.Count > 0) { tdViewModel = tdList[0]; }
        }
        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);
        }
    }
}