;** Cobrador *******************************************************************
;*  Cadastro de Cobradores                                                     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 07/11/2003 por Karen Lauar Nery
;Ultima Alteracao: 23/05/2008 por Anivel Augusto Rodrigues
;Motivo Alteracao: Inclusao Controla_Edicao
;Ultima Alteracao: 29/12/2010 por Bruno Carvalho
;Motivo Alteracao: Ajustes Novo Layout de Teclas
;Ultima Alteracao: 01/01/2013 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes SetaCorRegistro("Editando") 

;*******************************************************************************
;* Rotina para Localizar Registro                                              *
;*******************************************************************************
Proc CHAVE()
While True
  End
  SEQ=[Codigo do Cobrador]
  Down
  Moveto [Codigo do Cobrador]

  SetaCorRegistro("Editar")

  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("Cobrador","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 If IsBlank(SEQ)
                  Then []="1"
                  Else []=StrVal(NumVal(SEQ)+1)
               EndIf
       EndIf
       []=Alinh()
       CODIGO=[]
       Del
       Locate CODIGO
       If Retval
          Then CHAVE=0
          Else CHAVE=1
               End Down
               [Codigo do Cobrador]=CODIGO
       EndIf
       If IsLockRecord()
          Then Loop
       EndIf
       Quitloop
  EndSwitch
EndWhile
EndProc

;*******************************************************************************
;* Rotina para Digitacao das Informacoes                                       *
;*******************************************************************************
Proc DIGITA()
Moveto [Descricao do Cobrador]
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()="Descricao do Cobrador"
          Then If QuerDesfazer("")
                  Then If CHAVE=1
                          Then Del
                          Else Undo
                       EndIf
                       CHAVE=9
                       QuitLoop
               EndIf
          Else Left
       EndIf
  Case Retval="ENTER":
       If IsBlank([])
          Then Loop
       EndIf
       If Field() = "Descricao do Cobrador"
          Then QuitLoop
          Else Right
       EndIf
  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 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 "Cobrador"
PickForm "F"
While True
  CHAVE()
  If CHAVE=9
     Then QuitLoop
  EndIf
  Controla_EdicaoC()
EndWhile
Do_It!
ClearAll
Release Vars All
Release Procs All
