BOM的問題﹐不能用樹狀的表結構(100分)

  • 主题发起人 主题发起人 Change_On_Insta
  • 开始时间 开始时间
C

Change_On_Insta

Unregistered / Unconfirmed
GUEST, unregistred user!
不能用樹狀的表結構,BOM表結構不能變﹐因為會影響到許多關聯查詢
BOM設計如下:
SQL> desc bom;
Name Type Nullable Default Comments
------------- ------------ -------- ------- --------
COUNTRY_CODE VARCHAR2(10) 主鍵
CUSTOMER VARCHAR2(3) 主鍵
A_PARTS VARCHAR2(4) 主鍵
B_PARTS VARCHAR2(4) 主鍵
A_CODE VARCHAR2(20) Y
B_CODE VARCHAR2(20) Y
NOTES VARCHAR2(1) Y

想要在樹圖中顯示﹐點擊右鍵還要可以新增修改刪除
老板要這兩天就交,怎么辦
 
是不是一张表的两个字段自关联,构成数形,呵呵,我刚写玩。
 
不是兩個字段自關聯
而是
A 1 001
A 1 002
A 2 009
A 5 001
這樣的數據﹐轉換成樹表示
 
看不动!
 
bom 的 最简单的 表结构 可以如下(为了方便构成树,我加了一个字段f_level):
f_id f_Name f_parent_id f_level
100 a 0 1
101 b 100 2
102 c 100 2
103 d 101 3
则构成树形:
a
--b
--d
--c
这样的数据库 比较简单,可以在oracle 中用一条sql 完成
delphi 中也不过就是一个树的递归遍历了



 
問題就在這里﹐原來的表結構不許動﹐不能加層次或父ID的欄位,因為程式已經寫好﹐
不想影響太多的東西
表﹕
A 1 001
A 2 001
B 2 001
要轉換成
-A
-1
-001
-2
-001
-B
-2
-001
 
这样应该好解决么。因为层数已经定了,第几层的内容也定了呀。
 
function InitContentTreeView(TreeView : TTreeView; ClientDataSet : TClientDataSet; ClientDataSet1 : TClientDataSet) : Integer;
var
TreeNode, TreeNode1, TreeNode2, TreeNode3, TreeNode4 : TTreeNode;
i, j : Integer;
PTypeAndID : PointTypeAndID;
begin
with TreeView.Items do
begin
with ClientDataSet do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'PLATBILL_MANAGE';
PTypeAndID^.TypeID := '';
TreeNode := AddChildObject(nil, '节目单', PTypeAndID);
TreeNode.ImageIndex := ICO_PLATBILL_MANAGE;
TreeNode.SelectedIndex := ICO_PLATBILL_MANAGE;

New(PTypeAndID);
PTypeAndID^.TypeType := 'CHANNEL';
PTypeAndID^.TypeID := '';
TreeNode1 := AddChildObject(TreeNode, '频道', PTypeAndID);
TreeNode1.ImageIndex := ICO_CHANNEL;
TreeNode1.SelectedIndex := ICO_CHANNEL;

New(PTypeAndID);
PTypeAndID^.TypeType := 'CHANNEL_ALL';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '全部频道', PTypeAndID);
TreeNode2.ImageIndex := ICO_CHANNEL_ALL;
TreeNode2.SelectedIndex := ICO_CHANNEL_ALL;

New(PTypeAndID);
PTypeAndID^.TypeType := 'CHANNEL_CATEGORY_SORT';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '按类别分类', PTypeAndID);
TreeNode2.ImageIndex := ICO_CHANNEL_CATEGORY_SORT;
TreeNode2.SelectedIndex := ICO_CHANNEL_CATEGORY_SORT;

Close;
CommandText := 'Select * From CHANNEL_CATEGORY Order By CATEGORY_NAME';
Open;
for i := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'CHANNEL_CATEGORY' ;
PTypeAndID^.TypeID := FieldByName('CATEGORY_ID').AsString;
TreeNode3 := AddChildObject(TreeNode2, FieldByName('CATEGORY_NAME').AsString, PTypeAndID);
TreeNode3.ImageIndex := ICO_CHANNEL_CATEGORY;
TreeNode3.SelectedIndex := ICO_CHANNEL_CATEGORY;
if not Eof then
Next;
end;

New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCCONTENT';
PTypeAndID^.TypeID := '';
TreeNode1 := AddChildObject(TreeNode, '广播节目', PTypeAndID);
TreeNode1.ImageIndex := ICO_VBCCONTENT;
TreeNode1.SelectedIndex := ICO_VBCCONTENT;

New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCCONTENT_ALL';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '全部广播节目', PTypeAndID);
TreeNode2.ImageIndex := ICO_VBCCONTENT_ALL;
TreeNode2.SelectedIndex := ICO_VBCCONTENT_ALL;

New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCCONTENT_CATEGORY_SORT';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '按类别分类', PTypeAndID);
TreeNode2.ImageIndex := ICO_VBCCONTENT_CATEGORY_SORT;
TreeNode2.SelectedIndex := ICO_VBCCONTENT_CATEGORY_SORT;

Close;
CommandText := 'Select * From VBCCONTENT_CATEGORY Order By CATEGORY_NAME';
Open;
for i := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCCONTENT_CATEGORY' ;
PTypeAndID^.TypeID := FieldByName('CATEGORY_ID').AsString;
TreeNode3 := AddChildObject(TreeNode2, FieldByName('CATEGORY_NAME').AsString, PTypeAndID);
TreeNode3.ImageIndex := ICO_VBCCONTENT_CATEGORY;
TreeNode3.SelectedIndex := ICO_VBCCONTENT_CATEGORY;
if not Eof then
Next;
end;

New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCEPG';
PTypeAndID^.TypeID := '';
TreeNode1 := AddChildObject(TreeNode, '广播节目单', PTypeAndID);
TreeNode1.ImageIndex := ICO_VBCEPG;
TreeNode1.SelectedIndex := ICO_VBCEPG;

New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCEPG_ALL';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '全部广播节目单', PTypeAndID);
TreeNode2.ImageIndex := ICO_VBCEPG_ALL;
TreeNode2.SelectedIndex := ICO_VBCEPG_ALL;

New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCEPG_CHANNEL_CATEGORY_SORT';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '按频道分类', PTypeAndID);
TreeNode2.ImageIndex := ICO_CHANNEL_CATEGORY_SORT;
TreeNode2.SelectedIndex := ICO_CHANNEL_CATEGORY_SORT;

Close;
CommandText := 'Select * From CHANNEL_CATEGORY Order By CATEGORY_NAME';
Open;
for i := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCEPG_CHANNEL_CATEGORY' ;
PTypeAndID^.TypeID := FieldByName('CATEGORY_ID').AsString;
TreeNode3 := AddChildObject(TreeNode2, FieldByName('CATEGORY_NAME').AsString, PTypeAndID);
TreeNode3.ImageIndex := ICO_CHANNEL_CATEGORY;
TreeNode3.SelectedIndex := ICO_CHANNEL_CATEGORY;
with ClientDataSet1 do
begin
Close;
CommandText := Format('Select * From CHANNEL_CODE Where CATEGORY_ID=''%s'' Order By CHANNEL_NAME',[ClientDataSet.FieldByName('CATEGORY_ID').AsString]);
Open;
for j := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCEPG_CHANNEL_CODE';
PTypeAndID^.TypeID := FieldByName('CHANNEL_ID').AsString;
TreeNode4 := AddChildObject(TreeNode3, FieldByName('CHANNEL_NAME').AsString, PTypeAndID);
TreeNode4.ImageIndex := ICO_CHANNEL_CODE;
TreeNode4.SelectedIndex := ICO_CHANNEL_CODE;
if not Eof then
Next;
end;
end;
if not Eof then
Next;
end;

New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCEPG_VBCCONTENT_CATEGORY_SORT';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '按类别分类', PTypeAndID);
TreeNode2.ImageIndex := ICO_VBCCONTENT_CATEGORY_SORT;
TreeNode2.SelectedIndex := ICO_VBCCONTENT_CATEGORY_SORT;

Close;
CommandText := 'Select * From VBCCONTENT_CATEGORY Order By CATEGORY_NAME';
Open;
for i := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCEPG_VBCCONTENT_CATEGORY' ;
PTypeAndID^.TypeID := FieldByName('CATEGORY_ID').AsString;
TreeNode3 := AddChildObject(TreeNode2, FieldByName('CATEGORY_NAME').AsString, PTypeAndID);
TreeNode3.ImageIndex := ICO_VBCCONTENT_CATEGORY;
TreeNode3.SelectedIndex := ICO_VBCCONTENT_CATEGORY;
with ClientDataSet1 do
begin
Close;
CommandText := Format('Select * From VBCCONTENT_CODE Where CATEGORY_ID=''%s'' Order By VBCCONTENT_NAME',[ClientDataSet.FieldByName('CATEGORY_ID').AsString]);
Open;
for j := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'VBCEPG_VBCCONTENT_CODE';
PTypeAndID^.TypeID := FieldByName('VBCCONTENT_ID').AsString;
TreeNode4 := AddChildObject(TreeNode3, FieldByName('VBCCONTENT_NAME').AsString, PTypeAndID);
TreeNode4.ImageIndex := ICO_VBCCONTENT_CODE;
TreeNode4.SelectedIndex := ICO_VBCCONTENT_CODE;
if not Eof then
Next;
end;
end;
if not Eof then
Next;
end;

New(PTypeAndID);
PTypeAndID^.TypeType := 'CONTENT';
PTypeAndID^.TypeID := '';
TreeNode1 := AddChildObject(TreeNode, '点播节目', PTypeAndID);
TreeNode1.ImageIndex := ICO_CONTENT;
TreeNode1.SelectedIndex := ICO_CONTENT;

New(PTypeAndID);
PTypeAndID^.TypeType := 'CONTENT_ALL';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '全部点播节目', PTypeAndID);
TreeNode2.ImageIndex := ICO_CONTENT_ALL;
TreeNode2.SelectedIndex := ICO_CONTENT_ALL;

New(PTypeAndID);
PTypeAndID^.TypeType := 'CONTENT_CATEGORY_SORT';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '按类别分类', PTypeAndID);
TreeNode2.ImageIndex := ICO_CONTENT_CATEGORY_SORT;
TreeNode2.SelectedIndex := ICO_CONTENT_CATEGORY_SORT;

Close;
CommandText := 'Select * From CONTENT_CATEGORY Order By CATEGORY_NAME';
Open;
for i := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'CONTENT_CATEGORY' ;
PTypeAndID^.TypeID := FieldByName('CATEGORY_ID').AsString;
TreeNode3 := AddChildObject(TreeNode2, FieldByName('CATEGORY_NAME').AsString, PTypeAndID);
TreeNode3.ImageIndex := ICO_CONTENT_CATEGORY;
TreeNode3.SelectedIndex := ICO_CONTENT_CATEGORY;
with ClientDataSet1 do
begin
Close;
CommandText := Format('Select * From CONTENT_SUBCATEGORY Where CATEGORY_ID=''%s'' Order By SUBCATEGORY_NAME',[ClientDataSet.FieldByName('CATEGORY_ID').AsString]);
Open;
for j := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'CONTENT_SUBCATEGORY';
PTypeAndID^.TypeID := FieldByName('SUBCATEGORY_ID').AsString;
TreeNode4 := AddChildObject(TreeNode3, FieldByName('SUBCATEGORY_NAME').AsString, PTypeAndID);
TreeNode4.ImageIndex := ICO_CONTENT_SUBCATEGORY;
TreeNode4.SelectedIndex := ICO_CONTENT_SUBCATEGORY;
if not Eof then
Next;
end;
end;
if not Eof then
Next;
end;

New(PTypeAndID);
PTypeAndID^.TypeType := 'CONTENT_PROVIDER_SORT';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '按供应商分类', PTypeAndID);
TreeNode2.ImageIndex := ICO_CONTENT_PROVIDER_SORT;
TreeNode2.SelectedIndex := ICO_CONTENT_PROVIDER_SORT;

Close;
CommandText := 'Select * From PROVIDER_CATEGORY Order BY CATEGORY_NAME';
Open;
for i := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'PROVIDER_CATEGORY';
PTypeAndID^.TypeID := FieldByName('CATEGORY_ID').AsString;
TreeNode3 := AddChildObject(TreeNode2, FieldByName('CATEGORY_NAME').AsString, PTypeAndID);
TreeNode3.ImageIndex := ICO_PROVIDER_CATEGORY;
TreeNode3.SelectedIndex := ICO_PROVIDER_CATEGORY;
with ClientDataSet1 do
begin
Close;
CommandText := Format('Select * From CONTENT_PROVIDER Where CATEGORY_ID=''%s'' Order By PROVIDER_NAME',[ClientDataSet.FieldByName('CATEGORY_ID').AsString]);
Open;
for j := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'CONTENT_PROVIDER';
PTypeAndID^.TypeID := FieldByName('PROVIDER_ID').AsString;
TreeNode4 := AddChildObject(TreeNode3, FieldByName('PROVIDER_NAME').AsString, PTypeAndID);
TreeNode4.ImageIndex := ICO_CONTENT_PROVIDER;
TreeNode4.SelectedIndex := ICO_CONTENT_PROVIDER;
if not Eof then
Next;
end;
end;
if not Eof then
Next;
end;

New(PTypeAndID);
PTypeAndID^.TypeType := 'CONTENT_RATING_SORT';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '按等级分类', PTypeAndID);
TreeNode2.ImageIndex := ICO_CONTENT_RATING_SORT;
TreeNode2.SelectedIndex := ICO_CONTENT_RATING_SORT;

Close;
CommandText := 'Select * From CONTENT_RATING Order By RATING_NO, RATING_NAME';
Open;
for i := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'CONTENT_RATING';
PTypeAndID^.TypeID := FieldByName('RATING_ID').AsString;
TreeNode3 := AddChildObject(TreeNode2, FieldByName('RATING_NAME').AsString, PTypeAndID);
TreeNode3.ImageIndex := ICO_CONTENT_RATING;
TreeNode3.SelectedIndex := ICO_CONTENT_RATING;
if not Eof then
Next;
end;

New(PTypeAndID);
PTypeAndID^.TypeType := 'VODLOCATION';
PTypeAndID^.TypeID := '';
TreeNode1 := AddChildObject(TreeNode, '点播节目位置', PTypeAndID);
TreeNode1.ImageIndex := ICO_VODLOCATION;
TreeNode1.SelectedIndex := ICO_VODLOCATION;

{New(PTypeAndID);
PTypeAndID^.TypeType := 'VODLOCATION_ALL';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '全部点播节目位置', PTypeAndID);
TreeNode2.ImageIndex := ICO_VODLOCATION_ALL;
TreeNode2.SelectedIndex := ICO_VODLOCATION_ALL;

New(PTypeAndID);
PTypeAndID^.TypeType := 'VODLOCATION_DEVICE_SORT';
PTypeAndID^.TypeID := '';
TreeNode2 := AddChildObject(TreeNode1, '按设备分类', PTypeAndID);
TreeNode2.ImageIndex := ICO_VODLOCATION_DEVICE_SORT;
TreeNode2.SelectedIndex := ICO_VODLOCATION_DEVICE_SORT;

Close;
CommandText := 'Select * From DEVICE_CODE Order By DEVICE_NAME';
Open;
for i := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'VODLOCATION_DEVICE' ;
PTypeAndID^.TypeID := FieldByName('DEVICE_ID').AsString;
TreeNode3 := AddChildObject(TreeNode2, FieldByName('DEVICE_NAME').AsString, PTypeAndID);
TreeNode3.ImageIndex := ICO_VODLOCATION_DEVICE;
TreeNode3.SelectedIndex := ICO_VODLOCATION_DEVICE;
if not Eof then
Next;
end;}
end;
end;
Result := 0;
end;

{ InitContentTreeView
TreeView TTreeView 存放所有节目单和节目源元素
ClientDataSet,ClientDataSet1 : TClientDataSet
返回值 Integer 永远等于 0 。
var
TreeNode, TreeNode1, TreeNode2, TreeNode3, TreeNode4 : TTreeNode;
//五层的TreeView的每一级 元素
i, j : Integer;
//循环用
PTypeAndID : PointTypeAndID;
//为TreeView 指向的指针类型 }

function InitLPartitionTreeView(TreeView : TTreeView; ClientDataSet, ClientDataSet1, ClientDataSet2, ClientDataSet3, ClientDataSet4 : TClientDataSet) : Integer;
var
TreeNode, TreeNode1, TreeNode2, TreeNode3, TreeNode4, TreeNode5 : TTreeNode ;
i1, i2, i3, i4, i5, NcubeCount : Integer ;
PTypeAndID : PointTypeAndID;
begin
NcubeCount := 0;
with TreeView.Items do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'MPEGFILE_MANAGE';
PTypeAndID^.TypeID := '';
TreeNode := AddChildObject(nil, '节目源', PTypeAndID);
TreeNode.ImageIndex := ICO_MPEGFILE_MANAGE;
TreeNode.SelectedIndex := ICO_MPEGFILE_MANAGE;

with ClientDataSet do
begin
Close ;
CommandText := 'Select * From LOCATION_Code Where LEVEL_ID=3 ORDER BY LOCATION_NAME' ;
Open ;
for i1 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'FIRST_LOCATION';
PTypeAndID^.TypeID := FieldByName('LOCATION_ID').AsString;
TreeNode1 := AddChildObject(TreeNode, FieldByName('LOCATION_NAME').AsString, PTypeAndID);
TreeNode1.ImageIndex := ICO_FRIST_LOCATION;
TreeNode1.SelectedIndex := ICO_FRIST_LOCATION;
with ClientDataSet3 do
begin
Close ;
CommandText := Format('Select * From DEVICE_CODE Where CATEGORY_ID = ''VOD'' AND LOCATION_ID=''%s'' ORDER BY DEVICE_NAME',[ClientDataSet.FieldByName('LOCATION_ID').AsString]) ;
Open ;
for i4 := 0 to RecordCount - 1 do
begin
NcubeCount := NcubeCount + 1;
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_CODE';
PTypeAndID^.TypeID := FieldByName('DEVICE_ID').AsString;
TreeNode4 := AddChildObject(TreeNode1, FieldByName('DEVICE_NAME').AsString, PTypeAndID);
TreeNode4.ImageIndex := ICO_DEVICE_CODE;
TreeNode4.SelectedIndex := ICO_DEVICE_CODE;
with ClientDataSet4 do
begin
Close ;
CommandText := Format('Select * From DEVICE_LPARTITION Where DEVICE_ID=''%s'' ORDER BY LOGICAL_PARTITION',[ClientDataSet3.FieldByName('DEVICE_ID').AsString]) ;
Open ;
for i5 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_LPARTITION';
PTypeAndID^.TypeID := FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString;
PTypeAndID^.TypeID1 := ClientDataSet3.FieldByName('DEVICE_ID').AsString;
TreeNode5 := AddChildObject(TreeNode4, FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString, PTypeAndID);
TreeNode5.ImageIndex := ICO_DEVICE_LPARTITION;
TreeNode5.SelectedIndex := ICO_DEVICE_LPARTITION;
ClientDataSet4.Next;
end;
end;
ClientDataSet3.Next;
end;
end;
with ClientDataSet1 do
begin
Close ;
CommandText := Format('Select * From LOCATION_Code Where LEVEL_ID=2 and UPPERLOCATION_ID=''%s'' ORDER BY LOCATION_NAME',[ClientDataSet.FieldByName('LOCATION_ID').AsString]) ;
Open ;
for i2 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'SECOND_LOCATION';
PTypeAndID^.TypeID := FieldByName('LOCATION_ID').AsString;
TreeNode2 := AddChildObject(TreeNode1, FieldByName('LOCATION_NAME').AsString, PTypeAndID);
TreeNode2.ImageIndex := ICO_SECOND_LOCATION;
TreeNode2.SelectedIndex := ICO_SECOND_LOCATION;
with ClientDataSet3 do
begin
Close ;
CommandText := Format('Select * From DEVICE_CODE Where LOCATION_ID=''%s'' ORDER BY DEVICE_NAME',[ClientDataSet1.FieldByName('LOCATION_ID').AsString]) ;
Open ;
for i4 := 0 to RecordCount - 1 do
begin
NcubeCount := NcubeCount + 1;
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_CODE';
PTypeAndID^.TypeID := FieldByName('DEVICE_ID').AsString;
TreeNode4 := AddChildObject(TreeNode2, FieldByName('DEVICE_NAME').AsString, PTypeAndID);
TreeNode4.ImageIndex := ICO_DEVICE_CODE;
TreeNode4.SelectedIndex := ICO_DEVICE_CODE;
with ClientDataSet4 do
begin
Close ;
CommandText := Format('Select * From DEVICE_LPARTITION Where DEVICE_ID=''%s'' ORDER BY LOGICAL_PARTITION',[ClientDataSet3.FieldByName('DEVICE_ID').AsString]) ;
Open ;
for i5 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_LPARTITION';
PTypeAndID^.TypeID := FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString;
PTypeAndID^.TypeID1 := ClientDataSet3.FieldByName('DEVICE_ID').AsString;
TreeNode5 := AddChildObject(TreeNode4, FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString, PTypeAndID);
TreeNode5.ImageIndex := ICO_DEVICE_LPARTITION;
TreeNode5.SelectedIndex := ICO_DEVICE_LPARTITION;
ClientDataSet4.Next;
end;
end;
ClientDataSet3.Next;
end;
end;
with ClientDataSet2 do
begin
Close ;
CommandText := Format('Select * From LOCATION_Code Where LEVEL_ID=1 and UPPERLOCATION_ID=''%s'' ORDER BY LOCATION_NAME',[ClientDataSet1.FieldByName('LOCATION_ID').AsString]) ;
Open ;
for i3 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'THIRD_LOCATION';
PTypeAndID^.TypeID := FieldByName('LOCATION_ID').AsString;
TreeNode3 := AddChildObject(TreeNode2, FieldByName('LOCATION_NAME').AsString, PTypeAndID);
TreeNode3.ImageIndex := ICO_THIRD_LOCATION;
TreeNode3.SelectedIndex := ICO_THIRD_LOCATION;
with ClientDataSet3 do
begin
Close ;
CommandText := Format('Select * From DEVICE_CODE Where LOCATION_ID=''%s'' ORDER BY DEVICE_NAME',[ClientDataSet2.FieldByName('LOCATION_ID').AsString]) ;
Open ;
for i4 := 0 to RecordCount - 1 do
begin
NcubeCount := NcubeCount + 1;
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_CODE';
PTypeAndID^.TypeID := FieldByName('DEVICE_ID').AsString;
TreeNode4 := AddChildObject(TreeNode3, FieldByName('DEVICE_NAME').AsString, PTypeAndID);
TreeNode4.ImageIndex := ICO_DEVICE_CODE;
TreeNode4.SelectedIndex := ICO_DEVICE_CODE;
with ClientDataSet4 do
begin
Close ;
CommandText := Format('Select * From DEVICE_LPARTITION Where DEVICE_ID=''%s'' ORDER BY LOGICAL_PARTITION',[ClientDataSet3.FieldByName('DEVICE_ID').AsString]) ;
Open ;
for i5 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_LPARTITION';
PTypeAndID^.TypeID := FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString;
PTypeAndID^.TypeID1 := ClientDataSet3.FieldByName('DEVICE_ID').AsString;
TreeNode5 := AddChildObject(TreeNode4, FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString, PTypeAndID);
TreeNode5.ImageIndex := ICO_DEVICE_LPARTITION;
TreeNode5.SelectedIndex := ICO_DEVICE_LPARTITION;
ClientDataSet4.Next;
end;
end;
ClientDataSet3.Next;
end;
end;
ClientDataSet2.Next;
end;
end;
ClientDataSet1.Next;
end;
end;
ClientDataSet.Next;
end;
end;
end ;
Result := NcubeCount;
end;

{ InitLPartitionTreeView
TreeView TTreeView 存放所有节目单和节目源元素
ClientDataSet,ClientDataSet1, ClientDataSet2, ClientDataSet3, ClientDataSet4 : TClientDataSet
返回值 Integer NCUBE的数量 。
var
TreeNode, TreeNode1, TreeNode2, TreeNode3, TreeNode4, TreeNode5 : TTreeNode ;
//六层的TreeView的每一级 元素
i1, i2, i3, i4, i5 : Integer
//循环用
NcubeCount : Integer
//NCUBE的数量
PTypeAndID : PointTypeAndID;
//为TreeView 指向的指针类型}


留下你的qq和mail,哦们可以交流
 
上面大老的代碼謝了﹐cp下來慢慢看
晚上睡覺前想了一下﹐其實算法也簡單﹐掃描表的每筆資料﹐一個一個往上加
早上過來一揮而就:
{$R *.dfm}
function TForm1.search(level:integer;value:string;Tree:TTreeView;parent:TTreeNode):TTreeNode;
var k:integer;
begin
result:=nil;
if level=0 then
begin
for k:=0 to Tree.Items.Count-1 do
begin
if (Tree.Items[k].Level=0)and(Tree.Items[k].Text=value) then
begin
result:=Tree.Items[k];
break;
end;
end;
end
else
begin
for k:=0 to Tree.Items.Count-1 do
begin
if (Tree.Items[k].Level=level)and(Tree.Items[k].Text=value)
and(Tree.Items[k].Parent=parent) then
begin
result:=Tree.Items[k];
break;
end;
end;

end;



end;

procedure TForm1.Button1Click(Sender: TObject);
var parentnode,currnode,tmpnode:TTreeNode; i:integer;
procedure buildtree(cur:integer);
begin
if currnode=nil then
begin
tmpnode:=TreeView1.Items.AddChild(parentnode,q_bom.Fields[cur].Value);
tmpnode.Data:=pchar(inttostr(i)+'/'+inttostr(cur));
parentnode:=tmpnode; //如果新增一個﹐則它是父
end
else parentnode:=currnode;
end;

procedure buildother(cur:integer);
begin
tmpnode:=TreeView1.Items.AddChild(parentnode,q_bom.Fields[cur].Value);
tmpnode.Data:=pchar(inttostr(i)+'/'+inttostr(cur));
end;

begin
while not(q_bom.Eof) do
begin
//*********************************************************//
currnode:=search(0,q_bom.Fields[0].Value,TreeView1,nil);
if currnode=nil then
begin
tmpnode:=TreeView1.Items.AddChild(currnode,q_bom.Fields[0].Value);
tmpnode.Data:=pchar(inttostr(i)+'/'+'0');
parentnode:=tmpnode; //如果新增一個﹐則它是父
end
else parentnode:=currnode;
//*********************************************************//
currnode:=search(1,q_bom.Fields[1].Value,TreeView1,parentnode);
buildtree(1);
{ if currnode=nil then
begin
tmpnode:=TreeView1.Items.AddChild(parentnode,q_bom.Fields[1].Value);
tmpnode.Data:=pchar(inttostr(i)+'/'+'1');
parentnode:=tmpnode;
end
else parentnode:=currnode; }
//*********************************************************//
currnode:=search(2,q_bom.Fields[2].Value,TreeView1,parentnode);
buildtree(2);
{ if currnode=nil then
begin
tmpnode:=TreeView1.Items.AddChild(parentnode,q_bom.Fields[2].Value);
tmpnode.Data:=pchar(inttostr(i)+'/'+'2');
parentnode:=tmpnode;
end
else parentnode:=currnode; }
//*********************************************************//
currnode:=search(3,q_bom.Fields[3].Value,TreeView1,parentnode);
buildtree(3);
//*********************************************************//
{tmpnode:=TreeView1.Items.AddChild(parentnode,q_bom.Fields[4].Value);
tmpnode.Data:=pchar(inttostr(i)+'/'+inttostr(4));}
buildother(4);
buildother(5);
buildother(6);
buildother(7);
//**********************************************************//

i:=i+1;
q_bom.Next;
end;
end;
 
留下你的mail和qq大家可以交流一下
 
俺有msn: mchkz@hotmail.com 不过我不是高手。赫赫!
 
qjwlq@sina.com
廣東東莞﹐專做鞋廠,不是高手
 
多人接受答案了。
 
后退
顶部