Exemple #1
0
        /// <summary>
        /// 查找指定条件的公司分页集合
        /// </summary>
        /// <param name="companySearcher">公司查询对象</param>
        /// <param name="pager">分页对象</param>
        /// <param name="tran">中间事务对象</param>
        /// <returns>返回查找到的分页集合,包括按条件可查询到的所有记录数和当前分页的对象集合</returns>
        public PageList <Company> FindList(CompanySearcher companySearcher, Pager pager, ICTransaction tran)
        {
            CompanySearcher      querySearcher = null;
            HibernateTransaction hTran         = null;
            ISession             session       = null;
            PageList <Company>   pList         = new PageList <Company>();
            HQLQueryParser       queryParser   = new HQLQueryParser();
            StringBuilder        query         = new StringBuilder();

            query.AppendLine("SELECT ");
            query.AppendLine("   C ");
            query.AppendLine("FROM ");
            query.AppendLine("   Company C ");

            if (companySearcher != null)
            {
                querySearcher           = (CompanySearcher)companySearcher.Clone();
                querySearcher.TableName = "C";
            }

            queryParser.SearcherParse(querySearcher);

            if (!string.IsNullOrEmpty(queryParser.ConditionString))
            {
                query.AppendLine("WHERE ");
                query.AppendLine("   " + queryParser.ConditionString);
            }

            if (!string.IsNullOrEmpty(queryParser.SortString))
            {
                query.AppendLine("ORDER BY ");
                query.AppendLine("   " + queryParser.SortString);
            }

            if (tran != null)
            {
                hTran            = (HibernateTransaction)tran;
                session          = hTran.CurrentSession;
                pList.TotalCount = this.Count(querySearcher, tran);
            }
            else
            {
                session          = this.CurrentHibernateConfig.GetCurrentSession();
                pList.TotalCount = this.Count(querySearcher);
            }

            if (pager != null)
            {
                pList.RecordList = HibernateHelper.FindObjectListByHQL <Company>(session, query.ToString(), queryParser.ParamCollection, pager);
            }
            else
            {
                pList.RecordList = HibernateHelper.FindObjectListByHQL <Company>(session, query.ToString(), queryParser.ParamCollection);
            }

            return(pList);
        }
Exemple #2
0
        /// <summary>
        /// 查找指定条件的员工分页集合
        /// </summary>
        /// <param name="employeeSearcher">员工查询对象</param>
        /// <param name="pager">分页对象</param>
        /// <param name="tran">中间事务对象</param>
        /// <returns>返回查找到的分页集合,包括按条件可查询到的所有记录数和当前分页的对象集合</returns>
        public PageList <Employee> FindList(EmployeeSearcher employeeSearcher, Pager pager, ICTransaction tran)
        {
            EmployeeSearcher     querySearcher = null;
            HibernateTransaction hTran         = null;
            ISession             session       = null;
            PageList <Employee>  pList         = new PageList <Employee>();
            HQLQueryParser       queryParser   = new HQLQueryParser();
            StringBuilder        query         = new StringBuilder();

            query.Append("SELECT ");
            query.Append(" E ");
            query.Append("FROM ");
            query.Append("  Employee E ");

            if (employeeSearcher != null)
            {
                querySearcher           = (EmployeeSearcher)employeeSearcher.Clone();
                querySearcher.TableName = "E";

                if (querySearcher.CurrCompany != null)
                {
                    querySearcher.CurrCompany.TableName = "C";
                    query.Append("LEFT JOIN ");
                    query.Append("  E.CurrCompany C ");
                }

                if (querySearcher.CurrDepartment != null)
                {
                    querySearcher.CurrDepartment.TableName = "D";
                    query.Append("LEFT JOIN ");
                    query.Append("  E.CurrDepartment D ");
                }

                if (querySearcher.CurrPosition != null)
                {
                    querySearcher.CurrPosition.TableName = "P";
                    query.Append("LEFT JOIN ");
                    query.Append("  E.CurrPosition P ");
                }
            }

            queryParser.SearcherParse(querySearcher);

            if (!string.IsNullOrEmpty(queryParser.ConditionString))
            {
                query.Append("WHERE ");
                query.Append("  " + queryParser.ConditionString);
            }

            if (!string.IsNullOrEmpty(queryParser.SortString))
            {
                query.Append("ORDER BY ");
                query.Append("  " + queryParser.SortString);
            }

            if (tran != null)
            {
                hTran            = (HibernateTransaction)tran;
                session          = hTran.CurrentSession;
                pList.TotalCount = this.Count(querySearcher, tran);
            }
            else
            {
                session          = this.CurrentHibernateConfig.GetCurrentSession();
                pList.TotalCount = this.Count(querySearcher);
            }

            if (pager != null)
            {
                pList.RecordList = HibernateHelper.FindObjectListByHQL <Employee>(session, query.ToString(), queryParser.ParamCollection, pager);
            }
            else
            {
                pList.RecordList = HibernateHelper.FindObjectListByHQL <Employee>(session, query.ToString(), queryParser.ParamCollection);
            }

            return(pList);
        }