コード例 #1
0
        public void ReLoad()
        {
            uint totalRecords;
            uint newPageSize;

            totalRecords = PageContract.GetTotalCount();
            if ((cmbPageSizes != null) && (cmbPageSizes.SelectedItem != null))
            {
                newPageSize = (uint)cmbPageSizes.SelectedItem;
            }
            else
            {
                newPageSize = 10;
            }

            if (totalRecords == 0)
            {
                ItemsSource.Clear();
                TotalPages = 1;
                Page       = 1;
            }
            else
            {
                TotalPages = (totalRecords / newPageSize) + (uint)((totalRecords % newPageSize == 0) ? 0 : 1);
            }

            uint newPage = 1;

            uint StartingIndex = (newPage - 1) * newPageSize;

            uint oldPage = Page;

            RaisePreviewPageChange(Page, newPage);

            Page = newPage;
            ItemsSource.Clear();

            ICollection <object> fetchData = PageContract.GetRecordsBy(StartingIndex, newPageSize, FilterTag);

            // ItemsSource.Clear();
            foreach (object row in fetchData)
            {
                ItemsSource.Add(row);
            }
            RaisePageChanged(oldPage, Page);
        }
コード例 #2
0
        private void Navigate(PageChanges change)
        {
            uint totalRecords;
            uint newPageSize;

            if (PageContract == null)
            {
                return;
            }

            totalRecords = PageContract.GetTotalCount();
            newPageSize  = (uint)cmbPageSizes.SelectedItem;

            if (totalRecords == 0)
            {
                ItemsSource.Clear();
                TotalPages = 1;
                Page       = 1;
            }
            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;

            uint oldPage = Page;

            RaisePreviewPageChange(Page, newPage);

            Page = newPage;
            ItemsSource.Clear();

            ICollection <object> fetchData = PageContract.GetRecordsBy(StartingIndex, newPageSize, FilterTag);

            foreach (object row in fetchData)
            {
                ItemsSource.Add(row);
            }

            RaisePageChanged(oldPage, Page);
        }