Imports System.Drawing Imports System.IO Imports System.Windows.Forms Imports DevExpress.Utils Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Columns Imports DevExpress.XtraGrid.Views.Grid Imports DevExpress.XtraPrinting Imports DigitalData.Modules.Config Imports DigitalData.Modules.Logging Imports DigitalData.Modules.ZooFlow Imports DigitalData.Modules.Language Public Class frmDocumentResultList Private _LogConfig As LogConfig Private _Logger As Logger Private _Config As ConfigManager(Of DocumentResultConfig) Private _Environment As Environment Private _Params As DocumentResultParams Private _ResultLists As List(Of DocumentResult) Private _IsLoading As Boolean = True Public Sub New(LogConfig As LogConfig, Environment As Environment, Params As DocumentResultParams) ' Dieser Aufruf ist für den Designer erforderlich. InitializeComponent() ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. Dim oConfigPath As String = Path.Combine(Application.UserAppDataPath, "DocumentResultList", Params.WindowGuid) _LogConfig = LogConfig _Logger = LogConfig.GetLogger() _Config = New ConfigManager(Of DocumentResultConfig)(LogConfig, oConfigPath) _Environment = Environment _Params = Params _ResultLists = Params.Results End Sub Private Sub frmDocumentResultList_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try ' Load config SplitContainerControl1.SplitterPosition = _Config.Config.SplitContainer1Distance SwitchMainContainerHorizontal.Checked = _Config.Config.SplitContainer1Horizontal SplitContainerControl2.SplitterPosition = _Config.Config.SplitContainer2Distance SwitchDetailContainerHorizontal.Checked = _Config.Config.SplitContainer2Horizontal DocumentViewer1.Init(_Params.ViewerLicense) Dim oTotalResults = 0 For Each oList In _ResultLists oTotalResults += oList.Datatable.Rows.Count Next Text = String.Format(Text, oTotalResults) ' Load Grids For index = 0 To _ResultLists.Count - 1 Select Case index Case 0 Dim oResult As DocumentResult = _ResultLists.Item(0) GridBand1.Caption = $"{oResult.Title} ({oResult.Datatable.Rows.Count})" CreateDocumentGrid(GridView1, oResult.Datatable) Case 1 Dim oResult As DocumentResult = _ResultLists.Item(1) GridBand2.Caption = $"{oResult.Title} ({oResult.Datatable.Rows.Count})" CreateDocumentGrid(GridView2, oResult.Datatable) Case 2 Dim oResult As DocumentResult = _ResultLists.Item(2) GridBand3.Caption = $"{oResult.Title} ({oResult.Datatable.Rows.Count})" CreateDocumentGrid(GridView3, oResult.Datatable) Case Else MessageBox.Show("You have more than three searches configured. This Window will only show the first three result lists!") Exit For End Select Next ' Hide Grids depending on Result count Select Case _ResultLists.Count Case 1 SplitContainerControl1.SetPanelCollapsed(True) SplitContainerControl2.SetPanelCollapsed(True) Case 2 SplitContainerControl2.SetPanelCollapsed(True) End Select Catch ex As Exception _Logger.Error(ex) MessageBox.Show("Error while loading results:" & vbNewLine & vbNewLine & ex.Message, Text) Finally _IsLoading = False End Try End Sub Private Sub CreateDocumentGrid(GridView As GridView, Datatable As DataTable) Dim oMyDocDatatable As New DataTable Try 'Die Icon Colum erstellen und konfigurieren oMyDocDatatable.Columns.Add(New DataColumn() With { .DataType = GetType(Image), .ColumnName = "ICON", .Caption = "" }) oMyDocDatatable.Columns.Add(New DataColumn() With { .DataType = GetType(String), .ColumnName = "FULL_FILENAME", .Caption = "Fullpath" }) oMyDocDatatable.Columns.Add(New DataColumn() With { .DataType = GetType(Int32), .ColumnName = "DocID", .Caption = "DocID" }) oMyDocDatatable.Columns.Add(New DataColumn() With { .DataType = GetType(String), .ColumnName = "Filename", .Caption = "Filename" }) Dim oRestColArray As New List(Of String) For Each oCol As DataColumn In Datatable.Columns Dim onewColumn As New DataColumn() If oCol.ColumnName <> "DocID" And oCol.ColumnName <> "FULL_FILENAME" And oCol.ColumnName <> "Filename" Then onewColumn.DataType = GetType(String) onewColumn.ColumnName = oCol.ColumnName onewColumn.Caption = oCol.Caption oMyDocDatatable.Columns.Add(onewColumn) oRestColArray.Add(onewColumn.ColumnName) End If Next For Each oRow As DataRow In Datatable.Rows Dim oFullpath = oRow.Item("FULL_FILENAME") Dim oDocID = oRow.Item("DocID") 'Dim Folderpath = Path.GetDirectoryName(fullpath) Dim oFilename = IO.Path.GetFileName(oFullpath) Dim oFileextension = IO.Path.GetExtension(oFullpath) Dim oNewRow As DataRow oNewRow = oMyDocDatatable.NewRow() 'Icon zuweisen Select Case oFileextension.ToUpper Case ".csv".ToUpper oNewRow.Item(0) = My.Resources.xls Case ".txt".ToUpper oNewRow.Item(0) = My.Resources.txt Case ".pdf".ToUpper oNewRow.Item(0) = My.Resources.pdf Case ".doc".ToUpper oNewRow.Item(0) = My.Resources.doc Case ".docx".ToUpper oNewRow.Item(0) = My.Resources.doc Case ".xls".ToUpper oNewRow.Item(0) = My.Resources.xls Case ".xlsx".ToUpper oNewRow.Item(0) = My.Resources.xls Case ".xlsm".ToUpper oNewRow.Item(0) = My.Resources.xls Case ".ppt".ToUpper oNewRow.Item(0) = My.Resources.ppt Case ".pptx".ToUpper oNewRow.Item(0) = My.Resources.ppt Case ".dwg".ToUpper oNewRow.Item(0) = My.Resources.dwg Case ".dxf".ToUpper oNewRow.Item(0) = My.Resources.dxf Case ".msg".ToUpper oNewRow.Item(0) = My.Resources._page Case ".msg".ToUpper oNewRow.Item(0) = My.Resources._page Case ".tif".ToUpper oNewRow.Item(0) = My.Resources.tiff Case ".tiff".ToUpper oNewRow.Item(0) = My.Resources.tiff Case ".jpg".ToUpper oNewRow.Item(0) = My.Resources.jpg Case Else oNewRow.Item(0) = My.Resources._blank End Select 'Den Filepath mitgeben oNewRow.Item(1) = oFullpath oNewRow.Item(2) = oDocID oNewRow.Item(3) = oFilename Dim oIndex = 4 'Fängt bei 4 an, um die definierten Spalten zu überspringen For Each oColumnName As String In oRestColArray Dim oRowValue oRowValue = oRow.Item(oColumnName) oNewRow.Item(oIndex) = oRowValue.ToString oIndex += 1 Next oMyDocDatatable.Rows.Add(oNewRow) Next Dim oGridControl As GridControl = GridView.GridControl oGridControl.DataSource = oMyDocDatatable oGridControl.ForceInitialize() Try GridView.Columns.Item("DocID").Visible = False Catch ex As Exception End Try Try GridView.Columns.Item("FULL_FILENAME").Visible = False Catch ex As Exception End Try Dim oCreated, oChanged As String If _Environment.User.Language <> "de-DE" Then oChanged = "Changed" oCreated = "Created" Else oChanged = "Geändert" oCreated = "Erstellt" End If Dim oCreatedColumn = GridView.Columns(oCreated) If Not IsNothing(oCreatedColumn) Then oCreatedColumn.DisplayFormat.FormatType = FormatType.DateTime oCreatedColumn.DisplayFormat.FormatString = _Environment.User.DateFormat & " HH:MM:ss" End If Dim oChangedColumn = GridView.Columns(oChanged) If Not IsNothing(oChangedColumn) Then oChangedColumn.DisplayFormat.FormatType = FormatType.DateTime oChangedColumn.DisplayFormat.FormatString = _Environment.User.DateFormat & " HH:MM:ss" End If ' Alle Spalten aus ReadOnly setzen, danach werden alle passenden auf nicht ReadOnly gesetzt For Each oColumn As GridColumn In GridView.Columns oColumn.OptionsColumn.AllowEdit = False Next GridView.Columns.Item("ICON").MaxWidth = 24 GridView.Columns.Item("ICON").MinWidth = 24 GridView.OptionsView.BestFitMaxRowCount = -1 GridView.BestFitColumns(True) Catch ex As Exception _Logger.Error(ex) End Try End Sub Private Sub SwitchMainContainerHorizontal_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles SwitchMainContainerHorizontal.CheckedChanged SplitContainerControl1.Horizontal = SwitchMainContainerHorizontal.Checked If _Config IsNot Nothing And _IsLoading = False Then _Config.Config.SplitContainer1Horizontal = SwitchMainContainerHorizontal.Checked _Config.Save() End If End Sub Private Sub BarToggleSwitchItem2_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles SwitchDetailContainerHorizontal.CheckedChanged SplitContainerControl2.Horizontal = SwitchDetailContainerHorizontal.Checked If _Config IsNot Nothing And _IsLoading = False Then _Config.Config.SplitContainer2Horizontal = SwitchDetailContainerHorizontal.Checked _Config.Save() End If End Sub Private Sub BarButtonItemExportGrid1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemExportGrid1.ItemClick XtraSaveFileDialog.FileName = Utils.ConvertTextToSlug(GridBand1.Caption) & ".xlsx" XtraSaveFileDialog.DefaultExt = ".xlsx" If XtraSaveFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim oOptions As New XlsxExportOptions() With { .ExportMode = XlsxExportMode.SingleFile } GridControl1.ExportToXlsx(XtraSaveFileDialog.FileName, oOptions) End If End Sub Private Sub SplitContainerControl1_SplitterPositionChanged(sender As Object, e As EventArgs) Handles SplitContainerControl1.SplitterPositionChanged If _IsLoading = False Then _Config.Config.SplitContainer1Distance = SplitContainerControl1.SplitterPosition _Config.Save() End If End Sub Private Sub SplitContainerControl2_SplitterPositionChanged(sender As Object, e As EventArgs) Handles SplitContainerControl2.SplitterPositionChanged If _IsLoading = False Then _Config.Config.SplitContainer2Distance = SplitContainerControl2.SplitterPosition _Config.Save() End If End Sub End Class