qlixes

Lazarus/ZQuery

Aug 15th, 2018
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.50 KB | None | 0 0
  1. procedure TForm1.btnImportClick(Sender: TObject);
  2. var
  3.   FSQL:String;
  4. begin
  5.   ZQuery1 := TZQuery.Create(nil);
  6.   ZQuery1.Connection := ZConnection1;
  7.   FDoc := TCSVDocument.Create;
  8.   FDoc.Delimiter := Edit4.Text[1];
  9.   FSQL:='';
  10.   if (not FileExists(Edit3.Text)) or (Edit3.Text <> '') then
  11.     FDoc.LoadFromFile(Edit3.Text);
  12.   i := RadioGroup1.ItemIndex;
  13.   Memo2.Lines.Clear;
  14.   if (FDoc.MaxColCount = Memo1.Lines.Count) then
  15.   begin
  16.     ZQuery1.Close;
  17.     for j := 1 to FDoc.RowCount - 1 do  //krn ada header
  18.     begin
  19.       //ZQuery1.Close;
  20.       //ZQuery1.SQL.Clear;
  21.       k := imp.ReadInteger(RadioGroup1.Items.Strings[i], Memo1.Lines[0], 0);
  22.       s := QuotedStr(copy(Trim(FDoc.Cells[0, j]), 0, k));
  23.       for m := 1 to Memo1.Lines.Count - 1 do
  24.       begin
  25.         l := imp.ReadInteger(RadioGroup1.Items.Strings[i], Memo1.Lines[m], 0);
  26.         s += ',' + QuotedStr(copy(Trim(FDoc.Cells[m, j]), 0, l));
  27.       end;
  28.       FSQL:= FSQL + 'EXECUTE PROCEDURE '+dbi.ReadString('StoredProcedure', RadioGroup1.Items.Strings[i], 'ErrorSP')+ '(' + s + ','+QuotedStr(dbi.ReadString('System', 'LOGIN', 'ErrorLogin'))+ '); ';
  29.       lblImportLoading.Caption := 'Processing : ' + IntToStr(trunc(j / (FDoc.RowCount - 1) * 100)) + ' %';
  30.       lblImportLoading.Update;
  31.     end;
  32.     try
  33.       ZQuery1.SQL.Clear;
  34.       ZQuery1.SQL.Text:= trim(FSQL);
  35.       ZQuery1.ExecSQL;
  36.       ZQuery1.Free;
  37.     except
  38.       showMessage('Error !');
  39.     end;
  40.   end
  41.   else
  42.     ShowMessage('Column CSV not match with database !');
  43. end;
Advertisement
Add Comment
Please, Sign In to add comment