Imports System.Data.SqlServerCe
Imports CamadaDTO
Imports System.Collections.Generic
Public Class ConfigDAL

    Public Function GetConfig() As Config
        Dim strSql As String
        Dim objdb As New AcessoDados
        strSql = "Select * from configuracao where numeroConfiguracao = 1"
        Dim dataReader As DataRow = objdb.ExecuteAndGetRow(strSql)
        Dim ens As Config = New Config
        ens.numeroConfiguracao = IIf(IsDBNull(dataReader("numeroConfiguracao")), 0, dataReader("numeroConfiguracao"))
        ens.proprietario = IIf(IsDBNull(dataReader("proprietario")), "", dataReader("proprietario"))
        ens.numeroSerie = IIf(IsDBNull(dataReader("numeroSerie")), "", dataReader("numeroSerie"))
        ens.sinalSonoro = IIf(IsDBNull(dataReader("sinalSonoro")), 0, dataReader("sinalSonoro"))
        ens.portaCom = IIf(IsDBNull(dataReader("portaCom")), "", dataReader("portaCom"))
        ens.boundRate = IIf(IsDBNull(dataReader("boundRate")), "", dataReader("boundRate"))
        ens.stopBits = IIf(IsDBNull(dataReader("stopBits")), "", dataReader("stopBits"))
        ens.paridade = IIf(IsDBNull(dataReader("paridade")), "", dataReader("paridade"))
        ens.dataBits = IIf(IsDBNull(dataReader("dataBits")), "", dataReader("dataBits"))
        Return ens
    End Function


    Public Function Salvar(ByVal ens As Config) As Boolean
        Dim strsql As String = String.Empty
        Dim objDB As New AcessoDados

        strsql = "Update configuracao set proprietario ='" & ens.proprietario & "' , numeroSerie ='" & ens.numeroSerie & "' , boundRate ='" & ens.boundRate & "' , dataBits ='" & ens.dataBits & "' , paridade ='" & ens.paridade & "' , portaCom ='" & ens.portaCom & "' , sinalSonoro ='" & ens.sinalSonoro & "' , stopBits='" & ens.stopBits & "'" & "  where numeroConfiguracao= '1'"

        Try
            objDB.ExecuteQuery(strsql)
        Catch ex As Exception
            Throw New Exception
        End Try

        Return True
    End Function

End Class
