using System;
using System.Data;
using System.Collections.Generic;

namespace Stat.Html
{
    public class PVStat
    {
        /// <summary>
        /// PV统计详细数据列表（HTML）
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="cPage"></param>
        /// <param name="pSize"></param>
        /// <returns></returns>
        public static string GetList(DataTable dt, int cPage, int pSize)
        {
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            if (dt != null && dt.Rows.Count > 0)
            {
                /*--------------------------------------------------------*/
                int st = (cPage - 1) * pSize;
                st = st > dt.Rows.Count ? dt.Rows.Count : st;
                int et = st + pSize;
                et = et > dt.Rows.Count ? dt.Rows.Count : et;
                /*--------------------------------------------------------*/
                tep.Append(" <table bgcolor=\"#cedfef\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"100%\" class=\"padding\">");
                tep.Append(" <tr>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"8%\" align=\"center\"  height=\"25\"><strong>排名</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"47%\" align=\"left\" ><strong>访问页面</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"8%\" align=\"left\" ><strong>访问次数</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"7%\" align=\"left\" ><strong>I P</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"8%\" align=\"left\" ><strong>U V</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"7%\" align=\"left\" ><strong>人均PV</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"*\" align=\"left\" ><strong>PV比例</strong></td>");
                tep.Append("  </tr>");

                for (int i = st; i < et; i++)
                {
                    /*----------合计--------------------------------------------*/
                    if (i == 0)
                    {
                        tep.Append("<tr bgcolor=\"#FFFFFF\" onmouseover=\"this.style.backgroundColor='#EEF3F9';\" onmouseout=\"this.style.backgroundColor='#FFFFFF';\">");
                        tep.Append(" <td align=\"center\" height=23 class=\"blud14\">合计</td>");
                        tep.Append(" <td align=\"left\"><span class=\"blud14\">-</span></td>");
                        tep.Append(" <td align=\"left\"><span class=\"blud14\">" + dt.Rows[0][2] + "</span></td>");
                        tep.Append(" <td align=\"left\"><span class=\"blud14\">" + ShowToday(dt.Rows[0][3].ToString()) + "</span></td>");
                        tep.Append(" <td align=\"left\"><span class=\"blud14\">" + ShowToday(dt.Rows[0][4].ToString()) + "</span></td>");
                        tep.Append(" <td align=\"left\"><span class=\"blud14\">" + ShowToday(Convert.ToDouble(dt.Rows[0][5]).ToString("0.0")) + "</span></td>");
                        tep.Append(" <td align=\"left\" >&nbsp;100%</td>");
                        tep.Append("</tr>");
                    }
                    /*--------------------------------------------------------*/
                    else
                    {
                        tep.Append("<tr bgcolor=\"#FFFFFF\" onmouseover=\"this.style.backgroundColor='#EEF3F9';\" onmouseout=\"this.style.backgroundColor='#FFFFFF';\">");

                        if (i < 4)
                        {
                            tep.Append(" <td align=\"center\" height=\"23\"><span class=\"red14\"><strong>" + (i) + "</strong></span></td>");
                        }
                        else
                        {
                            tep.Append(" <td align=\"center\" height=\"23\">" + (i) + "</td>");
                        }
                        tep.Append(" <td align=\"left\" ><a href=\"" + dt.Rows[i][1].ToString() + "\" target=\"_blank\"><strong>" + dt.Rows[i][1].ToString() + "</strong></a></td>");
                        tep.Append(" <td align=\"left\" ><span class=\"red14\"><strong>" + dt.Rows[i][2] + "</strong></span></td>");
                        tep.Append(" <td align=\"left\" ><span class=\"red14\">" + ShowToday(dt.Rows[i][3].ToString()) + "</span></td>");
                        tep.Append(" <td align=\"left\" ><span class=\"red14\">" + ShowToday(dt.Rows[i][4].ToString()) + "</span></td>");
                        tep.Append(" <td align=\"left\" ><span class=\"red14\">" + ShowToday(Convert.ToDouble(dt.Rows[i][5]).ToString("0.0")) + "</span></td>");
                        tep.Append(" <td align=\"left\" ><img src=\"Images/bar4.gif\" height=\"10\" width=\"" + Convert.ToInt32(dt.Rows[i][6]) + "\" />&nbsp;" + Convert.ToDouble(dt.Rows[i][6]).ToString("0.00") + "%</td>");

                        tep.Append("</tr>");

                        st++;
                    }
                }
                tep.Append("</table>");

            }

            return tep.ToString();
        }

        private static string ShowToday(string str)
        {
            if (str.IndexOf("-") == 0)
            {
                return "-";
            }
            return str;
        }
        /*--------------------*/
        /// <summary>
        /// PV统计详细数据列表（HTML）
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="cPage"></param>
        /// <param name="pSize"></param>
        /// <returns></returns>
        public static string GetList_PV(List<Model.StatItem> dt, int cPage, int pSize)
        {
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            if (dt != null && dt.Count > 0)
            {
                /*--------------------------------------------------------*/
                int st = (cPage - 1) * pSize;
                st = st > dt.Count ? dt.Count : st;
                int et = st + pSize;
                et = et > dt.Count ? dt.Count : et;
                /*--------------------------------------------------------*/
                tep.Append(" <table bgcolor=\"#cedfef\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"100%\" class=\"padding\">");
                tep.Append(" <tr>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"10%\" align=\"center\"  height=\"25\"><strong>排名</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"60%\" align=\"left\" ><strong>访问页面</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"*\" align=\"left\" ><strong>访问次数</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"15%\" align=\"left\" ><strong>PV比例</strong></td>");
                tep.Append("  </tr>");

                for (int i = st; i < et; i++)
                {
                    /*----------合计--------------------------------------------*/
                    if (i == 0)
                    {
                        tep.Append("<tr bgcolor=\"#FFFFFF\" onmouseover=\"this.style.backgroundColor='#EEF3F9';\" onmouseout=\"this.style.backgroundColor='#FFFFFF';\">");
                        tep.Append(" <td align=\"center\" height=23 class=\"blud14\">合计</td>");
                        tep.Append(" <td align=\"left\"><span class=\"blud14\">-</span></td>");
                        tep.Append(" <td align=\"left\"><span class=\"blud14\">" + dt[0].PvCount + "</span></td>");
                        tep.Append(" <td align=\"left\" >&nbsp;100%</td>");
                        tep.Append("</tr>");
                    }
                    /*--------------------------------------------------------*/
                    else
                    {
                        tep.Append("<tr bgcolor=\"#FFFFFF\" onmouseover=\"this.style.backgroundColor='#EEF3F9';\" onmouseout=\"this.style.backgroundColor='#FFFFFF';\">");

                        if (i < 4)
                        {
                            tep.Append(" <td align=\"center\" height=\"23\"><span class=\"red14\"><strong>" + (i) + "</strong></span></td>");
                        }
                        else
                        {
                            tep.Append(" <td align=\"center\" height=\"23\">" + (i) + "</td>");
                        }
                        tep.Append(" <td align=\"left\" ><a href=\"" + dt[i].Name + "\" target=\"_blank\"><strong>" + dt[i].Name + "</strong></a></td>");
                        tep.Append(" <td align=\"left\" ><span class=\"red14\"><strong>" + dt[i].PvCount + "</strong></span></td>");                
                        tep.Append(" <td align=\"left\" ><img src=\"Images/bar4.gif\" height=\"10\" width=\"" + Convert.ToInt32(dt[i].Percent) + "\" />&nbsp;" + dt[i].Percent.ToString("0.00") + "%</td>");

                        tep.Append("</tr>");

                        st++;
                    }
                }
                tep.Append("</table>");

            }

            return tep.ToString();
        }
    }
}
