ZooFlow: WIP Search

This commit is contained in:
Jonathan Jenne 2021-11-25 15:48:00 +01:00
parent 96d77e9f68
commit 297a8d144b
8 changed files with 227 additions and 114 deletions

View File

@ -0,0 +1,107 @@
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 = $"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)
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

View File

@ -1,8 +1,12 @@
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 = ""
End Class
Namespace Search
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"
End Class
End Namespace

View File

@ -1,6 +1,7 @@
Public Class SearchFilter
Namespace Search
Public Class SearchFilter
Public Shared Property DefaultFilters As New List(Of FilterTimeframe) From {
Public Shared Property DefaultFilters As New List(Of FilterTimeframe) From {
New FilterTimeframe() With {.Name = "Kein", .DisableFilter = True, .[To] = Nothing},
New FilterTimeframe() With {.Name = "Eigener", .CustomFilter = True, .[To] = Date.Now, .From = Date.Now},
New FilterTimeframe() With {
@ -21,15 +22,17 @@
}
}
Public Class FilterTimeframe
Public Property Name As String
Public Property From As Date
Public Property [To] As Date = Date.Now
Public Property DisableFilter As Boolean = False
Public Property CustomFilter As Boolean = False
Public Class FilterTimeframe
Public Property Name As String
Public Property From As Date
Public Property [To] As Date = Date.Now
Public Property DisableFilter As Boolean = False
Public Property CustomFilter As Boolean = False
Public Overrides Function ToString() As String
Return Name.ToString
End Function
Public Overrides Function ToString() As String
Return Name.ToString
End Function
End Class
End Class
End Class
End Namespace

View File

@ -1,64 +1,70 @@
Public Class SearchToken
Namespace Search
Public Class SearchToken
Public Enum [ValueType]
AttributeName
AttributeValue
AttributeOperator
End Enum
Public Enum [ValueType]
AttributeName
AttributeValue
AttributeOperator
End Enum
Public Enum [InputMode]
[Default]
[Operator]
Value
End Enum
Public Enum [InputMode]
[Default]
[Operator]
Value
End Enum
Public Enum [OperatorToken]
Equals
NotEquals
End Enum
Public Enum [OperatorToken]
Equals
NotEquals
GreaterThan
LessThan
Contains
End Enum
Public MustInherit Class TokenValue
Public Value As Object
Public Type As [ValueType]
Public MustInherit Class TokenValue
Public Value As Object
Public Type As [ValueType]
Public Overrides Function ToString() As String
Return Value.ToString()
End Function
Public Overrides Function ToString() As String
Return Value.ToString()
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
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

View File

@ -1,41 +1,28 @@
Imports System.Collections
Imports System.ComponentModel
Imports DevExpress.XtraEditors
Imports DigitalData.GUIs.ZooFlow.SearchToken
Imports DigitalData.GUIs.ZooFlow.Search
Imports DigitalData.GUIs.ZooFlow.Search.SearchToken
Imports DigitalData.Modules.EDMI.API
Public Class frmSearchNeu
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)
Private Search As Search.Search
Private Database As DatabaseWithFallback
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 InputMode As InputMode = InputMode.Default
Private SearchQuery As New BindingList(Of SearchCriteria)
Private Sub XtraForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TokenListDefault = TokenListAttributes
AddTokens(SearchControl2, TokenListDefault)
Database = New DatabaseWithFallback(My.LogConfig, My.Application.Service.Client, My.DatabaseECM, My.DatabaseIDB)
Search = New Search.Search(My.LogConfig, My.Application.User, Database)
GridControl1.DataSource = SearchQuery
Dim oTokens = Search.GetAttributeTokens()
AddTokens(SearchControl2, oTokens)
GridControl1.DataSource = Search.Query
cmbSelect.SelectedIndex = 0
End Sub
@ -73,27 +60,27 @@ Public Class frmSearchNeu
Case GetType(AttributeKeyToken)
' After the attribute key comes an operator
SetTokens(pEditor, TokenListOperands)
InputMode = InputMode.Operator
SetTokens(pEditor, Search.GetOperatorTokens(GetType(String)))
Search.InputMode = InputMode.Operator
Case GetType(AttributeOperatorToken)
' After the attribute operator comes a value
SetTokens(pEditor, TokenListAttrValues)
InputMode = InputMode.Value
Search.InputMode = InputMode.Value
Case GetType(AttributeValueToken)
' After the attribute value comes another value
SetTokens(pEditor, TokenListAttrValues)
InputMode = InputMode.Value
Search.InputMode = InputMode.Value
Case Else
SetTokens(pEditor, TokenListDefault)
InputMode = InputMode.Default
Search.InputMode = InputMode.Default
End Select
Else
SetTokens(pEditor, TokenListDefault)
InputMode = InputMode.Default
Search.InputMode = InputMode.Default
End If
pEditor.Properties.EndUpdate()
@ -119,8 +106,8 @@ Public Class frmSearchNeu
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 {
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,
@ -129,4 +116,8 @@ Public Class frmSearchNeu
})
End If
End Sub
Private Sub RibbonControl1_Click(sender As Object, e As EventArgs) Handles RibbonControl1.Click
End Sub
End Class

View File

@ -9,7 +9,7 @@ Imports DevExpress.XtraEditors
Imports DevExpress.XtraSplashScreen
Imports DigitalData.GUIs.Common
Imports DigitalData.GUIs.ZooFlow.ClassConstants
Imports DigitalData.GUIs.ZooFlow.SearchFilter
Imports DigitalData.GUIs.ZooFlow.Search.SearchFilter
Imports System.Threading.Tasks

View File

@ -350,6 +350,7 @@
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="MyApplication.vb" />
<Compile Include="Queries\ClassQueries.vb" />
<Compile Include="Search\Search.vb" />
<Compile Include="Search\SearchCriteria.vb" />
<Compile Include="Search\SearchFilter.vb" />
<Compile Include="Search\SearchToken.vb" />

View File

@ -99,6 +99,7 @@ Public Class frmtest
Dim oResult As Long = Await My.Application.Service.Client.NewFileAsync(
txtFile2Import.Text,
"WORK",
"DOC",
"DEFAULT",
New NewFileOptions With {
.KeepExtension = CheckBoxKeepExtension.Checked,