using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Stat.Html
{
    public class ViewNav
    {
        /// <summary>
        /// 
        /// </summary>
        public static string Get(int webid, DateTime st, DateTime et)
        {
            string strTd;
            string strYd;
            string strD7;
            string strMd;
            string strPro;
            string strNext;
            CommonDate(webid, ref st, ref et, out strTd, out strYd, out strD7, out strMd, out strPro, out strNext);
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            //
            Common(strTd, strYd, strD7, strMd, strPro, strNext, tep);
            //
            Stype1(webid, st, et, tep);
            //
            return tep.ToString();
        }
        /// <summary>
        /// 
        /// </summary>
        public static string Get_IP(int webid, DateTime st, DateTime et, string ip)
        {
            string strTd;
            string strYd;
            string strD7;
            string strMd;
            string strPro;
            string strNext;
            CommonDate(webid, ref st, ref et, out strTd, out strYd, out strD7, out strMd, out strPro, out strNext);
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            //
            Common(strTd, strYd, strD7, strMd, strPro, strNext, tep);
            //
            StypeIP(webid, st, et, ip, tep);
            //
            return tep.ToString();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static string Get_Engine(int webid, DateTime st, DateTime et, string key, int engineId)
        {
            string strTd;
            string strYd;
            string strD7;
            string strMd;
            string strPro;
            string strNext;
            CommonDate(webid, ref st, ref et, out strTd, out strYd, out strD7, out strMd, out strPro, out strNext);
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            //
            Common2(strTd, strYd, strD7, strMd, strPro, strNext, tep);
            //
            StypeEngine(webid, st, et, key, engineId, tep);
            //
            return tep.ToString();
        }

        /// <summary>
        /// 地区查询
        /// </summary>
        public static string Area_IP(int webid, string area, string ip)
        {
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            tep.Append("查询最近20分钟 >&nbsp;&nbsp;");
            tep.Append("地区&nbsp;<input name=\"sArea\" type=\"text\" id=\"sArea\" value=\"" + area + "\" />&nbsp;");
            tep.Append("I P&nbsp;<input name=\"sIP\" type=\"text\" id=\"sIP\" value=\"" + ip + "\" />&nbsp;");
            tep.Append("<input type=\"button\" name=\"SubmitSearch\" id=\"SubmitSearch\" value=\"查询\" />&nbsp;");
            tep.Append("<input name=\"hdfWebid\" type=\"hidden\" id=\"hdfWebid\" value=\"" + webid + "\" />");
            return tep.ToString();
        }
        /// <summary>
        /// 来路页面查询
        /// </summary>
        public static string Referer_IP(int webid, string Referer, string ip)
        {
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            tep.Append("查询最近20分钟 >&nbsp;&nbsp;");
            tep.Append("来路页面&nbsp;<input name=\"sReferer\" type=\"text\" id=\"sReferer\" value=\"" + Referer + "\" />&nbsp;");
            tep.Append("I P&nbsp;<input name=\"sIP\" type=\"text\" id=\"sIP\" value=\"" + ip + "\" />&nbsp;");
            tep.Append("<input type=\"button\" name=\"SubmitSearch\" id=\"SubmitSearch\" value=\"查询\" />&nbsp;");
            tep.Append("<input name=\"hdfWebid\" type=\"hidden\" id=\"hdfWebid\" value=\"" + webid + "\" />");
            return tep.ToString();
        }
        /// <summary>
        /// 停留页面查询
        /// </summary>
        public static string Page_IP(int webid, string sPage, string ip)
        {
            System.Text.StringBuilder tep = new System.Text.StringBuilder();
            tep.Append("查询最近20分钟 >&nbsp;&nbsp;");
            tep.Append("停留页面&nbsp;<input name=\"sPage\" type=\"text\" id=\"sPage\" value=\"" + sPage + "\" />&nbsp;");
            tep.Append("I P&nbsp;<input name=\"sIP\" type=\"text\" id=\"sIP\" value=\"" + ip + "\" />&nbsp;");
            tep.Append("<input type=\"button\" name=\"SubmitSearch\" id=\"SubmitSearch\" value=\"查询\" />&nbsp;");
            tep.Append("<input name=\"hdfWebid\" type=\"hidden\" id=\"hdfWebid\" value=\"" + webid + "\" />");
            return tep.ToString();
        }






        /*-------------------------------------------------------*/
        private static void CommonDate(int webid, ref DateTime st, ref DateTime et, out string strTd, out string strYd, out string strD7, out string strMd, out string strPro, out string strNext)
        {
            string td = DateTime.Now.ToShortDateString();//今日
            string yd = DateTime.Now.AddDays(-1).ToShortDateString();//昨日
            string d7 = DateTime.Now.AddDays(-7).ToShortDateString();
            DateTime md = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            string m1 = md.ToShortDateString();
            string m2 = md.AddMonths(1).AddDays(-1).ToShortDateString();
            //
            strTd = "?wid=" + webid + "&st=" + td + "&et=" + td + "";
            strYd = "?wid=" + webid + "&st=" + yd + "&et=" + yd + "";
            strD7 = "?wid=" + webid + "&st=" + d7 + "&et=" + yd + "";
            strMd = "?wid=" + webid + "&st=" + m1 + "&et=" + m2 + "";
            strPro = "?wid=" + webid + "&st=" + st.AddDays(-1).ToShortDateString() + "&et=" + et.AddDays(-1).ToShortDateString() + "";
            strNext = "?wid=" + webid + "&st=" + st.AddDays(1).ToShortDateString() + "&et=" + et.AddDays(1).ToShortDateString() + "";
            //
        }
        private static void Common(string strTd, string strYd, string strD7, string strMd, string strPro, string strNext, System.Text.StringBuilder tep)
        {
            tep.Append("<a href=\"" + strTd + "\">今日</a>&nbsp;<a href=\"" + strYd + "\">昨日</a>&nbsp;<a href=\"" + strD7 + "\">最近7天</a>&nbsp;");
            tep.Append("<a href=\"" + strMd + "\">本月</a>&nbsp;<a href=\"" + strPro + "\">前一天</a>&nbsp;<a href=\"" + strNext + "\">后一天</a>&nbsp;");

        }
        private static void Common2(string strTd, string strYd, string strD7, string strMd, string strPro, string strNext, System.Text.StringBuilder tep)
        {
            tep.Append("<a href=\"" + strTd + "\">今日</a>&nbsp;<a href=\"" + strYd + "\">昨日</a>&nbsp;");
            tep.Append("<a href=\"" + strPro + "\">前一天</a>&nbsp;<a href=\"" + strNext + "\">后一天</a>&nbsp;");

        }
        /// <summary>
        /// 时间查询
        /// </summary>
        private static void Stype1(int webid, DateTime st, DateTime et, System.Text.StringBuilder tep)
        {
            tep.Append("从&nbsp;<input name=\"sTime\" type=\"text\" id=\"sTime\" value=\"" + st.ToShortDateString() + "\" />&nbsp;");
            tep.Append("至&nbsp;<input name=\"eTime\" type=\"text\" id=\"eTime\" value=\"" + et.ToShortDateString() + "\" />&nbsp;");
            tep.Append("<input type=\"button\" name=\"SubmitSearch\" id=\"SubmitSearch\" value=\"查询\" />&nbsp;");
            tep.Append("<input name=\"hdfWebid\" type=\"hidden\" id=\"hdfWebid\" value=\"" + webid + "\" />");
        }
        /// <summary>
        /// 带IP查询
        /// </summary>
        private static void StypeIP(int webid, DateTime st, DateTime et, string ip, System.Text.StringBuilder tep)
        {
            tep.Append("IP&nbsp;<input name=\"sIP\" type=\"text\" id=\"sIP\" value=\"" + ip + "\" />&nbsp;");
            tep.Append("从&nbsp;<input name=\"sTime\" type=\"text\" id=\"sTime\" value=\"" + st.ToShortDateString() + "\" />&nbsp;");
            tep.Append("至&nbsp;<input name=\"eTime\" type=\"text\" id=\"eTime\" value=\"" + et.ToShortDateString() + "\" />&nbsp;");
            tep.Append("<input type=\"button\" name=\"SubmitSearch\" id=\"SubmitSearch\" value=\"查询\" />&nbsp;");
            tep.Append("<input name=\"hdfWebid\" type=\"hidden\" id=\"hdfWebid\" value=\"" + webid + "\" />");
        }
        /// <summary>
        /// 带关键字查询
        /// </summary>
        private static void StypeEngine(int webid, DateTime st, DateTime et, string key, int engineId, System.Text.StringBuilder tep)
        {
            tep.Append("关键字&nbsp;<input name=\"sKeyWord\" type=\"text\" id=\"sKeyWord\" value=\"" + key + "\" />&nbsp;");
            //
            string[,] arr = Stat.Items.Engine.Get();
            tep.Append("<select name=\"engine\" id=\"engine\">");
            tep.Append("<option value=\"0\">全部</option>");
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                if (arr[i, 0] == engineId.ToString())
                {
                    tep.Append("<option value=\"" + arr[i, 0] + "\" selected=\"selected\" >" + arr[i, 1] + "</option>");
                }
                else
                {
                    tep.Append("<option value=\"" + arr[i, 0] + "\">" + arr[i, 1] + "</option>");
                }
            }
            tep.Append("</select>");
            //
            tep.Append("从&nbsp;<input name=\"sTime\" type=\"text\" id=\"sTime\" value=\"" + st.ToShortDateString() + "\" />&nbsp;");
            tep.Append("至&nbsp;<input name=\"eTime\" type=\"text\" id=\"eTime\" value=\"" + et.ToShortDateString() + "\" />&nbsp;");
            tep.Append("<input type=\"button\" name=\"SubmitSearch\" id=\"SubmitSearch\" value=\"查询\" />&nbsp;");
            tep.Append("<input name=\"hdfWebid\" type=\"hidden\" id=\"hdfWebid\" value=\"" + webid + "\" />");
        }
    }
}
