數據如下﹕
create tabel aa(classID varchar(10),className varchar(50) parent varchar(10))
insert into aa
select
A , 輔料 , NULL union all select
A-01 , 日常輔料 , A union all select
A-01-001 , 布碎 , A-01 union all select
A-01-002 , 手套 , A-01 union all select
A-01-003 , 掃把 , A-01 union all select
A-01-004 , 書寫品 , A-01 union all select
A-01-005 , 衛生品 , A-01 union all select
A-01-006 , 用具 , A-01 union all select
A-02 , 生產輔料 , A union all select
A-02-002 , 樹脂板 , A-02 union all select
A-02-003 , 生粉 , A-02 union all select
A-02-004 , 燃油 , A-02 union all select
A-02-005 , 膠水 , A-02 union all select
A-02-006 , 包裝帶 , A-02 union all select
A-02-007 , 釘線 , A-02 union all select
A-02-008 , 啤具 , A-02 union all select
A-02-009 , 化工品 , A-02 union all select
A-02-011 , 其它 , A-02 union all select
A-02-012 , 膠紙 , A-02 union all select
A-02-013 , 海綿 , A-02 union all select
A-02-014 , 四色水墨 , A-02 union all select
A-02-015 , 雜色水墨 , A-02 select * from aadrop table aa
.........................................................................
create tabel aa(classID varchar(10),className varchar(50) parent varchar(10))
insert into aa
select
A , 輔料 , NULL union all select
A-01 , 日常輔料 , A union all select
A-01-001 , 布碎 , A-01 union all select
A-01-002 , 手套 , A-01 union all select
A-01-003 , 掃把 , A-01 union all select
A-01-004 , 書寫品 , A-01 union all select
A-01-005 , 衛生品 , A-01 union all select
A-01-006 , 用具 , A-01 union all select
A-02 , 生產輔料 , A union all select
A-02-002 , 樹脂板 , A-02 union all select
A-02-003 , 生粉 , A-02 union all select
A-02-004 , 燃油 , A-02 union all select
A-02-005 , 膠水 , A-02 union all select
A-02-006 , 包裝帶 , A-02 union all select
A-02-007 , 釘線 , A-02 union all select
A-02-008 , 啤具 , A-02 union all select
A-02-009 , 化工品 , A-02 union all select
A-02-011 , 其它 , A-02 union all select
A-02-012 , 膠紙 , A-02 union all select
A-02-013 , 海綿 , A-02 union all select
A-02-014 , 四色水墨 , A-02 union all select
A-02-015 , 雜色水墨 , A-02 select * from aadrop table aa
.........................................................................
var
root: TTreeNode;
begin //1
root := classTree.Items.AddFirst(nil, '所有物料分類');
createLeaf(root);
classtree.Items.GetFirstNode.Expand(false);
end; //1procedure TgoodsClassFrm0.createLeaf(parent: TTreeNode);
var
node: TTreeNode;
cond: string;
begin //1
with tadoquery.Create(nil) do
begin //2
if Mstr(parent.Text, '(', ')') = '' then
cond := ' where parentClass is null '
else
cond := ' where parentClass =''' + Mstr(parent.Text, '(', ')') + '''';
Connection := purchdm.conn;
close;
sql.Clear;
sql.add('select * from goodsClass ' + cond +
' order by classID');
open;
while not eof do
begin
node := classTree.Items.AddChild(parent, '(' + trim(
fieldbyname('classID').AsString) + ') ' + trim(
fieldbyname('className').AsString));
if recordExists('select 1 from store..goodsClass where parentClass =''' +
fieldbyname('classID').AsString + '''') then
createLeaf(node);
next;
end;
close;
free;
end; //2
end; //1