;*** AltCor ********************************************************************
;*  Altera a Cor do Sistema                                                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 30/04/2013 por Bruno Carvalho
;Ultima Alteracao: 10/05/2013 por Anivel Augusto Rodrigues 
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 23/05/2013 por Bruno Carvalho 
;Motivo Alteracao: Ajsutes p/ o cursor andar com apenas um toque/clique
;Ultima Alteracao: 31/12/2015 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes criado privdir() sys_Cor do sistema
;Ultima Alteracao: 14/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog
;Ultima Alteracao: 03/01/2017 por Rafael Matos
;Motivo Alteracao: Ajustes showdialog MensagemRadioButtons()                   
;Ultima Alteracao: 06/04/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog   

;*******************************************************************************
;Rotina ShowDialog
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Private Janela_SD, CoresSD, WinArray88 
Temp=True
MSG_CAMPO=""
TECLA=""

If Disparo="UPDATE" Or Disparo="OPEN"
   Then VSDGCOR=ControlValue("TG_COR")

        Window handle Dialog To Janela_SD
        If IsAssigned(CoresSD)
           Then Release Vars CoresSD
        EndIf
        Dynarray WinArray88[]
        Dynarray CoresSD[]
     
        Switch
          Case VSDGCOR=1  : CoresSD[01]=15    CoresSD[05]=14    CoresSD[14]=8    CoresSD[02]=7     CoresSD[15]=14   CoresSD[16]=14
          Case VSDGCOR=2  : CoresSD[01]=31    CoresSD[05]=30    CoresSD[14]=16   CoresSD[02]=25    CoresSD[15]=31   CoresSD[16]=31
          Case VSDGCOR=3  : CoresSD[01]=47    CoresSD[05]=46    CoresSD[14]=32   CoresSD[02]=42    CoresSD[15]=47   CoresSD[16]=47
          Case VSDGCOR=4  : CoresSD[01]=63    CoresSD[05]=62    CoresSD[14]=48   CoresSD[02]=58    CoresSD[15]=63   CoresSD[16]=62
          Case VSDGCOR=5  : CoresSD[01]=79    CoresSD[05]=78    CoresSD[14]=64   CoresSD[02]=76    CoresSD[15]=79   CoresSD[16]=78
          Case VSDGCOR=6  : CoresSD[01]=95    CoresSD[05]=94    CoresSD[14]=80   CoresSD[02]=93    CoresSD[15]=95   CoresSD[16]=95
          Case VSDGCOR=7  : CoresSD[01]=111   CoresSD[05]=110   CoresSD[14]=96   CoresSD[02]=110   CoresSD[15]=111  CoresSD[16]=111
          Case VSDGCOR=8  : CoresSD[01]=120   CoresSD[05]=116   CoresSD[14]=112  CoresSD[02]=120   CoresSD[15]=120  CoresSD[16]=120
          Case VSDGCOR=9  : CoresSD[01]=128   CoresSD[05]=142   CoresSD[14]=128  CoresSD[02]=135   CoresSD[15]=128  CoresSD[16]=128
          Case VSDGCOR=10 : CoresSD[01]=160   CoresSD[05]=172   CoresSD[14]=160  CoresSD[02]=162   CoresSD[15]=160  CoresSD[16]=160
          Case VSDGCOR=11 : CoresSD[01]=230   CoresSD[05]=237   CoresSD[14]=230  CoresSD[02]=224   CoresSD[15]=230  CoresSD[16]=230
        EndSwitch    

        Window SetColors     Janela_SD From CoresSD
        Window SetAttributes Janela_SD From WinArray88
EndIf

If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = 9: Temp=False
     Case Evento["KeyCode"] = -59: Dialog_F1()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_COR"    : Campo="NO"
            Case Campo="YES" Or Campo="NO" : Campo="TG_COR"
          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_COR"      : Campo="YES" 
                         VSDGCOR=ControlValue("TG_COR")
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_COR" :
      MensagemRadioButtons()
Endswitch

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp

EndProc ;SD_Dialog()

;*******************************************************************************
;* Rotina Principal                                                          * 
;*******************************************************************************
Autolib="\\Sistemas\\Cadastro\\Bibliot,\\Sistemas\\Cadastro\\Bib_Show"

Aguarde("Atualizando Sistema")
Password("t01avivcl")
Password("FechaSys")

View "SysTable"
COR_ATUAL=[Cor_Sistema]
ClearAll 

Switch
  Case COR_ATUAL="PRETO"    : VSDGCOR=1 
  Case COR_ATUAL="AZUL"     : VSDGCOR=2
  Case COR_ATUAL="VERDE"    : VSDGCOR=3
  Case COR_ATUAL="CYAN"     : VSDGCOR=4
  Case COR_ATUAL="VERMELHO" : VSDGCOR=5
  Case COR_ATUAL="MAGENTA"  : VSDGCOR=6
  Case COR_ATUAL="MARROM"   : VSDGCOR=7
  Case COR_ATUAL="BRANCO"   : VSDGCOR=8
  Case COR_ATUAL="CINZA"    : VSDGCOR=9
  Case COR_ATUAL="LIMAO"    : VSDGCOR=10
  Case COR_ATUAL="AMARELO"  : VSDGCOR=11
EndSwitch   

While True
  ShowDialog "Escolha a Cor do Sistema" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE","UPDATE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 05,12   Height 13 Width 72

    RadioButtons @ 01,02 Height 3 Width 66
      "PRETO     ",
      "AZUL      ",
      "VERDE     ",
      "CYAN      ",
      "VERMELHO  ",
      "MAGENTA   ",
      "MARROM    ",
      "BRANCO    ",
      "CINZA     ",
      "LIMAO     ",
      "AMARELO   " 
    Tag "TG_COR"
    To VSDGCOR     
     
    @ 06,03 ?? "Sua cor do Sistema atual ‚ "+COR_ATUAL   
                              
    Pushbutton @ 09,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 09,36 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  Switch
    Case VSDGCOR=1  : VSDGCOR="PRETO"
    Case VSDGCOR=2  : VSDGCOR="AZUL"
    Case VSDGCOR=3  : VSDGCOR="VERDE"
    Case VSDGCOR=4  : VSDGCOR="CYAN"
    Case VSDGCOR=5  : VSDGCOR="VERMELHO"
    Case VSDGCOR=6  : VSDGCOR="MAGENTA"
    Case VSDGCOR=7  : VSDGCOR="MARROM"
    Case VSDGCOR=8  : VSDGCOR="BRANCO"
    Case VSDGCOR=9  : VSDGCOR="CINZA"
    Case VSDGCOR=10 : VSDGCOR="LIMAO"
    Case VSDGCOR=11 : VSDGCOR="AMARELO"
  EndSwitch   

;;If VSDGCOR=COR_ATUAL Then QuitLoop EndIf

  CoEdit "SysTable"
  Moveto [Cor_Sistema]
  []=VSDGCOR
  Do_It!
  ClearAll 

  FileWrite PrivDir()+"SYS_COR.sc" From  "SYS_COR="+VSDGCOR+"\n"

  Editor Open "Savevars.sc"
  Editor Find "SYS_COR "
  If RetVal
     Then DELETELINE
          ENTER
          UP
          TypeIn "SYS_COR = \""
          TypeIn VSDGCOR
          TypeIn "\""
          DOWN
  EndIf
  Home
  Do_It!
  
  RetVal=-22
  IsTeclaAtalho()


  QuitLoop
EndWhile
ClearAll
Release Vars All
Release Procs All
