Exemplo n.º 1
0
        public static IList <T> FindPagingByCriteria <T>(object finder, string methodName, object[] parameters, int firstResult, int maxResults, string sortExpression)
        {
            MethodInfo methodInfo   = finder.GetType().GetMethod(methodName);
            object     invokeResult = methodInfo.Invoke(finder, parameters);
            IList <T>  result       = new List <T>();

            if (invokeResult is ISQLQuery)
            {
                ISQLQuery query = (ISQLQuery)invokeResult;

                if (firstResult != -1 && maxResults != -1)
                {
                    query.SetFirstResult(firstResult);
                    query.SetMaxResults(maxResults);
                }

                result = query.List <T>();
            }
            else if (invokeResult is IQuery)
            {
                IQuery query = (IQuery)invokeResult;

                if (firstResult != -1 && maxResults != -1)
                {
                    query.SetFirstResult(firstResult);
                    query.SetMaxResults(maxResults);
                }

                result = query.List <T>();
            }
            else if (invokeResult is ICriteria)
            {
                ICriteria criteria = (ICriteria)invokeResult;

                if (!string.IsNullOrEmpty(sortExpression))
                {
                    sortExpression = sortExpression.Trim();
                    if (sortExpression.ToLower().EndsWith(" asc"))
                    {
                        sortExpression = sortExpression.Substring(0, sortExpression.Length - 4);
                        criteria.AddOrder(Order.Asc(sortExpression));
                    }
                    else if (sortExpression.ToLower().EndsWith(" desc"))
                    {
                        sortExpression = sortExpression.Substring(0, sortExpression.Length - 5);
                        criteria.AddOrder(Order.Desc(sortExpression));
                    }
                }

                if (firstResult != -1 && maxResults != -1)
                {
                    criteria.SetFirstResult(firstResult);
                    criteria.SetMaxResults(maxResults);
                }

                result = criteria.List <T>();
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// For Reports
        /// </summary>
        /// <param name="firstResult"></param>
        /// <param name="maxResults"></param>
        /// <param name="nativeSQLQuery">Standard SQL Query</param>
        /// <param name="resultTransformer"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public ICollection <T> FindAll(string sqlQuery, int firstResult, int maxResults, NHibernate.Transform.IResultTransformer resultTransformer, params Parameter[] parameters)
        {
            ISQLQuery query = CreateSQLQuery(sqlQuery, parameters);

            query.SetResultTransformer(resultTransformer);
            query.SetFirstResult(firstResult);
            query.SetMaxResults(maxResults);
            return(query.List <T>());
        }
Exemplo n.º 3
0
        public IList QueryBySQL(string sql, string[] names, object[] values, int pageIndex, int pageSize)
        {
            ISQLQuery query = session.CreateSQLQuery(sql);

            for (int i = 0; i < names.Length; i++)
            {
                query.SetParameter(names[i], values[i]);
            }
            return(query.SetFirstResult((pageIndex - 1) * pageSize).SetMaxResults(pageSize).List());
        }
Exemplo n.º 4
0
        public System.Collections.IList QueryBySQL(string sql, object[] values, int pageIndex, int pageSize)
        {
            ISQLQuery query = session.CreateSQLQuery(sql);

            for (int i = 0; i < values.Length; i++)
            {
                query.SetParameter(i, values[i]);
            }
            query.SetFirstResult((pageIndex - 1) * pageSize);
            query.SetMaxResults(pageSize);
            return(query.List());
        }
Exemplo n.º 5
0
        public System.Collections.IList QueryBySQL(string sql, string[] names, object[] values, int pageIndex, int pageSize)
        {
            if (names.Length != values.Length)
            {
                throw new QueryParameterException("查询参数不匹配!");
            }
            ISQLQuery query = session.CreateSQLQuery(sql);

            for (int i = 0; i < values.Length; i++)
            {
                query.SetParameter(names[i], values[i]);
            }
            query.SetFirstResult((pageIndex - 1) * pageSize);
            query.SetMaxResults(pageSize);
            return(query.List());
        }
Exemplo n.º 6
0
        public IList <TDto> GetBySql <TDto>(Pager pager, String countSql, String sql, IDictionary <string, Object> namedParameters)
        {
            Check.Require(pager != null, "pager may not be null!");
            CheckSqlInjection(sql);
            ISQLQuery q  = Session.CreateSQLQuery(sql);
            ISQLQuery cq = Session.CreateSQLQuery(countSql);

            if (namedParameters != null)
            {
                foreach (var namedParameter in namedParameters)
                {
                    q.SetParameter(namedParameter.Key, namedParameter.Value);
                    cq.SetParameter(namedParameter.Key, namedParameter.Value);;
                }
            }
            pager.ItemCount = (int)cq.UniqueResult();
            if (pager.PageSize > 0)
            {
                q.SetFirstResult(pager.FromRowIndex).SetMaxResults(pager.PageSize);
            }
            return(q.SetResultTransformer(
                       Transformers.AliasToBean <TDto>()).List <TDto>());
        }
Exemplo n.º 7
0
        public IList QueryBySQL(string sql, int pageIndex, int pageSize)
        {
            ISQLQuery query = session.CreateSQLQuery(sql);

            return(query.SetFirstResult((pageIndex - 1) * pageSize).SetMaxResults(pageSize).List());
        }