将Feature/XP.Common和Feature/XP.Hardware分支合并至Develop/XP.forHardwareAndCommon,完善XPapp注册和相关硬件类库通用类库功能。
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using XP.Common.Database.Models;
|
||||
|
||||
namespace XP.Common.Database.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// 分页计算辅助工具
|
||||
/// </summary>
|
||||
public static class PaginationHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 计算分页偏移量(SQLite OFFSET)
|
||||
/// </summary>
|
||||
public static int CalculateOffset(PaginationRequest pagination)
|
||||
{
|
||||
if (pagination.PageIndex < 1) pagination.PageIndex = 1;
|
||||
if (pagination.PageSize < 1) pagination.PageSize = 20;
|
||||
return (pagination.PageIndex - 1) * pagination.PageSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证并修正分页参数
|
||||
/// </summary>
|
||||
public static PaginationRequest ValidateAndFix(PaginationRequest pagination)
|
||||
{
|
||||
var fixedPagination = new PaginationRequest
|
||||
{
|
||||
PageIndex = pagination.PageIndex < 1 ? 1 : pagination.PageIndex,
|
||||
PageSize = pagination.PageSize < 1 ? 20 : (pagination.PageSize > 1000 ? 1000 : pagination.PageSize),
|
||||
OrderBy = pagination.OrderBy ?? string.Empty
|
||||
};
|
||||
return fixedPagination;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user