;** Rc_0141 ********************************************************************
;*  Opcao de Relatorio para Lista Telefonica                                   *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 17/02/2004 por Karen Lauar Nery
;Ultima Alteracao: 04/01/2012 por Bruno Carvalho
;Motivo Alteracao: Incluido no Report Telefone Celular
;Ultima Alteracao: 09/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog
;Ultima Alteracao: 26/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes showdialog e TG_CODMODELO                   
;Ultima Alteracao: 29/05/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Adicionado ValidarModelosRelatorios()

;*******************************************************************************
;* Rotina p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
Proc ORDEM()
{Ask} {Listfone} Check
Do_It!
ClearAll
EndProc ; (Ordem)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
MSG_CAMPO=""
TECLA=""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = -59: Dialog_F1()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_CODMODELO"     : Campo="NO"
            Case Campo="TG_OPRELCODALF"   : Campo="TG_CODMODELO"
            Case Campo="YES" Or Campo="NO": Campo="TG_CODMODELO"
          EndSwitch
     Case (Evento["KeyCode"] <= -104 And Evento["KeyCode"] >= -113) Or 
           Evento["KeyCode"]  = -139 Or  Evento["KeyCode"]  = -140:
           SYS_TECLA_ACIONADA=Evento["KeyCode"]
           Seta_Tecla_Acionada()
           CancelDialog
     Case Evento["KeyCode"] = 13:
          Temp=False
          If Checa_TAG()
             Then Switch
                    Case Campo="TG_CODMODELO"    : 
                        If VSDGCODMODELO="01"
                           Then Campo="TG_OPRELCODALF"
                                VSDGNOMOPRELCODALF=""
                           Else VSDGOPRELCODALF=""
                                VSDGNOMOPRELCODALF="ALFABETICA"                                
                                Campo="YES"
                        EndIf                         
                    Case Campo="TG_OPRELCODALF"  : 
                         If VSDGOPRELCODALF="1"
                            Then VSDGNOMOPRELCODALF="CODIGO"
                            Else VSDGNOMOPRELCODALF="CIDADE/BAIRRO"
                         EndIf        
                         Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_OPRELCODALF":
       MSG_CAMPO="Op‡”es: 1=Codigo  2=Cidade/Bairro"
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;************************************
;* ROTINA PARA Ler/Gravacao Opcao   *
;************************************
Proc ModeloRelatoriosCarregaLista()

VSDGCODMODELO     = ""
VSDGMODELO        = ""

;ModeloRelatoriosAdd("XXX XX maximo 70 XX")

ModeloRelatoriosAdd("Criar") ; linha obrigatoria inicial
ModeloRelatoriosAdd("01  Lista Tel. Comercial/Residencial/Celular")
ModeloRelatoriosAdd("02  Lista Tel. Celular/Observa‡äes")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista

;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
LimpAguarde()

ModeloRelatoriosCarregaLista()

While True
 ShowDialog "Menu de Opcao p/ Relat¢rios" Proc "SD_Dialog"
   Trigger "OPEN","ARRIVE"
    Key "TAB","ReverseTab","ENTER","ESC","F1",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140    
     @ 05,12 Height 10 Width 72
     
    Label  @ 01,00  "Modelo de ~R~elat¢rio"  For "TG_CODMODELO"
    Accept @ 02,01  Width 06 "A3"  Picture "!*!" Tag "TG_CODMODELO" To VSDGCODMODELO
    Accept @ 02,06  Width 63 "A60"  Picture "!*!" Tag "TG_MODELO" To VSDGMODELO 

    Label  @ 03,00 "Ordem" For "TG_OPRELCODALF"
    Accept @ 04,04 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 04,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF

    Pushbutton @ 06,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 06,36 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  if not ValidarModelosRelatorios() then loop endif         

 DISPOSITIVO()
 If OK="" Then Loop EndIf

 AGUARDE("Aguarde, gerando relat¢rio")
 ORDEM()
 If IsEmpty("Answer")
    Then MENSAGEM("N„o Existem Registros a Processar")
         Loop
 EndIf  
  
  Switch
      Case VSDGCODMODELO="01"  :  If VSDGOPRELCODALF = "1" Then CopyReport "\\Base\\Sistemas\\Cadastro\\Listfone" "R"  "Answer" "R" 
                                                           Else CopyReport "\\Base\\Sistemas\\Cadastro\\Listfone" "1"  "Answer" "R" 
                                  EndIf
      Case VSDGCODMODELO="02"  :  CopyReport "\\Base\\Sistemas\\Cadastro\\Listfone" "2"  "Answer" "R"                                                  
  EndSwitch
  
  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

