using System;
using System.Collections.Generic;
namespace Stat.Html
{
    public class Vpage
    {
        /// <summary>
        /// 页面数据列表（HTML）
        /// </summary>
        /// <param name="list"></param>
        /// <param name="cPage"></param>
        /// <param name="pSize"></param>
        /// <returns></returns>
        public static string Get(List<Model.ViewOnClick> list, Model.PageInfo page, int webid, string ip, DateTime t1, DateTime t2)
        {
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            if (list != null && list.Count > 0)
            {
                int st = (page.PageIndex - 1) * page.PageSize;

                for (int i = 0; i < list.Count; i++)
                {
                    tep.Append(" <table bgcolor=\"#cedfef\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"100%\" class=\"padding\">");
                    tep.Append(" <tr>");
                    tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"40\" align=\"left\"  height=\"25\"><strong>编号</strong></td>");
                    tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"120\" align=\"left\"><strong>I P</strong></td>");
                    tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"120\" align=\"left\" ><strong>访问时间</strong></td>");
                    tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"120\" align=\"left\" ><strong>停留时间</strong></td>");
                    tep.Append("   <td bgcolor=\"#e9f1fa\" width=\"*\" align=\"left\" class=\"zdhh\"><strong>来源：<a href=\"" + list[i].LastUrl + "\" target=\"_blank\">" + list[i].LastUrl + "</a></strong></td>");
                    tep.Append("  </tr>");

                    tep.Append("<tr bgcolor=\"#FFFFFF\" onmouseover=\"this.style.backgroundColor='#EEF3F9';\" onmouseout=\"this.style.backgroundColor='#FFFFFF';\">");
                    //编号
                    tep.Append(" <td align=\"left\" height=25>&nbsp;" + (st + i + 1) + "</td>");
                    //IP地址
                    if (ip != null && ip.Length > 7)
                    {
                        tep.Append(" <td align=\"left\" ><span class=\"red14\">" + list[i].IP + "</span></td>");
                    }
                    else
                    {
                        tep.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></td>");

                    }
                    //访问时间
                    tep.Append(" <td align=\"left\" ><span >" + list[i].ViewTime + "</span></td>");
                    //停留时间
                    if (i < (list.Count - 1))
                    {
                        if (list[i].Mac == list[(i + 1)].Mac && list[i].View_Alone == list[(i + 1)].View_Alone)
                        {
                            TimeSpan ts = list[(i + 1)].ViewTime.Subtract(list[i].ViewTime);
                            tep.Append(" <td align=\"left\" ><span >" + ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds + "</span></td>");
                        }
                        else
                        {

                            tep.Append(" <td align=\"left\" ><span >用户退出</span></td>");
                        }
                    }
                    else
                    {
                        tep.Append(" <td align=\"left\" ><span >暂不显示</span></td>");
                    }
                    //
                    tep.Append(" <td align=\"left\" class=\"zdhh\">访问：<a href=\"" + list[i].CurrentUrl + "\" target=\"_blank\"><span class=\"red14\">" + list[i].CurrentUrl + "</span></a></td>");
                    tep.Append("</tr>");
                    tep.Append("</table><br>");
                }
            }
            return tep.ToString();
        }
    }
}
