;** Aplic **********************************************************************
;*  Manutencao Cadastro de Aplicacoes                                          *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/95 por Anivel Augusto Rodrigues
;Ultima Alteracao: 23/05/2008 por Anivel Augusto Rodrigues
;Motivo Alteracao: Inclusao Controla_Edicao

;*******************************************************************************
;* Rotina para Localizar Registro                                              *
;*******************************************************************************
Proc CHAVE()
Moveto [Codigo da Aplicacao]
End
SEQ=[Codigo da Aplicacao]
Down

While true
      SetaCorRegistro("Editar")
      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("Aplic","MR")
             If EDITAR="S"
                Then CHAVE=0
                     Controla_EdicaoC()
                Else If EXCLUIR="S"
                        Then If QuerExcluir("")
                                Then DEL
                                Else UnLockrecord
                             EndIf
                        Else Moveto [Codigo da Aplicacao]
                             End
                             SEQ = [Codigo da Aplicacao]
                             Down
                             QuitLoop
                     EndIf
             EndIf
             SetaPosForm()
           EndWhile
      Case Retval="ESC":
           CHAVE=9
           Del
           QuitLoop
      Case Retval="ENTER":
           If IsBlank([])
              Then If IsBlank(SEQ)
                      Then SEQ="1"
                      Else SEQ=StrVal(NumVal(SEQ)+1)
                    EndIf
                    []=SEQ
           EndIf
           []=ALINH()
           CODAPLIC=[]
           Del
           Locate CODAPLIC
           If Retval
              Then CHAVE=0
              Else CHAVE=1
                   End Down
                   [Codigo da Aplicacao]=CODAPLIC
           EndIf
           If IsLockRecord()
              Then End
                   SEQ=[Codigo da Aplicacao]
                   Down
                   Moveto [Codigo da Aplicacao]
                   Loop
           EndIf
           Quitloop
      EndSwitch
EndWhile
EndProc

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

Moveto [Descricao Aplicacao]
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()="Descricao Aplicacao"
              Then If QuerDesfazer("")
                      Then If CHAVE=1
                              Then Del
                              Else Undo
                           EndIf
                           CHAVE=9
                           QuitLoop
                   EndIf
              Else Left
           EndIf
      Case Retval="ENTER":
           If Field() = "Conta Contabil"
              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

;*******************************************************************************
;* 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 "Aplic"
PickForm "F"
While True
  CHAVE()
  If CHAVE=9
     Then QuitLoop
  EndIf
  Controla_EdicaoC()
EndWhile
Do_It!
ClearAll
Release Vars All
Release Procs All
