RecordOrganizer/app/DD-Record-Organizer/frmDocSearchResult.vb

278 lines
11 KiB
VB.net

Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Text
Imports DevExpress.XtraGrid.Views.Base
Public Class frmDocSearchResult
<DllImport("Shell32", CharSet:=CharSet.Auto, SetLastError:=True)>
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
<MarshalAs(UnmanagedType.LPTStr)> Public lpVerb As String
<MarshalAs(UnmanagedType.LPTStr)> Public lpFile As String
<MarshalAs(UnmanagedType.LPTStr)> Public lpParameters As String
<MarshalAs(UnmanagedType.LPTStr)> Public lpDirectory As String
Dim nShow As Integer
Dim hInstApp As IntPtr
Dim lpIDList As IntPtr
<MarshalAs(UnmanagedType.LPTStr)> 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 DT_RESULT As DataTable
Public Sub LoadDocSearch(reload As Boolean)
Try
Cursor = Cursors.WaitCursor
If reload = False Then
DT_RESULT = ClassDatabase.Return_Datatable(CURRENT_DOCSEARCH_SQL, True)
End If
DT_RESULT = DT_RESULT
GridControlDocSearch.DataSource = Nothing
GridViewDoc_Search.Columns.Clear()
GridControlDocSearch.DataSource = DT_RESULT
GridViewDoc_Search.BestFitColumns(True)
ToolStripLabelCaption.Text = $"{CURRENT_DOCSEARCH_CAPTION} ({DT_RESULT.Rows.Count} rows)"
Load_DocGrid_Layout()
GridControlDocSearch.DataSource = DT_RESULT
GridControlDocSearch.DataSource = DT_RESULT
'If GridViewDoc_Search.RowCount > 15000 Then
' ToolStripButton2.Enabled = False
'Else
' ToolStripButton2.Enabled = True
'End If
ToolStripButton2.Enabled = True
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
ClassWindreamDocGrid.GetDocItems(GridViewDoc_Search)
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
ClassWindreamDocGrid.GetDocItems(GridViewDoc_Search)
Refresh_DocID()
End If
End Sub
Sub Refresh_DocID()
If ClassWindreamDocGrid.SELECTED_DOC_ID <> 0 Then
Dim msg = "Doc-ID: " & ClassWindreamDocGrid.SELECTED_DOC_ID.ToString
tslblDocID.Text = msg
Else
tslblDocID.Text = "DocRow not selected"
End If
End Sub
Sub Open_File()
Me.Cursor = Cursors.WaitCursor
Dim allow_Open As Boolean = False
ClassWindreamDocGrid.GetDocItems(GridViewDoc_Search)
Dim Result = ClassDOC_SEARCH.Get_File_Rights(ClassWindreamDocGrid.SELECTED_DOC_ID)
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(ClassWindreamDocGrid.DT_RESULTFILES) Then
MsgBox("Could not read File Parameters(5)!", MsgBoxStyle.Exclamation)
Exit Sub
End If
For Each row As DataRow In ClassWindreamDocGrid.DT_RESULTFILES.Rows
ClassHelper.File_open(row.Item("DOC_PATH"), row.Item("DOC_ID"))
If CURRENT_OFFICE_FILE_CHANGED = True Then LoadDocSearch(True)
Next
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(ClassWindreamDocGrid.DT_RESULTFILES) Then
MsgBox("Could not read File Parameters(5)!", MsgBoxStyle.Exclamation)
Exit Sub
End If
For Each row As DataRow In ClassWindreamDocGrid.DT_RESULTFILES.Rows
ClassHelper.Open_Folder(row.Item("DOC_PATH"), row.Item("DOC_ID"))
Next
End Sub
Private Sub docCM_Copy_Click(sender As Object, e As EventArgs) Handles docCM_Copy.Click
If ClassWindreamDocGrid.SELECTED_DOC_PATH <> "" Then
Try
Dim selectedfile(0) As String
selectedfile(0) = ClassWindreamDocGrid.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
ClassWindreamDocGrid.GetDocItems(GridViewDoc_Search)
If IsNothing(ClassWindreamDocGrid.DT_RESULTFILES) Then
MsgBox("Could not read File Parameters (LinkRecord)!", MsgBoxStyle.Exclamation)
Exit Sub
End If
Dim frm As New frmDoc_Links
frm.Show()
frm.BringToFront()
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
End Sub
Sub Show_File_Properties()
If IsNothing(ClassWindreamDocGrid.DT_RESULTFILES) Then
MsgBox("Could not read File Parameters(4)!", MsgBoxStyle.Exclamation)
Exit Sub
End If
For Each row As DataRow In ClassWindreamDocGrid.DT_RESULTFILES.Rows
If row.Item("DOC_PATH") <> "" Then
Cursor = Cursors.WaitCursor
Dim sei As New SHELLEXECUTEINFO
sei.cbSize = Marshal.SizeOf(sei)
sei.lpVerb = "properties"
sei.lpFile = row.Item("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
End If
Cursor = Cursors.Default
Next
End Sub
Private Sub frmDocSearchResult_Load(sender As Object, e As EventArgs) Handles Me.Load
LoadDocSearch(False)
Me.Text = CURRENT_DOCSEARCH_CAPTION
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 frmDocSearchResult_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Save_DocGrid_Layout()
End Sub
Private Sub GridControlDocSearch_DoubleClick(sender As Object, e As EventArgs) Handles GridControlDocSearch.DoubleClick
ClassWindreamDocGrid.GetDocItems(GridViewDoc_Search)
Refresh_DocID()
End Sub
Private Sub GridViewDoc_Search_ColumnFilterChanged(sender As Object, e As EventArgs) Handles GridViewDoc_Search.ColumnFilterChanged
ToolStripLabelCaption.Text = $"{CURRENT_DOCSEARCH_CAPTION} ({GridViewDoc_Search.RowCount} rows [filtered])"
If GridViewDoc_Search.RowCount > 12000 Then
ToolStripButton2.Enabled = False
Else
ToolStripButton2.Enabled = True
End If
End Sub
Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
LoadDocSearch(False)
End Sub
Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
Try
Dim saveFileDialogDocSearchResult As New SaveFileDialog
saveFileDialogDocSearchResult.Filter = "Excel File|*.xlsx"
saveFileDialogDocSearchResult.Title = "Export to Excel:"
saveFileDialogDocSearchResult.ShowDialog()
If saveFileDialogDocSearchResult.FileName <> "" Then
Cursor = Cursors.WaitCursor
GridControlDocSearch.MainView.ExportToXlsx(saveFileDialogDocSearchResult.FileName)
Dim result As MsgBoxResult
Dim msg = String.Format("Datei wurde erstellt! Wollen Sie diese nun öffnen?")
If USER_LANGUAGE <> "de-DE" Then
msg = String.Format("File was created. Do You want to open excel?")
End If
result = MessageBox.Show(msg, "Exporting result:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If result = MsgBoxResult.Yes Then
Process.Start(saveFileDialogDocSearchResult.FileName)
End If
End If
Catch ex As Exception
MsgBox("Unexpected Error in ExportExcel: " & ex.Message, MsgBoxStyle.Critical)
End Try
Cursor = Cursors.Default
End Sub
Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click
Dim XMLPath = Get_DocGrid_Layout_Filename()
If File.Exists(XMLPath) Then
File.Delete(XMLPath)
LoadDocSearch(True)
End If
End Sub
End Class