How do I do this?

  • Thread starter Thread starter Merlin
  • Start date Start date
M

Merlin

Hi,

This is want I want to do, but not sure how to do it:-

I want to create a class that has events, for example a Class called
"Security" that has an event called "Security Changed", I then want to
attach this in some way to some forms and controls and then have the event
"Security Changed" visible in these. Then whenever I fire the event
"Security Changed" from anywhere all open forms/controls with the same event
attached also fire.

I'm after this functionality so that I can setup a password scheme, so that
a user by default has Read Only access to all program forms, but if they
then enter a password all open forms change to Full Access. There are many
ways to accomplish this but the way described above would be much more
manageable.

Is this possible?

Thanks.

Merlin
 
Hi Merlin

This is how i do security in my company management system.

I have a class that as 4 methods BrowseButtons(form),
BrowseMenus(form), ActivateMenus(form) and ActivateButtons
(form). All are called in form_load event. The browse
methods are a precaution if i add a new button or menu
item there are immediatly stored in a sql table with my
user id. The Activates methods read the user acess to
buttons and menus for each form and activate them.

I have a collection of form when the form loads it adds
itself when it unloads it removes itself.

I have a 'Terminate Session' in the main form and i use
the collection to browse all form and calling for each
ActivateMenus(form) and ActivateButtons(form).

The browse and activate methods use
System.Reflection.FieldInfo()

Kind Regards
Jorge Cavalheiro
 
Merlin said:
Hi,

This is want I want to do, but not sure how to do it:-

I want to create a class that has events, for example a Class called
"Security" that has an event called "Security Changed", I then want to
attach this in some way to some forms and controls and then have the event
"Security Changed" visible in these. Then whenever I fire the event
"Security Changed" from anywhere all open forms/controls with the same event
attached also fire.

I'm after this functionality so that I can setup a password scheme, so that
a user by default has Read Only access to all program forms, but if they
then enter a password all open forms change to Full Access. There are many
ways to accomplish this but the way described above would be much more
manageable.

Is this possible?

Thanks.

Merlin

I possible way to do this is as follows:

In your User Object (the current user with security permissions)
create a property SecurityLevel or something similar
Also create an Event SecurityChanged, fire the event when
SecurityLevel changes

Create an Interface ILockable

Public Interface ILockable
Property Locked() As Boolean
End Interface

have each Form/UserControl implement ILockable

Public Overridable Property Locked() As Boolean Implements
ILockable.Locked
Get
Return m_Locked
End Get
Set(ByVal Value As Boolean)
m_Locked = Value
setLockedState(Value)
End Set
End Property

in each Form/UserControl create a Sub setLockedState(Value) that sets
the state of the controls on the form

In your main form add and handler for the User_SecurityChanged event,
loop though all open forms testing if they implement ILockable. If
they do, set the locked state.

Alternately, have each form listen for the User_SecurityChanged event
and Lock accordingly

k.
 
Thanks K.

User said:
"Merlin" <[email protected]> wrote in message

I possible way to do this is as follows:

In your User Object (the current user with security permissions)
create a property SecurityLevel or something similar
Also create an Event SecurityChanged, fire the event when
SecurityLevel changes

Create an Interface ILockable

Public Interface ILockable
Property Locked() As Boolean
End Interface

have each Form/UserControl implement ILockable

Public Overridable Property Locked() As Boolean Implements
ILockable.Locked
Get
Return m_Locked
End Get
Set(ByVal Value As Boolean)
m_Locked = Value
setLockedState(Value)
End Set
End Property

in each Form/UserControl create a Sub setLockedState(Value) that sets
the state of the controls on the form

In your main form add and handler for the User_SecurityChanged event,
loop though all open forms testing if they implement ILockable. If
they do, set the locked state.

Alternately, have each form listen for the User_SecurityChanged event
and Lock accordingly

k.
 
Back
Top