using System;
using System.Collections.Generic;
using System.Web;
namespace Stat.Html
{
    public class Engine
    {
        /// <summary>
        /// 获取 搜索引擎页面 （HTML）
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="webid"></param>
        /// <param name="st"></param>
        /// <param name="et"></param>
        /// <returns></returns>
        public static string Get(IList<Model.StatItem> list, int webid, string st, string et)
        {
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            if (list != null && list.Count > 1)
            {
                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=\"12%\" align=\"left\" ><strong>搜索引擎</strong></td>");

                if (list[0].KeyCount > 0)
                    tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"12%\" align=\"left\" ><strong>关键字个数</strong></td>");

                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"12%\" align=\"left\" ><strong>搜索次数</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"12%\" align=\"left\" ><strong>I P</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"12%\" align=\"left\" ><strong>独立访客</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"12%\" align=\"left\" ><strong>人均搜索次数</strong></td>");
                tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"*\" align=\"left\" ><strong>份额比例</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>");
                        if (list[0].KeyCount > 0)
                            tep.Append(" <td align=\"left\"><a href=\"Keyword.aspx?wid=" + webid + "&st=" + st + "&et=" + et + "&e=0&k=\" title=\"查看详细\"><span class=\"blud14\">" + list[0].KeyCount + "</span></a></td>");
                        tep.Append(" <td align=\"left\"><a href=\"EngineList.aspx?wid=" + webid + "&st=" + st + "&et=" + et + "&e=0&k=\" title=\"查看详细\"><span class=\"blud14\">" + list[0].PvCount + "</span></a></td>");
                        tep.Append(" <td align=\"left\"><span class=\"blud14\">" + list[0].IpCount + "</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\" ><strong>" + list[i].Name + "</strong></td>");
                        if (list[0].KeyCount > 0)
                            tep.Append(" <td align=\"left\" ><a href=\"Keyword.aspx?wid=" + webid + "&st=" + st + "&et=" + et + "&e=" + Stat.Items.Engine.EngineToNumber(list[i].Name) + "&k=\" title=\"查看详细\"><span class=\"red14\">" + list[i].KeyCount + "</span></a></td>");
                        tep.Append(" <td align=\"left\" ><a href=\"EngineList.aspx?wid=" + webid + "&st=" + st + "&et=" + et + "&e=" + Stat.Items.Engine.EngineToNumber(list[i].Name) + "&k=\" title=\"查看详细\"><span class=\"red14\"><strong>" + list[i].PvCount + "</strong></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\">" + Convert.ToDouble(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;" + Convert.ToDouble(list[i].Percent).ToString("0.00") + "%</td>");

                        tep.Append("</tr>");
                    }
                }
                tep.Append("</table>");
            }
            return tep.ToString();
        }
        /// <summary>
        ///  获取关键字列表（HTML）
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="cPage"></param>
        /// <param name="pSize"></param>
        /// <param name="webid"></param>
        /// <param name="egid"></param>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <returns></returns>
        public static string GetKey(IList<Model.StatItem> list, int cPage, int pSize, int webid, int egid, string t1, string t2)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            if (list != null && list.Count > 0)
            {
                sb.Append(" <table bgcolor=\"#cedfef\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"100%\" class=\"padding\">");
                sb.Append(" <tr>");
                sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"8%\" align=\"center\"  height=\"25\"><strong>排名</strong></td>");
                sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"20%\" align=\"left\" ><strong>关键字</strong></td>");
                sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"13%\" align=\"left\" ><strong>搜索次数</strong></td>");
                sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"13%\" align=\"left\" ><strong>I P</strong></td>");
                sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"13%\" align=\"left\" ><strong>独立访客</strong></td>");
                sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"13%\" align=\"left\" ><strong>人均搜索次数</strong></td>");
                sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"20%\" align=\"left\" ><strong>次数比例</strong></td>");
                sb.Append("  </tr>");
                //
                int st = (cPage - 1) * pSize;
                st = st > list.Count ? list.Count : st;
                int et = st + pSize;
                et = et > list.Count ? list.Count : et;
                //
                for (int i = st; i < et; i++)
                {
                    if (i == 0)
                    {
                        sb.Append("<tr bgcolor=\"#FFFFFF\" onmouseover=\"this.style.backgroundColor='#EEF3F9';\" onmouseout=\"this.style.backgroundColor='#FFFFFF';\">");
                        sb.Append(" <td align=\"center\" height=23 class=\"blud14\">&nbsp;总&nbsp;&nbsp;计&nbsp;</td>");
                        sb.Append(" <td align=\"left\"><span class=\"blud14\">-</span></td>");
                        sb.Append(" <td align=\"left\"><span class=\"blud14\">" + list[0].PvCount + "</span></td>");
                        sb.Append(" <td align=\"left\"><span class=\"blud14\">" + list[0].IpCount + "</span></td>");
                        sb.Append(" <td align=\"left\"><span class=\"blud14\">" + list[0].UvCount + "</span></td>");
                        sb.Append(" <td align=\"left\"><span class=\"blud14\">" + list[0].PerPV.ToString("0.0") + "</span></td>");
                        sb.Append(" <td align=\"left\" >&nbsp;100%</td>");
                        sb.Append("</tr>");
                    }
                    else
                    {
                        sb.Append("<tr bgcolor=\"#FFFFFF\" onmouseover=\"this.style.backgroundColor='#EEF3F9';\" onmouseout=\"this.style.backgroundColor='#FFFFFF';\">");

                        if (i < 4)
                        {
                            sb.Append(" <td align=\"center\" height=\"23\"><span class=\"red14\"><strong>" + (i) + "</strong></span></td>");
                        }
                        else
                        {
                            sb.Append(" <td align=\"center\" height=\"23\">" + (i) + "</td>");
                        }
                        sb.Append(" <td align=\"left\" >" + list[i].EngineKeyword + "</td>");
                        sb.Append(" <td align=\"left\" ><a href=\"EngineList.aspx?wid=" + webid + "&st=" + t1 + "&et=" + t2 + "&e=" + egid + "&k=" + HttpContext.Current.Server.UrlEncode(list[i].EngineKeyword) + "\" title=\"详细\"><span class=\"red14\"><strong>" + list[i].PvCount + "</strong></span></a></td>");
                        sb.Append(" <td align=\"left\" ><span class=\"red14\">" + list[i].IpCount + "</span></td>");
                        sb.Append(" <td align=\"left\" ><span class=\"red14\">" + list[i].UvCount + "</span></td>");
                        sb.Append(" <td align=\"left\" ><span class=\"red14\">" + list[i].PerPV.ToString("0.0") + "</span></td>");
                        sb.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>");

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

        /// <summary>
        /// 获取 搜索详细数据列表（HTML）
        /// </summary>
        /// <param name="list"></param>
        /// <param name="cPage"></param>
        /// <param name="pSize"></param>
        /// <param name="webid"></param>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <returns></returns>
        public static string GetList(List<Model.ViewClick> list, int cPage, int pSize, int webid, string t1, string t2)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            if (list != null && list.Count > 0)
            {
                int st = (cPage - 1) * pSize + 1;

                for (int i = 0; i < list.Count; i++)
                {
                    sb.Append(" <table bgcolor=\"#cedfef\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"100%\" class=\"padding\">");
                    sb.Append(" <tr>");
                    sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"38\" align=\"left\"  height=\"25\"><strong>编号</strong></td>");
                    sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"45\" align=\"left\"><strong>引擎</strong></td>");
                    sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"157\" align=\"left\"><strong>关键字</strong></td>");
                    sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"120\" align=\"left\"><strong>用户I P</strong></td>");
                    sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"110\" align=\"left\" ><strong>时间</strong></td>");
                    sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"*\" align=\"left\" class=\"zdhh\"><strong>网站入口：" + list[i].CurrentUrl + "</strong></td>");
                    sb.Append("  </tr>");

                    sb.Append("<tr bgcolor=\"#FFFFFF\" onmouseover=\"this.style.backgroundColor='#EEF3F9';\" onmouseout=\"this.style.backgroundColor='#FFFFFF';\">");

                    sb.Append(" <td align=\"left\" height=25>&nbsp;" + (st) + "</td>");
                    sb.Append(" <td align=\"left\" ><span class=\"red14\">" + Stat.Items.Engine.NumberToEngine(list[i].EngineId.ToString()) + "</span></td>");
                    sb.Append(" <td align=\"left\" ><a href=\"Keyword.aspx?wid=" + webid + "&st=" + t1 + "&et=" + t2 + "&e=" + list[i].EngineId + "&k=" + HttpContext.Current.Server.UrlEncode(list[i].EngineKeyWord) + "\" title=\"查看详细\"><span class=\"red14\">" + list[i].EngineKeyWord + "</span></a></td>");
                    sb.Append(" <td align=\"left\" ><a href=\"Vpage.aspx?wid=" + webid + "&st=" + t1 + "&et=" + t2 + "&ip=" + list[i].IP + "\" title=\"追踪该IP\"><span class=\"red14\">" + list[i].IP + "</span></a><br/>(" + Stat.Items.Area.NumberToName(list[i].AreaId1.ToString()) + ")</td>");
                    sb.Append(" <td align=\"left\" ><span >" + list[i].ViewTime + "</span></td>");
                    sb.Append(" <td align=\"left\" class=\"zdhh\">搜索来源：<a href=\"" + list[i].LastUrl + "\" target=\"_blank\"><span class=\"red14\">" + list[i].LastUrl + "</span></a></td>");


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

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

            }

            return sb.ToString();
        }

    }
}
