Procedure

TfrmReports.Timer1Timer

Module

fReports

Last Modified

7/15/2014 3:26:38 PM

Visibility

Public/Published

Owner

TfrmReports

Declaration

procedure Timer1Timer(Sender: TObject);

Calls Hierarchy


TfrmReports.Timer1Timer
 ├GetRemoteStatus
 ├TfrmReports.UpdateRemoteStatus
 ├ModifyHDRData
 ├GetRemoteData
 ├TRemoteReportList.Add
 │ └TRemoteReport.Create
 └TfrmReports.LoadListView
   ├TRowObject.Add
   │ ├TCellObject.Create
   │ └TCellObject.Add
   └TUser.HasKey
     └HasSecurityKey

Calls

Name Declaration Comments
TRemoteReportList.Add procedure Add(AReportList, AHandle: string); -
GetRemoteData procedure GetRemoteData(Dest: TStrings; aHandle: string; aItem: PChar); -
GetRemoteStatus function GetRemoteStatus(aHandle: string): String; -
TfrmReports.LoadListView procedure LoadListView(aReportData: TStringList); -
ModifyHDRData procedure ModifyHDRData(Dest: string; aHandle: string; aID: string); -
TfrmReports.UpdateRemoteStatus procedure UpdateRemoteStatus(aSiteID, aStatus: string); -


Source

1510  procedure TfrmReports.Timer1Timer(Sender: TObject);
1511  var
1512    i,j,fail,t: integer;
1513    r0,aSite: String;
1514    aHDR, aID, aRet: String;
1515  begin
1516    inherited;
1517    with RemoteSites.SiteList do
1518     begin
1519      for i := 0 to Count - 1 do
1520        if TRemoteSite(Items[i]).Selected then
1521         begin
1522          if Length(TRemoteSite(Items[i]).RemoteHandle) > 0 then
1523            begin
1524              r0 := GetRemoteStatus(TRemoteSite(Items[i]).RemoteHandle);
1525              aSite := TRemoteSite(Items[i]).SiteName;
1526              TRemoteSite(Items[i]).QueryStatus := r0; //r0='1^Done' if no errors
1527              UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID, piece(r0,'^',2));
1528              if piece(r0,'^',1) = '1' then
1529                begin
1530                  aHDR := piece(TRemoteSite(Items[i]).CurrentReportQuery, '^', 13);
1531                  aID := piece(piece(TRemoteSite(Items[i]).CurrentReportQuery, '^', 2),':',1);
1532                  if aHDR = '1' then
1533                    begin
1534                      ModifyHDRData(aRet, TRemoteSite(Items[i]).RemoteHandle ,aID);
1535                    end;
1536                  GetRemoteData(TRemoteSite(Items[i]).Data, TRemoteSite(Items[i]).RemoteHandle,Items[i]);
1537                  RemoteReports.Add(TRemoteSite(Items[i]).CurrentReportQuery,
1538                    TRemoteSite(Items[i]).RemoteHandle);
1539                  TRemoteSite(Items[i]).RemoteHandle := '';
1540                  TabControl1.OnChange(nil);
1541                  if (length(piece(uHState,';',2)) > 0) then
1542                    begin
1543                      uRemoteReportData.Clear;
1544                      QuickCopy(TRemoteSite(Items[i]).Data,uRemoteReportData);
1545                      fail := 0;
1546                      if uRemoteReportData.Count > 0 then
1547                        begin
1548                          if uRemoteReportData[0] = 'Report not available at this time.' then
1549                            begin
1550                              fail := 1;
1551                              UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID,'Report not available');
1552                            end;
1553                          if piece(uRemoteReportData[0],'^',1) = '-1' then
1554                            begin
1555                              fail := 1;
1556                              UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID,'Communication failure');
1557                            end;
1558                          if fail = 0 then
1559                            LoadListView(uRemoteReportData);
1560                        end;
1561                    end;
1562                end
1563              else
1564                begin
1565                  uRemoteCount := uRemoteCount + 1;
1566                  if uRemoteCount > 90 then
1567                    begin
1568                      TRemoteSite(Items[i]).RemoteHandle := '';
1569                      TRemoteSite(Items[i]).QueryStatus := '-1^Timed out';
1570                      UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID,'Timed out');
1571                      StatusText('');
1572                      TabControl1.OnChange(nil);
1573                    end
1574                  else
1575                    StatusText('Retrieving reports from '
1576                  + TRemoteSite(Items[i]).SiteName + '...');
1577                end;
1578              t := Timer1.Interval;
1579              if t < 5000 then
1580                begin
1581                  if t < 3001 then Timer1.Interval := 4000
1582                  else if t < 4001 then Timer1.Interval := 5000;
1583                end;
1584            end;
1585         end;
1586       if Timer1.Enabled = True then
1587         begin
1588           j := 0;
1589           for i := 0 to Count -1 do
1590             begin
1591               if Length(TRemoteSite(Items[i]).RemoteHandle) > 0 then
1592                 begin
1593                   j := 1;
1594                   break;
1595                 end;
1596             end;
1597           if j = 0 then  //Shutdown timer if all sites have been processed
1598             begin
1599               Timer1.Enabled := False;
1600               StatusText('');
1601             end;
1602           j := 0;
1603           for i := 0 to Count -1 do
1604             if TRemoteSite(Items[i]).Selected = true then
1605               begin
1606                 j := 1;
1607                 break;
1608               end;
1609           if j = 0 then  //Shutdown timer if user has de-selected all sites
1610             begin
1611               Timer1.Enabled := False;
1612               StatusText('');
1613               TabControl1.OnChange(nil);
1614             end;
1615         end;
1616     end;
1617  end;