jj 14_12
This commit is contained in:
parent
f2997b8f26
commit
1607cb96c5
68
app/DD-Record-Organiser/ClassControlValueCache.vb
Normal file
68
app/DD-Record-Organiser/ClassControlValueCache.vb
Normal file
@ -0,0 +1,68 @@
|
||||
Public Class ClassControlValueCache
|
||||
|
||||
Private Shared Property Cache As New Dictionary(Of String, Dictionary(Of String, DataTable))
|
||||
|
||||
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())
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
End Class
|
||||
@ -396,8 +396,13 @@ Public Class ClassControlValues
|
||||
|
||||
Public Shared Sub LoadControlValuesList(RecordID As Integer, FormID As Integer, controls As Control.ControlCollection)
|
||||
Try
|
||||
|
||||
Dim SW As Stopwatch = Stopwatch.StartNew()
|
||||
|
||||
For Each Ctrl As Control In controls
|
||||
If TypeOf Ctrl Is ComboBox Then
|
||||
Dim swInner As Stopwatch = Stopwatch.StartNew()
|
||||
|
||||
Dim Combobox = DirectCast(Ctrl, ComboBox)
|
||||
|
||||
Dim SQL As String = String.Format("SELECT SQL_COMMAND_1 FROM TBPMO_CONTROL WHERE FORM_ID = {0} AND NAME = '{1}'", CURRENT_FORM_ID, Ctrl.Name)
|
||||
@ -412,14 +417,24 @@ Public Class ClassControlValues
|
||||
SQL2 = SQL2.ToString.Replace("@PARENTRECORD_ID", CURRENT_PARENTID)
|
||||
' If LogErrorsOnly = False Then ClassLogger.Add(">> SQL Combobox: " & cmbSql, False)
|
||||
End If
|
||||
Dim DT_Combobox As DataTable = ClassDatabase.Return_Datatable(SQL2)
|
||||
|
||||
Dim controlId As Integer = GetControlID_for_Name(Combobox.Name, FormID)
|
||||
'Dim DT_Combobox As DataTable = ClassDatabase.Return_Datatable(SQL2)
|
||||
|
||||
' Zuerst versuchen, DataTable aus dem Cache zu laden
|
||||
Dim DT_Combobox As DataTable = ClassControlValueCache.LoadFromCache(FormID, controlId)
|
||||
' Wenn DataTable nicht im Cache vorhanden, aus der Datenbank laden
|
||||
If IsNothing(DT_Combobox) Then
|
||||
DT_Combobox = ClassDatabase.Return_Datatable(SQL2)
|
||||
End If
|
||||
|
||||
If DT_Combobox Is Nothing = False Then
|
||||
If DT_Combobox.Rows.Count > 0 Then
|
||||
Combobox.DataSource = DT_Combobox
|
||||
Combobox.DisplayMember = DT_Combobox.Columns(1).ColumnName
|
||||
Combobox.ValueMember = DT_Combobox.Columns(0).ColumnName
|
||||
'Combobox.AutoCompleteMode = AutoCompleteMode.Append
|
||||
'Combobox.AutoCompleteSource = AutoCompleteSource.ListItems
|
||||
|
||||
ClassControlValueCache.SaveToCache(FormID, controlId, DT_Combobox)
|
||||
End If
|
||||
|
||||
Dim iWidestWidth As Integer = 300
|
||||
@ -438,13 +453,20 @@ Public Class ClassControlValues
|
||||
Combobox.DropDownWidth = Math.Max(iWidestWidth, Combobox.Width)
|
||||
End If
|
||||
|
||||
LoadControlValue(RecordID, GetControlID_for_Name(Combobox.Name, FormID), Ctrl)
|
||||
LoadControlValue(RecordID, controlId, Ctrl)
|
||||
|
||||
End If
|
||||
|
||||
swInner.Stop()
|
||||
Console.WriteLine("Loading List for Control {0} took {1} milliseconds", Ctrl.Name, swInner.ElapsedMilliseconds)
|
||||
End If
|
||||
|
||||
|
||||
Next
|
||||
|
||||
SW.Stop()
|
||||
Console.WriteLine("LoadControlValuesList took {0} milliseconds to load", SW.ElapsedMilliseconds)
|
||||
|
||||
Catch ex As Exception
|
||||
MsgBox("Unexpected Error in LoadControlValuesList:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||
End Try
|
||||
|
||||
@ -241,6 +241,7 @@
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ClassControlValueCache.vb" />
|
||||
<Compile Include="ClassControlValuesConverter.vb" />
|
||||
<Compile Include="ClassLicence.vb" />
|
||||
<Compile Include="frmAbout.designer.vb">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user