Using System; Using System. Collections. Generic; Using System. Linq; Using System. Text; Using System. Text. RegularExpressions; Namespace SyntacticSugar { /// <Summary> /// ** Description: Paging class /// ** Founding Date: /// ** Modification time :- /// ** Prepared by sunkaixuan Public class PageString { /// <Summary> /// Whether it is in English (default: false) /// </Summary> Public bool SetIsEnglish {get; set ;} /// <Summary> /// Whether to display paging text (default: true) /// </Summary> Public bool SetIsShowText {get; set ;} /// <Summary> /// Style (default: "pagination ") /// </Summary> Public string SetClassName {get; set ;} /// <Summary> /// Paging parameter name (default: "pageIndex ") /// </Summary> Public string SetPageIndexName {get; set ;} /// <Summary> /// Whether asynchronous synchronization href = ''asynchronous onclick = ajaxPage () (default: false) /// </Summary> Public bool SetIsAjax {get; set ;} /// <Summary> /// Custom text // String. Format ("{0} {1} {2}", "total records", "Current page number", "total page number ") // Default value: span class = \ "pagetext \" strong, total/strong: {0} strong, current/strong: {1}/{2}/span /// </Summary> Public string SetTextFormat {get; set ;} Public PageString () { SetIsEnglish = false; SetIsShowText = true; SetTextFormat = "<span class = \" pagetext \ "> <strong> total </strong>: {0} <strong> current </strong>: {1}/{2} </span> "; SetClassName = "pagination "; SetPageIndexName = "pageIndex "; SetIsAjax = false; } /* Free Style . Pagination. click {cursor: pointer} . Pagination a {text-decoration: none; border: 1px solid # AAE; color: # 15B; font-size: 13px; border-radius: 2px ;} . Pagination span {color: #666; font-size: 13px; display: inline-block; border: 1px solid # ccc; padding: 0.2em 0.6em ;} . Pagination span. pagetext {border: none} . Pagination a: hover {background: # 26B; color: # fff ;} . Pagination a {display: inline-block; padding: 0.2em 0.6em ;} . Pagination. page_current {background: # 26B; color: # fff; border: 1px solid # AAE; margin-right: 5px ;} . Pagination {margin-top: 20px ;} . Pagination. current. prev,. pagination. current. next {color: #999; border-color: #999; background: # fff ;} **/ /// <Summary> /// Paging algorithm <1> 20 pages home page Previous Page 1 2 3 4 5 6 7 8 9 10 next page last page /// </Summary> /// <Param name = "total"> total number of records </param> /// <Param name = "pageSize"> Number of records per page </param> /// <Param name = "pageIndex"> current page </param> /// <Param name = "query_string"> Url parameter </param> /// <Returns> </returns> Public string ToString (int total, int pageSize, int pageIndex, string query_string) { Int allpage = 0; Int next = 0; Int pre = 0; Int startcount = 0; Int endcount = 0; StringBuilder pagestr = new StringBuilder (); PageIndex = 0? 1: pageIndex; Pagestr. AppendFormat ("<div class = \" {0} \ ">", SetClassName ); If (pageIndex <1) {pageIndex = 1 ;} // Calculate the total number of pages If (pageSize! = 0) { Allpage = (total/pageSize ); Allpage = (total % pageSize )! = 0? Allpage + 1: allpage ); Allpage = (allpage = 0? 1: allpage ); } Next = pageIndex + 1; Pre = pageIndex-1; Startcount = (pageIndex + 5)> allpage? Allpage-9: pageIndex-4; // start Number of the intermediate page // End number of the intermediate page Endcount = pageIndex <5? 10: pageIndex + 5; If (startcount <1) {startcount = 1;} // to avoid negative output, if it is smaller than 1, it starts from number 1. If (allpage <endcount) {endcount = allpage;} // the possibility of page number + 5 will generate the final output sequence number greater than the total page number, then it should be controlled within the number of pages Bool isFirst = pageIndex = 1; Bool isLast = pageIndex = allpage; If (SetIsShowText) Pagestr. AppendFormat (SetTextFormat, total, pageIndex, allpage ); If (isFirst) { Pagestr. Append ("<span> homepage </span> <span> previous page </span> "); } Else { Pagestr. appendFormat ("<a href = \" {0} pageIndex = 1 \ "> homepage </a> <a href = \" {0} pageIndex = {1} \ "> previous Page </a> ", query_string, pre ); } // Intermediate page processing, which increases the time complexity and reduces the space complexity For (int I = startcount; I <= endcount; I ++) { Bool isCurent = pageIndex = I; If (isCurent) { Pagestr. Append ("<a class = \" page_current \ ">" + I + "</a> "); } Else { Pagestr. Append ("<a href = \" "+ query_string +" pageIndex = "+ I +" \ ">" + I + "</a> "); } } If (isLast) { Pagestr. Append ("<span> next page </span> <span> last page </span> "); } Else { Pagestr. append ("<a href = \" "+ query_string +" pageIndex = "+ next +" \ "> next page </a> <a href = \" "+ query_string +" pageIndex = "+ allpage +" \ "> last page </a> "); } Pagestr. AppendFormat ("</div> "); Return ConversionData (pagestr. ToString ()); } Private string ConversionData (string page) { If (SetIsEnglish) { Page = page. replace ("Previous Page", "Previous "). replace ("Next", "Next "). replace ("total", "total "). replace ("Current", "Current "). replace ("entry", "records "). replace ("Homepage", "First "). replace ("Last page", "Last "); } If (SetIsAjax) { Var matches = Regex. Matches (page, @ "href \ = "".*? ", RegexOptions. Singleline ); If (matches! = Null & matches. Count> 0) { Foreach (Match m in matches) { Page = page. replace (m. value, string. format ("class = \" click \ "onclick = \" ajaxPage ('{0}') \ "", Regex. match (m. value, string. format (@ "{0 }\= (\ d +)", SetPageIndexName )). groups [1]. value )); } } } Return page; } } } |