219 lines
8.5 KiB
VB.net
219 lines
8.5 KiB
VB.net
Imports DD_Clipboard_Watcher.ClassProfileFilter
|
|
Imports DevExpress.XtraEditors
|
|
Imports ClassConstants
|
|
|
|
Public Class frmProfileMatch
|
|
Private PrimaryFont As New Font("Segoe UI", 12, FontStyle.Bold)
|
|
Private SecondaryFont As New Font("Segoe UI", 10)
|
|
|
|
Private OpenForms As New List(Of IResultForm)
|
|
Private ShouldHideInitially As Boolean = False
|
|
|
|
Private Sub frmProfileMatch_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not ConfigManager.Config.MatchWindowLocation.IsEmpty Then
|
|
Location = ConfigManager.Config.MatchWindowLocation
|
|
End If
|
|
|
|
If Not ConfigManager.Config.MatchWindowSize.IsEmpty Then
|
|
Size = ConfigManager.Config.MatchWindowSize
|
|
End If
|
|
|
|
If USER_LANGUAGE = "de-DE" Then
|
|
Label1.Text = $"Clipboard Watcher hat mehr als einen Match für Ihre Suche nach ""{CURRENT_CLIPBOARD_CONTENTS}"" gefunden:"
|
|
Else
|
|
Label1.Text = $"Clipboard Watcher found more than on match for your search for ""{CURRENT_CLIPBOARD_CONTENTS}"":"
|
|
End If
|
|
|
|
Dim oCreatedTiles = CreateTiles()
|
|
|
|
' Open Result Forms directly if only one match found
|
|
If oCreatedTiles = 1 Then
|
|
Dim oProfileId As Integer = CURRENT_MATCHING_PROFILES.Select(Function(p) p.Guid).First()
|
|
OpenResultForms(oProfileId)
|
|
ShouldHideInitially = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub frmProfileMatch_Shown(sender As Object, e As EventArgs) Handles Me.Shown
|
|
If ShouldHideInitially Then
|
|
Hide()
|
|
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 CURRENT_MATCHING_PROFILES
|
|
If oProfile.ProfileType = ClassConstants.PROFILE_TYPE_DATA_DOCS 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 = ClassConstants.PROFILE_TYPE_DATA_DOCS Or oProfile.ProfileType = ClassConstants.PROFILE_TYPE_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 = ClassConstants.PROFILE_TYPE_DATA_DOCS Or oProfile.ProfileType = ClassConstants.PROFILE_TYPE_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()
|
|
oNameElement.Text = Profile.Name
|
|
oNameElement.TextAlignment = TileItemContentAlignment.TopLeft
|
|
oNameElement.Appearance.Normal.Font = PrimaryFont
|
|
oItem.Elements.Add(oNameElement)
|
|
|
|
Dim oCommentElement = New TileItemElement()
|
|
oCommentElement.Text = Profile.Comment
|
|
oCommentElement.TextAlignment = TileItemContentAlignment.MiddleLeft
|
|
oCommentElement.Appearance.Normal.Font = SecondaryFont
|
|
oItem.Elements.Add(oCommentElement)
|
|
|
|
Dim oCountElement = New TileItemElement()
|
|
oCountElement.Text = GetCountText(Profile, CountText)
|
|
oCountElement.TextAlignment = TileItemContentAlignment.BottomRight
|
|
oCountElement.Appearance.Normal.Font = SecondaryFont
|
|
oItem.Elements.Add(oCountElement)
|
|
|
|
Return oItem
|
|
End Function
|
|
|
|
Private Function GetCountText(Profile As ClassProfileFilter.ProfileData, CountText As String) As String
|
|
Dim oText As String = "No implemented"
|
|
|
|
If Profile.CountData = ClassConstants.INVALID_COUNT_SQL Then
|
|
oText = "Invalid SQL!"
|
|
ElseIf Profile.CountData = ClassConstants.NO_COUNT_SQL Then
|
|
oText = "No SQL!"
|
|
Else
|
|
oText = CountText
|
|
End If
|
|
|
|
If Profile.CountDocs = ClassConstants.INVALID_COUNT_SQL Then
|
|
oText = "Invalid SQL!"
|
|
ElseIf Profile.CountDocs = ClassConstants.NO_COUNT_SQL Then
|
|
oText = "No SQL!"
|
|
Else
|
|
oText = CountText
|
|
End If
|
|
|
|
Return oText
|
|
End Function
|
|
|
|
Private Sub frmProfileMatch_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
|
|
Try
|
|
ConfigManager.Config.MatchWindowSize = Size
|
|
ConfigManager.Config.MatchWindowLocation = Location
|
|
ConfigManager.Save()
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Logger.Info("Error in Save FormLayout: " & ex.Message)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub SimpleButton1_Click(sender As Object, e As EventArgs)
|
|
Close()
|
|
End Sub
|
|
|
|
Private Sub TileControlMatch_ItemClick(sender As Object, e As TileItemEventArgs) Handles TileControlMatch.ItemClick
|
|
Dim oItem As TileItem = e.Item
|
|
Dim oProfileId As Integer = oItem.Tag
|
|
|
|
OpenResultForms(oProfileId)
|
|
|
|
Hide()
|
|
End Sub
|
|
|
|
Private Sub OpenResultForms(ProfileId As Integer)
|
|
Dim oMatchingProfiles As New List(Of ProfileData)
|
|
|
|
If ProfileId = -1 Then
|
|
' Click on Show all, add all matching profiles
|
|
oMatchingProfiles = CURRENT_MATCHING_PROFILES.
|
|
Select(Function(p) p).
|
|
ToList()
|
|
Else
|
|
' Click on specific profile
|
|
Dim oProfile As ProfileData = CURRENT_MATCHING_PROFILES.
|
|
Where(Function(p) p.Guid = ProfileId).
|
|
First()
|
|
oMatchingProfiles.Add(oProfile)
|
|
|
|
If (oProfile.ProfileType = ClassConstants.PROFILE_TYPE_DATA_DOCS Or oProfile.ProfileType = ClassConstants.PROFILE_TYPE_DOCS_ONLY) And oProfile.CountDocs > 0 Then
|
|
' Show Result Document Form
|
|
Dim oForm As New frmResultDoc(Me, oMatchingProfiles)
|
|
AddHandler oForm.FormClosed, AddressOf ProfileResultForm_Closed
|
|
OpenForms.Add(oForm)
|
|
|
|
oForm.Show()
|
|
End If
|
|
|
|
If oProfile.ProfileType = ClassConstants.PROFILE_TYPE_DATA_DOCS Or oProfile.ProfileType = ClassConstants.PROFILE_TYPE_DATA_ONLY And oProfile.CountData > 0 Then
|
|
' Show Result Data Form
|
|
Dim oForm As New frmResultSQL(Me, oMatchingProfiles)
|
|
AddHandler oForm.FormClosed, AddressOf ProfileResultForm_Closed
|
|
OpenForms.Add(oForm)
|
|
|
|
oForm.Show()
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub ProfileResultForm_Closed(sender As Object, e As FormClosedEventArgs)
|
|
Dim oShouldOpenAgain As Boolean = False
|
|
Dim oThisForm = New List(Of IResultForm) From {sender}
|
|
|
|
If TypeOf sender Is frmResultDoc Or TypeOf sender Is frmResultSQL Then
|
|
For Each oForm As IResultForm In OpenForms
|
|
' Determine if frmProfileMatch should be shown
|
|
If oForm.ShouldReturnToMatchForm Then
|
|
oShouldOpenAgain = True
|
|
End If
|
|
Next
|
|
End If
|
|
|
|
' If frmProfileMatch should be shown, close all windows of this profile
|
|
If oShouldOpenAgain Then
|
|
For Each oForm As Form In OpenForms.Except(oThisForm)
|
|
RemoveHandler oForm.FormClosed, AddressOf ProfileResultForm_Closed
|
|
oForm.Close()
|
|
Next
|
|
|
|
Show()
|
|
End If
|
|
End Sub
|
|
|
|
|
|
End Class |