Solved

Passing user selection from UI to DAL

Posted on 2006-11-13
9
637 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 500 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
 
LVL 7

Author Comment

by:Camillia
ID: 17930521
David, i didnt see your comment, let me try that...
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now