Mini.Crm/Mini.Web/WebHelper/Pagination.cs

115 lines
5.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Mini.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mini.Web.WebHelper
{
public class Pagination
{
/// <summary>
/// 获取分页html(默认分页 10,30,50,100)
/// </summary>
/// <param name="page">分页的信息</param>
/// <param name="tableId">分页对应的表格ID</param>
/// <returns></returns>
public static string GetPage(Pager page, string tableId)
{
string paginations = "10,30,50,100";
return GetPage(page, tableId, paginations);
}
/// <summary>
/// 获取分页html
/// </summary>
/// <param name="page">分页的信息</param>
/// <param name="tableId">分页对应的表格ID</param>
/// <param name="paginations">分页的参数15,20,30</param>
/// <returns></returns>
public static string GetPage(Pager page, string tableId, string paginations)
{
string pageMessage = JsonHelper.ObjDivertToJson(page);
StringBuilder tool = new StringBuilder();
string[] pagination = paginations.Split(',');
tool.AppendLine(string.Format("<div pagination='{1}' class='datagrid-pager pagination' tableId='{0}'> <table cellspacing='0' cellpadding='0' border='0'> <tbody> <tr> ", tableId, pageMessage));
tool.AppendLine(" <td><select class='pagination-page-list'>");
foreach (string str in pagination)
{
tool.AppendLine(string.Format("<option>{0}</option>", str));
}
tool.AppendLine(" </select> </td>");
tool.AppendLine("<td><div class='pagination-btn-separator'></div></td>");
if (page.page <= 1)
{
tool.AppendLine(GetPageButton(false, "pagination-first", "page_first"));
tool.AppendLine(GetPageButton(false, "pagination-prev", "page_prev"));
}
else
{
tool.AppendLine(GetPageButton(true, "pagination-first", "page_first"));
tool.AppendLine(GetPageButton(true, "pagination-prev", "page_prev"));
}
tool.AppendLine("<td><div class='pagination-btn-separator'></div></td>");
tool.AppendLine(" <td><span style='padding-left:6px;'>Page</span></td>");
tool.AppendLine(string.Format("<td><input type='text' size='2' value='{0}' class='pagination-num'></td>", page.page));
tool.AppendLine(string.Format("<td><span nid='ofPage' style='padding-right:6px;'>of {0}</span></td>", page.totalPages));
tool.AppendLine("<td><div class='pagination-btn-separator'></div></td>");
if (page.page >= page.totalPages)
{
tool.AppendLine(GetPageButton(false, "pagination-next", "page_next"));
tool.AppendLine(GetPageButton(false, "pagination-last", "page_last"));
}
else
{
tool.AppendLine(GetPageButton(true, "pagination-next", "page_next"));
tool.AppendLine(GetPageButton(true, "pagination-last", "page_last"));
}
tool.AppendLine("<td><div class='pagination-btn-separator'></div></td>");
tool.AppendLine(GetPageButton(true, "pagination-load", "page_load"));
tool.AppendLine(string.Format("</tr></tbody></table> <div class='pagination-info'>从 {0} 到 {1} 共 {2} 条数据</div><div style='clear:both;'></div> </div> ", ((page.page - 1) * page.rows + 1), (page.page * page.rows > page.totalRows ? page.totalRows : page.page * page.rows), page.totalRows));
return tool.ToString();
}
public static string GetPage(Pager page)
{
StringBuilder tool = new StringBuilder();
tool.AppendLine(string.Format("第 {0}/{1} 页 |", page.page, page.totalPages));
if (page.page <= 1)
{
tool.AppendLine("第一页 | 上一页 |");
}
else
{
tool.AppendLine(string.Format("<a href='javascript:ShowPage(1);'>第一页</a> | <a href='javascript:ShowPage({0});'>上一页</a> |", page.page - 1));
}
if (page.page >= page.totalPages)
{
tool.AppendLine("下一页 | 最后一页 | ");
}
else
{
tool.AppendLine(string.Format("<a href='javascript:ShowPage({0});'>下一页</a> | <a href='javascript:ShowPage({1});'>最后一页</a>", page.page + 1, page.totalPages));
}
tool.AppendLine("到第 <input type='text' name='num' style='width:40px; height:18px' value='" + page.page + "' onChange='toPage(this)' maxlength='6'> 页");
return tool.ToString();
}
private static string GetPageButton(bool disabled, string icon, string id)
{
StringBuilder button = new StringBuilder();
button.AppendFormat("<td><a id='{1}' class='l-btn l-btn-plain {0} ' href='javascript:void(0)'>", (disabled ? "" : "l-btn-disabled"), id);
button.AppendLine("<span class='l-btn-left'>");
button.AppendLine("<span class='l-btn-text'>");
button.AppendLine(string.Format("<span class='l-btn-empty {0}'>&nbsp;</span>", icon));
button.AppendLine(@"</span></span></a></td>");
return button.ToString();
}
}
}