using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

/// <summary>
///PasePage 的摘要说明
/// </summary>
public class PasePage : System.Web.UI.Page
{
    public PasePage()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //

       
    }


    protected override void OnInit(EventArgs e)
    {
        if (Session["UserName"] == null)
        {
            Response.Write("<script>window.top.location.href='../login.aspx';</script>");
        }
    }

    protected int GetInt(object obj, int defaultValue)
    {
        if (obj != null)
        {
            try
            {
                defaultValue = Convert.ToInt32(obj);
            }
            catch
            {
            }
        }
        return defaultValue;
    }

    /// <summary>
    /// 截取数组字符串
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public string GetSubStr(string[] str, string s)
    {
        foreach (string substr in str)
        {
            if (s.IndexOf(substr) > -1)
            {
                s = s.Substring(0, s.IndexOf(substr));
            }
        }
        if (s.LastIndexOf('?') + 1 == s.Length)
        {
            s = s.Replace("?", "");
        }
        if (s.LastIndexOf('&') + 1 == s.Length)
        {
            s = s.Replace("&", "");
        }
        return s;
    }

    /// <summary>
    /// 获取分页信息
    /// </summary>
    public static void GetPage(StringBuilder sb, int currentPage, int totalCount, int pageSize)
    {
        //int j = 0;
        //int temp_page = currentPage;
        //if (temp_page - 5 > 0 && totalPage >= 10)
        //{
        //    temp_page -= 5;
        //    if (totalPage - temp_page < 9)
        //        temp_page = totalPage - 9;
        //}
        //else
        //{
        //    temp_page = 1;
        //}
        int totalPage = (totalCount - 1) / pageSize + 1;
        sb.Append("<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"margin-bottom:-5px;\">");
        //sb.Append("<tr><td class=\"page_left_td\">");
        sb.Append("<tr ><td align=\"center\">");
        //sb.Append("【&nbsp;共<font class=\"page_blue\">").Append(totalCount).Append("</font>条&nbsp;当前第<font class=\"page_blue\">");
        //sb.Append(currentPage).Append("</font>页&nbsp;共<font class=\"page_blue\">").Append(totalPage).Append("</font>页&nbsp;】");
        sb.Append("【&nbsp;共<b>").Append(totalCount).Append("</b>条&nbsp;当前第<font color=\"red\"><b>");
        sb.Append(currentPage).Append("</b></font>页&nbsp;共<b>").Append(totalPage).Append("</b>页&nbsp;】");

        //sb.Append("</td><td style=\"padding-top:3px;padding-left:10px;\">");
        sb.Append("</td><td style=\"padding-left:10px;\">");
        //sb.Append("<img src=\"../../images/info_sel/left_sy.png\" style=\"cursor:pointer;\" ");  
        sb.Append("<span style=\"cursor:pointer;\" ");
        if (currentPage != 1)
        {
            sb.Append(" onclick=\"toPage(1);\" ");
        }
        //sb.Append("/>");
        sb.Append(">【首页】</span>");
        sb.Append("&nbsp;&nbsp;");
        //sb.Append("<img src=\"../../images/info_sel/left_syy.png\" style=\"cursor:pointer;\" ");
        sb.Append("<span style=\"cursor:pointer;\" ");
        if (currentPage != 1)
        {
            int tempPage = currentPage - 1;
            sb.Append(" onclick=\"toPage(").Append(tempPage).Append(");\" ");
        }
        //sb.Append("/>");
        sb.Append(">【上一页】</span>");
        sb.Append("&nbsp;&nbsp;");
        //sb.Append("<img src=\"../../images/info_sel/left_xyy.png\" style=\"cursor:pointer;\" ");
        sb.Append("<span style=\"cursor:pointer;\" ");
        if (currentPage != totalPage)
        {
            int tempPage = currentPage + 1;
            sb.Append(" onclick=\"toPage(").Append(tempPage).Append(");\" ");
        }
        //sb.Append("/>");
        sb.Append(">【下一页】</span>");
        sb.Append("&nbsp;&nbsp;");
        //sb.Append("<img src=\"../../images/info_sel/left_wy.png\" style=\"cursor:pointer;\" ");
        sb.Append("<span style=\"cursor:pointer;\" ");
        if (currentPage != totalPage)
        {
            sb.Append(" onclick=\"toPage(").Append(totalPage).Append(")\" ");
        }
        //sb.Append("/>");
        sb.Append(">【尾页】</span>");
        sb.Append("</td><td align=\"right\" >");
        //sb.Append("<img onclick=\"toIndex();\" style=\"cursor:pointer;\" src=\"../../images/info_sel/left_fh.png\" />");
        sb.Append("&nbsp;");
        sb.Append("</td>");
        sb.Append("</tr></table>");

        //sb.Append("<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">");
        //sb.Append("<tr><td align='right' style=\"padding-right:50px;\">");
        //sb.Append("【 共<b>").Append(totalCount).Append("</b> 条&nbsp; 当前第<font color=\"red\"><b>").Append(currentPage).Append("</b></font>页&nbsp; 共<b>").Append(totalPage).Append("</b>页 】");
        //sb.Append("</td><td style=\"padding-left:50px;\">");
        //if (currentPage == 1)
        //    sb.Append("<span class=\"page_dis\">【首页】</span><span class=\"page_dis\">【上一页】</span>");
        //else
        //{
        //    int tempPage = currentPage - 1;
        //    sb.Append("<span class=\"page_def\" onclick=\"toPage(1);\">【首页】</span><span class=\"page_def\" onclick=\"toPage(").Append(tempPage).Append(");\">【上一页】</span>");
        //}

        //for (int i = temp_page; i <= totalPage && j < 10; i++)
        //{
        //    j++;
        //    if (currentPage == i)
        //        sb.Append("<span class=\"page_num_sel\">").Append(i).Append("</span>");
        //    else
        //        sb.Append("<span class=\"page_num\" onclick=\"toPage(").Append(i).Append(");\">").Append(i).Append("</span>");
        //}
        //if (currentPage == totalPage)
        //    sb.Append("<span class=\"page_dis\">【下一页】</span><span class=\"page_dis\">【尾页】</span>");
        //else
        //{
        //    int tempPage = currentPage + 1;
        //    sb.Append("<span class=\"page_def\" onclick=\"toPage(");
        //    sb.Append(tempPage);
        //    sb.Append(");\">【下一页】</span><span class=\"page_def\" onclick=\"toPage(");
        //    sb.Append(totalPage);
        //    sb.Append(");\">【尾页】</span>");
        //}
        //sb.Append("</td></tr></table>");
    }
}
