CREATE FUNCTION power_load(@userid VARCHAR(20))
RETURNS @Table Table
(
JIBEI_ID int,
pid int,
JIEBEI_NAME varchar(50),
IMAGE_INDEX int
)
/*
函数作用: 得到权限
*/
as
begin
declare @quanxian table
(
POPEDOM_ID int
)
declare @POPEDOM_ID int
--------------------------
declare dep_right cursor for
SELECT dbo.POPEDOM.POPEDOM_ID
FROM dbo.USER_INFO INNER JOIN
dbo.depart_rights INNER JOIN
dbo.POPEDOM ON
dbo.depart_rights.POPEDOM_ID = dbo.POPEDOM.POPEDOM_ID ON
dbo.USER_INFO.DEPT_ID = dbo.depart_rights.GANGWEI_BIANHAO
WHERE ((dbo.USER_INFO.USER_NUM = @userid) or (dbo.USER_INFO.USER_NUM= 'vanguard'))
open dep_right
FETCH NEXT FROM dep_right INTO @POPEDOM_ID
WHILE @@FETCH_STATUS = 0
begin
insert into @quanxian values(@POPEDOM_ID)
FETCH NEXT FROM dep_right INTO @POPEDOM_ID
END
CLOSE dep_right
DEALLOCATE dep_right
--------------------------
declare use_right cursor for
SELECT dbo.POPEDOM.POPEDOM_ID
FROM dbo.suer_rights INNER JOIN
dbo.POPEDOM ON
dbo.suer_rights.POPEDOM_ID = dbo.POPEDOM.POPEDOM_ID
WHERE ((dbo.suer_rights.userid = @userid) or (dbo.suer_rights.userid= 'vanguard'))
open use_right
FETCH NEXT FROM use_right INTO @POPEDOM_ID
WHILE @@FETCH_STATUS = 0
begin
insert into @quanxian values(@POPEDOM_ID)
FETCH NEXT FROM use_right INTO @POPEDOM_ID
END
CLOSE use_right
DEALLOCATE use_right
-------------------------
declare @pid int,@jebei_id int
declare powerOpen cursor for
select * from @quanxian
open powerOpen
FETCH NEXT FROM powerOpen INTO @POPEDOM_ID
WHILE @@FETCH_STATUS = 0
begin
insert into @Table select JIBEI_ID, PID, JIEBEI_NAME, IMAGE_INDEX FROM dbo.JIEBEI where JIBEI_ID=@POPEDOM_ID
SELECT @pid=PID FROM dbo.JIEBEI where JIBEI_ID=@POPEDOM_ID --
while @pid<>0
begin
select @jebei_id=pid from dbo.JIEBEI where JIBEI_ID=@pid
insert into @Table select JIBEI_ID, PID, JIEBEI_NAME, IMAGE_INDEX FROM dbo.JIEBEI where JIBEI_ID=@pid
if @jebei_id=0 break
select @pid=@jebei_id
end
FETCH NEXT FROM powerOpen INTO @POPEDOM_ID
END
CLOSE powerOpen
DEALLOCATE powerOpen
-------------------------------
RETURN
end
上面的是一个根据用户ID生成不同权限的函数
然后生成不同的树形菜单。
请关注:http://www.delphibbs.com/delphibbs/dispq.asp?lid=3262196