Files
7-Dongan-Interface/DatabaseClient/DBClient.cs
2026-05-29 13:57:08 +08:00

63 lines
1.9 KiB
C#
Raw 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 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;
}
}
}