source: cprs/branches/foia-cprs/CPRS-Chart/fAllgyBox.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: 4.2 KB
Line 
1unit fAllgyBox;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, fRptBox, StdCtrls, ExtCtrls, ComCtrls, fARTAllgy, ORFn;
8
9type
10 TfrmAllgyBox = class(TfrmReportBox)
11 cmdEdit: TButton;
12 cmdAdd: TButton;
13 cmdInError: TButton;
14 procedure cmdAddClick(Sender: TObject);
15 procedure cmdEditClick(Sender: TObject);
16 procedure cmdInErrorClick(Sender: TObject);
17 private
18 { Private declarations }
19 FAllergyIEN: integer;
20 procedure RefreshText;
21 public
22 { Public declarations }
23 end;
24
25procedure AllergyBox(ReportText: TStrings; ReportTitle: string; AllowPrint: boolean; AllergyIEN: integer);
26
27var
28 frmAllgyBox: TfrmAllgyBox;
29
30implementation
31
32{$R *.dfm}
33
34uses rCover, fCover;
35
36const
37 NEW_ALLERGY = True;
38 ENTERED_IN_ERROR = True;
39
40function CreateAllergyBox(ReportText: TStrings; ReportTitle: string; AllowPrint: boolean): TfrmAllgyBox;
41var
42 i, AWidth, MaxWidth, AHeight: Integer;
43 Rect: TRect;
44 // %$@# buttons!
45 BtnArray: array of TButton;
46 BtnRight: array of integer;
47 BtnLeft: array of integer;
48 j, k: integer;
49begin
50 Result := TfrmAllgyBox.Create(Application);
51 try
52 with Result do
53 begin
54 k := 0;
55 with pnlButton do for j := 0 to ControlCount - 1 do
56 if Controls[j] is TButton then
57 begin
58 SetLength(BtnArray, k+1);
59 SetLength(BtnRight, k+1);
60 BtnArray[j] := TButton(Controls[j]);
61 BtnRight[j] := ResizeWidth(Font, MainFont, BtnArray[j].Width - BtnArray[j].Width - BtnArray[j].Left);
62 k := k + 1;
63 end;
64 MaxWidth := 350;
65 for i := 0 to ReportText.Count - 1 do
66 begin
67 AWidth := lblFontTest.Canvas.TextWidth(ReportText[i]);
68 if AWidth > MaxWidth then MaxWidth := AWidth;
69 end;
70 cmdPrint.Visible := AllowPrint;
71 MaxWidth := MaxWidth + GetSystemMetrics(SM_CXVSCROLL);
72 AHeight := (ReportText.Count * (lblFontTest.Height + 2)) + pnlbutton.Height;
73 AHeight := HigherOf(AHeight, 250);
74 if AHeight > (Screen.Height - 80) then AHeight := Screen.Height - 80;
75 if MaxWidth > Screen.Width then MaxWidth := Screen.Width;
76 ClientWidth := MaxWidth;
77 ClientHeight := AHeight;
78 Rect := BoundsRect;
79 ForceInsideWorkArea(Rect);
80 BoundsRect := Rect;
81 ResizeAnchoredFormToFont(Result);
82 SetLength(BtnLeft, k);
83 for j := 0 to k - 1 do
84 BtnLeft[j] := pnlButton.Width - BtnArray[j].Width - BtnRight[j];
85 memReport.Lines.Assign(ReportText);
86 for i := 1 to Length(ReportTitle) do if ReportTitle[i] = #9 then ReportTitle[i] := ' ';
87 Caption := ReportTitle;
88 memReport.SelStart := 0;
89 end;
90 except
91 KillObj(@Result);
92 raise;
93 end;
94end;
95
96procedure AllergyBox(ReportText: TStrings; ReportTitle: string; AllowPrint: boolean; AllergyIEN: integer);
97begin
98 frmAllgyBox := CreateAllergyBox(ReportText, ReportTitle, AllowPrint);
99 try
100 with frmAllgyBox do
101 begin
102 FAllergyIEN := AllergyIEN;
103 if not ContainsVisibleChar(memReport.Text) then RefreshText;
104 ShowModal;
105 end;
106 finally
107 frmAllgyBox.Release;
108 end;
109end;
110
111procedure TfrmAllgyBox.cmdAddClick(Sender: TObject);
112var
113 Changed: boolean;
114begin
115 inherited;
116 Visible := False;
117 Changed := EnterEditAllergy(0, NEW_ALLERGY, not ENTERED_IN_ERROR);
118 if not Changed then
119 Close
120 else
121 begin
122 frmCover.UpdateAllergiesList;
123 Close;
124 end
125end;
126
127procedure TfrmAllgyBox.cmdEditClick(Sender: TObject);
128var
129 Changed: boolean;
130begin
131 inherited;
132 Visible := False;
133 Changed := EnterEditAllergy(FAllergyIEN, not NEW_ALLERGY, not ENTERED_IN_ERROR);
134 if Changed then RefreshText;
135 Visible := True;
136end;
137
138procedure TfrmAllgyBox.cmdInErrorClick(Sender: TObject);
139var
140 Changed: boolean;
141begin
142 inherited;
143 Visible := False;
144 Changed := MarkEnteredInError(FAllergyIEN);
145 if Changed then
146 begin
147 frmCover.UpdateAllergiesList;
148 Close;
149 end
150 else Visible := True;
151end;
152
153procedure TfrmAllgyBox.RefreshText;
154begin
155 memReport.Clear;
156 memReport.Lines.Assign(DetailAllergy(FAllergyIEN));
157end;
158
159end.
Note: See TracBrowser for help on using the repository browser.