ERROR ON BTNBMP CLASS : resolved!!!

ERROR ON BTNBMP CLASS : resolved!!!

Postby MdaSolution » Fri Aug 05, 2011 11:58 am

I trying to create a small saloon with ten tables ,

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)


Image





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
Image
save it as TABLE_GREEN.bmp

Image
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

 
Last edited by MdaSolution on Sat Aug 06, 2011 2:12 pm, edited 1 time in total.
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: ERROR ON BTNBMP CLASS

Postby MdaSolution » Fri Aug 05, 2011 9:23 pm

Any solution or it is a bug of btnbmp class ?
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: ERROR ON BTNBMP CLASS

Postby Daniel Garcia-Gil » Fri Aug 05, 2011 10:58 pm

Hello

is a bug in your code...

every call to Load_tables, you're building a new button without destroy current...
after 10 call you will have Total Buttons x 10 and painted one over one
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: ERROR ON BTNBMP CLASS

Postby MdaSolution » Sat Aug 06, 2011 1:18 pm

thanks
how I can destroy all abtn ?

I try with

IF lcarga
AEVAL( aBtn, {| oBtn | oBtn:end() } )
else
aBtn := Array(totarray)
aData := ARRAY( TOTY, TOTX )
endif

where lcarga is .f. for the first lap and .t. for the second lap when I want refresh the saloon

but it make error I also tried with destroy() function


or

you have an easy solution fr this problem ?
I must show tables of restaurant from a date to another date
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: ERROR ON BTNBMP CLASS

Postby Daniel Garcia-Gil » Sat Aug 06, 2011 1:31 pm

Hello

no destroy the button, if the button exist only change the properties
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: ERROR ON BTNBMP CLASS

Postby MdaSolution » Sat Aug 06, 2011 1:51 pm

sorry but not I understtod,
I must change the property for all buttons , but i not know wich button to change how make to select that specific or those buttons ?
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: ERROR ON BTNBMP CLASS

Postby Daniel Garcia-Gil » Sat Aug 06, 2011 2:16 pm

Hello

sorry, i cant help you about that

i could say a idea you should "build" it...

each button execute a action, for this way you can know what button was pressed and change properties if is necessary
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: ERROR ON BTNBMP CLASS : resolved!!!

Postby MdaSolution » Sat Aug 06, 2011 2:58 pm

Sorry ,

I resolved!!!


I made a function ( same the load_tables() ) but not create the abtn array and then I change colors and captions..now run ok

thanks Daniel
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: ERROR ON BTNBMP CLASS : resolved!!!

Postby MdaSolution » Sun Aug 07, 2011 9:37 am

Daniel,

My solution is this

Code: Select all  Expand view


      Function change_state( aData,aBtn,dDataIni,dDataFin,lNumbers)



         SELECT tables

        tables->(DBGOTOP())


      Do While !tables->(Eof())
                   nY := tables->Y
                   nX := tables->X
                   n :=  tables->camera
                   aData[nY,nX] := tables->ID
                   nBotone:=n

                       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

                               DO CASE

                         CASE aData[nY,nX] == "O"
                                             IF nState = 2
                                           aBtn[nBotone]:setfile(TABLE_OCCUPATE,TABLE_OCCUPATE)
                                            aBtn[nBotone]:cTooltip:= cPosName
                                             elseif nState = 1
                                             aBtn[nBotone]:setfile(TABLE_FREE,TABLE_FREE)
                                             aBtn[nBotone]:cTooltip:=  cPosName
                                          endif

                                            IF lNumbers
                                                 aBtn[nBotone]:cCaption :=str(n)
                                              else
                                                  aBtn[nBotone]:cCaption:=""
                                                 endif

                                  ENDCASE

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




                tables->(DBSkip())
                nX :=0
                nY:=0
                n:=0
                nState := 1
                cPosName := ""
                nBotone:=0
             ENDDO
             retun nil






it seems run ok , after 8/7 refresh ( I click the button and call this function ) the exe CRASH ..... WHY ?


I use an Windows Seven Home Premium 64 bit and I have 8 GB memory

this the error
----------------------------------------------------------------------------------------------
firma problema:
Nome evento problema: APPCRASH
Nome applicazione: testbtn.Exe
Versione applicazione: 0.0.0.0
Timestamp applicazione: 00000000
Nome modulo con errori: testbtn.Exe
Versione modulo con errori: 0.0.0.0
Timestamp modulo con errori: 00000000
Codice eccezione: c0000005
Offset eccezione: 0000be13
Versione SO: 6.1.7600.2.0.0.768.3
ID impostazioni locali: 1040
Informazioni aggiuntive 1: b736
Ulteriori informazioni 2: b736f472dc6905a34fec743cbb53b715
Ulteriori informazioni 3: 7f2a
Ulteriori informazioni 4: 7f2aab8b38753cb4243f22764696c61e
-----------------------------------------------------------------------------------------------




In your opinion, the search with the dates might work or there are errors? or it is a dbf problem ?
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 72 guests

cron