355 lines
14 KiB
VB.net
355 lines
14 KiB
VB.net
Imports System.Drawing
|
|
Imports DevExpress.Utils
|
|
Imports DevExpress.XtraGrid
|
|
Imports DevExpress.XtraGrid.Columns
|
|
Imports DevExpress.XtraGrid.Views.Grid
|
|
Imports DigitalData.GUIs.Common
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.ZooFlow
|
|
Imports DigitalData.Modules.ZooFlow.Params
|
|
Imports Patterns.ClassPatterns
|
|
|
|
Public Class frmResult
|
|
Implements IResultForm
|
|
|
|
Private _LogConfig As LogConfig
|
|
Private _Logger As Logger
|
|
Private _Params As ClipboardWatcherParams
|
|
Private _Environment As Environment
|
|
Private _DocumentSearches As DataTable
|
|
Private _MatchingProfiles As List(Of ProfileData)
|
|
Private _Database As MSSQLServer
|
|
Private _ResultType As ResultType
|
|
|
|
Private Class Search
|
|
Public DataTable As DataTable
|
|
Public TabIndex As Integer
|
|
Public TabCaption As String
|
|
Public ProfileId As Integer
|
|
Public SQLCommand As String
|
|
End Class
|
|
|
|
Public Enum ResultType
|
|
Data
|
|
Document
|
|
End Enum
|
|
|
|
Public Property ShouldReturnToMatchForm As Boolean = False Implements IResultForm.ShouldReturnToMatchForm
|
|
|
|
Public Sub New(LogConfig As LogConfig, Environment As Environment, Params As ClipboardWatcherParams, ResultType As ResultType)
|
|
' Dieser Aufruf ist für den Designer erforderlich.
|
|
InitializeComponent()
|
|
|
|
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
|
_MatchingProfiles = Params.MatchingProfiles
|
|
_LogConfig = LogConfig
|
|
_Logger = LogConfig.GetLogger
|
|
_Database = Environment.Database
|
|
_Environment = Environment
|
|
_Params = Params
|
|
_ResultType = ResultType
|
|
End Sub
|
|
|
|
Private Async Sub frmResult_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
|
GridView1.ShowLoadingPanel()
|
|
|
|
Dim oSearches As New List(Of Search)
|
|
|
|
If _ResultType = ResultType.Data Then
|
|
oSearches = Await LoadDataSearchesAsync()
|
|
Else
|
|
oSearches = Await LoadDocumentSearchesAsync()
|
|
End If
|
|
|
|
For Each oSearch As Search In oSearches
|
|
RefreshTabDoc(oSearch.ProfileId, oSearch.DataTable, oSearch.TabIndex, oSearch.TabCaption)
|
|
Next
|
|
|
|
GridView1.HideLoadingPanel()
|
|
End Sub
|
|
|
|
Private Async Function LoadDocumentSearchesAsync() As Task(Of List(Of Search))
|
|
Return Await Task.Run(AddressOf DoLoadDocumentSearches)
|
|
End Function
|
|
|
|
|
|
|
|
Private Function DoLoadDocumentSearches() As List(Of Search)
|
|
Dim oMatchingIds = String.Join(",", _MatchingProfiles.Select(Function(p) p.Guid).ToArray())
|
|
Dim oSQL As String = $"SELECT * FROM TBCW_PROF_DOC_SEARCH WHERE ACTIVE = 1 AND PROFILE_ID in ({oMatchingIds}) ORDER BY TAB_INDEX"
|
|
Dim oSearchesDataTable = _Database.GetDatatable(oSQL)
|
|
Dim oDocSearches As New List(Of Search)
|
|
Dim oCounter As Integer = 0
|
|
Dim oPatterns As New Patterns.ClassPatterns(_LogConfig)
|
|
|
|
_DocumentSearches = 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")
|
|
Dim oConnectionId As Integer = oRow.Item("CONN_ID")
|
|
|
|
oSQL = oRow.Item("SQL_COMMAND")
|
|
oSQL = oPatterns.ReplaceUserValues(oSQL, _Environment.User)
|
|
oSQL = oPatterns.ReplaceInternalValues(oSQL)
|
|
|
|
Dim oDatatable As DataTable = _Database.GetDatatable(oSQL, oConnectionId)
|
|
oDocSearches.Add(New Search() With {
|
|
.DataTable = oDatatable,
|
|
.ProfileId = oProfileId,
|
|
.TabCaption = oTabTitle,
|
|
.TabIndex = oCounter,
|
|
.SQLCommand = oSQL
|
|
})
|
|
|
|
oCounter += 1
|
|
Next
|
|
|
|
Return oDocSearches
|
|
End Function
|
|
|
|
Private Async Function LoadDataSearchesAsync() As Task(Of List(Of Search))
|
|
Return Await Task.Run(AddressOf DoLoadDataSearches)
|
|
End Function
|
|
|
|
Private Function DoLoadDataSearches() As List(Of Search)
|
|
Dim oMatchingIds = String.Join(",", _MatchingProfiles.Select(Function(p) p.Guid).ToArray())
|
|
Dim oSQL As String = $"SELECT * FROM TBCW_PROF_DATA_SEARCH WHERE ACTIVE = 1 AND PROFILE_ID in ({oMatchingIds}) ORDER BY TAB_INDEX"
|
|
Dim oSearchesDataTable = _Database.GetDatatable(oSQL)
|
|
Dim oDataSearches As New List(Of Search)
|
|
Dim oCounter As Integer = 0
|
|
Dim oPatterns As New Patterns.ClassPatterns(_LogConfig)
|
|
|
|
_DocumentSearches = 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")
|
|
Dim oConnectionId As Integer = oRow.Item("CONN_ID")
|
|
|
|
oSQL = oRow.Item("SQL_COMMAND")
|
|
oSQL = oPatterns.ReplaceUserValues(oSQL, _Environment.User)
|
|
oSQL = oPatterns.ReplaceInternalValues(oSQL)
|
|
|
|
Dim oDatatable As DataTable = _Database.GetDatatable(oSQL, oConnectionId)
|
|
oDataSearches.Add(New Search() With {
|
|
.DataTable = oDatatable,
|
|
.ProfileId = oProfileId,
|
|
.TabCaption = oTabTitle,
|
|
.TabIndex = oCounter,
|
|
.SQLCommand = oSQL
|
|
})
|
|
|
|
oCounter += 1
|
|
Next
|
|
|
|
Return oDataSearches
|
|
End Function
|
|
|
|
Sub RefreshTabDoc(ProfileId As Integer, Datatable As DataTable, TabIndex As Integer, TabCaption As String)
|
|
Try
|
|
Dim oSelectedGridControl As GridControl = GridControl1
|
|
Dim oSelectedGridView As GridView = GridView1
|
|
|
|
Select Case TabIndex
|
|
Case 0
|
|
GridControl1.DataSource = Nothing
|
|
GridView1.Columns.Clear()
|
|
oSelectedGridView = GridView1
|
|
oSelectedGridControl = GridControl1
|
|
Case 1
|
|
GridControl2.DataSource = Nothing
|
|
GridView2.Columns.Clear()
|
|
oSelectedGridView = GridView2
|
|
oSelectedGridControl = GridControl2
|
|
Case 2
|
|
GridControl3.DataSource = Nothing
|
|
GridView3.Columns.Clear()
|
|
oSelectedGridView = GridView3
|
|
oSelectedGridControl = GridControl3
|
|
Case 3
|
|
GridControl4.DataSource = Nothing
|
|
GridView4.Columns.Clear()
|
|
oSelectedGridControl = GridControl4
|
|
oSelectedGridView = GridView4
|
|
Case 4
|
|
GridControl5.DataSource = Nothing
|
|
GridView5.Columns.Clear()
|
|
oSelectedGridControl = GridControl5
|
|
oSelectedGridView = GridView5
|
|
End Select
|
|
|
|
'oSelectedGridControl.ContextMenuStrip = ContextMenuStripWMFile
|
|
|
|
If Not IsNothing(Datatable) Then
|
|
XtraTabControl.TabPages(TabIndex).Text = $"{TabCaption} ({Datatable.Rows.Count})"
|
|
'clsWMDocGrid.DTDocuments = Datatable
|
|
|
|
If _ResultType = ResultType.Document Then
|
|
CreateDocumentGrid(oSelectedGridView, Datatable)
|
|
Else
|
|
CreateDataGrid(oSelectedGridView, Datatable)
|
|
End If
|
|
|
|
'Dim oxmlPath As String = Get_DocGrid_Layout_Filename(XtraTabControlDocs.SelectedTabPageIndex)
|
|
'If File.Exists(oxmlPath) Then
|
|
' oSelectedGridView.RestoreLayoutFromXml(oxmlPath)
|
|
' oSelectedGridView.GuessAutoFilterRowValuesFromFilter()
|
|
'End If
|
|
LabelStatus.Caption = $"Tab [{TabCaption}] refreshed - {Now}"
|
|
XtraTabControl.TabPages(TabIndex).PageVisible = True
|
|
Else
|
|
'clsWMDocGrid.DTDocuments = Nothing
|
|
End If
|
|
Catch ex As Exception
|
|
_Logger.Error(ex)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub CreateDataGrid(GridView As GridView, Datatable As DataTable)
|
|
End Sub
|
|
|
|
Private Sub CreateDocumentGrid(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 = 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
|
|
|
|
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 _Environment.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 = _Environment.User.DateFormat & " HH:MM:ss"
|
|
End If
|
|
|
|
Dim changedColumn = MyGridView.Columns(changed)
|
|
If Not IsNothing(changedColumn) Then
|
|
changedColumn.DisplayFormat.FormatType = FormatType.DateTime
|
|
changedColumn.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 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
|
|
End Class |