Alex,
The reason they are numbered is that they correspond to a reference key in a
table which I want to build a search SQL string for.
I would have the Enum have values such as 1, 2, 4, 8, 16, as that is
required.
Then I would consider having a Hashtable that maps the above values to 1, 2,
3, 4, 5, 6 to do the lookup in SQL. (see below)
Remember the point of using Flags & Or operator is to support passing in two
CustomCCItemType values at the same time, in a signal value:
CustomCCItemType.Drawing Or CustomCCItemType.PNumber
However you will need to extract each CustomCCItemType individually to build
your SQL statement. (see below)
The problem as I see it is the way the Enum implements a "set of values" by
combining the bit values into a single integer, where as SQL implements a
"set of values" by combining individual values into a collection of multiple
integers. Hence your delima.
One way to map the Enum to SQL key:
I would have a hash table that is keyed by the CustomCCItemType
values themselves, the value would be the SQL Key.
' Note it is best to do this once, as a Shared variable of your class.
Dim mapping As New Hashtable()
Dim index As Integer
For Each value As CustomCCItemType In
[Enum].GetValues(GetType(CustomCCItemType))
index += 1
mapping.Add(value, index)
Next
If the SQL keys are not consecutive then the above will not work, I would
use individual mapping.Add statements for each Enum to Key pair, instead of
the loop.
mapping.Add(CustomCCItemType.Drawing, 1)
mapping.Add(CustomCCItemType.PNumber, 2)
mapping.Add(CustomCCItemType.ConsumablePNumber, 3)
...
The problem would seem to be 'extracting' each unique attribute out of the
CustomCCItemType parameter, I would use my hash table to map bit masks (the
keys) that I use to check the parameter.
Dim keys As New ArrayList()
For Each de As DictionaryEntry In mapping
Dim key As CustomCCItemType = CType(de.Key, CustomCCItemType)
If (input And key) = key Then
keys.Add(de.Value)
End If
Next
The keys ArrayList now contains a list of SQL keys to use for your SQL
statement. Rather then using the keys ArrayList you could use a
StringBuilder and directly build the SQL statement.
Hope this helps
Jay
Hope this helps
Jay