From 896426da3baae5c6f9cd3d1e118884e780d2d34c Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 11 Mar 2019 14:49:48 +0100 Subject: [PATCH] Improve Base Form Properties, Improve PanelManager --- EDMI_ClientSuite/ClassErrorHandler.vb | 9 ++-- EDMI_ClientSuite/ClassPanelManager.vb | 38 ++++++++++++++--- EDMI_ClientSuite/ClientSuite.vbproj | 1 - EDMI_ClientSuite/FormDefaults/BaseForm.vb | 14 ++++++- .../FormDefaults/BaseRibbonForm.vb | 21 +++++++++- EDMI_ClientSuite/Panels/BasePanel.vb | 1 + .../Panels/DocumentPanel.Designer.vb | 42 +++++++++---------- EDMI_ClientSuite/Panels/DocumentPanel.vb | 14 +++++++ EDMI_ClientSuite/Panels/IPanel.vb | 3 -- EDMI_ClientSuite/Panels/PanelInfo.vb | 27 ++++++++++-- EDMI_ClientSuite/_TEST/frmDocTest.vb | 2 +- EDMI_ClientSuite/_TEST/frmFileTest.vb | 8 ++-- EDMI_ClientSuite/frmMain.vb | 8 ++-- EDMI_ClientSuite/frmObjectEditor.vb | 6 +-- EDMI_ClientSuite/frmSearch.vb | 12 ++++-- 15 files changed, 145 insertions(+), 61 deletions(-) delete mode 100644 EDMI_ClientSuite/Panels/IPanel.vb diff --git a/EDMI_ClientSuite/ClassErrorHandler.vb b/EDMI_ClientSuite/ClassErrorHandler.vb index 1a8dc024..bceded3f 100644 --- a/EDMI_ClientSuite/ClassErrorHandler.vb +++ b/EDMI_ClientSuite/ClassErrorHandler.vb @@ -10,6 +10,10 @@ Public Class ClassErrorHandler Public Sub New(Logger As Logger) _Logger = Logger End Sub + Public Sub ShowErrorMessage(Exception As Exception) + _Logger.Error(Exception) + MsgBox(GetMessage(Exception), MsgBoxStyle.Critical, "Unexpected Error") + End Sub Private Function GetMessage(Exception As Exception) Dim oTargetSite = Exception.TargetSite @@ -34,11 +38,6 @@ Public Class ClassErrorHandler Return oMessage End Function - Public Sub ShowErrorMessage(Exception As Exception) - _Logger.Error(Exception) - MsgBox(GetMessage(Exception), MsgBoxStyle.Critical, "Unexpected Error") - End Sub - Private Function GetMethodName(Exception As Exception) As String Dim oMethodName = Exception.TargetSite?.ReflectedType?.Name diff --git a/EDMI_ClientSuite/ClassPanelManager.vb b/EDMI_ClientSuite/ClassPanelManager.vb index 38740535..b740f3d1 100644 --- a/EDMI_ClientSuite/ClassPanelManager.vb +++ b/EDMI_ClientSuite/ClassPanelManager.vb @@ -2,6 +2,7 @@ Imports DevExpress.XtraBars.Docking2010 Imports DevExpress.XtraBars.Docking2010.Views Imports DevExpress.XtraBars.Docking2010.Views.Tabbed +Imports DevExpress.XtraGrid Imports DigitalData.Modules.Logging Public Class ClassPanelManager @@ -88,17 +89,42 @@ Public Class ClassPanelManager ' TODO: determine how much panels at most can be added ' check if initial panels should be loaded For Each oPanelInfo As PanelInfo In oInitialPanelInfo - ' Create the control - Dim oControl = oPanelInfo.InnerControl - oControl.Dock = DockStyle.Fill - - ' Create the panel and add the control + ' create the panel Dim oPanel = _dockManager.AddPanel(oPanelInfo.Position) + + ' create the control + Dim oControl As BasePanel = GetPanelControl(oPanelInfo) + + If oControl Is Nothing Then + Dim oPanelType = oPanelInfo.PanelControl.GetType.ToString + _logger.Warn("Unknown panel type {0}", oPanelType) + Continue For + End If + + ' configure the panel + oPanel.Options.ShowCloseButton = oPanelInfo.CanBeClosed + oPanel.Options.ShowAutoHideButton = oPanelInfo.CanBePinned + oPanel.Options.ShowMaximizeButton = oPanelInfo.CanBeMaximized + oPanel.Options.AllowFloating = oPanelInfo.CanBeUndocked + + ' hashcode is needed to know which form a panel belongs to oPanel.Tag = oForm.GetHashCode - oPanel.Text = oPanelInfo.Caption + oPanel.Text = oPanelInfo.Title oPanel.Controls.Add(oControl) Next ' TODO: establish communication channel to load panels on-demand End Sub + + Private Function GetPanelControl(PanelInfo As PanelInfo) As BasePanel + If TypeOf PanelInfo.PanelControl Is DocumentPanel Then + Dim oPanelControl As DocumentPanel = DirectCast(PanelInfo.PanelControl, DocumentPanel) + oPanelControl.Datasource = PanelInfo.Datasource + oPanelControl.Dock = DockStyle.Fill + + Return oPanelControl + Else + Return Nothing + End If + End Function End Class diff --git a/EDMI_ClientSuite/ClientSuite.vbproj b/EDMI_ClientSuite/ClientSuite.vbproj index 3f30d0fa..8a291d82 100644 --- a/EDMI_ClientSuite/ClientSuite.vbproj +++ b/EDMI_ClientSuite/ClientSuite.vbproj @@ -159,7 +159,6 @@ UserControl - DockManagerTest.vb diff --git a/EDMI_ClientSuite/FormDefaults/BaseForm.vb b/EDMI_ClientSuite/FormDefaults/BaseForm.vb index b40c8eb1..d647492e 100644 --- a/EDMI_ClientSuite/FormDefaults/BaseForm.vb +++ b/EDMI_ClientSuite/FormDefaults/BaseForm.vb @@ -14,8 +14,14 @@ Imports DigitalData.Modules.Logging Public Class BaseForm Inherits Form - Protected ReadOnly _Logger As Logger - Protected ReadOnly _ErrorHandler As ClassErrorHandler + Private ReadOnly _Logger As Logger + Private ReadOnly _ErrorHandler As ClassErrorHandler + + Protected ReadOnly Property Logger As Logger + Get + Return _Logger + End Get + End Property Public Sub New() ' Get the full name of the inheriting form @@ -30,4 +36,8 @@ Public Class BaseForm ' depends on a global var like My.LogConfig ' you might need to check for its existence with ? End Sub + + Public Sub ShowErrorMessage(Exception As Exception) + _ErrorHandler.ShowErrorMessage(Exception) + End Sub End Class \ No newline at end of file diff --git a/EDMI_ClientSuite/FormDefaults/BaseRibbonForm.vb b/EDMI_ClientSuite/FormDefaults/BaseRibbonForm.vb index 10fcc0ff..b130bb3f 100644 --- a/EDMI_ClientSuite/FormDefaults/BaseRibbonForm.vb +++ b/EDMI_ClientSuite/FormDefaults/BaseRibbonForm.vb @@ -17,8 +17,14 @@ Imports DigitalData.Modules.Logging Public Class BaseRibbonForm Inherits RibbonForm - Protected ReadOnly _Logger As Logger - Protected ReadOnly _ErrorHandler As ClassErrorHandler + Private ReadOnly _Logger As Logger + Private ReadOnly _ErrorHandler As ClassErrorHandler + + Protected ReadOnly Property Logger As Logger + Get + Return _Logger + End Get + End Property Public Sub New() ' Get the full name of the inheriting form @@ -34,6 +40,17 @@ Public Class BaseRibbonForm ' you might need to check for its existence with ? End Sub + Public Sub ShowErrorMessage(Exception As Exception) + _ErrorHandler.ShowErrorMessage(Exception) + End Sub + + ''' + ''' Returns a list of panels that will be show when the form is opened. + ''' This can be overridden by all inheriting forms to extend the list of panels + ''' Panels will be created by PanelManager. + ''' + ''' + ''' A list of PanelInformation Public Overridable Function GetInitialPanels() As List(Of PanelInfo) Return New List(Of PanelInfo) End Function diff --git a/EDMI_ClientSuite/Panels/BasePanel.vb b/EDMI_ClientSuite/Panels/BasePanel.vb index a3733566..86707bbc 100644 --- a/EDMI_ClientSuite/Panels/BasePanel.vb +++ b/EDMI_ClientSuite/Panels/BasePanel.vb @@ -1,3 +1,4 @@ Public Class BasePanel + Public Property Caption As String End Class diff --git a/EDMI_ClientSuite/Panels/DocumentPanel.Designer.vb b/EDMI_ClientSuite/Panels/DocumentPanel.Designer.vb index 0451c34f..05bf67b9 100644 --- a/EDMI_ClientSuite/Panels/DocumentPanel.Designer.vb +++ b/EDMI_ClientSuite/Panels/DocumentPanel.Designer.vb @@ -1,6 +1,6 @@  _ Partial Class DocumentPanel - Inherits System.Windows.Forms.UserControl + Inherits BasePanel 'UserControl überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. _ @@ -22,40 +22,40 @@ Partial Class DocumentPanel 'Das Bearbeiten mit dem Code-Editor ist nicht möglich. _ Private Sub InitializeComponent() - Me.GridControl1 = New DevExpress.XtraGrid.GridControl() - Me.GridView1 = New DevExpress.XtraGrid.Views.Grid.GridView() - CType(Me.GridControl1, System.ComponentModel.ISupportInitialize).BeginInit() - CType(Me.GridView1, System.ComponentModel.ISupportInitialize).BeginInit() + Me.GridControlMain = New DevExpress.XtraGrid.GridControl() + Me.GridViewMain = New DevExpress.XtraGrid.Views.Grid.GridView() + CType(Me.GridControlMain, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.GridViewMain, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' - 'GridControl1 + 'GridControlMain ' - Me.GridControl1.Dock = System.Windows.Forms.DockStyle.Fill - Me.GridControl1.Location = New System.Drawing.Point(0, 0) - Me.GridControl1.MainView = Me.GridView1 - Me.GridControl1.Name = "GridControl1" - Me.GridControl1.Size = New System.Drawing.Size(1027, 383) - Me.GridControl1.TabIndex = 0 - Me.GridControl1.ViewCollection.AddRange(New DevExpress.XtraGrid.Views.Base.BaseView() {Me.GridView1}) + Me.GridControlMain.Dock = System.Windows.Forms.DockStyle.Fill + Me.GridControlMain.Location = New System.Drawing.Point(0, 0) + Me.GridControlMain.MainView = Me.GridViewMain + Me.GridControlMain.Name = "GridControlMain" + Me.GridControlMain.Size = New System.Drawing.Size(1027, 383) + Me.GridControlMain.TabIndex = 0 + Me.GridControlMain.ViewCollection.AddRange(New DevExpress.XtraGrid.Views.Base.BaseView() {Me.GridViewMain}) ' - 'GridView1 + 'GridViewMain ' - Me.GridView1.GridControl = Me.GridControl1 - Me.GridView1.Name = "GridView1" + Me.GridViewMain.GridControl = Me.GridControlMain + Me.GridViewMain.Name = "GridViewMain" ' 'DocumentPanel ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.Controls.Add(Me.GridControl1) + Me.Controls.Add(Me.GridControlMain) Me.Name = "DocumentPanel" Me.Size = New System.Drawing.Size(1027, 383) - CType(Me.GridControl1, System.ComponentModel.ISupportInitialize).EndInit() - CType(Me.GridView1, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.GridControlMain, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.GridViewMain, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub - Friend WithEvents GridControl1 As DevExpress.XtraGrid.GridControl - Friend WithEvents GridView1 As DevExpress.XtraGrid.Views.Grid.GridView + Friend WithEvents GridControlMain As DevExpress.XtraGrid.GridControl + Friend WithEvents GridViewMain As DevExpress.XtraGrid.Views.Grid.GridView End Class diff --git a/EDMI_ClientSuite/Panels/DocumentPanel.vb b/EDMI_ClientSuite/Panels/DocumentPanel.vb index 73aca527..a1ac3cf3 100644 --- a/EDMI_ClientSuite/Panels/DocumentPanel.vb +++ b/EDMI_ClientSuite/Panels/DocumentPanel.vb @@ -1,12 +1,26 @@ Imports DevExpress.XtraGrid +Imports DevExpress.XtraGrid.Views.Grid +Imports DigitalData.GUIs.ClientSuite Public Class DocumentPanel Inherits BasePanel + Public WriteOnly Property Datasource As DataTable + Set(value As DataTable) + GridControlMain.DataSource = value + End Set + End Property + Private Sub DocumentPanel_Load(sender As Object, e As EventArgs) Handles Me.Load Dim oGridPatcher As New ClassControlPatcher(Of GridControl)(Me) oGridPatcher. ProcessContainer(AddressOf GridControlDefaults.DefaultGridSettings). ProcessContainer(AddressOf GridControlDefaults.ReadOnlyGridSettings) End Sub + + Private Sub GridViewMain_RowClick(sender As Object, e As RowClickEventArgs) Handles GridViewMain.RowClick + If e.Button = MouseButtons.Left And e.Clicks = 2 Then + MsgBox("Open Preview") + End If + End Sub End Class diff --git a/EDMI_ClientSuite/Panels/IPanel.vb b/EDMI_ClientSuite/Panels/IPanel.vb deleted file mode 100644 index 17fd6f87..00000000 --- a/EDMI_ClientSuite/Panels/IPanel.vb +++ /dev/null @@ -1,3 +0,0 @@ -Public Interface IPanel - ReadOnly Property PanelName As String -End Interface diff --git a/EDMI_ClientSuite/Panels/PanelInfo.vb b/EDMI_ClientSuite/Panels/PanelInfo.vb index 6a43a203..b72b2fad 100644 --- a/EDMI_ClientSuite/Panels/PanelInfo.vb +++ b/EDMI_ClientSuite/Panels/PanelInfo.vb @@ -1,7 +1,26 @@ Imports DevExpress.XtraBars.Docking Public Class PanelInfo - Public Caption As String - Public InnerControl As BasePanel - Public Position As DockingStyle -End Class + Public ReadOnly Title As String + Public ReadOnly PanelControl As BasePanel + Public ReadOnly Position As DockingStyle + Public ReadOnly Datasource As DataTable + + Public CanBeClosed As Boolean = True + Public CanBePinned As Boolean = True + Public CanBeUndocked As Boolean = True + Public CanBeMaximized As Boolean = True + + Public Sub New(PanelControl As BasePanel, Position As DockingStyle) + Me.Title = PanelControl.Caption + Me.PanelControl = PanelControl + Me.Position = Position + End Sub + + Public Sub New(PanelControl As BasePanel, Position As DockingStyle, Datasource As DataTable) + Me.Title = PanelControl.Caption + Me.PanelControl = PanelControl + Me.Position = Position + Me.Datasource = Datasource + End Sub +End Class \ No newline at end of file diff --git a/EDMI_ClientSuite/_TEST/frmDocTest.vb b/EDMI_ClientSuite/_TEST/frmDocTest.vb index b178e7c0..cd000db4 100644 --- a/EDMI_ClientSuite/_TEST/frmDocTest.vb +++ b/EDMI_ClientSuite/_TEST/frmDocTest.vb @@ -32,7 +32,7 @@ Public Class frmDocTest GridControl1.DataSource = oDatatable Catch ex As Exception - _ErrorHandler.ShowErrorMessage(ex) + ShowErrorMessage(ex) End Try End Sub diff --git a/EDMI_ClientSuite/_TEST/frmFileTest.vb b/EDMI_ClientSuite/_TEST/frmFileTest.vb index 14150ab0..ed8ab66b 100644 --- a/EDMI_ClientSuite/_TEST/frmFileTest.vb +++ b/EDMI_ClientSuite/_TEST/frmFileTest.vb @@ -11,7 +11,7 @@ Public Class frmFileTest _fileOp = New Document(My.LogConfig, My.Settings.EDM_NetworkService_Adress) Catch ex As Exception - _Logger.Warn($"Unexpected error in frmFileTest_Load: {ex.Message}") + Logger.Warn($"Unexpected error in frmFileTest_Load: {ex.Message}") End Try End Sub @@ -38,7 +38,7 @@ Public Class frmFileTest listboxLog.Items.Add($"----------------------------------------------------------") Catch ex As Exception MsgBox(ex.Message) - _Logger.Error(ex) + Logger.Error(ex) End Try End Sub @@ -60,7 +60,7 @@ Public Class frmFileTest listboxLog.Items.Add($"Filename: {oDocObject.FileName}") listboxLog.Items.Add($"----------------------------------------------------------") Catch ex As Exception - _ErrorHandler.ShowErrorMessage(ex) + ShowErrorMessage(ex) End Try End Sub @@ -82,7 +82,7 @@ Public Class frmFileTest listboxLog.Items.Add($"Filename: {oDocObject.FileName}") listboxLog.Items.Add($"----------------------------------------------------------") Catch ex As Exception - _ErrorHandler.ShowErrorMessage(ex) + ShowErrorMessage(ex) End Try End Sub End Class \ No newline at end of file diff --git a/EDMI_ClientSuite/frmMain.vb b/EDMI_ClientSuite/frmMain.vb index ac97cb01..9c7e147a 100644 --- a/EDMI_ClientSuite/frmMain.vb +++ b/EDMI_ClientSuite/frmMain.vb @@ -68,7 +68,7 @@ Public Class frmMain ' We're done loading now _Loading = False Catch ex As Exception - _ErrorHandler.ShowErrorMessage(ex) + ShowErrorMessage(ex) End Try End Sub @@ -96,7 +96,7 @@ Public Class frmMain 'DocumentManager.View.RestoreLayoutFromXml(oLayoutPathForDocumentManager) End If Catch ex As Exception - _ErrorHandler.ShowErrorMessage(ex) + ShowErrorMessage(ex) End Try End Sub Private Sub SaveLayout() @@ -112,7 +112,7 @@ Public Class frmMain 'DockManager.SaveLayoutToXml(oLayoutPathForDockManager) 'DocumentManager.View.SaveLayoutToXml(oLayoutPathForDocumentManager) Catch ex As Exception - _ErrorHandler.ShowErrorMessage(ex) + ShowErrorMessage(ex) End Try End Sub @@ -197,8 +197,6 @@ Public Class frmMain End Sub Private Sub MainNav_SelectedItemChanging(sender As Object, e As DevExpress.XtraBars.Navigation.SelectedItemChangingEventArgs) Handles MainNav.SelectedItemChanging - - Select Case e.Item.Name Case NavbarItemHome.Name Dim oForm As New frmHome() diff --git a/EDMI_ClientSuite/frmObjectEditor.vb b/EDMI_ClientSuite/frmObjectEditor.vb index b71888b1..a78a601a 100644 --- a/EDMI_ClientSuite/frmObjectEditor.vb +++ b/EDMI_ClientSuite/frmObjectEditor.vb @@ -32,7 +32,7 @@ Public Class frmObjectEditor } If _Datatable Is Nothing Then - _ErrorHandler.ShowErrorMessage(New ArgumentNullException("Datatable is empty")) + ShowErrorMessage(New ArgumentNullException("Datatable is empty")) End If End Sub @@ -54,7 +54,7 @@ Public Class frmObjectEditor Await LoadLanguageTableAsync(My.Application.User.Language) LoadDetailForm() Catch ex As Exception - _ErrorHandler.ShowErrorMessage(ex) + ShowErrorMessage(ex) End Try End Sub @@ -110,7 +110,7 @@ Public Class frmObjectEditor Await My.Channel.CloseDatabaseRequestAsync() Catch ex As Exception - _ErrorHandler.ShowErrorMessage(ex) + ShowErrorMessage(ex) End Try End Function diff --git a/EDMI_ClientSuite/frmSearch.vb b/EDMI_ClientSuite/frmSearch.vb index 4bf00a18..9086accc 100644 --- a/EDMI_ClientSuite/frmSearch.vb +++ b/EDMI_ClientSuite/frmSearch.vb @@ -16,11 +16,15 @@ Public Class frmSearch Public Overrides Function GetInitialPanels() As List(Of PanelInfo) Dim oList = MyBase.GetInitialPanels() + Dim oPanel = New DocumentPanel() + Dim oData As DataTable - oList.Add(New PanelInfo() With { - .Caption = "Search", - .InnerControl = New DocumentPanel(), - .Position = DockingStyle.Bottom + My.Channel.CreateDatabaseRequest("Get Users", False) + oData = My.Channel.ReturnDatatable("SELECT * FROM VWICM_USER").Table + My.Channel.CloseDatabaseRequest() + + oList.Add(New PanelInfo(oPanel, DockingStyle.Bottom, oData) With { + .CanBeClosed = False }) Return oList