FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour RESOLVED colorize a cell of XBROWSE
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
RESOLVED colorize a cell of XBROWSE
Posted: Wed Oct 15, 2014 07:25 AM
I wish change the color of a cell ( first column) of a xbrowse




to change color it control if the number day is on a archive of Holyday ( feste.dbf) I converte into a array aFeste

and if found the number day put the background color on the first cell

It make the command but lose the color , if the final user select a record it return the back color

I tried to use a refresh but i not run ok

Any solution ?


this is the source code of the test ( it create the dbf also)

On this test I set the december mounth and I wish show the Holydays of the december

Code (fw): Select all Collapse
 

#include "fivewin.ch"
#include "constant.ch"

 #Define COLORE_DOMENICHE   Rgb(255,218,185)  // COLORE ROSA
 #Define COLORE_NATALE      nRGB( 203, 225, 252 )
 #Define COLORE_PASQUA      CLR_HGRAY
 #Define COLORE_PATRONO     CLR_GREEN
 #Define COLORE_PASQUETTA   CLR_GRAY

 REQUEST HB_LANG_IT


REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO


static aFeste

Function Test()
   Local nMese:= 12
   Local nAnno  :="2014"
   Local dDate
   Local nDays:= 31
   Local aGiorni:= {}
   Local PGiorno
   Local oBrw


   Local  nBottom   := 29
   Local  nRight    := 22
   Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 180 )
   Local nHeight := nBottom * DLG_CHARPIX_H

    HB_LangSelect("IT")


   SET DATE FORMAT "dd-mm-yyyy"
   SET DELETED     ON
   SET CENTURY     ON
   SET EPOCH TO    year( date() ) - 20
   SET MULTIPLE    OFF

   RddSetDefault( "DBFCDX" )






   // create the array feste

     Crea_Festivita()

        aFeste  := {}

   if ! Db_Open_Root(".\FESTE","FS")
            return nil
         endif
      SELECT FS
    FS->(DbSetOrder(1))
    FS->(DbGoTop())
       DO WHILE ! FS->(EoF())
         AAdd( aFeste, {strzero(FS->GIORNO,2),str(FS->MESE),FS->DESCRI })
          FS->(DbSkip())
       ENDDO





  // create the calendar

       dDate:=   CTOD("01/"+strzero(nMese,2)+"/"+nAnno)
    FOR n=1 to nDays
             PGiorno:= CTOD(strzero(n,2)+"/"+StrZero(Month(dDate),2)+"/"+StrZero(Year(dDate),4))
             AADD(aGiorni,{ strzero(n,2)+" "+Left(cDow(PGiorno), 2) } )
               NEXT




   DEFINE FONT oFont NAME 'Tahoma' SIZE 0, -12
   DEFINE DIALOG oDlg        ;
   TITLE "Visualizzazione cartellino del mese di Dicembre"   ;
   SIZE nWidth, nHeight  PIXEL


 @ 0,0 XBROWSE oBrw OF oDlg               ;
      COLUMNS 1                  ;
      HEADERS "Giorno"   ;
      COLSIZES 75          ;
      ARRAY aGiorni LINES FASTEDIT CELL SIZE -10,-10 PIXEL


// colonna colore  per domenica e festività

       for nI = 1 to 1
        oBrw:aCols[ nI ]:bClrStd :=ChangeColor( oBrw,nI,nMese)
      next



   WITH OBJECT oBrw
          :lHScroll := .f.
          :lFooter:=.t.
          :MakeTotals()

          :CreateFromCode()
   END



ACTIVATE DIALOG oDlg center

return nil




static function ChangEColor( oBrw, n,nMese ,afeste)
return {|| { CLR_BLACK, ColorCellNew( oBrw:aRow[ n ],nMese) } }




static function ColorCellNew( ctesto,nMese)
   Local  nColor := GetSysColor( 5 )
   local uDito :=0
      Local n

   IF !ctesto = Nil

        asort(aFeste)

          For n=1 to len(aFeste)

              IF nMese=val(aFeste[n][2])

                 IF LEFT(alltrim(ctesto),2)=alltrim(aFeste[n][1])
                          nColor :=COLORE_DOMENICHE
                         else
                           nColor := GetSysColor( 5 )
                        ENDIF
                 ENDIF
              Next

    ENDIF

    return nColor






function Db_Open_Root(cDbf,cAlias)
   if file( cDbf + ".dbf" )
      USE &(cDbf+".dbf")      ;
         ALIAS &(cAlias) NEW
   else
     MsgStop( i18n( "Non si è trovato l'archivio dei dati." ) + CRLF + ;
               i18N( "Per favore  controlla la configurazione") + CRLF + ;
                i18N( "e indicizza gli archivi dell'applicazione." ) )
      return .f.
    END if
   if NetErr()
     msgStop( i18n( "Errore nell'aprire un archivio" ) + CRLF + ;
              i18n( "Per favore caricare di nuovo l'applicazione." ) )
      DbCloseAll()
      return .f.
   endif
return .t.







  Function Crea_Festivita()

   DbCreate('FS', {{'Giorno'    , 'N',    2,   0}  ,;
                   {'Mese'      , 'N',    2,   0}  ,;
                   {'Descri'    , 'C',   40,   0} }, 'DBFCDX')


     close all
      use &('FS') alias FS new
      select Fs
      if FILE('FESTE.DBF')
         delete file &('FESTE.cdx')
         append from &('FESTE')
         dbcommitall()
         close all
         delete file &('FESTE.dbf')

      endif
      close all
      rename &('FS.dbf') to &('FESTE.DBF')

       DbCloseAll()

       if ! Db_Open_Root(".\FESTE","FS")
            return nil
         endif
         SELECT FS

         IF   FS->(OrdKeyCount())=0


            APPEND BLANK
            REPLACE GIORNO WITH  1
            REPLACE MESE WITH    1
            REPLACE DESCRI WITH   "Capodanno"

            APPEND BLANK
            REPLACE GIORNO WITH  6
            REPLACE MESE WITH    1
            REPLACE DESCRI WITH   "Epifania"

            APPEND BLANK
            REPLACE GIORNO WITH  25
            REPLACE MESE WITH    4
            REPLACE DESCRI WITH   "Anniversario della liberazione"

            APPEND BLANK
            REPLACE GIORNO WITH  1
            REPLACE MESE WITH    5
            REPLACE DESCRI WITH   "Festa del Lavoro"

            APPEND BLANK
            REPLACE GIORNO WITH  2
            REPLACE MESE WITH    6
            REPLACE DESCRI WITH   "Festa della Repubblica"


            APPEND BLANK
            REPLACE GIORNO WITH  15
            REPLACE MESE WITH    8
            REPLACE DESCRI WITH   "Ferragosto"

            APPEND BLANK
            REPLACE GIORNO WITH  1
            REPLACE MESE WITH    11
            REPLACE DESCRI WITH   "Festa di tutti i santi"


            APPEND BLANK
            REPLACE GIORNO WITH  8
            REPLACE MESE WITH    12
            REPLACE DESCRI WITH   "Immacolata Concezione"

            APPEND BLANK
            REPLACE GIORNO WITH  19
            REPLACE MESE WITH    12
            REPLACE DESCRI WITH   "San Berardo"

            APPEND BLANK
            REPLACE GIORNO WITH  25
            REPLACE MESE WITH    12
            REPLACE DESCRI WITH   "Natale"

            APPEND BLANK
            REPLACE GIORNO WITH  26
            REPLACE MESE WITH    12
            REPLACE DESCRI WITH   "Santo Stefano"
          Endif
          INDEX ON FS->MESE TAG FS TO FESTE
       DbCloseAll()
       RETURN NIL
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 117
Joined: Tue Jan 03, 2006 06:18 PM
Re: colorize a cell of XBROWSE
Posted: Wed Oct 15, 2014 10:34 AM
Dear Silvo,

Try This,

Code (fw): Select all Collapse
#include "fivewin.ch"
#include "constant.ch"

 #Define COLORE_DOMENICHE   Rgb(255,218,185)  // COLORE ROSA
 #Define COLORE_NATALE      nRGB( 203, 225, 252 )
 #Define COLORE_PASQUA      CLR_HGRAY
 #Define COLORE_PATRONO     CLR_GREEN
 #Define COLORE_PASQUETTA   CLR_GRAY

 REQUEST HB_LANG_IT


REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO


static aFeste

Function Test()
   Local nMese:= 12
   Local nAnno  :="2014"
   Local dDate
   Local nDays:= 31
   Local aGiorni:= {}
   Local PGiorno
   Local oBrw


   Local  nBottom   := 29
   Local  nRight    := 22
   Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 180 )
   Local nHeight := nBottom * DLG_CHARPIX_H

    HB_LangSelect("IT")


   SET DATE FORMAT "dd-mm-yyyy"
   SET DELETED     ON
   SET CENTURY     ON
   SET EPOCH TO    year( date() ) - 20
   SET MULTIPLE    OFF

   RddSetDefault( "DBFCDX" )






   // create the array feste

     Crea_Festivita()

        aFeste  := {}

   if ! Db_Open_Root(".\FESTE","FS")
            return nil
         endif
      SELECT FS
    FS->(DbSetOrder(1))
    FS->(DbGoTop())
    DO WHILE ! FS->(EoF())
        IF FS->MESE == nMese
            AAdd( aFeste, {strzero(FS->GIORNO,2),str(FS->MESE),FS->DESCRI })
        ENDIF   
        FS->(DbSkip())
    ENDDO
    asort(aFeste)



  // create the calendar

    dDate:=   CTOD("01/"+strzero(nMese,2)+"/"+nAnno)
    FOR n=1 to nDays
             PGiorno:= CTOD(strzero(n,2)+"/"+StrZero(Month(dDate),2)+"/"+StrZero(Year(dDate),4))
             AADD(aGiorni,{ strzero(n,2)+" "+Left(cDow(PGiorno), 2), .F. } )
    NEXT
    FOR n=1 to nDays
    
        IF aSCAN(aFeste,{|x|x[1]== LEFT(aGiorni[N,1],2) }  )>0
           aGiorni[N,2] :=.T.
        ENDIF    
    NEXT




   DEFINE FONT oFont NAME 'Tahoma' SIZE 0, -12
   DEFINE DIALOG oDlg        ;
   TITLE "Visualizzazione cartellino del mese di Dicembre"   ;
   SIZE nWidth, nHeight  PIXEL


 @ 0,0 XBROWSE oBrw OF oDlg               ;
      COLUMNS 1                  ;
      HEADERS "Giorno"   ;
      COLSIZES 75          ;
      ARRAY aGiorni LINES FASTEDIT CELL SIZE -10,-10 PIXEL ;
      UPDATE


// colonna colore  per domenica e festività



    WITH OBJECT oBrw:oCol("Giorno" )
            :bClrStd := {|| IIF(   aGiorni[OBRW:KEYNO(),2] ==.T. ,;
                                   {COLORE_DOMENICHE,CLR_GREEN},;
                                   {GetSysColor( 5 ) ,CLR_GRAY} ;
                                );   
                        }                                
    END   


    WITH OBJECT oBrw
          :lHScroll := .f.
          :lFooter:=.t.
          :MakeTotals()

          :CreateFromCode()
    END



ACTIVATE DIALOG oDlg center

return nil






function Db_Open_Root(cDbf,cAlias)
   if file( cDbf + ".dbf" )
      USE &(cDbf+".dbf")      ;
         ALIAS &(cAlias) NEW
   else
     MsgStop( i18n( "Non si è trovato l'archivio dei dati." ) + CRLF + ;
               i18N( "Per favore  controlla la configurazione") + CRLF + ;
                i18N( "e indicizza gli archivi dell'applicazione." ) )
      return .f.
    END if
   if NetErr()
     msgStop( i18n( "Errore nell'aprire un archivio" ) + CRLF + ;
              i18n( "Per favore caricare di nuovo l'applicazione." ) )
      DbCloseAll()
      return .f.
   endif
return .t.







  Function Crea_Festivita()

   DbCreate('FS', {{'Giorno'    , 'N',    2,   0}  ,;
                   {'Mese'      , 'N',    2,   0}  ,;
                   {'Descri'    , 'C',   40,   0} }, 'DBFCDX')


     close all
      use &('FS') alias FS new
      select Fs
      if FILE('FESTE.DBF')
         delete file &('FESTE.cdx')
         append from &('FESTE')
         dbcommitall()
         close all
         delete file &('FESTE.dbf')

      endif
      close all
      rename &('FS.dbf') to &('FESTE.DBF')

       DbCloseAll()

       if ! Db_Open_Root(".\FESTE","FS")
            return nil
         endif
         SELECT FS

         IF   FS->(OrdKeyCount())=0


            APPEND BLANK
            REPLACE GIORNO WITH  1
            REPLACE MESE WITH    1
            REPLACE DESCRI WITH   "Capodanno"

            APPEND BLANK
            REPLACE GIORNO WITH  6
            REPLACE MESE WITH    1
            REPLACE DESCRI WITH   "Epifania"

            APPEND BLANK
            REPLACE GIORNO WITH  25
            REPLACE MESE WITH    4
            REPLACE DESCRI WITH   "Anniversario della liberazione"

            APPEND BLANK
            REPLACE GIORNO WITH  1
            REPLACE MESE WITH    5
            REPLACE DESCRI WITH   "Festa del Lavoro"

            APPEND BLANK
            REPLACE GIORNO WITH  2
            REPLACE MESE WITH    6
            REPLACE DESCRI WITH   "Festa della Repubblica"


            APPEND BLANK
            REPLACE GIORNO WITH  15
            REPLACE MESE WITH    8
            REPLACE DESCRI WITH   "Ferragosto"

            APPEND BLANK
            REPLACE GIORNO WITH  1
            REPLACE MESE WITH    11
            REPLACE DESCRI WITH   "Festa di tutti i santi"


            APPEND BLANK
            REPLACE GIORNO WITH  8
            REPLACE MESE WITH    12
            REPLACE DESCRI WITH   "Immacolata Concezione"

            APPEND BLANK
            REPLACE GIORNO WITH  19
            REPLACE MESE WITH    12
            REPLACE DESCRI WITH   "San Berardo"

            APPEND BLANK
            REPLACE GIORNO WITH  25
            REPLACE MESE WITH    12
            REPLACE DESCRI WITH   "Natale"

            APPEND BLANK
            REPLACE GIORNO WITH  26
            REPLACE MESE WITH    12
            REPLACE DESCRI WITH   "Santo Stefano"
          Endif
          INDEX ON FS->MESE TAG FS TO FESTE
       DbCloseAll()
       RETURN NIL


Regards,

Kok
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: colorize a cell of XBROWSE
Posted: Wed Oct 15, 2014 11:36 AM

thanks but I need also if right(alltrim(ctesto),2)="Do" (it must be colorized)

if the the day is sunday ..any solution ?

I made

:bClrStd := {||IIF( Right(oBrw:aRow[ 1 ],2)="Do", ;
{COLORE_DOMENICHE,CLR_GREEN},;
{GetSysColor( 5 ) ,CLR_GRAY} ;
);
}

but then not run the holydays

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 117
Joined: Tue Jan 03, 2006 06:18 PM
Re: colorize a cell of XBROWSE
Posted: Wed Oct 15, 2014 11:55 AM
Dear Silvio,

change this :

Code (fw): Select all Collapse
if upper( Left(cDow(PGiorno), 2)) =='DO'
                AADD(aGiorni,{ strzero(n,2)+" "+Left(cDow(PGiorno), 2), .t. } )
            else
             AADD(aGiorni,{ strzero(n,2)+" "+Left(cDow(PGiorno), 2), .F. } )
             
 endif


Regards,
kok
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: colorize a cell of XBROWSE
Posted: Wed Oct 15, 2014 03:06 PM
Kok,
I found another solution ...it run ok
I have on my app the array with 17 columns and I add another for insert the CR "F" instead of your .t. it run the same
I insert also the control for Sundays and Easter and day after Easter












Code (fw): Select all Collapse
WITH OBJECT oBrw:oCol("Giorno" )
       :bClrStd := {|| IIF(aGiorni[oBrw:KEYNO(),18]="F"                            .OR.  ;  //Holidays ....
                           Right(oBrw:aRow[ 1 ],2)="Do"                            .OR.  ;  // Sundays ...
                           Festa_Pasqua(nMese,Left(aGiorni[oBrw:KEYNO(),1],2))=.T. .OR.  ;  // Easter ...
                           Festa_Pasquetta(nMese,Left(aGiorni[oBrw:KEYNO(),1],2))=.T.   ,;  //day after Easter ...
                                   {CLR_BLUE,COLORE_DOMENICHE},;
                                   {CLR_BLUE ,CLR_WHITE} ;
                                );
                            }

    END



Only If I wish change colors for each type of Holidays I have problem , I 'll like to insert :
Sundays COLORE_DOMENICHE
Easter CLR_xxxxxx
or I can insert color to afeste array ( just an idea)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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

Continue the discussion