FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour strange problem with tdatabase
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
strange problem with tdatabase
Posted: Sat Aug 10, 2019 10:37 AM
I must erase all record of an invoice number ( the filed is 13cr)
Local nInvoice := "1234567890128"
the oPartres dbf is index on INDEX ON RESITEMS->INVNUM + STR( SERIAL, 3, 0 ) TAG invnum TO resitems

oPartres:=TDatabase():Open( , cDir+"ResItems", "DBFCDX", .T. )
oPartres:setorder(1)
oPartres:gotop()

oPartRes:Gotop()
Do While .not. oPartRes:eof()
IF alltrim(oPartRes:InvNum) == alltrim(nInvoice)
// Msginfo( oPartRes:InvNum ,nInvoice)
oPartRes:delete()
Endif
oPartRes:skip()
EndDo
oPartRes:Gotop()

SET DELETED ON
oPartRes:SetOrder( 0 )
oPartRes:GoTo( 1 )
oPartRes:ArrayToDBF( aItems, cItemFlds, nil, .t., .t. )

it save goog but erased all records
I wish save on dbf with the condition alltrim(oPartRes:InvNum) == alltrim(nInvoice

Any solution please ...
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: strange problem with tdatabase
Posted: Sat Aug 10, 2019 11:12 AM
Perhaps I resolve but I not Know it it is correct

Code (fw): Select all Collapse
    SET DELETED  ON
    oPartRes:setorder(0)
    oPartRes:Exec( < ||
    SET FILTER TO AllTrim( FIELD->INVNUM ) = alltrim(nInvoice)
   return nil
   > )
    oPartRes:gotop()
    oPartRes:ArrayToDBF( aItems, cItemFlds,nil , .t., .t. )
    oPartRes:SetFilter( "" )

any suggestion ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: strange problem with tdatabase
Posted: Sat Aug 10, 2019 11:35 PM

I must erase all record of an invoice number

If you want to delete all records where the field INVNUM == nInvoice, i.e., "1234567890128", then:
[code]
Local nInvoice := "1234567890128"

oPartres:Exec( <||
DELETE ALL FOR ALLTRIM(FIIELD->INVNUM) == nInvoice
> )
[code]
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: strange problem with tdatabase
Posted: Sun Aug 11, 2019 01:59 AM
You want to read all records relating to one invoice, add/edit/delete in memory and save all changes at once to the database.

FWH1907 simplifies the entire process.

Code (fw): Select all Collapse
oBatch := oPartRes:ReadBatch( { "INVNUM", nInvoice } )
// oBatch is like a mini Tdatabase
// Browse, Edit, Append, Delete records in oBatch
// All changes are made in memory only and not written to database
// When you want to write all changes, call
oBatch:SaveBatch()

//If you change the invoice number in the main table
oBatch:Load( { "INVNUM", nInvoce } ) // loads records of new invoice number

Please wait for a sample
Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: strange problem with tdatabase
Posted: Sun Aug 11, 2019 09:58 AM
Nages
I must use an array for the invoice body (xbrowse) where the first line (which cannot be deleted by the user only it can be modified) is like a repetition of the element described in the header ( saved on Reserva.dbf) for example:

HEADER


BODY


then the other lines of body are the services associated to this element





when the user change something of the first line of Xbrowse ( for a sample the dates) the procedure must change also the header

I need this solution because I have to enter the price of the item (ie the first line of the xbrowse) and then the prices of the other lines (services)
Reserva.dbf must have only the element number the arrival and departure dates the total cost and the customer, while in detail (resItems.dbf) there must be all the prices of both the element and the services associated with the element

doing so I do not know if I should save all the lines of the body or delete the first line and insert it again to the modification

I have big problems with the rescue now I'm trying this solution

1) delete all records on resItems.dbf having the same invoice number
2) re-enter the invoice item on resItems.dbfs from the aItems array

but I did not understand if it is correct to do this, or there is another method

then I have the problem of the lock record in reserva that is

1) I have to take the record on reserva.dbf
2) upload the invoice details to aItems
3) work on xbrowse
4) save on Resitems.dbf
5) save the record on reserva.dbf
6) unlock the record on reserva.dbf

but I still haven't figured out how I can do it
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: strange problem with tdatabase
Posted: Sun Aug 11, 2019 06:37 PM
nageswaragunupudi wrote:

I must erase all record of an invoice number

If you want to delete all records where the field INVNUM == nInvoice, i.e., "1234567890128", then:
Code (fw): Select all Collapse
Local nInvoice := "1234567890128"

oPartres:Exec( <||
   DELETE ALL FOR ALLTRIM(FIIELD->INVNUM) == nInvoice
   > )
[code][/quote]

Error
[code]Application
===========
   Path and name: C:\Work\Errori\aarray_dlg_invoice\test.Exe (32 bits)
   Size: 4,024,320 bytes
   Compiler version: Harbour 3.2.0dev (r1904111533)
   FiveWin  version: FWH 19.05
   C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
   Windows version: 6.2, Build 9200 

   Time from start: 0 hours 0 mins 3 secs 
   Error occurred at: 11-08-2019, 20:36:04
   Error description: Error DBFCDX/1022  Richiede un Lock

Stack Calls
===========
   Called from:  => DBDELETE( 0 )
   Called from:  => (b)EVAL( 387 )
   Called from:  => DBEVAL( 0 )
   Called from: test.prg => (b)TEST_INVOICE( 387 )
   Called from: .\source\classes\DATABASE.PRG => (b)TDATABASE( 140 )
   Called from: .\source\classes\DATABASE.PRG => TDATABASE:EXEC( 0 )
   Called from: test.prg => TEST_INVOICE( 388 )
   Called from: test.prg => MAIN( 46 )
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion