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: 39
Joined: Sat Apr 24, 2010 10:17 am
Been thanked: 5 times

A Class for DBF

Post by brunellopulix » Fri Jun 08, 2018 2:38 pm

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 70 times

User avatar
bpd2000
Posts: 1013
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 163 times
Been thanked: 70 times

Post by bpd2000 » Sat Jun 09, 2018 4:24 am

Thank you for sharing
BPD
Convert Dream into Reality through HMG

User avatar
danielmaximiliano
Posts: 2078
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Has thanked: 114 times
Been thanked: 15 times
Contact:

Post by danielmaximiliano » Sat Jun 09, 2018 7:20 pm

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

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. : +54901169026142
Telegram Name : DaNiElMaXiMiLiAnO

ASESORMIX
Posts: 73
Joined: Thu Oct 25, 2012 8:08 pm
Location: Bqto, Venezuela
Been thanked: 6 times

Post by ASESORMIX » Tue Jun 12, 2018 5:57 pm

Gracias por compartir tu trabajo.

brunellopulix
Posts: 39
Joined: Sat Apr 24, 2010 10:17 am
Been thanked: 5 times

Post by brunellopulix » Fri Jun 15, 2018 7:06 am

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: 319
Joined: Sat Dec 12, 2009 3:40 pm
Been thanked: 2 times

Post by Steed » Thu Jun 21, 2018 1:28 am

thanks

Post Reply