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 = "IDB 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 = "IDB Entitäten",
            .NewRecordTitle = "Neue Entität",
            .[Module] = MODULE_IDB,
            .Entity = PAGE_IDB_BUSINESS_ENTITIES
        }},
        {PAGE_META_SOURCE_SQL,
        New DetailSettings With {
            .GridTitle = "Source SQL",
            .NewRecordTitle = "Neuer Source SQL",
            .[Module] = MODULE_META,
            .Entity = PAGE_META_SOURCE_SQL
        }},
        {PAGE_GLOBIX_PROFILES,
        New DetailSettings With {
            .GridTitle = "Global Indexer Profile",
            .NewRecordTitle = "Neues GLOBIX Profil",
            .[Module] = MODULE_GLOBIX,
            .Entity = PAGE_GLOBIX_PROFILES
        }},
        {PAGE_CW_PROFILES,
        New DetailSettings With {
            .GridTitle = "Clipboard Watcher Profile",
            .NewRecordTitle = "Neues CW Profil",
            .[Module] = MODULE_CW,
            .Entity = PAGE_CW_PROFILES
        }}
    }

    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_CW_PROFILES
                Load_CWProfile(PrimaryKey, IsInsert)
                Return True

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

            Case PAGE_META_SOURCE_SQL
                Load_SourceSQL(PrimaryKey, IsInsert)
                Return True

            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_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 frmGlobixAdministration(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 ForeignKey As String
        Public Property SQLCommand As String
        Public Property SQLResult As DataTable
    End Class
End Class
