edit a record with tdatabase - I am in trouble

edit a record with tdatabase - I am in trouble

Postby Silvio.Falconi » Fri Jun 18, 2021 7:58 am

I state I can not use an xbrowse to get the record so I have to search the archive first before to make the modify

I select an obtn where I save a cargo with many info

local cNumPre :=oBtn:cargo[28]

//open the database and order on Invoice number
oReserva:=Tdatabase():Open(,::cDbfPath + "Reserva" ,"DBFCDX", .t.)
oReserva:setOrder("res_pre" ) // field invoice ( string 16 cr)

nInvoice:= ALLTRIM(cNumPre) I havethis infor from oBtn:cargo

If oReserva:seek(nInvoice) //search

//here i must create the record
oPrenota:= :=oReserva:record() // it is sure I stay on the same record of the invoice ?

else
Msginfo("invoice not found")
return nil
Endif

I tried and allway return error not found
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: edit a record with tdatabase - I am in trouble RESOLVED !!

Postby Silvio.Falconi » Fri Jun 18, 2021 8:26 am

Sorry I not had the index on "res_pre"
discovered the mystery


a question

when i define the opening of the database i have

Code: Select all  Expand view  RUN
CLASS TReserva from TXData
   METHOD New()
ENDCLASS

METHOD New( lShared ) CLASS TReserva
   Default lShared := .t.
   ::super:Open(,::cDbfPath + "Reserva" ,"DBFCDX", lShared)
   if ::use()
      ::setOrder(1)
      ::gotop()
   endif
   RETURN Self


could i create another method for order search? example

METHOD SearchInvoice(nInvoice,oPre,oRes) CLASS TReserva
local oRes,lReturn:=.f.

oRes:setOrder(res_pre)
If oRes:seek(Invoice)
oPre:=:=oRes:record()
lreturn :=.t.
else
msginfo("error")
endif
return lreturn :=.t.


and from the program I could automatically recall the record through the method created?

oRes:=Treserva():New()

If oReserva:searchInvoice(nInvoice,oPre,oRes)

....

any suggestions please
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: edit a record with tdatabase - I am in trouble

Postby nageswaragunupudi » Mon Jun 21, 2021 7:33 pm

Code: Select all  Expand view  RUN
#include "fivewin.ch"

REQUEST DBFCDX

static cSeek

//----------------------------------------------------------------------------//

function Main()

   local oStates, lFound := .f.
   local cExePath    := cFilePath( ExeName() )
   local cSeek       := "NY"

   SetGetColorFocus()

   oStates  := TDataBase():Open( nil, cExePath + "STATES", "DBFCDX", .t. )
   if oStates:Used()  // USED(). NOT USE()

      oStates:bEdit := { |oRec| EditStates( oRec, cSeek ) }

      do while MsgGet( "Enter", "STATE CODE", @cSeek )

         cSeek    := UPPER( PADR( cSeek, 2 ) )
         lFound   := .f.
         oStates:LookUp( cSeek, "CODE", { |oDbf| lFound := .t., oDbf:Load(), oDbf:Edit() } )
         oStates:Load()
         if !lFound
            oStates:Edit( .t. )
         endif

      enddo

   else
      ? "STATES.DBF not opened"
   endif

return nil

//----------------------------------------------------------------------------//

function EditStates( oRec, cCode )

   local oDbf     := oRec:uSource
   local oBrw     := oRec:oBrw
   local lNew     := ( oRec:RecNo == 0 )
   local lEdited  := .f.
   local oDlg, oFont

   if lNew
      oRec:Code   := cCode
   endif

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 350,170 PIXEL TRUEPIXEL FONT oFont ;
      TITLE If( lNew, "ADD NEW STATE", "EDIT STATE" )

   @  30, 20 SAY "State Code" SIZE 100,24 PIXEL OF oDlg
   @  60, 20 SAY "State Name" SIZE 100,24 PIXEL OF oDlg

   @  30,120 GET oRec:Code PICTURE "@!" SIZE 50,24 PIXEL OF oDlg VALID ;
      If( " " $ oRec:Code, ( MsgInfo( "Empty" ), .f. ), ;
      If( oDbf:LookUp( oRec:Code, "CODE", { || RECNO() != oRec:RecNo } ) == .t., ;
            ( MsgInfo( "DUPLICATE" ), .f. ), .t. ) )

   @  60,120 GET oRec:Name SIZE 200,24 PIXEL OF oDlg CASE PROPER ;
      VALID LEN( TRIM( oRec:Name ) ) > 5

   @ 120, 20 BUTTON "Save" SIZE 100,30 PIXEL OF oDlg WHEN oRec:Modified() ;
      ACTION ( lEdited := oRec:Save(), oDlg:End() )

   @ 120,230 BUTTON "Cancel" SIZE 100,30 PIXEL OF oDlg ACTION oDlg:End()

   oDlg:bPainted := { || oDlg:Box( 10, 10, 100, 340, { If( lNew, CLR_HRED, CLR_HBLUE ), 2 } ) }

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return lEdited

//----------------------------------------------------------------------------//
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: edit a record with tdatabase - I am in trouble

Postby nageswaragunupudi » Mon Jun 21, 2021 7:33 pm

Code: Select all  Expand view  RUN
#include "fivewin.ch"

REQUEST DBFCDX

static cSeek

//----------------------------------------------------------------------------//

function Main()

   local oStates, lFound := .f.
   local cExePath    := cFilePath( ExeName() )
   local cSeek       := "NY"

   SetGetColorFocus()

   oStates  := TDataBase():Open( nil, cExePath + "STATES", "DBFCDX", .t. )
   if oStates:Used()  // USED(). NOT USE()

      oStates:bEdit := { |oRec| EditStates( oRec, cSeek ) }

      do while MsgGet( "Enter", "STATE CODE", @cSeek )

         cSeek    := UPPER( PADR( cSeek, 2 ) )
         lFound   := .f.
         oStates:LookUp( cSeek, "CODE", { |oDbf| lFound := .t., oDbf:Load(), oDbf:Edit() } )
         oStates:Load()
         if !lFound
            oStates:Edit( .t. )
         endif

      enddo

   else
      ? "STATES.DBF not opened"
   endif

return nil

//----------------------------------------------------------------------------//

function EditStates( oRec, cCode )

   local oDbf     := oRec:uSource
   local oBrw     := oRec:oBrw
   local lNew     := ( oRec:RecNo == 0 )
   local lEdited  := .f.
   local oDlg, oFont

   if lNew
      oRec:Code   := cCode
   endif

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 350,170 PIXEL TRUEPIXEL FONT oFont ;
      TITLE If( lNew, "ADD NEW STATE", "EDIT STATE" )

   @  30, 20 SAY "State Code" SIZE 100,24 PIXEL OF oDlg
   @  60, 20 SAY "State Name" SIZE 100,24 PIXEL OF oDlg

   @  30,120 GET oRec:Code PICTURE "@!" SIZE 50,24 PIXEL OF oDlg VALID ;
      If( " " $ oRec:Code, ( MsgInfo( "Empty" ), .f. ), ;
      If( oDbf:LookUp( oRec:Code, "CODE", { || RECNO() != oRec:RecNo } ) == .t., ;
            ( MsgInfo( "DUPLICATE" ), .f. ), .t. ) )

   @  60,120 GET oRec:Name SIZE 200,24 PIXEL OF oDlg CASE PROPER ;
      VALID LEN( TRIM( oRec:Name ) ) > 5

   @ 120, 20 BUTTON "Save" SIZE 100,30 PIXEL OF oDlg WHEN oRec:Modified() ;
      ACTION ( lEdited := oRec:Save(), oDlg:End() )

   @ 120,230 BUTTON "Cancel" SIZE 100,30 PIXEL OF oDlg ACTION oDlg:End()

   oDlg:bPainted := { || oDlg:Box( 10, 10, 100, 340, { If( lNew, CLR_HRED, CLR_HBLUE ), 2 } ) }

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return lEdited

//----------------------------------------------------------------------------//
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: edit a record with tdatabase - I am in trouble

Postby Armando » Mon Jun 21, 2021 7:38 pm

Mr. Rao:

BTW, is there a class as TDataBase, but for MySQL?

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3229
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: edit a record with tdatabase - I am in trouble

Postby nageswaragunupudi » Mon Jun 21, 2021 7:50 pm

Yes.
FWH has a built-in library for MySQL.
Can connect to MySql, open tables, and use them just like TDatabase.

Full documentation:
viewtopic.php?f=3&t=33286

If you are already using ADO for MySQL, you can use TRecSet class, which works similarly to TDatabase.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: edit a record with tdatabase - I am in trouble

Postby Armando » Mon Jun 21, 2021 9:07 pm

Mr. Rao:

Thank you, I Will try it.

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3229
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: edit a record with tdatabase - I am in trouble

Postby Silvio.Falconi » Tue Jun 22, 2021 7:39 am

nageswaragunupudi wrote:




thanks for the sample test but I must search a string on field Invoice this string is 13 Cr
before i couldn't find the data because i didn't order for the index i needed now it's ok

now I'm here asking you something else

once I have found the record in the Reserva.dbf file I have to load all the data I need for the reservation,
in particular I should also search for invoice in the oRigheInvoice archive which would be the lines of the invoice body,
and I have them different fields and for now I have done in the traditional method that is with do while / adddd () / endo

so I have to populate an array to put in the xbrowse as you can seeon this picture

Image

in this array I have exactly 18 fields

my problem now is to save

i.e. for the reserva.dbf archive i.e. for the fields of the invoice header I have no problem,
instead I am afraid for the aData array that must be saved in the oRigheInvoice archive,
which for the first entry there is no problem for the modification I do not know how to do


Since I cannot pack I had thought of deleting the records that had invoice = nInvoice
and then inserting the new records but in doing so the archive becomes very large until the maintenance
operation by the administrator who can operate with archives in exclusive mode and will be able to pack the archive.



Or I have to come up with some other system that is what I saw on yunus.prg but I have not been able to implement it


in yunus' editinvoice function I saw that to load the records you do this

aItems := IIT->( FW_DbfToArray( cItemFlds, { || IIT->INVNUM == oRec:InvNum } ) )


I changed this line

static cItemFlds := "INVNUM,SERIAL,ITEMCODE,ITEMNAME,QUANTITY,UNIT,PRICE,DISCOUNT,RECNO()"

into

static cItemFlds := "ICO,TIPO,DESC,QTA,PREUNI,TOTQTA,DATAINI,DATAFIN,GIORNI,SCONTO,TOTALE,INVOICE,PRINTA4,PRINTPOS,STRUCTURE,BREVEDESC,PREZZOBASE,SERIAL,RECNO()"


how do i translate it into tdatabase?
I tried with
aData := oRigheInvoice:DbfToArray( cItemFlds, { || oRigheInvoice:Invoice == oRecPrenota:Invoice } )
but it not load any records
aData := oRigheInvoice:DbfToArray( cItemFlds, { || alltrim(oRigheInvoice:Invoice) == nInvoice } )
load all records from oRigheInvoice


then before save the array there is a part on source I not understood from this

WITH OBJECT oBrw

---

END


then I made the same from if lSave /endif but here make me error
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: edit a record with tdatabase - I am in trouble

Postby Silvio.Falconi » Tue Jun 22, 2021 10:47 am

Nages,
Now I found the solution
I can load to adata the records with

Code: Select all  Expand view  RUN
aData := oRigheInvoice:DbfToArray( cItemFlds, { || FIELD->Invoice ==alltrim(nInvoice) } )


Image

if I delete a rows on xbrowse
then the procedure not delete the record on save

Code: Select all  Expand view  RUN

static cItemFlds := "ICO,TIPO,DESC,QTA,PREUNI,TOTQTA,DATAINI,DATAFIN,GIORNI,SCONTO,TOTALE,INVOICE,PRINTA4,PRINTPOS,STRUCTURE,BREVEDESC,PREZZOBASE,SERIAL,RECNO()"




            if ! Empty( oBrowse:aDeleted )
                   AEval( oBrowse:aDeleted, { |a| a[ 19 ] := -a[19 ] } )
                   oRigheInvoice:ArrayToDBF( cItemFlds, oBrowse:aDeleted )
                endif

 



I checked it , if I delete a row of browse I see on obrowse:adeleted the record

NOt save the SERIAL number and not save the invoice number

Code: Select all  Expand view  RUN
               AEval( aData, { |a| a[ 12 ] := oRecPrenota:Invoice } )  // invoice number
                AEval( aData, { |a,i| a[ 18 ] := i } )       // serial not run


if I take the same record, if I had deleted a line, I should have the invoice without that line and instead nothing has changed, having the same lines of the invoice I had before

How do I resolve?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests