Einzelnen Beitrag anzeigen

DavidKlimas

Registriert seit: 24. Sep 2006
Ort: Arlon, Belgien
71 Beiträge
 
#19

Re: Spalten in Paradox Datenbank einfügen

  Alt 2. Mai 2007, 10:26
Das ist die komplette procedure aus dem Fahrplanprogramm...

Delphi-Quellcode:
procedure TMainForm.SaveButtonClick(Sender: TObject);
var
  int1: integer;
  int2: Integer;
  AllradyExist: Boolean;
  Query: TQuery;
  Str1: String;
begin
  If CheckListBox1.ItemIndex < 0 then
  begin
    ShowMessage('Select a TrainType');
    exit;
  end;
  For int1 := 1 to DKStringGrid4.RowCount -1 do
  begin
    If (StrToInt(DKStringGrid4.Cells[0, int1-1]) = CheckListBox1.ItemIndex+1) and (StrToInt(DKStringGrid4.Cells[1, int1-1]) = DKStringGrid2.RowCount - 1) then
    begin
      AllradyExist := true;
      For int2 := 0 to DKStringGrid2.RowCount-2 do
      begin
        If DKStringGrid2.Cells[0, int2] <> DKStringGrid4.Cells[int2+2, int1-1] then
          AllradyExist := False;
      end;
      If AllradyExist = True then
      begin
        ShowMessage('Allrady exist in List');
        exit;
      end;
    end;
  end;
  If DKStringGrid4.ColCount < DKStringGrid2.RowCount + 1 then
    DKStringGrid4.ColCount := DKStringGrid2.RowCount + 1;
  DKStringGrid4.Cells[0, DKStringGrid4.RowCount-1] := IntToStr(CheckListBox1.ItemIndex+1);
  DKStringGrid4.Cells[1, DKStringGrid4.RowCount-1] := IntToStr(DKStringGrid2.RowCount-1);
  For int1 := 0 to DKStringGrid2.RowCount - 1 do
  begin
    DKStringGrid4.Cells[int1+2, DKStringGrid4.RowCount-1] := DKStringGrid2.Cells[0, int1];
  end;
  DKStringGrid4.RowCount := DKStringGrid4.RowCount + 1;
  Int2 := LineTable.FieldCount-1;
  For int1 := Int2 to DKStringGrid2.RowCount-1 do
  begin
    LineTable.Active := False;
    LineTable.Close;
    Query := TQuery.Create(nil);
    try
      Query.DatabaseName := LineTable.DatabaseName;
      Query.SQL.Clear;
      Query.SQL.Add('Alter Table Lines');
      Query.SQL.Add('Add Stop'+IntToStr(int1)+' Char(5)');
      Query.ExecSQL;
    finally
      Query.Free;
    end;
    LineTable.Active := True;
    LineTable.Open;
  end;
  LineTable.Append;
  LineTable.Edit;
  LineTable.FieldByName('NumberOfStops').Value := DKStringGrid2.RowCount - 1;
  LineTable.FieldByName('TrainType').Value := CheckListBox1.ItemIndex+1;
  For int1 := 1 to DKStringGrid2.RowCount - 1 do
  begin
     LineTable.FieldByName('Stop'+IntToStr(Int1)).Value := DKStringGrid2.Cells[0,int1-1];
  end;
  LineTable.Post;
  //Departure :
  For int1 := 1 to DKStringGrid2.RowCount - 2 do
  begin
    Str1 := 'City'+DKStringGrid2.Cells[0, int1-1];
    if DepartureTable.Locate('City', Str1, [] ) = false then
    begin
      DepartureTable.Append;
      DepartureTable.FieldByName('City').Value := Str1;
      DepartureTable.FieldByName('NumberOfDepartures').Value := 0;
      DepartureTable.Post;
    end;
    Str1 := 'City'+DKStringGrid2.Cells[0, int1-1];
    DepartureTable.Locate('City', Str1, [] );
    DepartureTable.Edit;
    DepartureTable.FieldByName('NumberOfDepartures').Value := DepartureTable.FieldByName('NumberOfDepartures').Value + 1;
    DepartureTable.Post;
    If DepartureTable.FieldByName('NumberOfDepartures').AsVariant > DepartureTable.FieldCount-2 then
    begin
      Str1 := 'Line'+IntToStr(DepartureTable.FieldCount-1);
      DepartureTable.Active := False;
      DepartureTable.Close;
      Query := TQuery.Create(nil);
      try
        Query.DatabaseName := DepartureTable.DatabaseName;
        Query.SQL.Clear;
        Query.SQL.Add('Alter Table Departure');
        Query.SQL.Add('Add '+Str1+' Char(5)');
        Query.ExecSQL;
      finally
        Query.Free;
      end;
      DepartureTable.Active := True;
      DepartureTable.Open;
    end;
    Str1 := 'City'+DKStringGrid2.Cells[0, int1-1];
    DepartureTable.Locate('City', Str1, [] );
    DepartureTable.Edit;
    Str1 := 'Line'+DepartureTable.FieldByName('NumberOfDepartures').AsString;
    DepartureTable.FieldByName(Str1).Value := LineTable.RecordCount;
    DepartureTable.Post;
  end;
  //Arrival :
  For int1 := 2 to DKStringGrid2.RowCount - 1 do
  begin
    Str1 := 'City'+DKStringGrid2.Cells[0, int1-1];
    if ArrivalTable.Locate('City', Str1, [] ) = false then
    begin
      ArrivalTable.Append;
      ArrivalTable.FieldByName('City').Value := Str1;
      ArrivalTable.FieldByName('NumberOfArrivals').Value := 0;
      ArrivalTable.Post;
    end;
    Str1 := 'City'+DKStringGrid2.Cells[0, int1-1];
    ArrivalTable.Locate('City', Str1, [] );
    ArrivalTable.Edit;
    ArrivalTable.FieldByName('NumberOfArrivals').Value := ArrivalTable.FieldByName('NumberOfArrivals').Value + 1;
    ArrivalTable.Post;
    If ArrivalTable.FieldByName('NumberOfArrivals').AsVariant > ArrivalTable.FieldCount-2 then
    begin
      Str1 := 'Line'+IntToStr(ArrivalTable.FieldCount-1);
      ArrivalTable.Active := False;
      ArrivalTable.Close;
      Query := TQuery.Create(nil);
      try
        Query.DatabaseName := ArrivalTable.DatabaseName;
        Query.SQL.Clear;
        Query.SQL.Add('Alter Table Arrival');
        Query.SQL.Add('Add '+Str1+' Char(5)');
        Query.ExecSQL;
      finally
        Query.Free;
      end;
      ArrivalTable.Active := True;
      ArrivalTable.Open;
    end;
    Str1 := 'City'+DKStringGrid2.Cells[0, int1-1];
    ArrivalTable.Locate('City', Str1, [] );
    ArrivalTable.Edit;
    Str1 := 'Line'+ArrivalTable.FieldByName('NumberOfArrivals').AsString;
    ArrivalTable.FieldByName(Str1).Value := LineTable.RecordCount;
    ArrivalTable.Post;
  end;
  GenerateLineList;
end;
  Mit Zitat antworten Zitat