procedure TForm2.InsertNewJob();
var
CategoryLastID: Integer;
begin
Form1.SQLQuery1.Close;
Form1.SQLQuery1.SQL.Text := '
INSERT INTO tbmain VALUES(NULL, :title, :start, :ende, :memo, :fk_category_id, NULL, NULL, :fk_status_id, NULL)';
Form1.SQLQuery1.ParamByName('
title').AsString := TitleEdit.Text;
Form1.SQLQuery1.ParamByName('
start').AsDateTime := StartDateEdit.Date;
Form1.SQLQuery1.ParamByName('
ende').AsDateTime := EndeDateEdit.Date;
Form1.SQLQuery1.ParamByName('
memo').AsString := Memo.Text;
// Kategorie nicht vorhanden und ComboBox nicht leer, also erst neue Kategorie in die DB schreiben
if (CategoryComboBox.ItemIndex = -1)
and (CategoryComboBox.Text <> '
')
and (CategoryComboBox.Items.IndexOf(CategoryComboBox.Text) = -1)
then
begin
// String manuell reingeschrieben, String sonst in der CB nicht vorhanden
// Kategorie in die Tabelle tbcategory schreiben
Form1.SQLQueryCategory.Close;
Form1.SQLQueryCategory.SQL.Text := '
INSERT INTO tbcategory VALUES(NULL, :category)';
Form1.SQLQueryCategory.ParamByName('
category').AsString := CategoryComboBox.Text;
Form1.SQLQueryCategory.ExecSQL;
Form1.SQLTransaction1.Commit;
// Die letzte ID auslesen
Form1.SQLQueryCategory.Close;
Form1.SQLQueryCategory.SQL.Text := '
SELECT last_insert_rowid() as id_tbcategory FROM tbcategory';
Form1.SQLQueryCategory.Open;
CategoryLastID := Form1.SQLQueryCategory.FieldByName('
id_tbcategory').AsInteger;
Form1.SQLQuery1.ParamByName('
fk_category_id').AsInteger := CategoryLastID;
end else if (CategoryComboBox.ItemIndex = -1)
and (CategoryComboBox.Items.IndexOf(CategoryComboBox.Text) <> -1)
then
begin
// String manuell reingeschrieben, String in der CB vorhanden
Form1.SQLQuery1.ParamByName('
fk_category_id').AsInteger := Integer(CategoryComboBox.Items.Objects[CategoryComboBox.Items.IndexOf(CategoryComboBox.Text)]);
end else if CategoryComboBox.ItemIndex <> -1
then
begin
// String in der CB ausgewählt
Form1.SQLQuery1.ParamByName('
fk_category_id').AsInteger := Integer(CategoryComboBox.Items.Objects[CategoryComboBox.ItemIndex])
end;
Form1.SQLQuery1.ParamByName('
fk_status_id').AsInteger := 1;
Form1.SQLQuery1.ExecSQL;
Form1.SQLTransaction1.Commit;
end;