~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/webaccess/.svn/text-base/Pagging.ascx.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
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.
9
 
 |
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.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com
20
 
 |
21
 
 | Author: Rob
22
 
 |***************************************************************************/
23
 
 
24
 
using System;
25
 
using System.Data;
26
 
using System.Drawing;
27
 
using System.Web;
28
 
using System.Web.UI;
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;
34
 
 
35
 
namespace Novell.iFolderApp.Web
36
 
{
37
 
        /// <summary>
38
 
        ///     Pagging Control
39
 
        /// </summary>
40
 
        public class PaggingControl : UserControl
41
 
        {
42
 
                /// <summary>
43
 
                /// Pagging Start Index
44
 
                /// </summary>
45
 
                protected Literal StartIndex;
46
 
                
47
 
                /// <summary>
48
 
                /// Pagging End Index
49
 
                /// </summary>
50
 
                protected Literal EndIndex;
51
 
                
52
 
                /// <summary>
53
 
                /// Pagging Total
54
 
                /// </summary>
55
 
                protected Literal TotalLabel;
56
 
 
57
 
                /// <summary>
58
 
                /// Item Label Plural
59
 
                /// </summary>
60
 
                protected Literal ItemLabelPlural;
61
 
 
62
 
                /// <summary>
63
 
                /// Item Label Singular
64
 
                /// </summary>
65
 
                protected Literal ItemLabelSingular;
66
 
 
67
 
                /// <summary>
68
 
                /// Pagging First Image
69
 
                /// </summary>
70
 
                protected ImageButton FirstImage;
71
 
 
72
 
                /// <summary>
73
 
                /// Pagging First Image Disabled
74
 
                /// </summary>
75
 
                protected System.Web.UI.WebControls.Image FirstImageDisabled;
76
 
 
77
 
                /// <summary>
78
 
                /// Pagging Previous Image
79
 
                /// </summary>
80
 
                protected ImageButton PreviousImage;
81
 
 
82
 
                /// <summary>
83
 
                /// Pagging Previous Image Disabled
84
 
                /// </summary>
85
 
                protected System.Web.UI.WebControls.Image PreviousImageDisabled;
86
 
 
87
 
                /// <summary>
88
 
                /// Pagging Next Image
89
 
                /// </summary>
90
 
                protected ImageButton NextImage;
91
 
 
92
 
                /// <summary>
93
 
                /// Pagging Next Image Disabled
94
 
                /// </summary>
95
 
                protected System.Web.UI.WebControls.Image NextImageDisabled;
96
 
 
97
 
                /// <summary>
98
 
                /// Pagging Last Image
99
 
                /// </summary>
100
 
                protected ImageButton LastImage;
101
 
 
102
 
                /// <summary>
103
 
                /// Pagging Last Image Disabled
104
 
                /// </summary>
105
 
                protected System.Web.UI.WebControls.Image LastImageDisabled;
106
 
 
107
 
                /// <summary>
108
 
                /// Resource Manager
109
 
                /// </summary>
110
 
                private ResourceManager rm;
111
 
        
112
 
                /// <summary>
113
 
                /// Pagging Index
114
 
                /// </summary>
115
 
                private int index;
116
 
 
117
 
                /// <summary>
118
 
                /// Pagging Page Size
119
 
                /// </summary>
120
 
                private int page;
121
 
 
122
 
                /// <summary>
123
 
                /// Pagging Current Count
124
 
                /// </summary>
125
 
                private int count;
126
 
 
127
 
                /// <summary>
128
 
                /// Pagging Total
129
 
                /// </summary>
130
 
                private int total;
131
 
 
132
 
                #region Events
133
 
                
134
 
                /// <summary>
135
 
                /// On Page Change Event Handler
136
 
                /// </summary>
137
 
                public event EventHandler PageChange;
138
 
                
139
 
                #endregion
140
 
 
141
 
                /// <summary>
142
 
                /// Page Init
143
 
                /// </summary>
144
 
                /// <param name="sender"></param>
145
 
                /// <param name="e"></param>
146
 
                private void Page_Init(object sender, EventArgs e)
147
 
                {
148
 
                        index = 0;
149
 
 
150
 
                        // page size
151
 
                        try
152
 
                        {
153
 
                                page = (Session["Settings"] as WebSettings).PageSize;
154
 
                        }
155
 
                        catch
156
 
                        {
157
 
                                page = WebSettings.PageSizeDefault;
158
 
                        }
159
 
                }
160
 
 
161
 
                /// <summary>
162
 
                /// Page Load
163
 
                /// </summary>
164
 
                /// <param name="sender"></param>
165
 
                /// <param name="e"></param>
166
 
                private void Page_Load(object sender, System.EventArgs e)
167
 
                {
168
 
                        // localization
169
 
                        rm = (ResourceManager) Application["RM"];
170
 
                        
171
 
                        if (!IsPostBack)
172
 
                        {
173
 
                                // strings
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");
178
 
                        }
179
 
                        else
180
 
                        {
181
 
                                // read state
182
 
                                try
183
 
                                {
184
 
                                        total = int.Parse(TotalLabel.Text);
185
 
                                        index = (total > 0) ? int.Parse(StartIndex.Text) - 1 : 0;
186
 
                                        count = int.Parse(EndIndex.Text) - index;
187
 
                                }
188
 
                                catch
189
 
                                {
190
 
                                        // ignore parsing error
191
 
                                }
192
 
                        }
193
 
                }
194
 
 
195
 
                /// <summary>
196
 
                /// Get a Localized String
197
 
                /// </summary>
198
 
                /// <param name="key"></param>
199
 
                /// <returns></returns>
200
 
                protected string GetString(string key)
201
 
                {
202
 
                        return WebUtility.GetString(key, rm);
203
 
                }
204
 
 
205
 
                #region Public Methods
206
 
                #endregion
207
 
 
208
 
                #region Properties
209
 
 
210
 
                /// <summary>
211
 
                /// Index
212
 
                /// </summary>
213
 
                public int Index
214
 
                {
215
 
                        get { return index; }
216
 
                        set { index = value; }
217
 
                }
218
 
 
219
 
                /// <summary>
220
 
                /// Page Size
221
 
                /// </summary>
222
 
                public int PageSize
223
 
                {
224
 
                        get { return page; }
225
 
                }
226
 
 
227
 
                /// <summary>
228
 
                /// Count
229
 
                /// </summary>
230
 
                public int Count
231
 
                {
232
 
                        get { return count; }
233
 
                        set { count = value; }
234
 
                }
235
 
 
236
 
                /// <summary>
237
 
                /// Total
238
 
                /// </summary>
239
 
                public int Total
240
 
                {
241
 
                        get { return total; }
242
 
                        
243
 
                        set
244
 
                        {
245
 
                                total = value;
246
 
                        
247
 
                                // if the total is now smaller than the index
248
 
                                // move the index to the last page
249
 
                                if (total == 0)
250
 
                                {
251
 
                                        index = 0;
252
 
                                }
253
 
                                else if (index >= total)
254
 
                                {
255
 
                                        index = ((total - 1) / page) * page;
256
 
                                }
257
 
                        }
258
 
                }
259
 
 
260
 
                /// <summary>
261
 
                /// Plural Label
262
 
                /// </summary>
263
 
                public string LabelPlural
264
 
                {
265
 
                        get { return ItemLabelPlural.Text; }
266
 
                        set { ItemLabelPlural.Text = value; }
267
 
                }
268
 
 
269
 
                /// <summary>
270
 
                /// Singular Label
271
 
                /// </summary>
272
 
                public string LabelSingular
273
 
                {
274
 
                        get { return ItemLabelSingular.Text; }
275
 
                        set { ItemLabelSingular.Text = value; }
276
 
                }
277
 
 
278
 
                #endregion
279
 
 
280
 
                #region Web Form Designer
281
 
                
282
 
                /// <summary>
283
 
                /// On Intialize
284
 
                /// </summary>
285
 
                /// <param name="e"></param>
286
 
                override protected void OnInit(EventArgs e)
287
 
                {
288
 
                        InitializeComponent();
289
 
                        base.OnInit(e);
290
 
                }
291
 
                
292
 
                /// <summary>
293
 
                /// Initialize Components
294
 
                /// </summary>
295
 
                private void InitializeComponent()
296
 
                {
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);
304
 
                }
305
 
 
306
 
                #endregion
307
 
 
308
 
                /// <summary>
309
 
                /// First Image Click
310
 
                /// </summary>
311
 
                /// <param name="sender"></param>
312
 
                /// <param name="e"></param>
313
 
                private void FirstImage_Click(object sender, ImageClickEventArgs e)
314
 
                {
315
 
                        index = 0;
316
 
                        
317
 
                        PageChange(this, null);
318
 
                }
319
 
 
320
 
                /// <summary>
321
 
                /// Previous Image Click
322
 
                /// </summary>
323
 
                /// <param name="sender"></param>
324
 
                /// <param name="e"></param>
325
 
                private void PreviousImage_Click(object sender, ImageClickEventArgs e)
326
 
                {
327
 
                        index -= page;
328
 
                        
329
 
                        PageChange(this, null);
330
 
                }
331
 
 
332
 
                /// <summary>
333
 
                /// Next Image Click
334
 
                /// </summary>
335
 
                /// <param name="sender"></param>
336
 
                /// <param name="e"></param>
337
 
                private void NextImage_Click(object sender, ImageClickEventArgs e)
338
 
                {
339
 
                        index += page;
340
 
                        
341
 
                        PageChange(this, null);
342
 
                }
343
 
 
344
 
                /// <summary>
345
 
                /// Last Button Click
346
 
                /// </summary>
347
 
                /// <param name="sender"></param>
348
 
                /// <param name="e"></param>
349
 
                private void LastImage_Click(object sender, ImageClickEventArgs e)
350
 
                {
351
 
                        index = ((total - 1) / page) * page;
352
 
                        
353
 
                        PageChange(this, null);
354
 
                }
355
 
 
356
 
                /// <summary>
357
 
                /// Pre-Render
358
 
                /// </summary>
359
 
                /// <param name="sender"></param>
360
 
                /// <param name="e"></param>
361
 
                private void Pagging_PreRender(object sender, EventArgs e)
362
 
                {
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;
372
 
                }
373
 
        }
374
 
}