From 0c26b56c84fb6d4eac2ffcb306ed1fed2278977d Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 15 Jun 2022 16:36:18 +0200 Subject: [PATCH] Implement refreshing search from DocumentResultList --- ZooFlow/App.config | 54 +++++++++++- ZooFlow/Search/SearchRunner.vb | 141 ++++++++++++++++++++------------ ZooFlow/Search/frmSearchFlow.vb | 11 ++- ZooFlow/frmFlowForm.Designer.vb | 32 ++++---- 4 files changed, 166 insertions(+), 72 deletions(-) diff --git a/ZooFlow/App.config b/ZooFlow/App.config index f909033..e9c4984 100644 --- a/ZooFlow/App.config +++ b/ZooFlow/App.config @@ -21,10 +21,10 @@ - Skin/Office 2019 Colorful + - Custom/Digital Data Palette + Custom/Digital Data 2 @@ -36,7 +36,7 @@ - + True @@ -81,6 +81,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -107,6 +131,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ZooFlow/Search/SearchRunner.vb b/ZooFlow/Search/SearchRunner.vb index 6b20210..5e17f15 100644 --- a/ZooFlow/Search/SearchRunner.vb +++ b/ZooFlow/Search/SearchRunner.vb @@ -40,29 +40,41 @@ Namespace Search Public Event NeedsNewSavedSearch As EventHandler Public Event Closed As EventHandler(Of Integer) - Private Property _ActiveDateConstraint As String = String.Empty - Public ReadOnly Property ActiveDateConstraint As String - Get - Return _ActiveDateConstraint - End Get - End Property + 'Private Property _ActiveDateConstraint As String = String.Empty + 'Public ReadOnly Property ActiveDateConstraint As String + ' Get + ' Return _ActiveDateConstraint + ' End Get + 'End Property + + 'Private _ActiveSearchTokens As New List(Of SearchToken.Token) + 'Private _ActiveDateAttribute As String = SEARCH_FACT_DATE_DEFAULT + 'Private _ActiveTokenOperator As TokenOperator = TokenOperator.And + + 'Public ReadOnly Property ActiveDateAttribute As String + ' Get + ' Return _ActiveDateAttribute + ' End Get + 'End Property + + 'Public ReadOnly Property ActiveTokens As List(Of SearchToken.Token) + ' Get + ' Return _ActiveSearchTokens + ' End Get + 'End Property - Private _ActiveSearchTokens As New List(Of SearchToken.Token) - Private _ActiveDateAttribute As String = SEARCH_FACT_DATE_DEFAULT - Private _ActiveTokenOperator As TokenOperator = TokenOperator.And - Public ReadOnly Property ActiveDateAttribute As String - Get - Return _ActiveDateAttribute - End Get - End Property - Public ReadOnly Property ActiveTokens As List(Of SearchToken.Token) + Private _ActiveParams As New SearchParameters + + Public ReadOnly Property ActiveSearchParameters As SearchParameters Get - Return _ActiveSearchTokens + Return _ActiveParams End Get End Property + Public Property LastOpenedForm As Common.IResultForm + Public Property BaseSearchSQL As String Public Property ExplicitDate As Boolean = False @@ -122,10 +134,7 @@ Namespace Search End Function Public Async Function RunWithTokens(pTokens As IEnumerable(Of Search.SearchToken.Token), pDateFrom As Date, pDateTo As Date, pSearchTitle As String) As Task(Of SearchResult) - If pTokens.Count = 0 And - pDateFrom = Date.MinValue And - pDateTo = Date.MinValue And - _ActiveDateConstraint = String.Empty Then + If pTokens.Count = 0 And pDateFrom = Date.MinValue And pDateTo = Date.MinValue And _ActiveParams.DateConstraint = String.Empty Then Return New SearchResult(0) End If @@ -136,33 +145,38 @@ Namespace Search }) End Function + Private Async Function ExecuteSearch(pTokens As List(Of SearchToken.Token), pSearchTerm As String, pDateConstraint As String) As Task(Of Boolean) + Dim oSQL = String.Empty - 'Public Async Function RunWithSearchTerm(pSearchTerm As String, pDateFrom As Date, pDateTo As Date) As Task(Of SearchResult) - ' Return Await RunWithSearchTerm(pSearchTerm, pDateFrom, pDateTo, Nothing, Nothing) - 'End Function + _ActiveParams.DateConstraint = pDateConstraint - Private Async Function RunWithSearchOptions(pOptions As SearchOptions) As Task(Of SearchResult) - Dim oDateConstraint = Await GetDateConstraint(pOptions.DateFrom, pOptions.DateTo) - Dim oWindowTitle = GetResultWindowString(pOptions.SearchString, pOptions.SearchTitle) - Dim oParams = GetParams(oWindowTitle) - Dim oTokens = pOptions.SearchTokens - Dim oSearchTerm = pOptions.SearchString + If pTokens IsNot Nothing AndAlso pTokens.Count > 0 Then + _ActiveParams.SearchTokens = pTokens + _ActiveParams.SearchString = String.Empty - Dim oSQL = String.Empty + Await InsertSearchTokens(pTokens) + oSQL = $"EXEC PRIDB_SEARCH_GET_TOKEN_RESULT_DOCS {UserId}, '{pDateConstraint}', '{UserLanguage}'" + ElseIf pSearchTerm IsNot Nothing Then + _ActiveParams.SearchTokens.Clear() + _ActiveParams.SearchString = pSearchTerm - If oTokens IsNot Nothing AndAlso oTokens.Count > 0 Then - _ActiveSearchTokens = oTokens - Await InsertSearchTokens(oTokens) - oSQL = $"EXEC PRIDB_SEARCH_GET_TOKEN_RESULT_DOCS {UserId}, '{oDateConstraint}', '{UserLanguage}'" - ElseIf oSearchTerm IsNot Nothing Then - _ActiveSearchTokens.Clear() - oSQL = $"EXEC PRIDB_SEARCH_GET_TEXT_RESULTS {UserId},'{pOptions.SearchString}','{oDateConstraint}', '{UserLanguage}'" + oSQL = $"EXEC PRIDB_SEARCH_GET_TEXT_RESULTS {UserId},'{pSearchTerm}','{pDateConstraint}', '{UserLanguage}'" Else - _ActiveSearchTokens.Clear() - oSQL = $"EXEC PRIDB_SEARCH_GET_TEXT_RESULTS {UserId},'{String.Empty}','{oDateConstraint}', '{UserLanguage}'" + _ActiveParams.SearchTokens.Clear() + _ActiveParams.SearchString = String.Empty + + oSQL = $"EXEC PRIDB_SEARCH_GET_TEXT_RESULTS {UserId},'{String.Empty}','{pDateConstraint}', '{UserLanguage}'" End If - If Await My.Database.ExecuteNonQueryIDBAsync(oSQL) = True Then + Return Await My.Database.ExecuteNonQueryIDBAsync(oSQL) + End Function + + Private Async Function RunWithSearchOptions(pOptions As SearchOptions) As Task(Of SearchResult) + Dim oDateConstraint = Await GetDateConstraint(pOptions.DateFrom, pOptions.DateTo) + Dim oWindowTitle = GetResultWindowString(pOptions.SearchString, pOptions.SearchTitle) + Dim oParams = GetParams(oWindowTitle) + + If Await ExecuteSearch(pOptions.SearchTokens, pOptions.SearchString, oDateConstraint) = True Then Dim oDTDocResult = Await My.Database.GetDatatableIDBAsync(BaseSearchSQL) If oDTDocResult Is Nothing Then @@ -182,6 +196,7 @@ Namespace Search Dim oForm As New frmDocumentResultList(My.LogConfig, Environment, oParams) AddEventHandlers(oForm) + LastOpenedForm = oForm oForm.Show() Return New SearchResult(oRowCount) @@ -195,9 +210,25 @@ Namespace Search End If End Function + Public Async Function RunLastSearch() As Task(Of DocumentResultList.DocumentResult) + Try + If Await ExecuteSearch(_ActiveParams.SearchTokens, _ActiveParams.SearchString, _ActiveParams.DateConstraint) Then + Dim oResult = Await My.Database.GetDatatableIDBAsync(BaseSearchSQL) + + Return New DocumentResultList.DocumentResult() With { + .Title = SearchId, + .Datatable = oResult + } + Else + Return Nothing + End If + Catch ex As Exception + Logger.Error(ex) + Return Nothing + End Try + End Function + Private Sub AddEventHandlers(pForm As frmDocumentResultList) - ' TODO: Implement - 'AddHandler pForm.NeedsRefresh, AddressOf Form_NeedsRefresh AddHandler pForm.FormClosed, AddressOf Form_Closed ' Only setup event if it is actually used @@ -220,7 +251,7 @@ Namespace Search End Sub Private Async Function GetDateConstraint(pDateFrom As Date, pDateTo As Date) As Task(Of String) - Dim oSimpleDateConstraint = $"{_ActiveDateAttribute}~{_ActiveDateConstraint}" + Dim oSimpleDateConstraint = $"{_ActiveParams.DateAttribute}~{_ActiveParams.DateConstraint}" Dim oExplicitConstraint = Await MaybeSetExplicitDateConstraint(pDateFrom, pDateTo) If IsNothing(oExplicitConstraint) Then @@ -246,7 +277,7 @@ Namespace Search Dim oOperatorString - Select Case _ActiveTokenOperator + Select Case _ActiveParams.TokenOperator Case TokenOperator.Or oOperatorString = "OR" Case Else @@ -277,7 +308,7 @@ Namespace Search End If Dim oProc = $"EXEC PRIDB_SEARCH_ADD_USR_DATE {UserId},'{pDateFrom}','{oDateTo}'" If Await My.Database.ExecuteNonQueryIDBAsync(oProc) = True Then - Return $"{_ActiveDateAttribute}~DATEPART" + Return $"{_ActiveParams.DateAttribute}~DATEPART" Else Return Nothing End If @@ -332,19 +363,19 @@ Namespace Search End Function Public Sub SetDateConstraint() - _ActiveDateConstraint = String.Empty + _ActiveParams.DateConstraint = String.Empty End Sub Public Sub SetDateConstraint(pConstraintName As String) - _ActiveDateConstraint = pConstraintName + _ActiveParams.DateConstraint = pConstraintName End Sub Public Sub SetDateConstraint(pConstraint As DateConstraint) - _ActiveDateConstraint = DateConstraintToConstant(pConstraint) + _ActiveParams.DateConstraint = DateConstraintToConstant(pConstraint) End Sub Public Sub SetTokenOperator(pOperator As TokenOperator) - _ActiveTokenOperator = pOperator + _ActiveParams.DateConstraint = pOperator End Sub Public Function DateConstraintToConstant(pConstraint As DateConstraint) As String @@ -402,13 +433,21 @@ Namespace Search End Function Public Sub SetDateAttribute(pAttributeName As String) - _ActiveDateAttribute = pAttributeName + _ActiveParams.DateAttribute = pAttributeName End Sub Public Sub SetDateAttribute() - _ActiveDateAttribute = SEARCH_FACT_DATE_DEFAULT + _ActiveParams.DateAttribute = SEARCH_FACT_DATE_DEFAULT End Sub + Public Class SearchParameters + Public SearchTokens As New List(Of Search.SearchToken.Token) + Public TokenOperator As TokenOperator + Public SearchString As String + Public DateConstraint As String + Public DateAttribute As String + End Class + Public Class SearchOptions Public SearchTitle As String diff --git a/ZooFlow/Search/frmSearchFlow.vb b/ZooFlow/Search/frmSearchFlow.vb index d6044eb..e50fc69 100644 --- a/ZooFlow/Search/frmSearchFlow.vb +++ b/ZooFlow/Search/frmSearchFlow.vb @@ -6,6 +6,7 @@ Imports DevExpress.XtraEditors.Controls Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Views.Tile Imports DevExpress.XtraSplashScreen +Imports DigitalData.GUIs.Common Imports DigitalData.GUIs.ZooFlow.ClassConstants Imports DigitalData.GUIs.ZooFlow.SavedSearch Imports DigitalData.GUIs.ZooFlow.Search @@ -17,7 +18,7 @@ Public Class frmSearchFlow Private ReadOnly LogConfig As LogConfig = My.LogConfig Private ReadOnly Logger = My.LogConfig.GetLogger() Private SearchLoader As SearchLoader - Private SearchRunner As SearchRunner + Private WithEvents SearchRunner As SearchRunner Private TokenTable As DataTable = Nothing Private FormLoading As Boolean = True @@ -34,6 +35,7 @@ Public Class frmSearchFlow } AddHandler SearchRunner.NeedsNewSavedSearch, AddressOf SearchRunner_NewSavedSearch + AddHandler SearchRunner.NeedsRefresh, AddressOf SearchRunner_NeedsRefresh TokenTable = GetTokenTable() ComboBoxDateAttributes.Properties.Items.AddRange(LoadDateAttributes()) @@ -51,13 +53,18 @@ Public Class frmSearchFlow End Sub + Private Async Sub SearchRunner_NeedsRefresh(sender As Object, e As Integer) + Dim oResult = Await SearchRunner.RunLastSearch() + SearchRunner.LastOpenedForm.RefreshResults(New List(Of DocumentResultList.DocumentResult) From {oResult}) + End Sub + Private Sub SearchRunner_NewSavedSearch(sender As Object, e As EventArgs) Dim oForm As New frmEditSearch With {.IsNew = True} If oForm.ShowDialog() = DialogResult.OK Then ' Get active tokens and create the search - Dim oTokens = SearchRunner.ActiveTokens + Dim oTokens = SearchRunner.ActiveSearchParameters.SearchTokens SearchLoader.CreateCustomSearch(oForm.Title, oForm.Description, oTokens, oForm.ImageString) ' Reload the searches diff --git a/ZooFlow/frmFlowForm.Designer.vb b/ZooFlow/frmFlowForm.Designer.vb index 2fedcb8..17cfa55 100644 --- a/ZooFlow/frmFlowForm.Designer.vb +++ b/ZooFlow/frmFlowForm.Designer.vb @@ -38,6 +38,7 @@ Partial Class frmFlowForm Me.TestToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() Me.ToolStripSeparator2 = New System.Windows.Forms.ToolStripSeparator() Me.ZooFlowBeendenToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() + Me.TreeViewToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components) Me.PictureBoxSearch = New DevExpress.XtraEditors.SvgImageBox() Me.PictureBoxPM = New DevExpress.XtraEditors.SvgImageBox() @@ -77,7 +78,6 @@ Partial Class frmFlowForm Me.PMTaskBadgeGroup = New DevExpress.Utils.VisualEffects.Badge() Me.PMTaskBadgeIndividual = New DevExpress.Utils.VisualEffects.Badge() Me.TimerDisplay = New System.Windows.Forms.Timer(Me.components) - Me.TreeViewToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() Me.ContextMenuSystray.SuspendLayout() CType(Me.PictureBoxSearch, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.PictureBoxPM, System.ComponentModel.ISupportInitialize).BeginInit() @@ -108,56 +108,62 @@ Partial Class frmFlowForm ' Me.ContextMenuSystray.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.EinblendenToolStripMenuItem, Me.ToolStripSeparator1, Me.VerwaltungToolStripMenuItem, Me.ToolStripSeparator3, Me.SucheEntwurfToolStripMenuItem, Me.TestToolStripMenuItem, Me.ToolStripSeparator2, Me.ZooFlowBeendenToolStripMenuItem, Me.TreeViewToolStripMenuItem}) Me.ContextMenuSystray.Name = "ContextMenuSystray" - Me.ContextMenuSystray.Size = New System.Drawing.Size(181, 176) + Me.ContextMenuSystray.Size = New System.Drawing.Size(170, 154) ' 'EinblendenToolStripMenuItem ' Me.EinblendenToolStripMenuItem.Image = Global.DigitalData.GUIs.ZooFlow.My.Resources.Resources.action_add_16xMD Me.EinblendenToolStripMenuItem.Name = "EinblendenToolStripMenuItem" - Me.EinblendenToolStripMenuItem.Size = New System.Drawing.Size(180, 22) + Me.EinblendenToolStripMenuItem.Size = New System.Drawing.Size(169, 22) Me.EinblendenToolStripMenuItem.Text = "Einblenden" Me.EinblendenToolStripMenuItem.Visible = False ' 'ToolStripSeparator1 ' Me.ToolStripSeparator1.Name = "ToolStripSeparator1" - Me.ToolStripSeparator1.Size = New System.Drawing.Size(177, 6) + Me.ToolStripSeparator1.Size = New System.Drawing.Size(166, 6) ' 'VerwaltungToolStripMenuItem ' Me.VerwaltungToolStripMenuItem.Image = Global.DigitalData.GUIs.ZooFlow.My.Resources.Resources.gear_32xLG Me.VerwaltungToolStripMenuItem.Name = "VerwaltungToolStripMenuItem" - Me.VerwaltungToolStripMenuItem.Size = New System.Drawing.Size(180, 22) + Me.VerwaltungToolStripMenuItem.Size = New System.Drawing.Size(169, 22) Me.VerwaltungToolStripMenuItem.Text = "Verwaltung" ' 'ToolStripSeparator3 ' Me.ToolStripSeparator3.Name = "ToolStripSeparator3" - Me.ToolStripSeparator3.Size = New System.Drawing.Size(177, 6) + Me.ToolStripSeparator3.Size = New System.Drawing.Size(166, 6) ' 'SucheEntwurfToolStripMenuItem ' Me.SucheEntwurfToolStripMenuItem.Name = "SucheEntwurfToolStripMenuItem" - Me.SucheEntwurfToolStripMenuItem.Size = New System.Drawing.Size(180, 22) + Me.SucheEntwurfToolStripMenuItem.Size = New System.Drawing.Size(169, 22) Me.SucheEntwurfToolStripMenuItem.Text = "Suche Entwurf" ' 'TestToolStripMenuItem ' Me.TestToolStripMenuItem.Name = "TestToolStripMenuItem" - Me.TestToolStripMenuItem.Size = New System.Drawing.Size(180, 22) + Me.TestToolStripMenuItem.Size = New System.Drawing.Size(169, 22) Me.TestToolStripMenuItem.Text = "Test" ' 'ToolStripSeparator2 ' Me.ToolStripSeparator2.Name = "ToolStripSeparator2" - Me.ToolStripSeparator2.Size = New System.Drawing.Size(177, 6) + Me.ToolStripSeparator2.Size = New System.Drawing.Size(166, 6) ' 'ZooFlowBeendenToolStripMenuItem ' Me.ZooFlowBeendenToolStripMenuItem.Name = "ZooFlowBeendenToolStripMenuItem" - Me.ZooFlowBeendenToolStripMenuItem.Size = New System.Drawing.Size(180, 22) + Me.ZooFlowBeendenToolStripMenuItem.Size = New System.Drawing.Size(169, 22) Me.ZooFlowBeendenToolStripMenuItem.Text = "ZooFlow beenden" ' + 'TreeViewToolStripMenuItem + ' + Me.TreeViewToolStripMenuItem.Name = "TreeViewToolStripMenuItem" + Me.TreeViewToolStripMenuItem.Size = New System.Drawing.Size(169, 22) + Me.TreeViewToolStripMenuItem.Text = "treeView" + ' 'PictureBoxSearch ' Me.PictureBoxSearch.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _ @@ -528,12 +534,6 @@ Partial Class frmFlowForm ' Me.TimerDisplay.Interval = 60000 ' - 'TreeViewToolStripMenuItem - ' - Me.TreeViewToolStripMenuItem.Name = "TreeViewToolStripMenuItem" - Me.TreeViewToolStripMenuItem.Size = New System.Drawing.Size(180, 22) - Me.TreeViewToolStripMenuItem.Text = "treeView" - ' 'frmFlowForm ' Me.AllowDrop = True