{#INFO 'Import skl.karet ze souboru CSV - DPH2024'} var OD : TOpenDialog; s : string; i,x,y, c: integer; t : TStrings; t2 : TPOSQuery; st : TStrings; function DestTecka(const Value : string) : string; var x : integer; begin Result := Value; x := pos(',', Result); if x>0 then Result[x] := '.'; Result := Trim(Result); end; function DestCarka(const Value : string) : string; var x : integer; begin Result := Value; x := pos('.', Result); if x>0 then Result[x] := ','; end; begin x := 0; OD := TOpenDialog.Create(nil); try OD.Filter := 'CSV|*.csv'; if OD.Execute then s := OD.FileName; OD.Options := OD.Options + ofNoChangeDir; finally OD.Free; end; if FileExists(s) then begin t := TStringList.Create; try t.LoadFromFile(s); if t.Count=0 then begin MessageBox(0,'Zdrojový soubor neobsahuje žádné údaje', 'Chyba',48); end else begin c := 0; s := t.Strings[0]; for i := 1 to Length(s) do if s[i] = ';' then inc(c); t2 := TPOSQuery.Create; try if c=7 then begin for i := 2 to t.Count do try s := Format('Procházení importovaných dat %d%%',[Trunc((i/t.Count)*100)]); ShowInfo(s,'Import',Trunc((i/t.Count)*100)); t2.SQL.Clear; t2.SQL.Add('UPDATE TPPLU SET DPH=:DPH, DPH_IN=NULL, DPH2=NULL,PRICE=:PRICE WHERE ID=:ID'); t2.ParamByName['ID'] := ExtractWord(1, t.Strings[i-1],';'); t2.ParamByName['DPH'] := Format('%d',[Trunc(StrToFloat(Trim((ExtractWord(7, t.Strings[i-1],';')))))]); try t2.ParamByName['PRICE']:= StrToFloat( DestCarka(Trim((ExtractWord(8, t.Strings[i-1] ,';'))))); except t2.ParamByName['PRICE']:= StrToFloat( DestTecka(Trim((ExtractWord(8, t.Strings[i-1] ,';'))))); end; if t2.ExecSQL = 0 then begin end; x := x + 1; except MessageBox(0,'Error : [#'+IntToStr(i)+'] '+t.Strings[i-1], 'Informace',48); Exit; end; end else begin MessageBox(0,Format('Error : chyba struktury : %d',[c]), 'Informace',48); Exit; end; finally CloseInfo; t2.free; end; MessageBox(0,Format('Celkem importováno %d sklad.karet z %d záznamů.',[x,t.Count-1]), 'Informace',48); end; finally t.free; end; end; end.