ZooFlow: Update ZooFlow Search
This commit is contained in:
@@ -1,32 +1,132 @@
|
||||
Imports DevExpress.XtraEditors
|
||||
Imports System.Collections
|
||||
Imports System.ComponentModel
|
||||
Imports DevExpress.XtraEditors
|
||||
Imports DigitalData.GUIs.ZooFlow.SearchToken
|
||||
|
||||
Public Class frmSearchNeu
|
||||
Public Class Attribute
|
||||
Public Name As String
|
||||
Private ReadOnly TokenListAttributes As New Dictionary(Of String, Object) From {
|
||||
{"Rechnungsnummer", New SearchToken.AttributeKeyToken("InvoiceNo")},
|
||||
{"Rechnungsdatum", New SearchToken.AttributeKeyToken("InvoiceDate")},
|
||||
{"Kundennummer", New SearchToken.AttributeKeyToken("CustNo")}
|
||||
}
|
||||
Private ReadOnly TokenListAttrValues As New Dictionary(Of String, Object) From {
|
||||
{"1233", New SearchToken.AttributeValueToken(1233)},
|
||||
{"1234", New SearchToken.AttributeValueToken(1234)},
|
||||
{"1235", New SearchToken.AttributeValueToken(1235)},
|
||||
{"4711", New SearchToken.AttributeValueToken(4711)},
|
||||
{"4712", New SearchToken.AttributeValueToken(4712)}
|
||||
}
|
||||
Private ReadOnly TokenListDate As New Dictionary(Of String, Object) From {
|
||||
{"heute", New SearchToken.DateToken(Date.Now)},
|
||||
{"gestern", New SearchToken.DateToken(Date.Now.AddDays(-1))},
|
||||
{"letzte Woche", New SearchToken.DateToken(TimeSpan.FromDays(-7))},
|
||||
{"letzter Monat", New SearchToken.DateToken(TimeSpan.FromDays(-30))}
|
||||
}
|
||||
Private ReadOnly TokenListOperands As New Dictionary(Of String, Object) From {
|
||||
{"gleich", New AttributeOperatorToken(OperatorToken.Equals)},
|
||||
{"nicht gleich", New AttributeOperatorToken(OperatorToken.NotEquals)}
|
||||
}
|
||||
Private TokenListDefault As Dictionary(Of String, Object)
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return Name
|
||||
End Function
|
||||
End Class
|
||||
Private InputMode As InputMode = InputMode.Default
|
||||
Private SearchQuery As New BindingList(Of SearchCriteria)
|
||||
|
||||
Private Sub frmSearchNeu_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
Dim oSQL As String = "SELECT * FROM VWIDB_BE_ATTRIBUTE WHERE DEFAULT_SEARCH_ATTRIBUTE = 1 AND LANG_CODE = 'de-DE'"
|
||||
Dim oAttributeList As DataTable = My.DatabaseIDB.GetDatatable(oSQL)
|
||||
Private Sub XtraForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
TokenListDefault = TokenListAttributes
|
||||
AddTokens(SearchControl2, TokenListDefault)
|
||||
|
||||
Dim oAttributes As New List(Of Attribute)
|
||||
For Each oRow As DataRow In oAttributeList.Rows
|
||||
Dim oAttr = New Attribute With {.Name = oRow.Item("ATTR_TITLE")}
|
||||
oAttributes.Add(oAttr)
|
||||
GridControl1.DataSource = SearchQuery
|
||||
cmbSelect.SelectedIndex = 0
|
||||
End Sub
|
||||
|
||||
cmbOperator.Properties.Items.Add(oAttr)
|
||||
cmbOperator.Properties.Items.Add(oAttr)
|
||||
Private Sub SetTokens(Editor As TokenEdit, Tokens As Dictionary(Of String, Object))
|
||||
Editor.Properties.Tokens.Clear()
|
||||
AddTokens(Editor, Tokens)
|
||||
End Sub
|
||||
|
||||
Private Sub AddTokens(Editor As TokenEdit, Tokens As Dictionary(Of String, Object))
|
||||
For Each oToken In Tokens
|
||||
Dim oTokenEditToken = New TokenEditToken With {
|
||||
.Description = oToken.Key,
|
||||
.Value = oToken.Value
|
||||
}
|
||||
Editor.Properties.Tokens.Add(oTokenEditToken)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
lookupValue.Properties.DataSource = oAttributes
|
||||
lookupValue.Properties.DisplayMember = "TITLE"
|
||||
Private Sub SearchControl2_Properties_TokenAdded(sender As Object, e As DevExpress.XtraEditors.TokenEditTokenAddedEventArgs) Handles SearchControl2.Properties.TokenAdded
|
||||
Dim oEditor As TokenEdit = sender
|
||||
SetNewTokens(oEditor)
|
||||
End Sub
|
||||
|
||||
Private Sub SearchControl2_Properties_TokenRemoved(sender As Object, e As TokenEditTokenRemovedEventArgs) Handles SearchControl2.Properties.TokenRemoved
|
||||
Dim oEditor As TokenEdit = sender
|
||||
SetNewTokens(oEditor)
|
||||
End Sub
|
||||
|
||||
lookupValue.Properties.DataSource = oAttributes
|
||||
lookupValue.Properties.DisplayMember = "TITLE"
|
||||
Private Sub SetNewTokens(pEditor As TokenEdit)
|
||||
Dim oLastToken = pEditor.GetTokenList().LastOrDefault()
|
||||
pEditor.Properties.BeginUpdate()
|
||||
|
||||
If oLastToken IsNot Nothing Then
|
||||
Select Case oLastToken.Value.GetType
|
||||
|
||||
Case GetType(AttributeKeyToken)
|
||||
' After the attribute key comes an operator
|
||||
SetTokens(pEditor, TokenListOperands)
|
||||
InputMode = InputMode.Operator
|
||||
|
||||
Case GetType(AttributeOperatorToken)
|
||||
' After the attribute operator comes a value
|
||||
SetTokens(pEditor, TokenListAttrValues)
|
||||
InputMode = InputMode.Value
|
||||
|
||||
Case GetType(AttributeValueToken)
|
||||
' After the attribute value comes another value
|
||||
SetTokens(pEditor, TokenListAttrValues)
|
||||
InputMode = InputMode.Value
|
||||
|
||||
Case Else
|
||||
SetTokens(pEditor, TokenListDefault)
|
||||
InputMode = InputMode.Default
|
||||
|
||||
End Select
|
||||
Else
|
||||
SetTokens(pEditor, TokenListDefault)
|
||||
InputMode = InputMode.Default
|
||||
End If
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
' 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 InputMode = InputMode.Value And e.KeyCode = Keys.Enter And e.Control = True Then
|
||||
SearchQuery.Add(New SearchCriteria With {
|
||||
.ParenLeft = False,
|
||||
.Key = "test",
|
||||
.Op = OperatorToken.Equals,
|
||||
.Value = "test",
|
||||
.ParentRight = False
|
||||
})
|
||||
End If
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user