A Class for DBF

You can share your experience with HMG. Share with some screenshots/project details so that others will also be benefited.

Moderator: Rathinagiri

Post Reply
brunellopulix
Posts: 73
Joined: Sat Apr 24, 2010 10:17 am

A Class for DBF

Post by brunellopulix »

Hello to all
sometimes I feel the need to review the code I wrote some years ago. I found one that could be interesting for someone and I want to share it with you.
A class written for dbf.

#INCLUDE "HBGTINFO.CH"
*
#include 'dbfserver.prg'
#include 'customer.prg'
*
Request DBFCDX
REQUEST HB_GT_WVT_DEFAULT
*
Procedure Main()
Local cDbf := hb_CurDrive()+':\'+CurDir()+'\'+'Customer'
Local lShared := .F.
Local cAlias := nil // default
Local cRDD
Local oCustomer
Local nIndex
Local nChoice := 1
Local aExt := {'CDX','NTX'}
Local cExt := ''
Local aBlock := {}
Local nRec
*
* ALTD() // debug
*
nChoice := Alert('What driver?',aExt)
If nChoice > 0
cExt := aExt[nChoice]
Endif
*
aBlock := {{|o| Str(o:Recno(),4)+' '+Trim(o:FirstName)+' '+Trim(o:LastName)},{|o| Str(o:Recno(),4)+' '+Trim(o:LastName)+' '+Trim(o:FirstName)}}
cRDD := 'DBF'+cExt
*
oCustomer := Customer():New(cDbf+'.Dbf',lShared,cAlias,cRDD)
If cExt == 'CDX'
If !File(cDbf+'.'+cExt)
oCustomer:AddIndex(cDbf+'.'+cExt,'FIRSTNAME')
oCustomer:AddIndex(cDbf+'.'+cExt,'LASTNAME' )
oCustomer:AddIndex(cDbf+'.'+cExt,'CUSTNUM' )
oCustomer:Reindex()
Endif
oCustomer:SetIndex(cDbf+'.'+cExt)
*oCustomer:SetOrder(2)
oCustomer:OrdSetFocus('LASTNAME')
elseif cExt == 'NTX'
If !File(cDbf+'1.'+cExt)
oCustomer:AddIndex(cDbf+'1.'+cExt,'FIRSTNAME')
oCustomer:AddIndex(cDbf+'2.'+cExt,'LASTNAME' )
oCustomer:AddIndex(cDbf+'3.'+cExt,'CUSTNUM' )
oCustomer:Reindex()
Endif
oCustomer:SetIndex(cDbf+'1.'+cExt)
oCustomer:SetIndex(cDbf+'2.'+cExt)
oCustomer:SetIndex(cDbf+'3.'+cExt)
oCustomer:SetOrder(1)
Endif
*
Set Alternate ON
**************************************************************************
oCustomer:gotop()
********************** Copy *******************************************
* oCustomer:CopyDb('Cust1.dbf') // Tested => OK
* oCustomer:CopySdf('Cust1.Txt') // Tested => OK
* oCustomer:CopyStructure('Cust2.Dbf') // Tested => OK
********************** zap - Pack *************************************
* oCustomer:Zap() // Tested => OK
* oCustomer:Pack() // Tested => OK
********************** Append *****************************************
* oCustomer:AppendDb('Cust1.Dbf') // Tested => OK
* oCustomer:AppendSdf('Cust1.Txt') // Tested => OK
********************** Set Filter *************************************
* oCustomer:SetFilter({|| Left(FirstName,1) == 'M' }) // Tested => OK
* oCustomer:SetFilter({|| Trim(FirstName) == 'Carla' })// Tested => OK
********************** Clear Index ************************************
/*
oCustomer:ClearIndex() // Tested => OK
alert(str(oCustomer:IndexOrd())) // == 0
oCustomer:SetIndex(cDbf+'.'+cExt)
oCustomer:SetOrder(2)
alert(str(oCustomer:IndexOrd())) // == 2
*/
*********************** Locate ***************************************
/*
nRec := oCustomer:Recno()
oCustomer:Locate({||Trim(oCustomer:Lastname)=='Lennon'}) // Tested => OK
*
If !oCustomer:Eof()
Alert('ok! Lastname => '+Trim(oCustomer:Lastname)+' Found!')
*Alert(str(oCustomer:Recno()))
*if oCustomer:Rlock()
* oCustomer:FirstName('John')
* oCustomer:Unlock()
*Endif
else
Alert('No Found!')
*oCustomer:Append()
*oCustomer:FIRSTNAME('Sean')
*oCustomer:LASTNAME('Lennon')
Endif
oCustomer:Goto(nRec)
*/
*********************** Seek ***************************************
* oCustomer:Seek('Lennon') // Tested => OK
**********************************************************************
oCustomer:gotop()
*
Qout('----------Driver DBF'+cExt+'----------')
*
nIndex := oCustomer:IndexOrd()
Qout('----------Order => '+oCustomer:IndexKey())
Do while !oCustomer:EOF()
Qout(eval(aBlock[nIndex],oCustomer))
oCustomer:dbskip()
Enddo
wait
oCustomer:Close()
*
Set Alternate OFF
*
Return
*

regards
Brunello
Attachments
DbfServer.zip
(9.74 KiB) Downloaded 319 times
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: A Class for DBF

Post by bpd2000 »

Thank you for sharing
BPD
Convert Dream into Reality through HMG
User avatar
danielmaximiliano
Posts: 2607
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: A Class for DBF

Post by danielmaximiliano »

Thank you for sharing
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
ASESORMIX
Posts: 189
Joined: Thu Oct 25, 2012 8:08 pm
Location: Bqto, Venezuela

Re: A Class for DBF

Post by ASESORMIX »

Gracias por compartir tu trabajo.
brunellopulix
Posts: 73
Joined: Sat Apr 24, 2010 10:17 am

Re: A Class for DBF

Post by brunellopulix »

Hello

a small adjustment change the new method with this:

Method New(cDbf,lShared,alias,cRDD) Class DbfServer
Static nC := 0
*
hb_Default(@lShared,FALSE)
HB_Default(@alias ,'DB'+strzero(++nC,4))
HB_Default(@cRDD ,'DBFCDX')
*
::Shared := lShared
::alias := ""
::aIndexes := {}
*
dbUseArea( TRUE ,cRDD,cDbf,alias,::Shared, FALSE )
::alias := alias()
*
Return self


Regards
Brunello
User avatar
Steed
Posts: 427
Joined: Sat Dec 12, 2009 3:40 pm

Re: A Class for DBF

Post by Steed »

thanks
Post Reply