253 lines
8.3 KiB
VB.net
253 lines
8.3 KiB
VB.net
Imports DigitalData.GUIs.Common
|
|
Imports DigitalData.Modules.Base
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.ZooFlow
|
|
Imports System.Threading.Tasks
|
|
|
|
Public Class SearchRunner
|
|
Inherits BaseClass
|
|
|
|
Private Const SEARCH_FACT_DATE_DEFAULT As String = "ADDED_WHEN"
|
|
|
|
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)
|
|
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 _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
|
|
|
|
Private ReadOnly Environment As Environment
|
|
Private ReadOnly SearchTitle As String
|
|
|
|
Public Sub New(pLogConfig As LogConfig, pEnvironment As Environment, pSearchTitle As String)
|
|
MyBase.New(pLogConfig)
|
|
Environment = pEnvironment
|
|
SearchTitle = pSearchTitle
|
|
End Sub
|
|
|
|
Public Function Run(pDatatable As DataTable) As SearchResult
|
|
Return Run(pDatatable, "Suche")
|
|
End Function
|
|
|
|
Public Function Run(pDatatable As DataTable, pTitle As String) As SearchResult
|
|
Dim oParams = GetParams(pTitle)
|
|
oParams.Results.Add(New DocumentResultList.DocumentResult() With {
|
|
.Title = pTitle,
|
|
.Datatable = pDatatable
|
|
})
|
|
|
|
If pDatatable.Rows.Count = 1 Then
|
|
oParams.ShowFileList = False
|
|
End If
|
|
|
|
Dim oForm As New frmDocumentResultList(My.LogConfig, Environment, oParams)
|
|
|
|
' TODO: Implement, not needed right now
|
|
'AddHandler oForm.NeedsRefresh, AddressOf Form_NeedsRefresh
|
|
AddHandler oForm.FormClosed, AddressOf Form_Closed
|
|
|
|
oForm.Show()
|
|
|
|
Return New SearchResult()
|
|
End Function
|
|
|
|
Public Async Function Run(pSearchTerm As String) As Task(Of SearchResult)
|
|
Dim oWindowTitle = GetResultWindowString(pSearchTerm)
|
|
Return Await Run(pSearchTerm, Nothing, Nothing)
|
|
End Function
|
|
|
|
|
|
Public Async Function Run(pSearchTerm As String, pDateFrom As Date, pDateTo As Date) As Threading.Tasks.Task(Of SearchResult)
|
|
If pDateFrom.Equals(Date.MinValue) = False Then
|
|
ExplicitDate = True
|
|
End If
|
|
|
|
Dim oSearchTerm = pSearchTerm
|
|
Dim oWindowTitle = GetResultWindowString(pSearchTerm)
|
|
Dim oParams = GetParams(oWindowTitle)
|
|
Dim oDateConstraint = $"{_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
|
|
oDateConstraint = $"{_ActiveDateAttribute}~DATEPART"
|
|
End If
|
|
End If
|
|
|
|
Dim oSQL = $"EXEC PRIDB_SEARCH_TEXT_GET_RESULTS {My.Application.User.UserId},'{oSearchTerm}','{oDateConstraint}'"
|
|
|
|
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 = SearchTitle,
|
|
.Datatable = oDTDocResult
|
|
})
|
|
|
|
If oDTDocResult.Rows.Count = 1 Then
|
|
oParams.ShowFileList = False
|
|
End If
|
|
|
|
Dim oForm As New frmDocumentResultList(My.LogConfig, Environment, oParams)
|
|
|
|
' TODO: Implement, not needed right now
|
|
'AddHandler oForm.NeedsRefresh, AddressOf Form_NeedsRefresh
|
|
AddHandler oForm.FormClosed, AddressOf Form_Closed
|
|
|
|
oForm.Show()
|
|
|
|
Return New SearchResult()
|
|
Else
|
|
Return New SearchResult("No Results")
|
|
|
|
End If
|
|
Else
|
|
Return New SearchResult("Error in FlowSearch - Check Your log")
|
|
|
|
End If
|
|
End Function
|
|
|
|
Private Sub Form_Closed(sender As Object, e As EventArgs)
|
|
RaiseEvent Closed(sender, 0)
|
|
End Sub
|
|
|
|
Private Function GetParams(pWindowTitle As String) As DocumentResultList.Params
|
|
Dim oParams = New DocumentResultList.Params() With {
|
|
.WindowGuid = SearchTitle,
|
|
.WindowTitle = pWindowTitle,
|
|
.OperationModeOverride = Modules.ZooFlow.Constants.OperationMode.ZooFlow,
|
|
.ProfileGuid = 35452,
|
|
.ColumnNames = New DocumentResultList.ColumnNames With {
|
|
.ObjectIdColumn = "DocID"
|
|
},
|
|
.ShowBackNavigation = False
|
|
}
|
|
Return oParams
|
|
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 = String.Empty
|
|
|
|
''' <summary>
|
|
''' Returns a positive Search Result
|
|
''' </summary>
|
|
Public Sub New()
|
|
OK = True
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' Returns a failed search result with an error message
|
|
''' </summary>
|
|
''' <param name="pMessage"></param>
|
|
Public Sub New(pMessage As String)
|
|
OK = False
|
|
ErrorMessage = pMessage
|
|
End Sub
|
|
End Class
|
|
End Class
|