;** LSERVIC ********************************************************************
;*  Manutencao de Cadastro de SERVICOS                                         *
;*********************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 27/12/2012 por Kamila Gomes
;Ultima Alteracao: 18/02/2013 por Kamila Gomes
;Motivo Alteracao: Ajustes SetaCorRegistro("Editando")                     
;Ultima Alteracao: 23/07/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes CNAE                                            

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

End
Down
Moveto [Codigo_Servico]

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("LServic","MR")
             If EDITAR="S"
                Then CHAVE=0
                     Controla_EdicaoC()
               Else If EXCLUIR="S"
                        Then If QuerExcluir("")
                                Then DEL
                                Else UnLockRecord
                             EndIf
                        Else Moveto [Codigo_Servico]
                             End
                             Down
                             QuitLoop
                     EndIf
             EndIf
             SetaPosForm()
           EndWhile
      Case Retval="ESC":
           CHAVE=9
           Del
           QuitLoop
      Case RetVal="ENTER":
           If IsBlank([]) Then Loop EndIf
           CODN=[]
           Del
           Locate CODN
           If Retval
              Then CHAVE=0
              Else CHAVE=1
                   End Down
                   Moveto [Codigo_Servico]
                   [Codigo_Servico]=CODN
           EndIf
           If IsLockRecord()
              Then End Down
                   Moveto [Codigo_Servico]
                   Loop
           EndIf
           Quitloop
      EndSwitch
EndWhile
EndProc  ; (CHAVE)

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

Moveto [CodigoCNAE]
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()="CodigoCNAE"
              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()="CodigoCNAE":
                    If Not Edita_Memo("Descricao_Servico",10,01,13,76,"Descricao do Servico "+StrVal([Codigo_Servico]))
                       Then Undo
                    EndIf
                    quitloop
                 
                 Case Field()="":
                      If IsBlank([])Then Loop EndIf
                      QuitLoop
                      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"
CoEdit "LServic"

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