Improve RefreshHelper, dont run TimerRefresh if validator or admin is open

This commit is contained in:
Jonathan Jenne 2021-10-01 13:25:02 +02:00
parent 33ddd7a28b
commit bd68138b49
3 changed files with 241 additions and 213 deletions

View File

@ -4,223 +4,241 @@ Imports DevExpress.XtraGrid
Imports DevExpress.Utils
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Imports DigitalData.Modules.Logging
Public Class RefreshHelper
'<Serializable>
'Public Structure RowInfo
' Public Id As Object
' Public Level As Integer
'End Structure
''' <summary>
''' Saves information about the current row, like the level and row handle
''' </summary>
<Serializable>
Public Structure RowInfo
Public Id As Object
Public level As Integer
End Structure
Public Class RowInfo
Public Property Id As Object
Public Property Level As Integer
Public Property Handle As Integer
End Class
Private view As GridView
Private keyFieldName As String
Private Property _View As GridView
Private Property _KeyFieldName As String
Private Property _Logger As Logger
Private saveExpList_Renamed As ArrayList
Private Property _VisibleRowIndex As Integer = -1
Private saveSelList_Renamed As ArrayList
Private ReadOnly Property ExpansionViewInfoList() As New List(Of RowInfo)
Private ReadOnly Property SelectionViewInfoList() As New List(Of RowInfo)
Private ReadOnly Property ExpandedMasterRowList() As New List(Of Object)
Private saveMasterRowsList_Renamed As ArrayList
Private visibleRowIndex As Integer = -1
Public Sub New(ByVal view As GridView, ByVal keyFieldName As String)
Me.view = view
Me.keyFieldName = keyFieldName
End Sub
Public ReadOnly Property SaveExpList() As ArrayList
Get
If saveExpList_Renamed Is Nothing Then
saveExpList_Renamed = New ArrayList()
End If
Return saveExpList_Renamed
End Get
End Property
Public ReadOnly Property SaveSelList() As ArrayList
Get
If saveSelList_Renamed Is Nothing Then
saveSelList_Renamed = New ArrayList()
End If
Return saveSelList_Renamed
End Get
End Property
Public ReadOnly Property SaveMasterRowsList() As ArrayList
Get
If saveMasterRowsList_Renamed Is Nothing Then
saveMasterRowsList_Renamed = New ArrayList()
End If
Return saveMasterRowsList_Renamed
End Get
End Property
Protected Function FindParentRowHandle(ByVal rowInfo As RowInfo, ByVal rowHandle As Integer) As Integer
Dim result As Integer = view.GetParentRowHandle(rowHandle)
Do While view.GetRowLevel(result) <> rowInfo.level
result = view.GetParentRowHandle(result)
Loop
Return result
End Function
Protected Sub ExpandRowByRowInfo(ByVal rowInfo As RowInfo)
Dim dataRowHandle As Integer = view.LocateByValue(0, view.Columns(keyFieldName), rowInfo.Id)
If dataRowHandle <> GridControl.InvalidRowHandle Then
Dim parentRowHandle As Integer = FindParentRowHandle(rowInfo, dataRowHandle)
view.SetRowExpanded(parentRowHandle, True, False)
End If
End Sub
Protected Function GetRowHandleToSelect(ByVal rowInfo As RowInfo) As Integer
Dim dataRowHandle As Integer = view.LocateByValue(0, view.Columns(keyFieldName), rowInfo.Id)
If dataRowHandle <> GridControl.InvalidRowHandle Then
If view.GetRowLevel(dataRowHandle) <> rowInfo.level Then
Return FindParentRowHandle(rowInfo, dataRowHandle)
End If
End If
Return dataRowHandle
End Function
Protected Sub SelectRowByRowInfo(ByVal rowInfo As RowInfo, ByVal isFocused As Boolean)
If isFocused Then
view.FocusedRowHandle = GetRowHandleToSelect(rowInfo)
Else
view.SelectRow(GetRowHandleToSelect(rowInfo))
End If
End Sub
Public Sub SaveSelectionViewInfo(ByVal list As ArrayList)
list.Clear()
Dim column As GridColumn = view.Columns(keyFieldName)
Dim rowInfo As RowInfo
Dim selectionArray() As Integer = view.GetSelectedRows()
If selectionArray IsNot Nothing Then ' otherwise we have a single focused but not selected row
For i As Integer = 0 To selectionArray.Length - 1
Dim dataRowHandle As Integer = selectionArray(i)
rowInfo.level = view.GetRowLevel(dataRowHandle)
If dataRowHandle < 0 Then ' group row
dataRowHandle = view.GetDataRowHandleByGroupRowHandle(dataRowHandle)
End If
rowInfo.Id = view.GetRowCellValue(dataRowHandle, column)
list.Add(rowInfo)
Next i
End If
rowInfo.Id = view.GetRowCellValue(view.FocusedRowHandle, column)
rowInfo.level = view.GetRowLevel(view.FocusedRowHandle)
list.Add(rowInfo)
End Sub
Public Sub SaveExpansionViewInfo(ByVal list As ArrayList)
If view.GroupedColumns.Count = 0 Then
Return
End If
list.Clear()
Dim column As GridColumn = view.Columns(keyFieldName)
For i As Integer = -1 To Integer.MinValue + 1 Step -1
If Not view.IsValidRowHandle(i) Then
Exit For
End If
If view.GetRowExpanded(i) Then
Dim rowInfo As RowInfo
Dim dataRowHandle As Integer = view.GetDataRowHandleByGroupRowHandle(i)
rowInfo.Id = view.GetRowCellValue(dataRowHandle, column)
rowInfo.level = view.GetRowLevel(i)
list.Add(rowInfo)
End If
Next i
End Sub
Public Sub SaveExpandedMasterRows(ByVal list As ArrayList)
If view.GridControl.Views.Count = 1 Then
Return
End If
list.Clear()
Dim column As GridColumn = view.Columns(keyFieldName)
For i As Integer = 0 To view.DataRowCount - 1
If view.GetMasterRowExpanded(i) Then
list.Add(view.GetRowCellValue(i, column))
End If
Next i
End Sub
Public Sub SaveVisibleIndex()
visibleRowIndex = view.GetVisibleIndex(view.FocusedRowHandle) - view.TopRowIndex
End Sub
Public Sub LoadVisibleIndex()
Try
view.MakeRowVisible(view.FocusedRowHandle, True)
view.TopRowIndex = view.GetVisibleIndex(view.FocusedRowHandle) - visibleRowIndex
Catch ex As Exception
End Try
End Sub
Public Sub LoadSelectionViewInfo(ByVal list As ArrayList)
view.BeginSelection()
Try
view.ClearSelection()
For i As Integer = 0 To list.Count - 1
SelectRowByRowInfo(DirectCast(list(i), RowInfo), i = list.Count - 1)
Next i
Finally
view.EndSelection()
End Try
End Sub
Public Sub LoadExpansionViewInfo(ByVal list As ArrayList)
If view.GroupedColumns.Count = 0 Then
Return
End If
view.BeginUpdate()
Try
view.CollapseAllGroups()
For Each info As RowInfo In list
ExpandRowByRowInfo(info)
Next info
Finally
view.EndUpdate()
End Try
End Sub
Public Sub LoadExpandedMasterRows(ByVal list As ArrayList)
view.BeginUpdate()
Try
view.CollapseAllDetails()
Dim column As GridColumn = view.Columns(keyFieldName)
For i As Integer = 0 To list.Count - 1
Dim rowHandle As Integer = view.LocateByValue(0, column, list(i))
view.SetMasterRowExpanded(rowHandle, True)
Next i
Finally
view.EndUpdate()
End Try
Public Sub New(pLogConfig As LogConfig, pView As GridView, pKeyFieldName As String)
_View = pView
_KeyFieldName = pKeyFieldName
_Logger = pLogConfig.GetLogger()
End Sub
Public Sub SaveViewInfo()
Try
SaveExpandedMasterRows(SaveMasterRowsList)
SaveExpansionViewInfo(SaveExpList)
SaveSelectionViewInfo(SaveSelList)
SaveExpandedMasterRows()
SaveExpansionViewInfo()
SaveSelectionViewInfo()
SaveVisibleIndex()
Catch ex As Exception
_Logger.Error(ex)
End Try
End Sub
Public Sub LoadViewInfo()
Try
LoadExpandedMasterRows(SaveMasterRowsList)
LoadExpansionViewInfo(SaveExpList)
LoadSelectionViewInfo(SaveSelList)
LoadExpandedMasterRows()
LoadExpansionViewInfo()
LoadSelectionViewInfo()
LoadVisibleIndex()
Catch ex As Exception
_Logger.Error(ex)
End Try
End Sub
Private Function FindParentRowHandle(pRowInfo As RowInfo, oRowHandle As Integer) As Integer
Dim oParentRowHandle As Integer = _View.GetParentRowHandle(oRowHandle)
Do While _View.GetRowLevel(oParentRowHandle) <> pRowInfo.Level
oParentRowHandle = _View.GetParentRowHandle(oParentRowHandle)
Loop
Return oParentRowHandle
End Function
Private Function GetKeyColumn() As GridColumn
Return _View.Columns(_KeyFieldName)
End Function
Private Function GetKeyColumnValue(pRowHandle As Integer) As Object
Return _View.GetRowCellValue(pRowHandle, GetKeyColumn())
End Function
Private Sub ExpandRowByRowInfo(pRowInfo As RowInfo)
'Dim oDataRowHandle As Integer = _View.LocateByValue(0, GetKeyColumn(), rowInfo.Id)
Dim oDataRowHandle As Integer = pRowInfo.Handle
If oDataRowHandle <> GridControl.InvalidRowHandle Then
Dim parentRowHandle As Integer = FindParentRowHandle(pRowInfo, oDataRowHandle)
_View.SetRowExpanded(parentRowHandle, True, False)
End If
End Sub
Private Function GetRowHandleToSelect(pRowInfo As RowInfo) As Integer
'Dim oDataRowHandle As Integer = _View.LocateByValue(0, GetKeyColumn(), rowInfo.Id)
Dim oDataRowHandle As Integer = pRowInfo.Handle
If oDataRowHandle <> GridControl.InvalidRowHandle Then
If _View.GetRowLevel(oDataRowHandle) <> pRowInfo.Level Then
Return FindParentRowHandle(pRowInfo, oDataRowHandle)
End If
End If
Return oDataRowHandle
End Function
Private Sub SelectRowByRowInfo(pRowInfo As RowInfo, pIsFocused As Boolean)
If pIsFocused Then
_View.FocusedRowHandle = GetRowHandleToSelect(pRowInfo)
Else
_View.SelectRow(GetRowHandleToSelect(pRowInfo))
End If
End Sub
Private Sub SaveSelectionViewInfo()
SelectionViewInfoList.Clear()
Dim oSelectionArray() As Integer = _View.GetSelectedRows()
If oSelectionArray IsNot Nothing Then ' otherwise we have a single focused but not selected row
Dim oRowInfo As New RowInfo
For oIndex As Integer = 0 To oSelectionArray.Length - 1
Dim oDataRowHandle As Integer = oSelectionArray(oIndex)
oRowInfo.Level = _View.GetRowLevel(oDataRowHandle)
If oDataRowHandle < 0 Then ' group row
oDataRowHandle = _View.GetDataRowHandleByGroupRowHandle(oDataRowHandle)
End If
oRowInfo.Id = GetKeyColumnValue(oDataRowHandle)
oRowInfo.Handle = oDataRowHandle
SelectionViewInfoList.Add(oRowInfo)
Next
Else
SelectionViewInfoList.Add(New RowInfo With {
.Id = GetKeyColumnValue(_View.FocusedRowHandle),
.Level = _View.GetRowLevel(_View.FocusedRowHandle),
.Handle = _View.FocusedRowHandle
})
End If
End Sub
Private Sub SaveExpansionViewInfo()
' Dont do anything if the current view does not have any grouped columns
If _View.GroupedColumns.Count = 0 Then
Return
End If
' Clear the list first
ExpansionViewInfoList.Clear()
For oIndex As Integer = -1 To Integer.MinValue + 1 Step -1
If Not _View.IsValidRowHandle(oIndex) Then
Exit For
End If
If _View.GetRowExpanded(oIndex) Then
Dim oDataRowHandle As Integer = _View.GetDataRowHandleByGroupRowHandle(oIndex)
ExpansionViewInfoList.Add(New RowInfo With {
.Id = GetKeyColumnValue(oDataRowHandle),
.Level = _View.GetRowLevel(oIndex),
.Handle = oDataRowHandle
})
End If
Next
End Sub
Private Sub SaveExpandedMasterRows()
If _View.GridControl.Views.Count = 1 Then
Return
End If
ExpandedMasterRowList.Clear()
For oIndex As Integer = 0 To _View.DataRowCount - 1
If _View.GetMasterRowExpanded(oIndex) Then
ExpandedMasterRowList.Add(GetKeyColumnValue(oIndex))
End If
Next
End Sub
Private Sub SaveVisibleIndex()
_VisibleRowIndex = _View.GetVisibleIndex(_View.FocusedRowHandle) - _View.TopRowIndex
End Sub
Private Sub LoadVisibleIndex()
Try
_View.MakeRowVisible(_View.FocusedRowHandle, True)
_View.TopRowIndex = _View.GetVisibleIndex(_View.FocusedRowHandle) - _VisibleRowIndex
Catch ex As Exception
_Logger.Error(ex)
End Try
End Sub
Private Sub LoadSelectionViewInfo()
_View.BeginSelection()
Try
_View.ClearSelection()
For i As Integer = 0 To SelectionViewInfoList.Count - 1
SelectRowByRowInfo(DirectCast(SelectionViewInfoList(i), RowInfo), i = SelectionViewInfoList.Count - 1)
Next i
Catch ex As Exception
_Logger.Error(ex)
Finally
_View.EndSelection()
End Try
End Sub
Private Sub LoadExpansionViewInfo()
If _View.GroupedColumns.Count = 0 Then
Return
End If
_View.BeginUpdate()
Try
_View.CollapseAllGroups()
For Each info As RowInfo In ExpansionViewInfoList
ExpandRowByRowInfo(info)
Next info
Catch ex As Exception
_Logger.Error(ex)
Finally
_View.EndUpdate()
End Try
End Sub
Private Sub LoadExpandedMasterRows()
_View.BeginUpdate()
Try
_View.CollapseAllDetails()
Dim oColumn As GridColumn = GetKeyColumn()
For oIndex As Integer = 0 To ExpandedMasterRowList.Count - 1
Dim oRowHandle As Integer = _View.LocateByValue(0, oColumn, ExpandedMasterRowList(oIndex))
_View.SetMasterRowExpanded(oRowHandle, True)
Next oIndex
Catch ex As Exception
_Logger.Error(ex)
Finally
_View.EndUpdate()
End Try
End Sub
Public Class SW
Public label As String
Public stopwatch As Stopwatch

View File

@ -125,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADw
CAAAAk1TRnQBSQFMAgEBAgEAAawBBwGsAQcBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAAbQBBwG0AQcBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
@ -840,7 +840,7 @@
<value>728, 17</value>
</metadata>
<metadata name="Timer5Mins.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>426, 56</value>
<value>862, 97</value>
</metadata>
<metadata name="ToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>541, 56</value>

View File

@ -143,7 +143,7 @@ Public Class frmMain
LOGGER.Debug("Initializing MainForm....")
' Create helper to save/load expanded GroupColumns at runtime
RefreshHelper = New RefreshHelper(GridView_Docs, "GUID")
RefreshHelper = New RefreshHelper(LOGCONFIG, GridView_Docs, "GUID")
Dim oVErsion = String.Format("{0}.{1}.{2}", My.Application.Info.Version.Major, My.Application.Info.Version.Minor, My.Application.Info.Version.Build)
bsiVersion.Caption = oVErsion
If ERROR_STATE = "NO DB-CONNECTION" Or ERROR_STATE = "FAILED DBCONNECTION" Then
@ -1076,7 +1076,7 @@ Public Class frmMain
Me.BringToFront()
Visible = True
End Sub
Private Async Sub Timer_Tick(sender As System.Object, e As EventArgs) Handles TimerRefresh.Tick
Private Async Sub TimerRefresh_Tick(sender As System.Object, e As EventArgs) Handles TimerRefresh.Tick
Try
If TimerRefresh.Enabled = False Then
Exit Sub
@ -1089,21 +1089,25 @@ Public Class frmMain
End If
TimerRefresh_running = True
'If Application.OpenForms().OfType(Of frmValidator).Any Then
' Exit Sub
'End If
'If Application.OpenForms().OfType(Of frmAdministration).Any Then
' Exit Sub
'End If
'If Application.OpenForms().OfType(Of frmAdmin2).Any Then
' Exit Sub
'End If
' Cancel Refresh if a Validator Form or an Admin Form is opened
If Application.OpenForms().OfType(Of frmMassValidator).Any() Or
Application.OpenForms().OfType(Of frmValidator).Any() Or
Application.OpenForms().OfType(Of frmAdministration).Any() Or
Application.OpenForms().OfType(Of frmAdmin2).Any() Then
Exit Sub
End If
If USER_LANGUAGE <> "de-DE" Then
bsilastsync.Caption = "Last Client-Sync: " & Now.ToLongTimeString
Else
bsilastsync.Caption = "Letzte Synchronisation: " & Now.ToLongTimeString
End If
If GridControl_Docs.Visible = True And FormOpenClose = False Then RefreshHelper.SaveViewInfo()
If GridControl_Docs.Visible = True And FormOpenClose = False Then
RefreshHelper.SaveViewInfo()
End If
'If Not Application.OpenForms().OfType(Of frmValidator).Any Then
' Dim oUpdate = "Not Defined"
' Try
@ -1116,9 +1120,10 @@ Public Class frmMain
'End If
If bwSync.IsBusy Then
Exit Sub
TimerRefresh_running = False
Exit Sub
End If
Try
' SaveGridLayout()
'bwSync.ReportProgress(10)
@ -1208,7 +1213,6 @@ Public Class frmMain
End If
End Function
Private Sub ToolStripButton2_Click_2(sender As Object, e As EventArgs)
frmAdminPasswort.ShowDialog()
End Sub
@ -2016,7 +2020,11 @@ Public Class frmMain
FRONTEND_ACTION = "NONE"
End Sub
Async Function Reset_GridLayout(FormLoad As Boolean) As Tasks.Task
If GridControl_Docs.Visible = True And FormOpenClose = False Then RefreshHelper.SaveViewInfo()
If GridControl_Docs.Visible = True And FormOpenClose = False Then
RefreshHelper.SaveViewInfo()
End If
InResetlayout = True
' Layout zurücksetzen
ResetLayout()
@ -2144,7 +2152,9 @@ Public Class frmMain
Private Sub GridView_Docs_LostFocus(sender As Object, e As EventArgs) Handles GridView_Docs.LostFocus
' Save expanded GroupRows
If GridControl_Docs.Visible = True And FormOpenClose = False Then RefreshHelper.SaveViewInfo()
If GridControl_Docs.Visible = True And FormOpenClose = False Then
RefreshHelper.SaveViewInfo()
End If
End Sub
Sub LoadCURRENT_DT_PROFILES()
Dim oSQL = "select * from TBPM_PROFILE where ACTIVE = 1"