using System;
using System.Collections;
using System.Collections.Generic;
namespace Stat.web.v
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks> By： Juju 2010-10-17</remarks>
    public partial class Column : System.Web.UI.Page
    {
        Stat.Cache.IWebSite myWebsite = Stat.Cache.CacheFatory.CreateWebSite();
        /// <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);
            //
            Model.WebSites websiteModel = Stat.Cache.CacheFatory.CreateWebSite().Get(statModel.WebID);
            if (websiteModel!=null)
            {
                this.Page.Title = "栏目分析 " + websiteModel.WebName;
                statModel.GatherID = websiteModel.GatherServerID;
                //
                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();
            }
            else
            {
                Response.Write("该站点不存在！");
                Response.End();
            }
        }
        /// <summary>
        /// 分析数据
        /// </summary>
        protected void Show()
        {
            IList<Model.WebsiteStructure> role = myWebsite.GetRuleList(statModel.WebID);
            List<Model.StatItem> list = Stat.Items.Column.Get(BLL.ViewColumn.Get(statModel, role), role);
            ShowReport(list);
            ShowHtml(list);
        }
        /// <summary>
        /// 
        /// </summary>
        protected void ShowHtml(List<Model.StatItem> list)
        {
            //待处理
            this.LtrColumnList.Text = Stat.Html.ItemList.Get(list, statModel.WebID, "栏目分析", "co", statModel.StartTime.ToShortDateString(), statModel.EndTime.ToShortDateString());
            Response.Flush();
        }
        /// <summary>
        /// 获取数据
        /// </summary>
        protected void ShowReport(List<Model.StatItem> list)
        {
            if (list != null && list.Count > 10)
            {
                //string strXML = BLL.Report.Rp_ScrollColData.GetXML_Column(list, "栏目分析", "(" + statModel.StartTime.ToLongDateString() + "--" + statModel.EndTime.AddDays(-1).ToLongDateString() + ")", 0, "PV");
                //this.LtrRp_Column.Text = BLL.StatCharts.RenderChart("../StatCharts/ScrollColumn2D.swf", "", strXML, "chartProvince", "99", "300", false, false);
                //Response.Flush();
            }
            else
            {
                string strXML = Stat.Report.Rp_3_Pie3D.GetXML(list, "栏目分析", "(" + statModel.StartTime.ToLongDateString() + "--" + statModel.EndTime.AddDays(-1).ToLongDateString() + ")", 0, "PV");
                this.LtrRp_Column.Text = BLL.StatCharts.RenderChart("../StatCharts/Pie3D.swf", "", strXML, "chartProvince", "99", "300", false, false);
                Response.Flush();
            }
        }
    }
}