source: branches/DirectWeb/UHTMLControls.pas

Last change on this file was 91, checked in by george, 15 years ago
  • Upraveno: Třída TWebServer oddělena do samostatné jednotky.
File size: 2.8 KB
Line 
1unit UHTMLControls;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, UHTTPServer;
9
10type
11
12 { TPageList }
13
14 TPageList = class
15 NavigatorVisibleItems: Integer;
16 PageIndexName: string;
17 Page: Integer;
18 TotalCount: Integer;
19 ItemPerPage: Integer;
20 Output: string;
21 HandlerData: THTTPHandlerData;
22 function SQLLimit: string;
23 procedure Process;
24 constructor Create;
25 destructor Destroy; override;
26 end;
27
28implementation
29
30{ TPageList }
31
32function TPageList.SQLLimit: string;
33begin
34 Result := ' LIMIT ' + IntToStr(Page * ItemPerPage) + ', ' + IntToStr(ItemPerPage);
35end;
36
37procedure TPageList.Process;
38var
39 Count: Integer;
40 PagesMax: Integer;
41 PagesMin: Integer;
42 I: Integer;
43begin
44 if Assigned(HandlerData) and
45 (HandlerData.Session.IndexOfName(PageIndexName) <> -1) then
46 Page := StrToInt(HandlerData.Session.Values[PageIndexName])
47 else Page := 0;
48 if HandlerData.Request.Query.IndexOfName(PageIndexName) <> -1 then
49 Page := StrToInt(HandlerData.Request.Query.Values[PageIndexName]);
50
51 Count := Trunc(TotalCount / ItemPerPage) + 1;
52 if Page > Count - 1 then Page := Count - 1;
53
54 Output := '';
55 if Count > 1 then
56 with HandlerData, Request do begin
57
58 if Page > 0 then begin
59 Query.Values[PageIndexName] := IntToStr(0);
60 Output := Output + '<a href="?' + Query.Syntetize + '">&lt;&lt;</a>';
61 Query.Values[PageIndexName] := IntToStr(Page - 1);
62 Output := Output + ' <a href="?' + Query.Syntetize + '">&lt;</a>';
63 end;
64
65 // Get navigator visible range
66 PagesMin := Page - (NavigatorVisibleItems - 1) div 2;
67 if PagesMin < 0 then PagesMin := 0;
68 PagesMax := PagesMin + (NavigatorVisibleItems - 1);
69 if PagesMax > Count - 1 then PagesMax := Count - 1;
70
71 if PagesMin > 0 then Output := Output + ' .. ';
72 // Show page numbers
73 for I := PagesMin to PagesMax do begin
74 Query.Values[PageIndexName] := IntToStr(I);
75 if I = Page then begin
76 Output := Output + ' <strong>' + IntToStr(I + 1) + '</strong>'
77 end else begin
78 Output := Output + ' <a href="?' + Query.Syntetize + '">' +
79 IntToStr(I + 1) + '</a>';
80 end;
81 end;
82 if PagesMax < (Count - 1) then Output := Output + ' .. ';
83
84 if Page < (Count - 1) then begin
85 Query.Values[PageIndexName] := IntToStr(Page + 1);
86 Output := Output + ' <a href="?' + Query.Syntetize + '">&gt;</a>';
87 Query.Values[PageIndexName] := IntToStr(Count - 1);
88 Output := Output + ' <a href="?' + Query.Syntetize + '">&gt;&gt;</a>';
89 end;
90 end;
91
92 HandlerData.Session.Values[PageIndexName] := IntToStr(Page);
93end;
94
95constructor TPageList.Create;
96begin
97 PageIndexName := 'Page';
98 ItemPerPage := 40;
99 NavigatorVisibleItems := 30;
100end;
101
102destructor TPageList.Destroy;
103begin
104 inherited Destroy;
105end;
106
107end.
108
Note: See TracBrowser for help on using the repository browser.