General Category > Application Showcase
Sample app with latest controls
Phrog30:
I put together a little sample app that has some of the latest controls. This app is compiled and ready to go. Run the included modbus sim and have at it.
Edit, had to update a file, latest link
https://drive.google.com/file/d/1cKDpXR5fCnxmGkT6vuMejVZuXbUPXSTQ/view?usp=sharing
James
Gene T.:
James, I have had a look at this application hoping to get some guidance for security control.
I have noticed that the BasicButton in the first AdvancedHMI Components section has a property field for security.
I would like to have this available on other controls such as AnalogValueDisplay, MomentaryButton, SelctorSwitch but can't seem to figure out the "How To" to make this possible.If you would point me in the right direction it would be very much appreciated.
Thanks,
Gene
Phrog30:
My controls already have security, so you have that option. But...
I have a class called Globals. In this class is this code:
--- Quote ---Public Enum SecurityType
None = 0
Operators = 10
Maintenance = 20
Supervisor = 30
Engineer = 40
Admin = 50
End Enum
--- End quote ---
This is where I can globally change the security levels, but generally these 5 are all anyone would need.
Then, in the controls, I have a property...
--- Quote ---'******************************
'* Property - Security
'******************************
Private m_Security As myEnums.SecurityType
''' <summary>
''' Choose security for this button
''' </summary>
''' <remarks></remarks>
<System.ComponentModel.Description("Choose security for this button")>
Public Property Security As myEnums.SecurityType
Get
Return m_Security
End Get
Set(ByVal value As myEnums.SecurityType)
m_Security = value
End Set
End Property
--- End quote ---
Then, for a button, on a button press event, for example, add something like this...
--- Quote ---Dim securityText = [Enum].ToObject(GetType(myEnums.SecurityType), m_Security).ToString()
If Globals.LoginLevel >= m_Security Then
Else
Dim x As New Security_Notice
x.Level = securityText
x.ShowDialog()
Return
End If
--- End quote ---
Globals.LoginLevel is from my login stuff, if you make your own you will need to massage this part. Also, I use my own message popup, if you use your own you will need to edit that part as well.
Go through, read the comments, take a stab at it, then come back if you have questions. The way I did things isn't necessarily the right way, just the way I did it.
James
Phrog30:
To add....
Instead of a popup you could bind the security stuff to the enabled property. Then there isn't really any code to write, aside from binding to the enable property.
Phrog30:
Using enabled may simply it for you, in my class Globals, is this shared property. This is tied to my security stuff.
--- Quote ---Public Shared LoginName As String
Public Shared UserName As String
Private Shared s_LoginLevel As Integer
Public Shared Property LoginLevel As Integer
Get
Return s_LoginLevel
End Get
Set(value As Integer)
If s_LoginLevel <> value Then
s_LoginLevel = value
OnLoginLevelChanged(System.EventArgs.Empty)
End If
End Set
End Property
--- End quote ---
I then have an event, in the same class...
--- Quote --- Public Shared Event LoginLevelChanged As EventHandler
Private Shared Sub OnLoginLevelChanged(ByVal e As EventArgs)
RaiseEvent LoginLevelChanged(Nothing, e)
End Sub
--- End quote ---
Then could add a handler OnHandleCreated, I also look at security then to see about what to do.
--- Quote ---Protected Overrides Sub OnHandleCreated(e As EventArgs)
MyBase.OnHandleCreated(e)
AddHandler AdvancedHMI.Globals.LoginLevelChanged, AddressOf LoginLevelChanged
Dim securityText = [Enum].ToObject(GetType(myEnums.SecurityType), m_Security).ToString()
If Globals.LoginLevel >= m_Security Then
Me.Enabled = True
Else
Me.Enabled = False
End If
--- End quote ---
Then watch the event and look at the security level...
--- Quote ---Private Sub LoginLevelChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim securityText = [Enum].ToObject(GetType(myEnums.SecurityType), m_Security).ToString()
If Globals.LoginLevel >= m_Security Then
Me.Enabled = True
Else
Me.Enabled = False
End If
End Sub
--- End quote ---
Navigation
[0] Message Index
[#] Next page
Go to full version