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

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

Uploading from OR_30_258

File size: 12.5 KB
RevLine 
[459]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);
[460]202 if I = 0 then begin end; //added to keep compiler from generating a hint
[459]203 if code <> 0 then
204 begin
205 InfoBox('Invalid value of max occurences', 'Warning', MB_OK or MB_ICONWARNING);
206 edtDefaultMax.Text := inttostr(maxOcurs);
207 end;
208 if code = 0 then
209 if strtoint(edtDefaultMax.Text) <= 0 then
210 begin
211 InfoBox('Invalid value of max occurences', 'Warning', MB_OK or MB_ICONWARNING);
212 edtDefaultMax.Text := inttostr(maxOcurs);
213 end;
214 end;
215 fillLabelText;
216
217 end;
218end;
219
220procedure TfrmOptionsReportsDefault.fillLabelText;
221var
222 fromday,dayto: string;
223begin
224 fromday := DateToStr(FMDateTimeToDateTime(odcDfStart.FMDateTime));
225 dayto := DateToStr(FMDateTimeToDateTime(odcDfStop.FMDateTime));
226 lblDefaultText.Text := 'All of the CPRS reports except for Health Summary reports will be displayed on the CPRS Reports tab from start date: '
227 + fromday + ' to end date: ' + dayto + '.';
228end;
229
230procedure TfrmOptionsReportsDefault.edtDefaultStartKeyPress(Sender: TObject;
231 var Key: Char);
232begin
233 if Key = #13 then
234 begin
235 Perform(WM_NextDlgCtl, 0, 0);
236 exit;
237 end;
238end;
239
240procedure TfrmOptionsReportsDefault.edtDefaultEndKeyPress(Sender: TObject;
241 var Key: Char);
242begin
243 if Key = #13 then
244 begin
245 Perform(WM_NextDlgCtl, 0, 0);
246 exit;
247 end;
248end;
249
250procedure TfrmOptionsReportsDefault.edtDefaultMaxKeyPress(Sender: TObject;
251 var Key: Char);
252begin
253 if Key = #13 then
254 begin
255 Perform(WM_NextDlgCtl, 0, 0);
256 exit;
257 end;
258end;
259
260procedure TfrmOptionsReportsDefault.FormCreate(Sender: TObject);
261var
262 today : TFMDateTime;
263begin
264 today := FMToday;
265 rpcGetDefaultReportsSetting(startDate,endDate,maxOcurs);
266 odcDfStart.text := DateToStr(FMDateTimeToDateTime(FMDateTimeOffsetBy(today, startDate)));
267 sDate := odcDfStart.Text;
268 odcDfStop.text := DateToStr(FMDateTimeToDateTime(FMDateTimeOffsetBy(today, endDate)));
269 eDate := odcDfStop.Text;
270 if maxOcurs <> 0 then
271 begin
272 edtDefaultMax.Text := inttostr(maxOcurs);
273 fillLabelText;
274 end;
275 lblDefaultText.Text := 'Click dots in boxes to set start and end dates. You can also input values directly.';
276 btnCancel.caption := 'Cancel';
277 if (not User.ToolsRptEdit) then // For users with Reports settings edit parameter not set.
278 begin
279 lblDefaultText.Text := 'Settings can only be viewed (no editing provided).';
280 btnReset.visible := false;
281 btnOK.visible := false;
282 btnCancel.caption := 'Close';
283 odcDfStart.readOnly := true;
284 odcDfStart.enabled := false;
285 odcDfStart.onExit := nil;
286 odcDfStart.onKeyPress := nil;
287 odcDfStop.readOnly := true;
288 odcDfStop.enabled := false;
289 odcDfStop.onExit := nil;
290 odcDfStop.onKeyPress := nil;
291 edtDefaultMax.readOnly := true;
292 end;
293end;
294
295procedure TfrmOptionsReportsDefault.odcDfStartExit(Sender: TObject);
296const
297 TX_BAD_START = 'The start date is not valid.';
298 TX_STOPSTART = 'The start date must not be after the stop date.';
299
300var
301 x,ErrMsg,datestart,datestop: String;
302begin
303 if odcDfStart.text = '' then
304 begin
305 InfoBox(TX_BAD_START, 'Warning', MB_OK or MB_ICONWARNING);
306 odcDfStart.Text := sDate;
307 odcDfStart.Setfocus;
308 odcDfStart.SelectAll;
309 exit;
310 end;
311
312 ErrMsg := '';
313 odcDfStart.Validate(x);
314 if Length(x) > 0 then
315 begin
316 ErrMsg := TX_BAD_START;
317 InfoBox(TX_BAD_START, 'Warning', MB_OK or MB_ICONWARNING);
318 odcDfStart.Text := sDate;
319 odcDfStart.Setfocus;
320 odcDfStart.SelectAll;
321 exit;
322 end;
323 datestart := odcDfStart.RelativeTime;
324 datestop := odcDfStop.RelativeTime;
325 delete(datestart,1,1);
326 delete(datestop,1,1);
327 if StrToIntDef(datestop,0) < StrToIntDef(datestart,0) then
328 begin
329 InfoBox(TX_STOPSTART, 'Warning', MB_OK or MB_ICONWARNING);
330 odcDfStart.Text := odcDfStop.Text;
331 odcDfStart.SetFocus;
332 odcDfStart.SelectAll;
333 exit;
334 end;
335 odcDfStart.Text := DateToStr(FMDateTimeToDateTime(odcDfStart.FMDateTime));
336 fillLabelText;
337end;
338
339procedure TfrmOptionsReportsDefault.odcDfStopExit(Sender: TObject);
340const
341 TX_BAD_STOP = 'The stop date is not valid.';
342 TX_BAD_ORDER = 'The stop date must not be earlier than start date.';
343var
344 x, ErrMsg,datestart,datestop: string;
345begin
346 if odcDfStop.text = '' then
347 begin
348 InfoBox(TX_BAD_STOP, 'Warning', MB_OK or MB_ICONWARNING);
349 odcDfStop.Text := eDate;
350 odcDfStop.Setfocus;
351 odcDfStop.SelectAll;
352 exit;
353 end;
354
355 ErrMsg := '';
356 odcDfStop.Validate(x);
357 if Length(x) > 0 then
358 begin
359 ErrMsg := TX_BAD_STOP;
360 InfoBox(TX_BAD_STOP, 'Warning', MB_OK or MB_ICONWARNING);
361 odcDfStop.Visible := True;
362 odcDfStop.Text := eDate;
363 odcDfStop.Setfocus;
364 odcDfStop.SelectAll;
365 exit;
366 end;
367 datestart := odcDfStart.RelativeTime;
368 datestop := odcDfStop.RelativeTime;
369 delete(datestart,1,1);
370 delete(datestop,1,1);
371 if StrToIntDef(datestop,0) < StrToIntDef(datestart,0) then
372 begin
373 InfoBox(TX_BAD_ORDER, 'Warning', MB_OK or MB_ICONWARNING);
374 odcDfStop.Text := odcDfStart.Text;
375 odcDfStop.SetFocus;
376 odcDfStop.SelectAll;
377 exit;
378 end;
379 odcDfStop.Text := DateToStr(FMDateTimeToDateTime(odcDfStop.FMDateTime));
380 fillLabelText;
381end;
382
383
384procedure TfrmOptionsReportsDefault.odcDfStartKeyPress(Sender: TObject;
385 var Key: Char);
386begin
387 if Key = #13 then
388 begin
389 Perform(WM_NextDlgCtl, 0, 0);
390 exit;
391 end;
392 if Key = #27 then //Escape
393 begin
394 Key := #0;
395 btnCancel.Click;
396 end;
397end;
398
399procedure TfrmOptionsReportsDefault.odcDfStopKeyPress(Sender: TObject;
400 var Key: Char);
401begin
402 if Key = #13 then
403 begin
404 Perform(WM_NextDlgCtl, 0, 0);
405 exit;
406 end;
407 if Key = #27 then //Escape
408 begin
409 Key := #0;
410 btnCancel.Click;
411 end;
412end;
413
414procedure TfrmOptionsReportsDefault.odcDfStartClick(Sender: TObject);
415begin
416 odcDfStart.SelectAll;
417end;
418
419procedure TfrmOptionsReportsDefault.odcDfStopClick(Sender: TObject);
420begin
421 odcDfStop.SelectAll;
422end;
423
424procedure TfrmOptionsReportsDefault.edtDefaultMaxClick(Sender: TObject);
425begin
426 edtDefaultMax.SelectAll;
427end;
428
429end.
Note: See TracBrowser for help on using the repository browser.