Lookup method of Tdatabase

Re: Lookup method of Tdatabase

Postby Silvio.Falconi » Tue Aug 17, 2021 9:26 am

sent a new demo reserva.dbf
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: Lookup method of Tdatabase

Postby Silvio.Falconi » Tue Aug 17, 2021 10:00 am

Antonio Linares wrote:James,

very good finding

many thanks


Antonio congratulations for the new look, you look like santa claus ( fivewin's Santa claus)

Anyway I don't think the error is that i don't think at all that the function makes mistake for those wrong records, anyway tonight I recreated a new demo archive and I'm trying IsFree ()
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: Lookup method of Tdatabase

Postby Antonio Linares » Tue Aug 17, 2021 3:04 pm

thank you :-D

I am trying to get a better quality photo with 80x80 pixels from this one. Maybe someone could help ?

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Lookup method of Tdatabase

Postby cnavarro » Tue Aug 17, 2021 5:14 pm

Image
Mejor calidad es difícil
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Lookup method of Tdatabase

Postby Silvio.Falconi » Tue Aug 17, 2021 10:34 pm

I tested a small sample with one record on archive

as you an see here

Image

on Edit I check ( when I change the date or type or number)

lFreeRoom:= Isfree(cCamera,cTypeRoom,ddcheckout,ddcheckin,oPrenotazioni)


Code: Select all  Expand view  RUN
Function Isfree(cCamera,cTypeRoom,dCheckOut,dCheckIn,oPrenotazioni)
local lreturn :=.f.
local cSearch := oPrenotazioni:ApplyParams( "ROOM_ID == ? .AND. ALLTRIM(TYPE) == ? .AND. RECNO() != ? .AND. (CHECK_IN > ? .OR. CHECK_OUT < ? )", ;
            { cCamera, ALLTRIM( cTypeRoom ), oPrenotazioni:RecNo(), dCheckOut, dCheckIn } )

if oPrenotazioni:LookUp( cSearch, nil, { || .T. } ) == .T.
   ? "room is available"
   lreturn :=.t.
else
   ? "room is not availble"
   lreturn :=.f.
endif
return lreturn
 



give me the message "room is not availble"
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: Lookup method of Tdatabase

Postby cnavarro » Tue Aug 17, 2021 11:37 pm

Sorry Silvio
Code: Select all  Expand view  RUN

            { cCamera, ALLTRIM( cTypeRoom ), oPrenotazioni:RecNo(), dCheckOut, dCheckIn }
 

You don't think this line should be
Code: Select all  Expand view  RUN

            { cCamera, ALLTRIM( cTypeRoom ), oPrenotazioni:RecNo(), dCheckIn, dCheckOut }
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Lookup method of Tdatabase

Postby James Bott » Wed Aug 18, 2021 12:07 am

CNavarro,

You don't think this line should be:
Code: Select all  Expand view  RUN
{ cCamera, ALLTRIM( cTypeRoom ), oPrenotazioni:RecNo(), dCheckIn, dCheckOut }


Originally, I thought this also, but it gets evaluated like this:
Code: Select all  Expand view  RUN
... .and. ( oPrenotazioni:Check_IN > dCheck_OUT .or. oPrenotazioni:Check_OUT < dCheck_IN )


Thus it is checking to see that the proposed check_IN is less than the check_OUT of the record being evaluated OR the proposed check_OUT is less than the check_IN date of the record being evaluated. I know it is hard to grasp, but it only wants to know if there is no overlap in the reservation time. If it meets either one of the above tests, then it does not overlap.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Lookup method of Tdatabase

Postby Enrico Maria Giordano » Wed Aug 18, 2021 10:07 am

Antonio Linares wrote:I am trying to get a better quality photo with 80x80 pixels from this one. Maybe someone could help ?


Look at your mailbox and let me know.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Lookup method of Tdatabase

Postby Antonio Linares » Wed Aug 18, 2021 12:21 pm

Thank you Enrico!
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Lookup method of Tdatabase

Postby nageswaragunupudi » Thu Aug 19, 2021 5:03 pm

Mr. Silvio

I modified the test.prg sent by you.
Please try this.
I am sure the results are correct.
Code: Select all  Expand view  RUN
#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.

   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, 8 GROUP oGrp TO 140, 268 OF oDlg PIXEL

   @  24, 20 SAY "Number:" OF oDlg SIZE 52, 16 PIXEL FONT oFont
   @  20, 94 GET aGet[1]  VAR oRec:Rooms_Id  PICTURE "9999" OF oDlg SIZE 40, 24 PIXEL FONT oFont

   @  52, 20 SAY "Type:" OF oDlg SIZE 36, 16 PIXEL FONT oFont
   @  48, 94 GET aGet[2]  VAR oRec:Type   PICTURE "99" OF oDlg SIZE 20, 24 PIXEL FONT oFont

   @  80, 20 SAY "Check In:" OF oDlg SIZE 54, 16 PIXEL FONT oFont
   @  76, 94 DTPICKER aGet[3]  VAR oRec:Check_In OF oDlg SIZE 108, 24 PIXEL FONT oFont

   @ 108, 20 SAY "Check Out:" OF oDlg SIZE 64,16 PIXEL FONT oFont
   @ 104, 94 DTPICKER aGet[4]  VAR oRec:Check_Out OF oDlg SIZE 108, 24 PIXEL FONT oFont   ;

   @ 148,  8 SAY oSay PROMPT cText SIZE 260,24 PIXEL OF oDlg 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

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

Image
Regards

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

Re: Lookup method of Tdatabase

Postby James Bott » Thu Aug 19, 2021 5:20 pm

Nages,

Hmm, is there something different about the above two postings you made, or are they the same and you accidentally posted it twice?
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Lookup method of Tdatabase

Postby Otto » Thu Aug 19, 2021 5:24 pm

Dear Mr. Rao,
Thank you for this nice sample. Would you be so kind to post the dbf structure?
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6342
Joined: Fri Oct 07, 2005 7:07 pm

Re: Lookup method of Tdatabase

Postby nageswaragunupudi » Thu Aug 19, 2021 5:28 pm

James Bott wrote:Nages,

Hmm, is there something different about the above two postings you made, or are they the same and you accidentally posted it twice?

Same posting got posted twice. I don't know why. I deleted one of them now.
Regards

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

Re: Lookup method of Tdatabase

Postby James Bott » Thu Aug 19, 2021 5:35 pm

Otto:

Code: Select all  Expand view  RUN
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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Lookup method of Tdatabase

Postby Otto » Thu Aug 19, 2021 6:47 pm

James,
thank you.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6342
Joined: Fri Oct 07, 2005 7:07 pm

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 58 guests