*:*********************************************************************************************************
*:     Procedure file: LIMITY_IN.PRG   - import limitovych souboru, poslanych z centraly
*:                         - radky s nenalezenym ID_ROV jsou insertovany
*:                         - radky s   nalezenym ID_ROV a prazdnymi fieldy UZAVERKA a U_CIS jsou updatovany
*:           !!!   field nlimitrov.id_rov je na centrale primarykey a autoinc, ale na kase autoinc byt nesmi, proto je pokazde alterovan na Int   !!!
*: 2016-01-13: 
*: 2016-01-22: opravena chyba ve vypisu ? m.id_rov + " - Insert" (id_rov = integer)
*:              
*:*********************************************************************************************************
param data_path, import_path

*import_path = "c:\tmp"
*data_path   = "i:\d_az\data"
*pri_path    = ".\tmp\"
*crlf = CHR(13)+CHR(10)

import_path = import_path + IIF(RIGHT(m.import_path,1) = "\", "", "\")
data_path   =   data_path + IIF(RIGHT(  m.data_path,1) = "\", "", "\")
vysledek = " . . v.2016-0122: " + m.crlf

CLOSE DATABASES 
IF FILE(m.import_path + "nlimitrov.dbf")

    COPY FILE (m.import_path + "nlimit_hl.*")   to (m.data_path + "*.*")
    COPY FILE (m.import_path + "nlimitdni.*")   to (m.data_path + "*.*")
    COPY FILE (m.import_path + "nlimitchody.*") to (m.data_path + "*.*")
    COPY FILE (m.import_path + "nlimitsabl*.*") to (m.data_path + "*.*")
    COPY FILE (m.import_path + "nlimity.*")     to (m.data_path + "*.*")
    COPY FILE (m.import_path + "nlimittyp*.*")  to (m.data_path + "*.*")
    *     *     *     *     *     *     *     *     *     *     *     *     *
    COPY FILE (m.import_path + "nlimitrov.*") to (m.pri_path + "lim_in.*")

    err_message = ""
    LOCAL skin_oErr AS Exception
    TRY 
       USE         (m.data_path + "nlimitrov.dbf") EXCLUSIVE 
       ALTER table (m.data_path + "nlimitrov.dbf") alter id_rov Integer
       USE (m.pri_path + "lim_in") EXCLUSIVE IN 0

    CATCH TO skin_oErr 
       err_message = m.err_message + " " + ALLTRIM(STR(skin_oErr.ErrorNo)) + " " + skin_oErr.Message + " Line:" + ALLTRIM(STR(skin_oErr.LineNo))
    ENDTRY 

    IF EMPTY(m.err_message)    

        SELECT lim_in
        SCAN
            SCATTER MEMVAR 
            sele nlimitrov
            locate for id_rov = m.id_rov nooptimize
            if found()
               IF EMPTY(uzaverka + u_cis)
                   SCATTER FIELDS uzaverka, u_cis MEMVAR 
                   GATHER MEMVAR 
                   ? m.id_rov, " - Update"
               ELSE
                   ? m.id_rov, " - nic, uz bylo namarkovano"
               ENDIF 
            ELSE
               INSERT INTO nlimitrov FROM MEMVAR 
                   ? m.id_rov, " - Insert"
            endif

        ENDSCAN 
        vysledek = m.vysledek + "   ... OK"

    ELSE
        vysledek = m.vysledek + "[2#R]  " + "       ... " + m.err_message + "  "
    ENDIF
ELSE 

   vysledek = m.vysledek + "[2#R]  " + "       ... " + "neexistuje " + upper(m.import_path + "nlimitrov.dbf") + "  ... "
ENDIF 

CLOSE DATABASES 

