Refactor function retrieval and add handler for functions tab
Refactored GetMsSqlFunctions to accept multiple types and use SQL IN clause for function retrieval. Added rbFunctionsTb_CheckedChanged event handler to load MS-SQL functions into cmbDataviews and handle unsupported database types.
This commit is contained in:
@@ -796,70 +796,46 @@ Public Class frmNIVerknuepfungen
|
|||||||
Return Nothing
|
Return Nothing
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
Private Function GetMsSqlFunctions(Type As String) As String()
|
Private Function GetMsSqlFunctions(ParamArray types As String()) As String()
|
||||||
Try
|
Try
|
||||||
Dim SqlString As String
|
Dim SqlString As String
|
||||||
Dim DataViews() As String = Nothing
|
Dim DataViews() As String = Nothing
|
||||||
Dim i As Integer = 0
|
Dim i As Integer = 0
|
||||||
|
|
||||||
'Dim ConnectionString As SqlConnectionStringBuilder
|
|
||||||
Dim Connection As SqlConnection
|
Dim Connection As SqlConnection
|
||||||
Dim Command As SqlCommand
|
Dim Command As SqlCommand
|
||||||
Dim DataAdapter As SqlDataAdapter
|
Dim DataAdapter As SqlDataAdapter
|
||||||
Dim DataSet As DataSet = New DataSet()
|
Dim DataSet As DataSet = New DataSet()
|
||||||
|
|
||||||
Dim con As String
|
Dim con As String
|
||||||
' ConnectionString aufbauen
|
|
||||||
If _selectedProfil.UserId = "WINAUTH" Then
|
If _selectedProfil.UserId = "WINAUTH" Then
|
||||||
con = "Data Source=" & _selectedProfil.DataSource & ";Initial Catalog=" & _selectedProfil.InitialCatalog & ";Trusted_Connection=True;"
|
con = "Data Source=" & _selectedProfil.DataSource & ";Initial Catalog=" & _selectedProfil.InitialCatalog & ";Trusted_Connection=True;"
|
||||||
Else
|
Else
|
||||||
con = "Server=" & _selectedProfil.DataSource & ";Database=" & _selectedProfil.InitialCatalog & ";User Id=" & _selectedProfil.UserId & ";Password=" & _selectedProfil.Password & ";"
|
con = "Server=" & _selectedProfil.DataSource & ";Database=" & _selectedProfil.InitialCatalog & ";User Id=" & _selectedProfil.UserId & ";Password=" & _selectedProfil.Password & ";"
|
||||||
End If
|
End If
|
||||||
'ConnectionString = New SqlConnectionStringBuilder()
|
|
||||||
'ConnectionString.DataSource = Me._selectedProfil.DataSource
|
|
||||||
'ConnectionString.UserID = Me._selectedProfil.UserId
|
|
||||||
'ConnectionString.Password = Me._selectedProfil.Password
|
|
||||||
'ConnectionString.InitialCatalog = Me._selectedProfil.InitialCatalog
|
|
||||||
|
|
||||||
' Verbindung zur DB herstellen
|
|
||||||
Connection = New SqlConnection(con)
|
Connection = New SqlConnection(con)
|
||||||
Connection.Open()
|
Connection.Open()
|
||||||
|
|
||||||
' DB-Abfrage für alle Views definieren
|
Dim typeList As String = String.Join("','", types)
|
||||||
SqlString = $"SELECT O.name FROM sys.sql_modules M INNER JOIN sys.objects O ON M.object_id=O.object_id WHERE O.type = '{Type}'"
|
SqlString = $"SELECT O.name FROM sys.sql_modules M INNER JOIN sys.objects O ON M.object_id=O.object_id WHERE O.type IN ('{typeList}')"
|
||||||
|
|
||||||
' die DB-Abfrage erzeugen
|
|
||||||
Command = New SqlCommand(SqlString, Connection)
|
Command = New SqlCommand(SqlString, Connection)
|
||||||
|
|
||||||
' die DB-Abfrage durchführen
|
|
||||||
DataAdapter = New SqlDataAdapter(Command)
|
DataAdapter = New SqlDataAdapter(Command)
|
||||||
|
|
||||||
' das DataSet mit den Daten füllen
|
|
||||||
DataAdapter.Fill(DataSet)
|
DataAdapter.Fill(DataSet)
|
||||||
|
|
||||||
|
|
||||||
If DataSet.Tables(0).Rows.Count > 0 Then
|
If DataSet.Tables(0).Rows.Count > 0 Then
|
||||||
|
|
||||||
Dim tabellenart As String = "FUNCTIONS"
|
|
||||||
|
|
||||||
|
|
||||||
' alle Ergebnisse (VIEWs) durchlaufen
|
|
||||||
For Each row As DataRow In DataSet.Tables(0).Rows
|
For Each row As DataRow In DataSet.Tables(0).Rows
|
||||||
|
|
||||||
If DataViews IsNot Nothing Then ReDim Preserve DataViews(DataViews.Length) Else ReDim DataViews(0)
|
If DataViews IsNot Nothing Then ReDim Preserve DataViews(DataViews.Length) Else ReDim DataViews(0)
|
||||||
' View in Array schreiben
|
|
||||||
DataViews(i) = row.Item(0)
|
DataViews(i) = row.Item(0)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
Next
|
Next
|
||||||
' Array zurückgeben
|
|
||||||
Return DataViews
|
Return DataViews
|
||||||
Else
|
Else
|
||||||
Return Nothing
|
Return Nothing
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
MsgBox("Die MSSQL-Datenansichten der Datenbank konnten nicht fehlerfrei ausgelesen werden." & vbNewLine & vbNewLine & ex.Message, MsgBoxStyle.Exclamation, "Fehler beim Auslesen der Datenansichten MSSQL")
|
MsgBox("Die MSSQL-Datenansichten der Datenbank konnten nicht fehlerfrei ausgelesen werden." & vbNewLine & vbNewLine & ex.Message, MsgBoxStyle.Exclamation, "Fehler beim Auslesen der Datenansichten MSSQL")
|
||||||
Return Nothing
|
Return Nothing
|
||||||
@@ -3747,6 +3723,40 @@ Public Class frmNIVerknuepfungen
|
|||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Private Sub rbFunctionsTb_CheckedChanged(sender As Object, e As EventArgs) Handles rbFunctionsTb.CheckedChanged
|
||||||
|
If Not _flagIgnoreCheckedChanged Then
|
||||||
|
If Me._selectedProfil Is Nothing = False Then
|
||||||
|
Me.cmbDataviews.Items.Clear()
|
||||||
|
|
||||||
|
' View- oder Tabellenliste
|
||||||
|
Dim dataviews() As String = Nothing
|
||||||
|
If Me._selectedProfil.DbArt = "MS-SQL" Then
|
||||||
|
dataviews = Me.GetMsSqlFunctions("TF", "IF")
|
||||||
|
'ElseIf Me._selectedProfil.DbArt = "ODBC" Then
|
||||||
|
' dataviews = Me.GetOdbcDataviews(Me.rbViews.Checked)
|
||||||
|
'ElseIf Me._selectedProfil.DbArt = "OLE (Access)" Then
|
||||||
|
' dataviews = Me.GetOleDataviews(Me.rbViews.Checked)
|
||||||
|
Else
|
||||||
|
MsgBox("Der gewählte Datenbanktyp ist nicht für Funktionen unterstützt.", MsgBoxStyle.Critical, "Unbekannter Datenbanktyp")
|
||||||
|
End If
|
||||||
|
|
||||||
|
If dataviews IsNot Nothing Then
|
||||||
|
|
||||||
|
For Each dataview As String In dataviews
|
||||||
|
Me.cmbDataviews.Items.Add(dataview)
|
||||||
|
Next
|
||||||
|
|
||||||
|
End If
|
||||||
|
|
||||||
|
|
||||||
|
Me.txtSelectAnweisung.Text = ""
|
||||||
|
Else
|
||||||
|
MsgBox("Bitte wählen Sie ein Profil aus!", MsgBoxStyle.Information, "Achtung:")
|
||||||
|
End If
|
||||||
|
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
|
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
|
|||||||
Reference in New Issue
Block a user