Imports DevExpress.XtraLayout
Imports DigitalData.Modules.Logging
Public Class frmGlobixAdministration

    Implements IAdminForm
    Public Property PrimaryKey As Integer Implements IAdminForm.PrimaryKey
    Public Property HasChanges As Boolean Implements IAdminForm.HasChanges
    Public Property IsInsert As Boolean Implements IAdminForm.IsInsert
    Private Logger As Logger
    Private CURRCOntrolGroup As LayoutControlGroup
    Public Sub New(PrimaryKey As Integer)
        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        Logger = My.LogConfig.GetLogger()
        Me.PrimaryKey = PrimaryKey
        Me.IsInsert = IsInsert
    End Sub
    Public Shared _Namenkonvention As String
    Public Shared _aktDokart_Id As Integer

    Private SourceAttributes As List(Of String)
    Private SourceObjectTypes As List(Of String)

    Private Current_ObjectType As String = ""

    Private GroupToDelete As Integer = Nothing
    Dim frmloaded As Boolean = False
    Private Sub frmGlobixAdministration_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try
            Me.TBDD_DOKUMENTARTTableAdapter.Connection.ConnectionString = My.Database.CurrentSQLConnectionString
            '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.TBDD_INDEX_MAN_POSTPROCESSINGTableAdapter.Connection.ConnectionString = MyConnectionString
            'Me.TBWHDD_INDEX_MANTableAdapter.Connection.ConnectionString = MyConnectionString
            'Me.VWGI_USER_GROUPS_RELATIONTableAdapter.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

        Dim oDragDropManager As New ClassDragDrop()
        'oDragDropManager.AddGridView(viewAssignedGroups)
        'oDragDropManager.AddGridView(viewAvailableGroups)
        'oDragDropManager.AddGridView(viewAssignedUsers)
        'oDragDropManager.AddGridView(viewAvailableUsers)

        Dim oDatatable As New DataTable()
        oDatatable.Columns.Add("VALUE_TEXT")
        oDatatable.Columns.Add("DISPLAY_TEXT")

        oDatatable.Rows.Add("Default", "Datei Überschreiben")
        oDatatable.Rows.Add("New version", "Neue Version erstellen")
        oDatatable.Rows.Add("Question", "Nachfragen")

        ComboBox3.DataSource = oDatatable

        Try

            Load_Dokart()
            Logger.Debug("...Done Load_Dokart")
            'Me.TBDD_EINGANGSARTENTableAdapter.Fill(Me.MyDataset.TBDD_EINGANGSARTEN)
            Logger.Debug("...Done TBDD_EINGANGSARTEN")
            ' Me.TBDD_MODULESTableAdapter.Fill(Me.MyDataset.TBDD_MODULES)
            Logger.Debug("...Done TBDD_MODULES")
        Catch ex As Exception
            Logger.Error(ex)
            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
    Sub Load_Dokart()
        Try
            If PrimaryKey > 0 Then
                Me.TBDD_DOKUMENTARTTableAdapter.Fill(Me.GlobixDataset.TBDD_DOKUMENTART, PrimaryKey)
                GridControl1.Visible = False
            Else
                Me.TBDD_DOKUMENTARTTableAdapter.FillAllDoctypes(Me.GlobixDataset.TBDD_DOKUMENTART)
                GridControl1.Visible = True
            End If


            If GlobixDataset.TBDD_DOKUMENTART.Rows.Count > 0 Then
                GridView1.SelectRow(1)
                'EnableControls(XtraTabPageProfiles)
            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


    Public Function SaveData() As Boolean
        Throw New NotImplementedException()
    End Function

    Private Sub BESCHREIBUNGTextBox_TextChanged(sender As Object, e As EventArgs) Handles BESCHREIBUNGTextBox.TextChanged

    End Sub


    Private Sub Load_INDEXMAN(ProfileId As Integer)
        Try
            Me.TBDD_INDEX_MANTableAdapter.Fill(Me.GlobixDataset.TBDD_INDEX_MAN, CType(DokartGUIDTextBox.Text, Integer))
            If GlobixDataset.TBDD_INDEX_MAN.Rows.Count > 0 Then
                EnableControls(XtraTabPageManIndexe)
            End If
            ClearStatus()
        Catch ex As System.Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Load IndexeManuell: ")
        End Try
    End Sub
    Private Sub ClearStatus()
        bsiState.Caption = String.Empty
    End Sub
    Private Sub XtraTabControl2_SelectedPageChanged(sender As Object, e As DevExpress.XtraTab.TabPageChangedEventArgs) Handles XtraTabControl2.SelectedPageChanged
        Load_TabData()
    End Sub
    Sub Load_TabData()
        If frmloaded = False Then
            Exit Sub
        End If

        RibbonPageGroupProfileRegex.Enabled = False
        RibbonPageGroupManualIndex.Enabled = False
        RibbonPageGroupManualIndexFunctions.Enabled = False
        RibbonPageGroupAutoIndex.Enabled = False

        Select Case XtraTabControl2.SelectedTabPage.Name
            Case XtraTabPageManIndexe.Name
                RibbonPageGroupManualIndex.Enabled = True

                If DokartGUIDTextBox.Text <> "" Then
                    ' Load_INDEXMAN(Me.DokartGUIDTextBox.Text)
                End If
            Case XtraTabPageRework.Name
                RibbonPageGroupManualIndexFunctions.Enabled = True

                'Load_PostProcessing(Me.DOKART_GUIDTextBox.Text)
            Case XtraTabPageAutoIndexe.Name
                Load_INDEXE_AUTO(CType(DokartGUIDTextBox.Text, Integer))

                RibbonPageGroupAutoIndex.Enabled = True
                'Case XtraTabPageFolderPath.Name
                '    Try
                '        Dim Dt As DataTable = ClassDatabase.Return_Datatable("select NAME from VWDDINDICES_MAN_AUTO_ACTIVE where DOCTYPE_ID = " & DokartGUIDTextBox.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
                'Case XtraTabPageProfileRegex.Name
                '    TBGI_REGEX_DOCTYPETableAdapter.Fill(MyDataset.TBGI_REGEX_DOCTYPE, DOKART_GUIDTextBox.Text)
                '    RibbonPageGroupProfileRegex.Enabled = True
        End Select
    End Sub


    Private Sub Load_INDEXE_AUTO(ProfileId As Integer)
        Try
            Me.TBDD_INDEX_AUTOMTableAdapter.Fill(Me.GlobixDataset.TBDD_INDEX_AUTOM, CType(DokartGUIDTextBox.Text, Integer))
            If GlobixDataset.TBDD_INDEX_AUTOM.Rows.Count > 0 Then
                EnableControls(XtraTabPageAutoIndexe)
            End If
        Catch ex As System.Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Load Indexe Auto: ")
        End Try
    End Sub



    Sub EnableControls(Control As Control, Optional Value As Boolean = True)
        For Each oSubControl As Control In Control.Controls
            If oSubControl.Enabled <> Value Then
                oSubControl.Enabled = Value
            End If
        Next
    End Sub

    Private Sub Root_Click(sender As Object, e As EventArgs) Handles ControlGroupProfile.Click, ControlGroupIndexeMan.Click, ControlGroupIndexeAuto.Click
        CURRCOntrolGroup = sender
        Select Case CURRCOntrolGroup.Name

            Case ControlGroupProfile.Name
                RibbonPageGroup1.Text = "Profile"
            Case ControlGroupIndexeMan.Name
                RibbonPageGroup1.Text = "Manual Values"
            Case ControlGroupIndexeAuto.Name
                RibbonPageGroup1.Text = "Auto Values"
        End Select
    End Sub

    Public Function DeleteData() As Boolean Implements IAdminForm.DeleteData
        Throw New NotImplementedException()
    End Function
End Class