Imports System.ComponentModel Imports System.IO Imports System.Runtime.InteropServices Imports DevExpress.Utils Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Columns Imports DevExpress.XtraGrid.Views.Grid Imports DD_LIB_Standards Imports DevExpress.XtraGrid.Views.Base Imports DevExpress.XtraTab Public Class frmResultDoc #Region "Laufzeitvariablen & Konstanten" Private Shared BW_DocPath As String Private Shared BW_DocID As Integer Private Shared CurrSearchID As Integer Private DTDocSearchDefinition As DataTable Private _frmDocView As frmDocView 'You need a reference to Form1 Private _frmProfileMatch As frmProfileMatch 'You need a reference to Form1 Private _frmSQL As frmResultSQL 'You need a reference to Form1 Private _activeGridView As GridView #End Region Public Sub New() MyBase.New ' Dieser Aufruf ist für den Designer erforderlich. InitializeComponent() ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. _frmProfileMatch = Nothing End Sub Public Sub New(ProfileMatchForm As frmProfileMatch) ' Dieser Aufruf ist für den Designer erforderlich. InitializeComponent() ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. _frmProfileMatch = ProfileMatchForm End Sub Private Class DocSearch Public DataTable As DataTable Public TabIndex As Integer Public TabCaption As String Public ProfileId As Integer End Class Private Async Sub frmResultDoc_Load(sender As Object, e As EventArgs) Handles Me.Load ToolStripDropDownButtonFile.Visible = False If Not ConfigManager.Config.ResultDocWindowLocation.IsEmpty Then Location = ConfigManager.Config.ResultDocWindowLocation End If If Not ConfigManager.Config.ResultDocWindowSize.IsEmpty Then Size = ConfigManager.Config.ResultDocWindowSize End If Dim oFrmResultSQL As New frmResultSQL() _frmSQL = oFrmResultSQL _frmSQL.Show() GridViewDocSearch1.ShowLoadingPanel() Dim oSearches = Await LoadSearchesAsync() For Each oSearch As DocSearch In oSearches RefreshTabDoc(oSearch.ProfileId, oSearch.DataTable, oSearch.TabIndex, oSearch.TabCaption) Next GridViewDocSearch1.HideLoadingPanel() End Sub Private Sub frmResultDoc_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing Try ConfigManager.Config.ResultDocWindowSize = Size ConfigManager.Config.ResultDocWindowLocation = Location ConfigManager.Save() Catch ex As Exception Logger.Error(ex) Logger.Warn("Error in Save FormLayout: " & ex.Message) End Try _frmDocView?.Close() _frmSQL?.Close() If CURRENT_MATCHING_PROFILES.Count > 1 Then _frmProfileMatch?.Show() _frmProfileMatch?.BringToFront() End If End Sub Private Async Function LoadSearchesAsync() As Task(Of List(Of DocSearch)) Return Await Task.Run(AddressOf DoLoadSearches) End Function Private Function DoLoadSearches() As List(Of DocSearch) If IsNothing(CurrDocSearch2Load) Then Throw New ApplicationException("CurrDocSearch2Load is empty") End If Dim oSQL As String = $"SELECT * FROM TBCW_PROF_DOC_SEARCH WHERE ACTIVE = 1 AND PROFILE_ID in ({CurrDocSearch2Load}) ORDER BY TAB_INDEX" Dim oSearchesDataTable = clsDatabase.Return_Datatable(oSQL) Dim oDocSearches As New List(Of DocSearch) Dim oCounter As Integer = 0 DTDocSearchDefinition = oSearchesDataTable For Each oRow As DataRow In oSearchesDataTable.Rows Dim oProfileId As Integer = oRow.Item("PROFILE_ID") Dim oTabTitle As String = oRow.Item("TAB_TITLE") oSQL = oRow.Item("SQL_COMMAND") oSQL = clsPatterns.ReplaceAllValues(oSQL, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfileId) Dim oDatatable As DataTable = clsDatabase.Return_Datatable(oSQL) oDocSearches.Add(New DocSearch() With { .DataTable = oDatatable, .ProfileId = oProfileId, .TabCaption = oTabTitle, .TabIndex = oCounter }) oCounter += 1 Next Return oDocSearches End Function Sub RefreshTabDoc(ProfileId As Integer, Datatable As DataTable, TabIndex As Integer, TabCaption As String) Try Dim myGridControl As GridControl = GridControlDocSearch1 Dim myGridview As GridView = GridViewDocSearch1 Select Case TabIndex Case 0 GridControlDocSearch1.DataSource = Nothing GridViewDocSearch1.Columns.Clear() myGridview = GridViewDocSearch1 myGridControl = GridControlDocSearch1 Case 1 GridControlDocSearch2.DataSource = Nothing GridViewDocSearch2.Columns.Clear() myGridview = GridViewDocSearch2 myGridControl = GridControlDocSearch2 Case 2 GridControlDocSearch3.DataSource = Nothing GridViewDocSearch3.Columns.Clear() myGridview = GridViewDocSearch3 myGridControl = GridControlDocSearch3 Case 3 GridControlDocSearch4.DataSource = Nothing GridViewDocSearch4.Columns.Clear() myGridControl = GridControlDocSearch4 myGridview = GridViewDocSearch4 Case 4 GridControlDocSearch5.DataSource = Nothing GridViewDocSearch5.Columns.Clear() myGridControl = GridControlDocSearch5 myGridview = GridViewDocSearch5 End Select myGridControl.ContextMenuStrip = ContextMenuStripWMFile If Not IsNothing(Datatable) Then XtraTabControlDocs.TabPages(TabIndex).Text = $"{TabCaption} ({Datatable.Rows.Count})" clsWMDocGrid.DTDocuments = Datatable Create_GridControl(myGridview, Datatable) Dim oxmlPath As String = Get_DocGrid_Layout_Filename(XtraTabControlDocs.SelectedTabPageIndex) If File.Exists(oxmlPath) Then myGridview.RestoreLayoutFromXml(oxmlPath) myGridview.GuessAutoFilterRowValuesFromFilter() End If tslblState.Text = $"Tab [{TabCaption}] refreshed - {Now}" XtraTabControlDocs.TabPages(TabIndex).PageVisible = True Else clsWMDocGrid.DTDocuments = Nothing End If Catch ex As Exception Logger.Error(ex) End Try End Sub Private Sub Create_GridControl(MyGridView As GridView, _datatable As DataTable) Dim oMyDocDatatable As New DataTable Try 'Die Icon Colum erstellen und konfigurieren Dim oColIcon As New DataColumn() With { .DataType = GetType(Image), .ColumnName = "ICON", .Caption = "" } oMyDocDatatable.Columns.Add(oColIcon) Dim oColPath As New DataColumn() With { .DataType = GetType(String), .ColumnName = "FULL_FILENAME", .Caption = "Fullpath" } oMyDocDatatable.Columns.Add(oColPath) Dim oColDocID As New DataColumn() With { .DataType = GetType(Int32), .ColumnName = "DocID", .Caption = "DocID" } oMyDocDatatable.Columns.Add(oColDocID) 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 FILE_ROW As DataRow In _datatable.Rows Dim oFullpath = FILE_ROW.Item("FULL_FILENAME") Dim oDocID = FILE_ROW.Item("DocID") 'Dim Folderpath = Path.GetDirectoryName(fullpath) Dim oFilename = Path.GetFileName(oFullpath) Dim oFileextension = Path.GetExtension(oFullpath) Dim oNewRow As DataRow oNewRow = oMyDocDatatable.NewRow() 'Icon zuweisen Select Case oFileextension.ToUpper Case ".csv".ToUpper oNewRow.Item(0) = My.Resources.doc_excel_csv 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.email_go Case ".msg".ToUpper oNewRow.Item(0) = My.Resources.email_go 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 Dim i = 3 'Fängt bei 3 an, um die definierten Spalten zu überspringen For Each Colname As String In oRestColArray Dim oRowValue oRowValue = FILE_ROW.Item(Colname) oNewRow.Item(i) = oRowValue.ToString i += 1 Next oMyDocDatatable.Rows.Add(oNewRow) Next Dim oGridControl As GridControl = MyGridView.GridControl oGridControl.DataSource = oMyDocDatatable oGridControl.ForceInitialize() Try MyGridView.Columns.Item("DocID").Visible = False Catch ex As Exception End Try Try MyGridView.Columns.Item("FULL_FILENAME").Visible = False Catch ex As Exception End Try Dim created, changed As String If USER_LANGUAGE <> "de-DE" Then changed = "Changed" created = "Created" Else changed = "Geändert" created = "Erstellt" End If Dim createdColumn = MyGridView.Columns(created) If Not IsNothing(createdColumn) Then createdColumn.DisplayFormat.FormatType = FormatType.DateTime createdColumn.DisplayFormat.FormatString = USER_DATE_FORMAT & " HH:MM:ss" End If Dim changedColumn = MyGridView.Columns(changed) If Not IsNothing(changedColumn) Then changedColumn.DisplayFormat.FormatType = FormatType.DateTime changedColumn.DisplayFormat.FormatString = USER_DATE_FORMAT & " HH:MM:ss" End If ' Alle Spalten aus ReadOnly setzen, danach werden alle passenden auf nicht ReadOnly gesetzt For Each column As GridColumn In MyGridView.Columns column.OptionsColumn.AllowEdit = False Next MyGridView.Columns.Item("ICON").MaxWidth = 24 MyGridView.Columns.Item("ICON").MinWidth = 24 MyGridView.OptionsView.BestFitMaxRowCount = -1 MyGridView.BestFitColumns(True) Catch ex As Exception Logger.Error(ex) End Try End Sub Private Function Get_DocGrid_Layout_Filename(oIndex As Integer) Dim oFilename As String = String.Format("GridViewDoc_Search-{0}-{1}-UserLayout.xml", oIndex, CurrSearchID) Dim oPath = Path.Combine(Application.UserAppDataPath(), oFilename) Return oPath End Function Private Sub GridControlDocSearch_Leave(sender As Object, e As EventArgs) Handles GridControlDocSearch1.Leave, GridControlDocSearch2.Leave, GridControlDocSearch3.Leave, GridControlDocSearch4.Leave, GridControlDocSearch5.Leave SaveDocGridLayout() End Sub Sub SaveDocGridLayout() Dim oXMLPath = Get_DocGrid_Layout_Filename(XtraTabControlDocs.SelectedTabPageIndex) clsWMDocGrid.ActiveDocGrid.SaveLayoutToXml(oXMLPath) End Sub Private Sub EigenschaftenDateiToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EigenschaftenDateiToolStripMenuItem.Click Show_File_Properties() End Sub Sub Show_File_Properties() If IsNothing(clsWMDocGrid.DTDocuments) Then MsgBox("Could not read file Parameters!", MsgBoxStyle.Exclamation) Exit Sub End If Cursor = Cursors.WaitCursor For Each oRow As DataRow In clsWMDocGrid.DTDocuments.Rows Dim oWindows As New Windows(LogConfig) oWindows.ShowFileProperties(oRow.Item("DOC_PATH")) Next Cursor = Cursors.Default End Sub Private Sub DateiÖffnenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DateiÖffnenToolStripMenuItem.Click FileShow() End Sub Sub FileShow() Try If IsNothing(clsWMDocGrid.DTDocuments) Then MsgBox("Could not read fileparameters(5)!", MsgBoxStyle.Exclamation) Exit Sub End If For Each row As DataRow In clsWMDocGrid.DTDocuments.Rows File_SYSOPEN(row.Item("DOC_PATH"), row.Item("DOC_ID")) Next Catch ex As Exception End Try End Sub Private Shared Sub File_SYSOPEN(RESULT_DOC_PATH As Object, DocID As String) Try If RESULT_DOC_PATH <> Nothing Then BW_DocPath = RESULT_DOC_PATH BW_DocID = DocID Dim BWFileHandler As New BackgroundWorker AddHandler BWFileHandler.DoWork, AddressOf BWFileHandler_DoWork BWFileHandler.RunWorkerAsync() End If Catch ex As Exception MsgBox("Unexpected Error in File_SYSOPEN:" & vbNewLine & ex.Message & vbNewLine & RESULT_DOC_PATH & vbNewLine & "DocID: " & DocID, MsgBoxStyle.Critical) Logger.Error(ex) End Try End Sub Private Shared Sub BWFileHandler_DoWork() Try Dim oMyProcess = New Process() Dim oExtension Dim oSql Try 'Dim oPSI As New ProcessStartInfo(BW_DocPath) oMyProcess.StartInfo.FileName = BW_DocPath oMyProcess.StartInfo.UseShellExecute = True oMyProcess.StartInfo.RedirectStandardOutput = False oMyProcess.Start() 'oMyProcess.WaitForExit() Catch ex As Exception Logger.Error(ex) Exit Sub End Try Catch ex As Exception Logger.Error(ex) Try Process.Start(BW_DocPath) Catch ex1 As Exception Logger.Error(ex) End Try End Try End Sub Sub Refresh_DocID(myGrid As GridView) _activeGridView = myGrid clsWMDocGrid.ActiveDocGrid = myGrid clsWMDocGrid.ActiveDocGrid.EndSelection() clsWMDocGrid.GetDocItems() Try ContextMenuStripWMFile.Close() Catch ex As Exception End Try If ToolStripDropDownButtonFile.Visible = False Then ToolStripDropDownButtonFile.Visible = True End If If clsWMDocGrid.SELECTED_DOC_ID <> 0 Then Dim msg = "Doc-ID: " & clsWMDocGrid.SELECTED_DOC_ID.ToString tslblDocID.Text = msg ToolStripDropDownButtonFile.Enabled = True Dim frmCollection As New FormCollection() frmCollection = Application.OpenForms() Try If frmCollection.Item("frmDocView").IsHandleCreated Then 'MsgBox("Yes Opened") _frmDocView.Load_File_from_Path(clsWMDocGrid.SELECTED_DOC_PATH) Else Dim f As New frmDocView With f .Show() .Load_File_from_Path(clsWMDocGrid.SELECTED_DOC_PATH) End With End If Catch ex As Exception If ConfigManager.Config.LoadDocumentView = True Then Dim newDocView As New frmDocView With newDocView .Show() .Load_File_from_Path(clsWMDocGrid.SELECTED_DOC_PATH) End With _frmDocView = newDocView ToolStripButtonDocView.Checked = True Else ToolStripButtonDocView.Checked = False End If End Try BringToFront() Else tslblDocID.Text = "DocRow not selected" ToolStripDropDownButtonFile.Enabled = False End If End Sub Private Sub GridViewDocSearch_FocusedRowChanged(sender As GridView, e As Views.Base.FocusedRowChangedEventArgs) Handles GridViewDocSearch1.FocusedRowChanged, GridViewDocSearch2.FocusedRowChanged, GridViewDocSearch3.FocusedRowChanged, GridViewDocSearch4.FocusedRowChanged, GridViewDocSearch5.FocusedRowChanged _activeGridView = sender Refresh_DocID(sender) End Sub Private Sub GridViewDocSearch_ColumnWidthChanged(sender As GridView, e As Views.Base.ColumnEventArgs) Handles GridViewDocSearch1.ColumnWidthChanged, GridViewDocSearch2.ColumnWidthChanged, GridViewDocSearch3.ColumnWidthChanged, GridViewDocSearch4.ColumnWidthChanged, GridViewDocSearch5.ColumnWidthChanged _activeGridView = sender SaveDocGridLayout() End Sub Private Sub GridControlDocSearch1_DoubleClick(sender As GridControl, e As EventArgs) Handles GridControlDocSearch1.DoubleClick, GridControlDocSearch2.DoubleClick, GridControlDocSearch3.DoubleClick, GridControlDocSearch4.DoubleClick, GridControlDocSearch5.DoubleClick Refresh_DocID(sender.DefaultView) FileShow() End Sub Private Sub ÖffnenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ÖffnenToolStripMenuItem.Click FileShow() End Sub Private Sub EigenschaftenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EigenschaftenToolStripMenuItem.Click Show_File_Properties() End Sub Private Sub ToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem1.Click ReLoad_Active_DocTab() End Sub Private Sub ToolStripMenuItem2_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem2.Click Set_DoclayoutBack() End Sub Sub Set_DoclayoutBack() Dim oXMLPath = Get_DocGrid_Layout_Filename(XtraTabControlDocs.SelectedTabPageIndex) Try If File.Exists(oXMLPath) Then File.Delete(oXMLPath) ReLoad_Active_DocTab() tslblState.Text = "Layout has been set back!" Else tslblState.Text = "" End If Catch ex As Exception tslblState.Text = "" End Try End Sub Sub ReLoad_Active_DocTab() Try Dim oTabIndex = XtraTabControlDocs.SelectedTabPageIndex Dim oConID = DTDocSearchDefinition.Rows(oTabIndex).Item("CONN_ID") Dim oCommand = DTDocSearchDefinition.Rows(oTabIndex).Item("SQL_COMMAND") Dim oProfID = DTDocSearchDefinition.Rows(oTabIndex).Item("PROFILE_ID") Dim oTabTitle = DTDocSearchDefinition.Rows(oTabIndex).Item("TAB_TITLE") Dim oDatatable As DataTable oCommand = clsPatterns.ReplaceAllValues(oCommand, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfID) oDatatable = clsDatabase.Return_Datatable(oCommand) RefreshTabDoc(oProfID, oDatatable, oTabIndex, oTabTitle) Catch ex As Exception Logger.Error(ex) MsgBox($"Error while reloading tab data: " & vbNewLine & ex.Message) End Try End Sub Private Sub XtraTabControlDocs_SelectedPageChanged(sender As Object, e As TabPageChangedEventArgs) Handles XtraTabControlDocs.SelectedPageChanged Try If IsNothing(DTDocSearchDefinition) Then Exit Sub End If Dim oSearchDefinitionRow = DTDocSearchDefinition.Rows(XtraTabControlDocs.SelectedTabPageIndex) Dim oConID = oSearchDefinitionRow.Item("CONN_ID") Dim oCommand = oSearchDefinitionRow.Item("SQL_COMMAND") Dim oProfileID = oSearchDefinitionRow.Item("PROFILE_ID") Dim oTabIndex = oSearchDefinitionRow.Item("TAB_INDEX") Dim oTabCaption = oSearchDefinitionRow.Item("TAB_TITLE") Dim oDatatable As DataTable oCommand = clsPatterns.ReplaceAllValues(oCommand, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfileID) oDatatable = clsDatabase.Return_Datatable(oCommand) RefreshTabDoc(oProfileID, oDatatable, oTabIndex, oTabCaption) Catch ex As Exception Logger.Error(ex) MsgBox("Error while loading tab data: " & vbNewLine & ex.Message) End Try End Sub Private Sub GridControlDocSearch2_DoubleClick(sender As Object, e As EventArgs) Handles GridControlDocSearch2.DoubleClick Refresh_DocID(GridViewDocSearch2) FileShow() End Sub Private Sub GridControlDocSearch3_DoubleClick(sender As Object, e As EventArgs) Handles GridControlDocSearch3.DoubleClick Refresh_DocID(GridViewDocSearch3) FileShow() End Sub Private Sub GridControlDocSearch4_DoubleClick(sender As Object, e As EventArgs) Handles GridControlDocSearch4.DoubleClick Refresh_DocID(GridViewDocSearch4) FileShow() End Sub Private Sub GridControlDocSearch5_DoubleClick(sender As Object, e As EventArgs) Handles GridControlDocSearch5.DoubleClick Refresh_DocID(GridViewDocSearch5) FileShow() End Sub Private Sub OrdnerÖffnenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OrdnerÖffnenToolStripMenuItem.Click Open_Folder() End Sub Sub Open_Folder() Dim oFilepath = Path.GetDirectoryName(clsWMDocGrid.SELECTED_DOC_PATH) If Directory.Exists(oFilepath) = True Then Process.Start(oFilepath) Else MsgBox("Folder '" & oFilepath & "' not existing or accessible!", MsgBoxStyle.Exclamation) End If End Sub Private Sub ToolStripButtonDocView_Click(sender As Object, e As EventArgs) Handles ToolStripButtonDocView.Click If ConfigManager.Config.LoadDocumentView = False Then Dim newDocView As New frmDocView With newDocView .Show() .Load_File_from_Path(clsWMDocGrid.SELECTED_DOC_PATH) End With _frmDocView = newDocView ToolStripButtonDocView.Checked = True ConfigManager.Config.LoadDocumentView = True Else ToolStripButtonDocView.Checked = False ConfigManager.Config.LoadDocumentView = False Try _frmDocView.Close() Catch ex As Exception End Try End If ConfigManager.Save() End Sub Private Sub ToolStripButtonDocView_CheckedChanged(sender As Object, e As EventArgs) Handles ToolStripButtonDocView.CheckedChanged If ToolStripButtonDocView.Checked Then ToolStripButtonDocView.Text = "DocView (Active)" Else ToolStripButtonDocView.Text = "DocView (Inactive)" End If End Sub Private Sub frmResultDoc_Shown(sender As Object, e As EventArgs) Handles Me.Shown BringToFront() CurrSearchOpen = True End Sub End Class