Modules/GUIs.ZooFlow/Search/frmSearch2021.vb
2021-11-01 13:19:55 +01:00

138 lines
4.3 KiB
VB.net

Imports DevExpress.Utils
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Repository
Public Class frmSearch2021
Private ReadOnly TokenListAttributes As New Dictionary(Of String, Object) From {
{"Rechnungsnummer", New AttributeToken(7411)},
{"Rechnungsdatum", New AttributeToken(7412)},
{"Kundennummer", New AttributeToken(7413)}
}
Private ReadOnly TokenListAttrValues As New Dictionary(Of String, Object) From {
{"{1233}", New AttributeValueToken(1233)},
{"{1234}", New AttributeValueToken(1234)},
{"{1235}", New AttributeValueToken(1235)}
}
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))}
}
Private TokenListDefault As Dictionary(Of String, Object)
Private TokenListAll As Dictionary(Of String, Object)
Private Sub XtraForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim TokenList As New Dictionary(Of String, Object)
TokenListAll = TokenList.
Concat(TokenListAttributes).
Concat(TokenListAttrValues).
Concat(TokenListDate).
ToDictionary(Function(a) a.Key, Function(a) a.Value)
TokenListDefault = TokenList.
Concat(TokenListAttributes).
Concat(TokenListDate).
ToDictionary(Function(a) a.Key, Function(a) a.Value)
AddTokens(SearchControl2, TokenListDefault)
ComboBoxEdit1.SelectedIndex = 0
End Sub
Public Enum [ValueType]
AttributeName
AttributeValue
End Enum
Public Enum [InputMode]
[Default]
Value
End Enum
Public Class TokenValue
Public Value As Object
Public Type As [ValueType]
Public Overrides Function ToString() As String
Return Value.ToString()
End Function
End Class
Public Class AttributeToken
Inherits TokenValue
Public Sub New(pValue As Object)
Value = pValue
Type = ValueType.AttributeName
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
Private Sub AddTokens(Editor As TokenEdit, Tokens As Dictionary(Of String, Object))
For Each oToken In Tokens
Editor.Properties.Tokens.Add(New DevExpress.XtraEditors.TokenEditToken With {
.Description = oToken.Key,
.Value = oToken.Value
})
Next
End Sub
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
Private Sub SetNewTokens(pEditor As TokenEdit)
Dim oLastToken = pEditor.GetTokenList().LastOrDefault()
pEditor.Properties.BeginUpdate()
If oLastToken IsNot Nothing Then
pEditor.Properties.Tokens.Clear()
Select Case oLastToken.Value.GetType
Case GetType(AttributeToken)
AddTokens(pEditor, TokenListAttrValues)
Case GetType(AttributeValueToken)
AddTokens(pEditor, TokenListAll)
Case Else
AddTokens(pEditor, TokenListDefault)
End Select
pEditor.Properties.EndUpdate()
Else
pEditor.Properties.Tokens.Clear()
AddTokens(pEditor, TokenListDefault)
End If
End Sub
End Class