;** Listtit ********************************************************************
;*  Manutencao de Cadastro de comunicados                                      *
;*********************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 03/04/2019 por Anivel Augusto Rodrigues
;Ultima Alteracao:   /  /     por 
;Motivo Alteracao:                      

;*******************************************************************************
;* Rotina para Localizar Registro                                              *
;*******************************************************************************
Proc CHAVE()

while true
  End
  SEQ=[CodigoTitulo]
  Down
  
  Moveto [CodigoTitulo]
  
  SetaCorRegistro("Editar")
  While true
  
    TECLA=""
    AguardaTeclasPadrao()
  
    Switch
        Case RetVal=-33 : SemFuncoes()
        Case RetVal="F3": SemFicha()
        Case RetVal=-94 : MsgTeclasPadrao()
        Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
             While True
               PAGINA("ListTit","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
             quitloop
        Case Retval="ESC":
             CHAVE=9
             Del
             return
        Case RetVal="ENTER":
           COD=[]   
           Del
           If IsBlank(COD)
              Then COD=SEQ+1
           EndIf                       

           Locate COD
           If Retval
              Then CHAVE=0
              Else CHAVE=1
                   End Down
                   [CodigoTitulo]=COD
           EndIf
           If not IsLockRecord()
              Then return
           EndIf
  
           QuitLoop
        EndSwitch
  EndWhile
endwhile
EndProc  ; (CHAVE)

;*******************************************************************************
;* Rotina para Digitacao das Informacoes                                       *
;*******************************************************************************
Proc DIGITA()

Moveto [DescricaoTitulo]
While True

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

      Prompt TECLA
      SetaCorRegistro("Editando")
      Wait Field
           Until "ESC","ENTER","DEL","FIELDVIEW","F35"

      Switch

      Case Retval="ESC":
           If Field()="DescricaoTitulo"
              Then If QuerDesfazer("")
                      Then If CHAVE=1
                              Then Del
                              Else Undo
                           EndIf
                           CHAVE=9
                           QuitLoop
                   EndIf
              Else Left     
           EndIf
      Case Retval="ENTER":
           Switch
             Case Field()="DescricaoTitulo":
                if isblank([]) then fastmsg("Conte£do inv lido !") 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

;*******************************************************************************
;* 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"

sys_Valor()

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