1
/****************************************************************************
3
| Copyright (c) 2007 Novell, Inc.
6
| This program is free software; you can redistribute it and/or
7
| modify it under the terms of version 2 of the GNU General Public License as
8
| published by the Free Software Foundation.
10
| This program is distributed in the hope that it will be useful,
11
| but WITHOUT ANY WARRANTY; without even the implied warranty of
12
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
| GNU General Public License for more details.
15
| You should have received a copy of the GNU General Public License
16
| along with this program; if not, contact Novell, Inc.
18
| To contact Novell about this file by physical or electronic mail,
19
| you may find current contact information at www.novell.com
22
|***************************************************************************/
29
using System.Web.UI.WebControls;
30
using System.Web.UI.HtmlControls;
31
using System.Web.Security;
32
using System.Threading;
33
using System.Resources;
35
namespace Novell.iFolderApp.Web
40
public class PaggingControl : UserControl
43
/// Pagging Start Index
45
protected Literal StartIndex;
50
protected Literal EndIndex;
55
protected Literal TotalLabel;
60
protected Literal ItemLabelPlural;
63
/// Item Label Singular
65
protected Literal ItemLabelSingular;
68
/// Pagging First Image
70
protected ImageButton FirstImage;
73
/// Pagging First Image Disabled
75
protected System.Web.UI.WebControls.Image FirstImageDisabled;
78
/// Pagging Previous Image
80
protected ImageButton PreviousImage;
83
/// Pagging Previous Image Disabled
85
protected System.Web.UI.WebControls.Image PreviousImageDisabled;
88
/// Pagging Next Image
90
protected ImageButton NextImage;
93
/// Pagging Next Image Disabled
95
protected System.Web.UI.WebControls.Image NextImageDisabled;
98
/// Pagging Last Image
100
protected ImageButton LastImage;
103
/// Pagging Last Image Disabled
105
protected System.Web.UI.WebControls.Image LastImageDisabled;
110
private ResourceManager rm;
118
/// Pagging Page Size
123
/// Pagging Current Count
135
/// On Page Change Event Handler
137
public event EventHandler PageChange;
144
/// <param name="sender"></param>
145
/// <param name="e"></param>
146
private void Page_Init(object sender, EventArgs e)
153
page = (Session["Settings"] as WebSettings).PageSize;
157
page = WebSettings.PageSizeDefault;
164
/// <param name="sender"></param>
165
/// <param name="e"></param>
166
private void Page_Load(object sender, System.EventArgs e)
169
rm = (ResourceManager) Application["RM"];
174
FirstImage.ToolTip = FirstImageDisabled.ToolTip = GetString("FIRST");
175
PreviousImage.ToolTip = PreviousImageDisabled.ToolTip = GetString("PREVIOUS");
176
NextImage.ToolTip = NextImageDisabled.ToolTip = GetString("NEXT");
177
LastImage.ToolTip = LastImageDisabled.ToolTip = GetString("LAST");
184
total = int.Parse(TotalLabel.Text);
185
index = (total > 0) ? int.Parse(StartIndex.Text) - 1 : 0;
186
count = int.Parse(EndIndex.Text) - index;
190
// ignore parsing error
196
/// Get a Localized String
198
/// <param name="key"></param>
199
/// <returns></returns>
200
protected string GetString(string key)
202
return WebUtility.GetString(key, rm);
205
#region Public Methods
215
get { return index; }
216
set { index = value; }
232
get { return count; }
233
set { count = value; }
241
get { return total; }
247
// if the total is now smaller than the index
248
// move the index to the last page
253
else if (index >= total)
255
index = ((total - 1) / page) * page;
263
public string LabelPlural
265
get { return ItemLabelPlural.Text; }
266
set { ItemLabelPlural.Text = value; }
272
public string LabelSingular
274
get { return ItemLabelSingular.Text; }
275
set { ItemLabelSingular.Text = value; }
280
#region Web Form Designer
285
/// <param name="e"></param>
286
override protected void OnInit(EventArgs e)
288
InitializeComponent();
293
/// Initialize Components
295
private void InitializeComponent()
297
this.Init += new EventHandler(Page_Init);
298
this.Load += new EventHandler(Page_Load);
299
this.FirstImage.Click += new ImageClickEventHandler(FirstImage_Click);
300
this.PreviousImage.Click += new ImageClickEventHandler(PreviousImage_Click);
301
this.NextImage.Click += new ImageClickEventHandler(NextImage_Click);
302
this.LastImage.Click += new ImageClickEventHandler(LastImage_Click);
303
this.PreRender += new EventHandler(Pagging_PreRender);
309
/// First Image Click
311
/// <param name="sender"></param>
312
/// <param name="e"></param>
313
private void FirstImage_Click(object sender, ImageClickEventArgs e)
317
PageChange(this, null);
321
/// Previous Image Click
323
/// <param name="sender"></param>
324
/// <param name="e"></param>
325
private void PreviousImage_Click(object sender, ImageClickEventArgs e)
329
PageChange(this, null);
335
/// <param name="sender"></param>
336
/// <param name="e"></param>
337
private void NextImage_Click(object sender, ImageClickEventArgs e)
341
PageChange(this, null);
345
/// Last Button Click
347
/// <param name="sender"></param>
348
/// <param name="e"></param>
349
private void LastImage_Click(object sender, ImageClickEventArgs e)
351
index = ((total - 1) / page) * page;
353
PageChange(this, null);
359
/// <param name="sender"></param>
360
/// <param name="e"></param>
361
private void Pagging_PreRender(object sender, EventArgs e)
363
StartIndex.Text = (total > 0) ? (index + 1).ToString() : "0";
364
EndIndex.Text = (index + count).ToString();
365
TotalLabel.Text = total.ToString();
366
FirstImage.Visible = PreviousImage.Visible = (index > 0);
367
FirstImageDisabled.Visible = PreviousImageDisabled.Visible = !FirstImage.Visible;
368
NextImage.Visible = LastImage.Visible = ((index + count) < total);
369
NextImageDisabled.Visible = LastImageDisabled.Visible = !NextImage.Visible;
370
ItemLabelSingular.Visible = (total == 1);
371
ItemLabelPlural.Visible = !ItemLabelSingular.Visible;