Imports DigitalData.Modules.Logging Imports DevExpress.XtraEditors Public Class frmFlowSearch Private Logger As Logger Private FontLargeBold As New Font("Segoe UI", 10, FontStyle.Bold) Private FontLargeNormal As New Font("Segoe UI", 10) Private SecondaryFontBold As New Font("Segoe UI", 8, FontStyle.Bold) Private SecondaryFont As New Font("Segoe UI", 8) Dim oLastAttribute As String = "" Dim oAttributeCount As Integer = 1 Dim BASE_SSEARCHCommand As String Public Sub New(pBaseSearchSql As String) ' Dieser Aufruf ist für den Designer erforderlich. InitializeComponent() BASE_SSEARCHCommand = pBaseSearchSql ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. Logger = My.LogConfig.GetLogger() End Sub Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs) Handles txtSearch.TextChanged Try If txtSearch.Text = String.Empty Then Exit Sub End If lblFoundResult.Visible = False SearchContent(Trim(txtSearch.Text)) Catch ex As Exception lblFoundResult.Text = "Unexpected error in FlowSearch - Check Your log" lblFoundResult.Visible = True Logger.Error(ex) End Try End Sub Sub SearchContent(oSearchValue As String) oLastAttribute = "" Dim oSQL = BASE_SSEARCHCommand.Replace("@SEARCH_STRING", oSearchValue) TileControlMatch.Groups.Clear() Dim ODT As DataTable = My.DatabaseIDB.GetDatatable(oSQL) If Not IsNothing(ODT) Then Dim oView As DataView = New DataView(ODT) Dim oDTDistinctValues As DataTable = oView.ToTable(True, "ATTRIBUTE", "ATTR_ID") Dim oGroups = ODT.AsEnumerable().GroupBy(Function(row) row.Field(Of String)("ATTRIBUTE")) Dim oNewTable As New DataTable oNewTable.Columns.Add("ATTRIBUTE") oNewTable.Columns.Add("COUNT", Type.GetType("System.Int16")) For Each oGroup In oGroups oNewTable.Rows.Add(oGroup.Key, oGroup.Sum(Function(row) row.Field(Of Int32)("COUNT_OBJ"))) Next If Not IsNothing(oNewTable) Then Dim oAttrCount As Integer = 0 Dim oResultCount As Integer = 0 For Each orow As DataRow In oNewTable.Rows oAttrCount += 1 oResultCount += orow.Item(1) Next lblFoundResult.Text = GetResultString(oResultCount, oAttrCount, oSearchValue) lblFoundResult.Visible = True End If oNewTable.DefaultView.Sort = "COUNT ASC" oNewTable = oNewTable.DefaultView.ToTable For Each oGroupRow As DataRow In oNewTable.Rows Dim oGroup As New TileGroup oGroup.Text = $"{oGroupRow.Item(0).ToString} [{oGroupRow.Item(1).ToString}]" oGroup.Visible = True For Each oitemRow As DataRow In ODT.Rows If oitemRow.Item("ATTRIBUTE") = oGroupRow.Item(0) Then Dim oItem = CreateTile(oitemRow.Item("TERM_VALUE"), oitemRow.Item("COUNT_OBJ"), oGroupRow.Item(0).ToString, oitemRow.Item("ATTR_ID"), oitemRow.Item("TERM_GUID")) oGroup.Items.Add(oItem) End If Next TileControlMatch.Groups.Add(oGroup) Next Dim oTESTTABLE As DataTable = My.DatabaseIDB.GetDatatable("EXEC PRSEARCH_RUN1 '3',1,1") Else lblFoundResult.Text = "Result from DB Is Nothing..Check SQL" lblFoundResult.Visible = True End If End Sub Private Function GetResultString(CountObjects, CountAttribute, SearchContent) As String Dim oResultString = $"wurden {CountObjects} Objekte" ' IIf(CountAttribute = 1, $"wurden {CountObjects} Objekte", $"wurden {CountObjects} Objekte in {CountAttribute} Attributen") Dim oProfileString = IIf(CountAttribute = 1, "einem Attribut", $"{CountAttribute} Attributen") Dim oBase = "Es {0} in {1} für Ihre Suche nach '{2}' gefunden:" Return String.Format(oBase, oResultString, oProfileString, SearchContent) End Function Private Function CreateTile(pTermValue As String, pCount_Obj As String, pAttribute As String, pAttributeID As String, pTermGuid As Long) As TileItem Dim oItem As New TileItem() With {.Tag = $"{pTermGuid}#{pAttributeID}"} oItem.AppearanceItem.Normal.BackColor = Color.FromArgb(255, 214, 47) If oLastAttribute <> pAttribute Then oAttributeCount = 1 oLastAttribute = pAttribute oItem.ItemSize = TileItemSize.Wide ElseIf oAttributeCount = 2 Then oItem.ItemSize = TileItemSize.Medium End If oAttributeCount += 1 oItem.Elements.Clear() Dim oNameElement = New TileItemElement With { .Text = pTermValue, .TextAlignment = TileItemContentAlignment.TopLeft } Select Case oItem.ItemSize Case TileItemSize.Wide oNameElement.Appearance.Normal.Font = FontLargeBold Case Else oNameElement.Appearance.Normal.Font = SecondaryFontBold End Select oNameElement.Appearance.Normal.ForeColor = Color.Black oItem.Elements.Add(oNameElement) 'Dim oCommentElement = New TileItemElement With { ' .Text = "Anzahl Objekte: " & pCount_Obj, ' .TextAlignment = TileItemContentAlignment.MiddleLeft '} 'Select Case oItem.ItemSize ' Case TileItemSize.Wide ' oCommentElement.Appearance.Normal.Font = FontLargeNormal ' Case Else ' oCommentElement.Appearance.Normal.Font = SecondaryFont 'End Select 'oCommentElement.Appearance.Normal.ForeColor = Color.Black 'oItem.Elements.Add(oCommentElement) Dim oCountElement = New TileItemElement With { .Text = "Anzahl Objekte: " & pCount_Obj, .TextAlignment = TileItemContentAlignment.BottomRight } Select Case oItem.ItemSize Case TileItemSize.Wide oCountElement.Appearance.Normal.Font = FontLargeNormal Case Else oCountElement.Appearance.Normal.Font = SecondaryFont End Select oCountElement.Appearance.Normal.ForeColor = Color.Black oItem.Elements.Add(oCountElement) Return oItem End Function Private Sub txtSearch_Enter(sender As Object, e As EventArgs) Handles txtSearch.GotFocus Label1.Visible = True End Sub Private Sub frmFlowSearch_Load(sender As Object, e As EventArgs) Handles Me.Load TileControlMatch.Groups.Clear() End Sub End Class