using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Xml;
using System.IO;
using System.Windows.Forms;



/// <summary>
/// Doadmin 的摘要说明
/// </summary>
public class Doadmin
{
    public Doadmin()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    #region dropdownlist绑定
    /*
     * dropdownlist绑定 dl为dropdownlist控件ID sqlstr为SQL语句 dt为显示文本； dv为值；
     */
    public static void ddldatabind(DropDownList dl, string sqlstr, string dt, string dv)
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlDataAdapter sdr = new SqlDataAdapter(sqlstr, conn);
        DataSet ds = new DataSet();
        sdr.Fill(ds, "cu");
        dl.DataSource = ds;
        dl.DataTextField = dt;
        dl.DataValueField = dv;
        dl.DataBind();
        conn.Close();
    }
    public static void ddldatabind2(DropDownList dl,DataTable tb, string dt, string dv)
    {
        DataSet ds = new DataSet();
        ds.Tables.Add(tb);
        dl.DataSource = ds;
        dl.DataTextField = dt;
        dl.DataValueField = dv;
        dl.DataBind();
    }
    #endregion
    #region gridview绑定
    /*
     * gridview绑定 gv为gridview控件ID sqlstr为SQL语句；
     */
    public static void gvdatabind(GridView gv, string sqlstr)
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlDataAdapter sdr = new SqlDataAdapter(sqlstr, conn);
        DataSet ds = new DataSet();
        sdr.Fill(ds, "cu");
        gv.DataSource = ds;
        gv.DataBind();
        ds.Clear();
        conn.Close();
    }
 #endregion
    #region 执行SQL语句返回BOOL
    /*
     * 执行SQL语句成功与否；
     */ 
    public static bool Exec(string sqlstr)
    {
        try
        {
            SqlConnection conn = CDatabase.wtoconn();
            conn.Open();
            SqlCommand cmd = new SqlCommand(sqlstr, conn);
            cmd.ExecuteNonQuery();
            return true;
            conn.Close();
        }
        catch (Exception ex)
        {
            return false;
        }
    }


    /*Execsql
    * 只作执行SQL语句；
    */ 
    public static void Execsql(string sqlstr)
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand cmd = new SqlCommand(sqlstr, conn);
        cmd.ExecuteNonQuery();
        conn.Close();
    }
#endregion

    #region 删除文件
    /*
     * FilePicDelete(文件的绝对路径)
     */
    public static bool FilePicDelete(string path)
    {
        bool ret = false;
        System.IO.FileInfo file = new System.IO.FileInfo(path);
        if (file.Exists)
        {
            file.Delete();
            ret = true;
        }
        return ret;
    }
    #endregion

    #region 取客户端信息
    public static string GetRealIP()//真实客户端IP
    {
        string ip;
        try
        {
            HttpRequest request = HttpContext.Current.Request;

            if (request.ServerVariables["HTTP_VIA"] != null)
            {
                ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
            }
            else
            {
                ip = request.UserHostAddress;
            }
        }
        catch (Exception e)
        {
            throw e;
        }

        return ip;
    }   
   public static string GetPreUrl()//来源网址 
    {
        string preUrl;
        try
        {
            HttpRequest request = HttpContext.Current.Request;

            if (request.ServerVariables["HTTP_REFERER"] != null)
            {
                preUrl = request.ServerVariables["HTTP_REFERER"];
            }
            else
            {
                preUrl = request.UserHostAddress;
            }
        }
        catch (Exception e)
        {
            throw e;
        }

        return preUrl;
    }   
    public static string GetUrl()//完整入口
    {
        string Url;
        HttpRequest request = HttpContext.Current.Request;
        Url ="http://"+request.ServerVariables["Server_NAME"].ToString()+request.ServerVariables["URL"].ToString();
        return Url;
    }
   
    public static string GetScreen()//分辩率
    {
        string Screnn;
        HttpRequest request = HttpContext.Current.Request;
        
        Screnn = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString() + "*" + System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height.ToString();
        return Screnn;
    }
    public static string GetOS()//操作系统
    {
        try
        {
            string os;
            os = "其他";
            HttpRequest request = HttpContext.Current.Request;
            string strAgentInfo = request.UserAgent.ToString();
            if (strAgentInfo.Contains("NT 5.2"))
            {
                os = "Windows 2003";
            }
            else if (strAgentInfo.Contains("NT 5.1"))
            {
                os = "Windows XP";
            }
            else if (strAgentInfo.Contains("NT 5"))
            {
                os = "Windows 2000";
            }
            else if (strAgentInfo.Contains("NT 4.9"))
            {
                os = "Windows ME";
            }
            else if (strAgentInfo.Contains("NT 4"))
            {
                os = "Windows NT4";
            }
            else if (strAgentInfo.Contains("NT 98"))
            {
                os = "Windows 98";
            }
            else if (strAgentInfo.Contains("NT 95"))
            {
                os = "Windows 95";
            }
            else if (os.ToLower().Contains("Mac"))
            {
                os = "Mac";
            }
            else if (os.ToLower().Contains("unix"))
            {
                os = "UNIX";
            }
            else if (os.ToLower().Contains("linux"))
            {
                os = "Linux";
            }
            else if (os.Contains("SunOS"))
            {
                os = "SunOS";
            }
            return os;
        }
        catch (Exception e)
        {
            return "其他";
        }
    }
    public static string GetLAN()//语言
    {
        string lan;
        HttpRequest request = HttpContext.Current.Request;
        lan = request.UserLanguages[0];
        return lan;
    }
    public static string GetArear()//地区
    {
        try
        {
            string arear;
            SqlConnection conn = new SqlConnection("server=h30.dgasp.com;database=ip;user id=ipuser;pwd=ippwd;");
            conn.Open();
            long ip = Convert.ToInt64(Doadmin.GetRealIP().ToString().Replace(".", ""));
            SqlCommand smd = new SqlCommand("select address from IP where cast(IPS as BIGINT)<" + ip + " and cast(IPE as BIGINT)>" + ip + "", conn);
            arear = Convert.ToString(smd.ExecuteScalar());
            return arear;
        }
        catch(Exception e)
        {
            return "无法取得";
        }
    }
    #endregion

    #region 统计IP
    public static  void  isdate(DateTime date)//日表统计
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        DateTime d = date.Date;
        SqlCommand smd = new SqlCommand("select count(*) from MtjIP where adddate='"+d+"'", conn);
        if (Convert.ToInt32(smd.ExecuteScalar()) > 0)
        {
            Doadmin.Exec("update MtjIP set iptj=iptj+1 where adddate='" + d+"'");
        }
        else
        {
            Doadmin.Exec("insert into MtjIP(adddate,iptj) values ('"+d+"',1)");
        }
        conn.Close();
    }
    public static void isMoth(DateTime date)//月表统计
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        string  d =date.Year.ToString()+"年"+date.Month.ToString()+"月份";
        SqlCommand smd = new SqlCommand("select count(*) from YtjIP where adddate='" + d + "'", conn);
        if (Convert.ToInt32(smd.ExecuteScalar()) > 0)
        {
            Doadmin.Exec("update YtjIP set ytj=ytj+1 where adddate='" + d + "'");
        }
        else
        {
            Doadmin.Exec("insert into YtjIP(adddate,ytj) values ('" + d + "',1)");
        }
        conn.Close();
    }

    public static void isYear(DateTime date)//年表统计
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        string  d =date.Year.ToString()+"年";
        SqlCommand smd = new SqlCommand("select count(*) from ZIP where adddate='" + d + "'", conn);
        if (Convert.ToInt32(smd.ExecuteScalar()) > 0)
        {
            Doadmin.Exec("update ZIP set ipint=ipint+1 where adddate='" + d + "'");
        }
        else
        {
            Doadmin.Exec("insert into ZIP(adddate,ipint) values ('" + d + "',1)");
        }

        conn.Close();
    }

    public static void ishorm(DateTime date)//24小时分时统计
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        string d = date.Year.ToString() + "年" + date.Month.ToString() + "月" + date.Day.ToString() + "日" + date.Hour.ToString()+"时" ;
        string d2 = date.Year.ToString() + "年" + date.Month.ToString() + "月" + date.Day.ToString() + "日";
        SqlCommand smd = new SqlCommand("select count(*) from HtjIP where adddate='" + d + "'", conn);
        if (Convert.ToInt32(smd.ExecuteScalar()) > 0)
        {
            Doadmin.Exec("update HtjIP set iptj=iptj+1 where adddate='" + d + "'");
        }
        else
        {
            Doadmin.Exec("insert into HtjIP(adddate2,adddate,iptj) values ('"+d2+"','" + d + "',1)");
        }

        conn.Close();
    }
    #endregion

    #region 分页
    public static PagedDataSource ps(DataSet ds, Table Table1, int pagesize, int s)
    {

        HttpRequest Request = HttpContext.Current.Request;
        string[] stra;
        string str = "";
        string url = Request.Url.AbsoluteUri.ToString();
        int count = 0;//统计&
        int count2 = 0;//统计?
        for (int i = 0; i < url.Length; i++)
        {
            if (url[i] == '&')
            {
                count++;
            }
        }

        for (int i = 0; i < url.Length; i++)
        {
            if (url[i] == '?')
            {
                count2++;
            }
        }
        switch (count)
        {
            case 0:
                str = url + "&";
                break;
            case 1:
                stra = url.Split('&');
                str = stra[0] + "&";
                break;
            case 2:
                stra = url.Split('&');
                str = stra[0] + "&" + stra[1] + "&";
                break;
            case 3:
                stra = url.Split('&');
                str = stra[0] + "&" + stra[1] + "&" + stra[2] + "&";
                break;

        }

        if (s == 0)
        {
            if (count2 == 0)
            {
                str = url + "?";
            }
            else
            {
                stra = url.Split('?');
                str = stra[0] + "?";
            }
        }
        int curpage;
        if (Request.QueryString["page"] == null)
        {
            curpage = 1;
        }
        else
        {
            curpage = Convert.ToInt32(Request.QueryString["page"].ToString());
        }
        PagedDataSource ps = new PagedDataSource();
        ps.DataSource = ds.Tables["cu"].DefaultView;
        ps.AllowPaging = true;
        ps.PageSize = pagesize;


        if (Convert.ToInt32(Request.QueryString["page"]) < 1)
        {
            curpage = 1;
        }
        if (Convert.ToInt32(Request.QueryString["page"]) > ps.PageCount)
        {
            curpage = ps.PageCount;
        }
        ps.CurrentPageIndex = curpage - 1;
        TableRow tr = new TableRow();
        TableCell tc;
        HyperLink h1;
        h1 = new HyperLink();
        h1.Text = "Previous";
        h1.NavigateUrl = str + "page=" + (curpage - 1);
        if (curpage <= 1)
        {
            h1.Enabled = false;
            h1.CssClass = "disabled_tnt_pagination";
        }

        tc = new TableCell();
        tc.Controls.Add(h1);
        tr.Controls.Add(tc);

        if (curpage <= 10)
        {
            if (ps.PageCount > 10)
            {
                for (int i = 1; i <= 10; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);

            }
            else
            {
                for (int i = 1; i <= ps.PageCount; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
            }


        }
        if (curpage > 10 && curpage <= 20)
        {
            if (ps.PageCount >= 20)
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 11; i <= 20; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }

                }
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
            }
            else
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 11; i <= ps.PageCount; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
            }
        }

        if (curpage > 20 && curpage <= 30)
        {
            if (ps.PageCount >= 30)
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 21; i <= 30; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
            }
            else
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 21; i <= ps.PageCount; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
            }
        }
        if (curpage > 30 && curpage <= 40)
        {
            if (ps.PageCount >= 30)
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 31; i <= 40; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
            }
            else
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 31; i <= ps.PageCount; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
            }
        }






        h1 = new HyperLink();
        h1.Text = "Next";
        if (curpage >= ps.PageCount)
        {
            h1.Enabled = false;
            h1.CssClass = "disabled_tnt_pagination";
        }
        if (ps.PageCount != 0)
        {
            if (curpage > 0)
            {
                h1.NavigateUrl = str + "page=" + (curpage + 1);
            }
            else
            {
                h1.NavigateUrl = str + "page=" + (curpage + 2);
            }
        }
        else
        {
            h1.Enabled = false;
            h1.CssClass = "disabled_tnt_pagination";
        }
        tc = new TableCell();
        tc.Controls.Add(h1);
        tr.Controls.Add(tc);
        Table1.Controls.Add(tr);
        return ps;
    }

    #endregion

    #region 分页
    /* 分页[URL]：  psgb[中文分页调用]  ps[英文分页调用]
     * 
     * ds为数据源；Table1为显示页码的值； pagesize 多少记录为一页  s 为所链接所到参数  例如  a.aspx?id=100  
     * 因还需在此加上a.aspx?id=100&page=1 所以 s值为 1 如果直接传页码 a.aspx?page=1 则 s值为0
     */
    public static PagedDataSource psgb(DataSet ds, Table Table1, int pagesize, int s)
    {
        HttpRequest Request = HttpContext.Current.Request;
        string[] stra;
        string str = "";
        string url = Request.Url.AbsoluteUri.ToString();
        int count = 0;//统计&
        int count2 = 0;//统计?
        for (int i = 0; i < url.Length; i++)
        {
            if (url[i] == '&')
            {
                count++;
            }
        }

        for (int i = 0; i < url.Length; i++)
        {
            if (url[i] == '?')
            {
                count2++;
            }
        }
        switch (count)
        {
            case 0:
                str = url + "&";
                break;
            case 1:
                stra = url.Split('&');
                str = stra[0] + "&";
                break;
            case 2:
                stra = url.Split('&');
                str = stra[0] + "&" + stra[1] + "&";
                break;
            case 3:
                stra = url.Split('&');
                str = stra[0] + "&" + stra[1] + "&" + stra[2] + "&";
                break;
            case 4:
                stra = url.Split('&');
                str = stra[0] + "&" + stra[1] + "&" + stra[2] + "&"+stra[3]+"&";
                break;
            case 5:
                stra = url.Split('&');
                str = stra[0] + "&" + stra[1] + "&" + stra[2] + "&" + stra[3] + "&" + stra[4] + "&";
                break;

        }

        if (s == 0)
        {
            if (count2 == 0)
            {
                str = url + "?";
            }
            else
            {
                stra = url.Split('?');
                str = stra[0] + "?";
            }
        }
        int curpage;
        if (Request.QueryString["page"] == null)
        {
            curpage = 1;
        }
        else
        {
            curpage = Convert.ToInt32(Request.QueryString["page"].ToString());
        }
        PagedDataSource ps = new PagedDataSource();
        ps.DataSource = ds.Tables[0].DefaultView;
        ps.AllowPaging = true;
        ps.PageSize = pagesize;


        if (Convert.ToInt32(Request.QueryString["page"]) < 1)
        {
            curpage = 1;
        }
        if (Convert.ToInt32(Request.QueryString["page"]) > ps.PageCount)
        {
            curpage = ps.PageCount;
        }
        ps.CurrentPageIndex = curpage - 1;
        TableRow tr = new TableRow();
        TableCell tc;
        HyperLink h1;
        h1 = new HyperLink();
        h1.Text = "上一页";
        h1.NavigateUrl = str + "page=" + (curpage - 1);
        if (curpage <= 1)
        {
            h1.Enabled = false;
            h1.CssClass = "disabled_tnt_pagination";
        }

        tc = new TableCell();
        tc.Controls.Add(h1);
        tr.Controls.Add(tc);

        if (curpage <= 10)
        {
            if (ps.PageCount > 10)
            {
                for (int i = 1; i <= 10; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);

            }
            else
            {
                for (int i = 1; i <= ps.PageCount; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
            }


        }
        if (curpage > 10 && curpage <= 20)
        {
            if (ps.PageCount >= 20)
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 11; i <= 20; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }

                }
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
            }
            else
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 11; i <= ps.PageCount; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
            }
        }

        if (curpage > 20 && curpage <= 30)
        {
            if (ps.PageCount >= 30)
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 21; i <= 30; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
            }
            else
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 21; i <= ps.PageCount; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
            }
        }
        if (curpage > 30 && curpage <= 40)
        {
            if (ps.PageCount >= 30)
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 31; i <= 40; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
            }
            else
            {
                tc = new TableCell();
                h1 = new HyperLink();
                h1.Text = "…";
                tc.Controls.Add(h1);
                tr.Controls.Add(tc);
                for (int i = 31; i <= ps.PageCount; i++)
                {

                    if (curpage != i)
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.NavigateUrl = str + "page=" + i;
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                    else
                    {
                        tc = new TableCell();
                        h1 = new HyperLink();
                        h1.Text = Convert.ToString(i);
                        h1.CssClass = "active_tnt_link";
                        tc.Controls.Add(h1);
                        tr.Controls.Add(tc);
                    }
                }
            }
        }






        h1 = new HyperLink();
        h1.Text = "下一页";
        if (curpage >= ps.PageCount)
        {
            h1.Enabled = false;
            h1.CssClass = "disabled_tnt_pagination";
        }
        if (ps.PageCount != 0)
        {
            if (curpage > 0)
            {
                h1.NavigateUrl = str + "page=" + (curpage + 1);
            }
            else
            {
                h1.NavigateUrl = str + "page=" + (curpage + 2);
            }
        }
        else
        {
            h1.Enabled = false;
            h1.CssClass = "disabled_tnt_pagination";
        }
        tc = new TableCell();
        tc.Controls.Add(h1);
        tr.Controls.Add(tc);
        Table1.Controls.Add(tr);
        return ps;
    }

    #endregion
}

