Modules/GUIs.ZooFlow/Administration/frmAdmin_Start.vb
2021-02-19 16:13:03 +01:00

304 lines
11 KiB
VB.net

Imports DevExpress.Utils
Imports DevExpress.XtraBars.Docking2010.Views
Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraGrid
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 IDB_START = "IDB_START"
Private Const IDB_ATTRIBUTES = "IDB_ATTRIBUTES"
Private Const IDB_BUSINESS_ENTITY = "IDB_BUSINESS_ENTITY"
Private Const IDB_SOURCE_SQL = "IDB_SOURCE_SQL"
Private Const GLOBIX_PROFILES = "GLOBIX_PROFILES"
Private Const CW_PROFILES = "CW_PROFILES"
Private PrimaryKey As String = Nothing
Private SourceCommands As New Dictionary(Of String, SourceSql)
Private CurrentPage As String
Private Class SourceSql
Public Title As String
Public SQL As String
Public PrimaryKey As String
End Class
Private Sub frmAdministration_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Load_SQLData()
TreeListMenu.ExpandAll()
' Show Tab Header in Development, hide when running the app
XtraTabControl.ShowTabHeader = DefaultBoolean.False
End Sub
Private Function Load_SQLData() As Boolean
Try
Dim oTable As DataTable = My.Database.GetDatatable("SELECT * FROM TBZF_ADMIN_SOURCE_SQL")
SourceCommands.Clear()
For Each oRow As DataRow In oTable.Rows
Dim oSource As New SourceSql With {
.PrimaryKey = oRow.Item("PK_COLUMN").ToString,
.SQL = oRow.Item("SQL_COMMAND").ToString,
.Title = oRow.Item("ENTITY_TITLE").ToString
}
SourceCommands.Add(oRow.Item("ENTITY_TITLE").ToString, oSource)
Next
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function
Sub Display_Tab(pPageToDisplay As XtraTabPage)
Try
If pPageToDisplay.TabControl Is Nothing Then
Exit Sub
End If
For Each oDocument As XtraTabPage In pPageToDisplay.TabControl.TabPages
If oDocument.Name = pPageToDisplay.Name Then
oDocument.PageVisible = True
Else
oDocument.PageVisible = False
End If
Next
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Sub Display_RibbonPage(PageToDisplay As RibbonPage)
Try
For Each oPage As RibbonPage In RibbonControl1.Pages
If oPage.Name = PageToDisplay.Name Then
RibbonControl1.SelectedPage = PageToDisplay
End If
Next
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub TreeList1_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
Exit Sub
End If
CurrentPage = e.Node.Tag.ToString
Dim oSource As SourceSql
If SourceCommands.ContainsKey(CurrentPage) Then
oSource = SourceCommands.Item(CurrentPage)
End If
Select Case e.Node.Tag.ToString
Case IDB_START
Display_Tab(XtraTabPage_IDB)
Case IDB_ATTRIBUTES
Display_Tab(XtraTabPage_IDB)
Display_Tab(XtraTabPageIDB_Attributes_New)
Dim oTable As DataTable = My.Database.GetDatatable(oSource.SQL)
Load_Grid(oTable, oSource.PrimaryKey, GridAttributes)
Case IDB_BUSINESS_ENTITY
'DisplayTab(XtraTabPage_Entities)
Case GLOBIX_PROFILES
Display_Tab(XtraTabPage_GlobalIndexer)
Display_RibbonPage(RibbonPage_GlobalIndexer)
Case CW_PROFILES
Display_Tab(XtraTabPage_ClipboardWatcher)
Display_Tab(XtraTabPageCWProfiles)
Display_RibbonPage(RibbonPage_ClipboardWatcher)
Dim oTable As DataTable = My.Database.GetDatatable(oSource.SQL)
Load_Grid(oTable, oSource.PrimaryKey, GridCWProfiles)
Case IDB_SOURCE_SQL
Display_Tab(XtraTabPage_IDB)
Display_Tab(XtraTabPageIDB_SourceSQL)
Dim oTable As DataTable = My.Database.GetDatatable(oSource.SQL)
Load_Grid(oTable, oSource.PrimaryKey, GridSourceSQL)
End Select
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub Load_Grid(DataSource As DataTable, PrimaryKey As String, GridControl As GridControl)
Try
Me.PrimaryKey = PrimaryKey
GridControl.DataSource = DataSource
GridControl.ForceInitialize()
Dim oGridView = DirectCast(GridControl.DefaultView, GridView)
With oGridView.Appearance.EvenRow
.BackColor = Color.Gainsboro
.Options.UseBackColor = True
End With
With oGridView.Appearance.FocusedCell
.BackColor = Color.Gold
.Options.UseBackColor = True
End With
With oGridView.Appearance.FocusedRow
.BackColor = Color.Gold
.Options.UseBackColor = True
End With
With oGridView.OptionsBehavior
.Editable = False
.ReadOnly = True
End With
With oGridView.OptionsClipboard
.CopyColumnHeaders = DefaultBoolean.False
End With
With oGridView.OptionsFind
.AlwaysVisible = True
End With
With oGridView.OptionsView
.ShowAutoFilterRow = True
.EnableAppearanceEvenRow = True
.ShowIndicator = False
End With
AddHandler oGridView.KeyDown, Sub(sender As Object, e As KeyEventArgs)
Dim oView As GridView = DirectCast(sender, GridView)
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
oGridView.BestFitColumns()
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub View_DoubleClick(sender As Object, e As EventArgs) Handles _
ViewAttributes.DoubleClick, ViewSourceSQL.DoubleClick, ViewCWProfiles.DoubleClick
Dim oView As GridView = TryCast(sender, GridView)
Dim hitInfo As GridHitInfo = oView.CalcHitInfo(TryCast(e, DXMouseEventArgs).Location)
If hitInfo.InDataRow Then
Try
Dim oRow As DataRow = oView.GetFocusedDataRow
If oRow IsNot Nothing Then
Dim oPrimaryKey As Integer = oRow.Item(PrimaryKey)
Select Case oView.Name
Case ViewAttributes.Name
Load_Attribute(oPrimaryKey)
Case ViewSourceSQL.Name
Load_SourceSql(oPrimaryKey)
Case ViewCWProfiles.Name
Load_CWProfile(oPrimaryKey)
End Select
End If
Catch ex As Exception
ShowError(ex)
End Try
End If
End Sub
Private Sub Load_Attribute(PrimaryKey As Integer)
Try
Dim oForm As New frmAdmin_IDBAttribute(PrimaryKey)
oForm.ShowDialog()
If oForm.HasChanges Then
Dim oSource As SourceSql = SourceCommands.Item(CurrentPage)
Dim oTable As DataTable = My.Database.GetDatatable(oSource.SQL)
Load_Grid(oTable, oSource.PrimaryKey, GridAttributes)
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
Dim oSource As SourceSql = SourceCommands.Item(CurrentPage)
Dim oTable As DataTable = My.Database.GetDatatable(oSource.SQL)
Load_Grid(oTable, oSource.PrimaryKey, GridSourceSQL)
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
Dim oSource As SourceSql = SourceCommands.Item(CurrentPage)
Dim oTable As DataTable = My.Database.GetDatatable(oSource.SQL)
Load_Grid(oTable, oSource.PrimaryKey, GridCWProfiles)
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 = ViewAttributes.GetFocusedDataRow
If oRow IsNot Nothing Then
Dim oPrimaryKey As Integer = oRow.Item(PrimaryKey)
Load_Attribute(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