;** Numera‡Æo Para Mostru rio **************************************************
;*  PROGRAMA DE IMPRESSAO DE NUMERA€ÇO PARA MOSTRUARIO                         *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 10/12/2009 por Bruno Carvalho
;Ultima Alteracao: 03/01/2011 por Bruno Carvalho
;Motivo Alteracao: Ajustes Novo Layout de Teclas    

;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc ORDEM()
ClearAll

{Ask} {\\Sistemas\\Estoque\\RE_0010E} CheckPlus
Do_It!
ClearAll
EndProc  ; (Ordem)
;*******************************************************************************
;* Rotina para Localizar Registro                                              *
;*******************************************************************************
Proc CHAVE()

While True
  SetaCorRegistro("Editar")

  End
  Down

  Moveto [Numero]

  TECLA=""
  AguardaTeclasPadrao()

  If RetVal=-33
       Then Echo Normal
            Echo Off
            ShowPopup " Fun‡”es " CENTERED                           
             "F6 ~I~mprimir        " : " Imprimir etiquetas              " : "F6",
             "~C~ancelar           " : " Cancelar a Opera‡„o             " : "CANCELAR"
            EndMenu
             To MenuVar

            echo off
            If MenuVar="CANCELAR" or MenuVar="Esc"
                Then Loop                                       
            EndIf

            RetVal=MenuVar
  EndIf

  Switch
  Case RetVal="F3": SemFicha()
  Case RetVal=-94 : MsgTeclasPadrao()
  Case RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
       While True
         PAGINA("RE_0010E","MR")
         If EDITAR="S"
            Then CHAVE=0
                 Controla_EdicaoC()
            Else If EXCLUIR="S"
                    Then If QuerExcluir("")
                            Then DEL
                            Else UnLockRecord
                         EndIf
                    Else QuitLoop
                 EndIf
         EndIf
         SetaPosForm()
       EndWhile
  Case Retval="ESC":
       CHAVE=9
       Del
       QuitLoop
  Case RetVal="ENTER":
       If IsBlank([])
          Then Mensagem("Informe a Numera‡Æo para Mostru rio") 
               Loop
       EndIf
       CODIGO=[]
       Del
       Locate CODIGO
       If Retval
          Then CHAVE=0
          Else CHAVE=1
               End Down
               [Numero]=CODIGO
       EndIf
       If IsLockRecord()
          Then If CHAVE=1 Then Del EndIf
               Loop
       EndIf
       Quitloop
  Case Retval="F6" :
         Del
         If Not IsEmpty("Re_0010E")
            Then IMPRIME()
         EndIf
  EndSwitch  
EndWhile
EndProc

;*******************************************************************************
;* Rotina para Digitacao das Informacoes                                       *
;*******************************************************************************
Proc DIGITA()
Moveto [Quantidade]
While True

  TECLA=" Esc=Retornar  "

  If CHAVE=0
     Then TECLA=TECLA+"Del=Excluir  "
  EndIf

  MSGCAMPO=""
  Switch
     Case Field()="Numero"       : MSGCAMPO="Informe a Numera‡Æo para o Mostru rio (Ex: 01)"
     Case Field()="Quantidade"   : MSGCAMPO="Quantidade de Etiquetas a serem Impressas. (4 N£meros por Etiqueta)"
  EndSwitch

  Prompt TECLA

  Wait Field
       Message MSGCAMPO
       Until "ESC","ENTER","DEL","FIELDVIEW","F35"

  Switch
  Case Retval="ESC":
       Switch
       Case Field()="Numero" :
            If QuerDesfazer("")
                   Then If CHAVE=1
                          Then Del
                          Else If RecordStatus("Modified")
                                  Then Undo
                               EndIf
                       EndIf
                       CHAVE=9
                       QuitLoop
               EndIf
       Case Field()="Quantidade" : Moveto[Numero]
       Otherwise : Left           
       EndSwitch             
                  
  Case Retval="ENTER":
        If IsBlank([Numero])
           Then Mensagem("Informe a Numera‡Æo para Mostru rio") 
           Loop
        EndIf
        Switch
        Case Field() = "Quantidade" : 
             If IsBlank([])
                Then Loop
             EndIf    
             Quitloop
        Otherwise : Right
       EndSwitch
  Case Retval="FIELDVIEW" or Retval="F35":
       EDITFIELD()
  Case Retval="DEL":
       If CHAVE=0
          Then If QuerExcluir("")
                  Then DEL
                       QuitLoop
               EndIf
       EndIf
  EndSwitch
EndWhile
EndProc  ; (Digita)

;*******************************************************************************
;* Rotina para ImpressÆo                                                       *
;*******************************************************************************
Proc IMPRIME()
LimpaRodape(0)
Do_It!
ClearAll

While True

  DISPOSITIVO()
  If OK="" Then QuitLoop EndIf
  
  AGUARDE("Aguarde, Gerando Relat¢rio")
  ORDEM()
  If IsEmpty("Answer")
     Then MENSAGEM("N„o Existem Registros a Processar")
          Loop
  EndIf

  Empty("Answer")

  View "Answer"
  CoEdit "Re_0010E"
     Scan
     CopyToArray REG
     Moveto "Answer"
     For I From 1 to [Re_0010E->Quantidade]
      End
      Down
      CopyFromArray Reg
    EndFor
      Moveto "Re_0010E"
    EndScan
      Do_It!
      ClearAll
 
  CopyReport "\\Base\\Sistemas\\Estoque\\Re_0010E" "R" "Answer" "R"

  IMPRIREL("Answer","R")

  Delete "Answer"
  CHAVE=9
  QuitLoop
EndWhile
ClearAll

CoEdit "RE_0010E"
PickForm "F"    


EndProc  ; (Imprime)

;************************************
;* ROTINA PARA LIMPAR AGUARDE       *
;************************************
Proc LimpAguarde2L()
@ 23,0 ?? Fill(" ",80)
PaintCanvas Attribute 31 23,0,23,79
@ 24,0 ?? Fill(" ",80)
PaintCanvas Attribute 31 24,0,24,79
EndProc ; (LimpAguarde2L)


;*******************************************************************************
;* Rotina para controlar Edicao do registro                                    *
;*******************************************************************************
Proc Controla_EdicaoC()
DIGITA()
If RecordStatus("Locked") Then UnLockRecord EndIf         
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bibliot,\\Sistemas\\Cadastro\\Bib_Show"

CoEdit "RE_0010E"
PickForm "F"    

While True
  CHAVE()
  If CHAVE=9 Then QuitLoop EndIf
  Controla_EdicaoC()
EndWhile
Do_It!
ClearAll
Release Vars All
Release Procs All
