Imports DigitalData.GUIs.ZooFlow.Administration.ClassConstants

Public Class ClassDetailForm
    Inherits Base.BaseClass

    Public Event DetailFormClosed As EventHandler(Of Form)

    Public ReadOnly Property DetailDataList As New Dictionary(Of String, DetailData)
    Public ReadOnly Property DetailSettingsList As New Dictionary(Of String, DetailSettings) From {
        {PAGE_IDB_ATTRIBUTES,                   ' This Key will be matched with the Entity Id from the Database
        New DetailSettings With {
            .GridTitle = "Attribute",       ' This will be shown above the Data Grid
            .NewRecordTitle = "Neues Attribut", ' This will be shown on the "New" Button
            .[Module] = MODULE_IDB,
            .Entity = PAGE_IDB_ATTRIBUTES
        }},
        {PAGE_IDB_BUSINESS_ENTITIES,
        New DetailSettings With {
            .GridTitle = "BusinessEntity",
            .NewRecordTitle = "New BusinessEntity",
            .[Module] = MODULE_IDB,
            .Entity = PAGE_IDB_BUSINESS_ENTITIES
        }},
        {PAGE_IDB_OBJECT_STORES,                   ' This Key will be matched with the Entity Id from the Database
        New DetailSettings With {
            .GridTitle = "Object-Stores",       ' This will be shown above the Data Grid
            .NewRecordTitle = "New Object Store", ' This will be shown on the "New" Button
            .[Module] = MODULE_IDB,
            .Entity = PAGE_IDB_OBJECT_STORES
        }},
        {PAGE_META_SOURCE_SQL,
        New DetailSettings With {
            .GridTitle = "Source SQL",
            .NewRecordTitle = "New Source SQL",
            .[Module] = MODULE_META,
            .Entity = PAGE_META_SOURCE_SQL
        }},
        {PAGE_GI_PROFILES,
        New DetailSettings With {
            .GridTitle = "Global Indexer Profile",
            .NewRecordTitle = "New GLOBIX profile",
            .[Module] = MODULE_GI,
            .Entity = PAGE_GI_PROFILES
        }},
        {PAGE_CW_PROFILES,
        New DetailSettings With {
            .GridTitle = "Clipboard Watcher Profile",
            .NewRecordTitle = "New CW profile",
            .[Module] = MODULE_CW,
            .Entity = PAGE_CW_PROFILES
        }},
        {PAGE_IDB_ATTRIBUTE_REL,
        New DetailSettings With {
            .GridTitle = "Attribute-Relations",
            .NewRecordTitle = "",
            .[Module] = MODULE_IDB,
            .Entity = PAGE_IDB_ATTRIBUTES
        }},
        {PAGE_GI_RELATIONS,
        New DetailSettings With {
            .GridTitle = "Globix profile-relations",
            .NewRecordTitle = "",
            .[Module] = MODULE_GI,
            .Entity = PAGE_GI_RELATIONS
        }},
        {PAGE_IDB_DOCTYPE_CONFIG,
        New DetailSettings With {
            .GridTitle = "Doctype Configuration",
            .NewRecordTitle = "New Configuration",
            .[Module] = MODULE_IDB,
            .Entity = PAGE_IDB_DOCTYPE_CONFIG
        }}
    }

    Public Sub New(LogConfig As Modules.Logging.LogConfig)
        MyBase.New(LogConfig)
    End Sub

    Public Function Handle_OpenDetail(PrimaryKey As Integer, Page As String, IsInsert As Boolean) As Boolean
        Select Case Page
            Case PAGE_IDB_ATTRIBUTES
                Load_IDBAttribute(PrimaryKey, IsInsert)
                Return True

            Case PAGE_IDB_BUSINESS_ENTITIES
                Load_IDBEntity(PrimaryKey, IsInsert)
                Return True

            Case PAGE_IDB_OBJECT_STORES
                Load_IDBObjectstore(PrimaryKey, IsInsert)
                Return True

            Case PAGE_CW_PROFILES
                Load_CWProfile(PrimaryKey, IsInsert)
                Return True

            Case PAGE_GI_PROFILES
                GLOBIX_JUMP_DOCTYPE_ID = PrimaryKey
                Load_GLOBIXProfile(PrimaryKey, IsInsert)
                Return True

            Case PAGE_META_SOURCE_SQL
                Load_SourceSQL(PrimaryKey, IsInsert)
                Return True
            Case PAGE_IDB_ATTRIBUTE_REL
                Dim oForm As New frmAdmin_IDBBERelations
                oForm.ShowDialog()
                Return True
            Case PAGE_GI_RELATIONS
                Dim oForm As New frmAdmin_GlobixRelations
                oForm.ShowDialog()
                Return True
            Case PAGE_IDB_DOCTYPE_CONFIG
                Dim oForm As New frmAdmin_DoctypeConfig(PrimaryKey) With {.IsInsert = IsInsert}
                oForm.ShowDialog()
            Case Else
                Return False
        End Select
    End Function

    Private Sub Load_SourceSQL(PrimaryKey As Integer, IsInsert As Boolean)
        Try
            Dim oForm As New frmAdmin_SourceSQL(PrimaryKey) With {.IsInsert = IsInsert}
            oForm.ShowDialog()

            RaiseEvent DetailFormClosed(Me, oForm)
        Catch ex As Exception
            Logger.Error(ex)
            Throw ex
        End Try
    End Sub

    Private Sub Load_IDBAttribute(PrimaryKey As Integer, IsInsert As Boolean)
        Try
            Dim oForm As New frmAdmin_IDBAttribute(PrimaryKey) With {.IsInsert = IsInsert}
            oForm.ShowDialog()

            RaiseEvent DetailFormClosed(Me, oForm)
        Catch ex As Exception
            Logger.Error(ex)
            Throw ex
        End Try
    End Sub
    Private Sub Load_IDBObjectstore(PrimaryKey As Integer, IsInsert As Boolean)
        Try
            Dim oForm As New frmAdmin_IDBObjectStore(PrimaryKey) With {.IsInsert = IsInsert}
            oForm.ShowDialog()

            RaiseEvent DetailFormClosed(Me, oForm)
        Catch ex As Exception
            Logger.Error(ex)
            Throw ex
        End Try
    End Sub

    Private Sub Load_IDBEntity(PrimaryKey As Integer, IsInsert As Boolean)
        Try
            Dim oForm As New frmAdmin_IDBEntity(PrimaryKey) With {.IsInsert = IsInsert}
            oForm.ShowDialog()

            RaiseEvent DetailFormClosed(Me, oForm)
        Catch ex As Exception
            Logger.Error(ex)
            Throw ex
        End Try
    End Sub

    Private Sub Load_CWProfile(PrimaryKey As Integer, IsInsert As Boolean)
        Try
            Dim oForm As New frmAdmin_ClipboardWatcher(PrimaryKey) With {.IsInsert = IsInsert}
            oForm.ShowDialog()

            RaiseEvent DetailFormClosed(Me, oForm)
        Catch ex As Exception
            Logger.Error(ex)
            Throw ex
        End Try
    End Sub
    Private Sub Load_GLOBIXProfile(PrimaryKey As Integer, IsInsert As Boolean)
        Try
            Dim oForm As New frmAdmin_Globix(PrimaryKey) With {.IsInsert = IsInsert}
            oForm.ShowDialog()

            RaiseEvent DetailFormClosed(Me, oForm)
        Catch ex As Exception
            Logger.Error(ex)
            Throw ex
        End Try
    End Sub

    Public Class DetailSettings
        Public Property GridTitle As String
        Public Property [Module] As String
        Public Property Entity As String
        Public Property NewRecordTitle As String
    End Class

    Public Class DetailData
        Public Property Guid As Integer
        Public Property ParentId As Integer
        Public Property Entity As String
        Public Property Scope As String
        Public Property PrimaryKey As String
        Public Property SQLCommand As String
        Public Property SQLResult As DataTable
    End Class
End Class
