Zooflow: Search Improvements, Multiple Tokens
This commit is contained in:
@@ -8,34 +8,30 @@ Imports DevExpress.XtraSplashScreen
|
||||
Imports DigitalData.GUIs.ZooFlow.ClassConstants
|
||||
Imports DigitalData.GUIs.ZooFlow.Search
|
||||
Imports DigitalData.GUIs.ZooFlow.Search.SearchToken
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class frmFlowSearch2
|
||||
Private ReadOnly LogConfig As LogConfig = My.LogConfig
|
||||
Private ReadOnly Logger = My.LogConfig.GetLogger()
|
||||
Private SearchRunner As SearchRunner
|
||||
Private Search As Search.Search
|
||||
|
||||
Private TokenListDefault As New Dictionary(Of String, Object)
|
||||
Private TokenListOperands As New Dictionary(Of String, Object)
|
||||
Private TokenListAttrValues As New Dictionary(Of String, Object)
|
||||
|
||||
Private Sub frmFlowSearch2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
Search = New Search.Search(LogConfig, My.Application.User, My.Database)
|
||||
SearchRunner = New SearchRunner(My.LogConfig, My.Application.GetEnvironment, "FlowSearch") With {
|
||||
.BaseSearchSQL = LoadBaseSQL()
|
||||
}
|
||||
|
||||
TextEdit1.MaskBox.AutoCompleteSource = AutoCompleteSource.CustomSource
|
||||
TextEdit1.MaskBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend
|
||||
TextEdit1.MaskBox.AutoCompleteCustomSource = LoadAutoSuggest()
|
||||
|
||||
RadioGroup1.Properties.Items.AddRange(LoadDateConstraints.ToArray)
|
||||
|
||||
GridControl1.DataSource = LoadPredefinedSearches()
|
||||
|
||||
Dim oTokens = Search.GetValueTokensForAttribute()
|
||||
AddTokens(TokenEdit1, oTokens)
|
||||
Dim oTokens = GetValueTokensForAttribute()
|
||||
AddTokens(TokenEditEx1, oTokens)
|
||||
End Sub
|
||||
|
||||
Private Function LoadBaseSQL() As String
|
||||
@@ -52,21 +48,26 @@ Public Class frmFlowSearch2
|
||||
Return oSQL
|
||||
End Function
|
||||
|
||||
Private Function LoadAutoSuggest() As AutoCompleteStringCollection
|
||||
Dim oCollection As New AutoCompleteStringCollection
|
||||
Dim oSql = $"EXEC PRIDB_SEARCH_AUTOSUGGEST '{My.Application.User.Language}',{My.Application.User.UserId}"
|
||||
Dim oTable As DataTable = My.Database.GetDatatableIDB(oSql)
|
||||
|
||||
If oTable Is Nothing Then
|
||||
|
||||
Return New AutoCompleteStringCollection()
|
||||
End If
|
||||
Public Function GetValueTokensForAttribute() As List(Of AttributeValueToken)
|
||||
Dim oSQL = $"EXEC PRIDB_SEARCH_AUTOSUGGEST '{My.Application.User.Language}', {My.Application.User.UserId}"
|
||||
Dim oTable = My.Database.GetDatatableIDB(oSQL)
|
||||
Dim oTokens As New List(Of AttributeValueToken)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
oCollection.Add(oRow.Item("TERM"))
|
||||
Dim oTermValue = oRow.Item("TERM")
|
||||
Dim oTermId = oRow.ItemEx("TERM_ID", 0)
|
||||
Dim oAttributeTitle = oRow.Item("ATTR_TITLE")
|
||||
Dim oAttributeId = oRow.ItemEx("ATTR_ID", 0)
|
||||
|
||||
oTokens.Add(New AttributeValueToken() With {
|
||||
.AttributeId = oAttributeId,
|
||||
.AttributeTitle = oAttributeTitle,
|
||||
.TermId = oTermId,
|
||||
.TermValue = oTermValue
|
||||
})
|
||||
Next
|
||||
|
||||
Return oCollection
|
||||
Return oTokens.Distinct().ToList()
|
||||
End Function
|
||||
|
||||
Private Function LoadDateConstraints() As List(Of RadioGroupItem)
|
||||
@@ -117,36 +118,39 @@ Public Class frmFlowSearch2
|
||||
}
|
||||
End Function
|
||||
|
||||
Private Function GetTokens() As IEnumerable(Of AttributeValueToken)
|
||||
Dim oTokens = TokenEditEx1.GetTokenList()
|
||||
Return oTokens.Select(Of AttributeValueToken)(Function(token) token.Value)
|
||||
End Function
|
||||
|
||||
Private Async Sub TextEdit1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextEdit1.KeyUp
|
||||
If e.KeyCode = Keys.Enter Then
|
||||
Await RunSearch(TextEdit1.EditValue)
|
||||
Dim oTokens = GetTokens()
|
||||
Await RunSearch(oTokens)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Async Sub SearchControl2_KeyUp(sender As Object, e As KeyEventArgs) Handles TokenEdit1.KeyUp
|
||||
If e.KeyCode = Keys.Enter And TokenEdit1.IsPopupOpen = False Then
|
||||
Dim oTokens = TokenEdit1.GetTokenList()
|
||||
Dim oFirstToken = oTokens.FirstOrDefault()
|
||||
|
||||
If oFirstToken Is Nothing Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oTokenValue As TokenValue = oFirstToken.Value
|
||||
|
||||
Await RunSearch(oTokenValue.Value)
|
||||
Private Async Sub SearchControl2_KeyUp(sender As Object, e As KeyEventArgs) Handles TokenEditEx1.KeyUp
|
||||
If e.KeyCode = Keys.Enter And TokenEditEx1.IsPopupOpen = False Then
|
||||
Dim oTokens = GetTokens()
|
||||
Await RunSearch(oTokens)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Async Sub TextEdit1_ButtonClick(sender As Object, e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles TextEdit1.ButtonClick
|
||||
If e.Button.Tag = "SEARCH" Then
|
||||
Await RunSearch(TextEdit1.EditValue)
|
||||
Dim oTokens = GetTokens()
|
||||
Await RunSearch(oTokens)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Async Function RunSearch(pSearchTerm As String) As Threading.Tasks.Task
|
||||
Private Async Function RunSearch(pTokens As IEnumerable(Of AttributeValueToken)) As Threading.Tasks.Task
|
||||
Dim oHandle = StartUpdateUI()
|
||||
|
||||
If pTokens.Count = 0 Then
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oDateFrom = DateEditFrom.EditValue
|
||||
Dim oDateTo = DateEditTo.EditValue
|
||||
@@ -156,7 +160,7 @@ Public Class frmFlowSearch2
|
||||
End If
|
||||
|
||||
SearchRunner.SetDateConstraint()
|
||||
Dim oResult = Await SearchRunner.RunWithSearchTerm(pSearchTerm, oDateFrom, oDateTo)
|
||||
Dim oResult = Await SearchRunner.RunWithSearchTerm(String.Empty, oDateFrom, oDateTo, pTokens, "")
|
||||
|
||||
If oResult.OK = False Then
|
||||
SetStatusBarColor(Color.OrangeRed)
|
||||
@@ -280,70 +284,17 @@ Public Class frmFlowSearch2
|
||||
AddTokens(Editor, Tokens)
|
||||
End Sub
|
||||
|
||||
Private Sub AddTokens(Editor As TokenEdit, Tokens As Dictionary(Of String, Object))
|
||||
Private Sub AddTokens(Editor As TokenEdit, Tokens As IEnumerable(Of AttributeValueToken))
|
||||
For Each oToken In Tokens
|
||||
Dim oTokenEditToken = New TokenEditToken With {
|
||||
.Description = oToken.Key,
|
||||
.Value = oToken.Value
|
||||
.Description = oToken.ToString,
|
||||
.Value = oToken
|
||||
}
|
||||
Editor.Properties.Tokens.Add(oTokenEditToken)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
'Private Sub SearchControl2_Properties_TokenAdded(sender As Object, e As DevExpress.XtraEditors.TokenEditTokenAddedEventArgs) Handles TokenEdit1.Properties.TokenAdded
|
||||
' Dim oEditor As TokenEdit = sender
|
||||
' SetNewTokens(oEditor)
|
||||
'End Sub
|
||||
|
||||
'Private Sub SearchControl2_Properties_TokenRemoved(sender As Object, e As TokenEditTokenRemovedEventArgs) Handles TokenEdit1.Properties.TokenRemoved
|
||||
' Dim oEditor As TokenEdit = sender
|
||||
' SetNewTokens(oEditor)
|
||||
'End Sub
|
||||
|
||||
Private Sub SetNewTokens(pEditor As TokenEdit)
|
||||
Dim oLastToken = pEditor.GetTokenList().LastOrDefault()
|
||||
pEditor.Properties.BeginUpdate()
|
||||
|
||||
If pEditor.GetTokenList().Count > 0 Then
|
||||
SetTokens(pEditor, TokenListDefault)
|
||||
Search.InputMode = InputMode.Default
|
||||
Else
|
||||
SetTokens(pEditor, New Dictionary(Of String, Object))
|
||||
Search.InputMode = InputMode.Default
|
||||
End If
|
||||
|
||||
'If oLastToken IsNot Nothing Then
|
||||
' Select Case oLastToken.Value.GetType
|
||||
|
||||
' Case GetType(AttributeKeyToken)
|
||||
' ' After the attribute key comes an operator
|
||||
' SetTokens(pEditor, Search.GetOperatorTokens(GetType(String)))
|
||||
' Search.InputMode = InputMode.Operator
|
||||
|
||||
' Case GetType(AttributeOperatorToken)
|
||||
' ' After the attribute operator comes a value
|
||||
' SetTokens(pEditor, TokenListAttrValues)
|
||||
' Search.InputMode = InputMode.Value
|
||||
|
||||
' Case GetType(AttributeValueToken)
|
||||
' ' After the attribute value comes another value
|
||||
' SetTokens(pEditor, TokenListAttrValues)
|
||||
' Search.InputMode = InputMode.Value
|
||||
|
||||
' Case Else
|
||||
' SetTokens(pEditor, TokenListDefault)
|
||||
' Search.InputMode = InputMode.Default
|
||||
|
||||
' End Select
|
||||
'Else
|
||||
' SetTokens(pEditor, TokenListDefault)
|
||||
' Search.InputMode = InputMode.Default
|
||||
'End If
|
||||
|
||||
pEditor.Properties.EndUpdate()
|
||||
End Sub
|
||||
|
||||
Private Sub SearchControl2_CustomDrawTokenGlyph(sender As Object, e As TokenEditCustomDrawTokenGlyphEventArgs) Handles TokenEdit1.CustomDrawTokenGlyph
|
||||
Private Sub SearchControl2_CustomDrawTokenGlyph(sender As Object, e As TokenEditCustomDrawTokenGlyphEventArgs) Handles TokenEditEx1.CustomDrawTokenGlyph
|
||||
' Set Background according to token type
|
||||
Select Case e.Value.GetType()
|
||||
Case GetType(AttributeValueToken)
|
||||
@@ -355,6 +306,4 @@ Public Class frmFlowSearch2
|
||||
' This fixes: https://supportcenter.devexpress.com/ticket/details/t215578/tokenedit-glyph-is-not-visible-when-customdrawtokentext-is-used
|
||||
e.DefaultDraw()
|
||||
End Sub
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user