//---------------------------------------------------------------------
Function ReIndexar(aAlias, lTodo)
local oDlg, oAnimate, oMeter1, oMeter2, oSay1, oSay2, oSay3, oBtnCancel
local lEnd:=.f.
local n:=0, nMonto1:=0, nMonto2:=0
local oAnimate2
local nProg,nProg2
DEFAULT lTodo:=.f.
DEFINE DIALOG oDlg RESOURCE "CopyFiles" TRANSPARENT ;
TITLE "Creando ficheros indices (Reindexando)"
REDEFINE SAY oSay1 ID 110 OF oDlg //COLOR nClrTxt
REDEFINE SAY oSay2 ID 120 OF oDlg //COLOR nClrTxt
REDEFINE SAY oSay3 ID 140 OF oDlg //COLOR nClrTxt
REDEFINE METEREX oMeter1 VAR nProg ID 130 TOTAL 50 ROUND ; // ROUNDSIZE 6 //;
GRADIENT TRACK { { 1/2, nRGB( 198, 203, 213 ), nRGB( 219, 224, 233 ) },; //fondo
{ 1/2, nRGB( 224, 238, 237 ), nRGB( 224, 238, 237 ) } } ;
LINECOLORS nRGB( 110, 151,204 ), CLR_WHITE //Borde
REDEFINE METEREX oMeter2 VAR nProg2 ID 150 TOTAL 50 ROUND ; // ROUNDSIZE 6 //;
GRADIENT CHUNK { { 1/2, nRGB( 255, 251, 229 ), nRGB( 250, 223, 143 ) } , ; //barra
{ 1/2, nRGB( 244, 194, 51 ), nRGB( 252, 235, 173 ) } } ;
LINECOLORS nRGB( 110, 151,204 ), CLR_WHITE //borde
REDEFINE BUTTON oBtnCancel ID 2 OF oDlg //;
***ACTION ( lEnd := .t., SysRefresh(), MisAreas(), oAnimate:Stop(), MsgStop("Reindexacion ha sido abortada por el usuario.","Advertencia"), oDlg:End() )
oMeter2:nTotal = LEN(aIndices)
nTotAvance:=0
oDlg:bStart := { || oBtnCancel:Hide(),;
oAnimate:=TGif():New( oDlg, ".\Clip1.gif", 1,oDlg:nLeft()+40),;
oAnimate2:=TGif():New( oDlg, ".\RelojArena.gif", 1,oDlg:nWidth()-120),;
Reindexe( aAlias, oSay1, oSay2, oSay3, oMeter1, oMeter2, @lEnd, oDlg, lTodo ) }
ACTIVATE DIALOG oDlg CENTERED
oAnimate:Stop()
oAnimate2:Stop()
SysRefresh()
Return NIL
//---------------------------------------------------------------------------
Function Reindexe( aAlias, oSay1, oSay2, oSay3, oMeter1, oMeter2, lEnd, oDlg, lTodo )
local n:=0
local nInicia:=Seconds(),nFinaliza:=0
oMeter2:Set( 0 )
For n := 1 to Len( aAlias )
IF ! File( aAlias[ n ]+".dbf" )
MsgInfo( "Fichero no encontrado: " + aAlias[ n ], "Advertencia" )
loop
ELSE
DBSELECTAREA( aAlias[n] )
oSay1:SetText( "Base de Datos Actual: " + upper(aAlias[n]) )
If UPPER( aAlias[n] )="MCONTAB"
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,"mcontab->cuenta+mcontab->scuenta+mcontab->sscuenta+mcontab->ssscuenta+mcontab->sssscuenta","MCONTAB" )
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,"mcontab->nombre","MCONTNOM" )
ElseIf UPPER( aAlias[n] )="COMPROBD"
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,"COMPROBD->NUMDOC","COMPROBD" )
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,"COMPROBD->CTA+COMPROBD->SCTA+COMPROBD->SSCTA+COMPROBD->SSSCTA+COMPROBD->SSSSCTA","COMPDCTA" )
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,"COMPROBD->FECHEMIS","COMPDFEC" )
ElseIf UPPER( aAlias[n] )="NOTASDC"
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,"NOTASDC->numdoc","NOTASDC" )
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,"NOTASDC->cta+NOTASDC->scta+NOTASDC->sscta+NOTASDC->ssscta+NOTASDC->sssscta","NOTASCTA" )
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,"NOTASDC->FECHEMIS","NOTASFEC" )
Endif
ENDIF
Next
nFinaliza:= (Seconds()-nInicia)/60
if lTodo
MisAreas()
WritePProString("config","UltReindex",Dtoc(date()),cIniFile)
SysRefresh()
MsgWait("Reindexación completada." + " Tiempo (Minutos): "+alltrim(str(nFinaliza)),,2)
endif
SysRefresh()
oDlg:End()
return(NIL)
//----------------------------------------------------------------
Function IntegIndex( oSay2,oMeter1,oMeter2,oSay3,Campos,cNombIndice )
local nVar, nStep, nTotal
oSay2:SetText( "Integrando Indice " + cNombIndice )
nTotal := LastRec()
nStep := Max( Int( nTotal * .02 ), 1 ) // actualizar el meter cada 2% del progreso es mas rapido que por cada registro
nVar := 0
oMeter1:nTotal = nTotal
oMeter1:Set( 0 )
nTotAvance+=1
INDEX ON &(Campos) TO &(cNombIndice);
EVAL {|| oMeter1:Set( nVar += nStep ) , SysRefresh(), .t. } EVERY nStep
oMeter1:Set( nTotal )
oMeter2:Set( nTotAvance )
oSay3:SetText( "Indices creados: "+Transform(nTotAvance,"99,999,999") )
Return nil