From 4daff8ad250be50dd61e687eb6655034ee7e327d Mon Sep 17 00:00:00 2001 From: OlgunR Date: Mon, 16 Mar 2026 11:28:14 +0100 Subject: [PATCH] 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. --- ToolCollection/frmNIVerknuepfungen.vb | 66 +++++++++++++++------------ 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/ToolCollection/frmNIVerknuepfungen.vb b/ToolCollection/frmNIVerknuepfungen.vb index 2577ffc..c78f59d 100644 --- a/ToolCollection/frmNIVerknuepfungen.vb +++ b/ToolCollection/frmNIVerknuepfungen.vb @@ -796,70 +796,46 @@ Public Class frmNIVerknuepfungen Return Nothing End Try End Function - Private Function GetMsSqlFunctions(Type As String) As String() + Private Function GetMsSqlFunctions(ParamArray types As String()) As String() Try Dim SqlString As String Dim DataViews() As String = Nothing Dim i As Integer = 0 - 'Dim ConnectionString As SqlConnectionStringBuilder Dim Connection As SqlConnection Dim Command As SqlCommand Dim DataAdapter As SqlDataAdapter Dim DataSet As DataSet = New DataSet() Dim con As String - ' ConnectionString aufbauen If _selectedProfil.UserId = "WINAUTH" Then con = "Data Source=" & _selectedProfil.DataSource & ";Initial Catalog=" & _selectedProfil.InitialCatalog & ";Trusted_Connection=True;" Else con = "Server=" & _selectedProfil.DataSource & ";Database=" & _selectedProfil.InitialCatalog & ";User Id=" & _selectedProfil.UserId & ";Password=" & _selectedProfil.Password & ";" 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.Open() - ' DB-Abfrage für alle Views definieren - 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}'" + 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 IN ('{typeList}')" - ' die DB-Abfrage erzeugen Command = New SqlCommand(SqlString, Connection) - - ' die DB-Abfrage durchführen DataAdapter = New SqlDataAdapter(Command) - - ' das DataSet mit den Daten füllen DataAdapter.Fill(DataSet) - 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 - If DataViews IsNot Nothing Then ReDim Preserve DataViews(DataViews.Length) Else ReDim DataViews(0) - ' View in Array schreiben DataViews(i) = row.Item(0) i += 1 - - Next - ' Array zurückgeben + Return DataViews Else Return Nothing End If - 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") Return Nothing @@ -3747,6 +3723,40 @@ Public Class frmNIVerknuepfungen End If 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 End Sub