*:*****************************************************************************
*: Procedure file: HK_CRDDIN
*:*****************************************************************************
param sk_path, pripona, exp_path

IF EMPTY(exp_path)
  exp_path = "c:\ftp\data\"
ENDIF 
sk_path = sk_path + IIF(RIGHT(m.sk_path,1)="\", "", "\")
exp_path = exp_path + IIF(RIGHT(m.exp_path,1)="\", "", "\")
if ! directory(m.exp_path)
   mkdir (m.exp_path)
endif

CLOSE ALL
clos data
CLEAR WINDOW
set Safety Off
SET CPDIALOG OFF

vysledek = crlf

if file(m.exp_path + "hk_crddar" + m.pripona + ".dbf")
    use (m.sk_path + "hk_crddar")
    SET ORDER TO TAG u_dat
    sele 0
    use (m.exp_path + "hk_crddar" + m.pripona) Alias hk_crddar_x Exclusive
    *IF FSIZE('label') = 0
    *    ALTER TABLE (m.exp_path + "hk_crddar" + m.pripona) ADD COLUMN label C(1)
    *ENDIF     
    inde on datum + cis_kred + u_cis tag u_dat
    *repl all label with "X"
    SELECT * from (m.exp_path + "hk_crddar" + m.pripona) a INTO TABLE (m.exp_path+"pribylo");
     WHERE .NOT. exists (select * from (m.sk_path+"hk_crddar") b WHERE (a.datum=b.datum) AND (a.cis_kred=b.cis_kred) AND (a.u_cis=b.u_cis))  
    *scan
    *  sele hk_crddar
    *  locate for datum + cis_kred + u_cis = hk_crddar_x.datum + hk_crddar_x.cis_kred + hk_crddar_x.u_cis
    *  if found()
    *    sele hk_crddar_x
    *    repl label with ""
    *  else
    *    sele hk_crddar_x
    *  endif
    *endscan
    *DELETE FOR EMPTY(label) or (u_cis = "ARCHIV")
    *PACK 
    DELETE FOR (u_cis = "ARCHIV")
    PACK 
    sele hk_crddar 
    *appe from (m.exp_path + "hk_crddar" + m.pripona)
    appe from (m.exp_path + "pribylo")
    vysledek = vysledek + "[1#G]       appendovano " + "hk_crddar" + m.pripona + crlf
else
    vysledek = vysledek + "[1#B]       ... " + "neexistuje soubor " + m.exp_path + "hk_crddar" + m.pripona + crlf
endif
clos data


*!*****************************************************************************
*function zamkni
*private _iii
*_iii = 1
*do while ! flock() .and. m._iii < 33 .and. ! empt(dbf())
*    wait "Cekejte, zamykam " + dbf() + str(m._iii,6) wind time m._iii
*    _iii = m._iii + 1
*enddo
*return flock()
