Imports EDSL.Entities
Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Configuration
Imports System.Data.Common
Public Class dbMainMessage
  Private Shared strMainConnString As String = "MainConnString"
  Public Function GetMessage(ByVal intMessageID As Integer) As String
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Dim strOutput As String = ""
    Try
      Using dbCommand As DbCommand = db.GetStoredProcCommand("MainAdminMessageGet")
        db.AddInParameter(dbCommand, "MessageID", DbType.Int64, intMessageID)
        Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
        oRecordset.Read()
        strOutput = Convert.ToString(oRecordset("MessageText"))
        oRecordset.Close()
      End Using
      Return strOutput
    Catch ex As Exception
      Throw ex
      Return Nothing
    End Try
  End Function
  Public Function GetItem(ByVal intMessageID As Integer) As entMainMessage
    Dim objMessage As New entMainMessage
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Dim strOutput As String = ""
    Try
      Using dbCommand As DbCommand = db.GetStoredProcCommand("MainAdminMessageGet")
        db.AddInParameter(dbCommand, "MessageID", DbType.Int64, intMessageID)
        Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
        oRecordset.Read()
        With objMessage
          .MessageDesc = Convert.ToString(oRecordset("MessageDesc"))
          .MessageText = Convert.ToString(oRecordset("MessageText"))
          .MessageID = Convert.ToInt32(oRecordset("MessageID"))
        End With
        oRecordset.Close()
      End Using
      Return objMessage
    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 entMainMessage)
    Dim objPage As New List(Of entMainMessage)
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Try
      Using dbCommand As DbCommand = db.GetStoredProcCommand("MainAdminMessageGetAll")
        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 entMainMessage() With { _
            .MessageID = Convert.ToInt32(oRecordset("MessageID")), _
            .MessageDesc = Convert.ToString(oRecordset("MessageDesc")), _
            .MessageText = Convert.ToString(oRecordset("MessageText")) _
          })
        End While
        oRecordset.Close()
      End Using
    Catch ex As Exception
      Throw ex
    End Try
    Return objPage
  End Function
  Public Function SaveItem(ByVal intMessageID As Integer, ByVal strMessageText As String, ByVal intUserID As Integer) As Integer
    Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
    Dim strSPName As String = ""
    Try
      strSPName = "MainAdminMessageUPDATE"
      Using dbCommand As DbCommand = db.GetStoredProcCommand(strSPName)
        db.AddInParameter(dbCommand, "MessageID", DbType.Int16, intMessageID)
        db.AddInParameter(dbCommand, "MessageText", DbType.String, strMessageText)
        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
