add DataResultList
This commit is contained in:
223
GUIs.Common/DataResultList/frmDataResultList.vb
Normal file
223
GUIs.Common/DataResultList/frmDataResultList.vb
Normal file
@@ -0,0 +1,223 @@
|
||||
Imports System.IO
|
||||
Imports System.Windows.Forms
|
||||
Imports DevExpress.XtraGrid
|
||||
Imports DevExpress.XtraGrid.Views.BandedGrid
|
||||
Imports DevExpress.XtraGrid.Views.Base
|
||||
Imports DevExpress.XtraGrid.Views.Grid
|
||||
Imports DigitalData.Modules.Config
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.ZooFlow
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DevExpress.XtraPrinting
|
||||
Imports DigitalData.GUIs.Common
|
||||
|
||||
Public Class frmDataResultList
|
||||
Implements IResultForm
|
||||
|
||||
Private _LogConfig As LogConfig
|
||||
Private _Logger As Logger
|
||||
Private _Config As Object
|
||||
Private _Environment As Environment
|
||||
Private _Params As DataResultParams
|
||||
Private _ResultLists As List(Of DataResult)
|
||||
Private _IsLoading As Boolean
|
||||
|
||||
Private _ActiveGrid As GridControl = Nothing
|
||||
Private _ActiveGridBand As GridBand = Nothing
|
||||
Private _ActiveRowHandle As Integer = Constants.NO_ROW_HANDLE
|
||||
|
||||
Public Property ShouldReturnToMatchForm As Boolean Implements IResultForm.ShouldReturnToMatchForm
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Environment As Environment, Params As DataResultParams)
|
||||
' Dieser Aufruf ist für den Designer erforderlich.
|
||||
InitializeComponent()
|
||||
|
||||
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
||||
Dim oConfigPath As String = Path.Combine(Application.UserAppDataPath, "DocumentResultList", Params.WindowGuid)
|
||||
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_Config = New ConfigManager(Of DocumentResultConfig)(LogConfig, oConfigPath)
|
||||
_Environment = Environment
|
||||
_Params = Params
|
||||
_ResultLists = Params.Results
|
||||
|
||||
ShouldReturnToMatchForm = False
|
||||
End Sub
|
||||
|
||||
Private Sub frmDataResultList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
Try
|
||||
' Load config
|
||||
SplitContainerControl1.SplitterPosition = _Config.Config.SplitContainer1Distance
|
||||
SwitchMainContainerHorizontal.Checked = _Config.Config.SplitContainer1Horizontal
|
||||
SplitContainerControl2.SplitterPosition = _Config.Config.SplitContainer2Distance
|
||||
SwitchDetailContainerHorizontal.Checked = _Config.Config.SplitContainer2Horizontal
|
||||
|
||||
AddHandler GridView1.FocusedRowChanged, AddressOf GridView_FocusedRowChanged
|
||||
AddHandler GridView2.FocusedRowChanged, AddressOf GridView_FocusedRowChanged
|
||||
AddHandler GridView3.FocusedRowChanged, AddressOf GridView_FocusedRowChanged
|
||||
|
||||
Dim oTotalResults = 0
|
||||
|
||||
For Each oList In _ResultLists
|
||||
oTotalResults += oList.Datatable.Rows.Count
|
||||
Next
|
||||
|
||||
labelResultCount.Caption = String.Format(labelResultCount.Caption, oTotalResults)
|
||||
|
||||
' Load Grids
|
||||
For index = 0 To _ResultLists.Count - 1
|
||||
Select Case index
|
||||
Case 0
|
||||
Dim oResult As DataResult = _ResultLists.Item(0)
|
||||
GridBand1.Caption = $"{oResult.Title} ({oResult.Datatable.Rows.Count})"
|
||||
CreateDataGrid(GridView1, oResult.Datatable)
|
||||
|
||||
Case 1
|
||||
Dim oResult As DataResult = _ResultLists.Item(1)
|
||||
GridBand2.Caption = $"{oResult.Title} ({oResult.Datatable.Rows.Count})"
|
||||
CreateDataGrid(GridView2, oResult.Datatable)
|
||||
|
||||
Case 2
|
||||
Dim oResult As DataResult = _ResultLists.Item(2)
|
||||
GridBand3.Caption = $"{oResult.Title} ({oResult.Datatable.Rows.Count})"
|
||||
CreateDataGrid(GridView3, oResult.Datatable)
|
||||
|
||||
Case Else
|
||||
MessageBox.Show("You have more than three searches configured. This Window will only show the first three result lists!")
|
||||
Exit For
|
||||
End Select
|
||||
Next
|
||||
|
||||
' Hide Grids depending on Result count
|
||||
Select Case _ResultLists.Count
|
||||
Case 1
|
||||
SplitContainerControl1.SetPanelCollapsed(True)
|
||||
SplitContainerControl2.SetPanelCollapsed(True)
|
||||
Case 2
|
||||
SplitContainerControl2.SetPanelCollapsed(True)
|
||||
End Select
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Finally
|
||||
_IsLoading = False
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub GridView_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs)
|
||||
_ActiveRowHandle = e.FocusedRowHandle
|
||||
End Sub
|
||||
|
||||
Private Sub SplitContainerControl1_SplitterPositionChanged(sender As Object, e As EventArgs) Handles SplitContainerControl1.SplitterPositionChanged
|
||||
If _IsLoading = False Then
|
||||
_Config.Config.SplitContainer1Distance = SplitContainerControl1.SplitterPosition
|
||||
_Config.Save()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub SplitContainerControl2_SplitterPositionChanged(sender As Object, e As EventArgs) Handles SplitContainerControl2.SplitterPositionChanged
|
||||
If _IsLoading = False Then
|
||||
_Config.Config.SplitContainer2Distance = SplitContainerControl2.SplitterPosition
|
||||
_Config.Save()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub CreateDataGrid(GridView As GridView, Datatable As DataTable)
|
||||
GridView.GridControl.DataSource = Datatable
|
||||
End Sub
|
||||
|
||||
Private Sub GridView1_ColumnFilterChanged(sender As GridView, e As EventArgs) Handles GridView1.ColumnFilterChanged
|
||||
Dim oRowCount = sender.RowCount
|
||||
UpdateGridHeader(0, oRowCount)
|
||||
End Sub
|
||||
|
||||
Private Sub GridView2_ColumnFilterChanged(sender As GridView, e As EventArgs) Handles GridView2.ColumnFilterChanged
|
||||
Dim oRowCount = sender.RowCount
|
||||
UpdateGridHeader(1, oRowCount)
|
||||
End Sub
|
||||
|
||||
Private Sub GridView3_ColumnFilterChanged(sender As GridView, e As EventArgs) Handles GridView3.ColumnFilterChanged
|
||||
Dim oRowCount = sender.RowCount
|
||||
UpdateGridHeader(2, oRowCount)
|
||||
End Sub
|
||||
|
||||
Private Sub UpdateGridHeader(Index As Integer, Count As Integer)
|
||||
Select Case Index
|
||||
Case 0
|
||||
Dim oResult = _ResultLists.Item(0)
|
||||
GridBand1.Caption = $"{oResult.Title} ({Count})"
|
||||
|
||||
Case 1
|
||||
Dim oResult = _ResultLists.Item(1)
|
||||
GridBand2.Caption = $"{oResult.Title} ({Count})"
|
||||
|
||||
Case 2
|
||||
Dim oResult = _ResultLists.Item(2)
|
||||
GridBand3.Caption = $"{oResult.Title} ({Count})"
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Private Sub SetActiveGridBand()
|
||||
If _ActiveGrid.Equals(GridControl1) Then
|
||||
_ActiveGridBand = GridBand1
|
||||
ElseIf _ActiveGrid.Equals(GridControl2) Then
|
||||
_ActiveGridBand = GridBand2
|
||||
ElseIf _ActiveGrid.Equals(GridControl3) Then
|
||||
_ActiveGridBand = GridBand3
|
||||
Else
|
||||
_ActiveGridBand = Nothing
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Function GetActiveRow() As DataRow
|
||||
Dim oActiveGrid = GetActiveGridControl()
|
||||
Dim oActiveRowhandle = GetActiveRowHandle()
|
||||
|
||||
If oActiveGrid IsNot Nothing And oActiveRowhandle <> Constants.NO_ROW_HANDLE Then
|
||||
Dim oView = DirectCast(oActiveGrid.DefaultView, GridView)
|
||||
Dim oRow = oView.GetDataRow(oActiveRowhandle)
|
||||
Return oRow
|
||||
Else
|
||||
Return Nothing
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function GetActiveGridControl() As GridControl
|
||||
If _ActiveGrid Is Nothing Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Return _ActiveGrid
|
||||
End Function
|
||||
|
||||
Private Function GetActiveRowHandle() As Integer
|
||||
If _ActiveRowHandle = Constants.NO_ROW_HANDLE Then
|
||||
Return Constants.NO_ROW_HANDLE
|
||||
End If
|
||||
|
||||
Return _ActiveRowHandle
|
||||
End Function
|
||||
|
||||
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
|
||||
Dim oActiveGrid = GetActiveGridControl()
|
||||
|
||||
If oActiveGrid IsNot Nothing Then
|
||||
Dim oGridBand = _ActiveGridBand
|
||||
|
||||
XtraSaveFileDialog.FileName = Utils.ConvertTextToSlug(oGridBand.Caption) & ".xlsx"
|
||||
XtraSaveFileDialog.DefaultExt = ".xlsx"
|
||||
|
||||
If XtraSaveFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
|
||||
Dim oOptions As New XlsxExportOptions() With {
|
||||
.ExportMode = XlsxExportMode.SingleFile
|
||||
}
|
||||
oActiveGrid.ExportToXlsx(XtraSaveFileDialog.FileName, oOptions)
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick
|
||||
ShouldReturnToMatchForm = True
|
||||
Close()
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user