Imports DevExpress.XtraEditors.Repository

Public Class frmWM_Resultlist_Config


    Private Sub frmWD_Resultlist_Config_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Me.TBPMO_DOCSEARCH_RESULTLIST_CONFIG_TYPE_IDTableAdapter.Connection.ConnectionString = MYDB_ECM.CurrentConnectionString
            Me.TBPMO_DOCSEARCH_RESULTLIST_CONFIG_TYPE_IDTableAdapter.Fill(Me.DD_ECMAdmin.TBPMO_DOCSEARCH_RESULTLIST_CONFIG_TYPE_ID)
            Me.TBPMO_DOCSEARCH_RESULTLIST_CONFIGTableAdapter.Connection.ConnectionString = MYDB_ECM.CurrentConnectionString
            Me.TBPMO_DOCSEARCH_RESULTLIST_CONFIGTableAdapter.Fill(Me.DD_ECMAdmin.TBPMO_DOCSEARCH_RESULTLIST_CONFIG)
            Me.TBPMO_DOCRESULT_DROPDOWN_ITEMSTableAdapter.Connection.ConnectionString = MYDB_ECM.CurrentConnectionString

            Me.TBWH_ENTITYTableAdapter.Connection.ConnectionString = MYDB_ECM.CurrentConnectionString
            Me.TBWH_ENTITYTableAdapter.Fill(Me.DD_DMSDataSet.TBWH_ENTITY, USER_LANGUAGE)

            AddHandler DD_ECMAdmin.TBPMO_DOCSEARCH_RESULTLIST_CONFIG.TBPMO_DOCSEARCH_RESULTLIST_CONFIGRowDeleting, AddressOf TBPMO_DOCSEARCH_RESULTLIST_CONFIGRowDeleting

            Dim colorEdit As New RepositoryItemColorEdit()
            colorEdit.ShowCustomColors = False
            colorEdit.ShowSystemColors = False
            colorEdit.ShowWebColors = True
            colorEdit.StoreColorAsInteger = True

            AddHandler colorEdit.FormatEditValue, AddressOf colorEdit_Format
            AddHandler colorEdit.ParseEditValue, AddressOf colorEdit_Parse


            grvwCombobox.Columns.Item("GUID").Visible = False
            grvwCombobox.Columns.Item("ADDED_WHO").Visible = False
            grvwCombobox.Columns.Item("ADDED_WHEN").Visible = False
            grvwCombobox.Columns.Item("CHANGED_WHO").Visible = False
            grvwCombobox.Columns.Item("CHANGED_WHEN").Visible = False
            grvwCombobox.Columns.Item("CONFIG_ID").Visible = False
            grvwCombobox.Columns.Item("COLOR").ColumnEdit = colorEdit


            ' Gruppierung nach Entität und dann nach Sprache
            grvwMain.Columns.Item("NAME").GroupIndex = 0
            grvwMain.Columns.Item("LANGUAGE").GroupIndex = 1
            ' Unwichtige Spalten ausblenden
            grvwMain.Columns.Item("GUID").Visible = False
            grvwMain.Columns.Item("ADDED_WHO").Visible = False
            grvwMain.Columns.Item("ADDED_WHEN").Visible = False
            grvwMain.Columns.Item("CHANGED_WHO").Visible = False
            grvwMain.Columns.Item("CHANGED_WHEN").Visible = False
        Catch ex As System.Exception
            MsgBox("Error while loading TBPMO_DOCSEARCH_RESULTLIST_CONFIG:" & vbNewLine & ex.Message)
        End Try
    End Sub

    Private Sub TBPMO_DOCSEARCH_RESULTLIST_CONFIGBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TBPMO_DOCSEARCH_RESULTLIST_CONFIGBindingNavigatorSaveItem.Click
        Try
            Me.Validate()
            Me.TBPMO_DOCSEARCH_RESULTLIST_CONFIGBindingSource.EndEdit()

            If DD_ECMAdmin.TBPMO_DOCSEARCH_RESULTLIST_CONFIG.GetChanges() IsNot Nothing Then
                Me.CHANGED_WHOTextBox.Text = USER_USERNAME
                Me.TBPMO_DOCSEARCH_RESULTLIST_CONFIGBindingSource.EndEdit()
                Me.TBPMO_DOCSEARCH_RESULTLIST_CONFIGTableAdapter.Update(Me.DD_ECMAdmin.TBPMO_DOCSEARCH_RESULTLIST_CONFIG)
                labelSuccess.Visible = True
            Else
                MsgBox("No changes")
                labelSuccess.Visible = False
            End If
        Catch ex As Exception
            MsgBox("Error while saving TBPMO_DOCSEARCH_RESULTLIST_CONFIG:" & vbNewLine & ex.Message)
        End Try
    End Sub

    Private Sub TBPMO_DOCSEARCH_RESULTLIST_CONFIGBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBPMO_DOCSEARCH_RESULTLIST_CONFIGBindingSource.AddingNew
        DD_ECMAdmin.TBPMO_DOCSEARCH_RESULTLIST_CONFIG.ADDED_WHOColumn.DefaultValue = USER_USERNAME
        ' Alle neuhinzugefügten Columns müssen CONFIG_COLUMNS = True haben
        DD_ECMAdmin.TBPMO_DOCSEARCH_RESULTLIST_CONFIG.CONFIG_COLUMNSColumn.DefaultValue = True

        ' VISIBLE und EDITABLE sollen explizit ausgewählt werden, deshalb erstmal False setzen
        DD_ECMAdmin.TBPMO_DOCSEARCH_RESULTLIST_CONFIG.VISIBLEColumn.DefaultValue = False
        DD_ECMAdmin.TBPMO_DOCSEARCH_RESULTLIST_CONFIG.EDITABLEColumn.DefaultValue = False

        ' SEQUENCE Erhält den Standart Wert 1
        DD_ECMAdmin.TBPMO_DOCSEARCH_RESULTLIST_CONFIG.SEQUENCEColumn.DefaultValue = 0
    End Sub

    Private Sub grvwMain_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles grvwMain.FocusedRowChanged
        labelSuccess.Visible = False

        Dim rowHandle = grvwMain.GetSelectedRows().FirstOrDefault()
        If rowHandle >= 0 Then
            Dim row = grvwMain.GetRow(rowHandle)
            Dim configId As Integer = row.Item("GUID")

            TBPMO_DOCRESULT_DROPDOWN_ITEMSTableAdapter.Fill(DD_ECMAdmin.TBPMO_DOCRESULT_DROPDOWN_ITEMS, configId)
        End If





    End Sub

    Private Sub grvwMain_CustomUnboundColumnData(sender As Object, e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs) Handles grvwMain.CustomUnboundColumnData
        If e.IsGetData Then
            Dim row As DataRowView = e.Row
            Dim entityId = row.Item("ENTITY_ID")
            Dim entityRow As DataRow = DD_DMSDataSet.TBWH_ENTITY.Select("FORM_ID = " & entityId).First()
            If Not IsNothing(entityRow.Item("FORM_TITLE")) Then
                e.Value = entityRow.Item("FORM_TITLE").ToString()
            End If
        End If
    End Sub

    Private Sub TYPE_IDComboBox_SelectedValueChanged(sender As Object, e As EventArgs) Handles TYPE_IDComboBox.SelectedValueChanged
        Dim value = TYPE_IDComboBox.SelectedValue

        If value = 3 Then
            'show splitter
        Else
            'hide splitter
        End If
    End Sub

    Private Sub colorEdit_Format(sender As Object, e As DevExpress.XtraEditors.Controls.ConvertEditValueEventArgs)
        Console.WriteLine("")
    End Sub

    Private Sub colorEdit_Parse(sender As Object, e As DevExpress.XtraEditors.Controls.ConvertEditValueEventArgs)
        Console.WriteLine("")
    End Sub

    Private Sub grvwCombobox_RowUpdated(sender As Object, e As DevExpress.XtraGrid.Views.Base.RowObjectEventArgs) Handles grvwCombobox.RowUpdated
        TBPMO_DOCRESULT_DROPDOWN_ITEMSTableAdapter.Update(DD_ECMAdmin)
    End Sub

    Private Sub TBPMO_DOCSEARCH_RESULTLIST_CONFIGRowDeleting(sender As Object, e As DD_Record_Organizer.DD_ECMAdmin.TBPMO_DOCSEARCH_RESULTLIST_CONFIGRowChangeEvent)
        Dim isConfigColumn As Boolean = e.Row.Item("CONFIG_COLUMNS")

        If (isConfigColumn = False) Then
            e.Row.RejectChanges()
        End If

    End Sub

End Class