using System;
using System.Collections.Generic;

namespace Stat.web.v
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks> By： Juju 2010-12-11</remarks>
    public partial class SDomain : Html.ReportPage
    {
        /// <summary>
        /// 
        /// </summary>
        protected Model.StatInfo statModel = new Stat.Model.StatInfo();
        Model.PageInfo pageModel = new Stat.Model.PageInfo(100);
        /// <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.StatItem> list = BLL.ViewDomain.Get(statModel);
            ShowReport(list);
            ShowHtml(list);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="list"></param>
        protected void ShowHtml(List<Model.StatItem> list)
        {
            string strdtDomainList = Html.Domain.GetList(list, pageModel.PageIndex, pageModel.PageSize);
            this.LtrDomainList.Text = strdtDomainList;
            Response.Flush();
            if (list.Count > pageModel.PageSize)
            {
                string urlPar = "wid=" + statModel.WebID + "&st=" + statModel.strStartTime + "&et=" + statModel.strEndTime;
                this.LtrDomainPageIndex.Text = JPageIndex.GetIndex.Get(list.Count, pageModel.PageIndex, pageModel.PageSize, urlPar, 1, 0, 1, 6);

                Response.Flush();
            }
        }

        /// <summary>
        /// 获取数据
        /// </summary>
        protected void ShowReport(List<Model.StatItem> list)
        {
            if (list != null)
            {
                if (list.Count <= 10)
                {
                    string strXML = Stat.Report.Rp_3_Pie3D.GetXML(list, "来路域名", "(" + statModel.StartTime.ToShortDateString() + "--" + statModel.EndTime.ToShortDateString() + ")", 1, "PV");
                    this.LtrRp_Domain.Text = BLL.StatCharts.RenderChart("../StatCharts/Pie3D.swf", "", strXML, "chartDomain1", "99", "300", false, false);
                }
                else if (list.Count <= 15)
                {
                    string strXML = Stat.Report.Rp_3_Column2D.GetXML_Domain(list, pageModel.PageIndex, pageModel.PageSize, "来路域名", "来路域名", "PV", "PV", 0);
                    this.LtrRp_Domain.Text = BLL.StatCharts.RenderChart("../StatCharts/Column2D.swf", "", strXML, "chartDomain2", "99", "300", false, false);
                }
                else { return; }
                Response.Flush();
            }
        }
    }
}