Improve RefreshHelper, dont run TimerRefresh if validator or admin is open
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user