請教遞歸刪除 |
尚未結案
|
lsh998
中階會員 發表:163 回覆:138 積分:60 註冊:2005-01-07 發送簡訊給我 |
treeview1 有: boot | |----lsh | | | |----lsh1 | | | | | |----lsh11 | | | | | |-----lsh111 | |-----lsh2 | | | |----lsh21 | |-----lsq | |-----lsh11 | |-----lsh111 在数据库库里可以得到表: roleandrightname roleandrightnameparent nodesum boot lsh 1 lsh lsh1 1 lsh1 lsh11 1 lsh11 lsh111 2 lsh lsh2 1 lsh2 lsh21 1 boot lsq 1 lsq lsh11 1 ////////// 因为有两个 lsh11 lsh111 所以: lsh11 lsh111 2 现在 递归的删除:比如我输入 参数:lsh 则需要删除的有: boot lsh lsh lsh1 lsh11 lsh111 lsh lsh2 lsh2 lsh21 并且使 lsh11 lsh111 2 的 nodesum-1 还有一个特殊的是:如果输入的是: lsh11 则要删除 lsh11 lsh111 而不是 lsh11 lsh111 2 的 nodesum-1 shaooy 兄,下面一个是我写的:没有考虑 特殊输入的,可是也不行啊! //////////定义一个结构 type pright=^tpright; tpright=record roleandrightname:string; roleandrightparentname:string; roleandrightnamename:string; roleandrightsum:longint; rightjudge:boolean; end; //////////定义一个结构 procedure tform21.DeleteMySpecial(ps:string); //ps 是传入的父节点的名称 var s1,s2,s3,sp:string; roleandrightnamename:string; roleandrightsum:longint; i,j:longint; Exists:boolean ; aDOStoredP2:TADOStoredProc; aDOStoredP3:TADOStoredProc; begin Exists:=false; aDOStoredP2:=TADOStoredProc.Create(nil); aDOStoredP2.Connection:=form1.ADOConnection1; aDOStoredP2.Close; aDOStoredP2.ProcedureName:='procselect_employyeerightstable_on_roleandrightparentname'; aDOStoredP2.Parameters.Refresh; aDOStoredP2.Parameters.ParamByName('@roleandrightnameparent').value:=ps; aDOStoredP2.Open; aDOStoredP2.First; while not aDOStoredP2.Eof do begin s1:=aDOStoredP2.fieldbyname('roleandrightnameparent').AsString ; s2:=aDOStoredP2.fieldbyname('roleandrightname').AsString ; roleandrightnamename:=aDOStoredP2.fieldbyname('roleandrightnamename').AsString ; roleandrightsum:=strtoint(aDOStoredP2.fieldbyname('nodesum').AsString); if s1=ps then begin j:=StrToInt(aDOStoredP2.fieldbyname('nodesum').AsString) ; if j=1 then begin aDOStoredP3:=TADOStoredProc.Create(nil); aDOStoredP3.Connection:=form1.ADOConnection1; aDOStoredP3.Close; aDOStoredP3.ProcedureName:='procdelete_employyeerightstable_on_roleandrightname_on_roleandrightnameparent'; aDOStoredP3.Parameters.Refresh; aDOStoredP3.Parameters.ParamByName('@roleandrightname').value:=s2; aDOStoredP3.Parameters.ParamByName('@roleandrightnameparent').value:=s1; aDOStoredP3.Prepared:=true; aDOStoredP3.ExecProc; //ADOTable1.Delete ; DeleteMySpecial(s2); end; if j>1 then begin aDOStoredP3:=TADOStoredProc.Create(nil); aDOStoredP3.Connection:=form1.ADOConnection1; aDOStoredP3.Close; aDOStoredP3.ProcedureName:='procupdate_employyeerightstable_on_roleandrightname_on_roleandrightnameparent'; aDOStoredP3.Parameters.Refresh; aDOStoredP3.Parameters.ParamByName('@roleandrightname').value:=s2; aDOStoredP3.Parameters.ParamByName('@roleandrightnameparent').value:=s1; aDOStoredP3.Prepared:=true; aDOStoredP3.ExecProc; DeleteMySpecial(s2); end; end else begin aDOStoredP2.Next ; DeleteMySpecial(thehead); end; aDOStoredP2.Next ; end; end; 注: 如果 nodesum 值 为2 的话 有两种情况 比如: lsh11 lsh111 2 如果递归到 lsh11 lsh111 则使 nodesum 的值减 1(2-1) 如果首先输入的参数就是 : lsh11 的话 则 删除 lsh11 lsh111 2 谢谢各位大哥! |
ddy
站務副站長 發表:262 回覆:2105 積分:1169 註冊:2002-07-13 發送簡訊給我 |
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi lsh998, 請參考 http://delphi.ktop.com.tw/topic.php?topic_id=44484 並加以修改,即可達到相同功能
----------------------------------
小弟才疏學淺,若有謬誤尚請不吝指教
----------------------------------
------
Fishman |
lsh998
中階會員 發表:163 回覆:138 積分:60 註冊:2005-01-07 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |