source: cprs/branches/foia-cprs/CPRS-Chart/fRptBox.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: 6.7 KB
Line 
1unit fRptBox;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls, ORFn, ComCtrls, ExtCtrls, fFrame;
8
9type
10 TfrmReportBox = class(TForm)
11 lblFontTest: TLabel;
12 memReport: TRichEdit;
13 pnlButton: TPanel;
14 cmdPrint: TButton;
15 dlgPrintReport: TPrintDialog;
16 cmdClose: TButton;
17 procedure memReportClick(Sender: TObject);
18 procedure cmdPrintClick(Sender: TObject);
19 procedure cmdCloseClick(Sender: TObject);
20 procedure FormClose(Sender: TObject; var Action: TCloseAction);
21 procedure FormCreate(Sender: TObject);
22 end;
23
24procedure ReportBox(ReportText: TStrings; ReportTitle: string; AllowPrint: boolean);
25function ModelessReportBox(ReportText: TStrings; ReportTitle: string; AllowPrint: boolean): TfrmReportBox;
26procedure PrintStrings(Form: TForm; StringText: TStrings; const Title, Trailer: string);
27
28implementation
29
30uses
31 uCore, rCore, rReports, Printers;
32
33{$R *.DFM}
34
35function CreateReportBox(ReportText: TStrings; ReportTitle: string; AllowPrint: boolean): TfrmReportBox;
36var
37 i, AWidth, MaxWidth, AHeight: Integer;
38 Rect: TRect;
39 // %$@# buttons!
40 BtnArray: array of TButton;
41 BtnRight: array of integer;
42 BtnLeft: array of integer;
43 //cmdCloseRightMargin: integer;
44 //cmdPrintRightMargin: integer;
45 j, k: integer;
46begin
47 Result := TfrmReportBox.Create(Application);
48 try
49 with Result do
50 begin
51 k := 0;
52 with pnlButton do for j := 0 to ControlCount - 1 do
53 if Controls[j] is TButton then
54 begin
55 SetLength(BtnArray, k+1);
56 SetLength(BtnRight, k+1);
57 BtnArray[j] := TButton(Controls[j]);
58 BtnRight[j] := ResizeWidth(Font, MainFont, BtnArray[j].Width - BtnArray[j].Width - BtnArray[j].Left);
59 k := k + 1;
60 end;
61 //cmdCloseRightMargin := ResizeWidth(Font, MainFont, pnlButton.Width - cmdClose.Width - cmdClose.Left);
62 //cmdPrintRightMargin := ResizeWidth(Font, MainFont, pnlButton.Width - cmdPrint.Width - cmdPrint.Left);
63 MaxWidth := 350;
64 for i := 0 to ReportText.Count - 1 do
65 begin
66 AWidth := lblFontTest.Canvas.TextWidth(ReportText[i]);
67 if AWidth > MaxWidth then MaxWidth := AWidth;
68 end;
69 cmdPrint.Visible := AllowPrint;
70 MaxWidth := MaxWidth + GetSystemMetrics(SM_CXVSCROLL);
71 AHeight := (ReportText.Count * (lblFontTest.Height + 2)) + pnlbutton.Height;
72 AHeight := HigherOf(AHeight, 250);
73 if AHeight > (Screen.Height - 80) then AHeight := Screen.Height - 80;
74 if MaxWidth > Screen.Width then MaxWidth := Screen.Width;
75 ClientWidth := MaxWidth;
76 ClientHeight := AHeight;
77 Rect := BoundsRect;
78 ForceInsideWorkArea(Rect);
79 BoundsRect := Rect;
80 ResizeAnchoredFormToFont(Result);
81 SetLength(BtnLeft, k);
82 for j := 0 to k - 1 do
83 begin
84 BtnLeft[j] := pnlButton.Width - BtnArray[j].Width - BtnRight[j];
85 end;
86 //cmdClose.Left := pnlButton.Width - cmdClose.Width - cmdCloseRightMargin;
87 //cmdPrint.Left := pnlButton.Width - cmdPrint.Width - cmdPrintRightMargin;
88 memReport.Lines.Assign(ReportText);
89 for i := 1 to Length(ReportTitle) do if ReportTitle[i] = #9 then ReportTitle[i] := ' ';
90 Caption := ReportTitle;
91 memReport.SelStart := 0;
92 end;
93 except
94 KillObj(@Result);
95 raise;
96 end;
97end;
98
99procedure ReportBox(ReportText: TStrings; ReportTitle: string; AllowPrint: boolean);
100var
101 frmReportBox: TfrmReportBox;
102
103begin
104 frmReportBox := CreateReportBox(ReportText, ReportTitle, AllowPrint);
105 try
106 frmReportBox.ShowModal;
107 finally
108 frmReportBox.Release;
109 end;
110end;
111
112function ModelessReportBox(ReportText: TStrings; ReportTitle: string; AllowPrint: boolean): TfrmReportBox;
113begin
114 Result := CreateReportBox(ReportText, ReportTitle, AllowPrint);
115 Result.FormStyle := fsStayOnTop;
116 Result.Show;
117end;
118
119procedure PrintStrings(Form: TForm; StringText: TStrings; const Title, Trailer: string);
120var
121 AHeader: TStringList;
122 memPrintReport: TRichEdit;
123 MaxLines, LastLine, ThisPage, i: integer;
124 ErrMsg: string;
125// RemoteSiteID: string; //for Remote site printing
126// RemoteQuery: string; //for Remote site printing
127 dlgPrintReport: TPrintDialog;
128
129const
130 PAGE_BREAK = '**PAGE BREAK**';
131
132begin
133// RemoteSiteID := '';
134// RemoteQuery := '';
135 dlgPrintReport := TPrintDialog.Create(Form);
136 try
137 frmFrame.CCOWBusy := True;
138 if dlgPrintReport.Execute then
139 begin
140 AHeader := TStringList.Create;
141 CreatePatientHeader(AHeader, Title);
142 memPrintReport := TRichEdit.Create(Form);
143 try
144 MaxLines := 60 - AHeader.Count;
145 LastLine := 0;
146 ThisPage := 0;
147 with memPrintReport do
148 begin
149 Visible := False;
150 Parent := Form;
151 Font.Name := 'Courier New';
152 Font.Size := MainFontSize;
153 Width := Printer.Canvas.TextWidth(StringOfChar('-', 74));
154 //Width := 600;
155 repeat
156 with Lines do
157 begin
158 AddStrings(AHeader);
159 for i := 0 to MaxLines do
160 if i < StringText.Count then
161 Add(StringText[LastLine + i])
162 else
163 Break;
164 LastLine := LastLine + i;
165 Add(' ');
166 Add(' ');
167 Add(StringOfChar('-', 74));
168 if LastLine >= StringText.Count - 1 then
169 Add(Trailer)
170 else
171 begin
172 ThisPage := ThisPage + 1;
173 Add('Page ' + IntToStr(ThisPage));
174 Add(PAGE_BREAK);
175 end;
176 end;
177 until LastLine >= StringText.Count - 1;
178 PrintWindowsReport(memPrintReport, PAGE_BREAK, Title, ErrMsg);
179 end;
180 finally
181 memPrintReport.Free;
182 AHeader.Free;
183 end;
184 end;
185 finally
186 frmFrame.CCOWBusy := False;
187 dlgPrintReport.Free;
188 end;
189end;
190
191procedure TfrmReportBox.memReportClick(Sender: TObject);
192begin
193 //Close;
194end;
195
196procedure TfrmReportBox.cmdPrintClick(Sender: TObject);
197begin
198 PrintStrings(Self, memReport.Lines, Self.Caption, 'End of report');
199 memReport.Invalidate;
200end;
201
202procedure TfrmReportBox.cmdCloseClick(Sender: TObject);
203begin
204 Close;
205end;
206
207procedure TfrmReportBox.FormClose(Sender: TObject; var Action: TCloseAction);
208begin
209 if(not (fsModal in FormState)) then
210 Action := caFree;
211end;
212
213procedure TfrmReportBox.FormCreate(Sender: TObject);
214begin
215 memReport.Color := ReadOnlyColor;
216end;
217
218end.
Note: See TracBrowser for help on using the repository browser.