source: cprs/trunk/CPRS-Chart/uReports.pas@ 1138

Last change on this file since 1138 was 830, checked in by Kevin Toppenberg, 14 years ago

Upgrading to version 27

File size: 10.0 KB
Line 
1unit uReports;
2
3interface
4
5uses sysutils, classes, ORFN, ComCtrls, Forms, Graphics;
6
7type
8
9TCellObject = class //Data Object for each Cell in ListView
10 private
11 FName : string; //Column Name
12 FSite : string; //Site (#;name)
13 FInclude : string; //Set if data is to be included in detailed report
14 FTextType : string; //Type of data (WP)
15 FVisible : string; //Set if column property is visible
16 FHandle : string; //Row:Col identifier
17 FDataType : string; //Data Type of data in column (null or 0:freetext, 1:integer, 2:datetime)
18 FData : TStringList; //Data for this field (could be WP)
19 FCount : integer;
20
21 public
22 constructor Create;
23 destructor Destroy; override;
24 procedure Add(ASite, AHandle, AColumnData: string; AData: TStringList);
25 property Name :string read FName write FName;
26 property Site :string read FSite write FSite;
27 property Include :string read FInclude write FInclude;
28 property TextType :string read FTextType write FTextType;
29 property Visible :string read FVisible write FVisible;
30 property Handle :string read FHandle write FHandle;
31 property DataType :string read FDataType write FDatatype;
32 property Data :TStringList read FData write FData;
33 property Count :integer read FCount write FCount;
34 end;
35
36TRowObject = class //List of Row objects for ListView
37 private
38 FCount :integer;
39 FColumnList:TList;
40 public
41 constructor Create;
42 destructor Destroy; override;
43 procedure Add(ASite, AHandle, AColumnData: string; AData: TStringList);
44 procedure Clear;
45 property Count :integer read FCount;
46 property ColumnList :TList read FColumnList;
47 end;
48
49type
50 PReportTreeObject = ^TReportTreeObject;
51 TReportTreeObject = Record
52 ID : String; //Report ID ID:Text => when passed to broker add: ;Remote~uHState
53 Heading : String; //Report Heading
54 Qualifier : String; //Report Qualifier
55 Remote : String; //Remote Data Capable
56 RptType : String; //Report Type
57 Category : String; //Report Category
58 RPCName : String; //Associated RPC
59 IFN : String; //IFN of report in file 101.24
60 HSTAG : String; //Report extract tag;routine;component #
61 SortOrder : String; //#:# of columns to use in a multi-column sort
62 MaxDaysBack: String; //Maximum number of Days allowed for report
63 Direct : String; //Direct Remote Call flag
64 HDR : String; //HDR is data source if = 1
65 FHIE : String; //FHIE is data source if = 1
66 FHIEONLY : String; //FHIEONLY if data is to only include FHIE
67end;
68
69type
70 PProcTreeObj = ^TProcedureTreeObject;
71 TProcedureTreeObject = Record
72 ParentName : String; //Parent procedure name for exam/print sets
73 ProcedureName: String; //Same as ParentName for stand-alone procedures
74 MemberOfSet : String; //1 = descendant procedures have individual reports
75 //2 = descendant procedures have one shared report
76 ExamDtTm : String; //Exam Date Time
77 Associate : Integer; //Index of the associated TListItem in the lvReports
78end;
79
80var
81 RowObjects: TRowObject;
82
83//procedures & functions for Report Tree & ListView objects
84
85function MakeReportTreeObject(x: string): PReportTreeObject;
86function IsValidNumber(S: string; var V: extended): boolean;
87function StringToFMDateTime(Str: string): TFMDateTime;
88function ShortDateStrToDate(shortdate: string): string ;
89function StripSpace(str:string):string;
90function MakeProcedureTreeObject(x: string): PProcTreeObj;
91function MakePrntProcTreeObject(x: string): PProcTreeObj;
92
93//procedures & functions for Report Fonts
94
95procedure ReportTextFontChange(Self, Sender: TObject);
96function CreateReportTextComponent(ParentForm: TForm): TRichEdit;
97
98
99implementation
100
101const
102 Months: array[1..12] of string[3] = ('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
103
104constructor TCellObject.Create;
105
106begin
107 FData := TStringList.Create;
108end;
109
110destructor TCellObject.Destroy;
111begin
112 FData.Free;
113end;
114
115procedure TCellObject.Add(ASite, AHandle, AColumnData: string; AData: TStringList);
116
117begin
118 FName := piece(AColumnData,'^',1);
119 FSite := ASite;
120 FInclude := piece(AColumnData,'^',5);
121 FTextType := piece(AColumnData,'^',4);
122 FVisible := piece(AColumnData,'^',2);
123 FDataType := piece(AColumnData,'^',9);
124 FHandle := AHandle;
125 FCount := AData.Count;
126 FastAssign(AData, FData);
127end;
128
129function MakeReportTreeObject(x: string): PReportTreeObject;
130var
131 AnObject: PReportTreeObject;
132begin
133 //x=id^Name^Qualifier^HSTag;Routine^Entry^Routine^Remote^Type^Category^RPC^ifn^SortOrder^MaxDaysBack^Direct^HDR^FHIE
134 New(AnObject);
135 with AnObject^ do
136 begin
137 ID := UpperCase(Piece(x, U, 1)) + ':' + UpperCase(Piece(x, U, 2));
138 Heading := Piece(x, U, 2);
139 Qualifier := Piece(x, U, 3);
140 Remote := Piece(x, U, 7);
141 RptType := Piece(x, U, 8);
142 Category := Piece(x, U, 9);
143 RPCName := UpperCase(Piece(x, U, 10));
144 IFN := Piece(x, U, 11);
145 HSTag := UpperCase(Piece(x, U, 4));
146 SortOrder := Piece(x, U, 12);
147 MaxDaysBack := Piece(x, U, 13);
148 Direct := Piece(x, U, 14);
149 HDR := Piece(x, U, 15);
150 FHIE := Piece(x, U, 16);
151 FHIEONLY := Piece(x, U, 17);
152 end;
153 Result := AnObject;
154end;
155
156constructor TRowObject.Create;
157begin
158 FColumnList := TList.Create;
159 FCount := 0;
160end;
161
162destructor TRowObject.Destroy;
163begin
164 //Clear;
165 FColumnList.Free;
166 inherited Destroy;
167end;
168
169procedure TRowObject.Add(ASite, AHandle, AColumnData: string; AData: TStringList);
170var
171 ACell: TCellObject;
172begin
173 ACell := TCellObject.Create;
174 ACell.Add(ASite,AHandle,AColumnData,AData);
175 FColumnList.Add(ACell);
176 FCount := FColumnList.Count;
177end;
178
179procedure TRowObject.Clear;
180var
181 i: Integer;
182begin
183 with FColumnList do
184 for i := 0 to Count - 1 do
185 with TCellObject(Items[i]) do Free;
186 FColumnList.Clear;
187 FCount := 0;
188end;
189
190function IsValidNumber(S: string; var V: extended): boolean;
191var
192 NumCode: integer;
193 FirstSpace: integer;
194begin
195 FirstSpace := Pos(' ', S);
196 if FirstSpace > 0 then
197 S := Copy(S, 1, FirstSpace - 1);
198 Val(S, V, NumCode);
199 Result := (NumCode = 0);
200 if not Result then
201 begin
202 // Remove thousands seperators
203 S := StringReplace(S, ThousandSeparator, '', [rfReplaceAll]);
204 // change DecimalSeperator to '.' because Val only recognizes that, not
205 // the locale specific decimal char... then try again. Stupid Val.
206 S := StringReplace(S, DecimalSeparator, '.', [rfReplaceAll]);
207 Val(S, V, NumCode);
208 Result := (NumCode = 0);
209 end;
210end;
211
212function StringToFMDateTime(Str: string): TFMDateTime;
213var
214 mm,dd,yy,hh: integer;
215 day,time,hr,min: string;
216begin
217 day := piece(str,' ',1);
218 time := piece(str,' ',2);
219 hh := 0;
220 if length(time) > 0 then
221 begin
222 hr := piece(time,':',1);
223 if Copy(hr,1,1) = '0' then hr := Copy(hr,2,1);
224 if Copy(hr,1,1) = '0' then hr := '';
225 min := piece(time,':',2);
226 if Copy(min,1,1) = '0' then min := Copy(min,2,1);
227 if Copy(min,1,1) = '0' then min := '';
228 hh := StrToIntDef(hr + min,0);
229 end;
230 mm := StrToIntDef(piece(day,'/',1),0);
231 dd := StrToIntDef(piece(day,'/',2),0);
232 yy := StrToIntDef(piece(day,'/',3),0) - 1700;
233 Result := (yy * 10000) + (mm * 100) + dd + (hh/10000);
234end;
235
236function ShortDateStrToDate(shortdate: string): string ;
237{Converts date in format 'mmm dd,yy' or 'mmm dd,yyyy' to standard 'mm/dd/yy'}
238var
239 month,day,year: string ;
240 i: integer ;
241begin
242 result := 'ERROR' ;
243 if (Pos(' ',shortdate) <> 4) or ((Pos(',',shortdate) <> 7) and (Pos(',',shortdate) <> 6)) then exit ; {no spaces or comma}
244 for i := 1 to 12 do
245 if Months[i] = UpperCase(Copy(shortdate,1,3)) then month := IntToStr(i);
246 if month = '' then exit ; {invalid month name}
247 if length(month) = 1 then month := '0' + month;
248 if Pos(',',shortdate) = 7 then
249 begin
250 day := IntToStr(StrToInt(Copy(shortdate,5,2))) ;
251 year := IntToStr(StrToInt(Copy(shortdate,8,99))) ;
252 end;
253 if Pos(',',shortdate) = 6 then
254 begin
255 day := '0' + IntToStr(StrToInt(Copy(shortdate,5,1))) ;
256 year := IntToStr(StrToInt(Copy(shortdate,7,99))) ;
257 end;
258 result := month+'/'+day+'/'+year ;
259end ;
260
261function StripSpace(str: string): string;
262var
263 i,j: integer;
264begin
265 i := 1;
266 j := length(str);
267 while str[i] = #32 do inc(i);
268 while str[j] = #32 do dec(j);
269 result := copy(str, i, j-i+1);
270end;
271
272function MakeProcedureTreeObject(x: string): PProcTreeObj;
273var
274 AnObject: PProcTreeObj;
275begin
276 New(AnObject);
277 with AnObject^ do
278 begin
279 ParentName := Piece(x, U, 11);
280 ProcedureName := Piece(x, U, 4);
281 MemberOfSet := Piece(x, U, 10);
282 ExamDtTm := Piece(x, U, 2);
283 Associate := -1;
284 end;
285 Result := AnObject;
286end;
287
288function MakePrntProcTreeObject(x: string): PProcTreeObj;
289var
290 AnObject: PProcTreeObj;
291begin
292 New(AnObject);
293 with AnObject^ do
294 begin
295 ParentName := Piece(x, U, 11);
296 ExamDtTm := Piece(x, U, 2);
297 Associate := -1;
298 end;
299 Result := AnObject;
300end;
301
302procedure ReportTextFontChange(Self, Sender: TObject);
303begin
304 TFont(Sender).Size := 8;
305end;
306
307// CQ#70295
308function CreateReportTextComponent(ParentForm: TForm): TRichEdit;
309var
310 m: TMethod;
311begin
312 Result := TRichEdit.Create(ParentForm);
313 with Result do
314 begin
315 Parent := ParentForm;
316 Visible := False;
317 Width := 600;
318 Font.Name := 'Courier New';
319 Font.Size := 8;
320 m.Code := @ReportTextFontChange;
321 m.Data := ParentForm;
322 Font.OnChange := TNotifyEvent(m);
323 end;
324end;
325
326end.
Note: See TracBrowser for help on using the repository browser.