FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Funci贸n para indexar
Posts: 133
Joined: Fri Nov 30, 2007 11:34 AM

Funci贸n para indexar

Posted: Thu Oct 02, 2008 11:48 AM

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.

Saludos. Fernando
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM

Funci贸n para indexar

Posted: Thu Oct 02, 2008 12:01 PM
Jo茫o Santos - S茫o Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 133
Joined: Fri Nov 30, 2007 11:34 AM

Funci贸n para indexar

Posted: Thu Oct 02, 2008 04:58 PM

Gracias Karinha, probar茅.

Un saludo.

Saludos. Fernando
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM

Re: Funci贸n para indexar

Posted: Fri Oct 03, 2008 01:44 PM
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
Francisco J. Alegr铆a P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 58
Joined: Thu Aug 14, 2008 09:35 PM

Re: Funci贸n para indexar

Posted: Sun Oct 05, 2008 05:11 AM
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.



MsgMeter({|oMeter,oText,oDlg,lEnd|;
CrearInd(oMeter,oText,oDlg,@lEnd,aBas)},;
"","Creando Indices")

Return(NIL)

*************************************************************
/*

Funci贸n CrearInd()

*/

Function CrearInd(oMeter,oText,oDlg,lEnd,aBas)
Local nPor,aInd,nBas,nTot,nLargo,i,cDir
Field RUTCLI,NOMCLI,DIRCLI,MARCA,MODELO,PATENTE,NUMLIQ,FECHA,CODIGO,FACNUM,FACFE,RUTPRO,BOLNUM,BOLFE
Field REPAR,DETALLE,CARGOS,ABONOS,COMUNA,CIUDAD,PRVRUT,PRVNOM,PRVGIR,PRVDIR,NUMDOC,NUMFAC,FEFAC,CLIGIR
Field MARCAVE,FEVENCI,RUT

cDir:=Alltrim(cDirBas)+""

aInd:={{1,"PROV01","PRVRUT" ,{|| PRVRUT}},;
{1,"PROV02","PRVNOM" ,{|| PRVNOM}},;
{1,"PROV03","PRVGIR" ,{|| PRVGIR}},;
{1,"PROV04","PRVDIR" ,{|| PRVDIR}},;
.
.
// todas los indices por tabla. Es para NTX pero tambien te sirve para CDX
.
.


for i=1 to Len(aInd)
if File(cDir+aInd[i,2]+".NTX")
FErase(cDir+aInd[i,2]+".NTX")
endif
next

nPor:=5.26
nBas:=1
nTot:=100
nLargo:=Len(aInd)
oMeter:=nTot
oMeter:Set( nPor )

while nPor<=nTot .and. nBas<=19 .and. !lEnd
Memory(-1)
if aBas[nBas,1]
oText:SetText("Creando Indices de "+aBases[nBas])

DBUSEAREA(.T.,,cDir+aNomBas[nBas]) // Nombre de las tablas

for i=1 to nLargo
if nBas=aInd[i,1]
DBCreateIndex(cDir+aInd[i,2],aInd[i,3],aInd[i,4])
endif
next
DBCloseAll()
nPor+=5.26
oMeter:Set( nPor )
endif
nBas++
SysRefresh()
end

if lEnd
MsgBeep()
MsgStop("! Reordenamiento Detenido por Usuario !","Precauci贸n")
endif

Return(NIL)


Ojala te sirva

Saludos

Waldemar
Santiago Chile
隆 Dios es nuestra fortaleza !
Posts: 133
Joined: Fri Nov 30, 2007 11:34 AM

Funci贸n para indexar

Posted: Mon Oct 06, 2008 09:31 AM

Muchas gracias por la informaci贸n.

Un saludo.

Saludos. Fernando

Continue the discussion