做一个中间表,专门管理产品的层次,这是我软件用到的中间层,递归算法procedure pdCcCreate(Aid,Aclid,Aclmc:string; ASql1:string=''; ASql2: string='';M:integer=1;ACc:string='1';ACs:integer=1;Asl
ouble=1); //创建层次procedure pdCcCreate(Aid, Aclid, Aclmc, ASql1:string; ASql2: string; M: integer;ACc:string;Acs:integer;Asl:double);var adotmp:TADOQuery; Sqlstr,lb:string; Sql3,sql4:string; id,clid,clmc:string; i:integer; sl:double;begin try if m>10 then begin Fbl :=true; exit; end; adotmp :=TADOQuery.Create(nil); adotmp.Connection :=fdm.adocnn ; Sqlstr:='select * from Pl_Wljcsj_Wl where lb=''组件'' and id='+quotedstr(Aid); adotmp.SQL.Text:=Sqlstr; adotmp.Open; if Asql1='' then ASql1:='insert into Pl_Wljcsj_Cc(id,zjno,zjname,Cid1,CName1'; if Asql2='' then ASql2:='values('+quotedstr(Aid)+','+quotedstr(Aclid) +','+quotedstr(Aclmc)+','+quotedstr(Aclid) +','+quotedstr(Aclmc); i:=1; // Asl:=adotmp.fieldbyname('sl').AsCurrency*Asl; if not adotmp.IsEmpty then begin while not adotmp.eof do begin id:=adotmp.fieldbyname('lmid').AsString ; clid:=adotmp.fieldbyname('clid').AsString ; CLmc:=adotmp.fieldbyname('clmc').AsString ; Sql3:=ASql1+',Cid'+inttostr(m+1)+','+'Cname'+inttostr(m+1); Sql4:=ASql2+','+quotedstr(clid)+','+quotedstr(CLmc); Sl:= adotmp.fieldbyname('sl').AsCurrency; pdCcCreate(id, clid, CLmc,Sql3, Sql4,m+1,Acc+'-'+inttostr(i),ACs+1,Asl*Sl); adotmp.Next; i:=i+1; end; end else begin lb:='End'; // Sl:= adotmp.fieldbyname('sl').AsCurrency; end; Sqlstr:=ASql1+',lmid,clid,clmc,lb,cc,cs,sl)'+ ASql2+','+quotedstr(Aid)+',' +quotedstr(Aclid)+','+quotedstr(Aclmc)+','+quotedstr(lb)+','+quotedstr(Acc)+','+inttostr(Acs)+','+floattostr(Asl)+')'; fdm.adocnn.Execute(Sqlstr); finally adotmp.Free; end;end;