1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
//------------------------------------------------------------------------------
// <copyright file="ItemPager.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;
namespace System.Web.UI.MobileControls
{
/*
* Item pager, a class that provides state as items of a control are paginated.
*
* Copyright (c) 2000 Microsoft Corporation
*/
/// <include file='doc\ItemPager.uex' path='docs/doc[@for="ItemPager"]/*' />
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
public class ItemPager
{
private MobileControl _control;
private int _firstPageItemCount;
private int _fullPageItemCount;
private int _lastPageItemCount;
private int _firstPage;
private int _lastPage;
/// <include file='doc\ItemPager.uex' path='docs/doc[@for="ItemPager.ItemPager"]/*' />
public ItemPager()
{
}
/// <include file='doc\ItemPager.uex' path='docs/doc[@for="ItemPager.ItemPager1"]/*' />
public ItemPager(ControlPager pager, MobileControl control, int itemCount, int itemsPerPage, int itemWeight)
{
_control = control;
if (itemsPerPage > 0)
{
// User-specified pagination behavior, always given
// number of items per page.
if (itemCount < itemsPerPage)
{
_firstPageItemCount = itemCount;
_firstPage = _lastPage = pager.GetPage(itemCount * itemWeight);
}
else
{
int numberOfPages = (itemCount - 1) / itemsPerPage + 1;
_firstPageItemCount = itemsPerPage;
_fullPageItemCount = itemsPerPage;
_lastPageItemCount = itemCount - (numberOfPages - 1) * itemsPerPage;
_firstPage = pager.GetPage(itemsPerPage * itemWeight);
pager.PageCount += numberOfPages - 1;
if (numberOfPages > 1)
{
pager.RemainingWeight = Math.Max(0, pager.PageWeight - _lastPageItemCount * itemWeight);
}
_lastPage = _firstPage + numberOfPages - 1;
}
}
else
{
int totalItemWeight = itemCount * itemWeight;
if (totalItemWeight <= pager.RemainingWeight)
{
_firstPageItemCount = itemCount;
_firstPage = _lastPage = pager.GetPage(totalItemWeight);
}
else
{
_firstPageItemCount = pager.RemainingWeight / itemWeight;
int remainingItemCount = itemCount - _firstPageItemCount;
_fullPageItemCount = Math.Max(1, pager.PageWeight / itemWeight);
int fullPageCount = remainingItemCount / _fullPageItemCount;
_lastPageItemCount = remainingItemCount % _fullPageItemCount;
_firstPage = pager.PageCount;
// increment for first page
pager.PageCount++;
pager.RemainingWeight = pager.PageWeight;
// increment for full pages
pager.PageCount += fullPageCount;
// remove remaining weight for last page
pager.RemainingWeight -= _lastPageItemCount * itemWeight;
// correct if first page is empty
if (_firstPageItemCount == 0)
{
_firstPage++;
_firstPageItemCount = Math.Min(_fullPageItemCount, itemCount);
}
// correct if last page is empty
if (_lastPageItemCount == 0)
{
pager.PageCount--;
_lastPageItemCount = Math.Min(_fullPageItemCount, itemCount);
pager.RemainingWeight = 0;
}
_lastPage = pager.PageCount;
}
}
_control.FirstPage = _firstPage;
_control.LastPage = _lastPage;
}
/// <include file='doc\ItemPager.uex' path='docs/doc[@for="ItemPager.ItemIndex"]/*' />
public int ItemIndex
{
get
{
int page = _control.Form.CurrentPage;
if (page < _firstPage || page > _lastPage)
{
return -1;
}
if (page == _firstPage)
{
return 0;
}
else
{
int fullPageCount = (page - _firstPage) - 1;
return fullPageCount * _fullPageItemCount + _firstPageItemCount;
}
}
}
/// <include file='doc\ItemPager.uex' path='docs/doc[@for="ItemPager.ItemCount"]/*' />
public int ItemCount
{
get
{
int page = _control.Form.CurrentPage;
if (page < _firstPage || page > _lastPage)
{
return -1;
}
if (page == _firstPage)
{
return _firstPageItemCount;
}
else if (page == _lastPage)
{
return _lastPageItemCount;
}
else
{
return _fullPageItemCount;
}
}
}
}
}
|