Passing user selection from UI to DAL

1. In my DAL , I have an enum:

Public Enum DataProvider
       SqlServer
    IBM
End Enum

2. In UI, I have a radiobutton that user can select either "sql server" or "IBM".

3. In my DAL right now, I have a class and this line of code ***hardcoded***:
    Dim dbManager As IDBManager = New DBManager(DataProvider.SqlServer)

But I dont want to hardcode "DataProvider.SQlServer". I want to set it based on user's selection. I think I need to use maybe *** class properties *** in my DAL to set the proper enum values...

Is that correct? How can I pass that value and make use of the enum instead of hardcoding the value?

LVL 7
CamilliaAsked:
Who is Participating?
 
doobdaveConnect With a Mentor Commented:
Hi,

if I understood this correctly, you would have a property in your DAL cllass, as follows:

Private _DbmsType as DataProvider
Public Property DbmsType as DataProvider
        Get
            Return _DbmsType
        End Get
        Set(ByVal Value As DataProvider)
            _DbmsType = Value
        End Set
End Property

In your UI, you can set the property when the user selects the value.
In the DAL, you can do:

Dim dbManager As IDBManager = New DBManager(DbmsType)

hope this helps,

David

0
 
riyazthadCommented:
Best option is using Enterprise Library framework. there you can create two database instance like SQlServer and IBM. Then you need to pass this instance name to DAL and you can open specific connection with same code.

Thad
0
 
CamilliaAuthor Commented:

I have something similar to the enterprise libary...:
http://aspalliance.com/837_Implementing_a_Data_Access_Layer_in_C

and I cant change it at this point....

"Then you need to pass this instance name to DAL "...that's what I want to do...pass user selection to DAL ...should I use "class property" to read from the enum?

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
CamilliaAuthor Commented:
David, i didnt see your comment, let me try that...
0
 
Jayadev NairApplication DeveloperCommented:
Hi,

You can Give value for Enums. like,

Public Enum DataProvider
    SqlServer = 0
    IBM  = 1
End Enum

And while passing value @ constructor, pass like

Dim dbManager As IDBManager = New DBManager(0)

And by result, at your constructor(assuming)

Public Sub New(enValue as DataProvider)
 'When you use enValue variable you will get DataProvider.SQLServer (corresponding enum value of Integer you passed)
End Sub


Thanks.
0
 
riyazthadCommented:
This is what method I am saying

http://msdn.microsoft.com/msdnmag/issues/05/07/DataPoints/

This is very easy to code.

Thad
0
 
CamilliaAuthor Commented:
Thad- I cant use the EntLib at this point since we've already coded the DAL using that other link...

Question (using David's method)....

Using David's method, I have this

***DAL ****
 Private _DBmsType As DataProvider
        Public Property DBmsType() As DataProvider
            Get
                Return _DBmsType
            End Get
            Set(ByVal value As DataProvider)
                _DBmsType = value

            End Set
        End Property


        Public Function GetSystems(ByVal userLogin As String, ByVal userSelection As DataProvider) As ArrayList
            'get user's database options
            Dim retVal As New ArrayList

            Dim dbManager As IDBManager = New DBManager(DBmsType)
             ..............
            Return retVal

        End Function

***BLL ****

  Shared Function UniUser(ByVal Identity As String, ByVal userSelection As U_DAL.DataProvider) As ArrayList

            Dim userData As New ArrayList


            Dim test As New U_DAL.MyUni.WebProject.Data.UserData.UserAccess
            userData = test.GetSystems(RemoveDomain(Identity), userSelection)


            Return userData


        End Function

***********Now, I in User Interface (aspx page), I get the value of the radiobutton...but that's a string..how should UserInterface (aspx) page/radioButton ....pass to the BLL and then to DAL?? **************
0
 
CamilliaAuthor Commented:


 Basically, how do "In your UI, you can set the property when the user selects the value" and now pass it to BLL and then to DAL?
"
0
 
CamilliaAuthor Commented:
*** Getting close but still have a problem ****

1. *** in UserInterface, aspx, I have this:
       Dim test As New U_DAL.MyUni.WebProject.Data.UserData.UserAccess
        test.DBType = UDAL.DataProvider.SqlServer  '********* This SETS the correct value *************

        U_BLL.MuUni.WebProject.Business.UserInfo.User.UniUser("Tom")

2. *** IN BLL, I have this:
 Public Class User
        'check user authorization. If user exists,get datbases user can access
        Shared Function UniUser(ByVal Identity As String) As ArrayList

            Dim userData As New ArrayList

            Dim test As New U_DAL.MyUni.WebProject.Data.UserData.UserAccess
            userData = test.GetSystems(RemoveDomain(Identity))
            Return userData
        End Function

3. ***IN DAL,
Private _DBType As DataProvider
        Public Property DBType() As DataProvider
            Get
                Return _DBType
            End Get
            Set(ByVal value As DataProvider)
                _DBType = value

            End Set
        End Property

        Public Function GetSystems(ByVal userLogin As String) As ArrayList
            'get user's database options
            Dim retVal As New ArrayList

            Dim dbManager As IDBManager = New DBManager(DBType)
               ..........
            Return retVal

        End Function

*********BUT : Dim dbManager As IDBManager = New DBManager(DBType) gets the FIRST value in the enum. It looks like it gets reset by the time it gets to DAL. "DBType" goes to the property but then the "set" value is reset...

any ideas what i'm dong wrong?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.