Modules/GUIs.ZooFlow/Administration/frmAdmin_Start.vb
2021-04-08 16:57:57 +02:00

378 lines
13 KiB
VB.net

Imports DevExpress.Utils
Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.XtraTab
Imports DigitalData.Modules.Logging
Public Class frmAdmin_Start
Inherits frmAdmin_Base
Private Const COLUMN_NAME_ACTIVE = "ACTIVE"
Private Const MODULE_IDB = "IDB"
Private Const PAGE_IDB_START = "IDB_START"
Private Const PAGE_IDB_ATTRIBUTES = "IDB_ATTRIBUTES"
Private Const PAGE_IDB_BUSINESS_ENTITIES = "IDB_BUSINESS_ENTITIES"
Private Const PAGE_IDB_SOURCE_SQL = "IDB_SOURCE_SQL"
Private Const MODULE_GLOBIX = "GLOBIX"
Private Const PAGE_GLOBIX_PROFILES = "GLOBIX_PROFILES"
Private Const MODULE_CW = "CW"
Private Const PAGE_CW_PROFILES = "CW_PROFILES"
Private Const MODULE_META = "META"
Private Const PAGE_META_SOURCE_SQL = "META_SOURCE_SQL"
Private PrimaryKey As String = Nothing
Private AdminItems As New Dictionary(Of String, AdminItem)
Private AdminNodes As New Dictionary(Of String, AdminNode) From {
{PAGE_IDB_ATTRIBUTES,
New AdminNode With {
.Title = "IDB Attribute",
.[Module] = MODULE_IDB,
.Entity = PAGE_IDB_ATTRIBUTES
}},
{PAGE_IDB_BUSINESS_ENTITIES,
New AdminNode With {
.Title = "IDB Entitäten",
.[Module] = MODULE_IDB,
.Entity = PAGE_IDB_BUSINESS_ENTITIES
}},
{PAGE_META_SOURCE_SQL,
New AdminNode With {
.Title = "Source SQL",
.[Module] = MODULE_META,
.Entity = PAGE_META_SOURCE_SQL
}},
{PAGE_GLOBIX_PROFILES,
New AdminNode With {
.Title = "Global Indexer Profile",
.[Module] = MODULE_GLOBIX,
.Entity = PAGE_GLOBIX_PROFILES
}},
{PAGE_CW_PROFILES,
New AdminNode With {
.Title = "Clipboard Watcher Profile",
.[Module] = MODULE_CW,
.Entity = PAGE_CW_PROFILES
}}
}
Private CurrentModule As String
Private CurrentPage As String
Private CurrentItem As AdminItem
Private Class AdminNode
Public Property Title As String
Public Property [Module] As String
Public Property Entity As String
End Class
Private Class AdminItem
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
Private Sub frmAdministration_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Load_SQLData()
TreeListMenu.ExpandAll()
End Sub
Private Function Load_SQLData() As Boolean
Try
Dim oTable As DataTable = My.Database.GetDatatable("SELECT * FROM TBZF_ADMIN_SOURCE_SQL")
AdminItems.Clear()
For Each oRow As DataRow In oTable.Rows
Dim oItem As New AdminItem With {
.Guid = CInt(oRow.Item("GUID")),
.ParentId = CInt(oRow.Item("PARENT_ID")),
.Entity = oRow.Item("ENTITY_TITLE").ToString,
.Scope = oRow.Item("SCOPE").ToString,
.SQLCommand = oRow.Item("SQL_COMMAND").ToString,
.PrimaryKey = NotNull(oRow.Item("PK_COLUMN"), String.Empty),
.ForeignKey = NotNull(oRow.Item("FK_COLUMN"), String.Empty)
}
Try
oItem.SQLResult = My.Database.GetDatatable(oItem.SQLCommand)
Catch ex As Exception
oItem.SQLResult = Nothing
Logger.Error(ex)
End Try
AdminItems.Add(oItem.Entity, oItem)
Next
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function
Private Sub TreeListMenu_FocusedNodeChanged(sender As Object, e As DevExpress.XtraTreeList.FocusedNodeChangedEventArgs) Handles TreeListMenu.FocusedNodeChanged
Try
If e.Node Is Nothing OrElse e.Node.Tag Is Nothing Then
labelTitle.Text = "Start"
Exit Sub
End If
CurrentPage = e.Node.Tag.ToString
If AdminNodes.ContainsKey(CurrentPage) Then
Dim oNode = AdminNodes.Item(CurrentPage)
CurrentModule = oNode.Module
labelTitle.Text = oNode.Title
Else
MsgBox($"Page [{CurrentPage}] not found in AdminNodes! Exiting." & vbNewLine &
"Check your definitions in the TreeList NodeEditor and in SourceSQL", MsgBoxStyle.Critical, Text)
Exit Sub
End If
If AdminItems.ContainsKey(CurrentPage) Then
CurrentItem = AdminItems.Item(CurrentPage)
Load_GridData(CurrentItem)
Else
MsgBox($"Page [{CurrentPage}] not found in AdminItems! Exiting." & vbNewLine &
"Check your definitions in the TreeList NodeEditor and in SourceSQL", MsgBoxStyle.Critical, Text)
Exit Sub
End If
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub Style_ActiveColumn(ActiveColumn)
Dim oActiveEditor As New RepositoryItemImageComboBox With {
.SmallImages = ActiveImages,
.GlyphAlignment = HorzAlignment.Center
}
oActiveEditor.Buttons.Clear()
oActiveEditor.Items.AddRange(New List(Of ImageComboBoxItem) From {
New ImageComboBoxItem("Active", True, 0),
New ImageComboBoxItem("Inactive", False, 1)
})
With ActiveColumn
.Caption = " "
.Name = "columnActive"
.Visible = True
.VisibleIndex = 0
.ColumnEdit = oActiveEditor
.MaxWidth = 30
.MinWidth = 30
.Image = ActiveImages.GetImage(0)
.OptionsColumn.AllowEdit = False
End With
End Sub
Private Sub Load_GridData(Source As AdminItem)
If Source Is Nothing OrElse Source.SQLResult Is Nothing Then
Exit Sub
End If
GridControl1.DataSource = Source.SQLResult
GridControl1.ForceInitialize()
GridView1.PopulateColumns()
If GridView1.Columns.Item(COLUMN_NAME_ACTIVE) Is Nothing Then
Dim oActiveColumn = New GridColumn() With {.FieldName = COLUMN_NAME_ACTIVE}
GridView1.Columns.Add(oActiveColumn)
Style_ActiveColumn(oActiveColumn)
Else
Style_ActiveColumn(GridView1.Columns.Item(COLUMN_NAME_ACTIVE))
End If
With GridView1.Appearance.EvenRow
.BackColor = Color.Snow
.Options.UseBackColor = True
End With
With GridView1.Appearance.FocusedCell
.BackColor = Color.Gold
.Options.UseBackColor = True
End With
With GridView1.OptionsBehavior
.Editable = False
.ReadOnly = True
End With
With GridView1.OptionsView
.ShowAutoFilterRow = True
.EnableAppearanceEvenRow = True
.ShowIndicator = False
.ShowHorizontalLines = DefaultBoolean.True
.ShowVerticalLines = DefaultBoolean.True
End With
With GridView1.OptionsClipboard
.CopyColumnHeaders = DefaultBoolean.False
End With
With GridView1.OptionsFind
.AlwaysVisible = True
End With
AddHandler GridView1.KeyDown, Sub(sender As GridView, e As KeyEventArgs)
Dim oView As GridView = sender
If e.Control AndAlso e.KeyCode = Keys.C And e.Modifiers = Keys.Control Then
Dim oCellValue = oView.GetRowCellValue(oView.FocusedRowHandle, oView.FocusedColumn)
If oCellValue IsNot Nothing AndAlso oCellValue.ToString() <> String.Empty Then
Clipboard.SetText(oCellValue.ToString)
End If
e.Handled = True
End If
End Sub
GridView1.BestFitColumns()
End Sub
Private Sub GridView1_RowClick(sender As Object, e As RowClickEventArgs) Handles GridView1.RowClick
Try
If e.Clicks = 2 And e.Button = MouseButtons.Left Then
Dim oView As GridView = TryCast(sender, GridView)
Dim oRowView As DataRowView = oView.GetRow(e.RowHandle)
Dim oItem As AdminItem = CurrentItem
Dim oGuid = oRowView.Row.Item(oItem.PrimaryKey)
If oRowView IsNot Nothing Then
Select Case CurrentPage
Case PAGE_IDB_ATTRIBUTES
Load_IDBAttribute(oGuid)
Case PAGE_IDB_BUSINESS_ENTITIES
Load_IDBEntity(oGuid)
Case PAGE_CW_PROFILES
Load_CWProfile(oGuid)
Case PAGE_GLOBIX_PROFILES
GLOBIX_JUMP_DOCTYPE_ID = oGuid
Load_GLOBIXProfile(oGuid)
Case PAGE_META_SOURCE_SQL
Load_SourceSQL(oGuid)
Case Else
MsgBox($"The Form for the Tag [{CurrentPage}] has no Form assigned. Maybe you have a typo in your definitions (Database, NodeEditor)?", MsgBoxStyle.Exclamation, Text)
End Select
End If
End If
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub Load_SourceSQL(PrimaryKey As Integer)
Try
Dim oForm As New frmAdmin_SourceSQL(PrimaryKey)
oForm.ShowDialog()
If oForm.HasChanges Then
Load_SQLData()
Load_GridData(AdminItems.Item(CurrentPage))
End If
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub Load_IDBAttribute(PrimaryKey As Integer)
Try
Dim oForm As New frmAdmin_IDBAttribute(PrimaryKey)
oForm.ShowDialog()
If oForm.HasChanges Then
Load_SQLData()
Load_GridData(AdminItems.Item(CurrentPage))
End If
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub Load_IDBEntity(PrimaryKey As Integer)
Try
Dim oForm As New frmAdmin_IDBEntity(PrimaryKey)
oForm.ShowDialog()
If oForm.HasChanges Then
Load_SQLData()
Load_GridData(AdminItems.Item(CurrentPage))
End If
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub Load_CWProfile(PrimaryKey As Integer)
Try
Dim oForm As New frmAdmin_CWProfile(PrimaryKey)
oForm.ShowDialog()
If oForm.HasChanges Then
Load_SQLData()
Load_GridData(AdminItems.Item(CurrentPage))
End If
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub Load_GLOBIXProfile(PrimaryKey As Integer)
Try
Dim oForm As New frmGlobixAdministration(PrimaryKey)
oForm.ShowDialog()
If oForm.HasChanges Then
Load_SQLData()
Load_GridData(AdminItems.Item(CurrentPage))
End If
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub BarButtonItem7_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem7.ItemClick
Try
Dim oRow As DataRow = GridView1.GetFocusedRow
If oRow IsNot Nothing Then
Dim oPrimaryKey As Integer = DirectCast(oRow.Item(PrimaryKey), Integer)
Load_IDBAttribute(oPrimaryKey)
End If
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub BarButtonItem9_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem9.ItemClick
Load_SQLData()
ShowStatus("Source SQL neu geladen")
End Sub
Private Sub ShowStatus(v As String)
labelStatus.Caption = v
labelStatus.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
End Sub
Private Sub ResetStatus()
labelStatus.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
End Sub
End Class