seek with tdatabase

seek with tdatabase

Postby Silvio.Falconi » Wed Jun 03, 2020 5:08 pm

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

I made a test

Code: Select all  Expand view  RUN
#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?
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: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: seek with tdatabase

Postby Silvio.Falconi » Wed Jun 03, 2020 8:41 pm

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  Expand view  RUN


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

 
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: 7075
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 70 guests