source: cprs/branches/tmg-cprs/CPRS-Chart/fRptBox.pas@ 1154

Last change on this file since 1154 was 541, checked in by Kevin Toppenberg, 15 years ago

TMG Ver 1.1 Added HTML Support, better demographics editing

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