From f5c0a18a59864130cd137355660a52ab28d87e84 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 26 Oct 2021 11:06:04 +0200 Subject: [PATCH] ZooFlow: Add My.Helpers --- GUIs.ZooFlow/ClassHelpers.vb | 115 ++++++++++++++++++++++++++++ GUIs.ZooFlow/ClassInit.vb | 5 ++ GUIs.ZooFlow/Globix/ClassHelpers.vb | 48 ------------ GUIs.ZooFlow/ModuleHelpers.vb | 23 ------ GUIs.ZooFlow/MyApplication.vb | 1 + GUIs.ZooFlow/ZooFlow.vbproj | 5 +- 6 files changed, 125 insertions(+), 72 deletions(-) create mode 100644 GUIs.ZooFlow/ClassHelpers.vb delete mode 100644 GUIs.ZooFlow/Globix/ClassHelpers.vb diff --git a/GUIs.ZooFlow/ClassHelpers.vb b/GUIs.ZooFlow/ClassHelpers.vb new file mode 100644 index 00000000..652d849e --- /dev/null +++ b/GUIs.ZooFlow/ClassHelpers.vb @@ -0,0 +1,115 @@ +Imports DigitalData.GUIs.ZooFlow.Base +Imports DigitalData.Modules.Logging + +Public Class ClassHelpers + Inherits BaseClass + + Public Sub New(pLogConfig As LogConfig) + MyBase.New(pLogConfig) + End Sub + + Public Function GetValueFromDatatable(pDatatable As DataTable, pFilterString As String, pCheckColumn As String, pSortString As String) As Object + Try + If pDatatable.Rows.Count = 0 Then + Return Nothing + End If + + Dim oDataView As DataView = pDatatable.DefaultView + oDataView.RowFilter = pFilterString + + If oDataView.Count > 1 Then + Logger.Warn("Multiple Results For Filter [{0}] and Column [{1}].", pFilterString, pCheckColumn) + Return Nothing + End If + + If oDataView.Count = 0 Then + Logger.Warn("No Results For Filter [{0}] and Column [{1}].", pFilterString, pCheckColumn) + Return Nothing + End If + + Dim oView As DataRowView = oDataView.Item(0) + Dim oRow As DataRow = oView.Row + + Try + Return oRow.Item(pCheckColumn) + Catch ex As Exception + Logger.Warn("Datatable with Filter [{0}] does not contain Column [{1}]", pFilterString, pCheckColumn) + Logger.Error(ex) + Return Nothing + End Try + Catch ex As Exception + Logger.Error(ex) + Return Nothing + End Try + End Function + + Public Function GetFilteredDatatable(pDatatable As DataTable, pFilterString As String, pSortString As String) As DataTable + Try + If pDatatable.Rows.Count = 0 Then + Return Nothing + End If + + Dim oSelectedRows = pDatatable.Select(pFilterString, pSortString) + + If oSelectedRows.Count = 0 Then + Return Nothing + End If + + Dim oFilteredTable As DataTable = New DataTable() + oFilteredTable = oSelectedRows.CopyToDataTable() + Return oFilteredTable + + Catch ex As Exception + Logger.Error(ex) + Return Nothing + + End Try + End Function + + Public Shared Function FileExistsinDropTable(Filename As String) As Date + Dim oSQL As String + Dim oHash As String + Dim oFilesystem As New DigitalData.Modules.Filesystem.File(My.LogConfig) + + Try + If Filename.Contains("'") Then + Filename = Filename.Replace("'", "''") + End If + + Try + oHash = oFilesystem.GetChecksum(Filename) + Catch ex As Exception + oHash = "" + End Try + + oSQL = "SELECT * FROM TBGI_FILES_USER WHERE UPPER(FILE_HASH) = UPPER('" & oHash & "') AND WORKED = 0 ORDER BY ADDED_WHEN" + Dim oResult As DataTable = My.DatabaseECM.GetDatatable(oSQL) + + If oResult Is Nothing Then + Return Nothing + End If + + If oResult.Rows.Count = 0 Then + oSQL = "SELECT * FROM TBGI_HISTORY WHERE UPPER(FILE_HASH) = UPPER('" & oHash & "') ORDER BY ADDED_WHEN" + oResult = My.DatabaseECM.GetDatatable(oSQL) + + If oResult Is Nothing Then + Return Nothing + End If + + If oResult.Rows.Count = 0 Then + Return Nothing + Else + Dim oFirstRow As DataRow = oResult.Rows.Item(0) + Return oFirstRow.Item("ADDED_WHEN") + End If + Else + Dim oFirstRow As DataRow = oResult.Rows.Item(0) + Return oFirstRow.Item("ADDED_WHEN") + End If + Catch ex As Exception + MsgBox("Error in FileExistsinDropTable - Error-Message:" & vbNewLine & ex.Message & vbNewLine & "SQL-Command:" & vbNewLine & oSQL, MsgBoxStyle.Critical) + Return Nothing + End Try + End Function +End Class diff --git a/GUIs.ZooFlow/ClassInit.vb b/GUIs.ZooFlow/ClassInit.vb index 1d77cbbd..0bdf199f 100644 --- a/GUIs.ZooFlow/ClassInit.vb +++ b/GUIs.ZooFlow/ClassInit.vb @@ -40,6 +40,7 @@ Public Class ClassInit _Loader = New ClassInitLoader() ' === Init Schritte definieren + _Loader.AddStep("Initializing Base", AddressOf InitializeBase, True) _Loader.AddStep("Initializing Database (1/2)", AddressOf InitializeDatabase, True) _Loader.AddStep("Initializing EDMI Service", AddressOf InitializeService, True) _Loader.AddStep("Initializing Database (2/2)", AddressOf InitializeDatabaseWithFallback, True) @@ -58,6 +59,10 @@ Public Class ClassInit #Region "=== Init Steps ===" + Private Sub InitializeBase(MyApplication As My.MyApplication) + My.Helpers = New ClassHelpers(My.LogConfig) + End Sub + Private Sub InitializeDatabase(MyApplication As My.MyApplication) Dim oConnectionString = MSSQLServer.DecryptConnectionString(My.SystemConfig.ConnectionString) My.DatabaseECM = New MSSQLServer(My.LogConfig, oConnectionString) diff --git a/GUIs.ZooFlow/Globix/ClassHelpers.vb b/GUIs.ZooFlow/Globix/ClassHelpers.vb deleted file mode 100644 index 3fdda1b5..00000000 --- a/GUIs.ZooFlow/Globix/ClassHelpers.vb +++ /dev/null @@ -1,48 +0,0 @@ -Public Class ClassHelpers - Public Shared Function FileExistsinDropTable(Filename As String) As Date - Dim oSQL As String - Dim oHash As String - Dim oFilesystem As New DigitalData.Modules.Filesystem.File(My.LogConfig) - - Try - If Filename.Contains("'") Then - Filename = Filename.Replace("'", "''") - End If - - Try - oHash = oFilesystem.GetChecksum(Filename) - Catch ex As Exception - oHash = "" - End Try - - oSQL = "SELECT * FROM TBGI_FILES_USER WHERE UPPER(FILE_HASH) = UPPER('" & oHash & "') AND WORKED = 0 ORDER BY ADDED_WHEN" - Dim oResult As DataTable = My.DatabaseECM.GetDatatable(oSQL) - - If oResult Is Nothing Then - Return Nothing - End If - - If oResult.Rows.Count = 0 Then - oSQL = "SELECT * FROM TBGI_HISTORY WHERE UPPER(FILE_HASH) = UPPER('" & oHash & "') ORDER BY ADDED_WHEN" - oResult = My.DatabaseECM.GetDatatable(oSQL) - - If oResult Is Nothing Then - Return Nothing - End If - - If oResult.Rows.Count = 0 Then - Return Nothing - Else - Dim oFirstRow As DataRow = oResult.Rows.Item(0) - Return oFirstRow.Item("ADDED_WHEN") - End If - Else - Dim oFirstRow As DataRow = oResult.Rows.Item(0) - Return oFirstRow.Item("ADDED_WHEN") - End If - Catch ex As Exception - MsgBox("Error in FileExistsinDropTable - Error-Message:" & vbNewLine & ex.Message & vbNewLine & "SQL-Command:" & vbNewLine & oSQL, MsgBoxStyle.Critical) - Return Nothing - End Try - End Function -End Class diff --git a/GUIs.ZooFlow/ModuleHelpers.vb b/GUIs.ZooFlow/ModuleHelpers.vb index 3f9c710b..21fe76ee 100644 --- a/GUIs.ZooFlow/ModuleHelpers.vb +++ b/GUIs.ZooFlow/ModuleHelpers.vb @@ -85,27 +85,4 @@ Module ModuleHelpers End Try Return connectionString End Function - - Public Function FilterDatatable(pDatatable As DataTable, pFilterString As String, pCheckColumn As String, pSortString As String, pReturnDataTable As Boolean) As Object - Try - If pDatatable.Rows.Count = 0 Then - Return Nothing - End If - Dim oDataView As DataView = pDatatable.DefaultView - oDataView.RowFilter = pFilterString - If oDataView.Count = 1 And pReturnDataTable = False Then - Dim oView As DataRowView = oDataView.Item(0) - Dim oRow As DataRow = oView.Row - Return oRow.Item(pCheckColumn) - Else - Dim oDataTableCopy As DataTable = New DataTable() - oDataTableCopy = pDatatable.Select(pFilterString, pSortString).CopyToDataTable() - - Return oDataTableCopy - End If - Catch ex As Exception - MsgBox("Unexpected Error in FilterDatatable: " + ex.Message, MsgBoxStyle.Critical) - Return Nothing - End Try - End Function End Module diff --git a/GUIs.ZooFlow/MyApplication.vb b/GUIs.ZooFlow/MyApplication.vb index ca6c1bfb..6424c955 100644 --- a/GUIs.ZooFlow/MyApplication.vb +++ b/GUIs.ZooFlow/MyApplication.vb @@ -36,6 +36,7 @@ Namespace My Property Tables As New ClassTables Property Queries As New ClassQueries + Property Helpers As ClassHelpers #End Region Property Filestore_Work As String diff --git a/GUIs.ZooFlow/ZooFlow.vbproj b/GUIs.ZooFlow/ZooFlow.vbproj index 0886c015..9354c5f1 100644 --- a/GUIs.ZooFlow/ZooFlow.vbproj +++ b/GUIs.ZooFlow/ZooFlow.vbproj @@ -87,6 +87,9 @@ + + ..\Controls.SnapPanel\obj\Debug\DigitalData.Controls.SnapPanel.dll + P:\Visual Studio Projekte\Bibliotheken\MSG .NET\Bin\22_11_19\Independentsoft.Msg.dll @@ -202,7 +205,7 @@ Form - + True