Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VB.net - Macro Substitution
Message
De
12/11/2010 17:49:03
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Titre:
VB.net - Macro Substitution
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01488984
Message ID:
01488984
Vues:
338
Hello Everybody.

Ok - I know (by now) - .net is not capable of the beautifull Macro Substitution like VFP is :-( - thats why I need your help.

Here is the setup:
- Web asp.net page
- access controlled
- gather 'member of' groups from AD for current user - populate array (SecurityCodes)
- create/build a querry with linq gathering records from a MS SQL table. Result should be based on what current user is allowed to see
        Dim db = New DataClassesDataContext()
        Dim result_0 =
                From col_Row In db.Masters, z In db.DocumentTypes
                Select
                    Resource_ID = col_Row.Resource_ID,
                    Resource_First = col_Row.Resource_First,
                    Resource_Last = col_Row.Resource_Last,
                    VendorID = col_Row.VendorID,
                    Vendor_Name = col_Row.Vendor_Name,
                    ...,
                    SecurityCode = z.SecurityCode

        ' check Employee First
        If String.IsNullOrEmpty(Me.Employee_First.Text) = False Then
            n_Options = GetWildCardOptions(Me.Employee_First_WildCard_1.Checked, Me.Employee_First_WildCard_2.Checked, Me.Employee_First_WildCard_3.Checked)
            If n_Options = 0 Then
                result_0 = result_0.Where(Function(f) f.Resource_First.ToLower = Employee_First.Text.ToLower)
             ...
             End If
        End If

        ...

        '  i am trying to join db.Masters and db.DocumentTypes
        '  master is the master table with the info we need
        '  DocumentTypes contains 3 fields which link to the master table and a security code
        result_0 = result_0.Where(Function(f) f.Doc_Type_Level1.ToLower = f.Type_Level1.ToLower)
        result_0 = result_0.Where(Function(f) f.Doc_Type_Level2.ToLower = f.Type_Level2.ToLower)
        result_0 = result_0.Where(Function(f) f.Doc_Type_Level3.ToLower = f.Type_Level3.ToLower)


        '  now here comes the tricky part
        '  in VFP i would do the following:
        Dim CmdStr As String = ""
        Dim GroupCount As Integer = SecurityCodes.Length
        For i = 0 To GroupCount - 1
            CmdStr += If(i > 0, " OR ", "") + "((f.SecurityCode And " + SecurityCodes(i).ToString() + ") = " + SecurityCodes(i).ToString() + ")"
        Next

        result_0 = result_0.Where(Function(f) If(CmdStr, True, False))

        ' execute the SQL command
        result_0.ToList()
The above obviously does not work.

I basicly need to create a new where string with values from the security array - which changes between users.

The way a completed where string would look like is as follows:
result_0 = result_0.Where(Function(f) 
        (If(f.SecurityCode And 4) = 4, True, False) OR
        (If(f.SecurityCode And 32) = 32, True, False) OR
        (If(f.SecurityCode And 8) = 8, True, False))
You probably noticed that i am working with a bitwise AND to figure out if any of the users AD groups allow the user to view the record. The record may contain a value of 102 in f.SecurityCode (i.e.) which would allow several user groups access.

I have also tried to call a function and return True or False, but LINQ did not like that.

How would this be done - any ideas?

Thank you all for your help!
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform