检索数据库用树形目录表示(100分)

  • 主题发起人 主题发起人 逆风
  • 开始时间 开始时间

逆风

Unregistered / Unconfirmed
GUEST, unregistred user!
想检索一个acess的数据库某个字段,用树形目录表示,然后点击树形目录项,另一个窗口显示出该目录项在数据库详细的记录。
 
字段采用科目代码编码的方式
如:
01
0101
0102
010201
010202
0103
02
0201
......
根据编码建树
 
给你一段参考代码:

FQry1 := dm.GetQueryComponent;
v_sql := 'Select c.corp_id, c.corp_name, d.depart_id, d.depart_name, t.team_id, t.team_name' + #13#10 +
'From dbo.m_corp_info c Inner Join dbo.m_depart_info d On c.corp_id = d.corp_id Inner Join' + #13#10 +
'dbo.m_team_info t On d.corp_id = t.corp_id And d.depart_id = t.depart_id Order By c.corp_id,' + #13#10 +
'd.depart_id, t.team_id';
try
if dm.QueryDatabase(FQry1, v_sql) then
begin
while not FQry1.Eof do
begin
if TreeNode1 <> nil then
TreeNode1.Expand(False);
TreeNode1 := TvDoorCard.Items.AddChild(TreeNode0, FQry1.FieldByName('corp_name').AsString);
TreeNode1.ImageIndex := 1;
TreeNode1.SelectedIndex := 1;
New(P);
P^ := FQry1.FieldByName('corp_id').AsString;
TreeNode1.Data := P;
while not FQry1.Eof do
begin
TreeNode2 := TvDoorCard.Items.AddChild(TreeNode1, FQry1.FieldByName('depart_name').AsString);
TreeNode2.ImageIndex := 1;
TreeNode2.SelectedIndex := 1;
New(P);
P^ := FQry1.FieldByName('depart_id').AsString;
TreeNode2.Data := P;
while not FQry1.Eof do
begin
TreeNode3 := TvDoorCard.Items.AddChild(TreeNode2, FQry1.FieldByName('team_name').AsString);
TreeNode3.ImageIndex := 2;
TreeNode3.SelectedIndex := 2;
New(P);
P^ := FQry1.FieldByName('team_id').AsString;
TreeNode3.Data := P;
FQry1.Next;
if string(TreeNode2.Data^) <> FQry1.FieldByName('depart_id').AsString then
Break;
end;
FQry1.Next;
if string(TreeNode1.Data^) <> FQry1.FieldByName('corp_id').AsString then
Break;
end;
FQry1.Next;
end;
end;
finally
FQry1.Close;
FQry1.Free;
TvDoorCard.Items.EndUpdate;
TreeNode0.Expand(False);
for i := 0 to TreeNode0.Count - 1 do
TreeNode0.Item.Expand(False);
end;
 
TO:
Corn3,你这段代码可以解决问题,如果考虑一下重用,效果会更好
 
多人接受答案了。
 
后退
顶部