I use btnbmp class to show each table ( if the table is free I use green table , if the table is occupate I use red table).
I use two archive :
Tables.dbf where I save the configuration of tables ( x,y and number of table)
Reservation.dbf where I save the reservation of each table
On a Dialog I select the date init and the date final to reservation a table
when I select An Interval of dates it run ok : the procedure show on dialog the tables state ( green for free table , red for occupated table)
the strange problem is when the user move the mouse over the btnbmp the btnbmp return bach on old configuration
this happen also if I select the visualization of numbers of tables : if the user move the mouse over the btnbmp it erase the numbers ...why ?????
here the bmps used
save it as TABLE_GREEN.bmp
save it as TABLE_RED.bmp
this is the test.prg to try the problem : on this prg I insert also two function to create the sample data files (tables.dbf and reservation.dbf)
- Code: Select all Expand view
#include "fivewin.ch"
#include "dtpicker.ch"
REQUEST DBFCDX
#define TABLE_FREE "TABLE_GREEN.bmp"
#define TABLE_OCCUPATE "TABLE_RED.bmp"
#define COLORE_PANEL nRGB(255,221,187) // BRUSH OF PANEL
#define BMP_H 32
#define BMP_V 32
#define TOTY 20
#define TOTX 40
Function test()
Local oBrush
Local oChk,lNumbers :=.f.
SetBalloon( .T. )
SET DATE ITALIAN
RDDSetDefault( 'DBFCDX' )
dDataIni :=DATE()
dDataFin :=DATE()
DEFINE BRUSH oBrush1 COLOR COLORE_PANEL
// Create the Reservation Dbf Sample Data
Create_Reservation()
// Create the tables Dbf Sample Data
Create_Tables()
if ! Db_Open("RESERVATION","RESERVATION")
return nil
endif
INDEX ON RESERVATION->NUMTABLE TAG NUMTABLE
if ! Db_Open("tables","tables")
return nil
endif
INDEX ON tables->CAMERA TAG CAMtables
DEFINE DIALOG oSaloon SIZE 800,600;
TITLE "Show the saloon "
oPanel:= TPanel():New(40,2,400,400,oSaloon)
oPanel:SetBrush(oBrush1)
@ 0.8,2 say "From date" OF oSaloon SIZE 40,10
@ 0.8,22 say "To date" OF oSaloon SIZE 40,10
@ 0.8,10 DTPICKER dDataIni OF oSaloon SIZE 40,10 UPDATE VALID dDataIni<=dDataFin
* ON CHANGE (Load_tables(oPanel, dDataIni,dDataFin))
@ 0.8,32 DTPICKER dDataFin OF oSaloon SIZE 40,10 UPDATE VALID dDataIni<=dDataFin
* ON CHANGE (Load_tables(oPanel, dDataIni,dDataFin))
@ 26, 125 CHECKBOX oChk VAR lNumbers PROMPT "Show the tables With Numbers" OF oSaloon SIZE 100, 10 PIXEL UPDATE
@ 10.8,250 BTNBMP oBtnKO FILENAME "GO.BMP" PROMPT " REFRESH THE TABLES" OF oSaloon LEFT SIZE 100,16 NOBORDER;
ACTION Load_tables(oPanel, dDataIni,dDataFin,lNumbers)
oBtnKO:ltransparent:=.T.
ACTIVATE DIALOG oSaloon ;
ON INIT Load_tables(oPanel, dDataIni,dDataFin,lNumbers)
RETURN NIL
//-----------------------------------------------------------------//
Function Load_tables(oPanel, dDataIni,dDataFin,lNumbers)
Local numero:=48
Local totarray := TOTY*TOTX
Local cPosName
Local oFonttables
aBtn := Array(totarray)
aData := ARRAY( TOTY, TOTX )
nState:=1
DEFINE FONT oFonttables NAME "MS Sans Serif" SIZE 0, -12 BOLD
//----------------------------------------------------------------------------------------//
// show the tables
//----------------------------------------------------------------------------------------//
SELECT tables
tables->(DBGOTOP())
Do While !tables->(Eof())
nY := tables->Y
nX := tables->X
n := tables->camera
aData[nY,nX] := tables->ID
nBotone:=n
//----------------------------------------------------------------------------------------//
// search the num table into reservation and if the day is = show the table green or red
//----------------------------------------------------------------------------------------//
RESERVATION->(dbseek(n))
IF tables->ID=RESERVATION->TIPO
IF (RESERVATION->DATAIN >= dDataIni .AND. RESERVATION->DATAIN <= dDataFin ) .or. ;
( RESERVATION->DATAFIN >= dDataIni .AND. RESERVATION->DATAFIN <= dDataFin )
nState := 2
cPosName :="Table of "+RESERVATION->CUSTOMER
ELSE
nState := 1
cPosName :="Table free "+str(n)
ENDIF
ENDIF
///--------------------------show the table------------------------//
DO CASE
CASE aData[nY,nX] == "O"
IF nState = 1 // Free
IF lNumbers
@ nY*numero, nx*numero BTNBMP aBtn[nBotone] FILENAME TABLE_FREE ;
PIXEL OF oPanel SIZE BMP_H,BMP_V NOBORDER ;
TOOLTIP cPosName+" "+str(nState) PROMPT str(n) CENTER UPDATE FONT oFonttables
aBtn[nBotone]:setcolor( CLR_BLUE,CLR_WHITE)
aBtn[nBotone]:ltransparent:=.T.
else
@ nY*numero, nx*numero BTNBMP aBtn[nBotone] FILENAME TABLE_FREE ;
PIXEL OF oPanel SIZE BMP_H,BMP_V NOBORDER ;
TOOLTIP cPosName+" "+str(nState) CENTER UPDATE
aBtn[nBotone]:setcolor( CLR_BLUE,CLR_WHITE)
aBtn[nBotone]:ltransparent:=.T.
endif
elseif nState = 2
IF lNumbers
@ nY*numero, nx*numero BTNBMP aBtn[nBotone] FILENAME TABLE_OCCUPATE ;
PIXEL OF oPanel SIZE BMP_H,BMP_V NOBORDER ;
TOOLTIP cPosName+" "+str(nState) PROMPT str(n) CENTER UPDATE FONT oFonttables
aBtn[nBotone]:setcolor( CLR_BLUE,CLR_WHITE)
aBtn[nBotone]:ltransparent:=.T.
else
@ nY*numero, nx*numero BTNBMP aBtn[nBotone] FILENAME TABLE_OCCUPATE ;
PIXEL OF oPanel SIZE BMP_H,BMP_V NOBORDER ;
TOOLTIP cPosName+" "+str(nState) CENTER UPDATE
aBtn[nBotone]:setcolor( CLR_BLUE,CLR_WHITE)
aBtn[nBotone]:ltransparent:=.T.
endif
endif
ENDCASE
//---------------------------------------------------------------------//
tables->(DBSkip())
nX :=0
nY:=0
n:=0
nState := 1
cPosName := ""
nBotone:=0
ENDDO
RETURN NIL
function Db_Open(cDbf,cAlias)
if ! File(cDbf+'.CDX')
endif
if file( cDbf + ".dbf" ) .AND. file( cDbf + ".cdx" )
USE &(cDbf+".dbf") ;
INDEX &(cDbf+".cdx") ;
ALIAS &(cAlias) NEW
else
MsgStop( "error" )
return .f.
END if
if NetErr()
MsgStop( "error" )
dbCloseAll()
return .f.
endif
return .t.
//-------------------------- CREATION OF SAMPLE DATA -----------//
function Create_Reservation()
FIELD NUMTABLE
local NUM_TABLES :=10
local n, dStart
local aCols := { { 'NUMTABLE', 'N', 3, 0 }, ;
{ 'TIPO' , 'C', 1, 0 }, ;
{ 'DATAIN' , 'D', 8, 0 }, ;
{ 'DATAFIN' , 'D', 8, 0 },;
{ 'CUSTOMER' , 'C', 60, 0 }}
DbCreate( 'RESERVATION', aCols )
USE RESERVATION
INDEX ON NUMTABLE TAG NUMTABLE
dStart := AddMonth( BOY( Date() ), 7 ) // 1st March
for n := 1 to 1 * NUM_TABLES
APPEND BLANK
FIELD->NUMTABLE := n//HB_RandomInt( 1, NUM_TABLES )
FIELD->DATAIN := dStart + HB_RandomInt( 0, 20 )
FIELD->DATAFIN := FIELD->DATAIN + HB_RandomInt( 0, 5 )
FIELD->TIPO := "O"
FIELD->CUSTOMER := "CUST_"+ALLTRIM(STR(RECNO()))
next n
// MODIFY SOME RECORDS
browse()
CLOSE RESERVATION
RETURN NIL
Function Create_Tables()
FIELD CAMERA
LOCAL NUM_TABLES :=10
local n
local aCols := { { 'CAMERA', 'N', 3, 0 }, ;
{ 'ID' , 'C', 1, 0 }, ;
{ 'X' , 'N', 2, 0 }, ;
{ 'Y' , 'N', 2, 0 }}
DbCreate( 'TABLES', aCols )
USE TABLES
INDEX ON CAMERA TAG CAMTABLE
for n := 1 to 1 * NUM_TABLES
APPEND BLANK
FIELD->ID := "O"
FIELD->CAMERA := n
FIELD->X := n
FIELD->Y := 1
next n
browse()
CLOSE TABLES
RETURN NIL