;** LOCAL **********************************************************************
;*  PROGRAMA DE CADASTRO DE LOCAIS                                             *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 24/06/98 por Anivel Augusto Rodrigues
;Ultima Alteracao:   /  /   por
;Motivo Alteracao:

;*******************************************************************************
;* Rotina para Localizar Registro                                              *
;*******************************************************************************
Proc CHAVE()
While True
      End
      Down

      Prompt " Esc=Sair  F7=Paginar  "

      Wait Field
      Until "ESC","ENTER","F7","HOME","UP","PGUP",
            -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140
            
      If SubStr(RetVal,1,2)="-1"      
         Then SYS_TECLA_ACIONADA=RetVal 
              Seta_Tecla_Acionada()     
              RetVal="ESC"            
      EndIf                             
                                                                   

      Switch
      Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
           While True
             PAGINA("LOCAL","MR")
             If EDITAR="S"
                Then CHAVE=0
                     Return
                Else If EXCLUIR="S"
                        Then CONFIRMA()
                             If OK="S"
                                Then DEL
                             EndIf
                     EndIf
             EndIf
             QuitLoop
             End Down
           EndWhile
      Case Retval="ESC":
           CHAVE=9
           Del
           QuitLoop
      Case RetVal="ENTER":
           If IsBlank([])
              Then Loop
           EndIf
           CODIGO=[]
           Del
           Locate CODIGO
           If Retval
              Then CHAVE=0
              Else CHAVE=1
                   End Down
                   [Local]=CODIGO
           EndIf
           If IsLockRecord()
              Then Loop
           EndIf
           Quitloop
      EndSwitch
EndWhile
EndProc

;*******************************************************************************
;* Rotina para confirmacao da chave                                            *
;*******************************************************************************
Proc DIGITA()
Moveto [Local]
While True

      TECLA=" Esc=Retornar  "

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

      Prompt TECLA

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

      Switch
      Case Retval="ESC":
           If Field()="Local"
              Then If CHAVE=1
                      Then Del
                      Else If RecordStatus("Modified")
                              Then Undo
                           EndIf
                   EndIf
                   CHAVE=9
                   QuitLoop
              Else Left
           EndIf
      Case Retval="ENTER":
           If IsBlank([])
              Then Loop
           EndIf
           If Field() = "Local"
              Then CODIGO=[]
                   Del
                   Locate CODIGO
                   If Retval
                      Then CHAVE=0
                      Else CHAVE=1
                           End Down
                           [Local]=CODIGO
                   EndIf
                   QuitLoop
              Else Right
           EndIf
      Case Retval="FIELDVIEW" or Retval="F35":
           EDITFIELD()
      Case Retval="DEL":
           If CHAVE=0
              Then CONFIRMA()
                   If OK="S"
                      Then DEL
                           QuitLoop
                   EndIf
           EndIf
      EndSwitch
EndWhile
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bibliot,\\Sistemas\\Cadastro\\Bib_Show"
CoEdit "LOCAL"
PickForm "F"
While True
      CHAVE()
      If CHAVE=9
         Then QuitLoop
     EndIf
     If CHAVE=0
        Then DIGITA()
     EndIf
EndWhile
Do_It!
ClearAll
Release Vars All
Release Procs All
