unit DbTreeDm;

interface

uses
  SysUtils, Classes, sdDB, sdProvider, DB, ADODB, sdIDTree;

type
  TDbTreeData = class(TDataModule)
    acDbTree: TADOConnection;
    sdpDbTree: TsdADOProvider;
    sddDbTree: TsdDataSet;
    sdvDbTree: TsdDataView;
  private
    FDbTree: TsdIDTree;

    procedure LoadDbTree;
    procedure OpenDbTree(const AFileName, ATableName: string);
  public
    constructor Create(const AFileName, ATableName: string);

    property DbTree: TsdIDTree read FDbTree;
  end;

implementation

uses
  Connections;

{$R *.dfm}

{ TDbTreeData }

constructor TDbTreeData.Create(const AFileName, ATableName: string);
begin
  inherited Create(nil);
  OpenDbTree(AFileName, ATableName);
  LoadDbTree;
end;

procedure TDbTreeData.LoadDbTree;
begin
  FDbTree := TsdIDTree.Create;
  FDbTree.KeyFieldName := 'ID';
  FDbTree.ParentFieldName := 'ParentID';
  FDbTree.NextSiblingFieldName := 'NextSiblingID';
  FDbTree.DataView := sdvDbTree;
end;

procedure TDbTreeData.OpenDbTree(const AFileName, ATableName: string);
begin
  acDbTree.ConnectionString := Format(SAdoConnectStr, [AFileName]);
  acDbTree.Open;

  sdpDbTree.TableName := ATableName;
  sdpDbTree.Connection := acDbTree;

  sddDbTree.Open;
  sdvDbTree.Open;
end;

end.
