Little idea of ​​authority management

xiaoxiao2021-03-06  14

In a WinForm project, use the MDI form, open the MDI subform from the MENU on the main form, and have a permission ID for each sub-form. When you open, it is necessary to judge whether the user has permission, in order to put Verify this part of the universal use of the following: 1. Define an interface IRIGHT, there is only one method getRightID, enter:

Interface

Iright

{String getRightId ();

2. Each MDI subscriber inherits this interface and returns a permission ID in the getRightID, for example:

public

String

GetRightid ()

{Return "Customer";

3. Open the child form on the main form, plus the verification of permissions, for example:

Form2 f

=

New

Form2 ();

IF

(UserHaveright (GetUserrights

"

Admin

"

, f))))

{F.mdiparent = this; f.show ();}

Else

{F.dispose ();

Two functions called by:

Private

Bool

UserHaveright (ArrayList CurrentUserrights, Iright FormWillopen)

{IF (currentuserrights.contains))) {return true;} else {return false;}}

Private

ArrayList GetUserright (

String

UserID)

{ArrayList Result = New ArrayList (); Result.Add ("Customer"); Result.Add ("premise"); returnrate;}

At the beginning, the GtrightID was placed in a form base class, and the MDI sub-form charged this base class inherited and then Override, and later became the inheritance of the interface to consider this interface can also be used in the control, that is, not only Is the right to page level.

There is still a problem with that, in the inspection, the instance of the sub-form must be, if the inspection does not release it, there is a waste of resources, so that the inspection permissions are not passed, the current approach is still acceptable. . If there is a better way, please give me a good idea.

Since the company can't go online, this post is I wrote on the paper to the Internet cafe.

The code is just a problem, and it is not compiled.

转载请注明原文地址:https://www.9cbs.com/read-49638.html

New Post(0)