1 | unit uReports;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses sysutils, classes, ORFN;
|
---|
6 |
|
---|
7 | type
|
---|
8 |
|
---|
9 | TCellObject = 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 |
|
---|
36 | TRowObject = 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 |
|
---|
49 | type
|
---|
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 | end;
|
---|
64 |
|
---|
65 | type
|
---|
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
|
---|
74 | end;
|
---|
75 |
|
---|
76 | var
|
---|
77 | RowObjects: TRowObject;
|
---|
78 |
|
---|
79 | //procedures & functions for Report Tree & ListView objects
|
---|
80 |
|
---|
81 | function MakeReportTreeObject(x: string): PReportTreeObject;
|
---|
82 | function IsValidNumber(S: string; var V: extended): boolean;
|
---|
83 | function StringToFMDateTime(Str: string): TFMDateTime;
|
---|
84 | function ShortDateStrToDate(shortdate: string): string ;
|
---|
85 | function StripSpace(str:string):string;
|
---|
86 | function MakeProcedureTreeObject(x: string): PProcTreeObj;
|
---|
87 | function MakePrntProcTreeObject(x: string): PProcTreeObj;
|
---|
88 |
|
---|
89 | implementation
|
---|
90 |
|
---|
91 | const
|
---|
92 | Months: array[1..12] of string[3] = ('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
|
---|
93 |
|
---|
94 | constructor TCellObject.Create;
|
---|
95 |
|
---|
96 | begin
|
---|
97 | FData := TStringList.Create;
|
---|
98 | end;
|
---|
99 |
|
---|
100 | destructor TCellObject.Destroy;
|
---|
101 | begin
|
---|
102 | FData.Free;
|
---|
103 | end;
|
---|
104 |
|
---|
105 | procedure TCellObject.Add(ASite, AHandle, AColumnData: string; AData: TStringList);
|
---|
106 |
|
---|
107 | begin
|
---|
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);
|
---|
117 | end;
|
---|
118 |
|
---|
119 | function MakeReportTreeObject(x: string): PReportTreeObject;
|
---|
120 | var
|
---|
121 | AnObject: PReportTreeObject;
|
---|
122 | begin
|
---|
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;
|
---|
140 | end;
|
---|
141 |
|
---|
142 | constructor TRowObject.Create;
|
---|
143 | begin
|
---|
144 | FColumnList := TList.Create;
|
---|
145 | FCount := 0;
|
---|
146 | end;
|
---|
147 |
|
---|
148 | destructor TRowObject.Destroy;
|
---|
149 | begin
|
---|
150 | //Clear;
|
---|
151 | FColumnList.Free;
|
---|
152 | inherited Destroy;
|
---|
153 | end;
|
---|
154 |
|
---|
155 | procedure TRowObject.Add(ASite, AHandle, AColumnData: string; AData: TStringList);
|
---|
156 | var
|
---|
157 | ACell: TCellObject;
|
---|
158 | begin
|
---|
159 | ACell := TCellObject.Create;
|
---|
160 | ACell.Add(ASite,AHandle,AColumnData,AData);
|
---|
161 | FColumnList.Add(ACell);
|
---|
162 | FCount := FColumnList.Count;
|
---|
163 | end;
|
---|
164 |
|
---|
165 | procedure TRowObject.Clear;
|
---|
166 | var
|
---|
167 | i: Integer;
|
---|
168 | begin
|
---|
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;
|
---|
174 | end;
|
---|
175 |
|
---|
176 | function IsValidNumber(S: string; var V: extended): boolean;
|
---|
177 | var
|
---|
178 | NumCode: integer;
|
---|
179 | FirstSpace: integer;
|
---|
180 | begin
|
---|
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;
|
---|
196 | end;
|
---|
197 |
|
---|
198 | function StringToFMDateTime(Str: string): TFMDateTime;
|
---|
199 | var
|
---|
200 | mm,dd,yy,hh: integer;
|
---|
201 | day,time,hr,min: string;
|
---|
202 | begin
|
---|
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);
|
---|
220 | end;
|
---|
221 |
|
---|
222 | function ShortDateStrToDate(shortdate: string): string ;
|
---|
223 | {Converts date in format 'mmm dd,yy' or 'mmm dd,yyyy' to standard 'mm/dd/yy'}
|
---|
224 | var
|
---|
225 | month,day,year: string ;
|
---|
226 | i: integer ;
|
---|
227 | begin
|
---|
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 ;
|
---|
245 | end ;
|
---|
246 |
|
---|
247 | function StripSpace(str: string): string;
|
---|
248 | var
|
---|
249 | i,j: integer;
|
---|
250 | begin
|
---|
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);
|
---|
256 | end;
|
---|
257 |
|
---|
258 | function MakeProcedureTreeObject(x: string): PProcTreeObj;
|
---|
259 | var
|
---|
260 | AnObject: PProcTreeObj;
|
---|
261 | begin
|
---|
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;
|
---|
272 | end;
|
---|
273 |
|
---|
274 | function MakePrntProcTreeObject(x: string): PProcTreeObj;
|
---|
275 | var
|
---|
276 | AnObject: PProcTreeObj;
|
---|
277 | begin
|
---|
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;
|
---|
286 | end;
|
---|
287 |
|
---|
288 | end.
|
---|