using System;

namespace Stat.Html
{
    public class ViewNav
    {
        #region ：私有链接样式
        /// <summary>
        /// 获取今日链接
        /// </summary>
        /// <param name="webid"></param>
        /// <returns></returns>
        /// <remarks>Juju 2011-10-26</remarks>
        private static string GetTodayLink(int webid)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            string link = "?wid=" + webid + "&st=" + DateTime.Now.ToShortDateString() + "&et=" + DateTime.Now.AddDays(1).ToShortDateString() + "";
            navigationString.Append("<a href=\"" + link + "\">今日</a>");
            return navigationString.ToString();
        }
        /// <summary>
        /// 获取昨日链接
        /// </summary>
        /// <param name="webid"></param>
        /// <returns></returns>
        /// <remarks>Juju 2011-10-26</remarks>
        private static string GetYesterdayLink(int webid)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            string link = "?wid=" + webid + "&st=" + DateTime.Now.AddDays(-1).ToShortDateString() + "&et=" + DateTime.Now.ToShortDateString() + "";
            navigationString.Append("<a href=\"" + link + "\">昨日</a>");
            return navigationString.ToString();
        }
        /// <summary>
        /// 获取最近7天链接
        /// </summary>
        /// <param name="webid"></param>
        /// <returns></returns>
        private static string GetLastDay7Link(int webid)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            string link = "?wid=" + webid + "&st=" + DateTime.Now.AddDays(-7).ToShortDateString() + "&et=" + DateTime.Now.ToShortDateString() + "";
            navigationString.Append("<a href=\"" + link + "\">最近7天</a>");
            return navigationString.ToString();
        }
        /// <summary>
        /// 获取本月链接
        /// </summary>
        /// <param name="webid"></param>
        /// <returns></returns>
        private static string GetCurrentMonthLink(int webid)
        {
            DateTime md = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            string m1 = md.ToShortDateString();
            string m2 = md.AddMonths(1).AddDays(-1).ToShortDateString();
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            string link = "?wid=" + webid + "&st=" + m1 + "&et=" + m2 + "";
            navigationString.Append("<a href=\"" + link + "\">本月</a>");
            return navigationString.ToString();
        }
        /// <summary>
        /// 获取前一天链接
        /// </summary>
        /// <param name="webid"></param>
        /// <returns></returns>
        private static string GetPreviousDayLink(int webid, DateTime st, DateTime et)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            string link = "?wid=" + webid + "&st=" + st.AddDays(-1).ToShortDateString() + "&et=" + et.AddDays(-1).ToShortDateString() + "";
            navigationString.Append("<a href=\"" + link + "\">前一天</a>");
            return navigationString.ToString();
        }
        /// <summary>
        /// 获取前一天链接
        /// </summary>
        /// <param name="webid"></param>
        /// <returns></returns>
        private static string GetPreviousDayLink(int webid, DateTime st)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            string link = "?wid=" + webid + "&st=" + st.AddDays(-1).ToShortDateString() + "";
            navigationString.Append("<a href=\"" + link + "\">前一天</a>");
            return navigationString.ToString();
        }
        /// <summary>
        /// 获取后一天链接
        /// </summary>
        /// <param name="webid"></param>
        /// <returns></returns>
        private static string GetLaterDayLink(int webid, DateTime st, DateTime et)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            string link = "?wid=" + webid + "&st=" + st.AddDays(1).ToShortDateString() + "&et=" + et.AddDays(1).ToShortDateString() + "";
            navigationString.Append("<a href=\"" + link + "\">后一天</a>");
            return navigationString.ToString();
        }
        /// <summary>
        /// 获取后一天链接
        /// </summary>
        /// <param name="webid"></param>
        /// <returns></returns>
        private static string GetLaterDayLink(int webid, DateTime st)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            string link = "?wid=" + webid + "&st=" + st.AddDays(1).ToShortDateString();
            navigationString.Append("<a href=\"" + link + "\">后一天</a>");
            return navigationString.ToString();
        }
        /// <summary>
        /// 时间查询
        /// </summary>
        private static string GetDateTimeButton(int webid, DateTime st, DateTime et)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            navigationString.Append("从&nbsp;<input name=\"sTime\" type=\"text\" id=\"sTime\" value=\"" + st.ToShortDateString() + "\" />&nbsp;");
            navigationString.Append("至&nbsp;<input name=\"eTime\" type=\"text\" id=\"eTime\" value=\"" + et.ToShortDateString() + "\" />&nbsp;");
            navigationString.Append("<input type=\"button\" name=\"SubmitSearch\" id=\"SubmitSearch\" value=\"查询\" />&nbsp;");
            navigationString.Append("<input name=\"hdfWebid\" type=\"hidden\" id=\"hdfWebid\" value=\"" + webid + "\" />");
            return navigationString.ToString();
        }

        /// <summary>
        /// 时间查询
        /// </summary>
        private static string GetDateTimeButton(int webid, DateTime st)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            navigationString.Append("从&nbsp;<input name=\"sTime\" type=\"text\" id=\"sTime\" value=\"" + st.ToShortDateString() + "\" />&nbsp;");
            navigationString.Append("<input type=\"button\" name=\"SubmitSearch\" id=\"SubmitSearch\" value=\"查询\" />&nbsp;");
            navigationString.Append("<input name=\"hdfWebid\" type=\"hidden\" id=\"hdfWebid\" value=\"" + webid + "\" />");
            return navigationString.ToString();
        }
        /// <summary>
        /// 带关键字查询
        /// </summary>
        private static string GetKeyword(string key)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            navigationString.Append("关键字&nbsp;<input name=\"sKeyWord\" type=\"text\" id=\"sKeyWord\" value=\"" + key + "\" />&nbsp;");
            return navigationString.ToString();
        }
        /// <summary>
        /// 查询按钮
        /// </summary>
        private static string GetSeachButton()
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            navigationString.Append("<input type=\"button\" name=\"SubmitSearch\" id=\"SubmitSearch\" value=\"查询\" />&nbsp;");
            return navigationString.ToString();
        }
        /// <summary>
        /// 隐藏的wedid Hideden File
        /// </summary>
        private static string GetHidenWebid(int webid)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            navigationString.Append("<input name=\"hdfWebid\" type=\"hidden\" id=\"hdfWebid\" value=\"" + webid + "\" />");
            return navigationString.ToString();
        }

        /// <summary>
        /// 引擎分类查询
        /// </summary>
        private static string GetEngineCategory(int engineId)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            string[,] arr = Stat.Items.Engine.Get();
            navigationString.Append("<select name=\"engine\" id=\"engine\">");
            navigationString.Append("<option value=\"0\">全部</option>");
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                if (arr[i, 0] == engineId.ToString())
                    navigationString.Append("<option value=\"" + arr[i, 0] + "\" selected=\"selected\" >" + arr[i, 1] + "</option>");
                else
                    navigationString.Append("<option value=\"" + arr[i, 0] + "\">" + arr[i, 1] + "</option>");
            }
            navigationString.Append("</select>");
            return navigationString.ToString();
        }
        #endregion

        #region ：带有关键字搜索（今日，昨日，7日，本月，时间搜索框）
        /// <summary>
        /// 导航链接（今日，昨日，7日，本月，时间搜索框）
        /// </summary>
        /// <returns></returns>
        /// <remarks>Juju 2011-10-26</remarks>
        public static string GetNavigation(int webid, DateTime st, DateTime et, string key, int engineId)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            navigationString.Append(GetTodayLink(webid) + "&nbsp;");
            navigationString.Append(GetYesterdayLink(webid) + "&nbsp;");
            navigationString.Append(GetLastDay7Link(webid) + "&nbsp;");
            navigationString.Append(GetCurrentMonthLink(webid) + "&nbsp;");
            //  navigationString.Append(GetPreviousDayLink(webid, st, et) + "&nbsp;");
            // navigationString.Append(GetLaterDayLink(webid, st, et) + "&nbsp;");
            navigationString.Append(GetKeyword(key));
            navigationString.Append(GetEngineCategory(engineId));
            navigationString.Append(GetDateTimeButton(webid, st, et));
            return navigationString.ToString();
        }
        #endregion

        #region ：带有搜索引擎分类
        /// <summary>
        /// 导航链接（今日，昨日，7日，本月，时间搜索框）
        /// </summary>
        /// <returns></returns>
        /// <remarks>Juju 2011-10-26</remarks>
        public static string GetNavigation(int webid, DateTime st, DateTime et, int engineId)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            navigationString.Append(GetTodayLink(webid) + "&nbsp;");
            navigationString.Append(GetYesterdayLink(webid) + "&nbsp;");
            navigationString.Append(GetLastDay7Link(webid) + "&nbsp;");
            navigationString.Append(GetCurrentMonthLink(webid) + "&nbsp;");
            navigationString.Append(GetPreviousDayLink(webid, st, et) + "&nbsp;");
            navigationString.Append(GetLaterDayLink(webid, st, et) + "&nbsp;");
            navigationString.Append(GetEngineCategory(engineId));
            navigationString.Append(GetDateTimeButton(webid, st, et));
            return navigationString.ToString();
        }
        #endregion

        #region : 2天时间间隔一般导航
        /// <summary>
        /// 导航链接（今日，昨日，7日，本月，时间搜索框）
        /// </summary>
        /// <returns></returns>
        /// <remarks>Juju 2011-10-26</remarks>
        public static string GetNavigation(int webid, DateTime st, DateTime et)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            navigationString.Append(GetTodayLink(webid) + "&nbsp;");
            navigationString.Append(GetYesterdayLink(webid) + "&nbsp;");
            navigationString.Append(GetLastDay7Link(webid) + "&nbsp;");
            navigationString.Append(GetCurrentMonthLink(webid) + "&nbsp;");
            navigationString.Append(GetPreviousDayLink(webid, st, et) + "&nbsp;");
            navigationString.Append(GetLaterDayLink(webid, st, et) + "&nbsp;");
            navigationString.Append(GetDateTimeButton(webid, st, et));
            return navigationString.ToString();
        }
        #endregion

        #region ：单天 一般导航
        /// <summary>
        /// 单天导航链接（今日，昨日 上一天，下一天，单个时间搜索框）
        /// </summary>
        /// <returns></returns>
        /// <remarks>Juju 2011-11-2</remarks>
        public static string GetNavigation(int webid, DateTime st)
        {
            System.Text.StringBuilder navigationString = new System.Text.StringBuilder();
            navigationString.Append(GetTodayLink(webid) + "&nbsp;");
            navigationString.Append(GetYesterdayLink(webid) + "&nbsp;");
            navigationString.Append(GetPreviousDayLink(webid, st) + "&nbsp;");
            navigationString.Append(GetLaterDayLink(webid, st) + "&nbsp;");
            navigationString.Append(GetDateTimeButton(webid, st));
            return navigationString.ToString();
        }
        #endregion

    }
}
