Imports DD_LIB_Standards
Public Class frmWD_Dokumentart_Konfig
    Private Shared _Instance As frmWD_Dokumentart_Konfig = Nothing
    Private insert As Boolean = False
    Public Shared akt_DokartID As Integer
    Private IsInsert As Boolean = False
    Public Shared Function Instance() As frmWD_Dokumentart_Konfig
        If _Instance Is Nothing OrElse _Instance.IsDisposed = True Then
            _Instance = New frmWD_Dokumentart_Konfig
        End If
        _Instance.BringToFront()
        Return _Instance
    End Function
    Private Sub TBDD_EINGANGSARTENBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TBDD_EINGANGSARTENBindingNavigatorSaveItem.Click
        Save_Dokart()
    End Sub

    Private Sub frmDokumentart_Konfig_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        ClassWindowLocation.SaveFormLocationSize(Me, 99, 99, "frmDokumentartKonfig")
    End Sub

    Private Sub frmDokumentart_Konfig_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            ClassWindowLocation.LoadFormLocationSize(Me, 99, 99, "frmDokumentartKonfig")
            Me.TBDD_INDEX_AUTOMTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBDD_DOKUMENTARTTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBDD_EINGANGSARTENTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBPMO_WD_FORMVIEW_DOKTYPESTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBPMO_FORM_VIEWTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBWH_DOKART_MODULETableAdapter.Connection.ConnectionString = MyConnectionString

            Refresh_Dokart(False)
            ObjektTypenEintragen()
            If GUIDTextBox.Text <> "" Then
                Refresh_DokID_FORM_VIEW()
                Refresh_DokartModule(GUIDTextBox.Text)
                Refresh_Indexe_Auto(GUIDTextBox.Text)
                akt_DokartID = GUIDTextBox.Text
                Refresh_DokartModule(GUIDTextBox.Text)
            End If

            Me.TBPMO_FORM_VIEWTableAdapter.Fill(DD_DMSDataSet.TBPMO_FORM_VIEW)
        Catch ex As Exception
            MsgBox("Error in Load:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Sub Refresh_DokID_FORM_VIEW()
        Try
            Me.TBPMO_WD_FORMVIEW_DOKTYPESTableAdapter.Fill(DD_DMSDataSet.TBPMO_WD_FORMVIEW_DOKTYPES, GUIDTextBox.Text)
        Catch ex As Exception
            MsgBox("Error in Refresh_DokID_FORM_VIEW:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Sub Save_Dokart()
        Try
            Dim msg = "Dokumentart gespeichert - " & Now.ToString
            If USER_LANGUAGE <> "de-DE" Then
                msg = "Doctype saved - " & Now.ToString
            End If
            lblSaveDokart.Text = msg
            Me.TBDD_DOKUMENTARTBindingSource.EndEdit()
            If DD_DMSDataSet.TBDD_DOKUMENTART.GetChanges Is Nothing = False Then
                Me.GEANDERTWERTextBox.Text = USER_USERNAME
                Me.TBDD_DOKUMENTARTBindingSource.EndEdit()
                Me.TBDD_DOKUMENTARTTableAdapter.Update(Me.DD_DMSDataSet.TBDD_DOKUMENTART)
                If IsInsert = True Then
                    Dim DOCID = ClassDatabase.Execute_Scalar("SELECT MAX(GUID) FROM TBDD_DOKUMENTART WHERE BEZEICHNUNG = '" & BEZEICHNUNGTextBox.Text & "'", True)
                    If DOCID > 0 Then
                        Dim insert = "INSERT INTO TBDD_DOKUMENTART_MODULE (DOKART_ID, MODULE_ID) VALUES (" & DOCID & ", 0)"
                        If ClassDatabase.Execute_non_Query(insert, True) = True Then
                            Refresh_DokartModule(DOCID)
                            IsInsert = False
                        End If
                    End If
                End If
                Me.lblSaveDokart.Visible = True
            Else
                Me.lblSaveDokart.Visible = False
            End If
            Refresh_Doktype_Relevant_Data()
        Catch ex As Exception
            MsgBox("Error in Save_Dokart:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Sub Refresh_Dokart(All As Boolean)
        Try
            If All = False Then
                If LogErrorsOnly = False Then ClassLogger.Add(" >> Dokumentarten für RecordOrganizer werden geladen", False)
                Me.TBDD_DOKUMENTARTTableAdapter.FillByPMO(Me.DD_DMSDataSet.TBDD_DOKUMENTART, USER_LANGUAGE)
                If LogErrorsOnly = False Then ClassLogger.Add(" >> Anzahl Dokumentarten: " & DD_DMSDataSet.TBDD_DOKUMENTART.Rows.Count, False)
            Else
                If LogErrorsOnly = False Then ClassLogger.Add(" >> Alle Dokumentarten werden geladen", False)
                Me.TBDD_DOKUMENTARTTableAdapter.Fill(Me.DD_DMSDataSet.TBDD_DOKUMENTART, USER_LANGUAGE)
            End If

        Catch ex As Exception
            MsgBox("Error in Refresh_Dokart:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Sub Refresh_Indexe_Auto(DokTypeid As Integer)
        Try
            Me.TBDD_INDEX_AUTOMTableAdapter.Fill(Me.DD_DMSDataSet.TBDD_INDEX_AUTOM, DokTypeid)
        Catch ex As Exception
            MsgBox("Error in Refresh_Indexe_Auto:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Sub Save_Indexe_Auto()
        Try
            Me.TBDD_INDEX_AUTOMBindingSource.EndEdit()
            If DD_DMSDataSet.TBDD_INDEX_AUTOM.GetChanges Is Nothing = False Then
                Me.CHANGED_WHOTextBox.Text = USER_USERNAME
                Me.TBDD_INDEX_AUTOMBindingSource.EndEdit()
                Me.TBDD_INDEX_AUTOMTableAdapter.Update(Me.DD_DMSDataSet.TBDD_INDEX_AUTOM)
                Me.lblSaveIndex.Visible = True

            Else
                Me.lblSaveIndex.Visible = False
            End If
        Catch ex As Exception
            MsgBox("Error in Save_Indexe_Auto:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Sub Refresh_Eingangsarten()
        Try
            Me.TBDD_EINGANGSARTENTableAdapter.Fill(Me.DD_DMSDataSet.TBDD_EINGANGSARTEN)
        Catch ex As Exception
            MsgBox("Error in Refresh_Eingangsarten:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Private Sub TBDD_DOKUMENTARTBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBDD_DOKUMENTARTBindingSource.AddingNew
        Me.DD_DMSDataSet.TBDD_DOKUMENTART.ERSTELLTWERColumn.DefaultValue = USER_USERNAME
        IsInsert = True
    End Sub

    Private Sub TBDD_EINGANGSARTENBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBDD_EINGANGSARTENBindingSource.AddingNew
        Me.DD_DMSDataSet.TBDD_EINGANGSARTEN.ERSTELLTWERColumn.DefaultValue = USER_USERNAME
    End Sub

    Private Sub TBDD_INDEX_AUTOMBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBDD_INDEX_AUTOMBindingSource.AddingNew
        Me.DD_DMSDataSet.TBDD_INDEX_AUTOM.ADDED_WHOColumn.DefaultValue = USER_USERNAME
        Me.DD_DMSDataSet.TBDD_INDEX_AUTOM.DOCTYPE_IDColumn.DefaultValue = GUIDTextBox.Text
        load_Indices()
    End Sub

    Private Sub btnZielpfad_Click(sender As Object, e As EventArgs) Handles btnZielpfad.Click
        Try
            '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
                ' Desktop is the root folder in the dialog.
                If ZIEL_PFADTextBox.Text <> "" Then
                    .SelectedPath = ZIEL_PFADTextBox.Text
                End If
                '.RootFolder = Environment.SpecialFolder.Desktop
                ' Prompt the user with a custom message.
                .Description = "Zielordner für Dokumentart wählen:"
                If .ShowDialog = DialogResult.OK Then
                    Dim Path As String = .SelectedPath
                    ZIEL_PFADTextBox.Text = .SelectedPath
                End If
            End With
        Catch ex As Exception
            MsgBox("Unexpected Error in set Path:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try

    End Sub

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

    End Sub

    Private Sub OBJEKTTYPComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles OBJEKTTYPComboBox.SelectedIndexChanged
        load_Indices()
    End Sub
    Sub load_Indices()
        Try
            If Me.OBJEKTTYPComboBox.SelectedIndex <> -1 Then
                Me.INDEXNAMEComboBox.Items.Clear()
                Dim indexe = clsWD_GET.GetIndicesByObjecttype(OBJEKTTYPComboBox.Text)
                If indexe IsNot Nothing Then
                    Me.INDEXNAMEComboBox.Items.Add("(ONLY for Nameconvention)")
                    For Each index As String In indexe
                        Me.INDEXNAMEComboBox.Items.Add(index)
                    Next
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Fehler bei cmbDokumentTypen.SelectedIndexChanged: ")
        End Try
    End Sub
    Sub Load_Entities()
        Try
            'Me.TBDD_INDEX_AUTOMTableAdapter.Fill(Me.DD_DMSDataSet.TBDD_INDEX_AUTOM, frmDokumentart_Konfig.akt_DokartID)
            Dim DT_ENTITIES = ClassDatabase.Return_Datatable("select T.GUID, T.FORMVIEW_ID, [dbo].[FNPMO_GETOBJECTCAPTION]('" & USER_LANGUAGE & "','FORMVIEW_TITLE' + CONVERT(VARCHAR(5), T.FORMVIEW_ID), 1) AS 'FORM_TITLE' FROM TBPMO_WD_FORMVIEW_DOKTYPES T, TBPMO_FORM_VIEW T1 WHERE T.FORMVIEW_ID = T1.GUID AND T1.SCREEN_ID = 1 AND T.DOCTYPE_ID = " & akt_DokartID & " ORDER BY T1.FORM_TITLE")
            cmbEntity.DataSource = DT_ENTITIES
            cmbEntity.DisplayMember = DT_ENTITIES.Columns(2).ColumnName
            cmbEntity.ValueMember = DT_ENTITIES.Columns(0).ColumnName
        Catch ex As Exception
            MsgBox("Unexpected Error in Load_Entities: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try

    End Sub
    Sub Load_ControlTags(FORM_VIEW_ID As Integer)
        Try
            Dim DT1 As DataTable = ClassDatabase.Return_Datatable("SELECT [CONTROL_COL_NAME] AS DISPLAY FROM [VWPMO_CONTROL_SCREEN] WHERE CTRLTYPE_ID in (2,3,4) and FORM_ID = (SELECT FORM_ID FROM TBPMO_FORM_VIEW WHERE GUID = " & FORM_VIEW_ID & ")")
            If DT1.Rows.Count >= 1 Then
                cmbControlsEntity.DataSource = DT1
                cmbControlsEntity.DisplayMember = DT1.Columns(0).ColumnName
                cmbControlsEntity.ValueMember = DT1.Columns(0).ColumnName
                cmbControlsEntity.Enabled = True
                btnAddIndexA.Enabled = True
            Else
                cmbControlsEntity.Enabled = False
                btnAddIndexA.Enabled = False
            End If
        Catch ex As Exception
            MsgBox("Unexpected Error in Load Control Tags: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try

    End Sub
    Private Sub ToolStripButton7_Click(sender As Object, e As EventArgs) Handles ToolStripButton7.Click
        Save_Indexe_Auto()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnAddDokart_Entity.Click
        Me.TBPMO_WD_FORMVIEW_DOKTYPESTableAdapter.cmdInsert(Me.cmbEntity_Doctype.SelectedValue, Me.GUIDTextBox.Text, Me.OBJEKTTYPComboBox.Text, USER_USERNAME)
        Refresh_DokID_FORM_VIEW()
    End Sub

    Private Sub XtraTabControl1_SelectedPageChanged(sender As Object, e As DevExpress.XtraTab.TabPageChangedEventArgs) Handles XtraTabControl1.SelectedPageChanged
        Select Case XtraTabControl1.SelectedTabPageIndex
            Case 0

            Case 1

            Case 2
                Refresh_DokID_FORM_VIEW()
                Me.btnAddDokart_Entity.Text = "Entität zu Dokumentart ' " & Me.KURZNAMETextBox.Text & "' hinzufügen"
            Case 3
                Load_Variable_Folder()

        End Select
    End Sub
    Sub Load_Variable_Folder()
        lblpathsaved.Visible = False
        Try
            If GUIDTextBox.Text <> "" Then
                FOLDER_FOR_INDEXTextBox.Enabled = True
                grbxFolderforIndex.Enabled = True
                Dim sql As String = "SELECT FOLDER_FOR_INDEX FROM TBDD_DOKUMENTART WHERE GUID = " & GUIDTextBox.Text
                Dim result = ClassDatabase.Execute_Scalar(sql)
                If IsDBNull(result) Then
                    FOLDER_FOR_INDEXTextBox.Text = ""
                Else
                    FOLDER_FOR_INDEXTextBox.Text = result.ToString
                End If
            Else
                FOLDER_FOR_INDEXTextBox.Enabled = False
                grbxFolderforIndex.Enabled = False
                Exit Sub
            End If
        Catch ex As Exception
            MsgBox("Unexpected Error in Getting variable Folder Tag: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
            Exit Sub
        End Try
        Try
            Dim sql = String.Format("SELECT [CONTROL_ID] , [CONTROL_COL_NAME]AS DISPLAY FROM [VWPMO_CONTROL_SCREEN] " & _
                    "WHERE CTRLTYPE_ID in (2,3,4) and FORM_ID = {0} UNION ALL " & _
                    "SELECT [CONTROL_ID] , [CTRLSCR_CAPTION]  AS DISPLAY FROM [VWPMO_CONTROL_SCREEN] " & _
                    "WHERE CTRLTYPE_ID = 1 AND [CONTROL_SQLCOMMAND_1] <> '' and FORM_ID = {0} UNION ALL " & _
                    "SELECT '999', 'Doctype'  AS DISPLAY " & _
                    "ORDER BY DISPLAY", GUIDTextBox.Text)
            Dim DT1 As DataTable = ClassDatabase.Return_Datatable(sql)
            If DT1.Rows.Count >= 1 Then
                cmbIndex_Controls.DataSource = DT1
                cmbIndex_Controls.DisplayMember = DT1.Columns(1).ColumnName
                cmbIndex_Controls.ValueMember = DT1.Columns(0).ColumnName
                cmbIndex_Controls.Enabled = True
            Else
                cmbIndex_Controls.Enabled = False
            End If
        Catch ex As Exception
            MsgBox("Error in Load Controls for EntitySelect: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
        Try
            Dim sql = String.Format("SELECT GUID, 'M' + NAME AS DISPLAY FROM TBPMO_INDEX_MAN WHERE DOCTYPE_ID = {0} AND ACTIVE = 1 UNION ALL SELECT GUID,'A' + INDEXNAME AS DISPLAY FROM TBDD_INDEX_AUTOM WHERE  SQL_RESULT IS NOT NULL AND SQL_RESULT <> '' AND DOCTYPE_ID = {0} ORDER BY DISPLAY", GUIDTextBox.Text)
            Dim DT1 As DataTable = ClassDatabase.Return_Datatable(sql)
            If DT1.Rows.Count >= 1 Then
                cmbCrFolderIndex.DataSource = DT1
                cmbCrFolderIndex.DisplayMember = DT1.Columns(1).ColumnName
                cmbCrFolderIndex.ValueMember = DT1.Columns(0).ColumnName
                cmbCrFolderIndex.Enabled = True
            Else
                cmbCrFolderIndex.Enabled = False
            End If
        Catch ex As Exception
            MsgBox("Error in Load manual indices: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try

    End Sub
    Private Sub btnNamenkonvention_Click(sender As Object, e As EventArgs) Handles btnNamenkonvention.Click
        Save_Dokart()
        akt_DokartID = GUIDTextBox.Text

        Dim sql As String = "select COUNT(T.GUID) FROM TBPMO_WD_FORMVIEW_DOKTYPES T, TBPMO_FORM_VIEW T1 WHERE T.FORMVIEW_ID = T1.GUID AND T1.SCREEN_ID = 1 AND T.DOCTYPE_ID = " & akt_DokartID
        Dim count = ClassDatabase.Execute_Scalar(sql)
        If count > 0 Then
            frmDoctype_NameConvention.ShowDialog()
        Else
            Dim msg As String = "Achtung: Sie haben der Dokumentart noch keine Entitäten zugeordnet!"
            If USER_LANGUAGE <> "de-DE" Then
                msg = "Attention: You did not assign at least one entity to the document-type!"
            End If
            MsgBox(msg, MsgBoxStyle.Exclamation)
            XtraTabControl1.SelectedTabPageIndex = 2
            cmbEntity_Doctype.DroppedDown = True
        End If
    End Sub

    Private Sub ToolStripButton14_Click(sender As Object, e As EventArgs) Handles ToolStripButton14.Click

    End Sub

    Private Sub ToolStripButton9_Click(sender As Object, e As EventArgs) Handles ToolStripButton9.Click
        Dim i As Integer
        i = TBPMO_WD_FORMVIEW_DOKTYPESDataGridView.CurrentRow.Index
        If TBPMO_WD_FORMVIEW_DOKTYPESDataGridView.Item(0, i).Value Is Nothing = False Then
            TBPMO_WD_FORMVIEW_DOKTYPESTableAdapter.DeleteQuery(TBPMO_WD_FORMVIEW_DOKTYPESDataGridView.Item(0, i).Value)
            Refresh_DokID_FORM_VIEW()
        End If
    End Sub

    Private Sub ToolStripButton15_Click(sender As Object, e As EventArgs) Handles ToolStripButton15.Click
        Refresh_DokID_FORM_VIEW()
    End Sub

    Private Sub TBDD_INDEX_AUTOMBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles TBDD_INDEX_AUTOMBindingSource.CurrentChanged
        Me.lblSaveIndex.Visible = False
        If VALUETextBox.Text.StartsWith("@") Then
            chkEntityData.Checked = False
        ElseIf VALUETextBox.Text.Contains("#") Then
            chkEntityData.Checked = True
        End If
    End Sub

    Private Sub TBDD_DOKUMENTARTBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles TBDD_DOKUMENTARTBindingSource.CurrentChanged
        Me.lblSaveDokart.Visible = False
        If GUIDTextBox.Text = "" Then Exit Sub
        Refresh_Doktype_Relevant_Data()
        If VALUETextBox.Text.StartsWith("@") Then
            chkEntityData.Checked = False
        ElseIf VALUETextBox.Text.Contains("#") Then
            chkEntityData.Checked = True
        End If
        Select Case XtraTabControl1.SelectedTabPageIndex
            Case 0

            Case 1

            Case 2
                Refresh_DokID_FORM_VIEW()
                Me.btnAddDokart_Entity.Text = "Entität zu Dokumentart ' " & Me.KURZNAMETextBox.Text & "' hinzufügen"
            Case 3
                Load_Variable_Folder()

        End Select
    End Sub
    Sub Refresh_Doktype_Relevant_Data()
        Refresh_Indexe_Auto(GUIDTextBox.Text)
        akt_DokartID = GUIDTextBox.Text
        Refresh_DokID_FORM_VIEW()
        Refresh_DokartModule(GUIDTextBox.Text)
    End Sub
    Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
        Dim msg = "Sind Sie sicher, dass Sie diese Dokumentart löschen wollen?"
        If USER_LANGUAGE <> "de-DE" Then
            msg = "Are You sure You want to delete the selected Doctype?"
        End If
        Dim result As MsgBoxResult
        result = MessageBox.Show(msg, "Confirmation:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = MsgBoxResult.Yes Then
            Dim del = "EXEC [dbo].[PRPMO_DELETE_DOCTYPE] " & GUIDTextBox.Text
            If ClassDatabase.Execute_non_Query(del, True) = True Then
                Refresh_Dokart(False)
                Refresh_DokID_FORM_VIEW()
            End If
        End If
    End Sub

    Private Sub ToolStripButton16_Click(sender As Object, e As EventArgs) Handles ToolStripButton16.Click
        Refresh_Dokart(False)
    End Sub

    Private Sub ToolStripButton17_Click(sender As Object, e As EventArgs) Handles ToolStripButton17.Click
        Refresh_Dokart(True)
    End Sub

    Private Sub Refresh_DokartModule(dokart_id As Integer)
        Try
            Me.TBWH_DOKART_MODULETableAdapter.Fill(Me.DD_DMSDataSet.TBWH_DOKART_MODULE, dokart_id)
        Catch ex As System.Exception
            MsgBox("Error in Refresh_DokartModule:" & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try

    End Sub

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            TBWH_DOKART_MODULETableAdapter.InsertDokartModule(GUIDTextBox.Text)
            Refresh_DokartModule(GUIDTextBox.Text)
        Catch ex As Exception
            MsgBox("Error in Add Dokart/Module:" & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try
    End Sub

    Private Sub INDEXNAMEComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles INDEXNAMEComboBox.SelectedIndexChanged
        If INDEXNAMEComboBox.SelectedIndex <> -1 Then
            If COMMENTTextBox.Text = String.Empty Then
                If INDEXNAMEComboBox.Text = "(ONLY for Nameconvention)" Then
                    COMMENTTextBox.Text = "Please insert a description for this placeholder"
                End If
            End If
        End If
    End Sub

    Private Sub chkEntityData_CheckedChanged(sender As Object, e As EventArgs) Handles chkEntityData.CheckedChanged
        If chkEntityData.Checked Then
            GroupBox2.Enabled = True
            Load_Entities()
            VALUEComboBox.Enabled = False
        Else
            GroupBox2.Enabled = False
            VALUEComboBox.Enabled = True
        End If
    End Sub

    Private Sub cmbEntity_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbEntity.SelectedIndexChanged
        If cmbEntity.SelectedIndex <> -1 Then
            Dim FORM_VIEW_ID = ClassDatabase.Execute_Scalar("SELECT FORMVIEW_ID FROM TBPMO_WD_FORMVIEW_DOKTYPES WHERE GUID = " & Me.cmbEntity.SelectedValue, True)
            Load_ControlTags(FORM_VIEW_ID)
        End If

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If Not Me.cmbControlsEntity.Text = "" Then
            'AREANLAGE-[%mARENR]-[%aKurzname]-I[%Version]
            Dim text As String = "[%a" & Me.cmbControlsEntity.Text.ToString.ToUpper & "#" & cmbControlsEntity.SelectedValue & "]"
            VALUETextBox.Text = text
        End If
    End Sub

    Private Sub btnaddcrFolderParameter_Click(sender As Object, e As EventArgs) Handles btnaddcrFolderParameter.Click
        Dim str As String
        Dim Changes As Boolean = False
        If (FOLDER_FOR_INDEXTextBox.Text = "") = False Then
            str = FOLDER_FOR_INDEXTextBox.Text & "\"
        End If
        If cmbCrFolderIndex.SelectedIndex <> -1 Then
            Dim value = Me.cmbCrFolderIndex.Text.ToString.ToUpper
            Me.FOLDER_FOR_INDEXTextBox.Text = str & "[%" & value & "#" & cmbCrFolderIndex.SelectedValue & "]"
            Changes = True
            cmbCrFolderIndex.SelectedIndex = -1
        ElseIf cmbCrFolderDate.SelectedIndex <> -1 Then
            Me.FOLDER_FOR_INDEXTextBox.Text = str & "[%V_" & cmbCrFolderDate.Text & "]"
            cmbCrFolderDate.SelectedIndex = -1
            Changes = True
        ElseIf cmbIndex_Controls.SelectedIndex <> -1 Then
            Dim value
            Dim praefix
            Dim text As String
            Select Case cmbIndex_Controls.SelectedValue
                Case 999
                    value = "Doctype"
                    praefix = "[%VAR"
                Case Else
                    value = Me.cmbIndex_Controls.Text.ToString.ToUpper
                    praefix = "[%CTRL"
            End Select
            text = praefix & value & "#" & cmbIndex_Controls.SelectedValue & "]"
            text = text.Replace("##", "#")
            Me.FOLDER_FOR_INDEXTextBox.Text = str & text
            cmbIndex_Controls.SelectedIndex = -1
            Changes = True
        End If

        If Changes = True Then
            Dim upd = String.Format("UPDATE TBDD_DOKUMENTART SET FOLDER_FOR_INDEX = '{0}', GEANDERTWER = '{1}' WHERE GUID = {2}", FOLDER_FOR_INDEXTextBox.Text, USER_USERNAME, GUIDTextBox.Text)
            If ClassDatabase.Execute_non_Query(upd, False) = False Then
                MsgBox("Unexpected Error in Adding Variable path - Check logfile", MsgBoxStyle.Exclamation)
            End If
            cmbCrFolderIndex.SelectedIndex = -1
            cmbCrFolderDate.SelectedIndex = -1
            cmbIndex_Controls.SelectedIndex = -1
        End If

    End Sub

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

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Try
            Dim upd = String.Format("UPDATE TBDD_DOKUMENTART SET FOLDER_FOR_INDEX = '{0}', GEANDERTWER = '{1}' WHERE GUID = {2}", FOLDER_FOR_INDEXTextBox.Text, USER_USERNAME, GUIDTextBox.Text)
            If ClassDatabase.Execute_non_Query(upd, False) = False Then
                MsgBox("Unexpected Error in Adding Variable path - Check logfile", MsgBoxStyle.Exclamation)
            Else
                Dim msg = "Variabler Ordner gespeichert - " & Now.ToString
                If USER_LANGUAGE <> "de-DE" Then
                    msg = "Data saved - " & Now.ToString
                End If
                lblpathsaved.Text = msg
                lblpathsaved.Visible = True

            End If
        Catch ex As Exception

        End Try
    End Sub
End Class