Imports EDSL.Entities
Imports EDSL.DAL
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports System.Data.Common
Public Class dbMainDropDownFunctions
#Region "Private Fields"
  Private Shared strMainConnString As String = "MainConnString"
#End Region
#Region "Public Functions"
  Public Function GetDropDownValues(ByVal intType As Integer) As List(Of entMainDropDown)
    Dim dropDownValues As New List(Of entMainDropDown)
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Dim dropDownValue As entMainDropDown
    Using dbCommand As DbCommand = db.GetStoredProcCommand("MainGetDropDownReference")
      db.AddInParameter(dbCommand, "DropDownType", DbType.Int32, intType)
      Try
        Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
        While oRecordset.Read()
          dropDownValue = New entMainDropDown()
          With dropDownValue
            .DropDownValue = oRecordset("DropDownValue").ToString()
            .TextDisplay = oRecordset("TextDisplay").ToString()
            .SecondaryValue = oRecordset("SecondaryValue").ToString()
            .DropDownID = Convert.ToInt32(oRecordset("DropDownID"))
          End With
          dropDownValues.Add(dropDownValue)
        End While
        oRecordset.Close()
      Catch ex As Exception
        Throw (ex)
      End Try
    End Using
    Return dropDownValues
  End Function
  Public Function GetSingularValue(ByVal strValue As String, ByVal intType As Integer) As entMainDropDown
    Dim mainDropDown As entMainDropDown
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Using dbCommand As DbCommand = db.GetStoredProcCommand("MainGetDropDownReferenceValue")
      db.AddInParameter(dbCommand, "DropDownValue", DbType.String, strValue)
      db.AddInParameter(dbCommand, "DropDownType", DbType.Int32, intType)
      Try
        Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
        If oRecordset.Read Then
          mainDropDown = New entMainDropDown
          With mainDropDown
            .DropDownValue = oRecordset("DropDownValue").ToString()
            .TextDisplay = oRecordset("TextDisplay").ToString()
            .SecondaryValue = oRecordset("SecondaryValue").ToString()
          End With
        Else
          mainDropDown = Nothing
        End If
        oRecordset.Close()
      Catch ex As Exception
        Throw ex
      End Try
    End Using
    Return mainDropDown
  End Function
  Public Function GetTextDisplayForDDL(ByVal intDropDownID As Integer) As String
    Dim mainDropDown As entMainDropDown
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Using dbCommand As DbCommand = db.GetStoredProcCommand("MainGetDropDownReferenceText")
      db.AddInParameter(dbCommand, "DropDownID", DbType.String, intDropDownID)
      Try
        Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
        If oRecordset.Read Then
          mainDropDown = New entMainDropDown
          Return oRecordset("TextDisplay").ToString()
        Else
          Return ""
        End If
        oRecordset.Close()
      Catch ex As Exception
        Throw ex
      End Try
    End Using
  End Function
  Public Function GetSecondaryValue(ByVal strValue As String) As string
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Using dbCommand As DbCommand = db.GetStoredProcCommand("MainGetDropDownReferenceValue")
      db.AddInParameter(dbCommand, "DropDownValue", DbType.String, strValue)
      db.AddInParameter(dbCommand, "DropDownType", DbType.String, 6)
      Try
        Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
        If oRecordset.Read Then
          return oRecordset("SecondaryValue").ToString()
        Else
          Return 999999
        End If
        oRecordset.Close()
      Catch ex As Exception
        Throw ex
      End Try
    End Using
  End Function
#End Region
End Class
