seek with tdatabase

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

seek with tdatabase

Post by Silvio.Falconi »

I must check if a room is free or not for a a range date

I made a test

Code: Select all

#include "Fivewin.ch"


request dbfcdx
request dbffpt

Function test()

*local ddcheckin  := ctod("31/07/2020")
*local ddcheckout := ctod("31/07/2020")

local ddcheckin  := ctod("02/07/2020")
local ddcheckout := ctod("02/07/2020")


local number := 2
local cDesc  :="Om"
local cTipo  :="01"
local cRoom  := Left( cDesc,1)+Strzero(number,3)
local lFree  :=.f.
local oReservation

RddSetDefault( "DBFCDX" )



   oReservation:=TDatabase():Open( , "Reserva", "DBFCDX", .T. )
   oReservation:setorder(1)
   oReservation:gotop()


lFree := Search_Room(cRoom,ddcheckin,ddcheckout,oReservation)

? lFree

RETURN NIL
//--------------------------------------------------------------------------//

Function Search_Room(cRoom,ddcheckin,ddcheckout,oReservation)
   local lFound:=.f.
   Local cSeekT := (cRoom)  +  dtos(ddcheckin)


      oReservation:seek( cSeekT )




      WHILE !oReservation:eof()

         lFound := .t.

              oReservation:skip()
         ENDDO

         RETURN  lFound

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



 

the test always returns me false with either

local ddcheckin: = ctod ("07/31/2020")
local ddcheckout: = ctod ("07/31/2020")

and be with

local ddcheckin: = ctod ("02/07/2020")
local ddcheckout: = ctod ("02/07/2020")

but in reality only the first date range the room is not free for the second date range the room is free

how can i solve?
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: seek with tdatabase

Post by Silvio.Falconi »

I found this solution but I not Know if is Good or exist another method
Making a dbfilter , creating an array then search on this array if there is the number of Room
Any suggestions ?

Code: Select all


static function SearchRooms( dStart, dEnd, cRoom )

   field ROOMS_ID, CHECK_IN, CHECK_OUT

   local cCond, bCond
   local lfree:=.t.
   local aBusy   := {}
   local n

   ASize( aBusy, 0 )

   cCond    := "CHECK_OUT >= STOD('" + DTOS( dStart ) + "' ) .AND. " + ;
               "CHECK_IN <= STOD('" + DTOS( dEnd ) + "' )"
   cCond    += ".AND. ROOMS_ID ='"  + ALLTRIM(cRoom) + "' "

   bCond    := &( "{ || " + cCond + " }" )

   RE->( DBSETFILTER( bCond, cCond ), DBGOTOP() )
   RE->( DBEVAL( { || AAdd( aBusy, ROOMS_ID ) } ) )
   RE->( DBCLEARFILTER() )


     For n=1 to Len( aBusy )
        IF aBusy[n] == cRoom
           lFree:=.f.
        Endif
      next n

return lFree

 
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply