Imports System.ComponentModel
Imports System.Text.RegularExpressions

Public Class frmAdministration
    Public Shared _Namenkonvention As String
    Public Shared _aktDokart_Id As Integer

    Private GroupToDelete As Integer = Nothing

    Private IsInsert As Boolean = False
    Dim frmloaded As Boolean = False
    Private Sub TBDD_DOKUMENTARTBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TBDD_DOKUMENTARTBindingNavigatorSaveItem.Click
        Save_Dokumentart()
    End Sub

    Private Sub frmAdministration_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: Diese Codezeile lädt Daten in die Tabelle "MyDataset.TBGI_REGEX_DOCTYPE". Sie können sie bei Bedarf verschieben oder entfernen.

        'TODO: Diese Codezeile lädt Daten in die Tabelle "MyDataset.TBDD_USER_GROUPS". Sie können sie bei Bedarf verschieben oder entfernen.
        Try
            ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
            Me.TBDD_DOKUMENTARTTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBDD_EINGANGSARTENTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBDD_MODULESTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBDD_DOKART_MODULETableAdapter.Connection.ConnectionString = MyConnectionString
            TBDD_INDEX_MANTableAdapter.Connection.ConnectionString = MyConnectionString
            TBDD_INDEX_AUTOMTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBDD_USERTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBGI_CONFIGURATIONTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBGI_OBJECTTYPE_EMAIL_INDEXTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBDD_INDEX_MAN_POSTPROCESSINGTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBWHDD_INDEX_MANTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBDD_GROUPSTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.VWGI_USER_GROUPS_RELATIONTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBDD_GROUPS_USERTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.VWGI_DOCTYPE_GROUPTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBGI_REGEX_DOCTYPETableAdapter.Connection.ConnectionString = MyConnectionString
        Catch ex As Exception
            MsgBox("Error in load Connection-Strings - Check Database Connection - Form will be closed: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
            Me.Close()
        End Try

        XtraTabControl1.SelectedTabPageIndex = 0
        ToolStripComboBox1.SelectedIndex = 0
        Try
            Me.TBDD_EINGANGSARTENTableAdapter.Fill(Me.MyDataset.TBDD_EINGANGSARTEN)
            Me.TBDD_MODULESTableAdapter.Fill(Me.MyDataset.TBDD_MODULES)
            Me.TBGI_REGEX_DOCTYPETableAdapter.Fill(Me.MyDataset.TBGI_REGEX_DOCTYPE)
        Catch ex As Exception
            MsgBox("Error in frmAdministration_Load: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try
        If GI_withWindream = True Then
            If ClassWindream.Init() = True Then

            End If
        End If
    End Sub
    Private Sub ObjektTypenEintragen()
        Try
            Dim oDokumentTyp As WINDREAMLib.WMObject
            ' Combobox leeren
            Me.OBJEKTTYPComboBox.Items.Clear()
            ' alle Objekttypen durchlaufen
            For Each oDokumentTyp In ClassWindream.GetObjecttypesAsObjects
                ' und in die Combobox eintragen
                Me.OBJEKTTYPComboBox.Items.Add(oDokumentTyp.aName)
            Next
        Catch ex As Exception
            MsgBox("Fehlernachricht:" & vbNewLine & ex.Message, MsgBoxStyle.Critical, "Unexpected error inm Eintragen der Objekttypen")
        End Try

    End Sub
    Sub Load_Dokart(Type As String)
        Try
            '* Me.TBDD_DOKUMENTARTTableAdapter.Connection.ConnectionString = MyConnectionString
            If Type = "Global-Indexer Dokarten" Then
                Me.TBDD_DOKUMENTARTTableAdapter.FillByModuleGI(Me.MyDataset.TBDD_DOKUMENTART)
            Else
                Me.TBDD_DOKUMENTARTTableAdapter.Fill(Me.MyDataset.TBDD_DOKUMENTART)
            End If
            If MyDataset.TBDD_DOKUMENTART.Rows.Count > 0 Then
                enableControls(XtraTabPage1)
            End If
            If Me.DOKART_GUIDTextBox.Text <> "" Then
                Load_TabData()
            End If
        Catch ex As Exception
            MsgBox("Error in Load_Dokart: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try
    End Sub
    Sub Load_TabData()
        If frmloaded = False Then
            Exit Sub
        End If
        Select Case XtraTabControl2.SelectedTabPageIndex
            Case 0
                If DOKART_GUIDTextBox.Text <> "" Then
                    Load_INDEXMAN(Me.DOKART_GUIDTextBox.Text)
                End If
            Case 1
                Load_PostProcessing(Me.DOKART_GUIDTextBox.Text)
            Case 2
                Load_INDEXE_AUTO(Me.DOKART_GUIDTextBox.Text)
            Case 3
                Load_UserGroups()
                Load_DokartZuordnung(DOKART_GUIDTextBox.Text)
            Case 4
                Try
                    Dim Dt As DataTable = ClassDatabase.Return_Datatable("select NAME from VWDDINDICES_MAN_AUTO_ACTIVE where DOCTYPE_ID = " & DOKART_GUIDTextBox.Text & " order by NAME")
                    cmbCrFolderIndex.DataSource = Dt
                    cmbCrFolderIndex.DisplayMember = Dt.Columns(0).ColumnName
                Catch ex As Exception
                    MsgBox("Error in Load Data TabData 4: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
                End Try

        End Select
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'First create a FolderBrowserDialog object
        Dim FolderBrowserDialog1 As New FolderBrowserDialog
        ' Then use the following code to create the Dialog window
        ' Change the .SelectedPath property to the default location
        With FolderBrowserDialog1
            If ZIEL_PFADTextBox.Text <> "" Then
                .SelectedPath = ZIEL_PFADTextBox.Text
            End If
            ' Desktop is the root folder in the dialog.
            '.RootFolder = Environment.SpecialFolder.Desktop
            ' Prompt the user with a custom message.
            If USER_LANGUAGE = "de-DE" Then
                .Description = "Zielordner für Dokumentart wählen:"
            Else
                .Description = "Choose destination folder for Documenttype:"
            End If

            If .ShowDialog = DialogResult.OK Then
                Dim Path As String = .SelectedPath
                ZIEL_PFADTextBox.Text = .SelectedPath
            End If
        End With
    End Sub
    Sub Save_Dokumentart()
        Try
            Try
                Me.TBDD_DOKUMENTARTBindingSource.EndEdit()
            Catch ex As Exception
                If ex.Message.StartsWith("Der interne Datatable") Then
                    Save_Dokumentart()
                Else
                    MsgBox("Error in EndEdit 1 documenttype: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
                End If
            End Try

            If MyDataset.TBDD_DOKUMENTART.GetChanges Is Nothing = False Then
                Me.GEANDERTWERTextBox.Text = Environment.UserName
                Try
                    Me.TBDD_DOKUMENTARTBindingSource.EndEdit()
                Catch ex As Exception
                    If ex.Message.StartsWith("Der interne Datatable") Then
                        Save_Dokumentart()
                    Else
                        MsgBox("Error in EndEdit 2 documenttype: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
                    End If
                End Try
                TBDD_DOKUMENTARTTableAdapter.Update(MyDataset.TBDD_DOKUMENTART)
                lblSaveDokart.Visible = True
                If IsInsert = True Then
                    Dim oNewID As Integer
                    oNewID = ClassDatabase.Execute_Scalar("SELECT MAX(GUID) FROM TBDD_DOKUMENTART", MyConnectionString)
                    If IsNumeric(oNewID) Then
                        Dim osql = $" EXEC PRDD_CHECK_REL_DOCTYPE_MODULE 'GLOBIX',{oNewID}"
                        ClassDatabase.Execute_non_Query(osql)
                    End If

                End If
            Else
                lblSaveDokart.Visible = False
            End If
            IsInsert = False
        Catch ex As Exception
            MsgBox("Error in Save_Dokumentart: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try

    End Sub
    Private Sub btnNamenkonvention_Click(sender As Object, e As EventArgs) Handles btnNamenkonvention.Click
        Save_Dokumentart()
        Dim _temp As String
        _temp = Me.NAMENKONVENTIONTextBox.Text
        _Namenkonvention = Me.NAMENKONVENTIONTextBox.Text
        _aktDokart_Id = DOKART_GUIDTextBox.Text
        frmNamenkonvention.ShowDialog()
        Me.NAMENKONVENTIONTextBox.Text = _Namenkonvention
        If _temp <> NAMENKONVENTIONTextBox.Text Then
            Save_Dokumentart()
        End If
    End Sub

    Private Sub TBDD_DOKUMENTARTBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles TBDD_DOKUMENTARTBindingSource.CurrentChanged
        lblSaveDokart.Visible = False
        If DOKART_GUIDTextBox.Text <> String.Empty Then
            CURRENT_DOKART_ID = DOKART_GUIDTextBox.Text
            Load_TabData()
        End If

    End Sub

    Private Sub ToolStripComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ToolStripComboBox1.SelectedIndexChanged
        Load_Dokart(ToolStripComboBox1.Text)
    End Sub

    Private Sub TBDD_DOKUMENTARTBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBDD_DOKUMENTARTBindingSource.AddingNew
        Save_Dokumentart()
        Try
            Dim sql = "SELECT COUNT(T.GUID) FROM TBDD_DOKUMENTART T, TBDD_DOKUMENTART_MODULE T1 WHERE T.AKTIV = 1 AND T.GUID = T1.DOKART_ID AND T1.MODULE_ID = 1"
            Dim DoctypeCount = ClassDatabase.Execute_Scalar(sql, MyConnectionString, True)
            If DoctypeCount = LICENSE_DOCTYPE_COUNT Then
                If USER_LANGUAGE = "de-DE" Then
                    MsgBox("Ihre Anzahl von konfigurierbaren Dokuemntarten ist limitiert auf: '" & LICENSE_DOCTYPE_COUNT.ToString & "'. Sie können nun keine Dokumentart hinzufügen!" & vbNewLine & "Bitte kontaktieren Sie Digital Data für weitere Details.", MsgBoxStyle.Information)
                Else
                    MsgBox("Your amount of configurable documenttypes is limited to " & LICENSE_DOCTYPE_COUNT.ToString & " doctypes. You can not add more doctypes!" & vbNewLine & "Please contact Digital Data for further licensedetails", MsgBoxStyle.Information)
                End If
                Exit Sub
            End If
        Catch ex As Exception
            MsgBox("Unexpected error in Add Doctype: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try

        MyDataset.TBDD_DOKUMENTART.ERSTELLTWERColumn.DefaultValue = Environment.UserName
        MyDataset.TBDD_DOKUMENTART.OBJEKTTYPColumn.DefaultValue = ""
        IsInsert = True
    End Sub

    Private Sub Load_ZuordnungDokart_Module(Dokart As Integer)
        Try
            Me.TBDD_DOKART_MODULETableAdapter.Fill(Me.MyDataset.TBDD_DOKART_MODULE, Dokart)
        Catch ex As System.Exception
            MsgBox("Error in Load Zuordnung_Dokart: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try

    End Sub
    Private Sub btnadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click

        Dim osql = $" EXEC PRDD_CHECK_REL_DOCTYPE_MODULE 'GLOBIX',{DOKART_GUIDTextBox.Text}"
        ClassDatabase.Execute_non_Query(osql)
        LoadGlobix_Doctypes()
    End Sub

    Private Sub OBJEKTTYPComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles OBJEKTTYPComboBox.SelectedIndexChanged
        If WINDREAM_DIRECTCheckBox.Checked = True Then
            load_WDIndices()
        End If


    End Sub
    Sub load_WDIndices()
        Try
            If Me.OBJEKTTYPComboBox.SelectedIndex <> -1 Then
                Me.WD_INDEXComboBox.Items.Clear()
                Me.WD_INDEXComboBox.Items.Add("")
                Dim indexe = ClassWindream.GetIndicesByObjecttype(OBJEKTTYPComboBox.Text)
                If indexe IsNot Nothing Then
                    For Each index As String In indexe
                        Me.WD_INDEXComboBox.Items.Add(index)
                    Next
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in load_WDIndices: ")
        End Try
    End Sub
    Sub load_WDIndices2AutoIndizes()
        Try
            If Me.OBJEKTTYPComboBox.SelectedIndex <> -1 Then
                Me.INDEXNAME_AutoIndexCMB.Items.Clear()
                Dim indexe = ClassWindream.GetIndicesByObjecttype(OBJEKTTYPComboBox.Text)
                If indexe IsNot Nothing Then
                    For Each index As String In indexe
                        Me.INDEXNAME_AutoIndexCMB.Items.Add(index)
                    Next
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in load_WDIndices2AutoIndizes: ")
        End Try
    End Sub
    Private Sub frmAdministration_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        If DOKART_GUIDTextBox.Text <> "" Then
            Load_Dokart("Global-Indexer Dokarten")
            'Load_INDEXMAN(Me.DOKART_GUIDTextBox.Text)
            Load_ZuordnungDokart_Module(DOKART_GUIDTextBox.Text)
            If SUGGESTIONCheckBox.CheckState = CheckState.Checked Then
                btnSQLView.Visible = True
            Else
                btnSQLView.Visible = False
            End If
            Load_INDEXMAN(Me.DOKART_GUIDTextBox.Text)
        End If
        frmloaded = True
        tscmbUser.SelectedIndex = 0
        TBDD_INDEX_MANBindingNav.Visible = True
        TBDD_INDEX_MANBindingNav.Visible = True
        WM_CHECKED_CHANGE()
    End Sub

    Private Sub btndeleteZuordnung_Click(sender As Object, e As EventArgs) Handles btndeleteZuordnung.Click
        Try
            If Not ListBox2.SelectedValue Is Nothing Then
                Dim cmd As String = "Delete from TBDD_DOKUMENTART_MODULE where GUID = " & ListBox2.SelectedValue
                ClassDatabase.Execute_non_Query(cmd, True)
                Load_ZuordnungDokart_Module(DOKART_GUIDTextBox.Text)
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Delete Zuordnung: ")
        End Try

    End Sub

    Private Sub Load_INDEXMAN(DA_ID As Integer)
        Try
            Me.TBDD_INDEX_MANTableAdapter.Fill(Me.MyDataset.TBDD_INDEX_MAN, DA_ID)
            If MyDataset.TBDD_INDEX_MAN.Rows.Count > 0 Then
                enableControls(XtraTabPage3)
            End If
            lblSaveIndexMan.Visible = False
        Catch ex As System.Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Load IndexeManuell: ")
        End Try

    End Sub
    Private Sub Load_INDEXE_AUTO(DA_ID As Integer)
        Try
            Me.TBDD_INDEX_AUTOMTableAdapter.Fill(Me.MyDataset.TBDD_INDEX_AUTOM, DA_ID)
            If MyDataset.TBDD_INDEX_AUTOM.Rows.Count > 0 Then
                enableControls(XtraTabPage4)
            End If
            CheckIndexAutoWD()
        Catch ex As System.Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Load Indexe Auto: ")
        End Try

    End Sub
    Private Sub Load_PostProcessing(DA_ID As Integer)
        Try
            Me.TBWHDD_INDEX_MANTableAdapter.Fill(Me.MyDataset.TBWHDD_INDEX_MAN, DA_ID)
            Me.TBDD_INDEX_MAN_POSTPROCESSINGTableAdapter.Fill(Me.MyDataset.TBDD_INDEX_MAN_POSTPROCESSING, DA_ID)
            If MyDataset.TBDD_INDEX_MAN_POSTPROCESSING.Rows.Count > 0 Then
                enableControls(XtraTabPage6)
            End If
            lblsavePostProcess.Visible = False
        Catch ex As System.Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Load Postprocessing-Values: ")
        End Try

    End Sub


    Sub CheckIndexAutoWD()
        If WINDREAM_DIRECTCheckBox.Checked = True Then
            INDEXNAME_AutoIndexTXT.Visible = False
            load_WDIndices2AutoIndizes()
            INDEXNAME_AutoIndexCMB.Visible = True
        Else
            INDEXNAME_AutoIndexTXT.Visible = True
            INDEXNAME_AutoIndexCMB.Visible = False
        End If
    End Sub
    Private Sub TBDD_INDEX_MANBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBDD_INDEX_MANBindingSource.AddingNew
        Try
            Save_Dokumentart()
            IsInsert = True
            MyDataset.TBDD_INDEX_MAN.ADDED_WHOColumn.DefaultValue = Environment.UserName
            MyDataset.TBDD_INDEX_MAN.DOK_IDColumn.DefaultValue = Me.DOKART_GUIDTextBox.Text
            enableControls(XtraTabPage3)
            If GI_withWindream = True Then
                Load_INDEXMAN(Me.DOKART_GUIDTextBox.Text)
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Add IndexMan: ")
        End Try

    End Sub

    Private Sub ToolStripButton7_Click(sender As Object, e As EventArgs) Handles ToolStripButton7.Click
        Save_IndexMan()
    End Sub
    Sub Save_IndexMan()
        Try
            Me.TBDD_INDEX_MANBindingSource.EndEdit()
            If MyDataset.TBDD_INDEX_MAN.GetChanges Is Nothing = False Then
                CHANGED_WHOTextBox.Text = Environment.UserName
                Me.TBDD_INDEX_MANBindingSource.EndEdit()
                TBDD_INDEX_MANTableAdapter.Update(MyDataset.TBDD_INDEX_MAN)
                lblSaveIndexMan.Visible = True
            Else
                lblSaveIndexMan.Visible = False
            End If
            IsInsert = False
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Save Man Index: ")
        End Try
    End Sub
    Sub Save_IndexAuto()
        Try
            Me.TBDD_INDEX_AUTOMBindingSource.EndEdit()
            If MyDataset.TBDD_INDEX_AUTOM.GetChanges Is Nothing = False Then
                CHANGED_WHOTextBox3.Text = Environment.UserName
                Me.TBDD_INDEX_AUTOMBindingSource.EndEdit()
                TBDD_INDEX_AUTOMTableAdapter.Update(MyDataset.TBDD_INDEX_AUTOM)
                lblsaveAutoIndex.Visible = True
            Else
                lblsaveAutoIndex.Visible = False
            End If
            IsInsert = False
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Save Auto Index: ")
        End Try
    End Sub

    Private Sub TBDD_INDEX_MANBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles TBDD_INDEX_MANBindingSource.CurrentChanged
        lblSaveIndexMan.Visible = False
    End Sub

    Private Sub SUGGESTIONCheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles SUGGESTIONCheckBox.CheckedChanged
        If frmloaded = True Then
            If SUGGESTIONCheckBox.CheckState = CheckState.Checked Then
                btnSQLView.Visible = True
                MULTISELECTCheckBox.Visible = True
                VKT_ADD_ITEMCheckbox.Visible = True

            Else
                btnSQLView.Visible = False
                MULTISELECTCheckBox.Visible = False
                VKT_ADD_ITEMCheckbox.Visible = False

                'If (_indexIsVectorField) Then
                '    VKT_ADD_ITEMCheckbox.Enabled = True
                'Else
                '    VKT_ADD_ITEMCheckbox.Enabled = False
                'End If
            End If
        End If
    End Sub

    Private Sub ToolStripButton15_Click(sender As Object, e As EventArgs) Handles ToolStripButton15.Click
        If tscmbUser.SelectedIndex = 1 Then
            Refresh_User(True)
        Else
            Refresh_User(False)
        End If

    End Sub
    Sub Refresh_User(All As Boolean)
        Try
            If All = True Then
                Me.TBDD_USERTableAdapter.FillByAll(Me.MyDataset.TBDD_USER)
            Else
                Me.TBDD_USERTableAdapter.Fill(Me.MyDataset.TBDD_USER)
            End If
            If MyDataset.TBDD_USER.Rows.Count > 0 Then
                enableControls(XtraTabPage2)
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Refresh_User: ")
        End Try
    End Sub

    Private Sub XtraTabControl1_SelectedPageChanged(sender As Object, e As DevExpress.XtraTab.TabPageChangedEventArgs) Handles XtraTabControl1.SelectedPageChanged
        Select Case XtraTabControl1.SelectedTabPageIndex
            Case 0
                If DOKART_GUIDTextBox.Text <> "" Then
                    Load_ZuordnungDokart_Module(DOKART_GUIDTextBox.Text)
                End If
            Case 1
                If tscmbUser.SelectedIndex = 1 Then
                    Refresh_User(True)
                Else
                    Refresh_User(False)
                End If
                If USER_GUIDTextBox.Text <> "" Then
                    Load_UserRelation(USER_GUIDTextBox.Text)
                End If

                Load_UserGroups()
            Case 2
                ObjektTypenListBoxEintragen()
            Case 3
                Me.TBGI_REGEX_DOCTYPETableAdapter.Fill(Me.MyDataset.TBGI_REGEX_DOCTYPE)
                Dim osql = "SELECT GUID, BEZEICHNUNG FROM TBDD_DOKUMENTART WHERE (GUID IN (SELECT T.DOKART_ID FROM TBDD_DOKUMENTART_MODULE AS T INNER JOIN " &
                    "TBDD_MODULES AS T1 ON T.MODULE_ID = T1.GUID WHERE (T1.NAME = 'Global-Indexer'))) ORDER BY SEQUENCE, BEZEICHNUNG"
                Dim oDT As DataTable = ClassDatabase.Return_Datatable(osql)
                If Not IsNothing(oDT) Then
                    cmbDoctypeRegex.DataSource = oDT
                    cmbDoctypeRegex.ValueMember = "GUID"
                    cmbDoctypeRegex.DisplayMember = "BEZEICHNUNG"
                End If
        End Select

    End Sub
    Sub load_WDIndicesemail(Otype As String)
        Try
            IDX_EMAIL_DATE_INComboBox.Items.Clear()
            IDX_EMAIL_FROMComboBox.Items.Clear()
            IDX_EMAIL_IDComboBox.Items.Clear()
            IDX_EMAIL_SUBJECTComboBox.Items.Clear()
            IDX_EMAIL_TOComboBox.Items.Clear()
            IDX_CHECK_ATTACHMENTComboBox.Items.Clear()
            Dim indexe = ClassWindream.GetIndicesByObjecttype(Otype)
            If indexe IsNot Nothing Then
                For Each index As String In indexe
                    Select Case ClassWindream.GetTypeOfIndexAsIntByName(index)
                        Case 4 'Boolean
                            Me.IDX_CHECK_ATTACHMENTComboBox.Items.Add(index)
                        Case Else
                            Me.IDX_EMAIL_DATE_INComboBox.Items.Add(index)
                            Me.IDX_EMAIL_FROMComboBox.Items.Add(index)
                            Me.IDX_EMAIL_IDComboBox.Items.Add(index)
                            Me.IDX_EMAIL_SUBJECTComboBox.Items.Add(index)
                            Me.IDX_EMAIL_TOComboBox.Items.Add(index)
                    End Select


                Next
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in load_WDIndicesemail: ")
        End Try
    End Sub
    Private Sub ObjektTypenListBoxEintragen()
        Try
            Dim oDokumentTyp As WINDREAMLib.WMObject
            ' Combobox leeren
            Me.ListBoxObjekttypen.Items.Clear()
            ' alle Objekttypen durchlaufen
            For Each oDokumentTyp In ClassWindream.GetObjecttypesAsObjects
                ' und in die Combobox eintragen
                Me.ListBoxObjekttypen.Items.Add(oDokumentTyp.aName)
            Next
        Catch ex As Exception
            MsgBox("Error in ObjektTypenListBoxEintragen:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
            ClassLogger.Add(">> ACHTUNG: Error in ObjektTypenListBoxEintragen - " & ex.Message, False)
        End Try

    End Sub

    Private Sub btnSQLView_Click(sender As Object, e As EventArgs) Handles btnSQLView.Click
        Save_IndexMan()
        'CURRENT_INDEXMAN = GUIDTextBox1.Text
        'frmSQLSuggestion.ShowDialog()

        Dim oIndexGuid As Integer = GUIDTextBox1.Text
        Dim oDocTypeGuid As Integer = DOKART_GUIDTextBox.Text
        Dim oSQLCommand = ""

        Try
            Dim oSQL = $"SELECT SQL_RESULT, CONNECTION_ID FROM TBDD_INDEX_MAN WHERE GUID = {oIndexGuid}"
            Dim oDatatable As DataTable = ClassDatabase.Return_Datatable(oSQL)
            Dim oRow = oDatatable.Rows.Item(0)
            Dim oConnection As Integer = 1

            If Not IsDBNull(oRow.Item("CONNECTION_ID")) Then
                oConnection = oRow.Item("CONNECTION_ID")
            End If

            Dim oForm As New frmSQL_DESIGNER(oIndexGuid, oDocTypeGuid) With {
                .SQLCommand = oRow.Item("SQL_RESULT"),
                .ConnectionID = oConnection
            }

            If oForm.ShowDialog() = DialogResult.OK Then

                oSQLCommand = oForm.SQLCommand.Replace("'", "''")
                Dim oConnectionId = oForm.SQLConnectionId

                oSQL = $"UPDATE TBDD_INDEX_MAN SET CONNECTION_ID = {oConnectionId},SQL_RESULT = '{oSQLCommand}',CHANGED_WHO = '{Environment.UserName}' WHERE GUID = {oIndexGuid}"
                ClassDatabase.Execute_non_Query(oSQL, True)

            End If
        Catch ex As Exception
            LOGGER.Error(ex)
        End Try
    End Sub

    Private Sub WINDREAM_DIRECTCheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles WINDREAM_DIRECTCheckBox.CheckedChanged
        WM_CHECKED_CHANGE()
    End Sub
    Sub WM_CHECKED_CHANGE()
        If WINDREAM_DIRECTCheckBox.Checked Then
            OBJEKTTYPComboBox.Visible = True
            lblObjekttyp.Visible = True
            WD_INDEXComboBox.Visible = True
            lblWDINDEX.Visible = True
            If ClassWindream.Init() = True Then
                ObjektTypenEintragen()
            End If
        Else
            OBJEKTTYPComboBox.Visible = False
            lblObjekttyp.Visible = False
            lblWDINDEX.Visible = False
            WD_INDEXComboBox.Visible = False
        End If
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs)
        ClassWindream.GetSystemIndices("")
    End Sub

    Private Sub LoadIDXEmail(Otype As String)
        Try
            Me.TBGI_OBJECTTYPE_EMAIL_INDEXTableAdapter.Fill(Me.MyDataset.TBGI_OBJECTTYPE_EMAIL_INDEX, Otype)
        Catch ex As System.Exception
            MsgBox("Error in LoadIDXEmail:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try

    End Sub

    Private Sub ListBoxObjekttypen_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBoxObjekttypen.SelectedIndexChanged
        If ListBoxObjekttypen.SelectedIndex <> -1 Then
            pnlObjekttype_Config.Enabled = True
            LoadIDXEmail(ListBoxObjekttypen.SelectedItem)
            load_WDIndicesemail(ListBoxObjekttypen.SelectedItem)
            lblsavezuordnungIndex.Visible = False
        End If
    End Sub

    Private Sub btnidxemail_add_Click(sender As Object, e As EventArgs) Handles btnidxemail_add.Click
        pnlObjekttype_Config.Enabled = True
        Me.TBGI_OBJECTTYPE_EMAIL_INDEXBindingSource.AddNew()
    End Sub

    Private Sub TBGI_OBJECTTYPE_EMAIL_INDEXBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBGI_OBJECTTYPE_EMAIL_INDEXBindingSource.AddingNew
        If ListBoxObjekttypen.SelectedIndex <> -1 Then
            MyDataset.TBGI_OBJECTTYPE_EMAIL_INDEX.ADDED_WHOColumn.DefaultValue = Environment.UserName
            MyDataset.TBGI_OBJECTTYPE_EMAIL_INDEX.OBJECTTYPEColumn.DefaultValue = ListBoxObjekttypen.SelectedItem
        End If
    End Sub

    Private Sub btnidxemail_Save_Click(sender As Object, e As EventArgs) Handles btnidxemail_Save.Click
        Try
            Me.TBGI_OBJECTTYPE_EMAIL_INDEXBindingSource.EndEdit()
            If MyDataset.TBGI_OBJECTTYPE_EMAIL_INDEX.GetChanges Is Nothing = False Then
                CHANGED_WHOTextBox2.Text = Environment.UserName
                TBGI_OBJECTTYPE_EMAIL_INDEXBindingSource.EndEdit()
                TBGI_OBJECTTYPE_EMAIL_INDEXTableAdapter.Update(MyDataset.TBGI_OBJECTTYPE_EMAIL_INDEX)
                lblsavezuordnungIndex.Visible = True
            Else
                lblsavezuordnungIndex.Visible = False
            End If
        Catch ex As Exception
            MsgBox("Error in Save Index-Email:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Private Sub XtraTabControl2_SelectedPageChanged(sender As Object, e As DevExpress.XtraTab.TabPageChangedEventArgs) Handles XtraTabControl2.SelectedPageChanged
        Load_TabData()
    End Sub
    Private Sub ToolStripButton22_Click(sender As Object, e As EventArgs) Handles ToolStripButton22.Click
        Save_IndexAuto()
    End Sub

    Private Sub TBDD_INDEX_AUTOMBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBDD_INDEX_AUTOMBindingSource.AddingNew
        Try
            Save_Dokumentart()
            MyDataset.TBDD_INDEX_AUTOM.ADDED_WHOColumn.DefaultValue = Environment.UserName
            MyDataset.TBDD_INDEX_AUTOM.DOCTYPE_IDColumn.DefaultValue = Me.DOKART_GUIDTextBox.Text
            enableControls(XtraTabPage4)
            IsInsert = True
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Add IndexeAuto: ")
        End Try

    End Sub

    Private Sub TBDD_INDEX_AUTOMBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles TBDD_INDEX_AUTOMBindingSource.CurrentChanged
        CheckIndexAutoWD()
        lblsaveAutoIndex.Visible = False
    End Sub

    Private Sub SQL_ACTIVECheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles SQL_ACTIVECheckBox.CheckedChanged
        If frmloaded = True Then
            If SQL_ACTIVECheckBox.CheckState = CheckState.Checked Then
                btnSQLViewAuto.Visible = True
                lblValue.Visible = False
                VALUETextBox.Visible = False
                VALUETextBox.Text = ""
                lblWindowParameter.Visible = False
                lbFileparameter.Visible = False
                btnAddWindowsVariable.Visible = False
            Else
                lblValue.Visible = True
                VALUETextBox.Visible = True
                VALUETextBox.Text = ""
                btnSQLViewAuto.Visible = False
                lblWindowParameter.Visible = True
                lbFileparameter.Visible = True
                btnAddWindowsVariable.Visible = True
            End If
            If IsInsert = False Then
                Save_IndexAuto()
            End If
        End If
    End Sub

    Private Sub btnSQLViewAuto_Click(sender As Object, e As EventArgs) Handles btnSQLViewAuto.Click
        Save_IndexAuto()
        CURRENT_DOKART_ID = DOKART_GUIDTextBox.Text
        CURRENT_INDEXAUTO = GUIDAUTO_INDEXTextbox.Text
        CURRENT_SQL_CONFIG = "AUTO"
        'SQLConfigAutoIndex.ShowDialog()

        Dim oIndexGuid As Integer = GUIDAUTO_INDEXTextbox.Text
        Dim oDocTypeGuid As Integer = DOKART_GUIDTextBox.Text
        Dim oSQLCommand = ""

        Try
            Dim oSQL = $"SELECT SQL_RESULT, CONNECTION_ID FROM TBDD_INDEX_AUTOM WHERE GUID = {oIndexGuid}"
            Dim oDatatable As DataTable = ClassDatabase.Return_Datatable(oSQL)
            Dim oRow = oDatatable.Rows.Item(0)
            Dim oConnection As Integer = 1

            If Not IsDBNull(oRow.Item("CONNECTION_ID")) Then
                oConnection = oRow.Item("CONNECTION_ID")
            End If

            Dim oForm As New frmSQL_DESIGNER(oIndexGuid, oDocTypeGuid) With {
                .SQLCommand = oRow.Item("SQL_RESULT"),
                .ConnectionID = oConnection
            }

            If oForm.ShowDialog() = DialogResult.OK Then

                oSQLCommand = oForm.SQLCommand.Replace("'", "''")
                Dim oConnectionId = oForm.SQLConnectionId

                oSQL = $"UPDATE TBDD_INDEX_AUTOM SET CONNECTION_ID = {oConnectionId},SQL_RESULT = '{oSQLCommand}',CHANGED_WHO = '{Environment.UserName}' WHERE GUID = {oIndexGuid}"
                ClassDatabase.Execute_non_Query(oSQL, True)

            End If
        Catch ex As Exception
            LOGGER.Error(ex)
        End Try
    End Sub

    Private Sub ToolStripButton23_Click(sender As Object, e As EventArgs) Handles ToolStripButton23.Click
        Dim frm As New frmUserKonfig_AddUsers
        Cursor = Cursors.WaitCursor
        frm.ShowDialog()
        If tscmbUser.SelectedIndex = 1 Then
            Refresh_User(True)
        Else
            Refresh_User(False)
        End If
        Cursor = Cursors.Default
    End Sub

    Public Sub New()
        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()


    End Sub

    Private Sub TYPEComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TYPEComboBox.SelectedIndexChanged
        If TYPEComboBox.SelectedIndex <> -1 Then
            Select Case TYPEComboBox.Text
                Case "VBREPLACE"

                    If USER_LANGUAGE = "de-DE" Then
                        Text1Label.Text = "Alter Wert:"
                        Text2Label.Text = "Neuer Wert:"
                    Else
                        Text1Label.Text = "Old Value:"
                        Text2Label.Text = "New Value:"
                    End If

                    Me.TEXT1TextBox.Visible = True
                    TEXT1TextBox.Width = 165

                    Me.TEXT2TextBox.Visible = True
                    Me.TEXT2TextBox.Width = 191
                    Me.Text3Label.Visible = False
                    Me.TEXT3TextBox.Visible = False
                    Me.FUNCTION1TextBox.Visible = False
                    Me.FUNCTION2TextBox.Visible = False
                    Me.Function1Label.Visible = False
                    Me.Function2Label.Visible = False

                    Me.Function1Label.Visible = False
                    Me.Function2Label.Visible = False
                    Me.FUNCTION1TextBox.Visible = False
                    Me.FUNCTION2TextBox.Visible = False

                Case "VBSPLIT"

                    If USER_LANGUAGE = "de-DE" Then
                        Text1Label.Text = "Split-Zeichen:"
                        Text2Label.Text = "Wähle Vorkommen: Achtung Nullbasierend - Erstes Vorkommen = '0'"
                    Else
                        Text1Label.Text = "Split-Character:"
                        Text2Label.Text = "Choose occurrence: 0-Based - First occurrence = '0'"
                    End If

                    Me.FUNCTION1TextBox.Visible = True
                    Me.FUNCTION2TextBox.Visible = True
                    Me.Function1Label.Visible = True
                    Me.Function2Label.Visible = True


                    Me.TEXT1TextBox.Visible = True
                    TEXT1TextBox.Width = 50

                    Me.TEXT2TextBox.Visible = True
                    Me.TEXT2TextBox.Width = 50
                    Me.TEXT3TextBox.Visible = False
                    Me.Text3Label.Visible = False

                    Me.Function1Label.Visible = False
                    Me.Function2Label.Visible = False
                    Me.FUNCTION1TextBox.Visible = False
                    Me.FUNCTION2TextBox.Visible = False
                Case "REG. EXPRESSION"

                    If USER_LANGUAGE = "de-DE" Then
                        Me.Text1Label.Text = "Regulärer Ausdruck:"
                    Else
                        Me.Text1Label.Text = "Regular Expression:"
                    End If

                    Me.TEXT1TextBox.Visible = True
                    TEXT1TextBox.Width = 537
                    Me.Text2Label.Visible = False
                    Me.TEXT2TextBox.Visible = False
                    Me.Text3Label.Visible = False
                    Me.TEXT3TextBox.Visible = False
                    Me.FUNCTION1TextBox.Visible = False
                    Me.FUNCTION2TextBox.Visible = False
                    Me.Function1Label.Visible = False
                    Me.Function2Label.Visible = False

                    Me.Function1Label.Visible = False
                    Me.Function2Label.Visible = False
                    Me.FUNCTION1TextBox.Visible = False
                    Me.FUNCTION2TextBox.Visible = False
            End Select
        End If

    End Sub
    Private Sub ToolStripButton30_Click(sender As Object, e As EventArgs) Handles ToolStripButton30.Click

        Save_PostProcessing()
    End Sub
    Sub Save_PostProcessing()
        Try
            TBDD_INDEX_MAN_POSTPROCESSINGBindingSource.EndEdit()
            If MyDataset.TBDD_INDEX_MAN_POSTPROCESSING.GetChanges Is Nothing = False Then
                CHANGED_WHOTextBox4.Text = Environment.UserName
                TBDD_INDEX_MAN_POSTPROCESSINGBindingSource.EndEdit()
                Me.TBDD_INDEX_MAN_POSTPROCESSINGTableAdapter.Update(MyDataset.TBDD_INDEX_MAN_POSTPROCESSING)
                lblsavePostProcess.Visible = True
            Else
                lblsavePostProcess.Visible = False
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Save Post Processing: ")
        End Try
    End Sub

    Private Sub TBDD_INDEX_MAN_POSTPROCESSINGBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBDD_INDEX_MAN_POSTPROCESSINGBindingSource.AddingNew
        Save_Dokumentart()
        enableControls(XtraTabPage6)
        MyDataset.TBDD_INDEX_MAN_POSTPROCESSING.ADDED_WHOColumn.DefaultValue = Environment.UserName
        MyDataset.TBDD_INDEX_MAN_POSTPROCESSING.SEQUENCEColumn.DefaultValue = 1
    End Sub
    Sub enableControls(obj As Object)
        For Each element In obj.Controls
            If element.enabled = False Then
                element.enabled = True
            End If
        Next
    End Sub
    Private Sub ToolStripButton31_Click(sender As Object, e As EventArgs) Handles ToolStripButton31.Click
        Load_PostProcessing(Me.DOKART_GUIDTextBox.Text)
    End Sub

    Private Sub ToolStripButton38_Click(sender As Object, e As EventArgs) Handles ToolStripButton38.Click
        Save_UserGroups()
    End Sub
    Sub Save_UserGroups()
        Try
            TBDD_GROUPSBindingSource.EndEdit()
            If MyDataset.TBDD_GROUPS.GetChanges Is Nothing = False Then
                Dim changes = MyDataset.TBDD_GROUPS.GetChanges()

                ' If a Group was selected and deleted, delete references in TBDD_USRGRP_DOCTYPE and TBDD_GROUPS_USER
                If Not IsNothing(GroupToDelete) And MyDataset.TBDD_GROUPS.GetChanges(DataRowState.Deleted) Is Nothing = False Then
                    ClassDatabase.Execute_non_Query($"DELETE FROM TBDD_USRGRP_DOKTYPE WHERE GROUP_ID = {GroupToDelete}")
                    ClassDatabase.Execute_non_Query($"DELETE FROM TBDD_GROUPS_USER WHERE GROUP_ID = {GroupToDelete}")
                    GroupToDelete = Nothing
                End If

                CHANGED_WHOTextBox5.Text = Environment.UserName
                TBDD_INDEX_MAN_POSTPROCESSINGBindingSource.EndEdit()
                Me.TBDD_GROUPSTableAdapter.Update(MyDataset.TBDD_GROUPS)
                lblsaveTBDD_USER_GROUPS.Visible = True
            Else
                lblsaveTBDD_USER_GROUPS.Visible = False
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Save User-Groups: ")
        End Try
    End Sub
    Sub Load_UserGroups()
        Try
            Me.TBDD_GROUPSTableAdapter.FillNew(Me.MyDataset.TBDD_GROUPS)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in load User-Groups: ")
        End Try
    End Sub

    Private Sub XtraTabControl3_SelectedPageChanged(sender As Object, e As DevExpress.XtraTab.TabPageChangedEventArgs) Handles XtraTabControl3.SelectedPageChanged
        Select Case XtraTabControl3.SelectedTabPageIndex
            Case 0
                Load_UserRelation(USER_GUIDTextBox.Text)
            Case 1
                Load_UserGroups()
        End Select
    End Sub

    Private Sub TBDD_USER_GROUPSBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBDD_GROUPSBindingSource.AddingNew
        Me.MyDataset.TBDD_GROUPS.ADDED_WHOColumn.DefaultValue = Environment.UserName
    End Sub

    Private Sub Load_UserRelation(UserID As Integer)
        Try
            Me.VWGI_USER_GROUPS_RELATIONTableAdapter.Fill(Me.MyDataset.VWGI_USER_GROUPS_RELATION, UserID)
            lblnewUserZuordnung.Visible = False
        Catch ex As System.Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in load User-Relation: ")
        End Try
    End Sub

    Private Sub btnAddGroupRelation_Click(sender As Object, e As EventArgs) Handles btnAddGroupRelation.Click
        If cmbGroup2User.SelectedIndex <> -1 And USER_GUIDTextBox.Text <> "" Then
            Try
                TBDD_GROUPS_USERTableAdapter.cmdinsert(USER_GUIDTextBox.Text, cmbGroup2User.SelectedValue, Environment.UserName)
                Load_UserRelation(USER_GUIDTextBox.Text)
                lblnewUserZuordnung.Visible = True
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Add User-Relation: ")
            End Try

        End If
    End Sub

    Private Sub btnDeleteGroupRelation_Click(sender As Object, e As EventArgs) Handles btnDeleteGroupRelation.Click
        If Not ListBoxUserzuordnung.SelectedValue Is Nothing Then
            TBDD_GROUPS_USERTableAdapter.Delete(ListBoxUserzuordnung.SelectedValue)
            Load_UserRelation(USER_GUIDTextBox.Text)
        End If
    End Sub

    Private Sub TBDD_USERBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles TBDD_USERBindingSource.CurrentChanged
        If USER_GUIDTextBox.Text <> "" Then
            'Load_ZuordnungDokart_Module(ListBoxDokart.SelectedValue)
            Load_TabData()
            Load_UserRelation(USER_GUIDTextBox.Text)
        End If

    End Sub

    Private Sub Load_DokartZuordnung(DokID As Integer)
        Try
            Me.VWGI_DOCTYPE_GROUPTableAdapter.Fill(Me.MyDataset.VWGI_DOCTYPE_GROUP, DokID)
            lblnewDokartZuordnung.Visible = False
        Catch ex As System.Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Load Doctype-Relation: ")
        End Try

    End Sub

    Private Sub btnAddDokartGroupRelation_Click(sender As Object, e As EventArgs) Handles btnAddDokartGroupRelation.Click
        If cmbGroup2Dokart.SelectedIndex <> -1 And DOKART_GUIDTextBox.Text <> "" Then
            Try
                VWGI_DOCTYPE_GROUPTableAdapter.cmdInsert(DOKART_GUIDTextBox.Text, cmbGroup2Dokart.SelectedValue, Environment.UserName)
                Load_DokartZuordnung(DOKART_GUIDTextBox.Text)
                lblnewDokartZuordnung.Visible = True
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Add Doctype-Relation: ")
            End Try

        End If
    End Sub

    Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
        If Not ListBoxDokartzuordnung.SelectedValue Is Nothing Then
            VWGI_DOCTYPE_GROUPTableAdapter.cmdDelete(ListBoxDokartzuordnung.SelectedValue)
            Load_DokartZuordnung(DOKART_GUIDTextBox.Text)
        End If
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        frmSQL_Admin.ShowDialog()
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
        Dim result As MsgBoxResult

        If USER_LANGUAGE = "de-DE" Then
            result = MessageBox.Show("Sind Sie sicher dass Sie diese Dokumentart löschen wollen?", "Bestätigung erforderlich:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        Else
            result = MessageBox.Show("Are you sure you want to delete this documenttype", "Confirmation needed:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        End If

        If result = MsgBoxResult.Yes Then
            Try
                Dim del As String = " EXEC PRDD_GLOBIX_DELETE_DOCTYPE " & DOKART_GUIDTextBox.Text
                If ClassDatabase.Execute_non_Query(del, True) = True Then
                    Dim str = "Global-Indexer Dokarten"
                    If ToolStripComboBox1.Text <> "" Then
                        str = ToolStripComboBox1.Text
                    End If
                    Load_Dokart(str)


                    If USER_LANGUAGE = "de-DE" Then
                        MsgBox("Die Dokumentart wurde erfolgreich gelöscht!", MsgBoxStyle.Information)
                    Else
                        MsgBox("Documenttype successfully deleted!", MsgBoxStyle.Information)
                    End If

                End If
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Delete DocType: ")
            End Try
        End If
    End Sub

    Private Sub ToolStripButton40_Click(sender As Object, e As EventArgs) Handles ToolStripButton40.Click
        LoadGlobix_Doctypes()
    End Sub
    Sub LoadGlobix_Doctypes()
        Dim str = "Global-Indexer Dokarten"
        If ToolStripComboBox1.Text <> "" Then
            str = ToolStripComboBox1.Text
        End If
        Load_Dokart(str)
    End Sub
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        frmLicense.ShowDialog()
    End Sub

    Private Sub tscmbUser_SelectedIndexChanged(sender As Object, e As EventArgs) Handles tscmbUser.SelectedIndexChanged
        If tscmbUser.SelectedIndex = 1 Then
            Refresh_User(True)
        Else
            Refresh_User(False)
        End If
    End Sub

    Private Sub ToolStripButton14_Click(sender As Object, e As EventArgs) Handles ToolStripButton14.Click
        Save_User()
    End Sub
    Sub Save_User()
        Try
            TBDD_USERBindingSource.EndEdit()
            If MyDataset.TBDD_USER.GetChanges Is Nothing = False Then
                CHANGED_WHOTextBoxUser.Text = Environment.UserName
                TBDD_USERBindingSource.EndEdit()
                Me.TBDD_USERTableAdapter.Update(MyDataset.TBDD_USER)
                lblsaveUSer.Visible = True
            Else
                lblsaveUSer.Visible = False
            End If
            If ClassDatabase.Execute_Scalar("SELECT MODULE_GI FROM TBDD_USER WHERE GUID = " & USER_GUIDTextBox.Text, MyConnectionString) = 0 Then
                Dim sql As String = "UPDATE TBDD_USER SET MODULE_GI = 1 where GUID = " & USER_GUIDTextBox.Text
                ClassDatabase.Execute_non_Query(sql)

            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Save User: ")
        End Try
    End Sub

    Private Sub btncrFolder_delete_Click(sender As Object, e As EventArgs) Handles btncrFolder_delete.Click
        Me.FOLDER_FOR_INDEXTextBox.Text = ""
        Save_Dokumentart()
    End Sub

    Private Sub btnaddcrFolderParameter_Click(sender As Object, e As EventArgs) Handles btnaddcrFolderParameter.Click
        Dim str As String
        If (FOLDER_FOR_INDEXTextBox.Text = "") = False Then
            str = FOLDER_FOR_INDEXTextBox.Text & "\"
        End If
        If cmbCrFolderIndex.SelectedIndex <> -1 Then
            Me.FOLDER_FOR_INDEXTextBox.Text = str & "[%" & cmbCrFolderIndex.Text & "]"
            cmbCrFolderIndex.SelectedIndex = -1
        ElseIf cmbCrFolderDate.SelectedIndex <> -1 Then
            Me.FOLDER_FOR_INDEXTextBox.Text = str & "[%V_" & cmbCrFolderDate.Text & "]"
            cmbCrFolderDate.SelectedIndex = -1
        ElseIf txtcrFoldermanuell.Text <> "" Then
            Me.FOLDER_FOR_INDEXTextBox.Text = str & txtcrFoldermanuell.Text
            txtcrFoldermanuell.Text = ""
        End If
        Me.TBDD_DOKUMENTARTTableAdapter.cmdUpdateFolderIndex(Environment.UserName, FOLDER_FOR_INDEXTextBox.Text, DOKART_GUIDTextBox.Text)
        Me.lblSaveDokart.Visible = True
    End Sub
    Private Sub cmbCrFolderIndex_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbCrFolderIndex.SelectedIndexChanged
        cmbCrFolderDate.SelectedIndex = -1
        txtcrFoldermanuell.Text = ""
    End Sub

    Private Sub cmbCrFolderDate_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbCrFolderDate.SelectedIndexChanged
        cmbCrFolderIndex.SelectedIndex = -1
        txtcrFoldermanuell.Text = ""
    End Sub

    Private Sub txtcrFoldermanuell_TextChanged(sender As Object, e As EventArgs) Handles txtcrFoldermanuell.TextChanged
        cmbCrFolderDate.SelectedIndex = -1
        cmbCrFolderIndex.SelectedIndex = -1
    End Sub

    Private Sub tsbtnCopyDoctype_Click(sender As Object, e As EventArgs) Handles tsbtnCopyDoctype.Click
        Dim result As MsgBoxResult

        If USER_LANGUAGE = "de-DE" Then
            result = MessageBox.Show("Sind Sie sicher dass Sie diese Dokumentart kopieren wollen?", "Bestätigung erforderlich:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        Else
            result = MessageBox.Show("Are you sure you want to copy this documenttype", "Confirmation needed:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        End If

        If result = MsgBoxResult.Yes Then
            Try
                Dim copy = "exec PRDD_COPY_DOKPROFILE " & DOKART_GUIDTextBox.Text & ", 1"
                If ClassDatabase.Execute_non_Query(copy, True) Then

                    If USER_LANGUAGE = "de-DE" Then
                        MsgBox("Die Dokumentart wurde erfolgreich kopiert und auf INAKTIV gesetzt." & vbNewLine & "Bitte beachten Sie:" & vbNewLine & "- Die Dokumentart wurde keiner Usergruppe zugeordnet.", MsgBoxStyle.Information)
                    Else
                        MsgBox("Documenttype was copied successfully and set to INACTIVE." & vbNewLine & "Please note:" & vbNewLine & "- Documenttype was not assigned to a usergroup", MsgBoxStyle.Information)
                    End If

                    Dim str = "Global-Indexer Dokarten"
                    If ToolStripComboBox1.Text <> "" Then
                        str = ToolStripComboBox1.Text
                    End If
                    Load_Dokart(str)
                End If
            Catch ex As Exception
                MsgBox("Error in Copy Doctype:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
            End Try
        End If
    End Sub

    Private Sub FOLDER_FOR_INDEXTextBox_LostFocus(sender As Object, e As EventArgs) Handles FOLDER_FOR_INDEXTextBox.LostFocus
        'Me.TBDD_DOKUMENTARTTableAdapter.cmdUpdateFolderIndex(Environment.UserName, FOLDER_FOR_INDEXTextBox.Text, DOKART_GUIDTextBox.Text)
        'Me.lblSaveDokart.Visible = True
    End Sub

    Private Sub XtraTabControl2_SelectedPageChanging(sender As Object, e As DevExpress.XtraTab.TabPageChangingEventArgs) Handles XtraTabControl2.SelectedPageChanging
        Save_Dokumentart()
    End Sub
    Private Sub TBDD_USERBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBDD_USERBindingSource.AddingNew
        MyDataset.TBDD_USER.ADDED_WHOColumn.DefaultValue = Environment.UserName
        enableControls(XtraTabPage2)
    End Sub

    Private Sub btnAddWindowsVariable_Click(sender As Object, e As EventArgs) Handles btnAddWindowsVariable.Click
        If Not lbFileparameter.SelectedItem Is Nothing Then
            If GUIDAUTO_INDEXTextbox.Text <> "" Then
                Dim value As String

                Select Case lbFileparameter.SelectedIndex
                    Case 0 : value = "$filename_ext"
                    Case 1 : value = "$filename"
                    Case 2 : value = "$extension"
                    Case 3 : value = "$FileCreateDate"
                    Case 4 : value = "$FileCreatedWho"
                    Case 5 : value = "$DateDDMMYYY"
                    Case 6 : value = "$Username"
                    Case 7 : value = "$Usercode"
                End Select

                'Select Case lbFileparameter.SelectedItem.ToString.ToUpper
                '    Case "Dateiname (mit Endung)".ToUpper
                '        value = "$filename_ext"
                '    Case "Dateiname (ohne Endung)".ToUpper
                '        value = "$filename"
                '    Case "Dateiendung".ToUpper
                '        value = "$extension"
                '    Case "Datei Erstelldatum".ToUpper
                '        value = "$FileCreateDate"
                '    Case "Datei Erstellt wer".ToUpper
                '        value = "$FileCreatedWho"
                '    Case "Aktuelles Datum (DD.MM.YYYY)".ToUpper
                '        value = "$DateDDMMYYY"
                '    Case "Username"
                '        value = "$Username"
                '    Case "Usercode"
                '        value = "$Usercode"
                'End Select

                If value <> "" Then
                    VALUETextBox.Text = value
                    Save_IndexAuto()
                End If
            Else
                If USER_LANGUAGE = "de-DE" Then
                    MsgBox("Bitte fügen Sie zuerst einen neuen Index hinzu!", MsgBoxStyle.Information)
                Else
                    MsgBox("Please add a new index first!", MsgBoxStyle.Information)
                End If
            End If
        End If
    End Sub

    Private Sub VARIANTComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles VARIANTComboBox.SelectedIndexChanged

    End Sub

    Private Sub ToolStripButton41_Click(sender As Object, e As EventArgs) Handles ToolStripButton41.Click
        Load_INDEXMAN(Me.DOKART_GUIDTextBox.Text)
    End Sub

    Private Sub FOLDER_FOR_INDEXTextBox_TextChanged(sender As Object, e As EventArgs) Handles FOLDER_FOR_INDEXTextBox.TextChanged

    End Sub

    Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
        If GUIDTextBox1.Text <> "" Then
            Try
                Dim del = "DELETE FROM TBDD_INDEX_MAN_POSTPROCESSING WHERE IDXMAN_ID = " & GUIDTextBox1.Text
                If ClassDatabase.Execute_non_Query(del) = True Then
                    del = "DELETE FROM TBDD_INDEX_MAN WHERE GUID = " & GUIDTextBox1.Text
                    If ClassDatabase.Execute_non_Query(del) = True Then
                        Load_INDEXMAN(Me.DOKART_GUIDTextBox.Text)
                    End If
                End If
            Catch ex As Exception
                MsgBox("Unexpected Error in deleting manual index: " & ex.Message, MsgBoxStyle.Critical)
            End Try
        End If
    End Sub

    Private Sub ToolStripButton9_Click(sender As Object, e As EventArgs) Handles ToolStripButton9.Click
        Dim result As MsgBoxResult

        If USER_LANGUAGE = "de-DE" Then
            result = MessageBox.Show("Sind Sie sicher dass Sie diesen User löschen wollen?", "Bestätigung erforderlich:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        Else
            result = MessageBox.Show("Are you sure you want to delete this user?", "Confirmation needed:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        End If

        If result = MsgBoxResult.Yes Then
            Try
                Dim del As String = " EXEC PRDD_GLOBIX_DELETE_USER " & USER_GUIDTextBox.Text
                If ClassDatabase.Execute_non_Query(del, True) = True Then
                    If tscmbUser.SelectedIndex = 1 Then
                        Refresh_User(True)

                    Else
                        Refresh_User(False)
                    End If
                End If
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Delete User: ")
            End Try
        End If
    End Sub

    Private Sub tsbtnRefreshAutomatic_Click(sender As Object, e As EventArgs) Handles tsbtnRefreshAutomatic.Click
        Load_INDEXE_AUTO(Me.DOKART_GUIDTextBox.Text)
    End Sub

    Private Sub ToolStripButton33_Click(sender As Object, e As EventArgs) Handles ToolStripButton33.Click
        Dim list As ListBox = ListBox4

        If Not IsNothing(list.SelectedItem) Then
            Dim item As DataRowView = list.SelectedItem
            GroupToDelete = Integer.Parse(item.Row.Item("GUID"))
        Else
            GroupToDelete = Nothing
        End If
    End Sub

    Private _indexIsVectorField As Boolean = False

    Private Sub WD_INDEXComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles WD_INDEXComboBox.SelectedIndexChanged
        _indexIsVectorField = indexIsVectorField()
        MULTISELECTCheckBox.Visible = _indexIsVectorField
        VKT_PREVENT_MULTIPLE_VALUESCheckbox.Visible = _indexIsVectorField

        If Not _indexIsVectorField Then
            MULTISELECTCheckBox.Checked = False
            VKT_PREVENT_MULTIPLE_VALUESCheckbox.Checked = False
        End If
    End Sub

    Private Function indexIsVectorField() As Boolean
        Try
            Dim selectedIndexName As String = WD_INDEXComboBox.Text

            If selectedIndexName = String.Empty Then
                Return False
            End If

            ' Vektorindexe fangen bei 4000 an
            Return ClassWindream.GetTypeOfIndexAsIntByName(selectedIndexName) > 4000
        Catch ex As Exception
            Return False
        End Try
    End Function

    Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click

    End Sub

    Private Sub ToolStripButton42_Click(sender As Object, e As EventArgs) Handles ToolStripButton42.Click
        Try
            Me.TBGI_REGEX_DOCTYPEBindingSource.EndEdit()
        Catch ex As Exception

            MsgBox("Error in Save Regex1: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
            Exit Sub
        End Try

        If MyDataset.TBGI_REGEX_DOCTYPE.GetChanges Is Nothing = False Then
            Me.CHANGED_WHOTextBox1.Text = Environment.UserName
            Try
                Me.TBGI_REGEX_DOCTYPEBindingSource.EndEdit()
            Catch ex As Exception

                MsgBox("Error in Save Regex2: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)

            End Try
            TBGI_REGEX_DOCTYPETableAdapter.Update(MyDataset.TBGI_REGEX_DOCTYPE)

        End If
    End Sub

    Private Sub BindingNavigatorAddNewItem1_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem1.Click
        Me.TBGI_REGEX_DOCTYPEBindingSource.AddNew()
    End Sub

    Private Sub TBGI_REGEX_DOCTYPEBindingSource_AddingNew(sender As Object, e As AddingNewEventArgs) Handles TBGI_REGEX_DOCTYPEBindingSource.AddingNew
        MyDataset.TBGI_REGEX_DOCTYPE.ADDED_WHOColumn.DefaultValue = Environment.UserName
        MyDataset.TBGI_REGEX_DOCTYPE.REGEXColumn.DefaultValue = txtFilenameTest.Text
    End Sub

    Private Sub XtraTabPage1_Paint(sender As Object, e As PaintEventArgs) Handles XtraTabPage1.Paint

    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        My.Settings.Save()

        Try
            If Regex.IsMatch(txtFilenameTest.Text, REGEXTextBox.Text) Then
                MsgBox("The RegEx resulted in a proper match!", MsgBoxStyle.Information, "Perfect:")
            Else
                MsgBox("No Match- There might be an error in the RegEx!", MsgBoxStyle.Information, "Something wrong:")
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Testing Regex: ")
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem1_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem1.Click
        Try
            Dim oSQL = $"DELETE FROM TBGI_REGEX_DOCTYPE WHERE GUID = {GUIDTextBox.Text}"
            If ClassDatabase.Execute_non_Query(oSQL, True) = True Then
                Me.TBGI_REGEX_DOCTYPETableAdapter.Fill(Me.MyDataset.TBGI_REGEX_DOCTYPE)
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Deleting Regex:")
        End Try

    End Sub
End Class
