using System;
using System.Collections.Generic;

namespace Stat.Html
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>By ：Juju 2010-10-16</remarks>
    public class ItemList
    {
        /// <summary>
        /// 数据列表
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string Get(List<Model.StatItem> list, int webid, string itemName, string par, string t1, string t2)
        {
            if (list != null && list.Count > 0)
            {
                if (list[0].IpCount == 0)
                {
                    return GetSingle(list, webid, itemName, par, t1, t2);
                }
                else
                {
                    return GetMulti(list, webid, itemName, par, t1, t2);
                }
            }
            return null;
        }

        private static string GetMulti(List<Model.StatItem> list, int webid, string itemName, string par, string t1, string t2)
        {
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            if (list != null && list.Count > 0)
            {
                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=\"18%\" align=\"left\" ><strong>" + itemName + "</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"14%\" align=\"left\" ><strong>P V</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"14%\" align=\"left\" ><strong>I P</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"14%\" align=\"left\" ><strong>U V</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"14%\" align=\"left\" ><strong>人均PV</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"*\" align=\"left\" ><strong>PV比例</strong></td>");
                tep.Append("  </tr>");

                for (int i = 0; i < list.Count; 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\">&nbsp;总&nbsp;&nbsp;计&nbsp;</td>");
                        tep.Append(" <td align=\"left\"><span class=\"blud14\">-</span></td>");
                        tep.Append(" <td align=\"left\"><a href=\"Vpage.aspx?wid=" + webid + "&st=" + t1 + "&et=" + t2 + "\" title=\"查看\"><span class=\"blud14\">" + list[0].PvCount + "</span></a></td>");
                        tep.Append(" <td align=\"left\"><a href=\"vIP.aspx?wid=" + webid + "&st=" + t1 + "&et=" + t2 + "\" title=\"查看\"><span class=\"blud14\">" + list[0].IpCount + "</span></a></td>");
                        tep.Append(" <td align=\"left\" ><span class=\"blud14\">" + list[i].UvCount + "</span></td>");
                        tep.Append(" <td align=\"left\"><span class=\"blud14\">" + list[i].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\" >" + list[i].Name + "</td>");
                        tep.Append(" <td align=\"left\" ><a href=\"Vpage.aspx?wid=" + webid + "&" + par + "=" + list[i].ID + "&st=" + t1 + "&et=" + t2 + "\" title=\"查看\"><span class=\"red14\">" + list[i].PvCount + "</span></a></td>");
                        tep.Append(" <td align=\"left\" ><span class=\"red14\">" + list[i].IpCount + "</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>");
                    }

                }

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


        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private static string GetSingle(List<Model.StatItem> list, int webid, string itemName, string par, string t1, string t2)
        {
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            if (list != null && list.Count > 0)
            {
                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>" + itemName + "</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"25%\" 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 = 0; i < list.Count; i++)
                {
                    if (list[i].PvCount > 0)
                    {
                        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\">&nbsp;总&nbsp;&nbsp;计&nbsp;</td>");
                            tep.Append(" <td align=\"left\"><span class=\"blud14\">-</span></td>");
                            tep.Append(" <td align=\"left\"><a href=\"Vpage.aspx?wid=" + webid + "&st=" + t1 + "&et=" + t2 + "\" title=\"查看\"><span class=\"blud14\">" + list[0].PvCount + "</span></a></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\" >" + list[i].Name + "</td>");


                            tep.Append(" <td align=\"left\"><a href=\"Vpage.aspx?wid=" + webid + "&" + par + "=" + list[i].ID + "&st=" + t1 + "&et=" + t2 + "\" title=\"查看\"><span class=\"red14\">" + list[i].PvCount + "</span></a></td>");
                            tep.Append(" <td align=\"left\" ><img src=\"Images/bar4.gif\" height=\"10\" width=\"" + list[i].Percent.ToString("0.0") + "\" />&nbsp;" + list[i].Percent.ToString("0.00") + "%</td>");
                            tep.Append("</tr>");
                        }
                    }
                }
                tep.Append("</table>");
            }
            return tep.ToString();
        }
    }
}
