Imports System.Data.SqlClient

Module mdlBiblioteca

    Function SoNumeros(ByVal Keyascii As Short) As Short

        If InStr("1234567890", Chr(Keyascii)) = 0 Then
            SoNumeros = 0
        Else
            SoNumeros = Keyascii
        End If
        Select Case Keyascii
            Case 8
                SoNumeros = Keyascii
            Case 13
                SoNumeros = Keyascii
            Case 32
                SoNumeros = Keyascii
            Case 44
                SoNumeros = Keyascii

        End Select
    End Function
    Sub ExecutaSql(ByVal path As String, ByVal strBanco As String)

        Dim clsbanco As New clsBanco
        Dim con As SqlConnection = clsbanco.AbreBancoMaster()

        Try
            Dim sr As IO.StreamReader = IO.File.OpenText(path)
            Dim Bloco As String = String.Empty
            Dim Linha As String = String.Empty
            Dim cmd As SqlCommand = con.CreateCommand
            cmd.CommandType = CommandType.Text
            Try
                cmd.CommandText = "USE Master"
                cmd.ExecuteNonQuery()

                cmd.CommandText = "CREATE DATABASE [" & strBanco & "]"
                cmd.ExecuteNonQuery()


            Catch ex As Exception
                MessageBox.Show("Erro ao Selecionar o Banco de Dados!")
                Exit Sub
            End Try

            While Linha IsNot Nothing
                Linha = sr.ReadLine
                If Linha <> "GO" Then
                    Bloco = Bloco & ControlChars.NewLine & Linha
                Else
                    If Bloco <> "" Then
                        cmd.CommandText = Bloco
                        Try
                            cmd.ExecuteNonQuery()
                        Catch ex As Exception
                            MessageBox.Show("Erro ao executar o Seguinte Bloco de Comandos:" & ControlChars.NewLine & Bloco & ControlChars.NewLine & ex.Message)
                        End Try
                        Bloco = String.Empty
                    End If
                End If
            End While
        Catch ex As Exception
            MessageBox.Show("Erro ao Criar o Banco de Dados!" & ControlChars.NewLine & ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub


End Module
