Public Class frmGlobixNameconvention
    Public Property Nameconvention() As String
        Get
            Return txtnamenKonv.Text
        End Get
        Set(value As String)
            txtnamenKonv.Text = value
        End Set
    End Property
    Public Property DoctypeID As Integer
    Private Sub InsertAtSelection(str As String)
        Dim altePosition As Integer = txtnamenKonv.SelectionStart()
        txtnamenKonv.Text = txtnamenKonv.Text.Insert(altePosition, str)
        txtnamenKonv.SelectionStart = altePosition + str.Length
    End Sub
    Private Sub btnAddIndexM_Click(sender As Object, e As EventArgs) Handles btnAddIndexM.Click
        If Not Me.cmbIndex_m.Text = "" Then
            Dim text As String = clsPatterns.WrapPatternValue(clsPatterns.PATTERN_ATTR_MAN, cmbIndex_m.Text)
            InsertAtSelection(text)

        End If
    End Sub

    Private Sub btnAddIndexA_Click(sender As Object, e As EventArgs) Handles btnAddIndexA.Click
        If Not Me.cmbIndex_A.Text = "" Then
            Dim text As String = clsPatterns.WrapPatternValue(clsPatterns.PATTERN_ATTR_AUTO, cmbIndex_m.Text)
            InsertAtSelection(text)
        End If
    End Sub

    Private Sub frmGlobixNameconvention_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try
            Dim oSQL = $"SELECT * FROM TBDD_INDEX_MAN WHERE DOK_ID = {DoctypeID}"
            Dim oDTMANINDEX As DataTable = My.DatabaseECM.GetDatatable(oSQL)
            cmbIndex_m.DataSource = oDTMANINDEX
            cmbIndex_m.DisplayMember = oDTMANINDEX.Columns("NAME").ColumnName
            oSQL = $"SELECT * FROM TBDD_INDEX_AUTOM WHERE DOCTYPE_ID = {DoctypeID}"
            Dim oDTAUTOINDEX As DataTable = My.DatabaseECM.GetDatatable(oSQL)
            If Not IsNothing(oDTAUTOINDEX) And oDTAUTOINDEX.Rows.Count > 0 Then
                cmbIndex_A.DataSource = oDTAUTOINDEX
                cmbIndex_A.DisplayMember = oDTMANINDEX.Columns("WD_INDEX").ColumnName
            Else
                cmbIndex_A.Enabled = False
                btnAddIndexA.Enabled = False
            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnAddDate_Click(sender As Object, e As EventArgs) Handles btnAddDate.Click
        If Not Me.cmbDate.Text = "" Then
            'AREANLAGE-[%mARENR]-[%aKurzname]-I[%Version]
            Dim text As String = clsPatterns.WrapPatternValue(clsPatterns.PATTERN_INT, cmbDate.Text)
            InsertAtSelection(text)
        End If
    End Sub

    Private Sub btnAddDivers_Click(sender As Object, e As EventArgs) Handles btnAddDivers.Click
        If Not Me.cmbdivers.Text = "" Then
            Dim text As String = clsPatterns.WrapPatternValue(clsPatterns.PATTERN_INT, cmbdivers.Text)
            InsertAtSelection(text)
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim text As String = clsPatterns.WrapPatternValue(clsPatterns.PATTERN_INT, "OFilename")
        If Not txtnamenKonv.Text.Contains(text) Then
            InsertAtSelection(text)
        End If
    End Sub

    Private Sub SimpleButton2_Click(sender As Object, e As EventArgs) Handles SimpleButton2.Click
        Me.Close()
    End Sub

    Private Sub SimpleButton3_Click(sender As Object, e As EventArgs) Handles SimpleButton3.Click
        Me.Close()
    End Sub

    Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click
        Me.txtnamenKonv.Text = String.Empty
    End Sub
End Class