425 lines
19 KiB
VB.net
425 lines
19 KiB
VB.net
Imports DigitalData.Modules.Logging
|
|
Imports DevExpress.XtraEditors
|
|
Imports DigitalData.GUIs.Common
|
|
Imports DevExpress.XtraSplashScreen
|
|
Imports DevExpress.XtraBars
|
|
|
|
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_SEARCHCommand As String
|
|
Private LastSearchForm As frmDocumentResultList
|
|
Private ASorDB As ClassDataASorDB
|
|
Private EventtoggleChange As Boolean = False
|
|
|
|
Private SEARCH_FACT_DATE As String = "MONTH(OBJ.ADDED_WHEN) <> 13"
|
|
Public Sub New(pBaseSearchSql As String)
|
|
|
|
|
|
' Dieser Aufruf ist für den Designer erforderlich.
|
|
InitializeComponent()
|
|
BASE_SEARCHCommand = pBaseSearchSql
|
|
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
|
Logger = My.LogConfig.GetLogger()
|
|
ASorDB = New ClassDataASorDB(My.LogConfig)
|
|
End Sub
|
|
|
|
Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs) Handles txtSearch.TextChanged
|
|
Try
|
|
|
|
If txtSearch.Text = String.Empty Then
|
|
Reset_Form()
|
|
Exit Sub
|
|
End If
|
|
lblFoundResult.Visible = False
|
|
Start_FlowSearch()
|
|
|
|
Catch ex As Exception
|
|
lblFoundResult.Text = "Unexpected error in FlowSearch - Check Your log"
|
|
lblFoundResult.Visible = True
|
|
Logger.Error(ex)
|
|
End Try
|
|
End Sub
|
|
Sub Reset_Form()
|
|
TileControlMatch.Groups.Clear()
|
|
lblFoundResult.Visible = False
|
|
End Sub
|
|
Sub SearchContent(oSearchValue As String)
|
|
Try
|
|
oLastAttribute = ""
|
|
Dim oSQL = BASE_SEARCHCommand.Replace("@SEARCH_STRING", oSearchValue)
|
|
|
|
|
|
If BarToggleSwitchItemDateALL.Checked = False Then
|
|
oSQL = oSQL.Replace("MONTH(OBJ.ADDED_WHEN) <> 13", SEARCH_FACT_DATE)
|
|
End If
|
|
Dim oResultCountAttributes As Integer = 0
|
|
TileControlMatch.Groups.Clear()
|
|
|
|
Dim oResultsfromSearchDT As DataTable = My.DatabaseIDB.GetDatatable(oSQL)
|
|
If Not IsNothing(oResultsfromSearchDT) Then
|
|
|
|
Dim oView As DataView = New DataView(oResultsfromSearchDT)
|
|
Dim oDTDistinctValues As DataTable = oView.ToTable(True, "ATTRIBUTE", "ATTR_ID")
|
|
Dim oGroups = oResultsfromSearchDT.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.Int32"))
|
|
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
|
|
|
|
For Each orow As DataRow In oNewTable.Rows
|
|
oAttrCount += 1
|
|
oResultCountAttributes += orow.Item(1)
|
|
Next
|
|
lblFoundResult.Text = GetResultString(oResultCountAttributes, 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 oResultsfromSearchDT.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"))
|
|
If Not IsNothing(oItem) Then
|
|
oGroup.Items.Add(oItem)
|
|
End If
|
|
|
|
End If
|
|
Next
|
|
TileControlMatch.Groups.Add(oGroup)
|
|
Next
|
|
|
|
'Wenn weniger als 45 Belege gefunden wurden wird direkt die Suche ausgeführt
|
|
If oResultCountAttributes > 0 And oResultCountAttributes <= 45 Then
|
|
StartSearch_Full(oSearchValue)
|
|
Else
|
|
If oResultsfromSearchDT.Rows.Count = 0 Then
|
|
Reset_Form()
|
|
lblFoundResult.Text = "No Results"
|
|
lblFoundResult.Visible = True
|
|
End If
|
|
End If
|
|
|
|
Else
|
|
lblFoundResult.Text = "Result from DB Is Nothing..Check SQL"
|
|
lblFoundResult.Visible = True
|
|
End If
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
End Try
|
|
|
|
|
|
End Sub
|
|
Private Function StartSearch_Full(pSearchValue As String) As Boolean
|
|
Dim oHandle As IOverlaySplashScreenHandle = Nothing
|
|
Dim oItemsFound As Boolean = False
|
|
Dim oSearchData = My.Application.Search
|
|
|
|
Try
|
|
oHandle = SplashScreenManager.ShowOverlayForm(Me)
|
|
|
|
Dim oEXECSQL = $"EXEC PRFLOW_SEARCH_GET_RESULT '{pSearchValue}','{SEARCH_FACT_DATE}', {My.Application.User.UserId},'{oSearchData.SelectInStringAttributeIds}','{oSearchData.SelectInIntegerAttributeIds}'"
|
|
Dim oDTOBJECT_RESULT As DataTable = My.DatabaseIDB.GetDatatable(oEXECSQL)
|
|
If Not IsNothing(oDTOBJECT_RESULT) Then
|
|
If oDTOBJECT_RESULT.Rows.Count = 0 Then
|
|
lblFoundResult.Text = "No Results"
|
|
lblFoundResult.Visible = True
|
|
Return False
|
|
End If
|
|
oItemsFound = True
|
|
OpenResultForm(oDTOBJECT_RESULT)
|
|
End If
|
|
|
|
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
|
|
Finally
|
|
SplashScreenManager.CloseOverlayForm(oHandle)
|
|
|
|
End Try
|
|
Return oItemsFound
|
|
End Function
|
|
Private Sub OpenResultForm(pDTRESULT As DataTable)
|
|
Try
|
|
Dim oEnvironment As New Modules.ZooFlow.Environment() With {
|
|
.User = My.Application.User,
|
|
.Modules = My.Application.Modules,
|
|
.Database = My.Database,
|
|
.DatabaseIDB = My.DatabaseIDB,
|
|
.Settings = My.Application.Settings,
|
|
.Service = My.Application.Service
|
|
}
|
|
Dim oShortGuid = Guid.NewGuid()
|
|
Dim oWindowGuid = $"FLOWSEARCH-{My.User.Name}"
|
|
Dim oParams = New DocumentResultParams() With {
|
|
.WindowGuid = oWindowGuid,
|
|
.Results = New List(Of DocumentResult) From {
|
|
New DocumentResult() With {
|
|
.Title = "FlowSearchResult",
|
|
.Datatable = pDTRESULT
|
|
}
|
|
}
|
|
}
|
|
Dim oForm As New frmDocumentResultList(My.LogConfig, oEnvironment, oParams)
|
|
oForm.Show()
|
|
|
|
LastSearchForm = oForm
|
|
|
|
' Position Result Window below this window
|
|
LastSearchForm.Location = GetResultFormLocation()
|
|
LastSearchForm.Size = GetResultFormSize()
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Function GetResultFormLocation() As Point
|
|
Return Location
|
|
End Function
|
|
|
|
Private Function GetResultFormSize() As Size
|
|
Return Size
|
|
End Function
|
|
Private Function GetResultString(CountObjects As Integer, CountAttribute As Integer, SearchContent As String) 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
|
|
Try
|
|
Dim oItem As New TileItem() With {.Tag = $"{pTermGuid}|{pAttributeID}"}
|
|
|
|
If oLastAttribute <> pAttribute Then
|
|
oAttributeCount = 1
|
|
oLastAttribute = pAttribute
|
|
oItem.ItemSize = TileItemSize.Wide
|
|
oItem.AppearanceItem.Normal.BackColor = Color.FromArgb(165, 36, 49) ' GELB 255, 214, 47)
|
|
Else
|
|
oItem.ItemSize = TileItemSize.Medium
|
|
oItem.AppearanceItem.Normal.BackColor = Color.White
|
|
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
|
|
oNameElement.Appearance.Normal.ForeColor = Color.White
|
|
Case Else
|
|
oNameElement.Appearance.Normal.Font = SecondaryFontBold
|
|
oNameElement.Appearance.Normal.ForeColor = Color.FromArgb(165, 36, 49)
|
|
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
|
|
oCountElement.Appearance.Normal.ForeColor = Color.White
|
|
Case Else
|
|
oCountElement.Appearance.Normal.Font = SecondaryFont
|
|
oCountElement.Appearance.Normal.ForeColor = Color.FromArgb(165, 36, 49)
|
|
End Select
|
|
oItem.Elements.Add(oCountElement)
|
|
|
|
Return oItem
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return Nothing
|
|
End Try
|
|
|
|
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
|
|
|
|
Private Sub TileControlMatch_ItemClick(sender As Object, e As TileItemEventArgs) Handles TileControlMatch.ItemClick
|
|
Try
|
|
Dim oItem As TileItem = e.Item
|
|
Dim oItemTag = oItem.Tag
|
|
Dim oHandle As IOverlaySplashScreenHandle = Nothing
|
|
Dim oItemsFound As Boolean = False
|
|
Dim oSearchData = My.Application.Search
|
|
Dim oSplit = oItem.Tag.ToString.Split("|")
|
|
Try
|
|
oHandle = SplashScreenManager.ShowOverlayForm(Me)
|
|
Dim oDT As DataTable = ASorDB.GetDatatable("IDB", $"SELECT * FROM VWIDB_BE_ATTRIBUTE WHERE ATTR_ID = {oSplit(1)}", "VWIDB_BE_ATTRIBUTE", $"ATTR_ID = {oSplit(1)}")
|
|
Dim oType = oDT.Rows(0).Item("TYPE_NAME")
|
|
Dim oEXECSQL = $"EXEC PRFLOW_SEARCH_GET_RESULT_PER_TILE {oSplit(0)},{My.Application.User.UserId},'{oType}',{oSplit(1)},'{My.Application.User.Language}'"
|
|
Dim oDTOBJECT_RESULT As DataTable = My.DatabaseIDB.GetDatatable(oEXECSQL)
|
|
If Not IsNothing(oDTOBJECT_RESULT) Then
|
|
oItemsFound = True
|
|
OpenResultForm(oDTOBJECT_RESULT)
|
|
End If
|
|
|
|
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
|
|
Finally
|
|
SplashScreenManager.CloseOverlayForm(oHandle)
|
|
|
|
End Try
|
|
Catch ex As Exception
|
|
MsgBox($"Error while loading Searches: " & vbNewLine & ex.Message, MsgBoxStyle.Critical, Text)
|
|
Logger.Error(ex)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub BarToggleSwitchItem_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarToggleSwitchItemCURRENTYEAR.CheckedChanged, BarToggleSwitchItemLASTYEAR.CheckedChanged, BarToggleSwitchItemCURRENTMONTH.CheckedChanged,
|
|
BarToggleSwitchItemLASTMONTH.CheckedChanged, BarToggleSwitchItemTODAY.CheckedChanged, BarToggleSwitchItemYESTERDAY.CheckedChanged
|
|
Dim btsi As BarToggleSwitchItem = TryCast(sender, BarToggleSwitchItem)
|
|
If btsi.Checked = True Then
|
|
BarToggleSwitchItemDateALL.Checked = False
|
|
Dim oWHENDATE As String
|
|
Select Case btsi.Name
|
|
Case "BarToggleSwitchItemCURRENTYEAR"
|
|
oWHENDATE = "YEAR(OBJ.ADDED_WHEN) = YEAR(GETDATE())"
|
|
Case "BarToggleSwitchItemLASTYEAR"
|
|
oWHENDATE = "YEAR(OBJ.ADDED_WHEN) = (YEAR(GETDATE()) -1)"
|
|
Case "BarToggleSwitchItemCURRENTMONTH"
|
|
Case "BarToggleSwitchItemLASTMONTH"
|
|
Dim currentDate As DateTime = DateTime.Now
|
|
If currentDate.Month = 1 Then
|
|
oWHENDATE = "MONTH(OBJ.ADDED_WHEN) = 12 " & vbNewLine & "AND YEAR(OBJ.ADDED_WHEN) = (YEAR(GETDATE()) -1)"
|
|
Else
|
|
oWHENDATE = "MONTH(OBJ.ADDED_WHEN) = MONTH(GETDATE())"
|
|
End If
|
|
|
|
Case "BarToggleSwitchItemTODAY"
|
|
oWHENDATE = "convert(DATE,OBJ.ADDED_WHEN) = convert(DATE,GETDATE())"
|
|
Case "BarToggleSwitchItemYESTERDAY"
|
|
oWHENDATE = "convert(DATE,OBJ.ADDED_WHEN) = convert(DATE,GETDATE()-1)"
|
|
End Select
|
|
SEARCH_FACT_DATE = oWHENDATE
|
|
Select Case btsi.Name
|
|
Case "BarToggleSwitchItemCURRENTYEAR"
|
|
BarToggleSwitchItemLASTYEAR.Checked = False
|
|
BarToggleSwitchItemCURRENTMONTH.Checked = False
|
|
BarToggleSwitchItemLASTMONTH.Checked = False
|
|
BarToggleSwitchItemTODAY.Checked = False
|
|
BarToggleSwitchItemYESTERDAY.Checked = False
|
|
Case "BarToggleSwitchItemLASTYEAR"
|
|
BarToggleSwitchItemCURRENTYEAR.Checked = False
|
|
BarToggleSwitchItemCURRENTMONTH.Checked = False
|
|
BarToggleSwitchItemLASTMONTH.Checked = False
|
|
BarToggleSwitchItemTODAY.Checked = False
|
|
BarToggleSwitchItemYESTERDAY.Checked = False
|
|
Case "BarToggleSwitchItemCURRENTMONTH"
|
|
BarToggleSwitchItemCURRENTYEAR.Checked = False
|
|
BarToggleSwitchItemLASTYEAR.Checked = False
|
|
BarToggleSwitchItemLASTMONTH.Checked = False
|
|
BarToggleSwitchItemTODAY.Checked = False
|
|
BarToggleSwitchItemYESTERDAY.Checked = False
|
|
Case "BarToggleSwitchItemLASTMONTH"
|
|
BarToggleSwitchItemCURRENTYEAR.Checked = False
|
|
BarToggleSwitchItemLASTYEAR.Checked = False
|
|
BarToggleSwitchItemCURRENTMONTH.Checked = False
|
|
BarToggleSwitchItemTODAY.Checked = False
|
|
BarToggleSwitchItemYESTERDAY.Checked = False
|
|
Case "BarToggleSwitchItemTODAY"
|
|
BarToggleSwitchItemCURRENTYEAR.Checked = False
|
|
BarToggleSwitchItemLASTYEAR.Checked = False
|
|
BarToggleSwitchItemCURRENTMONTH.Checked = False
|
|
BarToggleSwitchItemYESTERDAY.Checked = False
|
|
Case "BarToggleSwitchItemYESTERDAY"
|
|
BarToggleSwitchItemCURRENTYEAR.Checked = False
|
|
BarToggleSwitchItemLASTYEAR.Checked = False
|
|
BarToggleSwitchItemCURRENTMONTH.Checked = False
|
|
BarToggleSwitchItemTODAY.Checked = False
|
|
End Select
|
|
Start_FlowSearch()
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub BarToggleSwitchItemDateALL_CheckedChanged(sender As Object, e As ItemClickEventArgs) Handles BarToggleSwitchItemDateALL.CheckedChanged
|
|
Dim btn As BarToggleSwitchItem = TryCast(sender, BarToggleSwitchItem)
|
|
If btn.Checked = True Then
|
|
BarToggleSwitchItemCURRENTYEAR.Checked = False
|
|
BarToggleSwitchItemLASTYEAR.Checked = False
|
|
BarToggleSwitchItemCURRENTMONTH.Checked = False
|
|
BarToggleSwitchItemLASTMONTH.Checked = False
|
|
BarToggleSwitchItemCURRENTMONTH.Checked = False
|
|
BarToggleSwitchItemTODAY.Checked = False
|
|
SEARCH_FACT_DATE = "MONTH(OBJ.ADDED_WHEN) <> 13"
|
|
End If
|
|
Start_FlowSearch()
|
|
|
|
End Sub
|
|
Sub Start_FlowSearch(Optional AllOver As Boolean = False)
|
|
If txtSearch.Text <> String.Empty Or AllOver = True Then
|
|
SearchContent(Trim(txtSearch.Text))
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub btnFindAll_Click(sender As Object, e As EventArgs)
|
|
|
|
End Sub
|
|
|
|
Private Sub CheckButton1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckButton1.CheckedChanged
|
|
If BarToggleSwitchItemDateALL.Checked = True Then
|
|
Dim result As MsgBoxResult
|
|
If My.Application.User.Language = "de-DE" Then
|
|
result = MessageBox.Show("Wollen Sie wirklich eine Suche über alle Objekte starten?", "Bestätigung erforderlich:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
|
|
Else
|
|
result = MessageBox.Show("Do You really want to start a search without limitation?", "Confirmation needed:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
|
|
End If
|
|
If result = MsgBoxResult.No Then
|
|
Exit Sub
|
|
End If
|
|
End If
|
|
StartSearch_Full("")
|
|
CheckButton1.Checked = True
|
|
End Sub
|
|
|
|
Private Sub btnFindAll_Click_1(sender As Object, e As EventArgs)
|
|
|
|
End Sub
|
|
End Class |