Zooflow: Search Improvements, Multiple Tokens
This commit is contained in:
@@ -1,116 +0,0 @@
|
||||
Imports System.ComponentModel
|
||||
Imports DevExpress.XtraEditors
|
||||
Imports DigitalData.GUIs.ZooFlow.Search.SearchToken
|
||||
Imports DigitalData.Modules.EDMI.API
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.ZooFlow.State
|
||||
|
||||
Namespace Search
|
||||
Public Class Search
|
||||
Private ReadOnly _SearchQuery As New BindingList(Of SearchCriteria)
|
||||
Private ReadOnly _LogConfig As LogConfig
|
||||
Private ReadOnly _Database As DatabaseWithFallback
|
||||
Private ReadOnly _UserState As UserState
|
||||
|
||||
Private ReadOnly _OpEquals As New KeyValuePair(Of String, Object)("gleich", New AttributeOperatorToken(OperatorToken.Equals))
|
||||
Private ReadOnly _OpNotEquals As New KeyValuePair(Of String, Object)("nicht gleich", New AttributeOperatorToken(OperatorToken.NotEquals))
|
||||
Private ReadOnly _OpGreaterThan As New KeyValuePair(Of String, Object)("größer als", New AttributeOperatorToken(OperatorToken.GreaterThan))
|
||||
Private ReadOnly _OpLessThan As New KeyValuePair(Of String, Object)("kleiner als", New AttributeOperatorToken(OperatorToken.LessThan))
|
||||
Private ReadOnly _OpContains As New KeyValuePair(Of String, Object)("enthält", New AttributeOperatorToken(OperatorToken.Contains))
|
||||
|
||||
Public ReadOnly Property Query As BindingList(Of SearchCriteria)
|
||||
|
||||
|
||||
|
||||
Private ReadOnly TokenListAttributes As New Dictionary(Of String, Object)
|
||||
'Private ReadOnly TokenListAttributes As New Dictionary(Of String, Object) From {
|
||||
' {"Rechnungsnummer", New AttributeKeyToken("InvoiceNo")},
|
||||
' {"Rechnungsdatum", New AttributeKeyToken("InvoiceDate")},
|
||||
' {"Kundennummer", New AttributeKeyToken("CustNo")}
|
||||
'}
|
||||
Private ReadOnly TokenListOperands As New Dictionary(Of String, Object) From {
|
||||
{"gleich", New AttributeOperatorToken(OperatorToken.Equals)},
|
||||
{"nicht gleich", New AttributeOperatorToken(OperatorToken.NotEquals)},
|
||||
{"größer als", New AttributeOperatorToken(OperatorToken.Equals)},
|
||||
{"kleiner als", New AttributeOperatorToken(OperatorToken.Equals)},
|
||||
{"enthält", New AttributeOperatorToken(OperatorToken.Equals)}
|
||||
}
|
||||
Private ReadOnly TokenListAttrValues As New Dictionary(Of String, Object)
|
||||
'Private ReadOnly TokenListAttrValues As New Dictionary(Of String, Object) From {
|
||||
' {"1233", New AttributeValueToken(1233)},
|
||||
' {"1234", New AttributeValueToken(1234)},
|
||||
' {"1235", New AttributeValueToken(1235)},
|
||||
' {"4711", New AttributeValueToken(4711)},
|
||||
' {"4712", New AttributeValueToken(4712)}
|
||||
'}
|
||||
Private ReadOnly TokenListDate As New Dictionary(Of String, Object) From {
|
||||
{"heute", New DateToken(Date.Now)},
|
||||
{"gestern", New DateToken(Date.Now.AddDays(-1))},
|
||||
{"letzte Woche", New DateToken(TimeSpan.FromDays(-7))},
|
||||
{"letzter Monat", New DateToken(TimeSpan.FromDays(-30))}
|
||||
}
|
||||
|
||||
Public InputMode As InputMode = InputMode.Default
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pUserState As UserState, pDatabase As DatabaseWithFallback)
|
||||
_LogConfig = pLogConfig
|
||||
_Database = pDatabase
|
||||
_UserState = pUserState
|
||||
End Sub
|
||||
|
||||
Public Function GetAttributeTokens() As Dictionary(Of String, Object)
|
||||
Dim oSQL = $"SELECT * FROM VWIDB_BE_ATTRIBUTE WHERE DEFAULT_SEARCH_ATTRIBUTE = 1 AND LANG_CODE = '{_UserState.Language}'"
|
||||
Dim oTable = _Database.GetDatatable("VWIDB_BE_ATTRIBUTE", oSQL, Constants.DatabaseType.IDB, $"DEFAULT_SEARCH_ATTRIBUTE = 1 AND LANG_CODE = '{_UserState.Language}'")
|
||||
Dim oTokens As New Dictionary(Of String, Object)
|
||||
|
||||
For Each oRow As DataRow In oTable.rows
|
||||
oTokens.Add(oRow.Item("ATTR_TITLE"), New AttributeKeyToken(oRow.Item("ATTR_ID")))
|
||||
Next
|
||||
|
||||
Return oTokens
|
||||
End Function
|
||||
|
||||
Public Function GetValueTokensForAttribute() As Dictionary(Of String, Object)
|
||||
Dim oSQL = $"EXEC PRIDB_SEARCH_AUTOSUGGEST '{_UserState.Language}', {_UserState.UserId}"
|
||||
Dim oTable = _Database.GetDatatableIDB(oSQL)
|
||||
Dim oTokens As New Dictionary(Of String, Object)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oTerm = oRow.Item("TERM")
|
||||
If oTokens.ContainsKey(oTerm) = False Then
|
||||
oTokens.Add(oTerm, New AttributeValueToken(oTerm))
|
||||
End If
|
||||
Next
|
||||
|
||||
Return oTokens
|
||||
End Function
|
||||
|
||||
Public Function GetOperatorTokens(pDataType As Type) As Dictionary(Of String, Object)
|
||||
Dim oResult = New Dictionary(Of String, Object)
|
||||
|
||||
Select Case pDataType.GetType
|
||||
Case GetType(Date)
|
||||
oResult.Add(_OpEquals.Key, _OpEquals.Value)
|
||||
|
||||
Case GetType(Integer)
|
||||
oResult.Add(_OpEquals.Key, _OpEquals.Value)
|
||||
oResult.Add(_OpNotEquals.Key, _OpNotEquals.Value)
|
||||
oResult.Add(_OpGreaterThan.Key, _OpGreaterThan.Value)
|
||||
oResult.Add(_OpLessThan.Key, _OpLessThan.Value)
|
||||
|
||||
Case GetType(Boolean)
|
||||
oResult.Add(_OpEquals.Key, _OpEquals.Value)
|
||||
oResult.Add(_OpNotEquals.Key, _OpNotEquals.Value)
|
||||
|
||||
Case Else
|
||||
oResult.Add(_OpEquals.Key, _OpEquals.Value)
|
||||
oResult.Add(_OpNotEquals.Key, _OpNotEquals.Value)
|
||||
oResult.Add(_OpContains.Key, _OpContains.Value)
|
||||
|
||||
End Select
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -2,7 +2,6 @@
|
||||
Public Class SearchCriteria
|
||||
Public Property ParenLeft As String = ""
|
||||
Public Property Key As String
|
||||
Public Property Op As SearchToken.OperatorToken = SearchToken.OperatorToken.Equals
|
||||
Public Property Value As Object
|
||||
Public Property ParentRight As String = ""
|
||||
Public Property JoinOperator As String = "AND"
|
||||
|
||||
@@ -1,70 +1,25 @@
|
||||
Namespace Search
|
||||
Public Class SearchToken
|
||||
|
||||
Public Enum [ValueType]
|
||||
AttributeName
|
||||
AttributeValue
|
||||
AttributeOperator
|
||||
End Enum
|
||||
Public Class AttributeValueToken
|
||||
Public AttributeTitle As String
|
||||
Public AttributeId As Integer
|
||||
Public TermValue As String
|
||||
Public TermId As Integer
|
||||
|
||||
Public Enum [InputMode]
|
||||
[Default]
|
||||
[Operator]
|
||||
Value
|
||||
End Enum
|
||||
Public Overrides Function GetHashCode() As Integer
|
||||
Return (TermId.GetHashCode & AttributeId.GetHashCode).GetHashCode()
|
||||
End Function
|
||||
|
||||
Public Enum [OperatorToken]
|
||||
Equals
|
||||
NotEquals
|
||||
GreaterThan
|
||||
LessThan
|
||||
Contains
|
||||
End Enum
|
||||
|
||||
Public MustInherit Class TokenValue
|
||||
Public Value As Object
|
||||
Public Type As [ValueType]
|
||||
Public Overrides Function Equals(obj As Object) As Boolean
|
||||
Return Me.GetHashCode() = DirectCast(obj, AttributeValueToken).GetHashCode()
|
||||
End Function
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return Value.ToString()
|
||||
Return $"{TermValue} ({AttributeTitle})"
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Public Class AttributeKeyToken
|
||||
Inherits TokenValue
|
||||
|
||||
Public Sub New(pValue As Object)
|
||||
Value = pValue
|
||||
Type = ValueType.AttributeName
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class AttributeOperatorToken
|
||||
Inherits TokenValue
|
||||
|
||||
Public Sub New(pValue As Object)
|
||||
Value = pValue
|
||||
Type = ValueType.AttributeOperator
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class AttributeValueToken
|
||||
Inherits TokenValue
|
||||
|
||||
Public Sub New(pValue As Object)
|
||||
Value = pValue
|
||||
Type = ValueType.AttributeValue
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class DateToken
|
||||
Inherits TokenValue
|
||||
|
||||
Public Sub New(pValue As Object)
|
||||
Value = pValue
|
||||
Type = ValueType.AttributeValue
|
||||
End Sub
|
||||
End Class
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -6,7 +6,6 @@ Imports DigitalData.GUIs.ZooFlow.Search.SearchToken
|
||||
Imports DigitalData.Modules.EDMI.API
|
||||
|
||||
Public Class frmSearchNeu
|
||||
Private Search As Search.Search
|
||||
Private Database As DatabaseWithFallback
|
||||
|
||||
Private TokenListDefault As New Dictionary(Of String, Object)
|
||||
@@ -17,13 +16,12 @@ Public Class frmSearchNeu
|
||||
|
||||
Private Sub XtraForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
Database = New DatabaseWithFallback(My.LogConfig, My.Application.Service.Client, My.DatabaseECM, My.DatabaseIDB)
|
||||
Search = New Search.Search(My.LogConfig, My.Application.User, Database)
|
||||
|
||||
Dim oTokens = Search.GetAttributeTokens()
|
||||
AddTokens(SearchControl2, oTokens)
|
||||
'Dim oTokens = Search.GetAttributeTokens()
|
||||
'AddTokens(SearchControl2, oTokens)
|
||||
|
||||
GridControl1.DataSource = Search.Query
|
||||
cmbSelect.SelectedIndex = 0
|
||||
'GridControl1.DataSource = Search.Query
|
||||
'cmbSelect.SelectedIndex = 0
|
||||
End Sub
|
||||
|
||||
Private Sub SetTokens(Editor As TokenEdit, Tokens As Dictionary(Of String, Object))
|
||||
@@ -52,69 +50,69 @@ Public Class frmSearchNeu
|
||||
End Sub
|
||||
|
||||
Private Sub SetNewTokens(pEditor As TokenEdit)
|
||||
Dim oLastToken = pEditor.GetTokenList().LastOrDefault()
|
||||
pEditor.Properties.BeginUpdate()
|
||||
'Dim oLastToken = pEditor.GetTokenList().LastOrDefault()
|
||||
'pEditor.Properties.BeginUpdate()
|
||||
|
||||
If oLastToken IsNot Nothing Then
|
||||
Select Case oLastToken.Value.GetType
|
||||
'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(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(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 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
|
||||
' Case Else
|
||||
' SetTokens(pEditor, TokenListDefault)
|
||||
' Search.InputMode = InputMode.Default
|
||||
|
||||
End Select
|
||||
Else
|
||||
SetTokens(pEditor, TokenListDefault)
|
||||
Search.InputMode = InputMode.Default
|
||||
End If
|
||||
' End Select
|
||||
'Else
|
||||
' SetTokens(pEditor, TokenListDefault)
|
||||
' Search.InputMode = InputMode.Default
|
||||
'End If
|
||||
|
||||
pEditor.Properties.EndUpdate()
|
||||
'pEditor.Properties.EndUpdate()
|
||||
End Sub
|
||||
|
||||
Private Sub SearchControl2_CustomDrawTokenGlyph(sender As Object, e As TokenEditCustomDrawTokenGlyphEventArgs) Handles SearchControl2.CustomDrawTokenGlyph
|
||||
' Set Background according to token type
|
||||
Select Case e.Value.GetType()
|
||||
Case GetType(AttributeKeyToken)
|
||||
e.Graphics.FillRectangle(New SolidBrush(ColorTranslator.FromHtml("#F87171")), e.Bounds)
|
||||
'' Set Background according to token type
|
||||
'Select Case e.Value.GetType()
|
||||
' Case GetType(AttributeKeyToken)
|
||||
' e.Graphics.FillRectangle(New SolidBrush(ColorTranslator.FromHtml("#F87171")), e.Bounds)
|
||||
|
||||
Case GetType(AttributeOperatorToken)
|
||||
e.Graphics.FillRectangle(New SolidBrush(ColorTranslator.FromHtml("#34D399")), e.Bounds)
|
||||
' Case GetType(AttributeOperatorToken)
|
||||
' e.Graphics.FillRectangle(New SolidBrush(ColorTranslator.FromHtml("#34D399")), e.Bounds)
|
||||
|
||||
Case GetType(AttributeValueToken)
|
||||
e.Graphics.FillRectangle(New SolidBrush(ColorTranslator.FromHtml("#60A5FA")), e.Bounds)
|
||||
Case Else
|
||||
End Select
|
||||
' Case GetType(AttributeValueToken)
|
||||
' e.Graphics.FillRectangle(New SolidBrush(ColorTranslator.FromHtml("#60A5FA")), e.Bounds)
|
||||
' Case Else
|
||||
'End Select
|
||||
|
||||
' Draw the glyph on top
|
||||
' This fixes: https://supportcenter.devexpress.com/ticket/details/t215578/tokenedit-glyph-is-not-visible-when-customdrawtokentext-is-used
|
||||
e.DefaultDraw()
|
||||
'' Draw the glyph on top
|
||||
'' This fixes: https://supportcenter.devexpress.com/ticket/details/t215578/tokenedit-glyph-is-not-visible-when-customdrawtokentext-is-used
|
||||
'e.DefaultDraw()
|
||||
End Sub
|
||||
|
||||
Private Sub SearchControl2_KeyUp(sender As Object, e As KeyEventArgs) Handles SearchControl2.KeyUp
|
||||
If Search.InputMode = InputMode.Value And e.KeyCode = Keys.Enter And SearchControl2.IsPopupOpen Then
|
||||
Search.Query.Add(New SearchCriteria With {
|
||||
.ParenLeft = False,
|
||||
.Key = "test",
|
||||
.Op = OperatorToken.Equals,
|
||||
.Value = "test",
|
||||
.ParentRight = False
|
||||
})
|
||||
End If
|
||||
'If Search.InputMode = InputMode.Value And e.KeyCode = Keys.Enter And SearchControl2.IsPopupOpen Then
|
||||
' Search.Query.Add(New SearchCriteria With {
|
||||
' .ParenLeft = False,
|
||||
' .Key = "test",
|
||||
' .Op = OperatorToken.Equals,
|
||||
' .Value = "test",
|
||||
' .ParentRight = False
|
||||
' })
|
||||
'End If
|
||||
End Sub
|
||||
|
||||
Private Sub RibbonControl1_Click(sender As Object, e As EventArgs) Handles RibbonControl1.Click
|
||||
|
||||
Reference in New Issue
Block a user