Пример #1
0
        /// <summary>
        /// Gets the number of items matching the given filter clauses.
        /// </summary>
        /// <param name="filterClauses">Filter clauses to match.</param>
        /// <returns>Number of items matching the filter clauses.</returns>
        public long GetFilteredItemsCount(FilterClause[] filterClauses)
        {
            List<DaoParameter> parameters = new List<DaoParameter>();
            string whereClause = string.Empty;
            bool isFiltered = false;

            foreach (FilterClause clause in filterClauses)
            {
                if (clause != null)
                {
                    string sqlClause = clause.GetSqlWhereClause(!isFiltered, parameters);
                    if (!string.IsNullOrEmpty(sqlClause))
                    {
                        whereClause += sqlClause + " ";
                        isFiltered = true;
                    }
                }
            }

            DaoConnection connection = null;
            long result = -1;
            try
            {
                connection = DaoConnection.Open(DaoConnectionEnum.SrsDatabase);

                 result = (long)connection.QueryScalar(
                    "SELECT COUNT(1) FROM " + SqlHelper.Table_SrsEntry + " se "
                    + whereClause,
                    parameters.ToArray());
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }

            return result;
        }
Пример #2
0
        /// <summary>
        /// Gets a filtered set of SRS entries.
        /// </summary>
        /// <param name="filterClauses">Filter clauses.</param>
        /// <returns>Filtered SRS entries.</returns>
        public IEnumerable<SrsEntry> GetFilteredItems(FilterClause[] filterClauses)
        {
            List<DaoParameter> parameters = new List<DaoParameter>();
            string whereClause = string.Empty;
            bool isFiltered = false;

            foreach (FilterClause clause in filterClauses)
            {
                if (clause != null)
                {
                    string sqlClause = clause.GetSqlWhereClause(!isFiltered, parameters);
                    if (!string.IsNullOrEmpty(sqlClause))
                    {
                        whereClause += sqlClause + " ";
                        isFiltered = true;
                    }
                }
            }

            DaoConnection connection = null;
            try
            {
                connection = DaoConnection.Open(DaoConnectionEnum.SrsDatabase);

                IEnumerable<NameValueCollection> results = connection.Query(
                    "SELECT * FROM " + SqlHelper.Table_SrsEntry + " se "
                    + whereClause
                    + "ORDER BY (se." + SqlHelper.Field_SrsEntry_CreationDate + ") DESC",
                    parameters.ToArray());

                SrsEntryBuilder srsEntryBuilder = new SrsEntryBuilder();
                foreach (NameValueCollection nvcEntry in results)
                {
                    yield return srsEntryBuilder.BuildEntity(nvcEntry, null);
                }
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }