Lookup method of Tdatabase

User avatar
Silvio.Falconi
Posts: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: Lookup method of Tdatabase

Post by Silvio.Falconi »

nageswaragunupudi wrote:Mr. Silvio

I modified the test.prg sent by you.
Please try this.
I am sure the results are correct.


Nages,
I thank you , I tried your sample with an empty dbf and run ok

BUT
instead of the xbrowse I have a planning beach where I have placed all the elements to rent

I have a beach planning where I have many btnbmps and I open the dialog of edit from each buttons

I had created that test.prg just to understand the problem and why the isfree function with lookup made a mistake

Image

from the planning beach I press a button with the mouse (btnbmp) and open the dialog for entering or modifying the reservation

in each btnbmp I have saved some information in cargo such as the INVOICE reservation number

So I cannot open function Edit_Reservation( oRec )

because I not have oRec


on my function of edit reservation I have

oPrenotazioni := TReserva():New()
oRecPrenota:=oPrenotazioni:record(.t.) // for add new
oRecPrenota:=oPrenotazioni:record() // for the edit

how do i use your method by calling it from the button ( btnbmp) ?
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
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Lookup method of Tdatabase

Post by nageswaragunupudi »

Code: Select all | Expand

oPrenotazioni := TReserva():New()
oPrenotazioni:Edit(.t.) // for add new
oPrenotazioni:Edit() // for the edit
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Lookup method of Tdatabase

Post by nageswaragunupudi »

My email to this address
otto@atzwanger.com
is not going
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio.Falconi
Posts: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: Lookup method of Tdatabase

Post by Silvio.Falconi »

nageswaragunupudi wrote:My email to this address
otto@atzwanger.com
is not going


strange
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: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: Lookup method of Tdatabase

Post by Silvio.Falconi »

nageswaragunupudi wrote:

Code: Select all | Expand

oPrenotazioni := TReserva():New()
oPrenotazioni:Edit(.t.) // for add new
oPrenotazioni:Edit() // for the edit
 


thanks
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
Otto
Posts: 6403
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 24 times
Been thanked: 2 times
Contact:

Re: Lookup method of Tdatabase

Post by Otto »

Dear Mr. Rao,
Thank you for telling me.
I see it is over quoted.
I will delete some mails.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Silvio.Falconi
Posts: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: Lookup method of Tdatabase

Post by Silvio.Falconi »

nageswaragunupudi wrote:

Code: Select all | Expand

oPrenotazioni := TReserva():New()
oPrenotazioni:Edit(.t.) // for add new
oPrenotazioni:Edit() // for the edit
 



Nages,
can you explain this ?
METHOD Record( cFieldList, lNew ) CLASS TReserva

where I found cFieldList or how I can set it ?
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: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: Lookup method of Tdatabase

Post by Silvio.Falconi »

James Bott wrote:Otto:

Code: Select all | Expand

Function genRESERVA()
   local aStruc:={}
   aadd( aStruc, { "DATE", "D",8, 0 } )
   aadd( aStruc, { "ROOMS_ID", "C",4, 0 } )
   aadd( aStruc, { "CHECK_IN", "D",8, 0 } )
   aadd( aStruc, { "CHECK_OUT", "D",8, 0 } )
   aadd( aStruc, { "STATUS", "C",2, 0 } )
   aadd( aStruc, { "TYPE", "C",2, 0 } )
   aadd( aStruc, { "FIRST", "C",15, 0 } )
   aadd( aStruc, { "LAST", "C",15, 0 } )
   aadd( aStruc, { "GUEST", "C",30, 0 } )
   aadd( aStruc, { "PHONE", "C",14, 0 } )
   aadd( aStruc, { "NUMPRE", "C",18, 0 } )
   aadd( aStruc, { "INVOICE", "C",18, 0 } )
   aadd( aStruc, { "SUBTOTAL", "N",12, 2 } )
   aadd( aStruc, { "DESCOUNT", "N",12, 2 } )
   aadd( aStruc, { "DATAPAYED", "D",8, 0 } )
   aadd( aStruc, { "DEPOSIT", "N",12, 2 } )
   aadd( aStruc, { "TOPAY", "N",12, 2 } )
   aadd( aStruc, { "TOTAL", "N",12, 2 } )
   aadd( aStruc, { "NOTE", "C",80, 0 } )
   aadd( aStruc, { "OMAGGIO", "L",1, 0 } )
   aadd( aStruc, { "LISTINO", "C",2, 0 } )
   aadd( aStruc, { "TIPODAY", "C",1, 0 } )
   aadd( aStruc, { "SECTOR", "C",1, 0 } )
   dbcreate( "RESERVA.DBF" , aStruc, "DBFCDX" )
Return nil


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

Function Reindex()
  ferase("Reserva.cdx")
  field ROOMS_ID, CHECK_IN, FIRST, LAST, TYPE, NUMPRE

  use Reserva exclusive
  index on (ROOMS_ID + DToS( CHECK_IN )) TAG "res_pre" TO RESERVA.cdx FOR ! deleted()
  index on ROOMS_ID + TYPE + DToS( CHECK_IN ) TAG "ROOMS+TYPE+CHECK_IN" TO RESERVA.cdx for ! deleted()
  index on upper(FIRST) TAG "FIRST" TO RESERVA.cdx FOR ! deleted()
  index on upper(LAST) TAG "LAST" TO RESERVA.cdx FOR ! deleted()
  index on TYPE tag "TYPE" TO RESERVA.cdx FOR ! deleted()
  index on NUMPRE TAG "NUMPRE" TO RESERVA.cdx FOR ! deleted()
  //index on ROOMS_ID + TYPE TAG "ROOM+TYPE" TO RESERVA.cdx FOR ! deleted()  // maybe not needed?
  use
Return nil




this is my structure


the original is that of Daniel Tplan class you found on samples folder of fwh


Code: Select all | Expand


 if ! File( "reserva.dbf" )

      aStructure = { { "date"     , "D",   8, 0 },;
                      { "rooms_id" , "C",   4, 0 },;
                      { "check_in" , "D",   8, 0 },;
                      { "check_out", "D",   8, 0 },;
                      { "status"   , "C",   2, 0 },;
                      { "guest"    , "C",  30, 0 } }

      DBCreate( "reserva", aStructure, "DBFCDX" )

   ENDIF

USE RESERVA ALIAS RE VIA "DBFCDX" NEW
   INDEX ON RE->ROOMS_ID + DToS( RE->CHECK_IN ) TAG room_in TO reserva

 



as you can see there is not type field
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
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Lookup method of Tdatabase

Post by James Bott »

oPrenotazioni:Edit()


I suggest that human interfaces should not be methods of a database class. One reason is that you are loading the human interface code for every copy of the database opened. Often you may have multiple copies of a database object open at the same time, and thus you would have the same edit code eating up memory for each copy.

Another possibility is that you might want to have a web interface so your edit routine would be completely different than the standard PC interface. Then you would have two interfaces in the database object and they would have to have different names. Now you would be loading code for two human interfaces for every copy of the database object that is open.

I do understand that in this case it was just for a quick and dirty test, but for normal use it is not a good idea.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Lookup method of Tdatabase

Post by nageswaragunupudi »

you are loading the human interface code for every copy of the database opened. Often you may have multiple copies of a database object open at the same time, and thus you would have the same edit code eating up memory for each copy.


Please read the class definition again.

database object and they would have to have different names


oDbf:bEdit := { |oRec| MyNewEdit( oRec ) }
oDbf:Edit()
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Lookup method of Tdatabase

Post by nageswaragunupudi »

METHOD Record( cFieldList, lNew ) CLASS TReserva

where I found cFieldList or how I can set it ?


cFieldList is an optional parameter. If you provide a list of fields, the record object (TDataRow class) will have those fields only. For full understanding, you also read the class TDataRow.

I advise you to ignore this for the time being. You just do not need this.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio.Falconi
Posts: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: Lookup method of Tdatabase

Post by Silvio.Falconi »

nageswaragunupudi wrote:
METHOD Record( cFieldList, lNew ) CLASS TReserva

where I found cFieldList or how I can set it ?


cFieldList is an optional parameter. If you provide a list of fields, the record object (TDataRow class) will have those fields only. For full understanding, you also read the class TDataRow.

I advise you to ignore this for the time being. You just do not need this.


thanks Rao
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: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: Lookup method of Tdatabase

Post by Silvio.Falconi »

Image

Rao,
I must insert a combobox instead of the get for type field

Code: Select all | Expand


 @  48, 94 COMBOBOX aGet[2] VAR nImage ITEMS aElementiItems ;
           BITMAPS aBmpCombo SIZE 98,220 PIXEL   OF oDlg HEIGHTGET 66 ;
           ON CHANGE  ( ctype:= aElementi[nImage][1],msginfo(ctype))

 


then isfree() not run ok
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: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: Lookup method of Tdatabase

Post by Silvio.Falconi »

now correct to
@ 48, 94 COMBOBOX aGet[2] VAR nImage ITEMS aElementiItems ;
BITMAPS aBmpCombo SIZE 98,220 PIXEL OF oDlg HEIGHTGET 66 ;
ON CHANGE ( ctype:= aElementi[nImage][1],Eval( bCheck ))
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: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: Lookup method of Tdatabase

Post by Silvio.Falconi »

nageswaragunupudi wrote:
METHOD Record( cFieldList, lNew ) CLASS TReserva

where I found cFieldList or how I can set it ?


cFieldList is an optional parameter. If you provide a list of fields, the record object (TDataRow class) will have those fields only. For full understanding, you also read the class TDataRow.

I advise you to ignore this for the time being. You just do not need this.



Nages,

I Insert on your test a folderex


Image

But I not compile it with Winxp theme resources





your test.prg ( with a Folder)

Code: Select all | Expand

#include "FiveWin.ch"
    #include "dtpicker.ch"

    request dbfcdx
    request dbffpt

    request hb_lang_it
    request hb_codepage_itwin

    function Main()

       RddSetDefault( "DBFCDX" )
       HB_LANGSELECT( "IT" )
       HB_SETCODEPAGE( "ITWIN" )
       SetHandleCount( 100 )
       FWNumFormat( "E", .t. )
       SetGetColorFocus()

       SET DATE FORMAT "dd-mm-yyyy"
       SET DELETED     ON
       SET CENTURY     ON
       SET EPOCH TO    year( date() ) - 20
       SET MULTIPLE    OFF

       Test()

    return nil

    //----------------------------------------------------------------------------------------------------------------------------------------------//
    function test()

       local oReserva
       local oDlg, oBar, oBrw, oFont

       oReserva := TReserva():New()
       oReserva :setorder( 0 )
       oReserva:GoTop()

    /*
       oReserva:goto(6) // nrecord number 6
       oReserva:Edit()
    */


       DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
       DEFINE DIALOG oDlg SIZE 700,400 PIXEL TRUEPIXEL FONT oFont TITLE "RESERVA"
       DEFINE BUTTONBAR oBar OF oDlg SIZE 80,32 2007

       @ 32,20 XBROWSE oBrw SIZE -200,-20 PIXEL OF oDlg DATASOURCE oReserva ;
          COLUMNS "DATE","ROOMS_ID","CHECK_IN","CHECK_OUT","STATUS","TYPE" ;
          LINES NOBORDER

       WITH OBJECT oBrw
          :nMarqueeStyle := MARQSTYLE_HIGHLROW
          :RecSelShowRecNo()
          :AddVar( "nBooked", 0 )
          :bClrStd := { || If( oBrw:BookMark == oBrw:nBooked, { CLR_WHITE, CLR_HRED }, { CLR_BLACK, CLR_WHITE } ) }
          //
          :CreateFromCode()
       END

       DEFINE BUTTON OF oBar PROMPT "New"    CENTER ACTION oBrw:EditSource( .t. )
       DEFINE BUTTON OF oBar PROMPT "Modify" CENTER ACTION oBrw:EditSource()

       ACTIVATE DIALOG oDlg CENTERED
       RELEASE FONT oFont

    return nil

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

    function Edit_Reservation( oRec )

       local oDlg, oFont, oBold, oSay, oGrp, oBtn, bCheck, cText := ""
       local aGet[4]
       local oBrw  := oRec:oBrw
       local lNew  := ( oRec:RecNo == 0 )
       local lSave := .f.
       local lFree := .t.

       local oFolder //Silvio

       DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0,-8
       oBold := oFont:Bold()

       DEFINE DIALOG oDlg SIZE 276,230 PIXEL TRUEPIXEL ;
                       TITLE If( lNew, "New","Modifica" ) + " record" FONT oFont

       @  0, 0 FOLDEREX oFolder OF oDlg SIZE 272,190 PIXEL  ;
        PROMPT "Prenotazioni" //Silvio

      // @ 0, 8 GROUP oGrp TO 140, 268 OF oDlg PIXEL

       @  5, 5 SAY "Number:" OF oFolder:aDialogs[1] SIZE 52, 10 PIXEL FONT oFont TRANSPARENT
       @  7, 57 GET aGet[1]  VAR oRec:Rooms_Id  PICTURE "9999" OF oFolder:aDialogs[1] SIZE 40, 10 PIXEL FONT oFont

       @  20, 5 SAY "Type:" OF oFolder:aDialogs[1] SIZE 36, 10 PIXEL FONT oFont  TRANSPARENT
       @  18, 57 GET aGet[2]  VAR oRec:Type   PICTURE "99" OF oFolder:aDialogs[1] SIZE 20, 10 PIXEL FONT oFont

       @  34, 5 SAY "Check In:" OF oFolder:aDialogs[1] SIZE 54, 10 PIXEL FONT oFont TRANSPARENT
       @  32, 57 DTPICKER aGet[3]  VAR oRec:Check_In OF oFolder:aDialogs[1] SIZE 68, 10 PIXEL FONT oFont

       @ 46, 5 SAY "Check Out:" OF oFolder:aDialogs[1] SIZE 64,10 PIXEL FONT oFont  TRANSPARENT
       @ 44, 57 DTPICKER aGet[4]  VAR oRec:Check_Out OF oFolder:aDialogs[1] SIZE 68, 10 PIXEL FONT oFont   ;

       @ 60,  1  SAY oSay PROMPT cText SIZE 160,10 PIXEL OF oFolder:aDialogs[1] CENTER VCENTER FONT oBold

       @ 192,  96 BUTTON oBtn PROMPT "Confirm" OF oDlg SIZE 84, 24 PIXEL FONT oFont ;
          WHEN oRec:Modified() .and. lFree ;
          DEFAULT ACTION ( lSave := .t., oDlg:End() )
       @ 192, 184 BUTTON oBtn PROMPT "Exit"    OF oDlg SIZE 84, 24 PIXEL FONT oFont ;
          CANCEL ACTION (oDlg:End())

       bCheck   := { || lFree := IsFree( oRec, oSay ), oDlg:AEvalWhen(), .t. }

       AEval( aGet, { |o| o:bValid := bCheck } )
       AEval( aGet, { |o| o:bChange := bCheck }, 3, 2 )

       ACTIVATE DIALOG oDlg CENTERED ON INIT Eval( bCheck )
       RELEASE FONT oFont, oBold

       if oBrw != nil .and. oBrw:nBooked != 0
          oBrw:nBooked   := 0
          oBrw:Refresh()
       endif

       IF lSave
         // oRec:SAVE()
       ENDIF

    return nil

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

    function Isfree( oRec, oSay )

       local lNew     := ( oRec:RecNo == 0 )
       local oDbf     := oRec:uSource
       local oBrw     := oRec:oBrw
       local lreturn := .t.
       local cSearch, nBooked := 0, hBooked

       cSearch  := "ROOMS_ID == ? .AND. ALLTRIM(TYPE) == ? .AND. RECNO() != ? .AND. " + ;
                   "CHECK_IN <= ? .AND. CHECK_OUT >= ?"

       if Empty( oRec:rooms_id ) .or. Empty( oRec:Type ) .or. Empty( oRec:check_in ) .or. ;
          Empty( oRec:check_out ) .or. oRec:check_in > oRec:check_out

          lreturn     := .f.
          oSay:VarPut( "INVALID DATA" )
          oSay:SetColor( CLR_WHITE, CLR_RED )
          oSay:Refresh()

       else
          cSearch  := oDbf:ApplyParams( cSearch, { oRec:rooms_id, oRec:type, oRec:RecNo, ;
                                                   oRec:check_out, oRec:check_in } )

          if oDbf:LookUp( cSearch, nil, { || nBooked := RECNO(), hBooked := FW_RecToHash(), .t. } ) == .t.
             lreturn  := .f.
             oSay:VarPut( "BOOKED FROM " + DTOC( hBooked[ "check_in" ] ) + " TO " + ;
                           DTOC( hBooked[ "check_out" ] ) )
             oSay:SetColor( CLR_WHITE, CLR_HRED )
             oSay:Refresh()
          elseif oRec:Modified()
             lreturn  := .t.
             oSay:VarPut( "FREE" )
             oSay:SetColor( CLR_WHITE, CLR_GREEN )
             oSay:Refresh()

          else
             lreturn  := .f.
             oSay:VarPut( "" )
             oSay:SetColor( CLR_BLACK, oSay:oWnd:nClrPane )
             oSay:Refresh()

          endif
       endif

       if oBrw != nil .and. oBrw:nBooked != nBooked
          oBrw:nBooked   := nBooked
          oBrw:Refresh()
       endif

    return lreturn

    //-------------------------------------------------------------------------------------------------------------------------------------------//
    // CLASSES
    //----------------------------------------------------------------------------//

    CLASS TXData from TDataBase
       DATA cDbfPath INIT cFilePath( ExeName() )
    ENDCLASS

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

    CLASS TReserva from TXData

       METHOD New()
       METHOD Record( cFieldList, lNew )

    ENDCLASS

    METHOD New( lShared ) CLASS TReserva

       Default lShared := .t.
       ::Super:Open(,::cDbfPath + "Reserva" ,"DBFCDX", lShared)
       if ::Used()
          ::setOrder(1)
          ::GoTop()
       endif

       ::bEdit  := { |oRec| Edit_Reservation( oRec ) }

    return Self

    METHOD Record( cFieldList, lNew ) CLASS TReserva

       local oRec  := ::Super:Record( cFieldList, lNew )

       if oRec:RecNo == 0 // lNew
          WITH OBJECT oRec
             :Rooms_id   := "0001"
             :Type       := "01"
             :Check_in   := Date()
             :Check_Out  := Date()
          END
       endif

    return oRec

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



Now, Please ,
Can you compile this test with a winxp theme ( resources) ?


Did you compile with the theme?

Do you still see the say control? ( @ 60, 1 SAY oSay PROMPT cText SIZE 160,10 PIXEL OF oFolder:aDialogs[1] CENTER VCENTER FONT oBold )
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
Post Reply