2019-09-12 17:06:14 +02:00

156 lines
5.3 KiB
VB.net

Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Windows
Imports DigitalData.Modules.ZooFlow
Imports DigitalData.Modules.ZooFlow.Params
''' <summary>
'''
''' Selfcontained:
''' - Config (Location of Window)
'''
''' Environment:
''' - Pattern Replacement Values
''' - User Info (isAdmin, etc)
''' - License Info?
''' - ConnectionString
'''
''' Parameters:
''' - Matching Profiles as List Of ProfileData
''' - Clipboard Content as String
''' </summary>
Public Class frmMatch
Private _LogConfig As LogConfig
Private _Logger As Logger
Private _Environment As Environment
Private _Params As ClipboardWatcherParams
Private PrimaryFont As New Font("Segoe UI", 12, FontStyle.Bold)
Private SecondaryFont As New Font("Segoe UI", 10)
Private Const NO_COUNT_SQL As Integer = 99998
Private Const INVALID_COUNT_SQL As Integer = 99999
Private Enum ProfileType
ANY = 0
DOCS_ONLY = 1
DATA_ONLY = 2
End Enum
Public Sub New(LogConfig As LogConfig, Environment As Environment, Params As ClipboardWatcherParams)
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
_Environment = Environment
_Params = Params
End Sub
Private Sub frmMatch_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim oCreatedTiles = CreateTiles()
If oCreatedTiles = -1 Then
Exit Sub
End If
End Sub
Function CreateTiles() As Integer
Try
Dim oCreatedTiles As Integer = 0
Dim oDocumentGroup = TileControlMatch.Groups.Item("TileGroupDocuments")
Dim oDataGroup = TileControlMatch.Groups.Item("TileGroupData")
Dim oDataDocumentsGroup = TileControlMatch.Groups.Item("TileGroupDocumentsData")
oDocumentGroup.Items.Clear()
oDataGroup.Items.Clear()
For Each oProfile As ProfileData In _Params.MatchingProfiles
If oProfile.ProfileType = ProfileType.ANY Then
If oProfile.CountData > 0 And oProfile.CountDocs > 0 Then
Dim oCountText = oProfile.CountData + oProfile.CountDocs
Dim oItem = CreateTile(oProfile, $"{oCountText} Ergebnisse")
oDataDocumentsGroup.Items.Add(oItem)
oCreatedTiles += 1
End If
End If
If oProfile.ProfileType = ProfileType.ANY Or oProfile.ProfileType = ProfileType.DOCS_ONLY Then
If oProfile.CountDocs > 0 Then
Dim oItem = CreateTile(oProfile, $"{oProfile.CountDocs} Dokumente")
oDocumentGroup.Items.Add(oItem)
oCreatedTiles += 1
End If
End If
If oProfile.ProfileType = ProfileType.ANY Or oProfile.ProfileType = ProfileType.DATA_ONLY Then
If oProfile.CountData > 0 Then
Dim oItem = CreateTile(oProfile, $"{oProfile.CountData} Datensätze")
oDataGroup.Items.Add(oItem)
oCreatedTiles += 1
End If
End If
Next
Return oCreatedTiles
Catch ex As Exception
_Logger.Error(ex)
MsgBox("Error while creating profile tiles!" & vbNewLine & ex.Message)
Return -1
End Try
End Function
Private Function CreateTile(Profile As ProfileData, CountText As String) As TileItem
Dim oItem As New TileItem() With {.Tag = Profile.Guid}
oItem.Elements.Clear()
Dim oNameElement = New TileItemElement With {
.Text = Profile.Name,
.TextAlignment = TileItemContentAlignment.TopLeft
}
oNameElement.Appearance.Normal.Font = PrimaryFont
oItem.Elements.Add(oNameElement)
Dim oCommentElement = New TileItemElement With {
.Text = Profile.Comment,
.TextAlignment = TileItemContentAlignment.MiddleLeft
}
oCommentElement.Appearance.Normal.Font = SecondaryFont
oItem.Elements.Add(oCommentElement)
Dim oCountElement = New TileItemElement With {
.Text = GetCountText(Profile, CountText),
.TextAlignment = TileItemContentAlignment.BottomRight
}
oCountElement.Appearance.Normal.Font = SecondaryFont
oItem.Elements.Add(oCountElement)
Return oItem
End Function
Private Function GetCountText(Profile As ProfileData, CountText As String) As String
Dim oText As String = "No implemented"
If Profile.CountData = INVALID_COUNT_SQL Then
oText = "Invalid SQL!"
ElseIf Profile.CountData = NO_COUNT_SQL Then
oText = "No SQL!"
Else
oText = CountText
End If
If Profile.CountDocs = INVALID_COUNT_SQL Then
oText = "Invalid SQL!"
ElseIf Profile.CountDocs = NO_COUNT_SQL Then
oText = "No SQL!"
Else
oText = CountText
End If
Return oText
End Function
End Class