*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*
* nastavi v setupech kas eet_typ = 0
*
* 2022-12-16
*
*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    

small_log(m.gchom_path + " " + m.sqldatabaza, PROGRAM())

IF m.issql

  IF ATC("d_magnetic", m.sqldatabaza) + ATC("d_xxxxxxx", m.sqldatabaza) > 0
    small_log ("v datech " + m.sqldatabaza + " se eet nevypina", PROGRAM())
  ELSE

    co_udelat = "UPDATE food600.defsubor SET var_value = '0' WHERE var_name = 'eet_typ' ;"

    DO open_database
    vysledek = sql_exec( m.co_udelat )
    zprava_do_logu = m.co_udelat + STR(m.vysledek, 5)
    IF m.vysledek < 0
        DIMENSION chybaexe(9)
        chybaexe(2) = "vsechno v poradku"
        AERROR(chybaexe)
        MESSAGEBOX("SQL Chyba" + CHR(10) + chybaexe(2),64)
        zprava_do_logu = m.zprava_do_logu + " " + chybaexe(2)
    ENDIF
    small_log (m.zprava_do_logu, PROGRAM())
  ENDIF 

ELSE 
    clos_data()
    crea table (m.gcpri_path + "soubory") free (adresar c(111), nazev c(44), atrib c(1), delka n(9), datum D )
    do jedenadresar with m.gchom_path
    SELECT soubory
    do while .t.
       locate for "D" $ atrib .and. delka = 0
       if found()
           repl delka with -1111111
           do jedenadresar with allt(adresar)
       else
           exit
       endif
    ENDDO 

    DELETE FOR ATC(".dbf  ", nazev) = 0
    DELETE FOR ATC("s_k32_", nazev) = 0

    SCAN 
        jedensoubor = ALLT(adresar) + ALLTRIM(nazev)
        chybicka = m.jedensoubor
        WAIT m.chybicka WINDOW NOWAIT 
        TRY
            SELECT 0
            USE (m.jedensoubor)
            LOCATE FOR var_name = "eet_typ " .and. VAL(var_value) # 3
            IF FOUND()
                chybicka = m.chybicka + " " + ALLTRIM(var_name) + ": " + ALLTRIM(var_value)
                REPLACE var_value WITH "0"
            ENDIF 
            USE 
            
        CATCH TO oErr 
            chybicka = m.chybicka + " " + ALLTRIM(STR(oErr.ErrorNo)) + " " + oErr.Message + " Line:" + ALLTRIM(STR(oErr.LineNo))
        ENDTRY
        small_log(m.chybicka, PROGRAM())
    ENDSCAN 
ENDIF 
WAIT CLEAR 


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
PROCEDURE  jedenadresar
PARAMETERS adresar

pocet = adir(qqq, m.adresar + "*", "D")
for ii = 1 to m.pocet
  if left(qqq(ii, 1), 1) # "."
     IF "D" $ qqq(ii, 5)
         insert into soubory (adresar,                  atrib, delka, datum) ;
             value (lowe(m.adresar)+lowe(qqq(ii, 1))+"\", "D",   0, qqq(ii, 3))
     ELSE 
         insert into soubory (adresar,  nazev,         atrib, delka,      datum) ;
                value (lowe(m.adresar), lowe(qqq(ii, 1)), "", qqq(ii, 2), qqq(ii, 3))
     ENDIF
  endif
endfor
