Imports System.IO Imports System.Runtime.InteropServices Imports DevExpress.XtraEditors 'Imports System.Runtime.InteropServices 'Imports System.Text Imports DevExpress.XtraGrid.Views.Base Imports DevExpress.XtraPrinting Imports DigitalData.Modules.Database Public Class frmDocSearchResult Inherits DevExpress.XtraBars.Ribbon.RibbonForm Public Shared Function ShellExecuteEx(ByRef lpExecInfo As SHELLEXECUTEINFO) As Boolean End Function Public Structure SHELLEXECUTEINFO Public cbSize As Integer Public fMask As Integer Public hwnd As IntPtr Public lpVerb As String Public lpFile As String Public lpParameters As String Public lpDirectory As String Dim nShow As Integer Dim hInstApp As IntPtr Dim lpIDList As IntPtr Public lpClass As String Public hkeyClass As IntPtr Public dwHotKey As Integer Public hIcon As IntPtr Public hProcess As IntPtr End Structure Private Const SEE_MASK_INVOKEIDLIST = &HC Private Const SEE_MASK_NOCLOSEPROCESS = &H40 Private Const SEE_MASK_FLAG_NO_UI = &H400 Public Const SW_SHOW As Short = 5 Private _Helper As ClassHelper Private DT_RESULT As DataTable Private SelectedDocID As Int64 Private SelectedFULL_FILEPATH As String Private Sub frmDocSearchResult_Load(sender As Object, e As EventArgs) Handles Me.Load LoadDocSearch(False) _Helper = New ClassHelper Text = CURRENT_DOCSEARCH_CAPTION DocumentViewer1.Init(LOGCONFIG, MYGDPICTURE_LICENSE_KEY, New DigitalData.Controls.DocumentViewer.DocumentViewer.ToolbarSettings() With { .ShowPrintButton = True, .ShowRotateButton = True, .ShowFlipButton = True, .ShowSettingButton = True }) End Sub Private Sub frmDocSearchResult_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing Save_DocGrid_Layout() End Sub Public Sub LoadDocSearch(reload As Boolean) Try Cursor = Cursors.WaitCursor If reload = False Then DT_RESULT = MYDB_ECM.GetDatatable(CURRENT_DOCSEARCH_SQL) End If DT_RESULT = DT_RESULT bsiInfo.Caption = $"{CURRENT_DOCSEARCH_CAPTION} ({DT_RESULT.Rows.Count} rows)" GridControlDocSearch.DataSource = DT_RESULT GridViewDoc_Search.OptionsView.ColumnAutoWidth = False GridViewDoc_Search.BestFitColumns() Load_DocGrid_Layout() Try GridViewDoc_Search.Columns.Item("FULL_FILENAME").Visible = False Catch ex As Exception End Try Catch ex As Exception LOGGER.Warn("Unexpected Error in LoadDocSearch: " & ex.Message) End Try Cursor = Cursors.Default End Sub Private Sub GridViewDoc_Search_FocusedColumnChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedColumnChangedEventArgs) Handles GridViewDoc_Search.FocusedColumnChanged If GridViewDoc_Search.RowCount > 0 Then GetDocID() Refresh_DocID() End If End Sub Private Sub GridViewDoc_Search_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs) Handles GridViewDoc_Search.FocusedRowChanged If GridViewDoc_Search.RowCount > 0 Then LoadFile2Viewer() End If End Sub Sub LoadFile2Viewer() GetDocID() Refresh_DocID() If SplitContainerControl1.Collapsed = False Then Dim OFilePath = ClassHelper.FORMAT_WM_PATH(SelectedFULL_FILEPATH) DocumentViewer1.LoadFile(OFilePath) End If End Sub Sub Refresh_DocID() If SelectedDocID <> 0 Then Dim msg = "Doc-ID: " & SelectedDocID.ToString bsiDocID.Caption = msg Else bsiDocID.Caption = "DocRow not selected" End If End Sub Sub GetDocID() Try Dim oDocID = GridViewDoc_Search.GetRowCellValue(GridViewDoc_Search.FocusedRowHandle, "DocID") SelectedFULL_FILEPATH = GridViewDoc_Search.GetRowCellValue(GridViewDoc_Search.FocusedRowHandle, "FULL_FILENAME") If Not IsNothing(oDocID) Then SelectedDocID = oDocID SelectedFULL_FILEPATH = GridViewDoc_Search.GetRowCellValue(GridViewDoc_Search.FocusedRowHandle, "FULL_FILENAME") End If Catch ex As Exception LOGGER.Error(ex) End Try End Sub Sub Open_File() Me.Cursor = Cursors.WaitCursor Dim allow_Open As Boolean = False GetDocID() Dim Result = ClassDOC_SEARCH.Get_File_Rights(SelectedDocID) If Not IsNothing(Result) Then Select Case Result.ToString Case "R" allow_Open = True Case "RW" allow_Open = True Case "RWA" allow_Open = True End Select End If If allow_Open = True Then If IsNothing(SelectedDocID) Then MsgBox("Could not read File Parameters(5)!", MsgBoxStyle.Exclamation) Exit Sub End If ClassHelper.File_open(SelectedFULL_FILEPATH, SelectedDocID, 0) If CURRENT_OFFICE_FILE_CHANGED = True Then LoadDocSearch(True) Else ClassHelper.MSGBOX_Handler("ERROR", "", "File does not exist! Please contact your admin!") End If Me.Cursor = Cursors.Default End Sub Private Sub docCM_Open_Click(sender As Object, e As EventArgs) Handles docCM_Open.Click Open_File() End Sub Private Sub OrdnerÖffnenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OrdnerÖffnenToolStripMenuItem.Click If IsNothing(SelectedFULL_FILEPATH) Then MsgBox("Could not read File Parameters(5)!", MsgBoxStyle.Exclamation) Exit Sub End If ClassHelper.Open_Folder(SelectedFULL_FILEPATH, SelectedDocID) End Sub Private Sub docCM_Copy_Click(sender As Object, e As EventArgs) Handles docCM_Copy.Click If ClassDocGrid.SELECTED_DOC_PATH <> "" Then Try Dim selectedfile(0) As String selectedfile(0) = ClassDocGrid.SELECTED_DOC_PATH Dim dataobj As New DataObject dataobj.SetData(DataFormats.FileDrop, True, selectedfile) Clipboard.Clear() Clipboard.SetDataObject(dataobj, True) Catch ex As Exception ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error", "Error in Copy file:", ex.Message) End Try Cursor = Cursors.Default End If End Sub Private Sub docCM_Showlinks_Click(sender As Object, e As EventArgs) Handles docCM_Showlinks.Click Try ClassDocGrid.GetDocItems(GridViewDoc_Search) If IsNothing(ClassDocGrid.DT_RESULTFILES) Then MsgBox("Could not read File Parameters (LinkRecord)!", MsgBoxStyle.Exclamation) Exit Sub End If Try For Each row In GridViewDoc_Search.GetSelectedRows Dim SELECTED_DOC_ID = GridViewDoc_Search.GetRowCellValue(row, "DocID") If IsNothing(SELECTED_DOC_ID) Then MsgBox("Could not Get a selected DocID!", MsgBoxStyle.Exclamation) Exit Sub End If CURRENT_DOC_ID = SELECTED_DOC_ID Dim frm As New frmDoc_Links frm.Show() frm.BringToFront() Next Catch ex As Exception MsgBox("Unexpected Error in Showing DocLinks: " & ex.Message, MsgBoxStyle.Critical) End Try Catch ex As Exception MsgBox("Unexpected Error in Showing DocLinks: " & ex.Message, MsgBoxStyle.Critical) End Try End Sub Private Sub docCM_PropertiesFile_Click(sender As Object, e As EventArgs) Handles docCM_PropertiesFile.Click Show_File_Properties() End Sub Sub Show_File_Properties() Try For Each row In GridViewDoc_Search.GetSelectedRows Dim SELECTED_DOC_PATH = _Helper.FORMAT_WM_PATH(GridViewDoc_Search.GetRowCellValue(row, "FULL_FILENAME")) Dim SELECTED_DOC_ID = GridViewDoc_Search.GetRowCellValue(row, "DocID") Cursor = Cursors.WaitCursor Dim sei As New SHELLEXECUTEINFO sei.cbSize = Marshal.SizeOf(sei) sei.lpVerb = "properties" sei.lpFile = SELECTED_DOC_PATH sei.nShow = SW_SHOW sei.fMask = SEE_MASK_INVOKEIDLIST If Not ShellExecuteEx(sei) Then Dim ex As New System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error()) ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error", "Error in Open file propertys:", ex.Message) End If Next Catch ex As Exception LOGGER.Error(ex) MsgBox(ex.Message, MsgBoxStyle.Critical) End Try End Sub Sub Save_DocGrid_Layout() Try Dim XMLPath = Get_DocGrid_Layout_Filename() GridViewDoc_Search.SaveLayoutToXml(XMLPath) ' Update_Status_Label(True, "Grid Layout Loaded") Catch ex As Exception ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error", ex.Message, ex.StackTrace) End Try End Sub Sub Load_DocGrid_Layout() Try Dim XMLPath = Get_DocGrid_Layout_Filename() If File.Exists(XMLPath) Then GridViewDoc_Search.RestoreLayoutFromXml(XMLPath) GridViewDoc_Search.GuessAutoFilterRowValuesFromFilter() End If Catch ex As Exception ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error", ex.Message, ex.StackTrace) End Try End Sub Private Function Get_DocGrid_Layout_Filename() Dim Filename As String = String.Format("GridViewDocSearchSW-{0}-UserLayout.xml", CURRENT_ENTITY_ID) LAYOUT_DOC_GRIDVIEW = System.IO.Path.Combine(Application.UserAppDataPath(), Filename) Return LAYOUT_DOC_GRIDVIEW End Function Private Sub GridControlDocSearch_DoubleClick(sender As Object, e As EventArgs) Handles GridControlDocSearch.DoubleClick GetDocID() Refresh_DocID() End Sub Private Sub GridViewDoc_Search_ColumnFilterChanged(sender As Object, e As EventArgs) Handles GridViewDoc_Search.ColumnFilterChanged bsiInfo.Caption = $"{CURRENT_DOCSEARCH_CAPTION} ({GridViewDoc_Search.RowCount} rows [filtered])" End Sub Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) LoadDocSearch(False) End Sub Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick Dim XMLPath = Get_DocGrid_Layout_Filename() If File.Exists(XMLPath) Then File.Delete(XMLPath) LoadDocSearch(True) End If End Sub Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick Try XtraSaveFileDialog1.FileName = GridViewDoc_Search.Name & ".xlsx" XtraSaveFileDialog1.DefaultExt = ".xlsx" If XtraSaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim oOptions As New XlsxExportOptions() With { .ExportMode = XlsxExportMode.SingleFile } GridViewDoc_Search.ExportToXlsx(XtraSaveFileDialog1.FileName, oOptions) If File.Exists(XtraSaveFileDialog1.FileName) Then MsgBox($"File successfully created: {XtraSaveFileDialog1.FileName}", MsgBoxStyle.Information) End If End If Catch ex As Exception MsgBox("Unexpected Error in ExportExcel: " & ex.Message, MsgBoxStyle.Critical) End Try End Sub Private Sub GridViewDoc_Search_DoubleClick(sender As Object, e As EventArgs) Handles GridViewDoc_Search.DoubleClick Open_File() End Sub Private Sub bchlitmPreview_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles bchlitmPreview.CheckedChanged SplitContainerControl1.Collapsed = Not bchlitmPreview.Checked If SplitContainerControl1.Collapsed = False Then LoadFile2Viewer() End If End Sub Private Sub DateienVerknüpfenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DateienVerknüpfenToolStripMenuItem.Click Try ClassDocGrid.GetDocItems(GridViewDoc_Search) Dim oDocuments = ClassDocGrid.SELECTED_DOCUMENTS If oDocuments.Count = 0 Or ClassDocGrid.HasNoSelectedDocuments(GridViewDoc_Search) Then MsgBox("Could not read File Parameters (LinkRecord)!", MsgBoxStyle.Exclamation) Exit Sub End If Dim oForm As New frmDocRecordLink With {.myDocuments = oDocuments} oForm.Show() Catch ex As Exception MsgBox("Unexpected Error in Showing DocRecordLink-Form: " & ex.Message, MsgBoxStyle.Critical) End Try End Sub End Class