Solved

Any good Idea to set rights in the software for every user

Posted on 2011-09-17
8
454 Views
Last Modified: 2013-11-13
We are making software and want any good Idea from you to set rights in the software for every user. Menu level to Tab level even till Table column level. just to enable/disable user wise. we make two tables one with list of Menus with On and Off . 2nd Table with list of all Menu and with this 2 table combination we can set the rights in the software.  If you have any good idea or any code or Any specail patch/utility available please let us know.
0
Comment
Question by:mahmood66
  • 5
  • 3
8 Comments
 
LVL 15

Expert Comment

by:x77
ID: 36555188
When I need achieve Right to users, I build a truth' Table.
Then I Build an Enumeration of Flags Type (An Integer supports 32 distinct values).
I can build Conbinations for especific privileges as mask with a name (A constant).

Then it is easy write code to Enable / disable controls based on Privilege mask.
0
 

Author Comment

by:mahmood66
ID: 36555524
dear,
can you elaborate with example.
0
 
LVL 15

Expert Comment

by:x77
ID: 36555626
<Flags()> _
Public Enum PrivPrj
    Adm = 1
    Otm = 2
    Ind = 4
    Condtra = 8
    Sap = 16
    EstudioTnd = 32
End Enum

  Public Property PrivAdm() As Boolean
      Get
          Return (PrivUsr And PrivPrj.Adm) > 0
      End Get
      Set(ByVal value As Boolean)
          PrivUsr = If(value, PrivUsr Or PrivPrj.Adm, PrivUsr And (Not PrivPrj.Adm))
      End Set
  End Property
  Public Property PrivEstudio() As Boolean
      Get
          Return (PrivUsr And (PrivPrj.EstudioTnd Or PrivPrj.Adm)) > 0
      End Get
      Set(ByVal value As Boolean)
          PrivUsr = If(value, PrivUsr Or PrivPrj.EstudioTnd, PrivUsr And (Not PrivPrj.EstudioTnd))
      End Set
  End Property
  Public ReadOnly Property PrivCondtra() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Condtra) > 0
      End Get
  End Property
  Public ReadOnly Property PrivInd() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Ind) > 0
      End Get
  End Property
  Public ReadOnly Property PrivOtm() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Otm) > 0
      End Get
  End Property
  Public ReadOnly Property PrivSap() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Sap) > 0
      End Get
  End Property

<Flags()> _
Public Enum PrivPrj
    Adm = 1
    Otm = 2
    Ind = 4
    Condtra = 8
    Sap = 16
    EstudioTnd = 32
End Enum

  Public Property PrivAdm() As Boolean
      Get
          Return (PrivUsr And PrivPrj.Adm) > 0
      End Get
      Set(ByVal value As Boolean)
          PrivUsr = If(value, PrivUsr Or PrivPrj.Adm, PrivUsr And (Not PrivPrj.Adm))
      End Set
  End Property
  Public Property PrivEstudio() As Boolean
      Get
          Return (PrivUsr And (PrivPrj.EstudioTnd Or PrivPrj.Adm)) > 0
      End Get
      Set(ByVal value As Boolean)
          PrivUsr = If(value, PrivUsr Or PrivPrj.EstudioTnd, PrivUsr And (Not PrivPrj.EstudioTnd))
      End Set
  End Property
  Public ReadOnly Property PrivCondtra() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Condtra) > 0
      End Get
  End Property
  Public ReadOnly Property PrivInd() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Ind) > 0
      End Get
  End Property
  Public ReadOnly Property PrivOtm() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Otm) > 0
      End Get
  End Property
  Public ReadOnly Property PrivSap() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Sap) > 0
      End Get
  End Property

....


    Private Restringido As Boolean
    Private Sub IsAdm()
        Restringido = Not PrivAdm OrElse Prj.ProyectoPublico AndAlso Prj.MaskEstado(PrjEst.ReadOnly)
        mSave.Enabled = Not Restringido
        CmdEdit.Enabled = Not Restringido
    End Sub

    TbAvSup.ReadOnly = PrivAdm OrElse Not (Util.PrvSup.Todos OrElse Array.IndexOf(Util.PrvSup.Sup, ActiveTr.Row(Tnd.SupCol)) >= 0)

     cDm = Dgv.Columns("DM")
     If PrivAdm OrElse PrivCondtra Then Dgv2.Columns.Add(DirectCast(cDm.Clone, DataGridViewColumn))

Open in new window

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 15

Expert Comment

by:x77
ID: 36555989
I Hide Usr and Name columns on PrivDlg

To Manage Mask on DataGridview you can use my FlagCheckBoxColumn

  Private Function AddPrvCol(ByVal header As String, ByVal Flag As Integer, ByVal Width As Integer) As FlagCheckBoxColumn
       Dim c As New FlagCheckBoxColumn(Flag) With {.HeaderText = header, .Width = Width, _
        .DataPropertyName = "Prv", .SortMode = DataGridViewColumnSortMode.Automatic}
       Dgv.Columns.Add(c)
       Return c
  End Function

        AddPrvCol("Adm", PrivPrj.Adm, 30)
        AddPrvCol("OTM", PrivPrj.Otm, 35)
        AddPrvCol("Ind", PrivPrj.Ind, 30)
        AddPrvCol("OTO", PrivPrj.Condtra, 35)
        AddPrvCol("Sap", PrivPrj.Sap, 30)
        AddPrvCol("Est", PrivPrj.EstudioTnd, 30)

<DebuggerStepThrough()> _
Public NotInheritable Class FlagCheckBoxColumn
    Inherits DataGridViewCheckBoxColumn
    Public mask As Integer

    Public Sub New (ByVal Mask As Integer)
        MyBase.New (False)
        CellTemplate = New FlagCheckBoxCell
        Me.mask = Mask
    End Sub

    'Forzando Private, me aseguro de que DirectCast(OwningColumn, FlagCheckBoxColumn) es válido
    Private NotInheritable Class FlagCheckBoxCell
        Inherits DataGridViewCheckBoxCell

        Sub New()
            MyBase.New (False)
            Me.ValueType = GetType (Boolean)
            'Soportados: Boolean, Integer-threeState...
        End Sub

        'El valor, no tiene por que ser necesariamente Int32, puede ser byte, short...
        Private Shared Function IntValue (ByVal V As Object) As Int32
            Return If(V Is DBNull.Value, 0, Convert.ToInt32 (V))
        End Function

        Protected Overrides Function GetValue (ByVal rowIndex As Integer) As Object
            Dim Mask As Integer = DirectCast (OwningColumn, FlagCheckBoxColumn).mask
            Return (IntValue (MyBase.GetValue (rowIndex)) And Mask) > 0
        End Function

        Protected Overrides Function SetValue (ByVal rowIndex As Integer, ByVal value As Object) As Boolean
            Dim Mask As Integer = DirectCast (OwningColumn, FlagCheckBoxColumn).mask
            Dim flags As Integer = IntValue (MyBase.GetValue (rowIndex))
            If True.Equals (value) Then flags = flags Or Mask Else flags = flags And (Not Mask)
            Return MyBase.SetValue (rowIndex, flags)
        End Function
    End Class
End Class

Open in new window

PrivDlg.png
0
 
LVL 15

Accepted Solution

by:
x77 earned 500 total points
ID: 36556167
For IntValue Method:

        'El valor, no tiene por que ser necesariamente Int32, puede ser byte, short...
        Private Shared Function IntValue (ByVal V As Object) As Int32
            Return If(V Is DBNull.Value, 0, Convert.ToInt32 (V))
        End Function

Privileges - Auto Restiction Dialog.

AdmPrivDlg
I Use it to validate Applictation behaviour with distinct privileges.
But Users can also work with auto Resticted privileges.
User can also restore original Privileges.

Private Sub Chk_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs)
        If disablechk Then Return
        Dim prv = OriginalPrivUsr Or PrivUsr
        Dim oK = (e.NewValue = CheckState.Unchecked) OrElse (prv And PrivPrj.Adm) > 0
        If oK Then
        ElseIf sender Is ChkTrDoc Then
           Dim v = If(e.Index = 0, Nothing, ChkTrDoc.Items(e.Index)), PrvSup = If(bOriginalValid, OriginalPrvSup, Util.PrvSup)
           If PrvSup.Autorizado(v) Then oK = True
        Else
           If (prv And (1 << e.Index)) > 0 Then oK = True
        End If
        If oK = False Then
           e.NewValue = e.CurrentValue : Beep()
        Else
           If bOriginalValid = False Then
              bOriginalValid = True
              OriginalPrvSup = Util.PrvSup
              OriginalPrivUsr = Util.PrivUsr
           End If
        End If
    End Sub

Open in new window


This Code do´nt allow a any user elevate Privileges, Only restrict.

I use a Dialog same this to Delegate Privileges:

A User can save data to a File (Serialization) saving also  information about privileges.
It Send this File to other user (Delegated) that can modify data an return modified file.

Original User validate Changes and Sync data to DataBase.
0
 

Author Comment

by:mahmood66
ID: 36559501
this user rights i am doing first time, kinldy let me know about database structure also, of any idea which  will help me in this.
Note:1.  i want to make menue and some of the menu must not be visible of some users.
         2. if form is having tabs (tab pages),  then i want to set rights tab wise even.
kindly let me know you good suggestion.
0
 
LVL 15

Expert Comment

by:x77
ID: 36561110
Each control, menu, ... has a Member variable Name.

Then you can do :

   MyMenuItem.visible = Required_Priv_User

Where Required_Priv_User is a Property or a boolean variable.

Note that you also can set "Enabled" or "ReadOnly" Control's properties.

0
 

Author Closing Comment

by:mahmood66
ID: 36572810
thanks that what I was looking for. and you given code and suggestion works
thanks again
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question