437 lines
18 KiB
VB.net
437 lines
18 KiB
VB.net
Imports DevExpress.Utils
|
|
Imports System.Text
|
|
Imports System.IO
|
|
Imports DevExpress.XtraGrid.Views.Grid
|
|
Imports System.Runtime.InteropServices
|
|
Imports DevExpress.XtraPrinting
|
|
Imports DevExpress.Data.Filtering.Helpers.SubExprHelper.CriteriaTokens
|
|
Imports DevExpress.XtraSplashScreen
|
|
Imports System.Threading
|
|
Imports DevExpress.XtraGrid
|
|
|
|
Public Class frmGlobalSearch
|
|
|
|
Inherits DevExpress.XtraBars.Ribbon.RibbonForm
|
|
<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 _Helper As ClassHelper
|
|
Dim sel_Records, FuULLTEXT_select As String
|
|
Private _ActiveGrid As GridControl = Nothing
|
|
Private Function GetActiveGridControl() As GridControl
|
|
If _ActiveGrid Is Nothing Then
|
|
Return Nothing
|
|
End If
|
|
|
|
Return _ActiveGrid
|
|
End Function
|
|
Private Sub GridControlWK1_Enter(sender As Object, e As EventArgs) Handles GridControlFiles.Enter, GridControlRecords.Enter
|
|
_ActiveGrid = sender
|
|
End Sub
|
|
Sub Refresh_Search()
|
|
|
|
If txtSearch.Text = "" Then
|
|
Exit Sub
|
|
End If
|
|
Me.Cursor = Cursors.WaitCursor
|
|
Dim oHandle = SplashScreenManager.ShowOverlayForm(Me)
|
|
Try
|
|
lblFT_Irregular.Visible = False
|
|
sel_Records = ""
|
|
FuULLTEXT_select = ""
|
|
|
|
If BarToggleSearchCombined.Checked = True Then
|
|
PREPARE_RECORD_SQL()
|
|
PREPARE_FT_SQL()
|
|
|
|
End If
|
|
If BarToggleSearchRecord.Checked = True Then
|
|
PREPARE_RECORD_SQL()
|
|
End If
|
|
If BarToggleFulltext.Checked Then
|
|
PREPARE_FT_SQL()
|
|
End If
|
|
Dim DT_Files As DataTable
|
|
Dim DT_RECORD_RESULT As DataTable
|
|
If BarToggleSearchCombined.Checked Or BarToggleSearchRecord.Checked Then
|
|
DT_RECORD_RESULT = Refresh_Records()
|
|
Else
|
|
SplitContainerMain.CollapsePanel = DevExpress.XtraEditors.SplitCollapsePanel.Panel1
|
|
SplitContainerMain.Collapsed = True
|
|
tslblRecordsResult.Text = String.Format("No records found")
|
|
GridControlRecords.DataSource = Nothing
|
|
End If
|
|
If BarToggleSearchCombined.Checked Or BarToggleFulltext.Checked Then
|
|
DT_Files = Refresh_Files()
|
|
If BarToggleFulltext.Checked Then
|
|
SplitContainerMain.CollapsePanel = DevExpress.XtraEditors.SplitCollapsePanel.Panel1
|
|
SplitContainerMain.Collapsed = True
|
|
End If
|
|
Else
|
|
SplitContainerMain.CollapsePanel = DevExpress.XtraEditors.SplitCollapsePanel.Panel2
|
|
SplitContainerMain.Collapsed = True
|
|
GridControlFiles.DataSource = Nothing
|
|
End If
|
|
|
|
|
|
|
|
Catch ex As Exception
|
|
|
|
Finally
|
|
SplashScreenManager.CloseOverlayForm(oHandle)
|
|
Me.Cursor = Cursors.Default
|
|
End Try
|
|
|
|
|
|
|
|
|
|
End Sub
|
|
Sub PREPARE_FT_SQL()
|
|
Dim oSearchTermFT = txtSearch.Text
|
|
oSearchTermFT = oSearchTermFT.Replace(" ", "%")
|
|
oSearchTermFT = oSearchTermFT.Replace(".", "")
|
|
Dim oSQLft = SQL_FULLTEXT
|
|
oSQLft = oSQLft.Replace("@FULLTEXT_RP", oSearchTermFT)
|
|
oSQLft = oSQLft.Replace("@FULLTEXT", txtSearch.Text)
|
|
|
|
LOGGER.Debug("oSQLft is: " + oSQLft)
|
|
FuULLTEXT_select = oSQLft
|
|
|
|
End Sub
|
|
Sub PREPARE_RECORD_SQL()
|
|
|
|
sel_Records = String.Format("Select T.RECORD_ID,TR.FORM_ID As ENTITY_ID ,[dbo].[FNPMO_GETOBJECTCAPTION]('{0}','FORMVIEW_TITLE' + CONVERT(VARCHAR(5), TFV.GUID), 1) as Entity," &
|
|
"T.VALUE,TR.ADDED_WHO as AddedWho,TR.ADDED_WHEN as AddedWhen,TR.CHANGED_WHO As ChangedWho,TR.CHANGED_WHEN as ChangedWhen from TBPMO_CONTROL_VALUE T,TBPMO_RECORD TR,TBPMO_FORM_VIEW TFV " &
|
|
"where T.RECORD_ID = TR.GUID AND TR.FORM_ID = TFV.FORM_ID AND T.value like '%{1}%' ORDER BY T.RECORD_ID", USER_LANGUAGE, txtSearch.Text)
|
|
End Sub
|
|
Private Function Refresh_Records()
|
|
Dim DT_RECORD_RESULT = MYDB_ECM.GetDatatable(sel_Records)
|
|
If Not IsNothing(DT_RECORD_RESULT) Then
|
|
SplitContainerMain.CollapsePanel = DevExpress.XtraEditors.SplitCollapsePanel.None
|
|
SplitContainerMain.Collapsed = False
|
|
If DT_RECORD_RESULT.Rows.Count > 0 Then
|
|
GridControlRecords.DataSource = DT_RECORD_RESULT
|
|
tslblRecordsResult.Text = String.Format("{0} records found", DT_RECORD_RESULT.Rows.Count)
|
|
Try
|
|
GridViewRecords.Columns("AddedWhen").DisplayFormat.FormatType = FormatType.DateTime
|
|
GridViewRecords.Columns("AddedWhen").DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss"
|
|
GridViewRecords.Columns("ChangedWhen").DisplayFormat.FormatType = FormatType.DateTime
|
|
GridViewRecords.Columns("ChangedWhen").DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss"
|
|
GridViewRecords.ApplyFindFilter(txtSearch.Text)
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
' FormID und RecordID immer ausblenden
|
|
GridViewRecords.Columns.Item("ENTITY_ID").Visible = False
|
|
Else
|
|
tslblRecordsResult.Text = String.Format("No records found")
|
|
GridControlRecords.DataSource = Nothing
|
|
End If
|
|
Return DT_RECORD_RESULT
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Function
|
|
Private Function Refresh_Files()
|
|
Dim DT_Files As DataTable
|
|
If FuULLTEXT_select <> "FT_Incompatible" Then
|
|
DT_Files = MYDB_ECM.GetDatatable(FuULLTEXT_select)
|
|
Else
|
|
tslblDocView.Text = String.Format("No full text result because the search term contained characters that are incompatible with a full text search.")
|
|
GridControlFiles.DataSource = Nothing
|
|
End If
|
|
|
|
If Not IsNothing(DT_Files) Then
|
|
SplitContainerMain.CollapsePanel = DevExpress.XtraEditors.SplitCollapsePanel.None
|
|
SplitContainerMain.Collapsed = False
|
|
If DT_Files.Rows.Count > 0 Then
|
|
GridControlFiles.DataSource = DT_Files
|
|
tslblDocView.Text = String.Format("{0} files found", DT_Files.Rows.Count)
|
|
Try
|
|
GridViewFiles.Columns("AddedWhen").DisplayFormat.FormatType = FormatType.DateTime
|
|
GridViewFiles.Columns("AddedWhen").DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss"
|
|
GridViewFiles.Columns("ChangedWhen").DisplayFormat.FormatType = FormatType.DateTime
|
|
GridViewFiles.Columns("ChangedWhen").DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss"
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
Try
|
|
GridViewFiles.Columns("ErstelltWann").DisplayFormat.FormatType = FormatType.DateTime
|
|
GridViewFiles.Columns("ErstelltWann").DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss"
|
|
GridViewFiles.Columns("GeändertWann").DisplayFormat.FormatType = FormatType.DateTime
|
|
GridViewFiles.Columns("GeändertWann").DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss"
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
' FormID und RecordID immer ausblenden
|
|
' GridViewFiles.Columns.Item("FULL_FILENAME").Visible = False
|
|
GridViewFiles.OptionsView.ColumnAutoWidth = False
|
|
GridViewFiles.BestFitColumns()
|
|
Else
|
|
tslblDocView.Text = String.Format(" No files found")
|
|
GridControlFiles.DataSource = Nothing
|
|
End If
|
|
Return DT_Files
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Function
|
|
|
|
|
|
|
|
|
|
Sub Export_Excel()
|
|
Dim oActiveGrid = GetActiveGridControl()
|
|
|
|
If oActiveGrid IsNot Nothing Then
|
|
Cursor = Cursors.WaitCursor
|
|
XtraSaveFileDialog1.FileName = oActiveGrid.Name & ".xlsx"
|
|
XtraSaveFileDialog1.DefaultExt = ".xlsx"
|
|
|
|
If XtraSaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
|
|
Dim oOptions As New XlsxExportOptions() With {
|
|
.ExportMode = XlsxExportMode.SingleFile
|
|
}
|
|
oActiveGrid.ExportToXlsx(XtraSaveFileDialog1.FileName, oOptions)
|
|
End If
|
|
Else
|
|
MessageBox.Show("Please select a grid/table that you would like to export.", Text, MessageBoxButtons.OK)
|
|
End If
|
|
Cursor = Cursors.Default
|
|
End Sub
|
|
|
|
Sub Show_Detail_Record()
|
|
Try
|
|
Dim RECORD_ID = GridViewRecords.GetFocusedRowCellValue(GridViewRecords.Columns("RECORD_ID"))
|
|
If Not IsNothing(RECORD_ID) Then
|
|
ClassJumpRecord.JumpToRecord(0, RECORD_ID)
|
|
End If
|
|
Catch ex As Exception
|
|
MsgBox("Unexpected Error in Show_Detail_Record:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
|
End Try
|
|
JUMP_RECORD_ID = 0
|
|
End Sub
|
|
|
|
Private Sub frmSearchAllOVer_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
|
|
Save_DocGrid_Layout()
|
|
Save_RecGrid_Layout()
|
|
End Sub
|
|
Private Sub frmSearchAllOVer_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
|
|
If e.KeyCode = Keys.Return Then
|
|
Refresh_Search()
|
|
End If
|
|
End Sub
|
|
|
|
|
|
Private Sub GridControlFiles_DoubleClick(sender As Object, e As EventArgs) Handles GridControlFiles.DoubleClick
|
|
File_open()
|
|
End Sub
|
|
Sub Save_DocGrid_Layout()
|
|
Try
|
|
Dim XMLPath = Get_DocGrid_Layout_Filename()
|
|
GridViewFiles.SaveLayoutToXml(XMLPath)
|
|
' Update_Status_Label(True, "Grid Layout Loaded")
|
|
Catch ex As Exception
|
|
MsgBox("Error in Save_DocGrid_Layout:" & vbNewLine & ex.Message)
|
|
End Try
|
|
End Sub
|
|
Sub Save_RecGrid_Layout()
|
|
Try
|
|
Dim XMLPath = Get_RecordGrid_Layout_Filename()
|
|
GridViewRecords.SaveLayoutToXml(XMLPath)
|
|
' Update_Status_Label(True, "Grid Layout Loaded")
|
|
Catch ex As Exception
|
|
MsgBox("Error in Save_RecGrid_Layout:" & vbNewLine & ex.Message)
|
|
End Try
|
|
End Sub
|
|
Sub Load_DocGrid_Layout()
|
|
Try
|
|
Dim XMLPath = Get_DocGrid_Layout_Filename()
|
|
If File.Exists(XMLPath) Then
|
|
GridViewFiles.RestoreLayoutFromXml(XMLPath)
|
|
GridViewFiles.GuessAutoFilterRowValuesFromFilter()
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
MsgBox("Error in Load_DocGrid_Layout:" & vbNewLine & ex.Message)
|
|
End Try
|
|
End Sub
|
|
Sub Load_RecordGrid_Layout()
|
|
Try
|
|
Dim XMLPath = Get_RecordGrid_Layout_Filename()
|
|
If File.Exists(XMLPath) Then
|
|
GridViewRecords.RestoreLayoutFromXml(XMLPath)
|
|
GridViewRecords.GuessAutoFilterRowValuesFromFilter()
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
MsgBox("Error in Load_RecordGrid_Layout:" & vbNewLine & ex.Message)
|
|
End Try
|
|
End Sub
|
|
Private Function Get_RecordGrid_Layout_Filename()
|
|
Dim EntityRegex As New RegularExpressions.Regex("\s+\(\d+\)")
|
|
Dim Filename As String = "frmGlobalSearch_RecordGrid-UserLayout.xml"
|
|
Return System.IO.Path.Combine(Application.UserAppDataPath(), Filename)
|
|
End Function
|
|
Private Function Get_DocGrid_Layout_Filename()
|
|
Dim EntityRegex As New RegularExpressions.Regex("\s+\(\d+\)")
|
|
Dim Filename As String = "frmGlobalSearch_DocGrid-UserLayout.xml"
|
|
Return System.IO.Path.Combine(Application.UserAppDataPath(), Filename)
|
|
End Function
|
|
|
|
Private Sub frmSearchAllOVer_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
_Helper = New ClassHelper
|
|
Load_DocGrid_Layout()
|
|
Load_RecordGrid_Layout()
|
|
End Sub
|
|
Sub Show_File_Properties()
|
|
Try
|
|
For Each row In GridViewFiles.GetSelectedRows
|
|
Dim SELECTED_DOC_PATH = _Helper.FORMAT_WM_PATH(GridViewFiles.GetRowCellValue(row, "FULL_FILENAME"))
|
|
Dim SELECTED_DOC_ID = GridViewFiles.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 Open_folder()
|
|
Try
|
|
For Each row In GridViewFiles.GetSelectedRows
|
|
Dim SELECTED_DOC_PATH = _Helper.FORMAT_WM_PATH(GridViewFiles.GetRowCellValue(row, "FULL_FILENAME"))
|
|
Dim SELECTED_DOC_ID = GridViewFiles.GetRowCellValue(row, "DocID")
|
|
ClassHelper.Open_Folder(SELECTED_DOC_PATH, SELECTED_DOC_ID)
|
|
Next
|
|
|
|
|
|
Catch ex As Exception
|
|
LOGGER.Error(ex)
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical)
|
|
End Try
|
|
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
Private Sub GridControlRecords_Click(sender As Object, e As EventArgs) Handles GridControlRecords.Click
|
|
RibbonPageGroupFiles.Enabled = False
|
|
RibbonPageGroupRecords.Enabled = True
|
|
End Sub
|
|
|
|
Private Sub GridControlFiles_Click(sender As Object, e As EventArgs) Handles GridControlFiles.Click
|
|
RibbonPageGroupFiles.Enabled = True
|
|
RibbonPageGroupRecords.Enabled = False
|
|
End Sub
|
|
|
|
|
|
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs)
|
|
Show_Detail_Record()
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem3.ItemClick
|
|
Refresh_Search()
|
|
End Sub
|
|
|
|
Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs) Handles txtSearch.TextChanged
|
|
Dim oTerm As String = txtSearch.Text
|
|
If txtSearch.Text.Contains(".") Then
|
|
lblFT_Irregular.Visible = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem4_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem4.ItemClick
|
|
Export_Excel()
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem6_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem6.ItemClick
|
|
Open_folder()
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem7_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem7.ItemClick
|
|
Show_File_Properties()
|
|
End Sub
|
|
Private Sub BarButtonItem8_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem8.ItemClick
|
|
Try
|
|
For Each row In GridViewFiles.GetSelectedRows
|
|
Dim SELECTED_DOC_ID = GridViewFiles.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
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem9_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem9.ItemClick
|
|
Show_Detail_Record()
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem10_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem10.ItemClick
|
|
File_open()
|
|
End Sub
|
|
|
|
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
|
|
|
|
End Sub
|
|
|
|
Sub File_open()
|
|
Me.Cursor = Cursors.WaitCursor
|
|
|
|
For Each row In GridViewFiles.GetSelectedRows
|
|
Dim SELECTED_DOC_PATH = _Helper.FORMAT_WM_PATH(GridViewFiles.GetRowCellValue(row, "FULL_FILENAME"))
|
|
Dim SELECTED_DOC_ID = GridViewFiles.GetRowCellValue(row, "DocID")
|
|
If IsNothing(SELECTED_DOC_PATH) Then
|
|
MsgBox("Could not read File Parameters!", MsgBoxStyle.Exclamation)
|
|
Exit Sub
|
|
End If
|
|
|
|
ClassHelper.File_open(SELECTED_DOC_PATH, SELECTED_DOC_ID, 0)
|
|
|
|
Next
|
|
Me.Cursor = Cursors.Default
|
|
|
|
End Sub
|
|
End Class |