示例#1
0
        /// <summary>
        /// Calculates record and page count for the specified query
        /// </summary>
        private VirtualRecordCount CalculateVirtualRecordCount()
        {
            var count = new VirtualRecordCount
            {
                RecordCount       = IsQueryTotalCount ? GetQueryVirtualCount() : TotalCount,
                RecordsInLastPage = ItemsPerPage
            };

            // Calculate the virtual number of records from the query

            // Calculate the correspondent number of pages
            var lastPage  = count.RecordCount / ItemsPerPage;
            var remainder = count.RecordCount % ItemsPerPage;

            if (remainder > 0)
            {
                lastPage++;
            }
            count.PageCount = lastPage;

            // Calculate the number of items in the last page
            if (remainder > 0)
            {
                count.RecordsInLastPage = remainder;
            }
            return(count);
        }
示例#2
0
        /// <summary>
        /// Prepares and returns the command object for the reader-based query
        /// </summary>
        private IDbCommand PrepareCommand(VirtualRecordCount countInfo)
        {
            // Determines how many records are to be retrieved.
            // The last page could require less than other pages
            var recsToRetrieve = ItemsPerPage;

            if (CurrentPageIndex == countInfo.PageCount - 1)
            {
                recsToRetrieve = countInfo.RecordsInLastPage;
            }

            var cmdText = GetQueryPageCommandText(recsToRetrieve);

            var conn = Main.DataApi.GetConnection(Main.ConnectionString);
            var cmd  = Main.DataApi.GetCommand();

            cmd.Connection  = conn;
            cmd.CommandText = cmdText;
            return(cmd);
        }