using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using TopWinCMS.BLL;
using TopWinCMS.Model;
using TopWinCMS.Common;
namespace TopWinCMS.WebUI.Admin.Counter
{
    public partial class Counter_Main : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RightsCheck.CheckWorkPower("Count_Read");
            CounterContent_Result();
            LB_Path.Text = Config.SiteName + " →  访问统计 → 访问统计概况";
        }

        #region 统计
        public void CounterContent_Result()
        {
            CounterContentInfo model = new CounterContentManage().Load();
            if (model == null)
            {
                MsgBox.Alert("统计系统还没有启用。");
                return;
            }

            long itotal;
            string stronline;
            long itoday;
            long iyesterday;
            double dbldays;
            double dbldayavg;
            int iguess;

            string strhightime;


            //总访问数 
            itotal = model.Total;
            LB_总访问量.Text = model.Total.ToString();

            //开始访问日期

            LB_开始统计于.Text = model.StartTime.ToShortDateString();
            if (itotal == 0)
            {
                MsgBox.Alert("统计系统还没有启用。");
                return;
            }

            //最高访问数
            LB_最高访问量.Text = model.High.ToString();


            //最高访问数发生日期
            strhightime = model.HighTime.Date.ToShortDateString();
            LB_最高量日期.Text = strhightime;


            //在线人数
            stronline = new CounterDiaryManage().TotalOnline();
            LB_在线人数.Text = stronline.ToString();


            //今日访问量、昨日访问量 
            if (model != null)
            {
                itoday = model.Today;
                iyesterday = model.Yesterday;
            }
            else
            {
                itoday = 0;
                iyesterday = 0;
            }
            LB_今日访问量.Text = model.Today.ToString();
            LB_昨日访问量.Text = model.Yesterday.ToString();


            //今年访问量（从主数据库读取）
            LB_今年访问量.Text = new CounterDiaryManage().ThisYear();

            //本月访问量
 
            LB_本月访问量.Text = new CounterDiaryManage().ThisMonth();

            //访问天数 
            dbldays = DateTime.Now.Subtract(model.StartTime).TotalDays;

            LB_统计天数.Text = Convert.ToInt32(dbldays).ToString();

            //平均每天访问量
            dbldayavg = itotal / dbldays;
            LB_平均日访量.Text = dbldayavg.ToString();

            double dbcf = System.Math.Pow(10, 5);
            dbldays = (int)(dbldays * dbcf + 0.5) / dbcf;
            dbldayavg = (int)(dbldayavg * dbcf + 0.5) / dbcf;

            //预计今日访问量
            double dblvdaylong = DateTime.Now.Subtract(DateTime.Now.Date).TotalDays;
            iguess = (int)(((itoday / dblvdaylong) + iyesterday) / 2 + 0.5);
            if (iguess < itoday)
                iguess = (int)((itoday / dblvdaylong) + 0.5);

            LB_预计今日.Text = iguess.ToString();


        }
        #endregion

    }
}