fergonm wrote:Buenos días.
Tengo una función que indexa la base de datos (Varias tablas y varios índices por cada tabla).
Me gustaría introducir un "meter" que indique la marcha de cada índice.
¿Hay algún ejemplo?
Muchas gracias.
Si deseas algo sencillo, prueba este:
//--------------------
FUNCTION IndTabla1()
DBSELECTAREA("TABLA1")
MsgMeter( { | oMeter, oText, oDlg, lEnd | ;
BuildIndex( oMeter, oText, oDlg, @lEnd,"TABLA1->NUMDOC","DCTOHIST") },;
"Integrando Indice DCTOHIST" )
MsgMeter( { | oMeter, oText, oDlg, lEnd | ;
BuildIndex( oMeter, oText, oDlg, @lEnd,;
"TABLA1->CTA","CTAHIST") },;
"Integrando Indice CTAHIST" )
RETURN NIL
//---------------------------
FUNCTION IndTabla2()
DBSELECTAREA("TABLA2")
DBSELECTAREA("TABLA2")
MsgMeter( { | oMeter, oText, oDlg, lEnd | ;
BuildIndex( oMeter, oText, oDlg, @lEnd,;
"TABLA2->CUENTA","MCONTAH") },;
"Integrando Indice MCONTAH" )
RETURN NIL
//----------------------------------------------------------------------------//
function BuildIndex( oMeter, oText, oDlg, lEnd, Campos,xIndice )
oMeter:nTotal = RecCount()
INDEX ON &(Campos) TO &(xIndice);
EVAL ( oMeter:Set( RecNo() ), SysRefresh(), ! lEnd )
return nil
//----------------------------------------------------------------------------//
function MsgMeter( bAction, cMsg, cTitle, lBoton )
local oDlg, oMeter, oText, oBtn, oFont
local lEnd := .f., lCancel := .f.
local nVal := 0
DEFAULT bAction := { || nil },;
cMsg := "Procesando...", cTitle := "Aguarde por favor",;
lBoton := .f.
DEFINE DIALOG oDlg RESOURCE "MSGMETER" COLOR "W+/B"
REDEFINE TSAYT ID 111 OF oDlg
REDEFINE TSAYT oText VAR cMsg ID 110 OF oDlg
REDEFINE METER oMeter VAR nVal TOTAL 10 ID 130 OF oDlg
if lBoton
@ 2.8, 18 BUTTON oBtn PROMPT "&Cancel" OF oDlg ;
ACTION ( lEnd:= .t., lCancel:= .t. ) SIZE 32, 11
endif
// This block gets evaluated only the first time the DialogBox is painted !!!
oDlg:bStart = { || Eval( bAction, oMeter, oText, oDlg, @lEnd, oBtn ),;
lEnd := .t., oDlg:End() }
ACTIVATE DIALOG oDlg CENTERED ;
VALID lEnd
return lCancel
Si deseas algo mas vistoso, prueba este ejemplo:
//---------------------------------------------------------------------
Function ReIndexar(aAlias, lTodo)
local oDlg, oAnimate, oMeter1, oMeter2, oSay1, oSay2, oSay3, oBtnCancel
local lEnd:=.f.
local n:=0, nMonto1:=0, nMonto2:=0
local oBrush,cBrush:="Fondo1.BMP"
local nClrTxt:= RGB(0,0,0)
DEFAULT lTodo:=.f.
DEFINE BRUSH oBrush FILENAME cBrush
DEFINE DIALOG oDlg RESOURCE "CopyFiles" BRUSH oBrush TRANSPARENT ;
TITLE "Creando ficheros indices (Reindexando)"
oAnimate = TAnimate():Redefine( 160, oDlg )
REDEFINE TSAYT oSay1 ID 110 OF oDlg COLOR nClrTxt
REDEFINE TSAYT oSay2 ID 120 OF oDlg COLOR nClrTxt
REDEFINE PROGRESS oMeter1 ID 130 OF oDlg
REDEFINE TSAYT oSay3 ID 140 OF oDlg COLOR nClrTxt
REDEFINE PROGRESS oMeter2 ID 150 OF oDlg
REDEFINE BUTTON oBtnCancel ID 2 OF oDlg
oDlg:bStart := { || oBtnCancel:Hide(), oAnimate:CopyFiles(), oAnimate:Play(),;
Reindexe( aAlias, oSay1, oSay2, oSay3, oMeter1, oMeter2, @lEnd, oDlg, oAnimate, lTodo ) }
ACTIVATE DIALOG oDlg CENTERED
SysRefresh()
Return NIL
//---------------------------------------------------------------------------
Function Reindexe( aAlias, oSay1, oSay2, oSay3, oMeter1, oMeter2, lEnd, oDlg, oAnimate, lTodo )
local n:=0, nTotReg:=0
for n := 1 to Len( aAlias )
if ! File( aAlias[ n ]+".dbf" )
MsgInfo( "Fichero no encontrado: " + aAlias[ n ], "Advertencia" )
else
If UPPER( aAlias[n] )="TABLA1"
nTotReg += (aAlias[n])->(RecCount()) * 2 //Cant de Reg*Cant de indices
ElseIf UPPER( aAlias[n] )="TABLA2"
nTotReg += (aAlias[n])->(RecCount()) * x num de indices
endif
SysRefresh()
next
oMeter2:SetRange(0,nTotReg)
nTotReg:=0
For n:=1 to len(aAlias)
DBSELECTAREA( aAlias[n] )
oSay1:SetText( "Base de Datos Actual: " + upper(aAlias[n]) )
If UPPER( aAlias[n] )="MCONTAB"
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,@nTotReg,;
"TABLA2->cuenta","MCONTCTA" )
ElseIf UPPER( aAlias[n] )="TABLA1"
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,@nTotReg,;
"TABLA1->","MCONTAH" )
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,@nTotReg,;
"TABLA1->FECHCIERRE","MCONTFEC" )
Endif
Next
oAnimate:Stop()
if lTodo
MisAreas()
WritePProString("config","UltReindex",Dtoc(date()),cIniFile)
SysRefresh()
MsgWait("Reindexación completada.",,2)
endif
SysRefresh()
oDlg:End()
return(NIL)
//----------------------------------------------------------------
Function IntegIndex( oSay2,oMeter1,oMeter2,oSay3,nTotReg,Campos,cNombIndice )
oSay2:SetText( "Integrando Indice " + cNombIndice )
oMeter1:SetRange(0,RecCount())
INDEX ON &(Campos) TO &(cNombIndice);
EVAL( oMeter1:SetPos( RecNo() ),oMeter2:SetPos(nTotReg+RecNo()), oSay3:SetText( "Registros Indexados: "+Transform(nTotReg+RecNo(),"99,999,999") ), SysRefresh() )
(),"99,999,999") ), SysRefresh() )
nTotReg+=RecCount()
Return nil
Saludos.
FranciscoA