Imports System.Data.SqlClient
Imports System.Xml

Module DB

    ''' <summary>
    ''' Provede jakýkoli SQL příkaz
    ''' </summary>
    ''' 
    Public Sub ExecuteCommand(ByVal Command As String, Optional ByVal connectionString As String = "")

        If Command.Contains("ur.php") Or Command.Contains("urchin.js") Or Command.Contains("script src") Then 'Odeslat chybu, pokud jde o prunik do databaze
            PCSolution.Email.OdeslatEmailAutoSMTP("info@pcsolution.cz", "soukup@pcsolution.cz", "DB Info", connectionString & vbCrLf & vbCrLf & Command)
            Exit Sub
        End If

        If connectionString = "" Then
            connectionString = getDB
        End If

        Dim sqlConn As New SqlConnection(connectionString)
        Dim Cmd As New SqlCommand(Command, sqlConn)
        sqlConn.Open()
        Cmd.ExecuteNonQuery()
        sqlConn.Close()

    End Sub

    ''' <summary>
    ''' Provede příkaz Select, výsledek uloží do DataTableu
    ''' </summary>
    ''' 
    Public Function ExecuteSelectCommand(ByVal Command As String, Optional ByVal connectionString As String = "") As Data.DataTable

        If connectionString = "" Then
            connectionString = getDB
        End If

        'propDBPocetDotazu += 1

        Dim sqlConn As New SqlConnection(connectionString)
        sqlConn.Open()
        Dim sqlAdapter As New SqlDataAdapter()
        sqlAdapter.SelectCommand = New SqlCommand(Command, sqlConn)
        Dim dbDS As New Data.DataTable()
        Try
            sqlAdapter.Fill(dbDS)
        Catch ex As Exception
            'HttpContext.Current.Response.Write(Command & "<br/>" & ex.ToString)
        End Try
        sqlConn.Close()

        Return dbDS

    End Function

End Module