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 Namespace Search
Public Property ParenLeft As String = "" Public Class SearchCriteria
Public Property Key As String Public Property ParenLeft As String = ""
Public Property Op As SearchToken.OperatorToken = SearchToken.OperatorToken.Equals Public Property Key As String
Public Property Value As Object Public Property Op As SearchToken.OperatorToken = SearchToken.OperatorToken.Equals
Public Property ParentRight As String = "" Public Property Value As Object
End Class 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 = "Kein", .DisableFilter = True, .[To] = Nothing},
New FilterTimeframe() With {.Name = "Eigener", .CustomFilter = True, .[To] = Date.Now, .From = Date.Now}, New FilterTimeframe() With {.Name = "Eigener", .CustomFilter = True, .[To] = Date.Now, .From = Date.Now},
New FilterTimeframe() With { New FilterTimeframe() With {
@@ -21,15 +22,17 @@
} }
} }
Public Class FilterTimeframe Public Class FilterTimeframe
Public Property Name As String Public Property Name As String
Public Property From As Date Public Property From As Date
Public Property [To] As Date = Date.Now Public Property [To] As Date = Date.Now
Public Property DisableFilter As Boolean = False Public Property DisableFilter As Boolean = False
Public Property CustomFilter As Boolean = False Public Property CustomFilter As Boolean = False
Public Overrides Function ToString() As String Public Overrides Function ToString() As String
Return Name.ToString Return Name.ToString
End Function End Function
End Class
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] Public Enum [ValueType]
AttributeName AttributeName
AttributeValue AttributeValue
AttributeOperator AttributeOperator
End Enum End Enum
Public Enum [InputMode] Public Enum [InputMode]
[Default] [Default]
[Operator] [Operator]
Value Value
End Enum End Enum
Public Enum [OperatorToken] Public Enum [OperatorToken]
Equals Equals
NotEquals NotEquals
End Enum GreaterThan
LessThan
Contains
End Enum
Public MustInherit Class TokenValue Public MustInherit Class TokenValue
Public Value As Object Public Value As Object
Public Type As [ValueType] Public Type As [ValueType]
Public Overrides Function ToString() As String Public Overrides Function ToString() As String
Return Value.ToString() Return Value.ToString()
End Function 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 Class
Public Class AttributeKeyToken End Namespace
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

View File

@@ -1,41 +1,28 @@
Imports System.Collections Imports System.Collections
Imports System.ComponentModel Imports System.ComponentModel
Imports DevExpress.XtraEditors 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 Public Class frmSearchNeu
Private ReadOnly TokenListAttributes As New Dictionary(Of String, Object) From { Private Search As Search.Search
{"Rechnungsnummer", New SearchToken.AttributeKeyToken("InvoiceNo")}, Private Database As DatabaseWithFallback
{"Rechnungsdatum", New SearchToken.AttributeKeyToken("InvoiceDate")},
{"Kundennummer", New SearchToken.AttributeKeyToken("CustNo")} Private TokenListDefault As New Dictionary(Of String, Object)
} Private TokenListOperands As New Dictionary(Of String, Object)
Private ReadOnly TokenListAttrValues As New Dictionary(Of String, Object) From { Private TokenListAttrValues As New Dictionary(Of String, Object)
{"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 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 Private Sub XtraForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TokenListDefault = TokenListAttributes Database = New DatabaseWithFallback(My.LogConfig, My.Application.Service.Client, My.DatabaseECM, My.DatabaseIDB)
AddTokens(SearchControl2, TokenListDefault) 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 cmbSelect.SelectedIndex = 0
End Sub End Sub
@@ -73,27 +60,27 @@ Public Class frmSearchNeu
Case GetType(AttributeKeyToken) Case GetType(AttributeKeyToken)
' After the attribute key comes an operator ' After the attribute key comes an operator
SetTokens(pEditor, TokenListOperands) SetTokens(pEditor, Search.GetOperatorTokens(GetType(String)))
InputMode = InputMode.Operator Search.InputMode = InputMode.Operator
Case GetType(AttributeOperatorToken) Case GetType(AttributeOperatorToken)
' After the attribute operator comes a value ' After the attribute operator comes a value
SetTokens(pEditor, TokenListAttrValues) SetTokens(pEditor, TokenListAttrValues)
InputMode = InputMode.Value Search.InputMode = InputMode.Value
Case GetType(AttributeValueToken) Case GetType(AttributeValueToken)
' After the attribute value comes another value ' After the attribute value comes another value
SetTokens(pEditor, TokenListAttrValues) SetTokens(pEditor, TokenListAttrValues)
InputMode = InputMode.Value Search.InputMode = InputMode.Value
Case Else Case Else
SetTokens(pEditor, TokenListDefault) SetTokens(pEditor, TokenListDefault)
InputMode = InputMode.Default Search.InputMode = InputMode.Default
End Select End Select
Else Else
SetTokens(pEditor, TokenListDefault) SetTokens(pEditor, TokenListDefault)
InputMode = InputMode.Default Search.InputMode = InputMode.Default
End If End If
pEditor.Properties.EndUpdate() pEditor.Properties.EndUpdate()
@@ -119,8 +106,8 @@ Public Class frmSearchNeu
End Sub End Sub
Private Sub SearchControl2_KeyUp(sender As Object, e As KeyEventArgs) Handles SearchControl2.KeyUp 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 If Search.InputMode = InputMode.Value And e.KeyCode = Keys.Enter And SearchControl2.IsPopupOpen Then
SearchQuery.Add(New SearchCriteria With { Search.Query.Add(New SearchCriteria With {
.ParenLeft = False, .ParenLeft = False,
.Key = "test", .Key = "test",
.Op = OperatorToken.Equals, .Op = OperatorToken.Equals,
@@ -129,4 +116,8 @@ Public Class frmSearchNeu
}) })
End If End If
End Sub End Sub
Private Sub RibbonControl1_Click(sender As Object, e As EventArgs) Handles RibbonControl1.Click
End Sub
End Class End Class

View File

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

View File

@@ -350,6 +350,7 @@
<Compile Include="My Project\AssemblyInfo.vb" /> <Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="MyApplication.vb" /> <Compile Include="MyApplication.vb" />
<Compile Include="Queries\ClassQueries.vb" /> <Compile Include="Queries\ClassQueries.vb" />
<Compile Include="Search\Search.vb" />
<Compile Include="Search\SearchCriteria.vb" /> <Compile Include="Search\SearchCriteria.vb" />
<Compile Include="Search\SearchFilter.vb" /> <Compile Include="Search\SearchFilter.vb" />
<Compile Include="Search\SearchToken.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( Dim oResult As Long = Await My.Application.Service.Client.NewFileAsync(
txtFile2Import.Text, txtFile2Import.Text,
"WORK", "WORK",
"DOC",
"DEFAULT", "DEFAULT",
New NewFileOptions With { New NewFileOptions With {
.KeepExtension = CheckBoxKeepExtension.Checked, .KeepExtension = CheckBoxKeepExtension.Checked,