Einzelnen Beitrag anzeigen

Vincend

Registriert seit: 8. Dez 2010
10 Beiträge
 
#3

AW: Sortierung für TJvDBTreeView

  Alt 9. Dez 2010, 21:19
*JUBEL JUBEL FREU FREU*

Endlich is es fertig!

Delphi-Quellcode:
procedure array_sortieren(i_uebergabe : Integer);
  var i_max, i_parent, i, i_ende : Integer;
      b_ende : Boolean;
      arr_test : array of Integer;
      arr_ausgabe : array of Integer;
      s_ausgabe : String;
begin
  b_ende := false;
  i := 0;
  i_ende := 1;
  SetLength(arr_test, 1);
  SetLength(arr_ausgabe, 1);

  with D_Datenmodul.qu_plz_ort do
  begin
    //Maximale Elemente das Baums finden
    Close;
    SQL.Text := 'SELECT COUNT(id_app_menue_xml_inhalte_content) as maximum ';
    SQL.Add('FROM tbl_app_menue_xml_inhalte_content ');
    SQL.Add('WHERE tbl_app_menue_xml_inhalte_id = '''+IntToStr(i_uebergabe)+'''');
    Open; First;
    i_max := FieldByName('maximum').AsInteger;
    //*****

    //Startpunkt des Baumes finden
    Close;
    SQL.Text := 'SELECT id_app_menue_xml_inhalte_content as parent_element ';
    SQL.Add('FROM tbl_app_menue_xml_inhalte_content ');
    SQL.Add('WHERE tbl_app_menue_xml_inhalte_id = '''+IntToStr(i_uebergabe)+''' + AND sub_id_app_menue_xml_inhalte_content = 0');
    Open; First;
    arr_test[0] := FieldByName('parent_element').AsInteger;
    arr_ausgabe[0] := FieldByName('parent_element').AsInteger;
    //*****

    while not b_ende do
    begin
      Close;
      SQL.Text := 'SELECT id_app_menue_xml_inhalte_content ';
      SQL.Add('FROM tbl_app_menue_xml_inhalte_content ');
      SQL.Add('WHERE sub_id_app_menue_xml_inhalte_content = '''+IntToStr(arr_test[Length(arr_test) - 1])+''' ');
      SQL.Add('AND id_app_menue_xml_inhalte_content not in (');

      for I := 0 to Length(arr_ausgabe) - 1 do //sortiertes nicht mehr beachten
      begin
        if i > 0 then SQL.Add(', ');
        SQL.Add(IntToStr(arr_ausgabe[i]));
      end;

      SQL.Add(') ORDER BY reihenfolge');
      Open; First;

      //Sortierung abspeichern & Baum-Pfadbestimmen in dem gesucht wird
      if not Eof then
      begin
        SetLength(arr_ausgabe, Length(arr_ausgabe) + 1);
        arr_ausgabe[Length(arr_ausgabe) - 1] := FieldByName('id_app_menue_xml_inhalte_content').AsInteger;
        i_ende := i_ende + 1;

        SetLength(arr_test, Length(arr_test) + 1);
        arr_test[Length(arr_test) - 1] := FieldByName('id_app_menue_xml_inhalte_content').AsInteger;
      end else
        SetLength(arr_test, Length(arr_test) - 1);
      //*****

      if i_ende = i_max then
        b_ende := true;
    end;
  end;

  for I := 0 to Length(arr_ausgabe) - 1 do
  s_ausgabe := s_ausgabe + ', ' + IntToStr(arr_ausgabe[i]);

  if (MessageDlg(s_ausgabe, mtWarning, [mbYes, mbCancel], 0) = mrYes) then
  begin

  end;
end;
Die Benennung is noch fürn hintern aber dafür wars ja auch nen Test in den Abendstunden.
Werd das die Tage mal vernünftig machen und online stellen.
Ausgehende Tabellenstruktur is ja oben.
  Mit Zitat antworten Zitat