前段日子,用Delphi开发了一个项目(不是公司的,,^_^ ),原来一直对用户授权有些疑问,利用下面这两个函数,一切问题都ok了,,呵呵。,。。。
function UserPermissionSQL(PQ:TQuery;User,MenuN:String):Boolean;//授权
Var aPerm:String;
begin
With PQ do
begin
Close;
SQL.Clear;
SQL.Add('Select Sys_Modal_Menu,Permission From SysPermission where SysU_Code = ');
SQL.Add(User);
Prepare;
Try
Open;
First;
if Locate('Sys_Modal_Menu',MenuN,[loCaseInsensitive]) then
begin
aPerm:=FieldByName('Permission').AsString;
if aPerm='1' then Result:=True else Result:=False;
end
else Result:=False;
Except
Application.MessageBox(' 系统授权失败!'+#13+#13+'该操作员可能并不存在!请选择正确的操作员工!!','系 统 错 误',0+MB_ICONERROR);;
end;
end;
end;
function ModalPermission(ModalName:TMainMenu;PQ:TQuery;User:String;Var MenuN:String):Boolean;//模块授权
Var i,j:Integer;
// MenuName:String;
begin
for i:= 0 to ModalName.Items.Count-1 do
begin
MenuN:=ModalName.Items[i].Name;
if UserPerMission(PQ,User,MenuN) then
ModalName.Items[i].Enabled:=True
else
ModalName.Items[i].Enabled:=False;
for j:=0 to ModalName.items[i].count-1 do
begin
MenuN:=ModalName.Items[i].Items[j].Name;
if UserPerMission(PQ,User,MenuN) then
ModalName.Items[i].Items[j].Enabled:=True
else
ModalName.Items[i].Items[j].Enabled:=False;
end;
end;
end;