views:

63

answers:

1

I've got an ASP.NET (VB.NET) page that has an Infragistics grid on it. One of the columns is called 'status'.

When I load the grid, I'm setting permissions to the fields at the column level, granting user roles (ENUM 'UserTypes') read/only or read/write permissions.

Next I need to loop through each row and assign permissions based upon the value (ENUM StatusVals) in the field 'status' as well as the user role.

I've got all this working, but it seems clunky and I want to improve it.

Here's a snapshot of one of the methods in which I pass in a row, the record status for that row, and the user type and loop through the cells to assign the permissions and colors. The question is: is there a more elegant way to do this so that as I add to it, it doesn't become a beast?

    Private Shared Sub SetDetailRowReadWrite_ByStatusVal(ByVal DetailRow As
 ig.UltraGridRow, ByVal sv As StatusVals, ByVal UserType As UserRoles)
    If sv = StatusVals.Pending _
        OrElse sv = StatusVals.Released _
        OrElse sv = StatusVals.Shipped _
        OrElse sv = StatusVals.Consolidated _
        OrElse sv = StatusVals.HOLD _
        OrElse sv = StatusVals.Cancelled _
        OrElse sv = StatusVals.PartialShipped Then

        For Each column As ig.UltraGridCell In DetailRow.Cells
            If column.Key = "StatusVal" Then
                column.Style.BackColor = Drawing.Color.LightGreen
                column.Style.ForeColor = Drawing.Color.Black

                If UserType = UserRoles.Fulfillment Then
                    SetFulfillmentStatusValEditPermission(sv, column)
                End If
            ElseIf Not (sv = StatusVals.Consolidated AndAlso UserType = UserRoles.Fulfillment) Then
                column.Style.BackColor = Drawing.Color.White
                column.AllowEditing = ig.AllowEditing.No
            End If
        Next

        LockSizesRow(DetailRow, UserType, sv)

    ElseIf sv = StatusVals.Incomplete AndAlso UserType = UserRoles.Fulfillment Then
        For Each c As ig.UltraGridCell In DetailRow.Cells
            c.AllowEditing = UltraWebGrid.AllowEditing.No
        Next
    End If
End Sub
A: 

You may want to look into the LoginView control in ASP.Net (2.0 and above) it gives you a templated control that maps templates to ASP.Net roles, including not logged in (anonymous).

This QuickStarts, although a bit dated demonstrate a simple example but the point is made rather cleanly.

CertifiedCrazy