> 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.
>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.
<Flags()> _ Public Enum SecurityCodes Guest = 1 Employee = 2 Manager = 4 Affiliate = 8 Distributor = 16 End Enumand maybe an extension method:
<System.Runtime.CompilerServices.Extension()> _ Public Function IncludesCode(ByVal sc As SecurityCodes, ByVal list As List(Of Integer)) As Boolean For Each i As Integer In list If sc.HasFlag(DirectCast(i, SecurityCodes)) Then Return True End If Next Return False End FunctionThen you can simply do, for example:
Dim InCodes As New List(Of Integer)() From {1, 4} Dim ToCheck As SecurityCodes = SecurityCodes.Guest Or SecurityCodes.Affiliate Dim b As Boolean = ToCheck.IncludesCode(InCodes)