• Cnic.LinkHelper


      1     public class LinkHelper
      2     {
      3 
      4         /// <summary>
      5         /// 获取总页数
      6         /// </summary>
      7         /// <param name="totalCount"></param>
      8         /// <param name="pageSize"></param>
      9         /// <returns></returns>
     10         public static int GetTotalPage(int totalCount, int pageSize)
     11         {
     12             if (totalCount % pageSize == 0)
     13             {
     14                 return totalCount / pageSize;
     15             }
     16             return totalCount / pageSize + 1;
     17         }
     18         /// <summary>
     19         /// 获取总页数
     20         /// </summary>
     21         /// <param name="totalCount"></param>
     22         /// <param name="pageSize"></param>
     23         /// <returns></returns>
     24         public static int GetPageCount(int totalCount, int pageSize)
     25         {
     26             return (totalCount + pageSize - 1) / pageSize;
     27         }
     28 
     29         #region 分页链接 Goosoz@163.com  /2012
     30 
     31 
     32 
     33         /// <summary>
     34         /// 中间是当前页码,左边右边各4个连接 
     35         /// </summary>
     36         /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
     37         /// <param name="page">page从1开始</param>
     38         /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
     39         /// <returns></returns>
     40         public static StringBuilder Simple4(string formatUrl, int page, int maxPage)
     41         {
     42             StringBuilder rtun = new StringBuilder();
     43             if (maxPage > 1)
     44             {
     45                 if (page > maxPage) { page = maxPage; }
     46                 if (page < 1) { page = 1; }
     47 
     48                 #region 中间 3,4,5,6,7,[8],9,10,11,12,13
     49                 int seek = 4;
     50 
     51                 int start = page - seek;
     52                 if ((maxPage - start) < 9) { start = maxPage - 9; }
     53                 if (start < 1) { start = 1; }
     54 
     55                 int end = page + seek;
     56                 if (end < 9) { end = 9; }
     57                 if (end > maxPage) { end = maxPage; }
     58 
     59                 for (int i = start; i <= end; i++)
     60                 {
     61                     if (i == page)
     62                     {
     63                         //rtun.Append("<b>" + i + "</b>");
     64                         rtun.Append("<b>");
     65                         rtun.Append(i);
     66                         rtun.Append("</b>");
     67                     }
     68                     else
     69                     {
     70                         //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
     71                         rtun.Append("<a href=\"");
     72                         rtun.Append(string.Format(formatUrl, i.ToString()));
     73                         rtun.Append("\">");
     74                         rtun.Append(i);
     75                         rtun.Append("</a>");
     76                     }
     77                 }
     78                 #endregion
     79 
     80             }
     81             return rtun;
     82         }
     83         /// <summary>
     84         /// 中间是当前页码,左边右边各4个连接
     85         /// </summary>
     86         /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
     87         /// <param name="page">page从1开始</param>
     88         /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
     89         /// <returns></returns>
     90         public static StringBuilder Simple4(string formatUrl, int page, int pageSize, int totalRow)
     91         {
     92             StringBuilder rtun = new StringBuilder();
     93             if (totalRow > pageSize)
     94             {
     95                 int maxPage = GetTotalPage(totalRow, pageSize);
     96 
     97                 if (page > maxPage) { page = maxPage; }
     98                 if (page < 1) { page = 1; }
     99 
    100                 #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    101                 int seek = 4;
    102 
    103                 int start = page - seek;
    104                 if ((maxPage - start) < 9) { start = maxPage - 9; }
    105                 if (start < 1) { start = 1; }
    106 
    107                 int end = page + seek;
    108                 if (end < 9) { end = 9; }
    109                 if (end > maxPage) { end = maxPage; }
    110 
    111                 for (int i = start; i <= end; i++)
    112                 {
    113                     if (i == page)
    114                     {
    115                         //rtun.Append("<b>" + i + "</b>");
    116                         rtun.Append("<b>");
    117                         rtun.Append(i);
    118                         rtun.Append("</b>");
    119                     }
    120                     else
    121                     {
    122                         //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    123                         rtun.Append("<a href=\"");
    124                         rtun.Append(string.Format(formatUrl, i.ToString()));
    125                         rtun.Append("\">");
    126                         rtun.Append(i);
    127                         rtun.Append("</a>");
    128                     }
    129                 }
    130                 #endregion
    131 
    132             }
    133             return rtun;
    134         }
    135         /// <summary>
    136         /// 中间是当前页码,左边右边各5个连接
    137         /// </summary>
    138         /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    139         /// <param name="page">page从1开始</param>
    140         /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    141         /// <returns></returns>
    142         public static StringBuilder Simple5(string formatUrl, int page, int maxPage)
    143         {
    144             StringBuilder rtun = new StringBuilder();
    145             if (maxPage > 1)
    146             {
    147                 if (page > maxPage) { page = maxPage; }
    148                 if (page < 1) { page = 1; }
    149 
    150                 #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    151                 int seek = 5;
    152 
    153                 int start = page - seek;
    154                 if ((maxPage - start) < 11) { start = maxPage - 11; }
    155                 if (start < 1) { start = 1; }
    156 
    157                 int end = page + seek;
    158                 if (end < 11) { end = 11; }
    159                 if (end > maxPage) { end = maxPage; }
    160 
    161                 for (int i = start; i <= end; i++)
    162                 {
    163                     if (i == page)
    164                     {
    165                         //rtun.Append("<b>" + i + "</b>");
    166                         rtun.Append("<b>");
    167                         rtun.Append(i);
    168                         rtun.Append("</b>");
    169                     }
    170                     else
    171                     {
    172                         //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    173                         rtun.Append("<a href=\"");
    174                         rtun.Append(string.Format(formatUrl, i.ToString()));
    175                         rtun.Append("\">");
    176                         rtun.Append(i);
    177                         rtun.Append("</a>");
    178                     }
    179                 }
    180                 #endregion
    181 
    182             }
    183             return rtun;
    184         }
    185         /// <summary>
    186         /// 中间是当前页码,左边右边各5个连接
    187         /// </summary>
    188         /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    189         /// <param name="page">page从1开始</param>
    190         /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    191         /// <returns></returns>
    192         public static StringBuilder Simple5(string formatUrl, int page, int pageSize, int totalRow)
    193         {
    194             StringBuilder rtun = new StringBuilder();
    195             if (totalRow > pageSize)
    196             {
    197                 int maxPage = GetTotalPage(totalRow, pageSize);
    198 
    199                 if (page > maxPage) { page = maxPage; }
    200                 if (page < 1) { page = 1; }
    201 
    202                 #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    203                 int seek = 5;
    204 
    205                 int start = page - seek;
    206                 if ((maxPage - start) < 11) { start = maxPage - 11; }
    207                 if (start < 1) { start = 1; }
    208 
    209                 int end = page + seek;
    210                 if (end < 11) { end = 11; }
    211                 if (end > maxPage) { end = maxPage; }
    212 
    213                 for (int i = start; i <= end; i++)
    214                 {
    215                     if (i == page)
    216                     {
    217                         //rtun.Append("<b>" + i + "</b>");
    218                         rtun.Append("<b>");
    219                         rtun.Append(i);
    220                         rtun.Append("</b>");
    221                     }
    222                     else
    223                     {
    224                         //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    225                         rtun.Append("<a href=\"");
    226                         rtun.Append(string.Format(formatUrl, i.ToString()));
    227                         rtun.Append("\">");
    228                         rtun.Append(i);
    229                         rtun.Append("</a>");
    230                     }
    231                 }
    232                 #endregion
    233 
    234             }
    235             return rtun;
    236         }
    237         /// <summary>
    238         /// 第一页 中间是当前页码,左边右边各4个连接 末页
    239         /// </summary>
    240         /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    241         /// <param name="page">page从1开始</param>
    242         /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    243         /// <returns></returns>
    244         public static StringBuilder Normal4(string formatUrl, int page, int maxPage)
    245         {
    246             StringBuilder rtun = new StringBuilder();
    247             if (maxPage > 1)
    248             {
    249                 if (page > maxPage) { page = maxPage; }
    250                 if (page < 1) { page = 1; }
    251                 #region 第一页
    252                 if (page == 1)
    253                 {
    254                     rtun.Append("<b>");
    255                     rtun.Append("第一页");
    256                     rtun.Append("</b>");
    257                 }
    258                 else
    259                 {
    260                     rtun.Append("<a href=\"");
    261                     rtun.Append(string.Format(formatUrl, page.ToString()));
    262                     rtun.Append("\">");
    263                     rtun.Append("第一页");
    264                     rtun.Append("</a>");
    265                 }
    266                 #endregion
    267 
    268                 #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    269                 int seek = 4;
    270 
    271                 int start = page - seek;
    272                 if ((maxPage - start) < 9) { start = maxPage - 9; }
    273                 if (start < 1) { start = 1; }
    274 
    275                 int end = page + seek;
    276                 if (end < 9) { end = 9; }
    277                 if (end > maxPage) { end = maxPage; }
    278 
    279                 for (int i = start; i <= end; i++)
    280                 {
    281                     if (i == page)
    282                     {
    283                         //rtun.Append("<b>" + i + "</b>");
    284                         rtun.Append("<b>");
    285                         rtun.Append(i);
    286                         rtun.Append("</b>");
    287                     }
    288                     else
    289                     {
    290                         //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    291                         rtun.Append("<a href=\"");
    292                         rtun.Append(string.Format(formatUrl, i.ToString()));
    293                         rtun.Append("\">");
    294                         rtun.Append(i);
    295                         rtun.Append("</a>");
    296                     }
    297                 }
    298                 #endregion
    299 
    300                 #region 末页
    301                 if (page == maxPage)
    302                 {
    303                     rtun.Append("<b>");
    304                     rtun.Append("末页");
    305                     rtun.Append("</b>");
    306                 }
    307                 else
    308                 {
    309                     rtun.Append("<a href=\"");
    310                     rtun.Append(string.Format(formatUrl, page.ToString()));
    311                     rtun.Append("\">");
    312                     rtun.Append("末页");
    313                     rtun.Append("</a>");
    314                 }
    315                 #endregion
    316             }
    317             return rtun;
    318         }
    319         /// <summary>
    320         /// 第一页 中间是当前页码,左边右边各4个连接 末页
    321         /// </summary>
    322         /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    323         /// <param name="page">page从1开始</param>
    324         /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    325         /// <returns></returns>
    326         public static StringBuilder Normal4(string formatUrl, int page, int pageSize, int totalRow)
    327         {
    328             StringBuilder rtun = new StringBuilder();
    329             if (totalRow > pageSize)
    330             {
    331                 int maxPage = GetTotalPage(totalRow, pageSize);
    332 
    333                 if (page > maxPage) { page = maxPage; }
    334                 if (page < 1) { page = 1; }
    335                 #region 第一页
    336                 if (page == 1)
    337                 {
    338                     rtun.Append("<b>");
    339                     rtun.Append("第一页");
    340                     rtun.Append("</b>");
    341                 }
    342                 else
    343                 {
    344                     rtun.Append("<a href=\"");
    345                     rtun.Append(string.Format(formatUrl, page.ToString()));
    346                     rtun.Append("\">");
    347                     rtun.Append("第一页");
    348                     rtun.Append("</a>");
    349                 }
    350                 #endregion
    351 
    352                 #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    353                 int seek = 4;
    354 
    355                 int start = page - seek;
    356                 if ((maxPage - start) < 9) { start = maxPage - 9; }
    357                 if (start < 1) { start = 1; }
    358 
    359                 int end = page + seek;
    360                 if (end < 9) { end = 9; }
    361                 if (end > maxPage) { end = maxPage; }
    362 
    363                 for (int i = start; i <= end; i++)
    364                 {
    365                     if (i == page)
    366                     {
    367                         //rtun.Append("<b>" + i + "</b>");
    368                         rtun.Append("<b>");
    369                         rtun.Append(i);
    370                         rtun.Append("</b>");
    371                     }
    372                     else
    373                     {
    374                         //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    375                         rtun.Append("<a href=\"");
    376                         rtun.Append(string.Format(formatUrl, i.ToString()));
    377                         rtun.Append("\">");
    378                         rtun.Append(i);
    379                         rtun.Append("</a>");
    380                     }
    381                 }
    382                 #endregion
    383 
    384                 #region 末页
    385                 if (page == maxPage)
    386                 {
    387                     rtun.Append("<b>");
    388                     rtun.Append("末页");
    389                     rtun.Append("</b>");
    390                 }
    391                 else
    392                 {
    393                     rtun.Append("<a href=\"");
    394                     rtun.Append(string.Format(formatUrl, page.ToString()));
    395                     rtun.Append("\">");
    396                     rtun.Append("末页");
    397                     rtun.Append("</a>");
    398                 }
    399                 #endregion
    400             }
    401             return rtun;
    402         }
    403         /// <summary>
    404         /// 第一页 中间是当前页码,左边右边各5个连接 末页
    405         /// </summary>
    406         /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    407         /// <param name="page">page从1开始</param>
    408         /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    409         /// <returns></returns>
    410         public static StringBuilder Normal5(string formatUrl, int page, int maxPage)
    411         {
    412             StringBuilder rtun = new StringBuilder();
    413             if (maxPage > 1)
    414             {
    415                 if (page > maxPage) { page = maxPage; }
    416                 if (page < 1) { page = 1; }
    417                 #region 第一页
    418                 if (page == 1)
    419                 {
    420                     rtun.Append("<b>");
    421                     rtun.Append("第一页");
    422                     rtun.Append("</b>");
    423                 }
    424                 else
    425                 {
    426                     rtun.Append("<a href=\"");
    427                     rtun.Append(string.Format(formatUrl, page.ToString()));
    428                     rtun.Append("\">");
    429                     rtun.Append("第一页");
    430                     rtun.Append("</a>");
    431                 }
    432                 #endregion
    433 
    434                 #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    435                 int seek = 5;
    436 
    437                 int start = page - seek;
    438                 if ((maxPage - start) < 11) { start = maxPage - 11; }
    439                 if (start < 1) { start = 1; }
    440 
    441                 int end = page + seek;
    442                 if (end < 11) { end = 11; }
    443                 if (end > maxPage) { end = maxPage; }
    444 
    445                 for (int i = start; i <= end; i++)
    446                 {
    447                     if (i == page)
    448                     {
    449                         //rtun.Append("<b>" + i + "</b>");
    450                         rtun.Append("<b>");
    451                         rtun.Append(i);
    452                         rtun.Append("</b>");
    453                     }
    454                     else
    455                     {
    456                         //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    457                         rtun.Append("<a href=\"");
    458                         rtun.Append(string.Format(formatUrl, i.ToString()));
    459                         rtun.Append("\">");
    460                         rtun.Append(i);
    461                         rtun.Append("</a>");
    462                     }
    463                 }
    464                 #endregion
    465 
    466                 #region 末页
    467                 if (page == maxPage)
    468                 {
    469                     rtun.Append("<b>");
    470                     rtun.Append("末页");
    471                     rtun.Append("</b>");
    472                 }
    473                 else
    474                 {
    475                     rtun.Append("<a href=\"");
    476                     rtun.Append(string.Format(formatUrl, page.ToString()));
    477                     rtun.Append("\">");
    478                     rtun.Append("末页");
    479                     rtun.Append("</a>");
    480                 }
    481                 #endregion
    482             }
    483             return rtun;
    484         }
    485         /// <summary>
    486         /// 第一页 中间是当前页码,左边右边各5个连接 末页
    487         /// </summary>
    488         /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    489         /// <param name="page">page从1开始</param>
    490         /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    491         /// <returns></returns>
    492         public static StringBuilder Normal5(string formatUrl, int page, int pageSize, int totalRow)
    493         {
    494             StringBuilder rtun = new StringBuilder();
    495             if (totalRow > pageSize)
    496             {
    497                 int maxPage = GetTotalPage(totalRow, pageSize);
    498 
    499                 if (page > maxPage) { page = maxPage; }
    500                 if (page < 1) { page = 1; }
    501                 #region 第一页
    502                 if (page == 1)
    503                 {
    504                     rtun.Append("<b>");
    505                     rtun.Append("第一页");
    506                     rtun.Append("</b>");
    507                 }
    508                 else
    509                 {
    510                     rtun.Append("<a href=\"");
    511                     rtun.Append(string.Format(formatUrl, page.ToString()));
    512                     rtun.Append("\">");
    513                     rtun.Append("第一页");
    514                     rtun.Append("</a>");
    515                 }
    516                 #endregion
    517 
    518                 #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    519                 int seek = 5;
    520 
    521                 int start = page - seek;
    522                 if ((maxPage - start) < 11) { start = maxPage - 11; }
    523                 if (start < 1) { start = 1; }
    524 
    525                 int end = page + seek;
    526                 if (end < 11) { end = 11; }
    527                 if (end > maxPage) { end = maxPage; }
    528 
    529                 for (int i = start; i <= end; i++)
    530                 {
    531                     if (i == page)
    532                     {
    533                         //rtun.Append("<b>" + i + "</b>");
    534                         rtun.Append("<b>");
    535                         rtun.Append(i);
    536                         rtun.Append("</b>");
    537                     }
    538                     else
    539                     {
    540                         //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    541                         rtun.Append("<a href=\"");
    542                         rtun.Append(string.Format(formatUrl, i.ToString()));
    543                         rtun.Append("\">");
    544                         rtun.Append(i);
    545                         rtun.Append("</a>");
    546                     }
    547                 }
    548                 #endregion
    549 
    550                 #region 末页
    551                 if (page == maxPage)
    552                 {
    553                     rtun.Append("<b>");
    554                     rtun.Append("末页");
    555                     rtun.Append("</b>");
    556                 }
    557                 else
    558                 {
    559                     rtun.Append("<a href=\"");
    560                     rtun.Append(string.Format(formatUrl, page.ToString()));
    561                     rtun.Append("\">");
    562                     rtun.Append("末页");
    563                     rtun.Append("</a>");
    564                 }
    565                 #endregion
    566             }
    567             return rtun;
    568         }
    569 
    570 
    571         /// <summary>
    572         /// 共xx条数据,x页 第一页 中间是当前页码,左边右边各4个连接 末页
    573         /// </summary>
    574         /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    575         /// <param name="page">page从1开始</param>
    576         /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    577         /// <returns></returns>
    578         public static StringBuilder Full4(string formatUrl, int page, int pageSize, int totalRow)
    579         {
    580             StringBuilder rtun = new StringBuilder();
    581             if (totalRow > pageSize)
    582             {
    583                 int maxPage = GetTotalPage(totalRow, pageSize);
    584 
    585 
    586                 if (page > maxPage) { page = maxPage; }
    587                 if (page < 1) { page = 1; }
    588 
    589                 rtun.Append("<strong>");
    590                 rtun.Append("");
    591                 rtun.Append(totalRow);
    592                 rtun.Append("条数据,");
    593                 rtun.Append(page);
    594                 rtun.Append("");
    595                 rtun.Append("</strong>");
    596 
    597                 #region 第一页
    598                 if (page == 1)
    599                 {
    600                     rtun.Append("<b>");
    601                     rtun.Append("第一页");
    602                     rtun.Append("</b>");
    603                 }
    604                 else
    605                 {
    606                     rtun.Append("<a href=\"");
    607                     rtun.Append(string.Format(formatUrl, page.ToString()));
    608                     rtun.Append("\">");
    609                     rtun.Append("第一页");
    610                     rtun.Append("</a>");
    611                 }
    612                 #endregion
    613 
    614                 #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    615                 int seek = 4;
    616 
    617                 int start = page - seek;
    618                 if ((maxPage - start) < 9) { start = maxPage - 9; }
    619                 if (start < 1) { start = 1; }
    620 
    621                 int end = page + seek;
    622                 if (end < 9) { end = 9; }
    623                 if (end > maxPage) { end = maxPage; }
    624 
    625                 for (int i = start; i <= end; i++)
    626                 {
    627                     if (i == page)
    628                     {
    629                         //rtun.Append("<b>" + i + "</b>");
    630                         rtun.Append("<b>");
    631                         rtun.Append(i);
    632                         rtun.Append("</b>");
    633                     }
    634                     else
    635                     {
    636                         //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    637                         rtun.Append("<a href=\"");
    638                         rtun.Append(string.Format(formatUrl, i.ToString()));
    639                         rtun.Append("\">");
    640                         rtun.Append(i);
    641                         rtun.Append("</a>");
    642                     }
    643                 }
    644                 #endregion
    645 
    646                 #region 末页
    647                 if (page == maxPage)
    648                 {
    649                     rtun.Append("<b>");
    650                     rtun.Append("末页");
    651                     rtun.Append("</b>");
    652                 }
    653                 else
    654                 {
    655                     rtun.Append("<a href=\"");
    656                     rtun.Append(string.Format(formatUrl, page.ToString()));
    657                     rtun.Append("\">");
    658                     rtun.Append("末页");
    659                     rtun.Append("</a>");
    660                 }
    661                 #endregion
    662             }
    663             return rtun;
    664         }
    665         /// <summary>
    666         /// 第一页 中间是当前页码,左边右边各4个连接 末页
    667         /// </summary>
    668         /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    669         /// <param name="page">page从1开始</param>
    670         /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    671         /// <returns></returns>
    672         public static StringBuilder Full5(string formatUrl, int page, int pageSize, int totalRow)
    673         {
    674             StringBuilder rtun = new StringBuilder();
    675             if (totalRow > pageSize)
    676             {
    677                 int maxPage = GetTotalPage(totalRow, pageSize);
    678 
    679 
    680                 if (page > maxPage) { page = maxPage; }
    681                 if (page < 1) { page = 1; }
    682 
    683                 rtun.Append("<strong>");
    684                 rtun.Append("");
    685                 rtun.Append(totalRow);
    686                 rtun.Append("条数据,");
    687                 rtun.Append(page);
    688                 rtun.Append("");
    689                 rtun.Append("</strong>");
    690 
    691                 #region 第一页
    692                 if (page == 1)
    693                 {
    694                     rtun.Append("<b>");
    695                     rtun.Append("第一页");
    696                     rtun.Append("</b>");
    697                 }
    698                 else
    699                 {
    700                     rtun.Append("<a href=\"");
    701                     rtun.Append(string.Format(formatUrl, page.ToString()));
    702                     rtun.Append("\">");
    703                     rtun.Append("第一页");
    704                     rtun.Append("</a>");
    705                 }
    706                 #endregion
    707 
    708                 #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    709                 int seek = 5;
    710 
    711                 int start = page - seek;
    712                 if ((maxPage - start) < 11) { start = maxPage - 11; }
    713                 if (start < 1) { start = 1; }
    714 
    715                 int end = page + seek;
    716                 if (end < 11) { end = 11; }
    717                 if (end > maxPage) { end = maxPage; }
    718 
    719                 for (int i = start; i <= end; i++)
    720                 {
    721                     if (i == page)
    722                     {
    723                         //rtun.Append("<b>" + i + "</b>");
    724                         rtun.Append("<b>");
    725                         rtun.Append(i);
    726                         rtun.Append("</b>");
    727                     }
    728                     else
    729                     {
    730                         //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    731                         rtun.Append("<a href=\"");
    732                         rtun.Append(string.Format(formatUrl, i.ToString()));
    733                         rtun.Append("\">");
    734                         rtun.Append(i);
    735                         rtun.Append("</a>");
    736                     }
    737                 }
    738                 #endregion
    739 
    740                 #region 末页
    741                 if (page == maxPage)
    742                 {
    743                     rtun.Append("<b>");
    744                     rtun.Append("末页");
    745                     rtun.Append("</b>");
    746                 }
    747                 else
    748                 {
    749                     rtun.Append("<a href=\"");
    750                     rtun.Append(string.Format(formatUrl, page.ToString()));
    751                     rtun.Append("\">");
    752                     rtun.Append("末页");
    753                     rtun.Append("</a>");
    754                 }
    755                 #endregion
    756             }
    757             return rtun;
    758         }
    759 
    760         #endregion
    761     }


    public class LinkHelper
    {

    /// <summary>
    /// 获取总页数
    /// </summary>
    /// <param name="totalCount"></param>
    /// <param name="pageSize"></param>
    /// <returns></returns>
    public static int GetTotalPage(int totalCount, int pageSize)
    {
    if (totalCount % pageSize == 0)
    {
    return totalCount / pageSize;
    }
    return totalCount / pageSize + 1;
    }
    /// <summary>
    /// 获取总页数
    /// </summary>
    /// <param name="totalCount"></param>
    /// <param name="pageSize"></param>
    /// <returns></returns>
    public static int GetPageCount(int totalCount, int pageSize)
    {
    return (totalCount + pageSize - 1) / pageSize;
    }

    #region 分页链接 Goosoz@163.com /2012



    /// <summary>
    /// 中间是当前页码,左边右边各4个连接
    /// </summary>
    /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    /// <param name="page">page从1开始</param>
    /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    /// <returns></returns>
    public static StringBuilder Simple4(string formatUrl, int page, int maxPage)
    {
    StringBuilder rtun = new StringBuilder();
    if (maxPage > 1)
    {
    if (page > maxPage) { page = maxPage; }
    if (page < 1) { page = 1; }

    #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    int seek = 4;

    int start = page - seek;
    if ((maxPage - start) < 9) { start = maxPage - 9; }
    if (start < 1) { start = 1; }

    int end = page + seek;
    if (end < 9) { end = 9; }
    if (end > maxPage) { end = maxPage; }

    for (int i = start; i <= end; i++)
    {
    if (i == page)
    {
    //rtun.Append("<b>" + i + "</b>");
    rtun.Append("<b>");
    rtun.Append(i);
    rtun.Append("</b>");
    }
    else
    {
    //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, i.ToString()));
    rtun.Append("\">");
    rtun.Append(i);
    rtun.Append("</a>");
    }
    }
    #endregion

    }
    return rtun;
    }
    /// <summary>
    /// 中间是当前页码,左边右边各4个连接
    /// </summary>
    /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    /// <param name="page">page从1开始</param>
    /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    /// <returns></returns>
    public static StringBuilder Simple4(string formatUrl, int page, int pageSize, int totalRow)
    {
    StringBuilder rtun = new StringBuilder();
    if (totalRow > pageSize)
    {
    int maxPage = GetTotalPage(totalRow, pageSize);

    if (page > maxPage) { page = maxPage; }
    if (page < 1) { page = 1; }

    #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    int seek = 4;

    int start = page - seek;
    if ((maxPage - start) < 9) { start = maxPage - 9; }
    if (start < 1) { start = 1; }

    int end = page + seek;
    if (end < 9) { end = 9; }
    if (end > maxPage) { end = maxPage; }

    for (int i = start; i <= end; i++)
    {
    if (i == page)
    {
    //rtun.Append("<b>" + i + "</b>");
    rtun.Append("<b>");
    rtun.Append(i);
    rtun.Append("</b>");
    }
    else
    {
    //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, i.ToString()));
    rtun.Append("\">");
    rtun.Append(i);
    rtun.Append("</a>");
    }
    }
    #endregion

    }
    return rtun;
    }
    /// <summary>
    /// 中间是当前页码,左边右边各5个连接
    /// </summary>
    /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    /// <param name="page">page从1开始</param>
    /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    /// <returns></returns>
    public static StringBuilder Simple5(string formatUrl, int page, int maxPage)
    {
    StringBuilder rtun = new StringBuilder();
    if (maxPage > 1)
    {
    if (page > maxPage) { page = maxPage; }
    if (page < 1) { page = 1; }

    #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    int seek = 5;

    int start = page - seek;
    if ((maxPage - start) < 11) { start = maxPage - 11; }
    if (start < 1) { start = 1; }

    int end = page + seek;
    if (end < 11) { end = 11; }
    if (end > maxPage) { end = maxPage; }

    for (int i = start; i <= end; i++)
    {
    if (i == page)
    {
    //rtun.Append("<b>" + i + "</b>");
    rtun.Append("<b>");
    rtun.Append(i);
    rtun.Append("</b>");
    }
    else
    {
    //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, i.ToString()));
    rtun.Append("\">");
    rtun.Append(i);
    rtun.Append("</a>");
    }
    }
    #endregion

    }
    return rtun;
    }
    /// <summary>
    /// 中间是当前页码,左边右边各5个连接
    /// </summary>
    /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    /// <param name="page">page从1开始</param>
    /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    /// <returns></returns>
    public static StringBuilder Simple5(string formatUrl, int page, int pageSize, int totalRow)
    {
    StringBuilder rtun = new StringBuilder();
    if (totalRow > pageSize)
    {
    int maxPage = GetTotalPage(totalRow, pageSize);

    if (page > maxPage) { page = maxPage; }
    if (page < 1) { page = 1; }

    #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    int seek = 5;

    int start = page - seek;
    if ((maxPage - start) < 11) { start = maxPage - 11; }
    if (start < 1) { start = 1; }

    int end = page + seek;
    if (end < 11) { end = 11; }
    if (end > maxPage) { end = maxPage; }

    for (int i = start; i <= end; i++)
    {
    if (i == page)
    {
    //rtun.Append("<b>" + i + "</b>");
    rtun.Append("<b>");
    rtun.Append(i);
    rtun.Append("</b>");
    }
    else
    {
    //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, i.ToString()));
    rtun.Append("\">");
    rtun.Append(i);
    rtun.Append("</a>");
    }
    }
    #endregion

    }
    return rtun;
    }
    /// <summary>
    /// 第一页 中间是当前页码,左边右边各4个连接 末页
    /// </summary>
    /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    /// <param name="page">page从1开始</param>
    /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    /// <returns></returns>
    public static StringBuilder Normal4(string formatUrl, int page, int maxPage)
    {
    StringBuilder rtun = new StringBuilder();
    if (maxPage > 1)
    {
    if (page > maxPage) { page = maxPage; }
    if (page < 1) { page = 1; }
    #region 第一页
    if (page == 1)
    {
    rtun.Append("<b>");
    rtun.Append("第一页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("第一页");
    rtun.Append("</a>");
    }
    #endregion

    #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    int seek = 4;

    int start = page - seek;
    if ((maxPage - start) < 9) { start = maxPage - 9; }
    if (start < 1) { start = 1; }

    int end = page + seek;
    if (end < 9) { end = 9; }
    if (end > maxPage) { end = maxPage; }

    for (int i = start; i <= end; i++)
    {
    if (i == page)
    {
    //rtun.Append("<b>" + i + "</b>");
    rtun.Append("<b>");
    rtun.Append(i);
    rtun.Append("</b>");
    }
    else
    {
    //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, i.ToString()));
    rtun.Append("\">");
    rtun.Append(i);
    rtun.Append("</a>");
    }
    }
    #endregion

    #region 末页
    if (page == maxPage)
    {
    rtun.Append("<b>");
    rtun.Append("末页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("末页");
    rtun.Append("</a>");
    }
    #endregion
    }
    return rtun;
    }
    /// <summary>
    /// 第一页 中间是当前页码,左边右边各4个连接 末页
    /// </summary>
    /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    /// <param name="page">page从1开始</param>
    /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    /// <returns></returns>
    public static StringBuilder Normal4(string formatUrl, int page, int pageSize, int totalRow)
    {
    StringBuilder rtun = new StringBuilder();
    if (totalRow > pageSize)
    {
    int maxPage = GetTotalPage(totalRow, pageSize);

    if (page > maxPage) { page = maxPage; }
    if (page < 1) { page = 1; }
    #region 第一页
    if (page == 1)
    {
    rtun.Append("<b>");
    rtun.Append("第一页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("第一页");
    rtun.Append("</a>");
    }
    #endregion

    #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    int seek = 4;

    int start = page - seek;
    if ((maxPage - start) < 9) { start = maxPage - 9; }
    if (start < 1) { start = 1; }

    int end = page + seek;
    if (end < 9) { end = 9; }
    if (end > maxPage) { end = maxPage; }

    for (int i = start; i <= end; i++)
    {
    if (i == page)
    {
    //rtun.Append("<b>" + i + "</b>");
    rtun.Append("<b>");
    rtun.Append(i);
    rtun.Append("</b>");
    }
    else
    {
    //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, i.ToString()));
    rtun.Append("\">");
    rtun.Append(i);
    rtun.Append("</a>");
    }
    }
    #endregion

    #region 末页
    if (page == maxPage)
    {
    rtun.Append("<b>");
    rtun.Append("末页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("末页");
    rtun.Append("</a>");
    }
    #endregion
    }
    return rtun;
    }
    /// <summary>
    /// 第一页 中间是当前页码,左边右边各5个连接 末页
    /// </summary>
    /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    /// <param name="page">page从1开始</param>
    /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    /// <returns></returns>
    public static StringBuilder Normal5(string formatUrl, int page, int maxPage)
    {
    StringBuilder rtun = new StringBuilder();
    if (maxPage > 1)
    {
    if (page > maxPage) { page = maxPage; }
    if (page < 1) { page = 1; }
    #region 第一页
    if (page == 1)
    {
    rtun.Append("<b>");
    rtun.Append("第一页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("第一页");
    rtun.Append("</a>");
    }
    #endregion

    #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    int seek = 5;

    int start = page - seek;
    if ((maxPage - start) < 11) { start = maxPage - 11; }
    if (start < 1) { start = 1; }

    int end = page + seek;
    if (end < 11) { end = 11; }
    if (end > maxPage) { end = maxPage; }

    for (int i = start; i <= end; i++)
    {
    if (i == page)
    {
    //rtun.Append("<b>" + i + "</b>");
    rtun.Append("<b>");
    rtun.Append(i);
    rtun.Append("</b>");
    }
    else
    {
    //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, i.ToString()));
    rtun.Append("\">");
    rtun.Append(i);
    rtun.Append("</a>");
    }
    }
    #endregion

    #region 末页
    if (page == maxPage)
    {
    rtun.Append("<b>");
    rtun.Append("末页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("末页");
    rtun.Append("</a>");
    }
    #endregion
    }
    return rtun;
    }
    /// <summary>
    /// 第一页 中间是当前页码,左边右边各5个连接 末页
    /// </summary>
    /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    /// <param name="page">page从1开始</param>
    /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    /// <returns></returns>
    public static StringBuilder Normal5(string formatUrl, int page, int pageSize, int totalRow)
    {
    StringBuilder rtun = new StringBuilder();
    if (totalRow > pageSize)
    {
    int maxPage = GetTotalPage(totalRow, pageSize);

    if (page > maxPage) { page = maxPage; }
    if (page < 1) { page = 1; }
    #region 第一页
    if (page == 1)
    {
    rtun.Append("<b>");
    rtun.Append("第一页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("第一页");
    rtun.Append("</a>");
    }
    #endregion

    #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    int seek = 5;

    int start = page - seek;
    if ((maxPage - start) < 11) { start = maxPage - 11; }
    if (start < 1) { start = 1; }

    int end = page + seek;
    if (end < 11) { end = 11; }
    if (end > maxPage) { end = maxPage; }

    for (int i = start; i <= end; i++)
    {
    if (i == page)
    {
    //rtun.Append("<b>" + i + "</b>");
    rtun.Append("<b>");
    rtun.Append(i);
    rtun.Append("</b>");
    }
    else
    {
    //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, i.ToString()));
    rtun.Append("\">");
    rtun.Append(i);
    rtun.Append("</a>");
    }
    }
    #endregion

    #region 末页
    if (page == maxPage)
    {
    rtun.Append("<b>");
    rtun.Append("末页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("末页");
    rtun.Append("</a>");
    }
    #endregion
    }
    return rtun;
    }


    /// <summary>
    /// 共xx条数据,x页 第一页 中间是当前页码,左边右边各4个连接 末页
    /// </summary>
    /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    /// <param name="page">page从1开始</param>
    /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    /// <returns></returns>
    public static StringBuilder Full4(string formatUrl, int page, int pageSize, int totalRow)
    {
    StringBuilder rtun = new StringBuilder();
    if (totalRow > pageSize)
    {
    int maxPage = GetTotalPage(totalRow, pageSize);


    if (page > maxPage) { page = maxPage; }
    if (page < 1) { page = 1; }

    rtun.Append("<strong>");
    rtun.Append("共");
    rtun.Append(totalRow);
    rtun.Append("条数据,");
    rtun.Append(page);
    rtun.Append("页");
    rtun.Append("</strong>");

    #region 第一页
    if (page == 1)
    {
    rtun.Append("<b>");
    rtun.Append("第一页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("第一页");
    rtun.Append("</a>");
    }
    #endregion

    #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    int seek = 4;

    int start = page - seek;
    if ((maxPage - start) < 9) { start = maxPage - 9; }
    if (start < 1) { start = 1; }

    int end = page + seek;
    if (end < 9) { end = 9; }
    if (end > maxPage) { end = maxPage; }

    for (int i = start; i <= end; i++)
    {
    if (i == page)
    {
    //rtun.Append("<b>" + i + "</b>");
    rtun.Append("<b>");
    rtun.Append(i);
    rtun.Append("</b>");
    }
    else
    {
    //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, i.ToString()));
    rtun.Append("\">");
    rtun.Append(i);
    rtun.Append("</a>");
    }
    }
    #endregion

    #region 末页
    if (page == maxPage)
    {
    rtun.Append("<b>");
    rtun.Append("末页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("末页");
    rtun.Append("</a>");
    }
    #endregion
    }
    return rtun;
    }
    /// <summary>
    /// 第一页 中间是当前页码,左边右边各4个连接 末页
    /// </summary>
    /// <param name="formatUrl">link.aspx?page={0}&type=3</param>
    /// <param name="page">page从1开始</param>
    /// <param name="maxPage">小于2不显示分页,并返还空字符串</param>
    /// <returns></returns>
    public static StringBuilder Full5(string formatUrl, int page, int pageSize, int totalRow)
    {
    StringBuilder rtun = new StringBuilder();
    if (totalRow > pageSize)
    {
    int maxPage = GetTotalPage(totalRow, pageSize);


    if (page > maxPage) { page = maxPage; }
    if (page < 1) { page = 1; }

    rtun.Append("<strong>");
    rtun.Append("共");
    rtun.Append(totalRow);
    rtun.Append("条数据,");
    rtun.Append(page);
    rtun.Append("页");
    rtun.Append("</strong>");

    #region 第一页
    if (page == 1)
    {
    rtun.Append("<b>");
    rtun.Append("第一页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("第一页");
    rtun.Append("</a>");
    }
    #endregion

    #region 中间 3,4,5,6,7,[8],9,10,11,12,13
    int seek = 5;

    int start = page - seek;
    if ((maxPage - start) < 11) { start = maxPage - 11; }
    if (start < 1) { start = 1; }

    int end = page + seek;
    if (end < 11) { end = 11; }
    if (end > maxPage) { end = maxPage; }

    for (int i = start; i <= end; i++)
    {
    if (i == page)
    {
    //rtun.Append("<b>" + i + "</b>");
    rtun.Append("<b>");
    rtun.Append(i);
    rtun.Append("</b>");
    }
    else
    {
    //rtun.Append("<a href=\"" + string.Format(formatUrl, i.ToString()) + "\">" + i + "</a>");
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, i.ToString()));
    rtun.Append("\">");
    rtun.Append(i);
    rtun.Append("</a>");
    }
    }
    #endregion

    #region 末页
    if (page == maxPage)
    {
    rtun.Append("<b>");
    rtun.Append("末页");
    rtun.Append("</b>");
    }
    else
    {
    rtun.Append("<a href=\"");
    rtun.Append(string.Format(formatUrl, page.ToString()));
    rtun.Append("\">");
    rtun.Append("末页");
    rtun.Append("</a>");
    }
    #endregion
    }
    return rtun;
    }

    #endregion
    }

  • 相关阅读:
    Appium-Java滑动操作
    使用uiautomatorviewer获取元素
    在eclipse中,Python项目遇到:…… from appium import webdriver ImportError: No module named appium
    Python遇到SyntaxError: Non-ASCII character 'xe5' in file D:eclipseworkspace est est_urllib2.py on line2
    在eclipse添加第一次添加Python项目时,提示: Project interpreter not specified
    安装pip环境以及pip常用命令使用
    虚拟机——安装虚拟机时,提示intel VT-x处于禁用状态
    【luogu 3370】【模板】字符串哈希
    【luogu 3378】【模板】堆
    【luogu 3383】【模板】线性筛素数
  • 原文地址:https://www.cnblogs.com/CodeBase/p/2796097.html
Copyright © 2020-2023  润新知