;** Calc_MA  *******************************************************************
;*  Calcula Madeira                                                            *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    : 23/04/2010 por Cleber Alves
;Ultima Alteracao: 
;Motivo Alteracao: 

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialogc(Disparo,Campo,Evento,Elemento)
private Disparo,Campo,Evento,Elemento,temp, MSG_CAMPO,TECLA
Temp=True
MSG_CAMPO=""
TECLA=""
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_Quant"         : Campo="NO"
            Case Campo="TG_Metros"        : Campo="TG_Quant"
            Case Campo="TG_Bitola1"       : Campo="TG_Metros"
            Case Campo="TG_Bitola2"       : Campo="TG_Bitola1"           
            Case Campo="YES" Or Campo="NO": Campo="TG_Bitola2"
          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
                  Switch
                    Case Campo="TG_COD"            :
                         VSDGCOD=ControlValue("TG_COD")
                         Campo="TG_NOME"
                         
                    Case Campo="TG_Quant"   : 
                    Quantmd=ControlValue("TG_Quant")
                    Campo="TG_Metros"
                    Case Campo="TG_Metros"  : 
                    Metrosmd=ControlValue("TG_Metros")
                    Campo="TG_Bitola1"                    
                    Case Campo="TG_Bitola1" : 
                    Bit1md=ControlValue("TG_Bitola1")                   
                    Campo="TG_Bitola2"                  
                    Case Campo="TG_Bitola2" :    
                         Bit2md=ControlValue("TG_Bitola2")  
                         totalmd= NumVal(Quantmd)*NumVal(Metrosmd )*NumVal(Bit1md)*NumVal(Bit2md)
                         Campo="YES"
                    Case Campo="YES":
                         AcceptDialog
                    Case Campo="NO":
                         CANCELDIALOG
                         
                  EndSwitch
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_DTINI":
       MSG_CAMPO="Informe a Data Inicial"  
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
;AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
;LimpAguarde()
Proc Cal()
Quantmd = 0
Metrosmd = 0
Bit1md = 0 
Bit2md = 0

  ShowDialog "Madeira" Proc "SD_Dialogc"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 03,08
    Height 15 Width 31

    Label  @ 01,01 "Quantidade"  For "TG_Quant"
    Accept @ 01,13 Width 08 "N"  Picture "#*#.[###]"  Tag "TG_Quant"   To Quantmd        

    Label  @ 03,01 "Metros"  For "TG_Metros"
    Accept @ 03,13 Width 08 "N"  Picture "#*#.[###]"  Tag "TG_Metros"   To Metrosmd     

    Label  @ 05,01 "Bitola-1"  For "TG_Bitola1"
    Accept @ 05,13 Width 08 "N"  Picture "#*#.[###]"  Tag "TG_Bitola1"   To Bit1md   

    Label  @ 07,01 "Bitola-2"  For "TG_Bitola2"
    Accept @ 07,13 Width 08 "N"  Picture "#*#.[###]"  Tag "TG_Bitola2"   To Bit2md

    Label  @ 09,01 "ToTal  ="  For "TG_TOTAL"
    Accept @ 09,13 Width 08 "N"  Picture "#*#.[###]"  Tag "TG_TOTAL"   To totalmd   
    
    Pushbutton @ 11,03 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 11,15 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue
    
  EndDialog  
  
  If RetVal 
     Then VSD_I_Quantidade = totalmd
  endif    
  
EndProc

Cal()

Release Procs SD_Dialogc,Cal
Release Vars Quantmd,Metrosmd,Bit1md,Bit2md,totalmd
