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