Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing user selection from UI to DAL

Posted on 2006-11-13
9
Medium Priority
?
646 Views
Last Modified: 2012-06-27
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?

0
Comment
Question by:Camillia
9 Comments
 
LVL 6

Expert Comment

by:riyazthad
ID: 17930486
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
 
LVL 8

Accepted Solution

by:
doobdave earned 2000 total points
ID: 17930506
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
 
LVL 7

Author Comment

by:Camillia
ID: 17930514

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:Camillia
ID: 17930521
David, i didnt see your comment, let me try that...
0
 
LVL 6

Expert Comment

by:Jayadev Nair
ID: 17930558
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
 
LVL 6

Expert Comment

by:riyazthad
ID: 17930559
This is what method I am saying

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

This is very easy to code.

Thad
0
 
LVL 7

Author Comment

by:Camillia
ID: 17930924
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
 
LVL 7

Author Comment

by:Camillia
ID: 17931279


 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
 
LVL 7

Author Comment

by:Camillia
ID: 17931570
*** 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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question