Imports EDSL.Entities
Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Configuration
Imports System.Data.Common
Public Class dbMainValue
  Private Shared strMainConnString As String = "MainConnString"
  Public Function GetValue(ByVal intValueID As integer) As string
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Dim strOutput As String = ""
    Try
      Using dbCommand As DbCommand = db.GetStoredProcCommand("MainAdminValueGet")
        db.AddInParameter(dbCommand, "MainValueID", DbType.Int64, intValueID)
        Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
        oRecordset.Read()
        strOutput = Convert.ToString(oRecordset("MainValueText"))
        oRecordset.Close()
      End Using
      Return strOutput
    Catch ex As Exception
        Throw ex
      Return nothing
    End Try
  End Function
  Public Function GetItem(ByVal intValueID As integer) As entMainValue
   Dim objValue As new entMainValue
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Dim strOutput As String = ""
    Try
      Using dbCommand As DbCommand = db.GetStoredProcCommand("MainAdminValueGet")
        db.AddInParameter(dbCommand, "MainValueID", DbType.Int64, intValueID)
        Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
        oRecordset.Read()
        objValue.ValueID = Convert.ToString(oRecordset("MainValueID"))
        objValue.ValueDesc = Convert.ToString(oRecordset("MainValueDesc"))
        objValue.Valuetext = Convert.ToString(oRecordset("MainValueText"))
        oRecordset.Close()
      End Using
      Return objValue
    Catch ex As Exception
        Throw ex
      Return nothing
    End Try
  End Function
  Public Function GetAll(byval strWHEREclause As String, ByVal strORDERBYclause As string) As List(Of entMainValue)
    Dim objPage As new list(Of entMainValue)
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Try
      Using dbCommand As DbCommand = db.GetStoredProcCommand("MainAdminValueGetAll")
        db.AddInParameter(dbCommand, "WHEREclause", DbType.String, strWHEREclause)
        db.AddInParameter(dbCommand, "ORDERBYclause", DbType.String, strORDERBYclause)
        Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
        While oRecordset.Read()
            objPage.Add(New entMainValue() with { _
              .ValueID = Convert.ToInt32(oRecordset("MainValueID")), _
              .ValueDesc = Convert.ToString(oRecordset("MainValueDesc")), _
              .ValueText = Convert.ToString(oRecordset("MainValueText")) _
            })
        End While
        oRecordset.Close()
      End Using
    Catch ex As Exception
        Throw ex
    End Try
    Return objPage
  End Function
  Public Function SaveItem(Byval intValueID As Integer, Byval strValueText As String, ByVal intUserID As integer) As Integer
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Dim strSPName As String = ""
    Try
      strSPName = "MainAdminValueUPDATE"
      Using dbCommand As DbCommand = db.GetStoredProcCommand(strSPName)
        db.AddInParameter(dbCommand, "MainValueID", DbType.Int16, intValueID)
        db.AddInParameter(dbCommand, "MainValueText", DbType.String, strValueText)
        db.AddInParameter(dbCommand, "UserID", DbType.Int16, intUserID)
        db.ExecuteNonQuery(dbCommand)
      End Using
      Return 0
    Catch ex As Exception
      Return 1
    End Try
  End Function
End Class
