Zooflow: Improve Search Form code
This commit is contained in:
190
GUIs.ZooFlow/Search/SearchRunner.vb
Normal file
190
GUIs.ZooFlow/Search/SearchRunner.vb
Normal file
@@ -0,0 +1,190 @@
|
||||
Imports DigitalData.GUIs.Common
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.ZooFlow
|
||||
|
||||
Public Class SearchRunner
|
||||
Inherits BaseClass
|
||||
|
||||
Private Const SEARCH_FACT_DATE_DEFAULT As String = "ADDED_WHEN"
|
||||
|
||||
Private Environment As Environment
|
||||
|
||||
Private Const CREATED_TOMORROW As String = "TOMORROW"
|
||||
Private Const CREATED_TODAY As String = "ECM_CREATED_TODAY"
|
||||
Private Const CREATED_YESTERDAY As String = "ECM_CREATED_YESTERDAY"
|
||||
Private Const CREATED_LAST_7_DAYS As String = "ECM_CREATED_LAST7DAYS"
|
||||
Private Const CREATED_YEAR_CURRENT As String = "ECM_CREATED_YEAR_CURRENT"
|
||||
Private Const CREATED_YEAR_LAST As String = "ECM_CREATED_YEAR_LAST"
|
||||
Private Const CREATED_MONTH_CURR As String = "ECM_CREATED_MONTH_CURRENT"
|
||||
Private Const CREATED_MONTH_LAST As String = "ECM_CREATED_MONTH_LAST"
|
||||
|
||||
Public Enum DateConstraint
|
||||
Today
|
||||
Tomorrow
|
||||
Yesterday
|
||||
Last7Days
|
||||
CurrentMonth
|
||||
LastMonth
|
||||
CurrentYear
|
||||
LastYear
|
||||
End Enum
|
||||
|
||||
Public Event NeedsRefresh As EventHandler(Of Integer)
|
||||
|
||||
Private _ActiveDateConstraint As String = CREATED_TODAY
|
||||
Public ReadOnly Property ActiveDateConstraint As String
|
||||
Get
|
||||
Return _ActiveDateConstraint
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Private _ActiveDateAttribute As String = SEARCH_FACT_DATE_DEFAULT
|
||||
Public ReadOnly Property ActiveDateAttribute As String
|
||||
Get
|
||||
Return _ActiveDateAttribute
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Property BaseSearchSQL As String
|
||||
Public Property ExplicitDate As Boolean = False
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pEnvironment As Environment)
|
||||
MyBase.New(pLogConfig)
|
||||
Environment = pEnvironment
|
||||
End Sub
|
||||
|
||||
Public Async Function Run(pSearchTerm As String, pDateFrom As Date, pDateTo As Date) As Threading.Tasks.Task(Of SearchResult)
|
||||
Dim oSearchTerm = pSearchTerm
|
||||
Dim oParams = New DocumentResultList.Params() With {
|
||||
.WindowGuid = "FlowSearch",
|
||||
.WindowTitle = GetResultWindowString(oSearchTerm),
|
||||
.OperationModeOverride = Modules.ZooFlow.Constants.OperationMode.ZooFlow,
|
||||
.ProfileGuid = 354522,
|
||||
.ColumnNames = New DocumentResultList.ColumnNames With {
|
||||
.ObjectIdColumn = "DocID"
|
||||
}
|
||||
}
|
||||
|
||||
Dim oP3 = $"{_ActiveDateAttribute}~{_ActiveDateConstraint}"
|
||||
|
||||
If ExplicitDate Then
|
||||
Dim oDate2 As Date
|
||||
If pDateTo.Equals(Date.MinValue) Then
|
||||
oDate2 = pDateTo
|
||||
Else
|
||||
oDate2 = pDateFrom
|
||||
End If
|
||||
Dim oProc = $"EXEC PRIDB_SEARCH_ADD_USR_DATE {My.Application.User.UserId},'{pDateFrom}','{oDate2}'"
|
||||
If Await My.Database.ExecuteNonQueryIDBAsync(oProc) = True Then
|
||||
oP3 = $"{_ActiveDateAttribute}~DATEPART"
|
||||
End If
|
||||
End If
|
||||
|
||||
Dim oSQL = $"EXEC PRIDB_SEARCH_TEXT_GET_RESULTS {My.Application.User.UserId},'{oSearchTerm}','{oP3}'"
|
||||
|
||||
If Await My.Database.ExecuteNonQueryIDBAsync(oSQL) = True Then
|
||||
Dim oDTDocResult = Await My.Database.GetDatatableIDBAsync(BaseSearchSQL)
|
||||
If oDTDocResult.Rows.Count > 0 Then
|
||||
oParams.Results.Add(New DocumentResultList.DocumentResult() With {
|
||||
.Title = "FlowSearchXYZ",
|
||||
.Datatable = oDTDocResult
|
||||
})
|
||||
Dim oForm As New frmDocumentResultList(My.LogConfig, Environment, oParams)
|
||||
|
||||
' TODO: Implement, not needed right now
|
||||
'AddHandler oForm.NeedsRefresh, AddressOf Form_NeedsRefresh
|
||||
|
||||
oForm.Show()
|
||||
|
||||
Return New SearchResult With {
|
||||
.OK = True
|
||||
}
|
||||
Else
|
||||
'bsiStatus.Caption = "No Results"
|
||||
Return New SearchResult With {
|
||||
.OK = False,
|
||||
.ErrorMessage = "No Results"
|
||||
}
|
||||
End If
|
||||
Else
|
||||
'bsiStatus.Caption = "Error in FlowSearch - Check Your log"
|
||||
Return New SearchResult With {
|
||||
.OK = False,
|
||||
.ErrorMessage = "Error in FlowSearch - Check Your log"
|
||||
}
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Private Function GetResultWindowString(SearchContent As String) As String
|
||||
If SearchContent <> String.Empty Then
|
||||
If My.Application.User.Language = State.UserState.LANG_DE_DE Then
|
||||
|
||||
Return $"Suche Nach '{SearchContent}'"
|
||||
Else
|
||||
Return $"Search For '{SearchContent}'"
|
||||
End If
|
||||
Else
|
||||
If My.Application.User.Language = State.UserState.LANG_DE_DE Then
|
||||
Return $"Suche Datumsbegrenzt"
|
||||
Else
|
||||
Return $"Search via date"
|
||||
End If
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Sub SetDateConstraint()
|
||||
_ActiveDateConstraint = String.Empty
|
||||
End Sub
|
||||
|
||||
Public Sub SetDateConstraint(pConstraintName As String)
|
||||
_ActiveDateConstraint = pConstraintName
|
||||
End Sub
|
||||
|
||||
Public Sub SetDateConstraint(pConstraint As DateConstraint)
|
||||
Select Case pConstraint
|
||||
Case DateConstraint.Today
|
||||
_ActiveDateConstraint = CREATED_TODAY
|
||||
|
||||
Case DateConstraint.Yesterday
|
||||
_ActiveDateConstraint = CREATED_YESTERDAY
|
||||
|
||||
Case DateConstraint.Tomorrow
|
||||
_ActiveDateConstraint = CREATED_TOMORROW
|
||||
|
||||
Case DateConstraint.Last7Days
|
||||
_ActiveDateConstraint = CREATED_LAST_7_DAYS
|
||||
|
||||
Case DateConstraint.CurrentMonth
|
||||
_ActiveDateConstraint = CREATED_MONTH_CURR
|
||||
|
||||
Case DateConstraint.LastMonth
|
||||
_ActiveDateConstraint = CREATED_MONTH_LAST
|
||||
|
||||
Case DateConstraint.CurrentYear
|
||||
_ActiveDateConstraint = CREATED_YEAR_CURRENT
|
||||
|
||||
Case DateConstraint.LastYear
|
||||
_ActiveDateConstraint = CREATED_YEAR_LAST
|
||||
|
||||
Case Else
|
||||
_ActiveDateAttribute = String.Empty
|
||||
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Public Sub SetDateAttribute(pAttributeName As String)
|
||||
_ActiveDateAttribute = pAttributeName
|
||||
End Sub
|
||||
|
||||
Public Sub SetDateAttribute()
|
||||
_ActiveDateAttribute = SEARCH_FACT_DATE_DEFAULT
|
||||
End Sub
|
||||
|
||||
Public Class SearchResult
|
||||
Public OK As Boolean
|
||||
Public ErrorMessage As String
|
||||
End Class
|
||||
End Class
|
||||
Reference in New Issue
Block a user