source: cprs/branches/foia-cprs/CPRS-Chart/uReports.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: 8.9 KB
Line 
1unit uReports;
2
3interface
4
5uses sysutils, classes, ORFN;
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
63end;
64
65type
66 PProcTreeObj = ^TProcedureTreeObject;
67 TProcedureTreeObject = Record
68 ParentName : String; //Parent procedure name for exam/print sets
69 ProcedureName: String; //Same as ParentName for stand-alone procedures
70 MemberOfSet : String; //1 = descendant procedures have individual reports
71 //2 = descendant procedures have one shared report
72 ExamDtTm : String; //Exam Date Time
73 Associate : Integer; //Index of the associated TListItem in the lvReports
74end;
75
76var
77 RowObjects: TRowObject;
78
79//procedures & functions for Report Tree & ListView objects
80
81function MakeReportTreeObject(x: string): PReportTreeObject;
82function IsValidNumber(S: string; var V: extended): boolean;
83function StringToFMDateTime(Str: string): TFMDateTime;
84function ShortDateStrToDate(shortdate: string): string ;
85function StripSpace(str:string):string;
86function MakeProcedureTreeObject(x: string): PProcTreeObj;
87function MakePrntProcTreeObject(x: string): PProcTreeObj;
88
89implementation
90
91const
92 Months: array[1..12] of string[3] = ('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
93
94constructor TCellObject.Create;
95
96begin
97 FData := TStringList.Create;
98end;
99
100destructor TCellObject.Destroy;
101begin
102 FData.Free;
103end;
104
105procedure TCellObject.Add(ASite, AHandle, AColumnData: string; AData: TStringList);
106
107begin
108 FName := piece(AColumnData,'^',1);
109 FSite := ASite;
110 FInclude := piece(AColumnData,'^',5);
111 FTextType := piece(AColumnData,'^',4);
112 FVisible := piece(AColumnData,'^',2);
113 FDataType := piece(AColumnData,'^',9);
114 FHandle := AHandle;
115 FCount := AData.Count;
116 FData.Assign(AData);
117end;
118
119function MakeReportTreeObject(x: string): PReportTreeObject;
120var
121 AnObject: PReportTreeObject;
122begin
123 //x=id^Name^Qualifier^HSTag;Routine^Entry^Routine^Remote^Type^Category^RPC^ifn^SortOrder^MaxDaysBack
124 New(AnObject);
125 with AnObject^ do
126 begin
127 ID := UpperCase(Piece(x, U, 1)) + ':' + UpperCase(Piece(x, U, 2));
128 Heading := Piece(x, U, 2);
129 Qualifier := Piece(x, U, 3);
130 Remote := Piece(x, U, 7);
131 RptType := Piece(x, U, 8);
132 Category := Piece(x, U, 9);
133 RPCName := UpperCase(Piece(x, U, 10));
134 IFN := Piece(x, U, 11);
135 HSTag := UpperCase(Piece(x, U, 4));
136 SortOrder := Piece(x, U, 12);
137 MaxDaysBack := Piece(x, U, 13);
138 end;
139 Result := AnObject;
140end;
141
142constructor TRowObject.Create;
143begin
144 FColumnList := TList.Create;
145 FCount := 0;
146end;
147
148destructor TRowObject.Destroy;
149begin
150 //Clear;
151 FColumnList.Free;
152 inherited Destroy;
153end;
154
155procedure TRowObject.Add(ASite, AHandle, AColumnData: string; AData: TStringList);
156var
157 ACell: TCellObject;
158begin
159 ACell := TCellObject.Create;
160 ACell.Add(ASite,AHandle,AColumnData,AData);
161 FColumnList.Add(ACell);
162 FCount := FColumnList.Count;
163end;
164
165procedure TRowObject.Clear;
166var
167 i: Integer;
168begin
169 with FColumnList do
170 for i := 0 to Count - 1 do
171 with TCellObject(Items[i]) do Free;
172 FColumnList.Clear;
173 FCount := 0;
174end;
175
176function IsValidNumber(S: string; var V: extended): boolean;
177var
178 NumCode: integer;
179 FirstSpace: integer;
180begin
181 FirstSpace := Pos(' ', S);
182 if FirstSpace > 0 then
183 S := Copy(S, 1, FirstSpace - 1);
184 Val(S, V, NumCode);
185 Result := (NumCode = 0);
186 if not Result then
187 begin
188 // Remove thousands seperators
189 S := StringReplace(S, ThousandSeparator, '', [rfReplaceAll]);
190 // change DecimalSeperator to '.' because Val only recognizes that, not
191 // the locale specific decimal char... then try again. Stupid Val.
192 S := StringReplace(S, DecimalSeparator, '.', [rfReplaceAll]);
193 Val(S, V, NumCode);
194 Result := (NumCode = 0);
195 end;
196end;
197
198function StringToFMDateTime(Str: string): TFMDateTime;
199var
200 mm,dd,yy,hh: integer;
201 day,time,hr,min: string;
202begin
203 day := piece(str,' ',1);
204 time := piece(str,' ',2);
205 hh := 0;
206 if length(time) > 0 then
207 begin
208 hr := piece(time,':',1);
209 if Copy(hr,1,1) = '0' then hr := Copy(hr,2,1);
210 if Copy(hr,1,1) = '0' then hr := '';
211 min := piece(time,':',2);
212 if Copy(min,1,1) = '0' then min := Copy(min,2,1);
213 if Copy(min,1,1) = '0' then min := '';
214 hh := StrToIntDef(hr + min,0);
215 end;
216 mm := StrToIntDef(piece(day,'/',1),0);
217 dd := StrToIntDef(piece(day,'/',2),0);
218 yy := StrToIntDef(piece(day,'/',3),0) - 1700;
219 Result := (yy * 10000) + (mm * 100) + dd + (hh/10000);
220end;
221
222function ShortDateStrToDate(shortdate: string): string ;
223{Converts date in format 'mmm dd,yy' or 'mmm dd,yyyy' to standard 'mm/dd/yy'}
224var
225 month,day,year: string ;
226 i: integer ;
227begin
228 result := 'ERROR' ;
229 if (Pos(' ',shortdate) <> 4) or ((Pos(',',shortdate) <> 7) and (Pos(',',shortdate) <> 6)) then exit ; {no spaces or comma}
230 for i := 1 to 12 do
231 if Months[i] = UpperCase(Copy(shortdate,1,3)) then month := IntToStr(i);
232 if month = '' then exit ; {invalid month name}
233 if length(month) = 1 then month := '0' + month;
234 if Pos(',',shortdate) = 7 then
235 begin
236 day := IntToStr(StrToInt(Copy(shortdate,5,2))) ;
237 year := IntToStr(StrToInt(Copy(shortdate,8,99))) ;
238 end;
239 if Pos(',',shortdate) = 6 then
240 begin
241 day := '0' + IntToStr(StrToInt(Copy(shortdate,5,1))) ;
242 year := IntToStr(StrToInt(Copy(shortdate,7,99))) ;
243 end;
244 result := month+'/'+day+'/'+year ;
245end ;
246
247function StripSpace(str: string): string;
248var
249 i,j: integer;
250begin
251 i := 1;
252 j := length(str);
253 while str[i] = #32 do inc(i);
254 while str[j] = #32 do dec(j);
255 result := copy(str, i, j-i+1);
256end;
257
258function MakeProcedureTreeObject(x: string): PProcTreeObj;
259var
260 AnObject: PProcTreeObj;
261begin
262 New(AnObject);
263 with AnObject^ do
264 begin
265 ParentName := Piece(x, U, 11);
266 ProcedureName := Piece(x, U, 4);
267 MemberOfSet := Piece(x, U, 10);
268 ExamDtTm := Piece(x, U, 2);
269 Associate := -1;
270 end;
271 Result := AnObject;
272end;
273
274function MakePrntProcTreeObject(x: string): PProcTreeObj;
275var
276 AnObject: PProcTreeObj;
277begin
278 New(AnObject);
279 with AnObject^ do
280 begin
281 ParentName := Piece(x, U, 11);
282 ExamDtTm := Piece(x, U, 2);
283 Associate := -1;
284 end;
285 Result := AnObject;
286end;
287
288end.
Note: See TracBrowser for help on using the repository browser.