using System;
using System.Collections.Generic;

namespace Stat.Html
{
    public class ViewIP
    {
        /// <summary>
        /// 访问IP数据列表（HTML）
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="cPage"></param>
        /// <param name="pSize"></param>
        /// <returns></returns>
        public static string GetList(List<Model.StatItem> list,int webid, int cPage, int pSize, string t1, string t2)
        {

            if (list != null && list.Count > 0)
            {
                int st = (cPage - 1) * pSize;
                st = st > list.Count ? list.Count : st;
                int et = st + pSize;
                et = et > list.Count ? list.Count : et;

                if (list[0].IpCount == 0)
                {
                    return GetSingle(list,webid, ref st, et, t1, t2);
                }
                else
                {
                    return GetMulti(list,webid, ref st, et, t1, t2);
                }
            }
            return null;


        }

        private static string GetMulti(List<Model.StatItem> list,int webid, ref int st, int et, string t1, string t2)
        {
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            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=\"20%\" align=\"left\" ><strong>来路 IP</strong></td>");
            tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"15%\" align=\"left\" ><strong>P V</strong></td>");
            tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"15%\" align=\"left\" ><strong>U V</strong></td>");
            tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"15%\" align=\"left\" ><strong>人均PV</strong></td>");
            tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"*\" align=\"left\" ><strong>份额比例</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\">" + list[0].PvCount + "</span></td>");
                    tep.Append(" <td align=\"left\"><span class=\"blud14\">" + list[0].UvCount + "</span></td>");
                    tep.Append(" <td align=\"left\"><span class=\"blud14\">" + list[0].PerPV.ToString("0.0") + "</span></td>");
                    tep.Append(" <td align=\"left\" >&nbsp;-</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=\"Vpage.aspx?wid=" + webid + "&ip=" + list[i].Name + "&st=" + t1 + "&et=" + t2 + "\" title=\"查看\"><strong>" + list[i].Name + "</strong></a></td>");
                    tep.Append(" <td align=\"left\" ><span class=\"red14\"><strong>" + list[i].PvCount + "</strong></span></td>");
                    tep.Append(" <td align=\"left\" ><span class=\"red14\">" + list[i].UvCount + "</span></td>");
                    tep.Append(" <td align=\"left\" ><span class=\"red14\">" + list[i].PerPV.ToString("0.0") + "</span></td>");
                    tep.Append(" <td align=\"left\" ><img src=\"Images/bar4.gif\" height=\"10\" width=\"" + Convert.ToInt32(list[i].Percent) + "\" />&nbsp;" + list[i].Percent.ToString("0.00") + "%</td>");

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

                    st++;
                }
            }
            tep.Append("</table>");
            return tep.ToString();
        }
        private static string GetSingle(List<Model.StatItem> list,int webid, ref int st, int et, string t1, string t2)
        {
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            tep.Append(" <table bgcolor=\"#cedfef\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"100%\" class=\"padding\">");
            tep.Append(" <tr>");
            tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"15%\" align=\"center\"  height=\"25\"><strong>排名</strong></td>");
            tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"25%\" align=\"left\" ><strong>来路域名</strong></td>");
            tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"20%\" align=\"left\" ><strong>P V</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\">" + list[0].PvCount + "</span></td>");
                    tep.Append(" <td align=\"left\" >&nbsp;-</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=\"Vpage.aspx?wid=" + webid + "&ip=" + list[i].Name + "&st=" + t1 + "&et=" + t2 + "\" title=\"查看\"><strong>" + list[i].Name + "</strong></a></td>");
                    tep.Append(" <td align=\"left\" ><span class=\"red14\"><strong>" + list[i].PvCount + "</strong></span></td>");

                    tep.Append(" <td align=\"left\" ><img src=\"Images/bar4.gif\" height=\"10\" width=\"" + Convert.ToInt32(list[i].Percent) + "\" />&nbsp;" + list[i].Percent.ToString("0.00") + "%</td>");

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