public List <T> Find <T>(string strSql) where T : new() { List <T> list = new List <T>(); IDataReader sdr = null; IDbConnection connection = null; try { connection = GetConnection(); bool closeConnection = GetWillConnectionState(); strSql = strSql.ToUpper(); String columns = SQLBuilderHelper.fetchColumns(strSql); T entity = new T(); PropertyInfo[] properties = ReflectionHelper.GetProperties(entity.GetType()); TableInfo tableInfo = EntityHelper.GetTableInfo(entity, DbOperateType.SELECT, properties); sdr = AdoHelper.ExecuteReader(closeConnection, connection, CommandType.Text, strSql, null); list = EntityHelper.toList <T>(sdr, tableInfo, properties); } catch (Exception ex) { throw ex; } finally { if (sdr != null) { sdr.Close(); } } return(list); }
public List <T> FindBySql <T>(string strSql, ParamMap param) where T : new() { List <T> list = new List <T>(); IDataReader sdr = null; try { strSql = strSql.ToLower(); String columns = SQLBuilderHelper.fetchColumns(strSql); PropertyInfo[] properties = ReflectionHelper.GetProperties(new T().GetType()); TableInfo tableInfo = EntityHelper.GetTableInfo(new T(), DbOperateType.SELECT, properties); if (param.IsPage && !SQLBuilderHelper.isPage(strSql)) { strSql = SQLBuilderHelper.builderPageSQL(strSql, param.OrderFields, param.IsDesc); } sdr = AdoHelper.ExecuteReader(AdoHelper.ConnectionString, 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 List <T> FindBySql <T>(string strSql, int pageIndex, int pageSize, string order, bool desc) where T : new() { List <T> list = new List <T>(); IDataReader sdr = null; try { strSql = strSql.ToLower(); String columns = SQLBuilderHelper.fetchColumns(strSql); PropertyInfo[] properties = ReflectionHelper.GetProperties(new T().GetType()); TableInfo tableInfo = EntityHelper.GetTableInfo(new T(), DbOperateType.SELECT, properties); strSql = SQLBuilderHelper.builderPageSQL(strSql, order, desc); ParamMap param = ParamMap.newMap(); param.setPageIndex(pageIndex); param.setPageSize(pageSize); sdr = AdoHelper.ExecuteReader(AdoHelper.ConnectionString, 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); T entity = new T(); PropertyInfo[] properties = ReflectionHelper.GetProperties(entity.GetType()); 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) { strSQL = SQLBuilderHelper.builderAccessSQL(strSQL, param.toDbParameters()); sdr = AdoHelper.ExecuteReader(closeConnection, connection, CommandType.Text, strSQL); } else { sdr = AdoHelper.ExecuteReader(closeConnection, connection, CommandType.Text, strSQL, param.toDbParameters()); } int count = this.Count(countSQL, param); 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); }
public List <T> FindByProperty <T>(string propertyName, object propertyValue) where T : new() { List <T> list = new List <T>(); IDataReader sdr = null; try { PropertyInfo[] properties = ReflectionHelper.GetProperties(new T().GetType()); TableInfo tableInfo = EntityHelper.GetTableInfo(new T(), DbOperateType.SELECT, properties); String strSql = EntityHelper.GetFindAllSql(tableInfo); strSql += string.Format(" WHERE {0} = @{1}", propertyName, propertyName); strSql = strSql.ToLower(); String columns = SQLBuilderHelper.fetchColumns(strSql);// strSql.Substring(0, strSql.IndexOf("FROM")); ColumnInfo columnInfo = new ColumnInfo(); columnInfo.Add(propertyName, propertyValue); IDbDataParameter[] parameters = DbFactory.CreateDbParameters(1); EntityHelper.SetParameters(columnInfo, parameters); sdr = AdoHelper.ExecuteReader(AdoHelper.ConnectionString, CommandType.Text, strSql, parameters); list = EntityHelper.toList <T>(sdr, tableInfo, properties); } catch (Exception ex) { throw ex; } finally { if (sdr != null) { sdr.Close(); } } return(list); }
public int Count(string strSql, ParamMap param) { int count = 0; try { strSql = strSql.ToLower(); String columns = SQLBuilderHelper.fetchColumns(strSql); if (AdoHelper.DbType == DatabaseType.ACCESS) { strSql = SQLBuilderHelper.builderAccessSQL(strSql, param.toDbParameters()); } count = Convert.ToInt32(AdoHelper.ExecuteScalar(AdoHelper.ConnectionString, CommandType.Text, strSql, param.toDbParameters())); } catch (Exception ex) { throw ex; } return(count); }
public int Count(string strSql, ParamMap param) { int count = 0; IDbConnection connection = null; bool closeConnection = GetWillConnectionState(); try { connection = GetConnection(); strSql = strSql.ToLower(); String columns = SQLBuilderHelper.fetchColumns(strSql); if (AdoHelper.DbType == DatabaseType.ACCESS) { strSql = SQLBuilderHelper.builderAccessSQL(strSql, param.toDbParameters()); count = Convert.ToInt32(AdoHelper.ExecuteScalar(connection, CommandType.Text, strSql)); } else { count = Convert.ToInt32(AdoHelper.ExecuteScalar(connection, CommandType.Text, strSql, param.toDbParameters())); } } catch (Exception ex) { throw ex; } finally { if (closeConnection) { connection.Close(); } } return(count); }