Imports System.Text.RegularExpressions
Public Class ClassFormFunctions
    Public Shared Function GetConnectionString(id As Integer)
        Dim connectionString As String = ""
        Try
            'Me.TBCONNECTIONTableAdapter.FillByID(Me.DD_DMSLiteDataSet.TBCONNECTION, id)
            Dim DTConnection As DataTable = ClassDatabase.Return_Datatable("SELECT * FROM TBDD_CONNECTION WHERE GUID = " & id)
            If DTConnection.Rows.Count = 1 Then
                Dim CSType = DTConnection.Rows(0).Item("SQL_PROVIDER").ToString.ToUpper
                Select Case CSType
                    Case "MS-SQL".ToUpper
                        If DTConnection.Rows(0).Item("USERNAME").ToString.ToLower = "winauth" Then
                            connectionString = "Data Source=" & DTConnection.Rows(0).Item("SERVER") & ";Initial Catalog= " & DTConnection.Rows(0).Item("DATENBANK") & ";Trusted_Connection=True;"
                        Else
                            connectionString = "Data Source=" & DTConnection.Rows(0).Item("SERVER") & ";Initial Catalog= " & DTConnection.Rows(0).Item("DATENBANK") & ";User Id=" & DTConnection.Rows(0).Item("USERNAME") & ";Password=" & DTConnection.Rows(0).Item("PASSWORD") & ";"
                        End If
                    Case "MS-SQLServer".ToUpper
                        If DTConnection.Rows(0).Item("USERNAME").ToString.ToLower = "winauth" Then
                            connectionString = "Data Source=" & DTConnection.Rows(0).Item("SERVER") & ";Initial Catalog= " & DTConnection.Rows(0).Item("DATENBANK") & ";Trusted_Connection=True;"
                        Else
                            connectionString = "Data Source=" & DTConnection.Rows(0).Item("SERVER") & ";Initial Catalog= " & DTConnection.Rows(0).Item("DATENBANK") & ";User Id=" & DTConnection.Rows(0).Item("USERNAME") & ";Password=" & DTConnection.Rows(0).Item("PASSWORD") & ";"
                        End If

                    Case "Oracle".ToUpper
                        If DTConnection.Rows(0).Item("BEMERKUNG").ToString.Contains("without tnsnames") Then
                            connectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" & DTConnection.Rows(0).Item("SERVER") & ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" &
                               DTConnection.Rows(0).Item("DATENBANK") & ")));User Id=" & DTConnection.Rows(0).Item("USERNAME") & ";Password=" & DTConnection.Rows(0).Item("PASSWORD") & ";"
                        Else
                            connectionString = "Data Source=" & DTConnection.Rows(0).Item("SERVER") & ";Persist Security Info=True;User Id=" & DTConnection.Rows(0).Item("USERNAME") & ";Password=" & DTConnection.Rows(0).Item("PASSWORD") & ";Unicode=True"
                        End If
                        'Dim conn As New OracleConnectionStringBuilder

                        'If chkOR_ohne_TNS.Checked Then
                        '    connstr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" & SERVERTextBox.Text & ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" & _
                        '        DATENBANKTextBox.Text & ")));User Id=" & USERNAMETextBox.Text & ";Password=" & PASSWORDTextBox.Text & ";"
                        'Else
                        '    conn.DataSource = DATENBANKTextBox.Text
                        '    conn.UserID = USERNAMETextBox.Text
                        '    conn.Password = PASSWORDTextBox.Text
                        '    conn.PersistSecurityInfo = True
                        '    conn.ConnectionTimeout = 120
                        '    connstr = conn.ConnectionString
                        'End If



                        'Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;Integrated Security=no;

                    Case Else
                        ClassLogger.Add(" - ConnectionType not integrated", False)
                        MsgBox("ConnectionType not integrated", MsgBoxStyle.Critical, "Please check connection:")
                End Select
            End If

        Catch ex As Exception
            ClassLogger.Add(" - Unexpected Error in GetConnectionString:" & vbNewLine & ex.Message)
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error in GetConnectionString:")

        End Try
        Return connectionString
    End Function
    Public Shared Function CleanInput(strIn As String) As String
        ' Replace invalid characters with empty strings.
        Try
            Return Regex.Replace(strIn, "[^\w\.@-]", "")
            ' If we timeout when replacing invalid characters, 
            ' we should return String.Empty.
        Catch e As RegexMatchTimeoutException
            Return String.Empty
        End Try
    End Function
   
End Class
