source: cprs/branches/tmg-cprs/CPRS-Chart/Options/fOptionsReminders.pas@ 1727

Last change on this file since 1727 was 453, checked in by Kevin Toppenberg, 16 years ago

Initial upload of TMG-CPRS 1.0.26.69

File size: 7.4 KB
Line 
1//kt -- Modified with SourceScanner on 8/8/2007
2unit fOptionsReminders;
3
4interface
5
6uses
7 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
8 StdCtrls, ExtCtrls, ORCtrls, OrFn, DKLang;
9
10type
11 TfrmOptionsReminders = class(TForm)
12 pnlBottom: TPanel;
13 btnOK: TButton;
14 btnCancel: TButton;
15 lstDisplayed: TORListBox;
16 lstNotDisplayed: TORListBox;
17 btnUp: TButton;
18 btnDown: TButton;
19 btnDelete: TButton;
20 btnAdd: TButton;
21 lblDisplayed: TLabel;
22 lblNotDisplayed: TLabel;
23 bvlBottom: TBevel;
24 radSort: TRadioGroup;
25 DKLanguageController1: TDKLanguageController;
26 procedure FormCreate(Sender: TObject);
27 procedure lstDisplayedChange(Sender: TObject);
28 procedure lstNotDisplayedChange(Sender: TObject);
29 procedure btnUpClick(Sender: TObject);
30 procedure btnDownClick(Sender: TObject);
31 procedure btnDeleteClick(Sender: TObject);
32 procedure btnAddClick(Sender: TObject);
33 function GetFirstSelection(aList: TORListBox): integer;
34 procedure SetItem(aList: TORListBox; index: integer);
35 procedure MoveSelected(aList: TORListBox; items: TStrings);
36 procedure btnOKClick(Sender: TObject);
37 procedure radSortClick(Sender: TObject);
38 private
39 { Private declarations }
40 procedure CheckEnable;
41 public
42 { Public declarations }
43 end;
44
45var
46 frmOptionsReminders: TfrmOptionsReminders;
47
48procedure DialogOptionsReminders(topvalue, leftvalue, fontsize: integer; var actiontype: Integer);
49
50implementation
51
52uses rOptions, fRemCoverSheet, rReminders;
53
54{$R *.DFM}
55
56procedure DialogOptionsReminders(topvalue, leftvalue, fontsize: integer; var actiontype: Integer);
57// create the form and make it modal, return an action
58var
59 frmOptionsReminders: TfrmOptionsReminders;
60begin
61 if NewRemCoverSheetListActive then
62 EditCoverSheetReminderList(TRUE)
63 else
64 begin
65 frmOptionsReminders := TfrmOptionsReminders.Create(Application);
66 actiontype := 0;
67 try
68 with frmOptionsReminders do
69 begin
70 if (topvalue < 0) or (leftvalue < 0) then
71 Position := poScreenCenter
72 else
73 begin
74 Position := poDesigned;
75 Top := topvalue;
76 Left := leftvalue;
77 end;
78 ResizeAnchoredFormToFont(frmOptionsReminders);
79 ShowModal;
80 actiontype := btnOK.Tag;
81 end;
82 finally
83 frmOptionsReminders.Release;
84 end;
85 end;
86end;
87
88procedure TfrmOptionsReminders.FormCreate(Sender: TObject);
89var
90 i: integer;
91 biglist, userlist: TStringList;
92begin
93 biglist := TStringList.Create;
94 userlist := TStringList.Create;
95 try
96 rpcGetReminders(biglist);
97 for i := 0 to biglist.Count - 1 do
98 if strtointdef(Piece(biglist[i], '^', 2), 0) > 0 then
99 userlist.Add(biglist[i])
100 else
101 lstNotDisplayed.Items.Add(biglist[i]);
102 SortByPiece(userlist, '^', 2);
103 for i := 0 to userlist.Count - 1 do
104 lstDisplayed.Items.Add(userlist[i]);
105 finally
106 biglist.free;
107 userlist.free;
108 end;
109 CheckEnable;
110end;
111
112procedure TfrmOptionsReminders.CheckEnable;
113// allow buttons to be enabled or not depending on selections
114begin
115 with lstDisplayed do
116 begin
117 if Items.Count > 0 then
118 begin
119 if SelCount > 0 then
120 begin
121 btnUp.Enabled := (SelCount > 0)
122 and (not Selected[0])
123 and (radSort.ItemIndex = 0);
124 btnDown.Enabled := (SelCount > 0)
125 and (not Selected[Items.Count - 1])
126 and (radSort.ItemIndex = 0);
127 btnDelete.Enabled := true;
128 end
129 else
130 begin
131 btnUp.Enabled := false;
132 btnDown.Enabled := false;
133 btnDelete.Enabled := false;
134 end;
135 end
136 else
137 begin
138 btnUp.Enabled := false;
139 btnDown.Enabled := false;
140 btnDelete.Enabled := false;
141 end;
142 end;
143 with lstNotDisplayed do
144 begin
145 btnAdd.Enabled := SelCount > 0;
146 end;
147end;
148
149procedure TfrmOptionsReminders.lstDisplayedChange(Sender: TObject);
150begin
151 CheckEnable;
152end;
153
154procedure TfrmOptionsReminders.lstNotDisplayedChange(Sender: TObject);
155begin
156 CheckEnable;
157end;
158
159procedure TfrmOptionsReminders.btnUpClick(Sender: TObject);
160var
161 newindex, i: integer;
162begin
163 with lstDisplayed do
164 begin
165 i := 0;
166 while i < Items.Count do
167 begin
168 if Selected[i] then
169 begin
170 newindex := i - 1;
171 Items.Move(i, newindex);
172 Selected[newindex] := true;
173 end;
174 inc(i);
175 end;
176 end;
177 lstDisplayedChange(self);
178end;
179
180procedure TfrmOptionsReminders.btnDownClick(Sender: TObject);
181var
182 newindex, i: integer;
183begin
184 with lstDisplayed do
185 begin
186 i := Items.Count - 1;
187 while i > -1 do
188 begin
189 if Selected[i] then
190 begin
191 newindex := i + 1;
192 Items.Move(i, newindex);
193 Selected[newindex] := true;
194 end;
195 dec(i);
196 end;
197 end;
198 lstDisplayedChange(self);
199end;
200
201procedure TfrmOptionsReminders.btnDeleteClick(Sender: TObject);
202var
203 index: integer;
204begin
205 index := GetFirstSelection(lstDisplayed);
206 MoveSelected(lstDisplayed, lstNotDisplayed.Items);
207 SetItem(lstDisplayed, index);
208 CheckEnable;
209end;
210
211procedure TfrmOptionsReminders.btnAddClick(Sender: TObject);
212var
213 index: integer;
214begin
215 index := GetFirstSelection(lstNotDisplayed);
216 MoveSelected(lstNotDisplayed, lstDisplayed.Items);
217 SetItem(lstNotDisplayed, index);
218 if radSort.ItemIndex = 1 then radSortClick(self);
219 CheckEnable;
220end;
221
222function TfrmOptionsReminders.GetFirstSelection(aList: TORListBox): integer;
223begin
224 for result := 0 to aList.Items.Count - 1 do
225 if aList.Selected[result] then exit;
226 result := LB_ERR;
227end;
228
229procedure TfrmOptionsReminders.SetItem(aList: TORListBox; index: integer);
230var
231 maxindex: integer;
232begin
233 with aList do
234 begin
235 SetFocus;
236 maxindex := aList.Items.Count - 1;
237 if Index = LB_ERR then
238 Index := 0
239 else if Index > maxindex then Index := maxindex;
240 Selected[index] := true;
241 end;
242 CheckEnable;
243end;
244
245procedure TfrmOptionsReminders.MoveSelected(aList: TORListBox; Items: TStrings);
246var
247 i: integer;
248begin
249 for i := aList.Items.Count - 1 downto 0 do
250 begin
251 if aList.Selected[i] then
252 begin
253 Items.AddObject(aList.Items[i], aList.Items.Objects[i]);
254 aList.Items.Delete(i);
255 end;
256 end;
257end;
258
259procedure TfrmOptionsReminders.btnOKClick(Sender: TObject);
260var
261 i: integer;
262 values: string;
263 aList: TStringList;
264begin
265 aList := TStringList.Create;
266 try
267 with lstDisplayed do
268 for i := 0 to Items.Count - 1 do
269 begin
270 values := inttostr(i + 1) + '^' + Piece(Items[i], '^', 1);
271 aList.Add(values);
272 end;
273 rpcSetReminders(aList);
274 finally
275 aList.free;
276 end;
277end;
278
279procedure TfrmOptionsReminders.radSortClick(Sender: TObject);
280var
281 i: integer;
282 userlist: TStringList;
283begin
284 userlist := TStringList.Create;
285 try
286 for i := 0 to lstDisplayed.Items.Count - 1 do
287 userlist.Add(lstDisplayed.Items[i]);
288 case radSort.ItemIndex of
289 0: SortByPiece(userlist, '^', 2);
290 else SortByPiece(userlist, '^', 3);
291 end;
292 lstDisplayed.Items.Clear;
293 for i := 0 to userlist.Count - 1 do
294 lstDisplayed.Items.Add(userlist[i]);
295 finally
296 userlist.free;
297 end;
298 CheckEnable;
299end;
300
301end.
Note: See TracBrowser for help on using the repository browser.