source: cprs/branches/foia-cprs/CPRS-Chart/Options/fOptionsReportsDefault.pas@ 459

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

Adding foia-cprs branch

File size: 12.5 KB
Line 
1unit fOptionsReportsDefault;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls, ExtCtrls, Spin, fOptions, ComCtrls, ORFn, ORNet, ORCtrls,
8 ORDtTm, rCore;
9
10type
11 TfrmOptionsReportsDefault = class(TForm)
12 Label2: TLabel;
13 Label3: TLabel;
14 Label4: TLabel;
15 edtDefaultMax: TCaptionEdit;
16 Bevel1: TBevel;
17 Bevel2: TBevel;
18 Panel1: TPanel;
19 btnOK: TButton;
20 btnReset: TButton;
21 lblDefaultText: TMemo;
22 btnCancel: TButton;
23 odcDfStart: TORDateBox;
24 odcDfStop: TORDateBox;
25 procedure btnOKClick(Sender: TObject);
26 procedure btnCancelClick(Sender: TObject);
27 procedure btnResetClick(Sender: TObject);
28 procedure edtDefaultMaxExit(Sender: TObject);
29 procedure edtDefaultStartKeyPress(Sender: TObject; var Key: Char);
30 procedure edtDefaultEndKeyPress(Sender: TObject; var Key: Char);
31 procedure edtDefaultMaxKeyPress(Sender: TObject; var Key: Char);
32 procedure FormCreate(Sender: TObject);
33 procedure odcDfStartExit(Sender: TObject);
34 procedure odcDfStopExit(Sender: TObject);
35 procedure odcDfStartKeyPress(Sender: TObject; var Key: Char);
36 procedure odcDfStopKeyPress(Sender: TObject; var Key: Char);
37 procedure odcDfStartClick(Sender: TObject);
38 procedure odcDfStopClick(Sender: TObject);
39 procedure edtDefaultMaxClick(Sender: TObject);
40 private
41 { Private declarations }
42 startDate, endDate, maxOcurs: integer;
43 sDate,eDate: String;
44 public
45 { Public declarations }
46 procedure fillLabelText;
47
48 end;
49
50var
51 frmOptionsReportsDefault: TfrmOptionsReportsDefault;
52
53procedure DialogOptionsHSDefault(topvalue, leftvalue, fontsize: integer; var actiontype: Integer);
54
55implementation
56
57uses rOptions, uOptions, fReports, uCore;
58{$R *.DFM}
59
60procedure DialogOptionsHSDefault(topvalue, leftvalue, fontsize: integer; var actiontype: Integer);
61var
62 frmOptionsReportsDefault: TfrmOptionsReportsDefault;
63begin
64 frmOptionsReportsDefault := TfrmOptionsReportsDefault.Create(Application);
65 actiontype := 0;
66 try
67 with frmOptionsReportsDefault do
68 begin
69 if (topvalue < 0) or (leftvalue < 0) then
70 Position := poScreenCenter
71 else
72 begin
73 Position := poDesigned;
74 Top := topvalue;
75 Left := leftvalue;
76 end;
77 ResizeAnchoredFormToFont(frmOptionsReportsDefault);
78 ShowModal;
79 actiontype := btnOK.Tag;
80 end;
81 finally
82 frmOptionsReportsDefault.Release;
83 end;
84end;
85
86procedure TfrmOptionsReportsDefault.btnOKClick(Sender: TObject);
87var
88 valueStartdate, valueEnddate, valueMax, values: string;
89begin
90 if (odcDfStart.Text = sDate) and (odcDfStop.Text = eDate) and (not edtDefaultMax.Modified ) then
91 begin
92 Close;
93 Exit;
94 end;
95
96 if (odcDfStart.Text='') or (odcDfStop.Text='') or (edtDefaultMax.Text='') then
97 begin
98 InfoBox('You have to fill out each box, don''t leave blank!', 'Warning', MB_OK or MB_ICONWARNING);
99 Exit;
100 end;
101
102 valueStartdate := odcDfStart.RelativeTime;
103 valueEnddate := odcDfStop.RelativeTime;
104 valueMax := edtDefaultMax.Text;
105 values := valueStartdate + ';' + valueEnddate + ';' + valueMax;
106 if InfoBox('Do you really want to change all of the reports settings to the specified values as following?'
107 +#13#13' Start date: ' + odcDfStart.Text
108 +#13' End date: ' + odcDfStop.Text
109 +#13' Max occurences: ' + edtDefaultMax.Text
110 +#13#13' Click Yes, all of the CPRS reports except for health summary reports will have these same settings.',
111 'Confirmation', MB_YESNO or MB_ICONQUESTION) = IDYES then
112 begin
113 rpcSetDefaultReportsSetting(values);
114 rpcActiveDefaultSetting;
115 frmReports.LoadTreeView;
116 with frmReports.tvReports do
117 begin
118 if Items.Count > 0 then
119 Selected := Items.GetFirstNode;
120 frmReports.tvReportsClick(Selected);
121 end;
122 Close;
123 end
124 else
125 begin
126 odcDfStart.Text := sDate;
127 odcDfStop.Text := eDate;
128 edtDefaultMax.Text := IntToStr(maxOcurs);
129 end;
130end;
131
132
133procedure TfrmOptionsReportsDefault.btnCancelClick(Sender: TObject);
134begin
135 Close;
136end;
137
138procedure TfrmOptionsReportsDefault.btnResetClick(Sender: TObject);
139var
140 startD,endD,maxOc: integer;
141 values,msg,stdate,endate: string;
142 today: TFMDateTime;
143begin
144 rpcRetrieveDefaultSetting(startD,endD,maxOc,msg);
145 today := FMToday;
146 if msg = 'NODEFAULT' then
147 begin
148 InfoBox('No default report settings are available', 'Warning', MB_OK or MB_ICONWARNING);
149 Exit;
150 end;
151 //if (startD=startDate) and (endD=endDate) and (maxOc=maxOcurs) then
152 // Exit;
153 stdate := DateToStr(FMDateTimeToDateTime(FMDateTimeOffsetBy(today, startD)));
154 endate := DateToStr(FMDateTimeToDateTime(FMDateTimeOffsetBy(today, endD)));
155 if InfoBox('Do you really want to change all of the reports settings to the default values as following?'
156 +#13#13' Start date: ' + stdate
157 +#13' End date: ' + endate
158 +#13' Max occurences: ' + IntToStr(maxOc)
159 +#13#13' Click Yes, all of the CPRS reports except for health summary reports will have these same settings.',
160 'Confirmation', MB_YESNO or MB_ICONQUESTION) = IDYES then
161 begin
162 rpcDeleteUserLevelReportsSetting;
163 odcDfStart.Text := stdate;
164 odcDfStop.Text := endate;
165 edtDefaultMax.Text := inttostr(maxOc);
166 values := odcDfStart.RelativeTime + ';' + odcDfStop.RelativeTime + ';' + edtDefaultMax.Text;
167 rpcSetDefaultReportsSetting(values);
168 rpcActiveDefaultSetting;
169 sDate := odcDfStart.Text;
170 eDate := odcDfStop.Text;
171 startDate := startD;
172 endDate := endD;
173 maxOcurs := maxOc;
174 fillLabelText;
175 frmReports.LoadTreeView;
176 with frmReports.tvReports do
177 begin
178 if Items.Count > 0 then
179 Selected := Items.GetFirstNode;
180 frmReports.tvReportsClick(Selected);
181 end;
182 end;
183end;
184
185procedure TfrmOptionsReportsDefault.edtDefaultMaxExit(Sender: TObject);
186var
187 newValue: string;
188 I, code: integer;
189begin
190 if edtDefaultMax.Modified then
191 begin
192
193 newValue := edtDefaultMax.Text;
194 if length(newValue) = 0 then
195 begin
196 InfoBox('Invalid value of max occurences', 'Warning', MB_OK or MB_ICONWARNING);
197 edtDefaultMax.Text := '100';
198 end;
199 if length(newValue) > 0 then
200 begin
201 Val(newValue, I, code);
202 if code <> 0 then
203 begin
204 InfoBox('Invalid value of max occurences', 'Warning', MB_OK or MB_ICONWARNING);
205 edtDefaultMax.Text := inttostr(maxOcurs);
206 end;
207 if code = 0 then
208 if strtoint(edtDefaultMax.Text) <= 0 then
209 begin
210 InfoBox('Invalid value of max occurences', 'Warning', MB_OK or MB_ICONWARNING);
211 edtDefaultMax.Text := inttostr(maxOcurs);
212 end;
213 end;
214 fillLabelText;
215
216 end;
217end;
218
219procedure TfrmOptionsReportsDefault.fillLabelText;
220var
221 fromday,dayto: string;
222begin
223 fromday := DateToStr(FMDateTimeToDateTime(odcDfStart.FMDateTime));
224 dayto := DateToStr(FMDateTimeToDateTime(odcDfStop.FMDateTime));
225 lblDefaultText.Text := 'All of the CPRS reports except for Health Summary reports will be displayed on the CPRS Reports tab from start date: '
226 + fromday + ' to end date: ' + dayto + '.';
227end;
228
229procedure TfrmOptionsReportsDefault.edtDefaultStartKeyPress(Sender: TObject;
230 var Key: Char);
231begin
232 if Key = #13 then
233 begin
234 Perform(WM_NextDlgCtl, 0, 0);
235 exit;
236 end;
237end;
238
239procedure TfrmOptionsReportsDefault.edtDefaultEndKeyPress(Sender: TObject;
240 var Key: Char);
241begin
242 if Key = #13 then
243 begin
244 Perform(WM_NextDlgCtl, 0, 0);
245 exit;
246 end;
247end;
248
249procedure TfrmOptionsReportsDefault.edtDefaultMaxKeyPress(Sender: TObject;
250 var Key: Char);
251begin
252 if Key = #13 then
253 begin
254 Perform(WM_NextDlgCtl, 0, 0);
255 exit;
256 end;
257end;
258
259procedure TfrmOptionsReportsDefault.FormCreate(Sender: TObject);
260var
261 today : TFMDateTime;
262begin
263 today := FMToday;
264 rpcGetDefaultReportsSetting(startDate,endDate,maxOcurs);
265 odcDfStart.text := DateToStr(FMDateTimeToDateTime(FMDateTimeOffsetBy(today, startDate)));
266 sDate := odcDfStart.Text;
267 odcDfStop.text := DateToStr(FMDateTimeToDateTime(FMDateTimeOffsetBy(today, endDate)));
268 eDate := odcDfStop.Text;
269 if maxOcurs <> 0 then
270 begin
271 edtDefaultMax.Text := inttostr(maxOcurs);
272 fillLabelText;
273 end;
274 lblDefaultText.Text := 'Click dots in boxes to set start and end dates. You can also input values directly.';
275 btnCancel.caption := 'Cancel';
276 if (not User.ToolsRptEdit) then // For users with Reports settings edit parameter not set.
277 begin
278 lblDefaultText.Text := 'Settings can only be viewed (no editing provided).';
279 btnReset.visible := false;
280 btnOK.visible := false;
281 btnCancel.caption := 'Close';
282 odcDfStart.readOnly := true;
283 odcDfStart.enabled := false;
284 odcDfStart.onExit := nil;
285 odcDfStart.onKeyPress := nil;
286 odcDfStop.readOnly := true;
287 odcDfStop.enabled := false;
288 odcDfStop.onExit := nil;
289 odcDfStop.onKeyPress := nil;
290 edtDefaultMax.readOnly := true;
291 end;
292end;
293
294procedure TfrmOptionsReportsDefault.odcDfStartExit(Sender: TObject);
295const
296 TX_BAD_START = 'The start date is not valid.';
297 TX_STOPSTART = 'The start date must not be after the stop date.';
298
299var
300 x,ErrMsg,datestart,datestop: String;
301begin
302 if odcDfStart.text = '' then
303 begin
304 InfoBox(TX_BAD_START, 'Warning', MB_OK or MB_ICONWARNING);
305 odcDfStart.Text := sDate;
306 odcDfStart.Setfocus;
307 odcDfStart.SelectAll;
308 exit;
309 end;
310
311 ErrMsg := '';
312 odcDfStart.Validate(x);
313 if Length(x) > 0 then
314 begin
315 ErrMsg := TX_BAD_START;
316 InfoBox(TX_BAD_START, 'Warning', MB_OK or MB_ICONWARNING);
317 odcDfStart.Text := sDate;
318 odcDfStart.Setfocus;
319 odcDfStart.SelectAll;
320 exit;
321 end;
322 datestart := odcDfStart.RelativeTime;
323 datestop := odcDfStop.RelativeTime;
324 delete(datestart,1,1);
325 delete(datestop,1,1);
326 if StrToIntDef(datestop,0) < StrToIntDef(datestart,0) then
327 begin
328 InfoBox(TX_STOPSTART, 'Warning', MB_OK or MB_ICONWARNING);
329 odcDfStart.Text := odcDfStop.Text;
330 odcDfStart.SetFocus;
331 odcDfStart.SelectAll;
332 exit;
333 end;
334 odcDfStart.Text := DateToStr(FMDateTimeToDateTime(odcDfStart.FMDateTime));
335 fillLabelText;
336end;
337
338procedure TfrmOptionsReportsDefault.odcDfStopExit(Sender: TObject);
339const
340 TX_BAD_STOP = 'The stop date is not valid.';
341 TX_BAD_ORDER = 'The stop date must not be earlier than start date.';
342var
343 x, ErrMsg,datestart,datestop: string;
344begin
345 if odcDfStop.text = '' then
346 begin
347 InfoBox(TX_BAD_STOP, 'Warning', MB_OK or MB_ICONWARNING);
348 odcDfStop.Text := eDate;
349 odcDfStop.Setfocus;
350 odcDfStop.SelectAll;
351 exit;
352 end;
353
354 ErrMsg := '';
355 odcDfStop.Validate(x);
356 if Length(x) > 0 then
357 begin
358 ErrMsg := TX_BAD_STOP;
359 InfoBox(TX_BAD_STOP, 'Warning', MB_OK or MB_ICONWARNING);
360 odcDfStop.Visible := True;
361 odcDfStop.Text := eDate;
362 odcDfStop.Setfocus;
363 odcDfStop.SelectAll;
364 exit;
365 end;
366 datestart := odcDfStart.RelativeTime;
367 datestop := odcDfStop.RelativeTime;
368 delete(datestart,1,1);
369 delete(datestop,1,1);
370 if StrToIntDef(datestop,0) < StrToIntDef(datestart,0) then
371 begin
372 InfoBox(TX_BAD_ORDER, 'Warning', MB_OK or MB_ICONWARNING);
373 odcDfStop.Text := odcDfStart.Text;
374 odcDfStop.SetFocus;
375 odcDfStop.SelectAll;
376 exit;
377 end;
378 odcDfStop.Text := DateToStr(FMDateTimeToDateTime(odcDfStop.FMDateTime));
379 fillLabelText;
380end;
381
382
383procedure TfrmOptionsReportsDefault.odcDfStartKeyPress(Sender: TObject;
384 var Key: Char);
385begin
386 if Key = #13 then
387 begin
388 Perform(WM_NextDlgCtl, 0, 0);
389 exit;
390 end;
391 if Key = #27 then //Escape
392 begin
393 Key := #0;
394 btnCancel.Click;
395 end;
396end;
397
398procedure TfrmOptionsReportsDefault.odcDfStopKeyPress(Sender: TObject;
399 var Key: Char);
400begin
401 if Key = #13 then
402 begin
403 Perform(WM_NextDlgCtl, 0, 0);
404 exit;
405 end;
406 if Key = #27 then //Escape
407 begin
408 Key := #0;
409 btnCancel.Click;
410 end;
411end;
412
413procedure TfrmOptionsReportsDefault.odcDfStartClick(Sender: TObject);
414begin
415 odcDfStart.SelectAll;
416end;
417
418procedure TfrmOptionsReportsDefault.odcDfStopClick(Sender: TObject);
419begin
420 odcDfStop.SelectAll;
421end;
422
423procedure TfrmOptionsReportsDefault.edtDefaultMaxClick(Sender: TObject);
424begin
425 edtDefaultMax.SelectAll;
426end;
427
428end.
Note: See TracBrowser for help on using the repository browser.