Optimierung Speed Load_Next Document

This commit is contained in:
Developer01
2026-01-30 12:09:21 +01:00
parent 0e6848aa69
commit df4a8df25a
3 changed files with 149 additions and 80 deletions

View File

@@ -259,8 +259,8 @@ Partial Class frmValidator
'DocumentViewer1
'
Me.DocumentViewer1.BackColor = System.Drawing.SystemColors.ControlLightLight
Me.DocumentViewer1.FileLoaded = False
resources.ApplyResources(Me.DocumentViewer1, "DocumentViewer1")
Me.DocumentViewer1.FileLoaded = False
Me.DocumentViewer1.Name = "DocumentViewer1"
Me.DocumentViewer1.Viewer_ForceTemporaryMode = False
'

View File

@@ -630,6 +630,9 @@
<data name="&gt;&gt;SplitContainer1.Panel1.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="DocumentViewer1.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
<data name="DocumentViewer1.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 0</value>
</data>
@@ -637,7 +640,7 @@
<value>4, 4, 4, 4</value>
</data>
<data name="DocumentViewer1.Size" type="System.Drawing.Size, System.Drawing">
<value>1121, 683</value>
<value>669, 422</value>
</data>
<data name="DocumentViewer1.TabIndex" type="System.Int32, mscorlib">
<value>0</value>

View File

@@ -126,6 +126,7 @@ Public Class frmValidator
Private frmMessages As frmValidator_Messages
Private ReadOnly _SqlDataCache As New Dictionary(Of String, DataTable)(StringComparer.OrdinalIgnoreCase)
Private ReadOnly _SqlScalarCache As New Dictionary(Of String, Object)(StringComparer.OrdinalIgnoreCase)
Private _SqlControlsByGuid As Dictionary(Of Integer, List(Of DataRow))
Private Class Translation_Strings
Inherits My.Resources.frmValidator_Strings
End Class
@@ -749,6 +750,35 @@ Public Class frmValidator
End Try
End Sub
Private Sub EnsureSqlControlLookup()
If _SqlControlsByGuid IsNot Nothing Then
Return
End If
_SqlControlsByGuid = New Dictionary(Of Integer, List(Of DataRow))()
If DTCONTROLS_WITH_SQL Is Nothing OrElse DTCONTROLS_WITH_SQL.Rows.Count = 0 Then
Return
End If
For Each row As DataRow In DTCONTROLS_WITH_SQL.Rows
If row.ItemEx("PROFIL_ID", 0) <> CURRENT_ProfilGUID Then
Continue For
End If
Dim controlId As Integer
If Not Integer.TryParse(row.Item("GUID").ToString(), controlId) Then
Continue For
End If
Dim list As List(Of DataRow) = Nothing
If Not _SqlControlsByGuid.TryGetValue(controlId, list) Then
list = New List(Of DataRow)()
_SqlControlsByGuid(controlId) = list
End If
list.Add(row)
Next
End Sub
Sub LoadSQLData(control As Control, pControlId As Integer)
Try
If TypeOf control Is Label Then
@@ -757,14 +787,14 @@ Public Class frmValidator
MyValidationLogger.Debug($"in LoadSQLData for ControlID [{pControlId}]...")
Dim oDTforControl As DataTable = DTCONTROLS_WITH_SQL.Clone()
Dim oExpression = $"GUID = {pControlId} AND PROFIL_ID = {CURRENT_ProfilGUID}"
DTCONTROLS_WITH_SQL.Select(oExpression).CopyToDataTable(oDTforControl, LoadOption.PreserveChanges)
EnsureSqlControlLookup()
If IsNothing(oDTforControl) Then Exit Sub
If oDTforControl.Rows.Count = 0 Then Exit Sub
Dim rows As List(Of DataRow) = Nothing
If _SqlControlsByGuid Is Nothing OrElse Not _SqlControlsByGuid.TryGetValue(pControlId, rows) Then
Exit Sub
End If
For Each row As DataRow In oDTforControl.Rows
For Each row As DataRow In rows
Dim name As String = row.Item("NAME")
Dim oGUID As String = row.Item("GUID")
Dim oReadOnly As Boolean = row.Item("READ_ONLY")
@@ -787,12 +817,12 @@ Public Class frmValidator
Dim oSQLStatement As String = row.Item("SQL_UEBERPRUEFUNG")
Dim oConnectionId As Integer = row.Item("CONNECTION_ID")
If IsNothing(oSQLStatement) Then
If String.IsNullOrWhiteSpace(oSQLStatement) Then
Continue For
End If
oSQLStatement = clsPatterns.ReplaceAllValues(oSQLStatement, PanelValidatorControl, True)
If IsNothing(oSQLStatement) Then
If String.IsNullOrWhiteSpace(oSQLStatement) Then
Continue For
End If
If clsPatterns.HasComplexPatterns(oSQLStatement) Then
@@ -800,18 +830,9 @@ Public Class frmValidator
Continue For
End If
Dim oDTContent As DataTable = Nothing
Dim cacheKey = $"{oConnectionId}|{oSQLStatement}"
If Not _SqlDataCache.TryGetValue(cacheKey, oDTContent) Then
oDTContent = DatabaseFallback.GetDatatable(New GetDatatableOptions(oSQLStatement, DatabaseType.ECM) With {
.ConnectionId = oConnectionId
})
If IsNothing(oDTContent) Then
MyValidationLogger.Warn($"SQL-Query [{oSQLStatement}] for control {control.Name} is invalid.")
Exit Sub
End If
_SqlDataCache(cacheKey) = oDTContent
Dim oDTContent As DataTable = GetCachedDatatable(oSQLStatement, oConnectionId)
If oDTContent Is Nothing OrElse oDTContent.Rows.Count = 0 Then
Continue For
End If
Dim oValue
@@ -824,7 +845,6 @@ Public Class frmValidator
lookup.Properties.ValueMember = oDTContent.Columns.Item(0).ColumnName
lookup.Properties.DisplayMember = oDTContent.Columns.Item(0).ColumnName
Catch ex As Exception
MyValidationLogger.Warn("Error in LookUpLoadSQLData: " & ex.Message)
End Try
@@ -838,7 +858,6 @@ Public Class frmValidator
oValue = value
Catch ex As Exception
MyValidationLogger.Warn("Error in TextBoxLoadSQLData: " & ex.Message)
End Try
ElseIf TypeOf control Is Windows.Forms.ComboBox Then
Try
@@ -863,10 +882,12 @@ Public Class frmValidator
Dim dataGridView As GridControl = control
Dim oDataSource As DataTable = dataGridView.DataSource
If oDataSource Is Nothing OrElse oDataSource.Rows.Count = 0 Then
Dim oDatatable As DataTable = oDTContent.Clone()
If oDataSource Is Nothing Then
oDataSource = oDTContent.Clone()
End If
For Each oColumn As DataColumn In oDatatable.Columns
If oDataSource.Rows.Count = 0 Then
For Each oColumn As DataColumn In oDTContent.Columns
If oDataSource.Columns(oColumn.ColumnName) Is Nothing Then
oDataSource.Columns.Add(oColumn.ColumnName, oColumn.DataType)
End If
@@ -2784,8 +2805,17 @@ Public Class frmValidator
Sub Load_Next_Document(first As Boolean)
Dim perfStart As DateTime = DateTime.MinValue
Dim perfLastCheck As DateTime = DateTime.MinValue
If LOG_HOTSPOTS Then
perfStart = DateTime.Now
perfLastCheck = perfStart
MyValidationLogger.Info("[PERF] Load_Next_Document START")
End If
_SqlDataCache.Clear()
_SqlScalarCache.Clear()
_SqlControlsByGuid = Nothing
CURRENT_WMFILE = Nothing
activate_controls(False)
oErrMsgMissingInput = ""
@@ -2793,9 +2823,10 @@ Public Class frmValidator
Override = False
OverrideAll = False
'Me.lblerror.Visible = False
_Indexe_Loaded = False
MyValidationLogger.Debug("In Load_Next_Document")
Dim layoutSuspended As Boolean = False
Try
If first = True Then
MyValidationLogger.Debug("First Document")
@@ -2804,17 +2835,12 @@ Public Class frmValidator
MyValidationLogger.Debug("Following Document ")
End If
' Controls nicht beim ersten Laden leeren
If first = False Then
PanelValidatorControl.SuspendLayout()
layoutSuspended = True
Clear_all_Input()
End If
'Select Case navtype
' Case "next"
' Case "previous"
' Case "first"
' Case "last"
'End Select
MyValidationLogger.Debug($"CURRENT_JUMP_DOC_GUID: {CURRENT_JUMP_DOC_GUID}'")
If CURRENT_JUMP_DOC_GUID = 0 Then
CURRENT_DOC_GUID = Get_Next_GUID()
@@ -2822,11 +2848,23 @@ Public Class frmValidator
ElseIf first = False Then
CURRENT_DOC_GUID = 0
End If
If LOG_HOTSPOTS Then
MyValidationLogger.Info($"[PERF] Nach Get_Next_GUID: {(DateTime.Now - perfLastCheck).TotalMilliseconds}ms")
perfLastCheck = DateTime.Now
End If
MyValidationLogger.Info("LoadNextDocument - Dokument-GUID: '" & CURRENT_DOC_GUID.ToString & "'")
If CURRENT_DOC_GUID > 0 Then
If (OPERATION_MODE_FS = ClassConstants.OpModeFS_PWM Or OPERATION_MODE_FS = ClassConstants.OpModeFS_IDBWM) And GetDocPathWindows(0) = False Then
SetStatusLabel($"File not accessible: {DocPathWindows}", "DarkOrange")
End If
If LOG_HOTSPOTS Then
MyValidationLogger.Info($"[PERF] Nach GetDocPathWindows: {(DateTime.Now - perfLastCheck).TotalMilliseconds}ms")
perfLastCheck = DateTime.Now
End If
If IDB_ACTIVE = False Then
If CreateWMObject() = False Then
Exit Sub
@@ -2843,17 +2881,22 @@ Public Class frmValidator
End If
End If
' >> >> >> >> >> >>##### Das Dokument in Bearbeitung nehmen ###########################
'PRTF_PROFILE_FILES_WORK("InWork")
If LOG_HOTSPOTS Then
MyValidationLogger.Info($"[PERF] Nach CreateWMObject/Load_IDB_DOC_DATA: {(DateTime.Now - perfLastCheck).TotalMilliseconds}ms")
perfLastCheck = DateTime.Now
End If
Dim sql = $"UPDATE TBPM_PROFILE_FILES Set IN_WORK = 1, IN_WORK_WHEN = GETDATE(), WORK_USER = '{USER_USERNAME}' WHERE GUID = {CURRENT_DOC_GUID}"
DatabaseFallback.ExecuteNonQueryECM(sql)
' ############ Infos eintragen #################
If LOG_HOTSPOTS Then
MyValidationLogger.Info($"[PERF] Nach IN_WORK-UPDATE: {(DateTime.Now - perfLastCheck).TotalMilliseconds}ms")
perfLastCheck = DateTime.Now
End If
If Amount_Docs2Validate > 1 Then
Dim omsg = String.Format(Translation_Strings.Verbleibende_Vorgänge___0_, Amount_Docs2Validate)
bsiInformation.Caption = omsg
bsiInformation.Caption = omsg
If RbnPgGrpActions.Visible = False Then
RbnPgGrpActions.Visible = True
@@ -2872,21 +2915,21 @@ Public Class frmValidator
MyValidationLogger.Debug("AllDocInfo created...")
If IDB_ACTIVE = False Then
oErrMsgMissingInput = Windream_get_Doc_info()
Else
' oErrorMessage = IDB_GetDocInfo()
End If
If LOG_HOTSPOTS Then
MyValidationLogger.Info($"[PERF] Nach Windream_get_Doc_info: {(DateTime.Now - perfLastCheck).TotalMilliseconds}ms")
perfLastCheck = DateTime.Now
End If
Dim oCurrency As String
If PROFIL_CURRENCY_ATTRIBUTE <> "" Then
oCurrency = GetVariableValuefromSource(PROFIL_CURRENCY_ATTRIBUTE, 1, False)
MyValidationLogger.Debug(String.Format("Read oCurrency from Attribute: {0} is {1}", PROFIL_CURRENCY_ATTRIBUTE, oCurrency))
Else
oCurrency = "EUR"
MyValidationLogger.Debug(String.Format("oCurrency by default is {0}", oCurrency))
End If
If Not IsNothing(oCurrency) Then
DocCurrency = oCurrency
Dim oValueType = DocCurrency.GetType.ToString
If IsDBNull(DocCurrency) Then
DocCurrency = "EUR"
Else
@@ -2897,33 +2940,55 @@ Public Class frmValidator
DocCurrency = "EUR"
End Try
End If
Else
MyValidationLogger.Warn($"oCurrency is Nothing - Check PROFIL_CURRENCY_ATTRIBUTE! ")
End If
If oErrMsgMissingInput = "" Then
If WMDocPathWindows <> String.Empty Or OPERATION_MODE_FS = ClassConstants.OpModeFS_ZF Then
MyValidationLogger.Debug($"Operationmode is {ClassConstants.OpModeFS_ZF}! Initializing Viewer ...")
LoadDocument_DDViewer()
MyValidationLogger.Debug("Viewer loaded!!")
If Current_Document.Extension <> "pdf" Then
bbtniAnnotation.Visibility = BarItemVisibility.Never
End If
End If
If LOG_HOTSPOTS Then
MyValidationLogger.Info($"[PERF] Nach LoadDocument_DDViewer: {(DateTime.Now - perfLastCheck).TotalMilliseconds}ms")
perfLastCheck = DateTime.Now
End If
FillIndexValues(first)
For Each oControl As Control In PanelValidatorControl.Controls
LoadSQLData(oControl, DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).Guid)
Next
If LOG_HOTSPOTS Then
MyValidationLogger.Info($"[PERF] Nach FillIndexValues: {(DateTime.Now - perfLastCheck).TotalMilliseconds}ms")
perfLastCheck = DateTime.Now
End If
MyValidationLogger.Debug("Indexmask loaded")
Dim sqlControls As DataRow() = Nothing
If DTCONTROLS_WITH_SQL IsNot Nothing AndAlso DTCONTROLS_WITH_SQL.Rows.Count > 0 Then
sqlControls = DTCONTROLS_WITH_SQL.Select($"PROFIL_ID = {CURRENT_ProfilGUID}")
End If
If sqlControls IsNot Nothing AndAlso sqlControls.Length > 0 Then
Dim sqlControlIds As New HashSet(Of Integer)()
For Each r As DataRow In sqlControls
Dim controlId As Integer = 0
If Integer.TryParse(r.Item("GUID").ToString, controlId) Then
sqlControlIds.Add(controlId)
End If
Next
For Each oControl As Control In PanelValidatorControl.Controls
Dim controlId = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).Guid
If sqlControlIds.Contains(controlId) Then
LoadSQLData(oControl, controlId)
End If
Next
End If
If LOG_HOTSPOTS Then
MyValidationLogger.Info($"[PERF] Nach LoadSQLData-Loop: {(DateTime.Now - perfLastCheck).TotalMilliseconds}ms")
perfLastCheck = DateTime.Now
End If
'Nun loggen das das Profil geladen wurde
If PROFIL_LOGINDEX <> "" Then
Dim oLogString = $"PMProfile loaded: [{CURRENT_ProfilGUID}-{CURRENT_ProfilName}]{PMDelimiter}{USER_USERNAME}{PMDelimiter}{Now.ToString}"
If IDB_ACTIVE = False Then
@@ -2951,19 +3016,14 @@ Public Class frmValidator
Me.Close()
End If
End If
Try
If DocCurrency <> String.Empty Then
If DocCurrency.ToString.Length <> 3 Then
MyValidationLogger.Info("DocCurrency-Length = 3 - Setting to EUR")
DocCurrency = "EUR"
End If
MyValidationLogger.Debug($"DocCurrency = {DocCurrency}")
For Each oControl As Control In PanelValidatorControl.Controls
Try
Dim oMeta = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata)
If TypeOf oControl Is GridControl Then
Dim oGrid As GridControl = DirectCast(oControl, GridControl)
Dim oControlMeta = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata)
@@ -2978,48 +3038,47 @@ Public Class frmValidator
settings.MaskExpression = "c"
settings.Culture = oCultureInfo
End Sub)
riTextEdit.UseMaskAsDisplayFormat = True 'Optional
riTextEdit.UseMaskAsDisplayFormat = True
oGrid.RepositoryItems.Add(riTextEdit)
Dim oGridView As GridView = DirectCast(oGrid.FocusedView, GridView)
For Each oCol As GridColumn In oGridView.Columns
Dim oColumnData As DataRow = oFilteredDatatable.
Select($"SPALTENNAME = '{oCol.FieldName}'").
FirstOrDefault()
Dim oColumnData As DataRow = oFilteredDatatable.Select($"SPALTENNAME = '{oCol.FieldName}'").FirstOrDefault()
If oColumnData Is Nothing Then
Continue For
End If
Dim oColumnType As String = oColumnData.Item("TYPE_COLUMN")
Select Case oColumnType
Case "CURRENCY"
Console.WriteLine("CurrencyFormatNecessary")
oCol.DisplayFormat.FormatType = FormatType.Custom
oCol.ColumnEdit = riTextEdit
End Select
If oColumnType = "CURRENCY" Then
oCol.DisplayFormat.FormatType = FormatType.Custom
oCol.ColumnEdit = riTextEdit
End If
Next
End If
Catch ex As Exception
MyValidationLogger.Error(ex)
End Try
Next
Else
MyValidationLogger.Warn($"DocCurrency is String.empty! ")
End If
Catch ex As Exception
MyValidationLogger.Warn($"Unexpected error in display format Currency: " & ex.Message)
End Try
Try
If LOG_HOTSPOTS Then
MyValidationLogger.Info($"[PERF] Nach Currency-Format: {(DateTime.Now - perfLastCheck).TotalMilliseconds}ms")
perfLastCheck = DateTime.Now
End If
Try
Show_WF_Messages(False)
Catch ex As Exception
MyValidationLogger.Error(ex)
End Try
Controls2B_EnDisabled()
If LOG_HOTSPOTS Then
MyValidationLogger.Info($"[PERF] Nach Show_WF_Messages + Controls2B_EnDisabled: {(DateTime.Now - perfLastCheck).TotalMilliseconds}ms")
End If
MyValidationLogger.Debug("frmValidator: LoadNextDocument finished!")
Catch ex As Exception
MyValidationLogger.Error(ex)
@@ -3027,6 +3086,13 @@ Public Class frmValidator
My.Settings.Save()
MyValidationLogger.Info("unexpected error in Load_Next_Document: " & ex.Message)
frmError.ShowDialog()
Finally
If layoutSuspended Then
PanelValidatorControl.ResumeLayout()
End If
If LOG_HOTSPOTS Then
MyValidationLogger.Info($"[PERF] Load_Next_Document GESAMT: {(DateTime.Now - perfStart).TotalMilliseconds}ms")
End If
End Try
End Sub
Sub Show_WF_Messages(pShow As Boolean)