refresh de form

Projeto MiniGui - Biblioteca visual para Harbour/xHarbour

Moderador: Moderadores

spereira
Usuário Nível 2
Usuário Nível 2
Mensagens: 85
Registrado em: 19 Jul 2004 11:42
Localização: Porto - Portugal

refresh de form

Mensagem por spereira »

Olá a todos.
Sou programador em Clipper a muitos anos e agora estou desenvolvendo o meu primeiro projeto em HMG. Estou achando o máximo mas ainda estou deparando com alguns problemas que não me deixam ir à frente.
Estou desenvolvendo um controle para monitorar o número de entrevistas que são realizadas no call center e estes valores devem ser atualizados online, ou pelo menos se não for possível online que se possa se recalcular os valores de tempos em tempos e/ou através de um botão.

Os valores da primeira vez eu já consegui colocar na tela, mas não estou conseguindo fazer o refresh destes valores, ou seja, não estou conseguindo executar o programa que reconta os valores das entrevistas feitas.

Em Clipper eu já possuo este controle e funciona bem, mas no formulário do HMG eu não sei como fazer.
Se alguém tiver uma idéia melhor do que esta que estou a fazer eu agradeço.

Segue abaixo o código:

Código: Selecionar todos

#include <hmg.ch>

Function Main()

    
  	DEFINE WINDOW Form_1   ;
              ROW 0 ;
		          COL 0 ;
		          WIDTH 800 ;
	            HEIGHT 600	;
	            TITLE "Controle de Estudos";		
		          WINDOWTYPE MAIN;
          		ON RELEASE CloseTables();
          		NOMAXIMIZE			;
          		NOSIZE				

              DEFINE LABEL Label_1
                    ROW    20
                    COL    300
                    WIDTH  200
                    HEIGHT 24
                    VALUE "Controle de Estudos"
                    FONTNAME "Arial"
                    FONTSIZE 14
                    TOOLTIP "Controle de Estudos"
                    FONTBOLD .T.
                    FONTITALIC .F.
                    FONTUNDERLINE .F.
                    FONTSTRIKEOUT .F.
                    HELPID Nil
                    VISIBLE .T.
                    TRANSPARENT .F.
                    ACTION Nil
                    AUTOSIZE .F.
                    BACKCOLOR NIL
                    FONTCOLOR {255,0,0}
              END LABEL

              @ 500,700 BUTTON Button_1 PICTURE "button5.bmp" WIDTH 50 HEIGHT 50 ACTION Refresh()
              
              Actualiza()
              Mostra_valores(.f.)   			 

  	END WINDOW
  	
  	Form_1.Center
        Form_1.Activate

Return

Procedure Opentables()

	Use Controle

Return

Procedure CloseTables()

	Close all

Return

Procedure Refresh
  Actualiza()
  Mostra_valores(.t.)   			 


/* Esta parte está comentada pois dá erro
  Use CONTROLE alias CONTROLE new
  dbgotop()
  do while .not. eof() .and. ATIVO

    mLABEL1 = "LABEL_R"+strzero(recno(),2)+ "_1"
    mLABEL2 = "LABEL_R"+strzero(recno(),2)+ "_2"
    mLABEL3 = "LABEL_R"+strzero(recno(),2)+ "_3"
    mLABEL4 = "LABEL_R"+strzero(recno(),2)+ "_4"
    mLABEL5 = "LABEL_R"+strzero(recno(),2)+ "_5"
    mLABEL6 = "LABEL_R"+strzero(recno(),2)+ "_6"
    mLABEL7 = "LABEL_R"+strzero(recno(),2)+ "_7"


  	Form_1.mLABEL1.Refresh
    Form_1.mLABEL2.Refresh
    Form_1.mLABEL3.Refresh
    Form_1.mLABEL4.Refresh
    Form_1.mLABEL5.Refresh
    Form_1.mLABEL6.Refresh
    Form_1.mLABEL7.Refresh

    skip

  enddo
 
  goto bott

  mLABEL_TOT_1 = "LABEL_R"+strzero(recno(),2)+ "_TOT_1"
  mLABEL_TOT_2 = "LABEL_R"+strzero(recno(),2)+ "_TOT_2"

  close all
*/
  
Return


//**********************************************************************************//
// Procedure para mostrar os valores calculados e gravados no ficheiro CONTROLE.DBF //
//**********************************************************************************//
Procedure Mostra_valores
parameters mRefresh

    if !mRefresh
        // Primeira linha do cabeçalho das colunas //
    	  @ 060,010 LABEL LCAB_L1C1;
                  WIDTH 90 ;
                  TOOLTIP "Concessionário";
                  VALUE 'Cliente'
                  
    	  @ 060,160 LABEL LCAB_L1C2;
                  WIDTH 90 ;
                  TOOLTIP "Total no Call Center";
                  VALUE 'Total no'
    
    	  @ 060,250 LABEL LCAB_L1C3;
                  WIDTH 90 ;
                  TOOLTIP "Registos por fazer";
                  VALUE 'Registos'
    
    	  @ 060,340 LABEL LCAB_L1C4;
                  WIDTH 90 ;
                  TOOLTIP "Registos bloqueados";
                  VALUE 'Registos'
    
    	  @ 060,430 LABEL LCAB_L1C5;
                  WIDTH 90 ;
                  TOOLTIP "Registos disponíveis";
                  VALUE 'Registos'
    
    	  @ 060,520 LABEL LCAB_L1C6;
                  WIDTH 90 ;
                  TOOLTIP "Entrevistas feitas";
                  VALUE 'Entrevistas'
    
    	  @ 060,610 LABEL LCAB_L1C7;
                  WIDTH 90 ;
                  TOOLTIP "Percentual de entrevistas feitas sobre o total no Call Center";
                  VALUE '% de feitos/'
                  
        // Segunda linha do cabeçalho das colunas //
    	  @ 075,160 LABEL LCAB_L2C2;
                  WIDTH 90 ;
                  TOOLTIP "Total no Call Center";
                  VALUE 'Call Center'
    
    	  @ 075,250 LABEL LCAB_L2C3;
                  WIDTH 90 ;
                  TOOLTIP "Registos por fazer";
                  VALUE 'p/fazer'
     
    	  @ 075,340 LABEL LCAB_L2C4;
                  WIDTH 90 ;
                  TOOLTIP "Registos Bloqueados";
                  VALUE 'Bloqueados'
    
    	  @ 075,430 LABEL LCAB_L2C5;
                  WIDTH 90 ;
                  TOOLTIP "Registos disponíveis";
                  VALUE 'Disponíveis'
    
    	  @ 075,520 LABEL LCAB_L2C6;
                  WIDTH 90 ;
                  TOOLTIP "Entrevistas feitas";
                  VALUE 'Feitas'
    
    	  @ 075,610 LABEL LCAB_L2C7;
                  WIDTH 90 ;
                  TOOLTIP "Percentual de entrevistas feitas sobre o total no Call Center";
                  VALUE 'Total'
    endif
                  
    mLINHA = 100
    
    Use CONTROLE alias CONTROLE new
    DbGotop()
    Do While .not. eof() .and. ATIVO

      mLABEL1 = "LABEL_R"+strzero(recno(),2)+ "_1"
      mLABEL2 = "LABEL_R"+strzero(recno(),2)+ "_2"
      mLABEL3 = "LABEL_R"+strzero(recno(),2)+ "_3"
      mLABEL4 = "LABEL_R"+strzero(recno(),2)+ "_4"
      mLABEL5 = "LABEL_R"+strzero(recno(),2)+ "_5"
      mLABEL6 = "LABEL_R"+strzero(recno(),2)+ "_6"
      mLABEL7 = "LABEL_R"+strzero(recno(),2)+ "_7"
                                                                                  
      @ mLINHA,010 LABEL &mLABEL1;
               WIDTH 90 ;
               TOOLTIP "Concessionário";
         			 VALUE Controle->Estudo

      @ mLINHA,170 LABEL &mLABEL2;
               WIDTH 50 ;
               TOOLTIP "Total no Call Center";
         			 VALUE STR(Controle->Tot_cc,6) RIGHTALIGN

      @ mLINHA,260 LABEL &mLABEL3;
               WIDTH 50 ;
               TOOLTIP "Registos por fazer";
         			 VALUE STR(Controle->TOT_MENS,6) RIGHTALIGN

      @ mLINHA,350 LABEL &mLABEL4;
               WIDTH 50 ;
               TOOLTIP "Registos bloqueados";
         			 VALUE STR(Controle->TOT_BLOQ,6) RIGHTALIGN

      skip
      mLINHA += 40
    Enddo

    goto bott

    mLABEL_TOT_1 = "LABEL_R"+strzero(recno(),2)+ "_TOT_1"
    mLABEL_TOT_2 = "LABEL_R"+strzero(recno(),2)+ "_TOT_2"
    mLABEL_TOT_3 = "LABEL_R"+strzero(recno(),2)+ "_TOT_3"
    mLABEL_TOT_4 = "LABEL_R"+strzero(recno(),2)+ "_TOT_4"
    mLABEL_TOT_5 = "LABEL_R"+strzero(recno(),2)+ "_TOT_5"
    mLABEL_TOT_6 = "LABEL_R"+strzero(recno(),2)+ "_TOT_6"
    mLABEL_TOT_7 = "LABEL_R"+strzero(recno(),2)+ "_TOT_7"

    @ mLINHA,010 LABEL &mLABEL_TOT_1;
             WIDTH 90 ;
             TOOLTIP "Totais";
       			 VALUE Controle->Estudo

    @ mLINHA,170 LABEL &mLABEL_TOT_2;
             WIDTH 50 ;
             TOOLTIP "Total no Call Center";
       			 VALUE STR(Controle->Tot_cc,6) RIGHTALIGN

    @ mLINHA,260 LABEL &mLABEL_TOT_3;
             WIDTH 50 ;
             TOOLTIP "Total por fazer";
       			 VALUE STR(Controle->Tot_mens,6) RIGHTALIGN

    @ mLINHA,350 LABEL &mLABEL_TOT_4;
             WIDTH 50 ;
             TOOLTIP "Total de registos bloqueados";
       			 VALUE STR(Controle->Tot_bloq,6) RIGHTALIGN

    close all
Return

//************************************************************//
// Procedure para atualizar os dados do ficheiro CONTROLE.DBF //
//************************************************************//
Procedure ACTUALIZA 


close all                                                 
use CONTROLE alias CONTROLE new

// abrir as areas de todos os ficheiros //
dbgotop()
do while .not. eof()
  if ATIVO
    mCAMINHO = alltrim(CAMINHO)
    mTENTADO = alltrim(TENTADOS)
    mALIAS_T = alltrim(ALIAS_TENT)
    mFICH_T  = mCAMINHO + mTENTADO

    mGRAVADO = alltrim(GRAVADOS)
    mALIAS_G = alltrim(ALIAS_GRAV)
    mFICH_G  = mCAMINHO + mGRAVADO

    use &mFICH_T alias &mALIAS_T new SHARED
    use &mFICH_G alias &mALIAS_G new SHARED

    select CONTROLE
  endif
  skip
enddo

// Inicializa as variaveis dos totais.
mGER_CC   = 0
mGER_MENS = 0
mGER_BLOQ = 0
mGER_DISP = 0
mGER_PVF  = 0
mGER_PERC = 0

select CONTROLE
goto top
do while .not. eof()
  if ATIVO
    mALIAS_T = alltrim(ALIAS_TENT)
    mALIAS_G = alltrim(ALIAS_GRAV)

    mTOT_CC   = 0
    mTOT_MENS = 0
    mTOT_BLOQ = 0
    mTOT_DISP = 0
    mTOT_PVF  = 0
    mPERCENT  = 0

    select &mALIAS_T
    count to mTOT_MENS
    count to mTOT_BLOQ for (substr(OBS1,1,2) = "XX" .or. substr(OBS1,1,2) = "xx")
    mTOT_DISP = mTOT_MENS - mTOT_BLOQ

    select &mALIAS_G
    count to mTOT_PVF

    mTOT_CC = mTOT_MENS + mTOT_PVF
    mPERCENT = iif(mTOT_CC > 0, (mTOT_PVF * 100)/mTOT_CC, 0)

    mGER_CC   += mTOT_CC
    mGER_MENS += mTOT_MENS
    mGER_BLOQ += mTOT_BLOQ
    mGER_DISP += mTOT_DISP
    mGER_PVF  += mTOT_PVF
    mGER_PERC = iif(mGER_CC > 0, (mGER_PVF * 100)/mGER_CC, 0)

    select CONTROLE
    rlock()
    replace TOT_CC   with mTOT_CC
    replace TOT_MENS with mTOT_MENS
    replace TOT_BLOQ with mTOT_BLOQ
    replace TOT_DISP with mTOT_DISP
    replace TOT_PVF  with mTOT_PVF
    replace TOT_PERC with mPERCENT
  endif
  skip
enddo

goto bottom
rlock()
replace TOT_CC   with mGER_CC
replace TOT_MENS with mGER_MENS
replace TOT_BLOQ with mGER_BLOQ
replace TOT_DISP with mGER_DISP
replace TOT_PVF  with mGER_PVF
replace TOT_PERC with mGER_PERC

close all

Return
Imagem

Agradeço desde já a ajuda.

Sérgio Pereira
Avatar do usuário
Pablo César
Usuário Nível 7
Usuário Nível 7
Mensagens: 5312
Registrado em: 31 Mai 2006 10:22
Localização: Curitiba - Paraná

refresh de form

Mensagem por Pablo César »

Sou programador em Clipper a muitos anos e agora estou desenvolvendo o meu primeiro projeto em HMG. Estou achando o máximo mas ainda estou deparando com alguns problemas que não me deixam ir à frente.
Oi Sérgio, fico muito contente saber que está gostando do HMG e mais ainda: errando... isso é sinal que você está aprendendo.

Sérgio, eu ja compilei seu programa, mas você poderia lista a estrutura do CONTROLE.DBF, daí vou poder te ajudar melhor. Pode ser ? E outra pergunta, esses dados provém de outro módulo, talvez de um Browse ?
estes valores devem ser atualizados online, ou pelo menos se não for possível online que se possa se recalcular os valores de tempos em tempos e/ou através de um botão.
Para que atualize você deve colocar um timer, mas o botão poderia ser utilizado também. Veja como ficaria com o timer:

...//... em lugar de @ 500,700 BUTTON Button_1... coloque
DEFINE TIMER Atualizador ;
INTERVAL 500 ;
ACTION Atualiza()
Um clip-abraço !

Pablo César Arrascaeta
Compartilhe suas dúvidas e soluções com todos os colegas aqui do fórum.
Evite enviar as dúvidas técnicas por MPs ou eMails, assim todos iremos beneficiar-nos.
Avatar do usuário
Toledo
Administrador
Administrador
Mensagens: 3133
Registrado em: 22 Jul 2003 18:39
Localização: Araçatuba - SP
Contato:

refresh de form

Mensagem por Toledo »

Olá Sergio, tente fazer o seguinte:

Código: Selecionar todos

Function Main()
Private nInter:=25  //Intervalo de Refresh em segundos
    
     DEFINE WINDOW Form_1   ;
              ROW 0 ;
              COL 0 ;
              WIDTH 800 ;
              HEIGHT 600   ;
              TITLE "Controle de Estudos";      
              WINDOWTYPE MAIN;
              ON INIT {|| Actualiza(), Mostra_valores(.f.)}
              ON RELEASE CloseTables();
              NOMAXIMIZE         ;
              NOSIZE            

              DEFINE LABEL Label_1
                    ROW    20
                    COL    300
                    WIDTH  200
                    HEIGHT 24
                    VALUE "Controle de Estudos"
                    FONTNAME "Arial"
                    FONTSIZE 14
                    TOOLTIP "Controle de Estudos"
                    FONTBOLD .T.
                    FONTITALIC .F.
                    FONTUNDERLINE .F.
                    FONTSTRIKEOUT .F.
                    HELPID Nil
                    VISIBLE .T.
                    TRANSPARENT .F.
                    ACTION Nil
                    AUTOSIZE .F.
                    BACKCOLOR NIL
                    FONTCOLOR {255,0,0}
              END LABEL

              @ 500,700 BUTTON Button_1 PICTURE "button5.bmp" WIDTH 50 HEIGHT 50 ACTION Refresh()

              DEFINE TIMER Timer_1 INTERVAL 15000 ACTION Refresh()
              
     END WINDOW

     Form_1.Timer_1.Value := (nInter*1000)     
     Form_1.Center
     Form_1.Activate

Return
Versão HMG Oficial

Código: Selecionar todos

Procedure Refresh
  Actualiza()

  Use CONTROLE alias CONTROLE new
  dbgotop()
  do while .not. eof() .and. ATIVO

    mLABEL1 = "LABEL_R"+strzero(recno(),2)+ "_1"
    mLABEL2 = "LABEL_R"+strzero(recno(),2)+ "_2"
    mLABEL3 = "LABEL_R"+strzero(recno(),2)+ "_3"
    mLABEL4 = "LABEL_R"+strzero(recno(),2)+ "_4"
    mLABEL5 = "LABEL_R"+strzero(recno(),2)+ "_5"
    mLABEL6 = "LABEL_R"+strzero(recno(),2)+ "_6"
    mLABEL7 = "LABEL_R"+strzero(recno(),2)+ "_7"


    Form_1.&(mLABEL1).Value := Controle->Estudo
    Form_1.&(mLABEL2).Value := STR(Controle->Tot_cc,6)
    Form_1.&(mLABEL3).Value := STR(Controle->TOT_MENS,6)
    Form_1.&(mLABEL4).Value := STR(Controle->TOT_BLOQ,6)

    skip

  enddo
 
  goto bott
  mLABEL_TOT_1 = "LABEL_R"+strzero(recno(),2)+ "_TOT_1"
  mLABEL_TOT_2 = "LABEL_R"+strzero(recno(),2)+ "_TOT_2"
  mLABEL_TOT_3 = "LABEL_R"+strzero(recno(),2)+ "_TOT_3"
  mLABEL_TOT_4 = "LABEL_R"+strzero(recno(),2)+ "_TOT_4"

  Form_1.&(mLABEL_TOT_1).Value := Controle->Estudo
  Form_1.&(mLABEL_TOT_2).Value := STR(Controle->Tot_cc,6)
  Form_1.&(mLABEL_TOT_3).Value := STR(Controle->TOT_MENS,6)
  Form_1.&(mLABEL_TOT_4).Value := STR(Controle->TOT_BLOQ,6)

  close all
  
Return
Versão Extended

Código: Selecionar todos

Procedure Refresh
  Actualiza()

  Use CONTROLE alias CONTROLE new
  dbgotop()
  do while .not. eof() .and. ATIVO

    mLABEL1 = "LABEL_R"+strzero(recno(),2)+ "_1"
    mLABEL2 = "LABEL_R"+strzero(recno(),2)+ "_2"
    mLABEL3 = "LABEL_R"+strzero(recno(),2)+ "_3"
    mLABEL4 = "LABEL_R"+strzero(recno(),2)+ "_4"
    mLABEL5 = "LABEL_R"+strzero(recno(),2)+ "_5"
    mLABEL6 = "LABEL_R"+strzero(recno(),2)+ "_6"
    mLABEL7 = "LABEL_R"+strzero(recno(),2)+ "_7"


    SetProperty( "Form_1", &mLABEL1, "Value", Controle->Estudo )
    SetProperty( "Form_1", &mLABEL2, "Value", STR(Controle->Tot_cc,6) )
    SetProperty( "Form_1", &mLABEL3, "Value", STR(Controle->TOT_MENS,6) )
    SetProperty( "Form_1", &mLABEL4, "Value", STR(Controle->TOT_BLOQ,6) )

    skip

  enddo
 
  goto bott
  mLABEL_TOT_1 = "LABEL_R"+strzero(recno(),2)+ "_TOT_1"
  mLABEL_TOT_2 = "LABEL_R"+strzero(recno(),2)+ "_TOT_2"
  mLABEL_TOT_3 = "LABEL_R"+strzero(recno(),2)+ "_TOT_3"
  mLABEL_TOT_4 = "LABEL_R"+strzero(recno(),2)+ "_TOT_4"

  SetProperty( "Form_1", &mLABEL_TOT_1, "Value", Controle->Estudo )
  SetProperty( "Form_1", &mLABEL_TOT_2, "Value", STR(Controle->Tot_cc,6) )
  SetProperty( "Form_1", &mLABEL_TOT_3, "Value", STR(Controle->TOT_MENS,6) )
  SetProperty( "Form_1", &mLABEL_TOT_4, "Value", STR(Controle->TOT_BLOQ,6) )

  close all
  
Return
Abraços,
Toledo - Clipper On Line
toledo@pctoledo.com.br
Harbour 3.2/MiniGui/HwGui
Faça uma doação para o fórum, clique neste link: http://www.pctoledo.com.br/doacao
spereira
Usuário Nível 2
Usuário Nível 2
Mensagens: 85
Registrado em: 19 Jul 2004 11:42
Localização: Porto - Portugal

refresh de form

Mensagem por spereira »

Olá Pablo e Toledo,
Muito obrigado pela ajuda.

Consegui fazer funcionar graças às vossas excelentes dicas, tanto o refresh quanto o timer. Sensacional!!!

Pablo, segue a estrutura do arquivo de controle:
  • Estrutura do Arquivo: CONTROLE.DBF

    1 ESTUDO C 30 0
    2 CAMINHO C 30 0
    3 TENTADOS C 8 0
    4 ALIAS_TENT C 7 0
    5 GRAVADOS C 8 0
    6 ALIAS_GRAV C 7 0
    7 TOT_CC N 6 0
    8 TOT_MENS N 6 0
    9 TOT_BLOQ N 6 0
    10 TOT_DISP N 6 0
    11 TOT_PVF N 6 0
    12 TOT_PERC N 6 0
    13 ATIVO L 1 0

Só não funciona se chamar estas funções no INIT do formulário, então chamei as funções após ter iniciado, conforme abaixo:

Código: Selecionar todos

#include <hmg.ch>

Function Main()
Private nInter:=25  //Intervalo de Refresh em segundos
    
  	DEFINE WINDOW Form_1   ;
              ROW 0 ;
		          COL 0 ;
		          WIDTH 800 ;
	            HEIGHT 600	;
	            TITLE "Controle de Estudos";		
		          WINDOWTYPE MAIN;
          		ON RELEASE CloseTables();
          		NOMAXIMIZE			;
          		NOSIZE				

              DEFINE LABEL Label_1
                    ROW    20
                    COL    300
                    WIDTH  200
                    HEIGHT 24
                    VALUE "Controle de Estudos"
                    FONTNAME "Arial"
                    FONTSIZE 14
                    TOOLTIP "Controle de Estudos"
                    FONTBOLD .T.
                    FONTITALIC .F.
                    FONTUNDERLINE .F.
                    FONTSTRIKEOUT .F.
                    HELPID Nil
                    VISIBLE .T.
                    TRANSPARENT .F.
                    ACTION Nil
                    AUTOSIZE .F.
                    BACKCOLOR NIL
                    FONTCOLOR {255,0,0}
              END LABEL

              @ 500,700 BUTTON Button_1 PICTURE "button5.bmp" WIDTH 50 HEIGHT 50 ACTION Refresh()

              DEFINE TIMER Timer_1 INTERVAL 15000 ACTION Refresh()
                            
              Actualiza()
              Mostra_valores()   			 

  	END WINDOW
  	
    Form_1.Timer_1.Value := (nInter*1000)
  	Form_1.Center
	  Form_1.Activate

Return
Andei vendo os exemplos do HMG da pasta SAMPLES, mas não consegui descobrir como fazer linhas horizontais e verticais para melhorar a aparência do formulário. Vocês poderiam me dar dicas de como fazer?

Mais uma vez obrigado pela ajuda.

Sérgio Pereira
Responder