using System.Collections.Generic;

namespace Stat.Html
{
    public class OnLine
    {
        /// <summary>
        /// 用户在线数据列表（HTML）
        /// </summary>
        /// <param name="list"></param>
        /// <param name="cPage"></param>
        /// <param name="pSize"></param>
        /// <returns></returns>
        public static string Get(IList<Model.Online> list, int webid, int cPage, int pSize)
        {
            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=\"12%\" align=\"left\"  height=\"25\"><strong>用户编号</strong></td>");
                sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"20%\" align=\"left\"><strong>上网 IP 地址</strong></td>");
                //sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"15%\" align=\"left\" ><strong>ISP运营商</strong></td>");
                sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"20%\" align=\"left\" ><strong>国家/地区</strong></td>");
                sb.Append("   <td bgcolor=\"#e9f1fa\" width=\"*\" 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++)
                {
                    sb.Append("<tr bgcolor=\"#FFFFFF\" onmouseover=\"this.style.backgroundColor='#EEF3F9';\" onmouseout=\"this.style.backgroundColor='#FFFFFF';\">");

                    sb.Append(" <td align=\"left\" height=23>&nbsp;" + (i + 1) + "</td>");
                    sb.Append(" <td align=\"left\" id=\"ipIndex_" + i + "\" ><a href=\"Vpage.aspx?wid=" + webid + "&ip=" + list[i].IP + "\" title=\"追踪该IP\" ><span class=\"red14\">" + list[i].IP + "</span></a></td>");
                    //sb.Append(" <td align=\"left\" ><span class=\"red14\">" + GetIpInfo(list[i].ISP, list[i].IP) + "</span></td>");
                    sb.Append(" <td align=\"left\" ><span class=\"red14\">" + list[i].Area + "</span></td>");
                    sb.Append(" <td align=\"left\" id=\"ipShow_" + i + "\" ><a href=\"javascript:void(0);\" onClick=\"GetInfo('" + list[i].IP + "',this);\">查看详细</a></td>");

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

        private static string GetIpInfo(string str, string ip)
        {
            if (str == null || str.Length == 0)
            {
                //  string url = "<a href=\"/IP.aspx?ip=" + ip + "\" target=\"_blank\">未知</a>");
                string url = "未知";
                return url;
            }
            return str;
        }
    }
}
