and I wish to try in the range of past dates if there is room and which has been in Reserva.dbf
When I make a seach the procedure not run well
for a sample if you made a seach from 01 March 2013 to 04 March 2013 you can see the room 30 occupied or another status while it must be Free
the SAMPLE TEST
- Code: Select all Expand view RUN
#include "fivewin.ch"
#include "ord.ch"
#include "constant.ch"
#include "dtpicker.ch"
#include "XBROWSE.ch"
#define LIGHTCYAN nRGB( 203, 225, 252 )
#define PLANNING_RESERVED 1
#define PLANNING_CONFIRMED 2
#define PLANNING_OCCUPIED 3
#define PLANNING_CANCELED 4
#define PLANNING_EMPTY 5
REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ordkeyno, ordkeycount,ordcreate,ordkeygoto
FUNCTION TEST()
Local oDlg, oLbx
Local dstart:=date()
Local dEnd :=date()
Loca aCheck := array(1,3)
local aStatus := { "Reserved", "Confirmed", "Occupied", "Canceled", "Empty" }
Local nBottom := 24
Local nRight := 51.9
Local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
Local nHeight := nBottom * DLG_CHARPIX_H
Local bClrGrad := { | lPressed | If( ! lPressed,;
{ { 1, nRGB( 253, 254, 255 ), nRGB( 179, 217, 255 ) } },;
{ { 1, nRGB( 179, 217, 255 ), nRGB( 253, 254, 255 ) } } ) }
RddSetDefault( "DBFCDX" )
SET DATE ITALIAN
SET DATE FORMAT "DD/MM/YYYY"
SET DELETED ON
SET CENTURY ON
SET EPOCH TO year( date() ) - 20
SET MULTIPLE OFF
Builddbf()
DEFINE DIALOG oDlg ;
TITLE "Check Free Rooms" ;
SIZE nWidth, nHeight TRANSPARENT PIXEL ;
GRADIENT { { 1,CLR_WHITE, LIGHTCYAN } } ;
STYLE nOr( DS_MODALFRAME, WS_POPUP, WS_CAPTION, 4 )
@ 10, 8 SAY "From :" OF oDlg pixel TRANSPARENT
@ 10, 30 DTPICKER dStart OF oDlg pixel SIZE 40,10
@ 10, 86 SAY "To :" OF oDlg pixel TRANSPARENT
@ 10, 100 DTPICKER dEnd OF oDlg pixel SIZE 40,10
@ 30, 10 XBROWSE oLbx OF oDlg ;
SIZE 185,130 PIXEL
oLbx:SetArray(aCheck)
oLbx:nMarqueeStyle := MARQSTYLE_HIGHLWIN7 //MARQSTYLE_HIGHLROW
oLbx:nColDividerStyle := LINESTYLE_LIGHTGRAY
oLbx:lColDividerComplete := .t.
oLbx:lRecordSelector := .f.
oLbx:lHScroll := .f.
oLbx:nHeaderHeight := 20
oLbx:nRowHeight := 20
oLbx:aCols[1]:cHeader := i18n("Room")
oLbx:aCols[1]:nWidth := 110
oLbx:aCols[2]:cHeader := i18n("Name")
oLbx:aCols[2]:nWidth := 100
oLbx:aCols[3]:cHeader := i18n("Status")
oLbx:aCols[3]:nWidth := 100
oLbx:nDataType := 1 // array
oLbx:nStretchCol := -1
oLbx:CreateFromCode()
olbx:bClrStd:= {|| if( acheck[oLbx:nArrayAt,3]="Free",{ CLR_GREEN, RGB(221,245,255)},{ CLR_BLACK, RGB(221,245,255) }) }
@ 10, 150 BTNBMP oBtnSearch PROMPT "&Search" FILENAME "view.bmp" SIZE 50, 15 ;
LEFT NOBORDER ;
ACTION (Check(@aCheck,dStart,dEnd,aStatus,oLbx),oLbx:show(),oLbx:refresh())
oBtnSearch:bClrGrad = bClrGrad
@ 163, 14 BTNBMP oBtnPrint PROMPT "&Print" FILENAME "REP_PRINTER.bmp" SIZE 50, 15 ;
LEFT NOBORDER ;
ACTION oLbx:Report("Stampa disponbilità dal "+dtos(dStart)+ " al "+dtos(dEnd))
oBtnPrint:bClrGrad = bClrGrad
@ 163, 145 BTNBMP oBtnCan PROMPT "&Exit" FILENAME "DLG_OK.bmp" SIZE 50, 15 ;
LEFT NOBORDER ;
ACTION ( oDlg:end( IDCANCEL ) )
oBtnCan:bClrGrad = bClrGrad
ACTIVATE DIALOG oDlg center ;
ON INIT oLbx:hide()
DbCloseAll()
return nil
// check status rooms
Function Check(aCheck,dStart,dEnd,aStatus,oLbx)
Local cDescribe := "Free..."
asize(aCheck,0)
olbx:hide()
ROOMS->( DbGoTop() )
DO WHILE ! ROOMS->( Eof() )
nRoom := ROOMS->ID
cRoomName := ROOMS->NAME
RESERVA->( DbGoTop() )
IF RESERVA->(DbSeek(nRoom, .t. ))
IF DToS( RESERVA->CHECK_OUT ) >= DToS( dStart ) ;
.AND. DToS( RESERVA->CHECK_IN ) <= DToS( dEnd )
nStatus = Val( RESERVA->STATUS )
if nStatus > 0 .and. nStatus < 5
cDescribe = aStatus[ nStatus ]
endif
AAdd( aCheck, { nRoom, cRoomName, cDescribe } )
ENDIF
ELSE
AAdd( aCheck, { nRoom, cRoomName, cDescribe } )
ENDIF
ROOMS->( DbSkip() )
ENDDO
olbx:show()
return aCheck
Function BuildDbf()
local aStructure
local i
if ! File( "rooms.dbf" )
aStructure = { { "id" , "C", 4, 0 },;
{ "name" , "C", 30, 0 },;
{ "type" , "C", 2, 0 } }
DBCreate( "rooms", aStructure, "DBFCDX" )
endif
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 ROOMS ALIAS ROOMS VIA "DBFCDX" NEW
INDEX ON ROOMS->ID TAG rooms_id TO rooms
USE RESERVA ALIAS RESERVA VIA "DBFCDX" NEW
INDEX ON RESERVA->ROOMS_ID + DToS( RESERVA->CHECK_IN ) TAG room_in TO reserva
if ROOMS->( LastRec() ) == 0
for i = 1 to 30
ROOMS->( DbAppend() )
ROOMS->ID = StrZero( i, 2 )
ROOMS->NAME = "Room " + StrZero( i, 2 )
ROOMS->TYPE = StrZero( i % 5, 2 )
next
endif
RETURN nil
To popolate the Reserva.Dbf for the test execute this function only the first time
- Code: Select all Expand view RUN
- Function Appe_Demo()
// only for demo
SELECT RESERVA
RESERVA->(DbAppend())
Replace RESERVA->date With date()
Replace RESERVA->roomS_id With "06"
Replace RESERVA->check_in With ctod("23/02/2013")
Replace RESERVA->check_out With ctod("23/02/2013")
Replace RESERVA->Status With "02"
Replace RESERVA->guest With "Bill Gates"
RESERVA->(DbAppend())
Replace RESERVA->date With date()
Replace RESERVA->roomS_id With "03"
Replace RESERVA->check_in With ctod("24/02/2013")
Replace RESERVA->check_out With ctod("02/03/2013")
Replace RESERVA->Status With "01"
Replace RESERVA->guest With "Micky Mouse"
RESERVA->(DbAppend())
Replace RESERVA->date With date()
Replace RESERVA->roomS_id With "07"
Replace RESERVA->check_in With ctod("26/02/2013")
Replace RESERVA->check_out With ctod("02/03/2013")
Replace RESERVA->Status With "03"
Replace RESERVA->guest With "Donald duck"
RESERVA->(DbAppend())
Replace RESERVA->date With date()
Replace RESERVA->roomS_id With "10"
Replace RESERVA->check_in With ctod("24/02/2013")
Replace RESERVA->check_out With ctod("26/02/2013")
Replace RESERVA->Status With "04"
Replace RESERVA->guest With "Customer Z"
RESERVA->(DbAppend())
Replace RESERVA->date With date()
Replace RESERVA->roomS_id With "13"
Replace RESERVA->check_in With ctod("19/02/2013")
Replace RESERVA->check_out With ctod("01/03/2013")
Replace RESERVA->Status With "05"
Replace RESERVA->guest With "Customer X"
RESERVA->(DbAppend())
Replace RESERVA->date With date()
Replace RESERVA->roomS_id With "12"
Replace RESERVA->check_in With ctod("24/02/2013")
Replace RESERVA->check_out With ctod("27/02/2013")
Replace RESERVA->Status With "04"
Replace RESERVA->guest With "Customer Y"
RESERVA->(DbCommit())
Retur nil
and the I cannot see the room number 6 and the number number 12 but sometimes also the number 13