#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 FreeRooms( dStart, dEnd,aCheck,oLbx,aStatus) // (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
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
// check status rooms
Function Check(aCheck,dStart,dEnd,aStatus,oLbx)
Local cDescribe := "Free"
Local nStatus := 0
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 RESERVA->CHECK_OUT >= dStart .AND. RESERVA->CHECK_IN <= dEnd
nStatus := Val( RESERVA->STATUS )
if nStatus > 0 .and. nStatus < 5
cDescribe := aStatus[ nStatus ]
endif
ENDIF
ENDIF
AAdd( aCheck, { nRoom, cRoomName, cDescribe } )
ROOMS->( DbSkip() )
nStatus:=0
cDescribe := "Free"
ENDDO
olbx:show()
return aCheck
function FreeRooms( dStart, dEnd,aCheck,oLbx,aStatus)
Local cDescribe := "Free"
Local nStatus := 0
FIELD CHECK_IN, CHECK_OUT
FIELD ID
// ERASE THE ARRAY
asize(aCheck,0)
olbx:hide()
/*
USE ROOMS
USE RESERVA
SET ORDER TO TAG ROOM_IN
SET FILTER TO MAX( dStart, CHECK_IN ) > MIN( dEnd, CHECK_OUT )
GO TOP
SELECT ROOMS
SET RELATION TO ID INTO RESERVA
GO TOP
SET FILTER TO EMPTY(RESERVA->ROOMS_ID)
GO TOP
XBROWSER "ROOMS"
CLOSE DATA
*/
DO WHILE ! ROOMS->( Eof() )
nRoom := ROOMS->ID
cRoomName := ROOMS->NAME
RESERVA->( DbGoTop() )
IF RESERVA->(DbSeek(nRoom, .t. ))
* if MAX( dStart, RESERVA->CHECK_IN ) > MIN( dEnd, RESERVA->CHECK_OUT )// then the room is free
if MAX( dStart, RESERVA->CHECK_IN ) <= MIN( dEnd, RESERVA->CHECK_OUT ) //then the room is not free.
nStatus = Val( RESERVA->STATUS )
cDescribe = aStatus[ nStatus ]
AAdd( aCheck, { nRoom, cRoomName, cDescribe } )
endif
*AAdd( aCheck, { nRoom, cRoomName, cDescribe } )
endif
ROOMS->( DbSkip() )
nStatus:=0
cDescribe := "Free"
ENDDO
olbx:show()
return aCheck