📄 userpermis_u.pas
字号:
unit UserPermis_U;
interface
{$IFDEF VER150}
{$DEFINE UCACTMANAGER}
{$ELSE}
{$IFDEF VER170}
{$DEFINE UCACTMANAGER}
{$ENDIF}
{$ENDIF}
uses
UCBase,
{$IFDEF UCACTMANAGER}
ActnMan, ActnMenus, Variants,
{$ENDIF}
{$IFDEF Ver140}
Variants,
{$ENDIF}
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, Buttons, ExtCtrls, StdCtrls, Menus, ImgList, DB,
ActnList, UCXPStyle;
type
PTreeMenu = ^TTreeMenu;
TTreeMenu = record
Selecionado : Integer;
MenuName : String;
end;
type
PTreeAction = ^TTreeAction;
TTreeAction = record
Grupo : Boolean;
Selecionado : Integer;
MenuName : String;
end;
type
PTreeControl = ^TTreeControl;
TTreeControl = record
Grupo : Boolean;
Selecionado : Integer;
CompName, FormName : String;
end;
type
TUserPermis = class(TForm)
Panel1: TPanel;
LbDescricao: TLabel;
Image1: TImage;
Panel3: TPanel;
BtLibera: TBitBtn;
BtBloqueia: TBitBtn;
BtGrava: TBitBtn;
lbUser: TLabel;
ImageList1: TImageList;
BtCancel: TBitBtn;
PC: TPageControl;
PageMenu: TTabSheet;
PageAction: TTabSheet;
TreeMenu: TTreeView;
TreeAction: TTreeView;
PageControls: TTabSheet;
TreeControls: TTreeView;
UCXPStyle: TUCXPStyle;
procedure BtGravaClick(Sender: TObject);
procedure TreeMenuClick(Sender: TObject);
procedure BtCancelClick(Sender: TObject);
procedure BtLiberaClick(Sender: TObject);
procedure BtBloqueiaClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure TreeActionClick(Sender: TObject);
procedure TreeControlsClick(Sender: TObject);
procedure TreeMenuCollapsing(Sender: TObject; Node: TTreeNode;
var AllowCollapse: Boolean);
procedure TreeMenuKeyPress(Sender: TObject; var Key: Char);
procedure TreeMenuMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
FMenu : TMenu;
FActions : TObject;
ChangingTree : Boolean;
{$IFDEF UCACTMANAGER}
FActMenuBar : TActionMainMenuBar;
procedure TrataItem( IT : TActionClientItem; node : TTreeNode);overload;
{$ENDIF}
procedure TrataItem(IT: TMenuItem; node: TTreeNode);overload;
procedure TreeMenuItem(marca: Boolean);
procedure Atualiza(Selec: Boolean);
procedure TreeActionItem(marca: Boolean);
procedure UnCheckChild(node: TTreeNode);
procedure TreeControlItem(marca: Boolean);
procedure CarregaTreeviews;
public
TempIdUser : Integer;
UCComponent : TUserControl;
DSPermiss, DSPermissEX, DSPerfil, DSPerfilEX : TDataset;
end;
var
UserPermis: TUserPermis;
implementation
{$R *.dfm}
procedure TUserPermis.BtGravaClick(Sender: TObject);
var
Contador : Integer;
begin
with TUserControl(Owner).TableRights do
begin
TUserControl(Owner).DataConnector.UCExecSQL('Delete from '+ TableName + ' Where '+FieldUserID+' = '+ IntToStr(TempIdUser)+ ' and '+FieldModule+' = '+ QuotedStr(TUserControl(owner).ApplicationID));
TUserControl(Owner).DataConnector.UCExecSQL('Delete from '+ TableName + 'EX Where '+FieldUserID+' = '+ IntToStr(TempIdUser)+ ' and '+FieldModule+' = '+ QuotedStr(TUserControl(owner).ApplicationID));
end;
for Contador := 0 to TreeMenu.Items.Count -1 do
if PTreeMenu(TreeMenu.Items[Contador].Data).Selecionado = 1 then
TUserControl(Owner).AddRight(TempIdUser, PTreeMenu(TreeMenu.Items[Contador].Data).MenuName);
for Contador := 0 to TreeAction.Items.Count -1 do
if PTreeAction(TreeAction.Items[Contador].Data).Selecionado = 1 then
TUserControl(Owner).AddRight(TempIdUser, PTreeAction(TreeAction.Items[Contador].Data).MenuName);
//Extra Rights
for Contador := 0 to Pred(TreeControls.Items.Count) do
if PTreeControl(TreeControls.Items[Contador].Data).Selecionado = 1 then
TUserControl(Owner).AddRightEX(TempIdUser, TUserControl(Owner).ApplicationID, PTreeControl(TreeControls.Items[Contador].Data).FormName, PTreeControl(TreeControls.Items[Contador].Data).CompName);
Close;
end;
procedure TUserPermis.TrataItem( IT : TMenuItem; node : TTreeNode);
var
contador : integer;
TempNode : TTreeNode;
TempPointer : PTreeMenu;
begin
for contador := 0 to IT.Count -1 do
if IT.Items[Contador].Caption <> '-' then
if IT.Items[Contador].Count > 0 then
begin
New(TempPointer);
TempPointer.Selecionado := 0;
TempPointer.MenuName := IT.Items[Contador].Name;
TempNode := TreeMenu.Items.AddChildObject(node, StringReplace(IT.Items[Contador].Caption,'&','',[rfReplaceAll]), TempPointer);
TrataItem(IT.Items[Contador],TempNode);
end else begin
New(TempPointer);
TempPointer.Selecionado := 0;
TempPointer.MenuName := IT.Items[Contador].Name;
TreeMenu.Items.AddChildObject(node,StringReplace(IT.Items[Contador].Caption,'&','',[rfReplaceAll]), TempPointer);
end;
end;
{$IFDEF UCACTMANAGER}
procedure TUserPermis.TrataItem( IT : TActionClientItem; node : TTreeNode);
var
contador : integer;
TempNode : TTreeNode;
TempPointer : PTreeMenu;
begin
for contador := 0 to IT.Items.Count -1 do
if IT.Items[Contador].Caption <> '-' then
if IT.Items[Contador].Items.Count > 0 then
begin
New(TempPointer);
TempPointer.Selecionado := 0;
TempPointer.MenuName := #1+'G'+IT.Items[Contador].Caption;
TempNode := TreeMenu.Items.AddChildObject(node, StringReplace(IT.Items[Contador].Caption,'&','',[rfReplaceAll]), TempPointer);
TrataItem(IT.Items[Contador],TempNode);
end else begin
New(TempPointer);
TempPointer.Selecionado := 0;
TempPointer.MenuName := IT.Items[Contador].Action.Name;
TreeMenu.Items.AddChildObject(node,StringReplace(IT.Items[Contador].Caption,'&','',[rfReplaceAll]), TempPointer);
end;
end;
{$ENDIF}
procedure TUserPermis.CarregaTreeviews;
var
Contador : Integer;
TempNode : TTreeNode;
TempPointer : PTreeMenu;
TempAPointer : PTreeAction;
TempCPointer : PTreeControl;
TempLista : TStringList;
Temp, Temp2, Desc : String;
FExtraRights : TUCCollection;
begin
ChangingTree := False;
PC.ActivePage := PageMenu;
FMenu := TUserControl(Owner).ControlRight.MainMenu;
if (not Assigned(FMenu) ) and (not Assigned(TUserControl(Owner).ControlRight.ActionList) )
{$IFDEF UCACTMANAGER} and (not Assigned(TUserControl(Owner).ControlRight.ActionManager) )
and (not Assigned(TUserControl(Owner).ControlRight.ActionMainMenuBar) ) {$ENDIF} then
begin
//retirado qmd
// MessageDlg('N鉶 foi atribuido um MainMenu/Actionlist/ActionManager/ActionMainManuBar !', mtError, [mbOK], 0);
// Exit; qmd
end;
if (Assigned(FMenu)) {$IFDEF UCACTMANAGER} and (not Assigned(TUserControl(Owner).ControlRight.ActionMainMenuBar)) {$ENDIF} then
begin
TreeMenu.Items.Clear;
for Contador := 0 to FMenu.Items.Count-1 do
if FMenu.Items[Contador].Count > 0 then
begin
New(TempPointer);
TempPointer.Selecionado := 0;
TempPointer.MenuName := FMenu.Items[Contador].Name;
TempNode := TreeMenu.Items.AddObject(nil, StringReplace(FMenu.Items[Contador].Caption,'&','',[rfReplaceAll]), TempPointer);
TrataItem(FMenu.Items[Contador],TempNode);
end else begin
New(TempPointer);
TempPointer.Selecionado := 0;
TempPointer.MenuName := FMenu.Items[Contador].Name;
TreeMenu.Items.AddObject(nil,StringReplace(FMenu.Items[Contador].Caption,'&','',[rfReplaceAll]), TempPointer);
end;
TreeMenu.FullExpand;
TreeMenu.Perform(WM_VSCROLL, SB_TOP, 0);
{$IFDEF UCACTMANAGER}
end
else if Assigned(TUserControl(Owner).ControlRight.ActionMainMenuBar) then
begin
FActMenuBar := TUserControl(Owner).ControlRight.ActionMainMenuBar;
TreeMenu.Items.Clear;
for Contador := 0 to FActMenuBar.ActionClient.Items.Count-1 do
begin
Temp := IntToStr(Contador);
if FActMenuBar.ActionClient.Items[StrToInt(Temp)].Items.Count > 0 then
begin
New(TempPointer);
TempPointer.Selecionado := 0;
TempPointer.MenuName := #1+'G'+ FActMenuBar.ActionClient.Items[StrToInt(Temp)].Caption;
TempNode := TreeMenu.Items.AddObject(nil, StringReplace(FActMenuBar.ActionClient.Items[StrToInt(Temp)].Caption,'&','',[rfReplaceAll]), TempPointer);
TrataItem(FActMenuBar.ActionClient.Items[StrToInt(Temp)],TempNode);
end else begin
New(TempPointer);
TempPointer.Selecionado := 0;
TempPointer.MenuName := FActMenuBar.ActionClient.Items[StrToInt(Temp)].Action.Name;
TreeMenu.Items.AddObject(nil,StringReplace(FActMenuBar.ActionClient.Items[StrToInt(Temp)].Action.Name,'&','',[rfReplaceAll]), TempPointer);
end;
TreeMenu.FullExpand;
TreeMenu.Perform(WM_VSCROLL, SB_TOP, 0);
end;
{$ENDIF}
end else PageMenu.TabVisible := False;
TempNode := nil;
if (Assigned(TUserControl(Owner).ControlRight.ActionList)) {$IFDEF UCACTMANAGER} or(Assigned(TUserControl(Owner).ControlRight.ActionManager)) {$ENDIF} then
begin
if Assigned(TUserControl(Owner).ControlRight.ActionList) then FActions := TUserControl(Owner).ControlRight.ActionList {$IFDEF UCACTMANAGER} else FActions := TUserControl(Owner).ControlRight.ActionManager {$ENDIF};
TreeAction.Items.Clear;
TempLista := TStringList.Create;
for Contador := 0 to TActionList(FActions).ActionCount -1 do
TempLista.Append(TAction(TActionList(FActions).Actions[contador]).Category + #1+TAction(TActionList(FActions).Actions[contador]).Name+ #2 + TAction(TActionList(FActions).Actions[contador]).Caption );
TempLista.Sort;
Temp := #1;
for Contador := 0 to TempLista.Count -1 do
begin
if Temp <> Copy(TempLista[Contador],1,Pos(#1,TempLista[Contador])-1) then
begin
New(TempAPointer);
TempAPointer.Grupo := True;
TempAPointer.Selecionado := 0;
TempAPointer.MenuName := 'Grupo';
TempNode := TreeAction.Items.AddObject(nil, StringReplace(Copy(TempLista[Contador],1,Pos(#1,TempLista[Contador])-1),'&','',[rfReplaceAll]), TempAPointer);
TempNode.ImageIndex := 2;
TempNode.SelectedIndex := 2;
Temp := Copy(TempLista[Contador],1,Pos(#1,TempLista[Contador])-1);
end;
Temp2 := TempLista[Contador];
Delete(Temp2,1,pos(#1,Temp2));
New(TempAPointer);
TempAPointer.Grupo := False;
TempAPointer.Selecionado := 0;
TempAPointer.MenuName := Copy(Temp2,1,Pos(#2,Temp2)-1);
Delete(Temp2,1,pos(#2,Temp2));
TreeAction.Items.AddChildObject(TempNode, StringReplace(Temp2,'&','',[rfReplaceAll]), TempAPointer);
end;
TreeAction.FullExpand;
TreeAction.Perform(WM_VSCROLL, SB_TOP, 0);
end else PageAction.TabVisible := False;
//ExtraRights
TempNode := nil;
if TUserControl(Owner).ExtraRight.Count > 0 then
begin
FExtraRights := TUserControl(Owner).ExtraRight;
TreeControls.Items.Clear;
TempLista := TStringList.Create;
for Contador := 0 to Pred(FExtraRights.Count) do
TempLista.Append(FExtraRights[Contador].GroupName + #1+FExtraRights[Contador].Caption+ #2 + FExtraRights[Contador].FormName +#3+FExtraRights[Contador].CompName);
TempLista.Sort;
Temp := #1;
for Contador := 0 to Pred(TempLista.Count) do
begin
if Temp <> Copy(TempLista[Contador],1,Pos(#1,TempLista[Contador])-1) then
begin
New(TempCPointer);
TempCPointer.Grupo := True;
TempCPointer.Selecionado := 0;
TempCPointer.FormName := 'Grupo';
TempCPointer.CompName := 'Grupo';
TempNode := TreeControls.Items.AddObject(nil, Copy(TempLista[Contador],1,Pos(#1,TempLista[Contador])-1), TempCPointer);
TempNode.ImageIndex := 2;
TempNode.SelectedIndex := 2;
Temp := Copy(TempLista[Contador],1,Pos(#1,TempLista[Contador])-1);
end;
Temp2 := TempLista[Contador];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -