public List <T> Find <T>(string strSQL, ParamMap param) where T : new() { List <T> list = new List <T>(); IDataReader sdr = null; IDbConnection connection = null; try { connection = GetConnection(); bool closeConnection = GetWillConnectionState(); string lowerSQL = strSQL.ToLower(); String columns = SQLBuilderHelper.fetchColumns(lowerSQL); T entity = new T(); Type classType = entity.GetType(); PropertyInfo[] properties = ReflectionHelper.GetProperties(classType); TableInfo tableInfo = EntityHelper.GetTableInfo(entity, DbOperateType.SELECT, properties); if (param.IsPage && !SQLBuilderHelper.isPage(lowerSQL)) { strSQL = SQLBuilderHelper.builderPageSQL(strSQL, param.OrderFields, param.IsDesc); } if (AdoHelper.DbType == DatabaseType.ACCESS) { strSQL = SQLBuilderHelper.builderAccessPageSQL(strSQL, param); } sdr = AdoHelper.ExecuteReader(closeConnection, connection, CommandType.Text, strSQL, param.toDbParameters()); list = EntityHelper.toList <T>(sdr, tableInfo, properties); } catch (Exception ex) { throw ex; } finally { if (sdr != null) { sdr.Close(); } } return(list); }
public PageResult <T> FindPage <T>(string strSQL, ParamMap param) where T : new() { PageResult <T> pageResult = new PageResult <T>(); List <T> list = new List <T>(); IDataReader sdr = null; IDbConnection connection = null; try { connection = GetConnection(); bool closeConnection = GetWillConnectionState(); strSQL = strSQL.ToLower(); String countSQL = SQLBuilderHelper.builderCountSQL(strSQL); String columns = SQLBuilderHelper.fetchColumns(strSQL); int count = this.Count(countSQL, param); T entity = new T(); Type classType = entity.GetType(); PropertyInfo[] properties = ReflectionHelper.GetProperties(classType); TableInfo tableInfo = EntityHelper.GetTableInfo(entity, DbOperateType.SELECT, properties); if (param.IsPage && !SQLBuilderHelper.isPage(strSQL)) { strSQL = SQLBuilderHelper.builderPageSQL(strSQL, param.OrderFields, param.IsDesc); } if (AdoHelper.DbType == DatabaseType.ACCESS) { if (param.getInt("page_offset") > count) { int limit = param.getInt("page_limit") + count - param.getInt("page_offset"); if (limit > 0) { strSQL = SQLBuilderHelper.builderAccessPageSQL(strSQL, param, limit); sdr = AdoHelper.ExecuteReader(closeConnection, connection, CommandType.Text, strSQL, param.toDbParameters()); list = EntityHelper.toList <T>(sdr, tableInfo, properties); } } else { strSQL = SQLBuilderHelper.builderAccessPageSQL(strSQL, param); sdr = AdoHelper.ExecuteReader(closeConnection, connection, CommandType.Text, strSQL, param.toDbParameters()); list = EntityHelper.toList <T>(sdr, tableInfo, properties); } } else { sdr = AdoHelper.ExecuteReader(closeConnection, connection, CommandType.Text, strSQL, param.toDbParameters()); list = EntityHelper.toList <T>(sdr, tableInfo, properties); } pageResult.Total = count; pageResult.DataList = list; } catch (Exception ex) { throw ex; } finally { if (sdr != null) { sdr.Close(); } } return(pageResult); }