using System;
using System.Collections.Generic;
using System.Text;
namespace Stat.Report
{
    /// <summary>
    /// 柱形报表2DDY
    /// </summary>
    public class Rp_3_Combi2DDY
    {
        /// <summary>
        /// 日访问量分布图
        /// </summary>
        /// <param name="list">数据源</param>
        /// <param name="caption">标题</param>
        /// <param name="subcaption">副标题</param>
        /// <param name="pyAxisName">PY 轴 名称</param>
        /// <param name="syAxisName">SY 轴 名称</param>
        /// <param name="numberSuffix">后缀</param>
        /// <param name="showValues">（0）</param>
        /// <param name="sNumberSuffix"></param>
        /// <returns></returns>
        public static string GetXML_vDay(List<Model.ViewDay> list, string caption, string subcaption, string pyAxisName, string syAxisName, string numberSuffix, string sNumberSuffix, int showValues, int pageIndex, int pageSize)
        {

            int st = (pageIndex - 1) * pageSize;
            st = st > list.Count ? list.Count : st;
            int et = st + pageSize;
            et = et > list.Count ? list.Count : et;

            StringBuilder strXML = new System.Text.StringBuilder();

            strXML.Append("<chart palette='2' caption='" + caption + "' subCaption='" + subcaption + "' showValues='" + showValues + "' divLineDecimalPrecision='1'");
            strXML.Append(" limitsDecimalPrecision='1' PYAxisName='" + pyAxisName + "' SYAxisName='" + syAxisName + "' formatNumberScale='0'");
            strXML.Append(" numberSuffix='" + numberSuffix + "' sNumberSuffix ='" + sNumberSuffix + "'");
            strXML.Append(" captionPadding='3' chartTopMargin='5' chartBottomMargin='10' chartLeftMargin='5' chartRightMargin='5' ");

            strXML.Append(" alternateHGridColor='FCB541' alternateHGridAlpha='15' divLineColor='FCB541' divLineAlpha='40'");
            strXML.Append(" canvasBorderColor='F7BD62' baseFontColor='000000' bgColor='FFFFFF' showBorder='0'>");
            int reCount = et - st;

            if (list != null && list.Count > 1)
            {

                /*--------------------------------------*/
                strXML.Append("<categories>");
                for (int i = st; i < et; i++)
                {
                    if (i != 0)
                    {
                        if (reCount <= 10)
                        {
                            strXML.Append("<category label='" + list[i].vYear + "/" + list[i].vMonth + "/" + list[i].vDay + "' />");
                        }
                        else if (reCount > 10 && reCount <= 20)
                        {
                            strXML.Append("<category label='" + list[i].vMonth + "/" + list[i].vDay + "' />");
                        }
                        else
                        {
                            strXML.Append("<category label='" + list[i].vDay + "' />");
                        }
                    }
                }
                strXML.Append("</categories>");
                /*--------------------------------------*/
                strXML.Append("<dataset seriesName='P V'>");
                string[] colorList = Plugin.Common.RpColor();
                int colorRandom = new Random().Next(0, 10);
                for (int i = st; i < et; i++)
                {
                    if (i != 0)
                    {
                        strXML.Append("<set value='" + list[i].pvCount + "'");
                        strXML.Append(" color='" + colorList[colorRandom].ToString() + "'");

                        strXML.Append(" toolText='" + list[i].vMonth + "月" + list[i].vDay + "日：");
                        strXML.Append(list[i].pvCount + " (P V) / ");
                        strXML.Append(list[i].ipCount + " (I P) / ");
                        strXML.Append(list[i].cusCount + " (U V) / ");
                        strXML.Append(list[i].newCount + " (新访客) / ");
                        strXML.Append(+list[i].timCount + " (次来访) / ");
                        strXML.Append(+list[i].otimCount + " (次回访) / ");
                        strXML.Append(list[i].AVG.ToString("0.0") + " (人均PV)");
                        strXML.Append("'  />");

                        colorRandom++;
                        colorRandom = colorRandom >= (colorList.GetLength(0) - 1) ? 0 : colorRandom; //颜色编号
                    }
                }
                strXML.Append("</dataset>");
                /*--------------------------------------*/
                strXML.Append("<dataset seriesName='I P' renderAs='Area' parentYAxis='P'>");
                for (int i = st; i < et; i++)
                {
                    if (i != 0)
                    {
                        strXML.Append("<set value='" + list[i].ipCount + "' />");
                    }
                }
                strXML.Append("</dataset>");
                /*--------------------------------------*/
                strXML.Append("<dataset lineThickness='3' seriesName='U V' parentYAxis='S'>");
                for (int i = st; i < et; i++)
                {
                    if (i != 0)
                    {
                        strXML.Append("<set value='" + list[i].cusCount + "'");
                        strXML.Append(" toolText='" + list[i].vMonth + "月" + list[i].vDay + "日：");
                        strXML.Append(list[i].cusCount + " 个独立访客 ' />");
                    }
                }
                strXML.Append("</dataset>");
                /*--------------------------------------*/
            }
            /*--------------------------------------*/
            strXML.Append(" <styles>");
            strXML.Append(" <definition>");
            strXML.Append("    <style name='myHTMLFont' type='font' isHTML='1' color='FF5904' />");
            strXML.Append(" </definition>");
            strXML.Append("  <application>");
            strXML.Append("     <apply toObject='TOOLTIP' styles='myHTMLFont' />");
            strXML.Append("  </application>");
            strXML.Append(" </styles>");
            /*--------------------------------------*/
            strXML.Append("</chart>");

            return strXML.ToString();
        }
    }
}
