chore: initial commit
This commit is contained in:
62
Interface_WebAPI/DatabaseClient/DBClient.cs
Normal file
62
Interface_WebAPI/DatabaseClient/DBClient.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DatabaseClient
|
||||
{
|
||||
public abstract class DBClient
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据连接字符串连接
|
||||
/// </summary>
|
||||
/// <param name="connString">连接字符串</param>
|
||||
public abstract void Connect(string connString);
|
||||
|
||||
/// <summary>
|
||||
/// 执行sql查询语句,返回DataTable
|
||||
/// </summary>
|
||||
/// <param name="sql">查询sql字符串</param>
|
||||
/// <returns></returns>
|
||||
public abstract DataTable ExecQuery(string sql);
|
||||
|
||||
/// <summary>
|
||||
/// 执行sql非查询语句,返回执行结果
|
||||
/// </summary>
|
||||
/// <param name="sql">非查询sql字符串</param>
|
||||
/// <returns></returns>
|
||||
public abstract int ExecNonQuery(string sql);
|
||||
|
||||
/// <summary>
|
||||
/// 分页,将原始表分成子表。约束为当前页数和每页记录数
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型类型</typeparam>
|
||||
/// <param name="originList">原始表</param>
|
||||
/// <param name="pageSize">每页记录数</param>
|
||||
/// <param name="currentPage">当前页数</param>
|
||||
/// <returns></returns>
|
||||
public static List<T> SplitePage<T>(List<T> originList,int pageSize,int currentPage)
|
||||
{
|
||||
List<T> resList = new List<T>();
|
||||
|
||||
var numAll = originList.Count;
|
||||
var numPage = numAll / pageSize + 1;
|
||||
|
||||
var start = (currentPage - 1) * pageSize;
|
||||
var end = start + pageSize;
|
||||
|
||||
for (int i = 0; i < originList.Count; i++)
|
||||
{
|
||||
var origin = originList[i];
|
||||
if (i >= start && i < end)
|
||||
{
|
||||
resList.Add(origin);
|
||||
}
|
||||
}
|
||||
|
||||
return resList;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user