// mgd 2015.11.30 -- 2016.01.12 // ArDashboard Viewer // Como usar: // 1) Colocar na pasta de Argow.exe, arDashboardViewer e Argow.interproc.dll (versão 1.1 ou maior) // 2) Selecionar Dashboard, ver sf.db.getResource( xxxxx, '' ) na linha 62 (ou perto) // 2) Rodar sendDashboard() const _ok= 789; //----- const _z= #0; procedure _replaceArgowParam( var cXml: string; const cSql: string ); var i, k, p: integer; q: char; cOld, cNew, cParam: string; begin p:= length( cSql ); repeat p:= pos( '--:AR', copy( cSql, 1, p )); k:= 0; i:= p; q:= _z; while ( i > 0 ) and ( k = 0 ) do begin if not ( q = _z ) then begin if ( cSql[i] = q ) then q:= _z; end else if charInSet( cSql[i], [ '''', '"' ] ) then begin q:= cSql[i]; end else if charInSet( cSql[i], [ '<', '>', '=', ' ' ] ) then begin k:= i + 1; end; dec(i); end; if ( k > 0 ) then begin i:= p + 3; // ir até final do ar_param while ( i < length( cSql )) and ((( 'A' <= UpperCase(cSql[i])) ) and ( UpperCase(cSql[i]) <= 'Z')) or ( cSql[i] = '_' ) do inc(i); cOld:= Copy(cSql, k, i-k); cNew:= sf.ar.replaceparams( cParam ); cParam:= Copy( cSql, p+2, i-(p+2)); cXml:= sf.sv.replace( cXml, Copy(cSql, k, i-k), sf.ar.replaceparams( cParam ), #1, false); end; until ( p = 0 ); end; //----- function sendDashboard( const cDashBoard: string ): boolean; var r, i, k: integer; ms: TMemoryStream; o: TArXmlDoc; nd, nq: TArXmlNode; cXml: string; begin result:= false; // pegar resource ms:= sf.db.getResource( cDashBoard, '' ); if not assigned( ms ) then exit; arDebug( 'Resource Pronto' ); // conectar r:= sf.ar.send( sf.ar.exeFolder + 'arDashboardViewer.exe', 'ArDashBoard', 1, '' ); if not ( r = _ok ) then exit; arDebug( 'Conetado.' ); o:= TArXmlDoc.Create; try // Colocar filtros de Argow (:AR_xxxx) cXml:= sf.sv.toStr( ms ); o.LoadFromStream( ms ); nd:= o.childNodes['DataSources']; for k:= 0 to nd.childNodes.count - 1 do begin if sameText( nd.ChildNodes[k].nodeName, 'SqlDataSource' ) then begin for i:= 0 to nd.ChildNodes[k].childNodes.count - 1 do begin nq:= nd.ChildNodes[k].childNodes[i]; if sameText( nq.nodeName, 'Query' ) and sameText( nq.attributes['Type'], 'CustomSqlQuery' ) then begin _replaceArgowParam( cXml, nq.childNodes['Sql'].text ); end; end; end; end; // enviar r:= sf.ar.send( sf.ar.exeFolder + 'arDashboardViewer.exe', 'ArDashBoard', 126, sf.sv.toStr( ms ) ); // 126: Open, 127: Close result:= ( r = _ok ); if not result then arDebug( sf.shell.LastError ); finally ms.free; o.free; end; end; function receiveMsg( iCode: integer; const sMsg: string ): integer; begin result:= iCode + length( sMsg ); arDebug( 'Código: ' + intToStr( iCode )); arDebug( sMsg ); end;