示例#1
0
        public PagedDataSet GetPagedDataSet(IFinder finder, Int32 Page, Int32 RecordsPerPage)
        {
            using (IDbConnection connection = OpenConnection())
            {
                try
                {
#if DEBUG
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
#endif
                    PagedDataSet ds = new PagedDataSet(finder.Table);

                    using (IDbCommand command = finder.CountCommand)
                    {
                        command.Connection = connection;
                        int numRecords = (int)command.ExecuteScalar();
                        ds.PagingInfo = new PagingInfo(numRecords, Page, RecordsPerPage);
#if DEBUG
                        LogMessage("GetPagedDataSet", finder.CountCommand, sw.ElapsedMilliseconds);
#endif
                    }

                    using (IDbCommand command = finder.FindCommand)
                    {
                        command.Connection = connection;
                        DbDataAdapter da = m_factory.CreateAdapter(command);
                        da.Fill(ds, ds.PagingInfo.StartRecord - 1, ds.PagingInfo.PageSize, finder.Table);
#if DEBUG
                        LogMessage("GetPagedDataSet", finder.FindCommand, sw.ElapsedMilliseconds);
#endif
                    }
#if DEBUG
                    sw.Stop();
#endif
                    return(ds);
                }
                finally
                {
                    CloseConnection(connection);
                }
            }
        }