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 { /// /// 根据连接字符串连接 /// /// 连接字符串 public abstract void Connect(string connString); /// /// 执行sql查询语句,返回DataTable /// /// 查询sql字符串 /// public abstract DataTable ExecQuery(string sql); /// /// 执行sql非查询语句,返回执行结果 /// /// 非查询sql字符串 /// public abstract int ExecNonQuery(string sql); /// /// 分页,将原始表分成子表。约束为当前页数和每页记录数 /// /// 泛型类型 /// 原始表 /// 每页记录数 /// 当前页数 /// public static List SplitePage(List originList,int pageSize,int currentPage) { List resList = new List(); 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; } } }