Common: Configurable Column Names for Fixed Columns, Helpers for Error Messages, Checks for Datatable contents and environment
This commit is contained in:
@@ -21,10 +21,11 @@ Imports System.Threading
|
||||
Public Class frmDocumentResultList
|
||||
Implements IResultForm
|
||||
|
||||
Private Const COLUMN_ICON = "ICON"
|
||||
Private Const COLUMN_FILEPATH = "FULL_FILENAME"
|
||||
Private Const COLUMN_FILENAME = "Filename"
|
||||
Private Const COLUMN_DOCID = "DocID"
|
||||
|
||||
Private COLUMN_FILEPATH = "FULL_FILENAME"
|
||||
Private COLUMN_FILENAME = "Filename"
|
||||
Private COLUMN_DOCID = "DocID"
|
||||
Private COLUMN_ICON = "ICON"
|
||||
|
||||
Private _IsLoading As Boolean = True
|
||||
Private _IsLegacy As Boolean = True
|
||||
@@ -36,10 +37,10 @@ Public Class frmDocumentResultList
|
||||
Private _Environment As Environment
|
||||
Private _Params As DocumentResultParams
|
||||
Private _ResultLists As List(Of DocumentResult)
|
||||
Private _Helpers As DocumentResultList
|
||||
|
||||
Private _ActiveGrid As GridControl = Nothing
|
||||
Private _ActiveGridBand As GridBand = Nothing
|
||||
Private _ActiveRowHandle As Integer = Constants.NO_ROW_HANDLE
|
||||
|
||||
Private _DocumentInfo As DocumentInfo = Nothing
|
||||
|
||||
@@ -52,47 +53,29 @@ Public Class frmDocumentResultList
|
||||
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
||||
Dim oConfigPath As String = Path.Combine(Application.UserAppDataPath, "ResultList", Params.WindowGuid)
|
||||
|
||||
COLUMN_DOCID = Params.ColumnNames.ObjectIdColumn
|
||||
COLUMN_FILENAME = Params.ColumnNames.FilenameColumn
|
||||
COLUMN_FILEPATH = Params.ColumnNames.FullPathColumn
|
||||
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_Config = New ConfigManager(Of DocumentResultConfig)(LogConfig, oConfigPath, oConfigPath)
|
||||
_Helpers = New DocumentResultList(LogConfig)
|
||||
|
||||
_Environment = Environment
|
||||
_Params = Params
|
||||
_ResultLists = Params.Results
|
||||
Try
|
||||
Dim Culture = CultureInfo.CreateSpecificCulture(_Environment.User.Language)
|
||||
' The following line provides localization for the application's user interface.
|
||||
Thread.CurrentThread.CurrentUICulture = Culture
|
||||
' The following line provides localization for data formats.
|
||||
Thread.CurrentThread.CurrentCulture = Culture
|
||||
' Set this culture as the default culture for all threads in this application.
|
||||
' Note: The following properties are supported in the .NET Framework 4.5+
|
||||
CultureInfo.DefaultThreadCurrentCulture = Culture
|
||||
CultureInfo.DefaultThreadCurrentUICulture = Culture
|
||||
Culture.DateTimeFormat.ShortDatePattern = _Environment.User.DateFormat
|
||||
Catch ex As Exception
|
||||
_Logger.Warn($"Error loading CultureInfo: {ex.Message}")
|
||||
End Try
|
||||
MaybeInitIDB()
|
||||
End Sub
|
||||
|
||||
Private Sub MaybeInitIDB()
|
||||
_IsLegacy = Not _Environment.Service.IsActive
|
||||
If _Environment.Service.IsActive Then
|
||||
Dim oSplit As List(Of String) = _Environment.Service.Address.Split(":").ToList()
|
||||
Dim oAddress As String = oSplit.Item(0)
|
||||
Dim oPort As Integer = oSplit.Item(1)
|
||||
|
||||
_IDBClient = New Client(_LogConfig, oAddress, oPort)
|
||||
|
||||
If Not _IDBClient.Connect() Then
|
||||
_Logger.Warn("Client could not connect to Service at [{0}]", _Environment.Service.Address)
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub frmDocumentResultList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
Try
|
||||
MaybeInitIDB()
|
||||
|
||||
' Initialize Viewer with GDPicture.NET License
|
||||
If _Environment.Settings.GdPictureKey = String.Empty Then
|
||||
Throw New ApplicationException("GDPicture Licensekey is missing!")
|
||||
End If
|
||||
DocumentViewer1.Init(_LogConfig, _Environment.Settings.GdPictureKey)
|
||||
|
||||
' Load config
|
||||
SplitContainerControl1.SplitterPosition = _Config.Config.SplitContainer1Distance
|
||||
@@ -115,12 +98,6 @@ Public Class frmDocumentResultList
|
||||
SwitchDetailContainerHorizontal.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
|
||||
End If
|
||||
|
||||
'RibbonControl.Minimized = True
|
||||
|
||||
' Initialize Viewer with GDPicture.NET License
|
||||
DocumentViewer1.Init(_LogConfig, _Environment.Settings.GdPictureKey)
|
||||
|
||||
|
||||
AddHandler GridView1.FocusedRowChanged, AddressOf GridView_FocusedRowChanged
|
||||
AddHandler GridView2.FocusedRowChanged, AddressOf GridView_FocusedRowChanged
|
||||
AddHandler GridView3.FocusedRowChanged, AddressOf GridView_FocusedRowChanged
|
||||
@@ -136,9 +113,10 @@ Public Class frmDocumentResultList
|
||||
End Sub
|
||||
|
||||
Private Sub GridView_FocusedRowChanged(sender As GridView, e As FocusedRowChangedEventArgs)
|
||||
_ActiveRowHandle = e.FocusedRowHandle
|
||||
_Helpers.SetRowHandle(e)
|
||||
|
||||
Try
|
||||
Reset_Errors()
|
||||
Cursor = Cursors.WaitCursor
|
||||
|
||||
If e.FocusedRowHandle >= 0 Then
|
||||
@@ -151,6 +129,9 @@ Public Class frmDocumentResultList
|
||||
LoadFile_IDB(oRow)
|
||||
End If
|
||||
|
||||
If IsNothing(_DocumentInfo) Or DocumentViewer1.FileLoaded = False Then
|
||||
Show_Warning("File could not be loaded!")
|
||||
End If
|
||||
DocumentViewer1.LoadFile(_DocumentInfo.FullPath)
|
||||
|
||||
If _DocumentInfo.AccessRight = Rights.AccessRight.VIEW_ONLY Then
|
||||
@@ -163,12 +144,27 @@ Public Class frmDocumentResultList
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
MsgBox("Error while changing row: " & ex.Message, MsgBoxStyle.Critical, Text)
|
||||
Show_CriticalError(ex.Message)
|
||||
Finally
|
||||
Cursor = Cursors.Default
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub MaybeInitIDB()
|
||||
_IsLegacy = Not _Environment.Service.IsActive
|
||||
If _Environment.Service.IsActive Then
|
||||
Dim oSplit As List(Of String) = _Environment.Service.Address.Split(":").ToList()
|
||||
Dim oAddress As String = oSplit.Item(0)
|
||||
Dim oPort As Integer = oSplit.Item(1)
|
||||
|
||||
_IDBClient = New Client(_LogConfig, oAddress, oPort)
|
||||
|
||||
If Not _IDBClient.Connect() Then
|
||||
_Logger.Warn("Client could not connect to Service at [{0}]", _Environment.Service.Address)
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub LoadFile_Legacy(GridRow As DataRow)
|
||||
Try
|
||||
Dim oFullPath = GridRow.Item(COLUMN_FILEPATH)
|
||||
@@ -192,7 +188,6 @@ Public Class frmDocumentResultList
|
||||
_DocumentInfo = _IDBClient.GetDocumentInfo(_Environment.User.UserId, oObjectId)
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
MsgBox("Error while loading file", MsgBoxStyle.Critical, Text)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
@@ -276,7 +271,6 @@ Public Class frmDocumentResultList
|
||||
|
||||
labelResultCount.Caption = String.Format(labelResultCount.Caption, oTotalResults)
|
||||
End Sub
|
||||
|
||||
Private Sub UpdateGridHeader(pResultList As List(Of DocumentResult), pIndex As Integer, pCount As Integer)
|
||||
Select Case pIndex
|
||||
Case 0
|
||||
@@ -296,6 +290,14 @@ Public Class frmDocumentResultList
|
||||
Private Sub CreateDocumentGrid(GridView As GridView, Datatable As DataTable)
|
||||
Dim oDocDatatable As New DataTable
|
||||
Try
|
||||
If Datatable.Columns.Contains(COLUMN_DOCID) = False Then
|
||||
Throw New ApplicationException($"Datatable is missing DocId Column [{COLUMN_DOCID}]!")
|
||||
End If
|
||||
|
||||
If Datatable.Columns.Contains(COLUMN_FILEPATH) = False Then
|
||||
Throw New ApplicationException($"Datatable is missing Filepath Column [{COLUMN_FILEPATH}]!")
|
||||
End If
|
||||
|
||||
'Die Icon Colum erstellen und konfigurieren
|
||||
oDocDatatable.Columns.Add(New DataColumn() With {
|
||||
.DataType = GetType(Image),
|
||||
@@ -314,7 +316,7 @@ Public Class frmDocumentResultList
|
||||
})
|
||||
oDocDatatable.Columns.Add(New DataColumn() With {
|
||||
.DataType = GetType(String),
|
||||
.ColumnName = "Filename",
|
||||
.ColumnName = COLUMN_FILENAME,
|
||||
.Caption = "Filename"
|
||||
})
|
||||
|
||||
@@ -340,12 +342,12 @@ Public Class frmDocumentResultList
|
||||
oNewRow = oDocDatatable.NewRow()
|
||||
|
||||
'Icon zuweisen
|
||||
oNewRow.Item(0) = GetIconByExtension(oFullpath)
|
||||
oNewRow.Item(COLUMN_ICON) = _Helpers.GetIconByExtension(oFullpath)
|
||||
|
||||
'Den Filepath mitgeben
|
||||
oNewRow.Item(1) = oFullpath
|
||||
oNewRow.Item(2) = oDocID
|
||||
oNewRow.Item(3) = oFilename
|
||||
oNewRow.Item(COLUMN_FILEPATH) = oFullpath
|
||||
oNewRow.Item(COLUMN_DOCID) = oDocID
|
||||
oNewRow.Item(COLUMN_FILENAME) = oFilename
|
||||
|
||||
Dim oIndex = 4 'Fängt bei 4 an, um die definierten Spalten zu überspringen
|
||||
For Each oColumnName As String In oRestColArray
|
||||
@@ -404,55 +406,14 @@ Public Class frmDocumentResultList
|
||||
|
||||
GridView.OptionsView.BestFitMaxRowCount = -1
|
||||
GridView.BestFitColumns(True)
|
||||
Catch ex As ApplicationException
|
||||
MsgBox($"Error while loading grid data: {vbNewLine}{vbNewLine}{ex.Message}", MsgBoxStyle.Critical, Text)
|
||||
_Logger.Error(ex)
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Function GetIconByExtension(FilePath As String) As Bitmap
|
||||
Dim oFileextension = Path.GetExtension(FilePath)
|
||||
|
||||
Select Case oFileextension.ToUpper
|
||||
Case ".csv".ToUpper
|
||||
Return My.Resources.xls
|
||||
Case ".txt".ToUpper
|
||||
Return My.Resources.txt
|
||||
Case ".pdf".ToUpper
|
||||
Return My.Resources.pdf
|
||||
Case ".doc".ToUpper
|
||||
Return My.Resources.doc
|
||||
Case ".docx".ToUpper
|
||||
Return My.Resources.doc
|
||||
Case ".xls".ToUpper
|
||||
Return My.Resources.xls
|
||||
Case ".xlsx".ToUpper
|
||||
Return My.Resources.xls
|
||||
Case ".xlsm".ToUpper
|
||||
Return My.Resources.xls
|
||||
Case ".ppt".ToUpper
|
||||
Return My.Resources.ppt
|
||||
Case ".pptx".ToUpper
|
||||
Return My.Resources.ppt
|
||||
Case ".dwg".ToUpper
|
||||
Return My.Resources.dwg
|
||||
Case ".dxf".ToUpper
|
||||
Return My.Resources.dxf
|
||||
Case ".msg".ToUpper
|
||||
Return My.Resources._page
|
||||
Case ".msg".ToUpper
|
||||
Return My.Resources._page
|
||||
Case ".tif".ToUpper
|
||||
Return My.Resources.tiff
|
||||
Case ".tiff".ToUpper
|
||||
Return My.Resources.tiff
|
||||
Case ".jpg".ToUpper
|
||||
Return My.Resources.jpg
|
||||
Case Else
|
||||
Return My.Resources._blank
|
||||
End Select
|
||||
End Function
|
||||
|
||||
|
||||
Private Sub SwitchMainContainerHorizontal_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles SwitchMainContainerHorizontal.CheckedChanged
|
||||
SplitContainerControl1.Horizontal = SwitchMainContainerHorizontal.Checked
|
||||
|
||||
@@ -508,7 +469,7 @@ Public Class frmDocumentResultList
|
||||
|
||||
Private Function GetActiveRow() As DataRow
|
||||
Dim oActiveGrid = GetActiveGridControl()
|
||||
Dim oActiveRowhandle = GetActiveRowHandle()
|
||||
Dim oActiveRowhandle = _Helpers.ActiveRowHandle
|
||||
|
||||
If oActiveGrid IsNot Nothing And oActiveRowhandle <> Constants.NO_ROW_HANDLE Then
|
||||
Dim oView = DirectCast(oActiveGrid.DefaultView, GridView)
|
||||
@@ -527,13 +488,7 @@ Public Class frmDocumentResultList
|
||||
Return _ActiveGrid
|
||||
End Function
|
||||
|
||||
Private Function GetActiveRowHandle() As Integer
|
||||
If _ActiveRowHandle = Constants.NO_ROW_HANDLE Then
|
||||
Return Constants.NO_ROW_HANDLE
|
||||
End If
|
||||
|
||||
Return _ActiveRowHandle
|
||||
End Function
|
||||
|
||||
Private Sub GridControl_Enter(sender As GridControl, e As EventArgs) Handles GridControl1.Enter, GridControl2.Enter, GridControl3.Enter
|
||||
_ActiveGrid = sender
|
||||
@@ -674,4 +629,20 @@ Public Class frmDocumentResultList
|
||||
MsgBox("Unexpected Error while preparing context menu", MsgBoxStyle.Critical, Text)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
Public Sub Show_CriticalError(Message As String)
|
||||
labelCriticalError.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
|
||||
labelCriticalError.Caption = Message
|
||||
End Sub
|
||||
|
||||
Public Sub Show_Warning(Message As String)
|
||||
labelWarning.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
|
||||
labelWarning.Caption = Message
|
||||
End Sub
|
||||
|
||||
Public Sub Reset_Errors()
|
||||
labelCriticalError.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
|
||||
labelWarning.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user