jj 19_01_16
This commit is contained in:
@@ -1,68 +1,31 @@
|
||||
Public Class ClassControlValueCache
|
||||
Private Shared Property Cache As New Dictionary(Of String, DataTable)
|
||||
|
||||
Private Shared Property Cache As New Dictionary(Of String, Dictionary(Of String, DataTable))
|
||||
' ClassControlValueCache
|
||||
' Ordnet SQL Queries den daraus resultierenden DataTables zu.
|
||||
'
|
||||
' Somit kann eine Query in der Laufzeit des Programms von mehreren Forms genutzt werden,
|
||||
' muss aber nur einmal vom Server abgefragt werden.
|
||||
Public Shared Function LoadFromCache(sqlCommand As String) As DataTable
|
||||
' Mit ToUpper wird das Command case-insensitive,
|
||||
' es ist also egal, ob die query GROSS oder klein geschrieben wird
|
||||
Dim UpperCaseCommand = sqlCommand.ToUpper()
|
||||
|
||||
Public Shared Function LoadFromCache(formId As Integer, controlId As Integer) As DataTable
|
||||
|
||||
Dim dict As Dictionary(Of String, DataTable) = GetCachedFormDict(formId.ToString())
|
||||
|
||||
If IsNothing(dict) Then
|
||||
Return Nothing
|
||||
Else
|
||||
|
||||
Dim dt As DataTable = GetCachedControlDict(dict, controlId.ToString())
|
||||
|
||||
If IsNothing(dt) Then
|
||||
Return Nothing
|
||||
Else
|
||||
Return dt
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
End Function
|
||||
|
||||
Public Shared Function SaveToCache(formId As Integer, controlId As Integer, dt As DataTable) As DataTable
|
||||
|
||||
Dim dict As Dictionary(Of String, DataTable) = GetCachedFormDict(formId.ToString())
|
||||
|
||||
If IsNothing(dict) Then
|
||||
dict = SetCachedFormDict(formId.ToString(), New Dictionary(Of String, DataTable))
|
||||
End If
|
||||
|
||||
SetCachedControlDict(dict, controlId.ToString(), dt)
|
||||
Return dt
|
||||
End Function
|
||||
|
||||
|
||||
Private Shared Function GetCachedFormDict(formId As Integer) As Dictionary(Of String, DataTable)
|
||||
|
||||
If Cache.ContainsKey(formId.ToString()) Then
|
||||
Return Cache.Item(formId.ToString())
|
||||
If Cache.ContainsKey(UpperCaseCommand) Then
|
||||
Return Cache.Item(UpperCaseCommand)
|
||||
Else
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
End Function
|
||||
|
||||
Private Shared Function SetCachedFormDict(formId As Integer, dict As Dictionary(Of String, DataTable)) As Dictionary(Of String, DataTable)
|
||||
Cache.Item(formId.ToString()) = dict
|
||||
Return dict
|
||||
End Function
|
||||
Public Shared Sub SaveToCache(sqlCommand As String, dt As DataTable)
|
||||
Dim UpperCaseCommand = sqlCommand.ToUpper()
|
||||
Cache.Item(UpperCaseCommand) = dt
|
||||
End Sub
|
||||
|
||||
Private Shared Function GetCachedControlDict(dict As Dictionary(Of String, DataTable), controlId As Integer) As DataTable
|
||||
|
||||
If dict.ContainsKey(controlId.ToString()) Then
|
||||
Return dict.Item(controlId.ToString())
|
||||
Else
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
End Function
|
||||
|
||||
Private Shared Function SetCachedControlDict(dict As Dictionary(Of String, DataTable), controlId As Integer, dt As DataTable) As DataTable
|
||||
dict.Item(controlId.ToString()) = dt
|
||||
Return dt
|
||||
End Function
|
||||
Public Shared Sub ClearCache()
|
||||
Cache.Clear()
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user