/// <summary> /// 设置分页页码 /// </summary> /// <param name="pageNum">当前页码</param> /// <param name="pageCount">总页数</param> /// <param name="sideNum">每页显示条数</param> /// <param name="startNum">开始页码</param> /// <param name="endNum">结束页码</param> public static void calcPage(int pageNum, int pageCount, int sideNum, ref int startNum, ref int endNum) { if (pageCount <= sideNum) { endNum = pageCount; } else { if ((sideNum + pageNum) >= pageCount) { endNum = pageCount; } else { endNum = sideNum + pageNum; if ((sideNum + pageNum) <= (2 * sideNum + 1)) { if ((2 * sideNum + 1) >= pageCount) { endNum = pageCount; } else { endNum = 2 * sideNum + 1; } } else { endNum = sideNum + pageNum; } } } if (pageNum <= sideNum) { startNum = 1; } else { if ((pageNum + sideNum) >= pageCount) { if ((2 * sideNum + 1) >= pageCount) { if ((pageCount - 2 * sideNum) >= 1) { startNum = pageCount - 2 * sideNum; } else { startNum = 1; } } else { startNum = pageCount - 2 * sideNum; } } else { if ((pageNum - sideNum) >= 1) { startNum = pageNum - sideNum; } else { startNum = 1; } } } }
时间: 2024-10-06 09:42:11