source: cprs/branches/foia-cprs/CPRS-Chart/Options/fOptionsReminders.pas@ 1328

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

Adding foia-cprs branch

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