using NFine.Code; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Text; using System.Threading.Tasks; namespace NFine.Repository { public class Repository : IRepository where T : new() { #region 事务 /// /// 事务开始 /// /// public DbTransaction BeginTrans() { return DataFactory.Database().BeginTrans(); } /// /// 提交事务 /// public void Commit() { DataFactory.Database().Commit(); } /// /// 回滚事务 /// public void Rollback() { DataFactory.Database().Rollback(); } /// /// 关闭数据库连接 /// public void Close() { DataFactory.Database().Close(); } #endregion #region SqlBulkCopy大批量数据插入 /// /// 大批量数据插入 /// /// 资料表 /// public bool BulkInsert(DataTable datatable) { return DataFactory.Database().BulkInsert(datatable); } #endregion #region 执行SQL语句 /// /// 执行SQL语句 /// /// Sql语句 /// public int ExecuteBySql(StringBuilder strSql) { return DataFactory.Database().ExecuteBySql(strSql); } /// /// 执行SQL语句 /// /// Sql语句 /// 事务对象 /// public int ExecuteBySql(StringBuilder strSql, DbTransaction isOpenTrans) { return DataFactory.Database().ExecuteBySql(strSql, isOpenTrans); } /// /// 执行SQL语句 /// /// Sql语句 /// sql语句对应参数 /// public int ExecuteBySql(StringBuilder strSql, DbParameter[] parameters) { return DataFactory.Database().ExecuteBySql(strSql, parameters); } /// /// 执行SQL语句 /// /// Sql语句 /// sql语句对应参数 /// 事务对象 /// public int ExecuteBySql(StringBuilder strSql, DbParameter[] parameters, DbTransaction isOpenTrans) { return DataFactory.Database().ExecuteBySql(strSql, parameters, isOpenTrans); } #endregion #region 执行存储过程 /// /// 执行存储过程 /// /// 存储过程 /// public int ExecuteByProc(string procName) { return DataFactory.Database().ExecuteByProc(procName); } /// /// 执行存储过程 /// /// 存储过程 /// 事务对象 /// public int ExecuteByProc(string procName, DbTransaction isOpenTrans) { return DataFactory.Database().ExecuteByProc(procName, isOpenTrans); } /// /// 执行存储过程 /// /// 存储过程 /// sql语句对应参数 /// public int ExecuteByProc(string procName, DbParameter[] parameters) { return DataFactory.Database().ExecuteByProc(procName, parameters); } /// /// 执行存储过程 /// /// 存储过程 /// sql语句对应参数 /// 事务对象 /// public int ExecuteByProc(string procName, DbParameter[] parameters, DbTransaction isOpenTrans) { return DataFactory.Database().ExecuteByProc(procName, parameters, isOpenTrans); } #endregion #region 插入数据 /// /// 插入数据 /// /// 实体类对象 /// public int Insert(T entity) { return DataFactory.Database().Insert(entity); } /// /// 插入数据 /// /// 实体类对象 /// 事务对象 /// public int Insert(T entity, DbTransaction isOpenTrans) { return DataFactory.Database().Insert(entity, isOpenTrans); } /// /// 批量插入数据 /// /// 实体类对象 /// public int Insert(List entity) { return DataFactory.Database().Insert(entity); } /// /// 批量插入数据 /// /// 实体类对象 /// 事务对象 /// public int Insert(List entity, DbTransaction isOpenTrans) { return DataFactory.Database().Insert(entity, isOpenTrans); } #endregion #region 修改数据 /// /// 修改数据 /// /// 实体对象 /// public int Update(T entity) { return DataFactory.Database().Update(entity); } /// /// 修改数据 /// /// 实体对象 /// 事务对象 /// public int Update(T entity, DbTransaction isOpenTrans) { return DataFactory.Database().Update(entity, isOpenTrans); } /// /// 修改数据 /// /// 实体属性名称 /// 字段值 /// public int Update(string propertyName, string propertyValue) { return DataFactory.Database().Update(propertyName, propertyValue); } /// /// 修改数据 /// /// 实体属性名称 /// 字段值 /// 事务对象 /// public int Update(string propertyName, string propertyValue, DbTransaction isOpenTrans) { return DataFactory.Database().Update(propertyName, propertyValue, isOpenTrans); } /// /// 批量修改数据 /// /// 实体对象 /// public int Update(List entity) { return DataFactory.Database().Update(entity); } /// /// 批量修改数据 /// /// 实体对象 /// 事务对象 /// public int Update(List entity, DbTransaction isOpenTrans) { return DataFactory.Database().Update(entity, isOpenTrans); } #endregion #region 删除数据 /// /// 删除数据 /// /// 实体类 /// public int Delete(T entity) { return DataFactory.Database().Delete(entity); } /// /// 删除数据 /// /// 实体类 /// 事务对象 /// public int Delete(T entity, DbTransaction isOpenTrans) { return DataFactory.Database().Delete(entity, isOpenTrans); } /// /// 删除数据 /// /// 主键值 /// public int Delete(object propertyValue) { return DataFactory.Database().Delete(propertyValue); } /// /// 删除数据 /// /// 主键值 /// 事务对象 /// public int Delete(object propertyValue, DbTransaction isOpenTrans) { return DataFactory.Database().Delete(propertyValue, isOpenTrans); } /// /// 删除数据 /// /// 实体属性名称 /// 字段值 /// public int Delete(string propertyName, string propertyValue) { return DataFactory.Database().Delete(propertyName, propertyValue); } /// /// 删除数据 /// /// 实体属性名称 /// 字段值 /// 事务对象 /// public int Delete(string propertyName, string propertyValue, DbTransaction isOpenTrans) { return DataFactory.Database().Delete(propertyName, propertyValue, isOpenTrans); } /// /// 删除数据 /// /// 表名 /// 键值生成SQL条件 /// public int Delete(string tableName, Hashtable ht) { return DataFactory.Database().Delete(tableName, ht); } /// /// 删除数据 /// /// 表名 /// 键值生成SQL条件 /// 事务对象 /// public int Delete(string tableName, Hashtable ht, DbTransaction isOpenTrans) { return DataFactory.Database().Delete(tableName, ht, isOpenTrans); } /// /// 批量删除数据 /// /// 主键值:数组1,2,3,4,5,6..... /// public int Delete(object[] propertyValue) { return DataFactory.Database().Delete(propertyValue); } /// /// 批量删除数据 /// /// 主键值:数组1,2,3,4,5,6..... /// 事务对象 /// public int Delete(object[] propertyValue, DbTransaction isOpenTrans) { return DataFactory.Database().Delete(propertyValue, isOpenTrans); } /// /// 批量删除数据 /// /// 实体属性名称 /// 字段值:数组1,2,3,4,5,6..... /// public int Delete(string propertyName, object[] propertyValue) { return DataFactory.Database().Delete(propertyName, propertyValue); } /// /// 批量删除数据 /// /// 实体属性名称 /// 字段值:数组1,2,3,4,5,6..... /// 事务对象 /// public int Delete(string propertyName, object[] propertyValue, DbTransaction isOpenTrans) { return DataFactory.Database().Delete(propertyName, propertyValue, isOpenTrans); } #endregion #region 查询数据列表、返回List /// /// 查询数据列表、返回List /// /// 显示条数 /// public List FindListTop(int Top) { return DataFactory.Database().FindListTop(Top); } /// /// 查询数据列表、返回List /// /// 显示条数 /// 实体属性名称 /// 字段值 /// public List FindListTop(int Top, string propertyName, string propertyValue) { return DataFactory.Database().FindListTop(Top, propertyName, propertyValue); } /// /// 查询数据列表、返回List /// /// 显示条数 /// 条件 /// public List FindListTop(int Top, string WhereSql) { return DataFactory.Database().FindListTop(Top, WhereSql); } /// /// 查询数据列表、返回List /// /// 显示条数 /// 条件 /// sql语句对应参数 /// public List FindListTop(int Top, string WhereSql, DbParameter[] parameters) { return DataFactory.Database().FindListTop(Top, WhereSql, parameters); } /// /// 查询数据列表、返回List /// /// public List FindList() { return DataFactory.Database().FindList(); } /// /// 查询数据列表、返回List /// /// 实体属性名称 /// 字段值 /// public List FindList(string propertyName, string propertyValue) { return DataFactory.Database().FindList(propertyName, propertyValue); } /// /// 查询数据列表、返回List /// /// 条件 /// public List FindList(string WhereSql) { return DataFactory.Database().FindList(WhereSql); } /// /// 查询数据列表、返回List /// /// 条件 /// sql语句对应参数 /// public List FindList(string WhereSql, DbParameter[] parameters) { return DataFactory.Database().FindList(WhereSql, parameters); } /// /// 查询数据列表、返回List /// /// Sql语句 /// public List FindListBySql(string strSql) { return DataFactory.Database().FindListBySql(strSql); } /// /// 查询数据列表、返回List /// /// Sql语句 /// sql语句对应参数 /// public List FindListBySql(string strSql, DbParameter[] parameters) { return DataFactory.Database().FindListBySql(strSql, parameters); } /// /// 查询数据列表、返回List /// /// 分页参数 /// public List FindListPage(ref Pagination Pagination) { string orderField = Pagination.sidx; string orderType = Pagination.sord; int pageIndex = Pagination.page; int pageSize = Pagination.rows; int totalRow = Pagination.records; List List = DataFactory.Database().FindListPage(orderField, orderType, pageIndex, pageSize, ref totalRow); Pagination.records = totalRow; return List; } /// /// 查询数据列表、返回List /// /// 条件 /// 分页参数 /// public List FindListPage(string WhereSql, ref Pagination Pagination) { string orderField = Pagination.sidx; string orderType = Pagination.sord; int pageIndex = Pagination.page; int pageSize = Pagination.rows; int totalRow = Pagination.records; List List = DataFactory.Database().FindListPage(WhereSql, orderField, orderType, pageIndex, pageSize, ref totalRow); Pagination.records = totalRow; return List; } /// /// 查询数据列表、返回List /// /// 条件 /// sql语句对应参数 /// 分页参数 /// public List FindListPage(string WhereSql, DbParameter[] parameters, ref Pagination Pagination) { string orderField = Pagination.sidx; string orderType = Pagination.sord; int pageIndex = Pagination.page; int pageSize = Pagination.rows; int totalRow = Pagination.records; List List = DataFactory.Database().FindListPage(WhereSql, parameters, orderField, orderType, pageIndex, pageSize, ref totalRow); Pagination.records = totalRow; return List; } /// /// 查询数据列表、返回List /// /// Sql语句 /// 分页参数 /// public List FindListPageBySql(string strSql, ref Pagination Pagination) { string orderField = Pagination.sidx; string orderType = Pagination.sord; int pageIndex = Pagination.page; int pageSize = Pagination.rows; int totalRow = Pagination.records; List List = DataFactory.Database().FindListPageBySql(strSql, orderField, orderType, pageIndex, pageSize, ref totalRow); Pagination.records = totalRow; return List; } /// /// 查询数据列表、返回List /// /// Sql语句 /// 分页参数 /// public List FindListPageBySql(string strSql, DbParameter[] parameters, ref Pagination Pagination) { string orderField = Pagination.sidx; string orderType = Pagination.sord; int pageIndex = Pagination.page; int pageSize = Pagination.rows; int totalRow = Pagination.records; List List = DataFactory.Database().FindListPageBySql(strSql, parameters, orderField, orderType, pageIndex, pageSize, ref totalRow); Pagination.records = totalRow; return List; } #endregion #region 查询数据列表、返回DataTable /// /// 查询数据列表、返回 DataTable /// /// 显示条数 /// public DataTable FindTableTop(int Top) { return DataFactory.Database().FindTableTop(Top); } /// /// 查询数据列表、返回 DataTable /// /// 显示条数 /// 条件 /// public DataTable FindTableTop(int Top, string WhereSql) { return DataFactory.Database().FindTableTop(Top, WhereSql); } /// /// 查询数据列表、返回 DataTable /// /// 显示条数 /// 条件 /// sql语句对应参数 /// public DataTable FindTableTop(int Top, string WhereSql, DbParameter[] parameters) { return DataFactory.Database().FindTableTop(Top, WhereSql, parameters); } /// /// 查询数据列表、返回 DataTable /// /// public DataTable FindTable() { return DataFactory.Database().FindTable(); } /// /// 查询数据列表、返回 DataTable /// /// 条件 /// public DataTable FindTable(string WhereSql) { return DataFactory.Database().FindTable(WhereSql); } /// /// 查询数据列表、返回 DataTable /// /// 条件 /// sql语句对应参数 /// public DataTable FindTable(string WhereSql, DbParameter[] parameters) { return DataFactory.Database().FindTable(WhereSql, parameters); } /// /// 查询数据列表、返回 DataTable /// /// Sql语句 /// public DataTable FindTableBySql(string strSql) { return DataFactory.Database().FindTableBySql(strSql); } /// /// 查询数据列表、返回 DataTable /// /// Sql语句 /// sql语句对应参数 /// public DataTable FindTableBySql(string strSql, DbParameter[] parameters) { return DataFactory.Database().FindTableBySql(strSql, parameters); } /// /// 查询数据列表、返回 DataTable /// /// 排序字段 /// 排序类型 /// 当前页 /// 页大小 /// 返回查询条数 /// public DataTable FindTablePage(ref Pagination Pagination) { string orderField = Pagination.sidx; string orderType = Pagination.sord; int pageIndex = Pagination.page; int pageSize = Pagination.rows; int totalRow = Pagination.records; DataTable dt = DataFactory.Database().FindTablePage(orderField, orderType, pageIndex, pageSize, ref totalRow); Pagination.records = totalRow; return dt; } /// /// 查询数据列表、返回 DataTable /// /// 条件 /// 分页参数 /// public DataTable FindTablePage(string WhereSql, ref Pagination Pagination) { string orderField = Pagination.sidx; string orderType = Pagination.sord; int pageIndex = Pagination.page; int pageSize = Pagination.rows; int totalRow = Pagination.records; DataTable dt = DataFactory.Database().FindTablePage(WhereSql, orderField, orderType, pageIndex, pageSize, ref totalRow); Pagination.records = totalRow; return dt; } /// /// 查询数据列表、返回 DataTable /// /// 条件 /// sql语句对应参数 /// 分页参数 /// public DataTable FindTablePage(string WhereSql, DbParameter[] parameters, ref Pagination Pagination) { string orderField = Pagination.sidx; string orderType = Pagination.sord; int pageIndex = Pagination.page; int pageSize = Pagination.rows; int totalRow = Pagination.records; DataTable dt = DataFactory.Database().FindTablePage(WhereSql, parameters, orderField, orderType, pageIndex, pageSize, ref totalRow); Pagination.records = totalRow; return dt; } /// /// 查询数据列表、返回 DataTable /// /// Sql语句 /// 分页参数 /// public DataTable FindTablePageBySql(string strSql, ref Pagination Pagination) { string orderField = Pagination.sidx; string orderType = Pagination.sord; int pageIndex = Pagination.page; int pageSize = Pagination.rows; int totalRow = Pagination.records; DataTable dt = DataFactory.Database().FindTablePageBySql(strSql, orderField, orderType, pageIndex, pageSize, ref totalRow); Pagination.records = totalRow; return dt; } /// /// 查询数据列表、返回 DataTable /// /// Sql语句 /// sql语句对应参数 /// 分页参数 /// public DataTable FindTablePageBySql(string strSql, DbParameter[] parameters, ref Pagination Pagination) { string orderField = Pagination.sidx; string orderType = Pagination.sord; int pageIndex = Pagination.page; int pageSize = Pagination.rows; int totalRow = Pagination.records; DataTable dt = DataFactory.Database().FindTablePageBySql(strSql, parameters, orderField, orderType, pageIndex, pageSize, ref totalRow); Pagination.records = totalRow; return dt; } /// /// 查询数据列表、返回 DataTable /// /// 存储过程 /// public DataTable FindTableByProc(string procName) { return DataFactory.Database().FindTableByProc(procName); } /// /// 查询数据列表、返回 DataTable /// /// 存储过程 /// sql语句对应参数 /// public DataTable FindTableByProc(string procName, DbParameter[] parameters) { return DataFactory.Database().FindTableByProc(procName, parameters); } #endregion #region 查询数据列表、返回DataSet /// /// 查询数据列表、返回DataSet /// /// Sql语句 /// public DataSet FindDataSetBySql(string strSql) { return DataFactory.Database().FindDataSetBySql(strSql); } /// /// 查询数据列表、返回DataSet /// /// Sql语句 /// sql语句对应参数 /// public DataSet FindDataSetBySql(string strSql, DbParameter[] parameters) { return DataFactory.Database().FindDataSetBySql(strSql, parameters); } /// /// 查询数据列表、返回DataSet /// /// 存储过程 /// public DataSet FindDataSetByProc(string procName) { return DataFactory.Database().FindDataSetByProc(procName); } /// /// 查询数据列表、返回DataSet /// /// 存储过程 /// sql语句对应参数 /// public DataSet FindDataSetByProc(string procName, DbParameter[] parameters) { return DataFactory.Database().FindDataSetByProc(procName, parameters); } #endregion #region 查询对象、返回实体 /// /// 查询对象、返回实体 /// /// 主键值 /// public T FindEntity(object propertyValue) { return DataFactory.Database().FindEntity(propertyValue); } /// /// 查询对象、返回实体 /// /// 实体属性名称 /// 字段值 /// public T FindEntity(string propertyName, object propertyValue) { return DataFactory.Database().FindEntity(propertyName, propertyValue); } /// /// 查询对象、返回实体 /// /// 条件 /// public T FindEntityByWhere(string WhereSql) { return DataFactory.Database().FindEntity(WhereSql); } /// /// 查询对象、返回实体 /// /// 条件 /// sql语句对应参数 /// public T FindEntityByWhere(string WhereSql, DbParameter[] parameters) { return DataFactory.Database().FindEntity(WhereSql, parameters); } /// /// 查询对象、返回实体 /// /// Sql语句 /// public T FindEntityBySql(string strSql) { return DataFactory.Database().FindEntityBySql(strSql); } /// /// 查询对象、返回实体 /// /// Sql语句 /// sql语句对应参数 /// public T FindEntityBySql(string strSql, DbParameter[] parameters) { return DataFactory.Database().FindEntityBySql(strSql, parameters); } #endregion #region 查询数据、返回条数 /// /// 查询数据、返回条数 /// /// public int FindCount() { return DataFactory.Database().FindCount(); } /// /// 查询数据、返回条数 /// 实体属性名称 /// 字段值 /// /// public int FindCount(string propertyName, string propertyValue) { return DataFactory.Database().FindCount(propertyName, propertyValue); } /// /// 查询数据、返回条数 /// /// 条件 /// public int FindCount(string WhereSql) { return DataFactory.Database().FindCount(WhereSql); } /// /// 查询数据、返回条数 /// /// 条件 /// sql语句对应参数 /// public int FindCount(string WhereSql, DbParameter[] parameters) { return DataFactory.Database().FindCount(WhereSql, parameters); } /// /// 查询数据、返回条数 /// /// Sql语句 /// public int FindCountBySql(string strSql) { return DataFactory.Database().FindCountBySql(strSql); } /// /// 查询数据、返回条数 /// /// Sql语句 /// sql语句对应参数 /// public int FindCountBySql(string strSql, DbParameter[] parameters) { return DataFactory.Database().FindCountBySql(strSql, parameters); } #endregion #region 查询数据、返回最大数 /// /// 查询数据、返回最大数 /// /// 实体属性名称 /// public object FindMax(string propertyName) { return DataFactory.Database().FindMax(propertyName); } /// /// 查询数据、返回最大数 /// /// 实体属性名称 /// 条件 /// public object FindMax(string propertyName, string WhereSql) { return DataFactory.Database().FindMax(propertyName, WhereSql); } /// /// 查询数据、返回最大数 /// /// 实体属性名称 /// 条件 /// sql语句对应参数 /// public object FindMax(string propertyName, string WhereSql, DbParameter[] parameters) { return DataFactory.Database().FindMax(propertyName, WhereSql, parameters); } /// /// 查询数据、返回最大数 /// /// Sql语句 /// public object FindMaxBySql(string strSql) { return DataFactory.Database().FindMaxBySql(strSql); } /// /// 查询数据、返回最大数 /// /// Sql语句 /// sql语句对应参数 /// public object FindMaxBySql(string strSql, DbParameter[] parameters) { return DataFactory.Database().FindMaxBySql(strSql, parameters); } #endregion } }