;** RESTRIC ********************************************************************
;*  Cadastro de CGC/CPF com Restricoes                                         *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 29/11/2012 por Kamila Gomes  
;Ultima Alteracao: 04/01/2013 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes 

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

While True
  End
  Down
  Moveto [CGC]
  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("RESTRIC","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":
  
         CGC=[]
         If IsBlank(CGC)                     Then Loop EndIf
         If Not Checa_CGC_CPF_Formatado(CGC) Then Loop EndIf
         Del
         Locate CGC
         If Retval
            Then CHAVE=0
            Else CHAVE=1
                 End Down
                [CGC]=CGC
         EndIf
  
         If IsLockRecord()
            Then Loop
         EndIf
         Return
    EndSwitch
  EndWhile
EndWhile
EndProc

;*******************************************************************************
;* Rotina para Digitacao das Informacoes                                       *
;*******************************************************************************

Proc DIGITA()
Moveto [Razao_Nome   ]
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()="Razao_Nome"
              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() = "Razao_Nome":
                      If IsFieldNull([]) Then Loop EndIf
                      If CHAVE=1
                           Then [Consta_Restricao]="S"
                               [Ultima Restricao]=Today()
                               QuitLoop
                           Else ShowPopup " Restricao " @ 02,52
                                  "Sim  " : " Consta Restri‡Æo       "   : "S",
                                  "NÆo  " : " CNPJ/CPF Liberado      "   : "N"
                           EndMenu
                           To MenuVar
                           If MenuVar="Esc"
                              Then Loop              
                              Else [Consta_Restricao]=MenuVar
                           EndIf
                           If Menuvar="S"     
                              Then [Ultima Restricao   ]=Today()
                                   [Liberacao Restricao]=BlankDate()
                                   QuitLoop
                              Else [Liberacao Restricao]=Today()
                                    QuitLoop
                          EndIf
                      EndIf     
            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 "Restric"
PickForm "F"

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