diff --git a/Global_Indexer/frmConnections.vb b/Global_Indexer/frmConnections.vb index 8ea3b31..1db217d 100644 --- a/Global_Indexer/frmConnections.vb +++ b/Global_Indexer/frmConnections.vb @@ -369,10 +369,128 @@ Public Class frmConnections Catch ex As Exception MsgBox("Error in Save Connection:" & vbNewLine & ex.Message, MsgBoxStyle.Critical) End Try + 'Catch ex As Exception + + ' Dim oConnectionGuid As Integer + ' oConnectionGuid = CurrentGuid + + ' ' StringBuilder VORHER deklarieren! + ' Dim beingUsedAt As New Text.StringBuilder() + + ' If oConnectionGuid <> 0 Then + ' Dim oSql As String = + ' "SELECT DA.BEZEICHNUNG AS Profil, + ' IM.NAME AS IndexName, + ' 'Manuell' AS IndexTyp + ' FROM TBDD_DOKUMENTART DA (NOLOCK) + ' INNER JOIN TBDD_INDEX_MAN IM + ' ON DA.GUID = IM.DOK_ID + ' WHERE IM.CONNECTION_ID = @connectionGuid + + ' UNION ALL + + ' SELECT DA.BEZEICHNUNG AS Profil, + ' IA.INDEXNAME AS IndexName, + ' 'Automatisch' AS IndexTyp + ' FROM TBDD_DOKUMENTART DA (NOLOCK) + ' INNER JOIN TBDD_INDEX_AUTOM IA + ' ON DA.GUID = IA.DOCTYPE_ID + ' WHERE IA.CONNECTION_ID = @connectionGuid;" + + ' Dim oDataTable As New DataTable() + ' oSql = oSql.Replace("@connectionGuid", oConnectionGuid.ToString) + ' oDataTable = DATABASE_ECM.GetDatatable(oSql) + + ' For Each oRow As DataRow In oDataTable.Rows + ' beingUsedAt.AppendLine($"- Profil: {oRow("Profil")} | {oRow("IndexTyp")}er Index: {oRow("IndexName")}") + ' Next + ' End If + + ' Dim msg As String = "Fehler beim Löschen der SQL-Verbindung:" & vbNewLine & + ' "Die SQL-Verbindung ist noch in Verwendung." + + ' If beingUsedAt.Length > 0 Then + ' msg &= vbNewLine & vbNewLine & "Verwendet in:" & vbNewLine & beingUsedAt.ToString() + ' End If + + ' MsgBox(msg, MsgBoxStyle.Critical) + 'End Try End Sub Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick - TBDD_CONNECTIONBindingSource.RemoveCurrent() + + Dim oCurrentRow As DataRowView = TryCast(TBDD_CONNECTIONBindingSource.Current, DataRowView) + Dim oConnectionGuid As Integer + If oCurrentRow IsNot Nothing AndAlso oCurrentRow("GUID") IsNot DBNull.Value Then + oConnectionGuid = oCurrentRow("GUID") + End If + + ' StringBuilder VORHER deklarieren! + Dim oBeingUsedAt As New Text.StringBuilder() + Dim oAppJobExist As Integer = 0 + + If oConnectionGuid <> 0 Then + Dim oSql As String = " + SELECT DA.BEZEICHNUNG AS Profil, + IM.NAME AS IndexName, + 'Manuell' AS IndexTyp + FROM TBDD_DOKUMENTART DA (NOLOCK) + INNER JOIN TBDD_INDEX_MAN IM + ON DA.GUID = IM.DOK_ID + WHERE IM.CONNECTION_ID = @connectionGuid + + UNION ALL + + SELECT DA.BEZEICHNUNG AS Profil, + IA.INDEXNAME AS IndexName, + 'Automatisch' AS IndexTyp + FROM TBDD_DOKUMENTART DA (NOLOCK) + INNER JOIN TBDD_INDEX_AUTOM IA + ON DA.GUID = IA.DOCTYPE_ID + WHERE IA.CONNECTION_ID = @connectionGuid;" + + Dim oDataTable As New DataTable() + oSql = oSql.Replace("@connectionGuid", oConnectionGuid.ToString) + oDataTable = DATABASE_ECM.GetDatatable(oSql) + + For Each oRow As DataRow In oDataTable.Rows + oBeingUsedAt.AppendLine($"- Profil: {oRow("Profil")} | {oRow("IndexTyp")}er Index: {oRow("IndexName")}") + Next + + Dim oSql2 As String = " + IF (EXISTS (SELECT * FROM [INFORMATION_SCHEMA].[TABLES] (NOLOCK) WHERE [TABLE_NAME] = 'TBAPPSERV_CRON_DETAIL')) BEGIN + SELECT Count(CD.DT_NAME) + FROM TBAPPSERV_CRON_DETAIL AS CD + INNER JOIN TBDD_CONNECTION AS CO + ON CD.CON_ID = CO.GUID + WHERE CON_ID = @connectionGuid + END; ELSE BEGIN + SELECT 0 + END;" + + oSql2 = oSql2.Replace("@connectionGuid", oConnectionGuid.ToString) + oAppJobExist = DATABASE_ECM.GetScalarValue(oSql2) + + End If + + Dim oMsg As String = "SQL-Verbindung kann nicht gelöscht werden:" & vbNewLine & vbNewLine & + "Die SQL-Verbindung ist noch in Verwendung." & vbNewLine + + If oBeingUsedAt.Length = 0 AndAlso oAppJobExist = 0 Then + TBDD_CONNECTIONBindingSource.RemoveCurrent() + Exit Sub + End If + + If oBeingUsedAt.Length > 0 Then + oMsg &= vbNewLine & vbNewLine & "Verwendet in:" & vbNewLine & oBeingUsedAt.ToString() + End If + + If oAppJobExist > 0 Then + oMsg &= vbNewLine & vbNewLine & "Verwendet in:" & vbNewLine & oAppJobExist.ToString() & " Cron Details" + End If + + MsgBox(oMsg, MsgBoxStyle.Critical) + End Sub Private Sub BarButtonItem5_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem5.ItemClick