using Lottomat.Util.WebControl;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;
namespace Lottomat.Data.Repository
{
///
/// 版 本 1.0
/// Copyright (c) 2016-2017
/// 创建人:赵轶
/// 日 期:2015.10.10
/// 描 述:定义仓储模型中的数据标准操作
///
public class Repository : IRepository
{
#region 构造
public IDatabase db;
///
/// 仓储模型
///
///
public Repository(IDatabase idatabase)
{
this.db = idatabase;
}
#endregion
#region 事务提交
///
/// 开始事务
///
///
public IRepository BeginTrans()
{
db.BeginTrans();
return this;
}
///
/// 提交
///
public void Commit()
{
db.Commit();
}
///
/// 回滚
///
public void Rollback()
{
db.Rollback();
}
#endregion
#region 执行 SQL 语句
///
/// 执行T-SQL
///
/// sql语句
///
public int ExecuteBySql(string strSql)
{
return db.ExecuteBySql(strSql);
}
///
/// 执行T-SQL
///
/// sql语句
/// DbCommand参数
///
public int ExecuteBySql(string strSql, params DbParameter[] dbParameter)
{
return db.ExecuteBySql(strSql, dbParameter);
}
///
/// 执行存储过程
///
/// 存储过程名称
///
public int ExecuteByProc(string procName)
{
return db.ExecuteByProc(procName);
}
///
/// 执行存储过程
///
/// 存储过程名称
/// DbCommand参数
///
public int ExecuteByProc(string procName, params DbParameter[] dbParameter)
{
return db.ExecuteByProc(procName, dbParameter);
}
#endregion
#region 对象实体 添加、修改、删除
///
/// 插入一条数据
///
/// 对象实体
///
public int Insert(T entity) where T : class
{
return db.Insert(entity);
}
///
/// 批量插入数据
///
/// 对象实体集合
///
public int Insert(List entity) where T : class
{
return db.Insert(entity);
}
///
/// 删除
///
///
public int Delete() where T : class
{
return db.Delete();
}
///
/// 删除一条数据
///
/// 对象实体
///
public int Delete(T entity) where T : class
{
return db.Delete(entity);
}
///
/// 批量删除
///
/// 对象实体集合
///
public int Delete(List entity) where T : class
{
return db.Delete(entity);
}
///
/// 根据条件删除数据
///
/// 条件
///
public int Delete(Expression> condition) where T : class, new()
{
return db.Delete(condition);
}
///
/// 根据主键删除一条数据
///
/// 主键
///
public int Delete(object keyValue) where T : class
{
return db.Delete(keyValue);
}
///
/// 根据主键批量删除一条数据
///
/// 主键数组
///
public int Delete(object[] keyValue) where T : class
{
return db.Delete(keyValue);
}
///
/// 根据属性删除
///
/// 属性值
/// 属性名
///
public int Delete(object propertyValue, string propertyName) where T : class
{
return db.Delete(propertyValue, propertyName);
}
///
/// 更新一条数据
///
/// 实体对象
///
public int Update(T entity) where T : class
{
return db.Update(entity);
}
///
/// 批量更新
///
/// 实体对象集合
///
public int Update(List entity) where T : class
{
return db.Update(entity);
}
///
/// 根据条件更新
///
/// 条件
///
public int Update(Expression> condition) where T : class, new()
{
return db.Update(condition);
}
#endregion
#region 对象实体 查询
///
/// 根据主键获取一条数据
///
/// 主键值
///
public T FindEntity(object keyValue) where T : class
{
return db.FindEntity(keyValue);
}
///
/// 根据条件获取一条数据
///
/// 条件
///
public T FindEntity(Expression> condition) where T : class, new()
{
return db.FindEntity(condition);
}
///
/// 获取IQueryable对象
///
///
public IQueryable IQueryable() where T : class, new()
{
return db.IQueryable();
}
///
/// 根据条件获取IQueryable对象
///
///
///
public IQueryable IQueryable(Expression> condition) where T : class, new()
{
return db.IQueryable(condition);
}
///
/// 获取一条数据,返回对象集合
///
///
///
public IEnumerable FindList() where T : class, new()
{
return db.FindList();
}
///
/// 根据条件获取一条数据,返回对象集合
///
/// 条件
///
public IEnumerable FindList(Expression> condition) where T : class, new()
{
return db.FindList(condition);
}
///
/// 根据T-SQL语句获取一条数据,返回对象集合
///
/// T-SQL语句
///
public IEnumerable FindList(string strSql) where T : class
{
return db.FindList(strSql);
}
///
/// 根据T-SQL语句获取一条数据,返回对象集合
///
/// T-SQL语句
/// DbCommand参数
///
public IEnumerable FindList(string strSql, DbParameter[] dbParameter) where T : class
{
return db.FindList(strSql, dbParameter);
}
///
/// 根据分页参数获取一条数据,返回对象集合
///
/// 分页参数
///
public IEnumerable FindList(Pagination pagination) where T : class, new()
{
int total = pagination.records;
var data = db.FindList(pagination.sidx, pagination.sord.ToLower() == "asc" ? true : false, pagination.rows, pagination.page, out total);
pagination.records = total;
return data;
}
///
/// 根据分页参数、条件获取一条数据,返回对象集合
///
/// 条件
/// 分页参数
///
public IEnumerable FindList(Expression> condition, Pagination pagination) where T : class, new()
{
int total = pagination.records;
var data = db.FindList(condition, pagination.sidx, pagination.sord.ToLower() == "asc" ? true : false, pagination.rows, pagination.page, out total);
pagination.records = total;
return data;
}
///
/// 根据分页参数获取一条数据,返回对象集合
///
/// T-SQL语句
/// 分页参数
///
public IEnumerable FindList(string strSql, Pagination pagination) where T : class
{
int total = pagination.records;
var data = db.FindList(strSql, pagination.sidx, pagination.sord.ToLower() == "asc" ? true : false, pagination.rows, pagination.page, out total);
pagination.records = total;
return data;
}
///
/// 根据分页参数获取一条数据,返回对象集合
///
/// T-SQL语句
/// DbCommand参数
/// 分页参数
///
public IEnumerable FindList(string strSql, DbParameter[] dbParameter, Pagination pagination) where T : class
{
int total = pagination.records;
var data = db.FindList(strSql, dbParameter, pagination.sidx, pagination.sord.ToLower() == "asc" ? true : false, pagination.rows, pagination.page, out total);
pagination.records = total;
return data;
}
#endregion
#region 数据源 查询
///
/// 返回DataTable
///
/// T-SQL语句
///
public DataTable FindTable(string strSql)
{
return db.FindTable(strSql);
}
///
/// 返回DataTable
///
/// T-SQL语句
/// DbCommand参数
///
public DataTable FindTable(string strSql, DbParameter[] dbParameter)
{
return db.FindTable(strSql, dbParameter);
}
///
/// 返回DataTable
///
/// T-SQL语句
/// 分页参数
///
public DataTable FindTable(string strSql, Pagination pagination)
{
int total = pagination.records;
var data = db.FindTable(strSql, pagination.sidx, pagination.sord.ToLower() == "asc" ? true : false, pagination.rows, pagination.page, out total);
pagination.records = total;
return data;
}
///
/// 返回DataTable
///
/// T-SQL语句
/// DbCommand参数
/// 分页参数
///
public DataTable FindTable(string strSql, DbParameter[] dbParameter, Pagination pagination)
{
int total = pagination.records;
var data = db.FindTable(strSql, dbParameter, pagination.sidx, pagination.sord.ToLower() == "asc" ? true : false, pagination.rows, pagination.page, out total);
pagination.records = total;
return data;
}
///
/// 获取分页DataTable
///
/// T-SQL语句
/// 排序字段
/// 是否升序
/// 每页条数
/// 索引
/// 总记录
///
public DataTable FindTable(string strSql, string orderField, bool isAsc, int pageSize, int pageIndex, out int total)
{
DataTable data = db.FindTable(strSql, orderField, isAsc, pageSize, pageIndex, out int totalRows);
total = totalRows;
return data;
}
///
/// 返回Object
///
/// T-SQL语句
///
public object FindObject(string strSql)
{
return db.FindObject(strSql);
}
///
/// 返回Object
///
/// T-SQL语句
/// DbCommand参数
///
public object FindObject(string strSql, DbParameter[] dbParameter)
{
return db.FindObject(strSql, dbParameter);
}
#endregion
}
}