1 | unit uReports;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses sysutils, classes, ORFN, ComCtrls, Forms, Graphics;
|
---|
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 | 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
|
---|
67 | end;
|
---|
68 |
|
---|
69 | type
|
---|
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
|
---|
78 | end;
|
---|
79 |
|
---|
80 | var
|
---|
81 | RowObjects: TRowObject;
|
---|
82 |
|
---|
83 | //procedures & functions for Report Tree & ListView objects
|
---|
84 |
|
---|
85 | function MakeReportTreeObject(x: string): PReportTreeObject;
|
---|
86 | function IsValidNumber(S: string; var V: extended): boolean;
|
---|
87 | function StringToFMDateTime(Str: string): TFMDateTime;
|
---|
88 | function ShortDateStrToDate(shortdate: string): string ;
|
---|
89 | function StripSpace(str:string):string;
|
---|
90 | function MakeProcedureTreeObject(x: string): PProcTreeObj;
|
---|
91 | function MakePrntProcTreeObject(x: string): PProcTreeObj;
|
---|
92 |
|
---|
93 | //procedures & functions for Report Fonts
|
---|
94 |
|
---|
95 | procedure ReportTextFontChange(Self, Sender: TObject);
|
---|
96 | function CreateReportTextComponent(ParentForm: TForm): TRichEdit;
|
---|
97 |
|
---|
98 |
|
---|
99 | implementation
|
---|
100 |
|
---|
101 | const
|
---|
102 | Months: array[1..12] of string[3] = ('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
|
---|
103 |
|
---|
104 | constructor TCellObject.Create;
|
---|
105 |
|
---|
106 | begin
|
---|
107 | FData := TStringList.Create;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | destructor TCellObject.Destroy;
|
---|
111 | begin
|
---|
112 | FData.Free;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | procedure TCellObject.Add(ASite, AHandle, AColumnData: string; AData: TStringList);
|
---|
116 |
|
---|
117 | begin
|
---|
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);
|
---|
127 | end;
|
---|
128 |
|
---|
129 | function MakeReportTreeObject(x: string): PReportTreeObject;
|
---|
130 | var
|
---|
131 | AnObject: PReportTreeObject;
|
---|
132 | begin
|
---|
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;
|
---|
154 | end;
|
---|
155 |
|
---|
156 | constructor TRowObject.Create;
|
---|
157 | begin
|
---|
158 | FColumnList := TList.Create;
|
---|
159 | FCount := 0;
|
---|
160 | end;
|
---|
161 |
|
---|
162 | destructor TRowObject.Destroy;
|
---|
163 | begin
|
---|
164 | //Clear;
|
---|
165 | FColumnList.Free;
|
---|
166 | inherited Destroy;
|
---|
167 | end;
|
---|
168 |
|
---|
169 | procedure TRowObject.Add(ASite, AHandle, AColumnData: string; AData: TStringList);
|
---|
170 | var
|
---|
171 | ACell: TCellObject;
|
---|
172 | begin
|
---|
173 | ACell := TCellObject.Create;
|
---|
174 | ACell.Add(ASite,AHandle,AColumnData,AData);
|
---|
175 | FColumnList.Add(ACell);
|
---|
176 | FCount := FColumnList.Count;
|
---|
177 | end;
|
---|
178 |
|
---|
179 | procedure TRowObject.Clear;
|
---|
180 | var
|
---|
181 | i: Integer;
|
---|
182 | begin
|
---|
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;
|
---|
188 | end;
|
---|
189 |
|
---|
190 | function IsValidNumber(S: string; var V: extended): boolean;
|
---|
191 | var
|
---|
192 | NumCode: integer;
|
---|
193 | FirstSpace: integer;
|
---|
194 | begin
|
---|
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;
|
---|
210 | end;
|
---|
211 |
|
---|
212 | function StringToFMDateTime(Str: string): TFMDateTime;
|
---|
213 | var
|
---|
214 | mm,dd,yy,hh: integer;
|
---|
215 | day,time,hr,min: string;
|
---|
216 | begin
|
---|
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);
|
---|
234 | end;
|
---|
235 |
|
---|
236 | function ShortDateStrToDate(shortdate: string): string ;
|
---|
237 | {Converts date in format 'mmm dd,yy' or 'mmm dd,yyyy' to standard 'mm/dd/yy'}
|
---|
238 | var
|
---|
239 | month,day,year: string ;
|
---|
240 | i: integer ;
|
---|
241 | begin
|
---|
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 ;
|
---|
259 | end ;
|
---|
260 |
|
---|
261 | function StripSpace(str: string): string;
|
---|
262 | var
|
---|
263 | i,j: integer;
|
---|
264 | begin
|
---|
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);
|
---|
270 | end;
|
---|
271 |
|
---|
272 | function MakeProcedureTreeObject(x: string): PProcTreeObj;
|
---|
273 | var
|
---|
274 | AnObject: PProcTreeObj;
|
---|
275 | begin
|
---|
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;
|
---|
286 | end;
|
---|
287 |
|
---|
288 | function MakePrntProcTreeObject(x: string): PProcTreeObj;
|
---|
289 | var
|
---|
290 | AnObject: PProcTreeObj;
|
---|
291 | begin
|
---|
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;
|
---|
300 | end;
|
---|
301 |
|
---|
302 | procedure ReportTextFontChange(Self, Sender: TObject);
|
---|
303 | begin
|
---|
304 | TFont(Sender).Size := 8;
|
---|
305 | end;
|
---|
306 |
|
---|
307 | // CQ#70295
|
---|
308 | function CreateReportTextComponent(ParentForm: TForm): TRichEdit;
|
---|
309 | var
|
---|
310 | m: TMethod;
|
---|
311 | begin
|
---|
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;
|
---|
324 | end;
|
---|
325 |
|
---|
326 | end.
|
---|