1 | unit fAllgyBox;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
7 | Dialogs, fRptBox, StdCtrls, ExtCtrls, ComCtrls, fARTAllgy, ORFn;
|
---|
8 |
|
---|
9 | type
|
---|
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 |
|
---|
25 | procedure AllergyBox(ReportText: TStrings; ReportTitle: string; AllowPrint: boolean; AllergyIEN: integer);
|
---|
26 |
|
---|
27 | var
|
---|
28 | frmAllgyBox: TfrmAllgyBox;
|
---|
29 |
|
---|
30 | implementation
|
---|
31 |
|
---|
32 | {$R *.dfm}
|
---|
33 |
|
---|
34 | uses rCover, fCover;
|
---|
35 |
|
---|
36 | const
|
---|
37 | NEW_ALLERGY = True;
|
---|
38 | ENTERED_IN_ERROR = True;
|
---|
39 |
|
---|
40 | function CreateAllergyBox(ReportText: TStrings; ReportTitle: string; AllowPrint: boolean): TfrmAllgyBox;
|
---|
41 | var
|
---|
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;
|
---|
49 | begin
|
---|
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;
|
---|
94 | end;
|
---|
95 |
|
---|
96 | procedure AllergyBox(ReportText: TStrings; ReportTitle: string; AllowPrint: boolean; AllergyIEN: integer);
|
---|
97 | begin
|
---|
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;
|
---|
109 | end;
|
---|
110 |
|
---|
111 | procedure TfrmAllgyBox.cmdAddClick(Sender: TObject);
|
---|
112 | var
|
---|
113 | Changed: boolean;
|
---|
114 | begin
|
---|
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
|
---|
125 | end;
|
---|
126 |
|
---|
127 | procedure TfrmAllgyBox.cmdEditClick(Sender: TObject);
|
---|
128 | var
|
---|
129 | Changed: boolean;
|
---|
130 | begin
|
---|
131 | inherited;
|
---|
132 | Visible := False;
|
---|
133 | Changed := EnterEditAllergy(FAllergyIEN, not NEW_ALLERGY, not ENTERED_IN_ERROR);
|
---|
134 | if Changed then RefreshText;
|
---|
135 | Visible := True;
|
---|
136 | end;
|
---|
137 |
|
---|
138 | procedure TfrmAllgyBox.cmdInErrorClick(Sender: TObject);
|
---|
139 | var
|
---|
140 | Changed: boolean;
|
---|
141 | begin
|
---|
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;
|
---|
151 | end;
|
---|
152 |
|
---|
153 | procedure TfrmAllgyBox.RefreshText;
|
---|
154 | begin
|
---|
155 | memReport.Clear;
|
---|
156 | memReport.Lines.Assign(DetailAllergy(FAllergyIEN));
|
---|
157 | end;
|
---|
158 |
|
---|
159 | end.
|
---|