Home > Back-end >  Control the permissions problem, which help me to optimize the teacher, is there a simple way.
Control the permissions problem, which help me to optimize the teacher, is there a simple way.

Time:04-20

The Main. ADOQuery1. SQL. The Clear;//open the permissions list, judgment when you login,
Main. ADOQuery1. SQL. The Add (' Select Top 1 * From S_SysUser Where UserName=: UserName ');
Main. ADOQuery1. The Parameters. ParamByName (" UserName "). The Value:=Trim (ComboBox1. Text);
The Main. ADOQuery1. Open;
If the Main. ADOQuery1. FieldByName (' NewBtn). AsString='0' Then/0/1/judge the value of the new button
The Begin
The Main. NewBitbtn1. Visible:=False;
End;

//the problem is, if such assumptions I have 1000 button, you will need to write code article 1000
How can simplify some, will be able to control each button is visible?

CodePudding user response:

A simple method is:
Write a generic function, the content of the input parameter is the user name, the button name (is actually need to judge the permissions), return privileges, and then to determine each button,

Do you want to write less code, can be button a derived class, with authority to judge in the new class content, and then use the new class, outside the relatively complex, for you may not use,

Rights management, make the whole system is quite complicated, with simple good, you slowly again after optimization,

CodePudding user response:

reference 1st floor tanqth response:
a simple solution is to:
Write a generic function, the content of the input parameter is the user name, the button name (is actually need to judge the permissions), return privileges, and then to determine each button,

Do you want to write less code, can be button a derived class, with authority to judge in the new class content, and then use the new class, outside the relatively complex, for you may not use,

Rights management, make the whole system is quite complicated, with simple good, you slowly again after optimization,

That I write this, can the efficiency of the system is too bad, too much code, will affect the performance?

CodePudding user response:

How is it possible that there are 1000 button?
Want to take ah? Simple, can:
Var
I: integer;
ButtonVisible: Boolean;
The begin
//...
ButtonVisible:=Main. ADOQuery1. FieldByName (' NewBtn). AsString<> '0'.

For I:=0 to Main. Do ControlCount - 1
. If the Main Controls [I] is TBitBtn then
Visible. The Main Controls [I]=ButtonVisible;

CodePudding user response:

To

CodePudding user response:

Button in the event to determine permissions to perform an action, or the form into the permissions before judgment, no permissions not let into,
Each have advantages and disadvantages, to decide,
  • Related