예제 #1
0
        public void Navigate(PageChanges change)
        {
            uint totalRecords;
            uint newPageSize;

            if (this.MyQuery == null || this.cmbPageSizes.ItemsSource == null)
            {
                return;
            }

            totalRecords = (uint)MyQuery.Count();
            newPageSize  = (uint)cmbPageSizes.SelectedItem;
            if (totalRecords == 0)
            {
                ItemsSource.Clear();
                TotalPages  = 1;
                Page        = 1;
                StartRecord = 0;
                EndRecord   = 0;
            }
            else
            {
                TotalPages = (totalRecords / newPageSize) + (uint)((totalRecords % newPageSize == 0) ? 0 : 1);
            }

            uint newPage = 1;

            switch (change)
            {
            case PageChanges.First:
                if (Page == 1)
                {
                    return;
                }
                break;

            case PageChanges.Previous:
                newPage = (Page - 1 > TotalPages) ? TotalPages : (Page - 1 < 1) ? 1 : Page - 1;
                break;

            case PageChanges.Current:
                newPage = (Page > TotalPages) ? TotalPages : (Page < 1) ? 1 : Page;
                break;

            case PageChanges.Next:
                newPage = (Page + 1 > TotalPages) ? TotalPages : Page + 1;
                //(Page + 1) < 1 ? 1 :
                break;

            case PageChanges.Last:
                if (Page == TotalPages)
                {
                    return;
                }
                newPage = TotalPages;
                break;

            default:
                break;
            }

            uint StartingIndex = (newPage - 1) * newPageSize;

            StartRecord = StartingIndex + 1;

            uint oldPage = Page;

            RaisePreviewPageChange(Page, newPage);

            Page         = newPage;
            TotalRecords = totalRecords;
            ItemsSource.Clear();

            IQueryable fetchData  = MyQuery.Skip(Convert.ToInt32(StartingIndex)).Take(Convert.ToInt32(newPageSize));
            var        enumerator = fetchData.GetEnumerator();

            while (enumerator.MoveNext())
            {
                ItemsSource.Add(enumerator.Current);
            }
            EndRecord = StartingIndex + Convert.ToUInt32(ItemsSource.Count);
            RaisePageChanged(oldPage, Page);
        }