예제 #1
0
        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);
        }
예제 #2
0
        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);
        }