Modules/GUIs.ZooFlow/frmSearchStart.vb

671 lines
30 KiB
VB.net

Option Explicit On
Imports DigitalData.Modules.Logging
Imports DevExpress.XtraTab
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraEditors
Imports DevExpress.XtraSplashScreen
Imports DigitalData.GUIs.Common
Imports System.Threading.Tasks
Public Class frmSearchStart
Private Logger As Logger
Private Const DEFAULT_X As Integer = 10
Private Const DEFAULT_Y As Integer = 10
Private SelectedTabIndex As Integer
Private SelectedTab As XtraTabPage
Private SEARCH_ID As Integer = 0
Private SEARCH_SQL As String
Private SEARCH_TITLE As String
Private SEARCH_COUNT As Integer = 0
Public DataLoaded As Boolean = False
Private DatatableAttributes As DataTable
Private DatatableSearchProfiles As DataTable
Private LastSearchForm As frmDocumentResultList
Private ChangedDateControls As List(Of String)
Public Sub New(ByVal pDTSearchProfiles As DataTable, Optional ByVal pRunSearch As Boolean = False)
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
DatatableSearchProfiles = pDTSearchProfiles
Logger = My.LogConfig.GetLogger()
Dim oSearchTerms As New DataTable
' Create four typed columns in the DataTable.
oSearchTerms.Columns.Add("BracketLeft", GetType(String))
oSearchTerms.Columns.Add("AttrID", GetType(Integer))
oSearchTerms.Columns.Add("AttrTitle", GetType(String))
oSearchTerms.Columns.Add("Criteria", GetType(String))
oSearchTerms.Columns.Add("SearchTerm", GetType(String))
oSearchTerms.Columns.Add("BracketRight", GetType(String))
oSearchTerms.Columns.Add("Operator", GetType(String))
End Sub
Private Async Sub frmSearchStart_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim oHandle As IOverlaySplashScreenHandle = Nothing
Try
oHandle = SplashScreenManager.ShowOverlayForm(Me)
pnlProfileChoose.Visible = False
For Each oTab As XtraTabPage In XtraTabControl1.TabPages
oTab.PageVisible = False
Next
RepositoryItemComboBox2.Items.AddRange(New List(Of FilterTimeframe) From {
New FilterTimeframe() With {.Name = "Kein", .DisableFilter = True},
New FilterTimeframe() With {.Name = "Eigener", .CustomFilter = True},
New FilterTimeframe() With {
.Name = "letzte 7 Tage",
.From = Date.Now.Subtract(TimeSpan.FromDays(7)),
.[To] = Date.Now
},
New FilterTimeframe() With {
.Name = "letzte 14 Tage",
.From = Date.Now.Subtract(TimeSpan.FromDays(14)),
.[To] = Date.Now
},
New FilterTimeframe() With {
.Name = "letzte 30 Tage",
.From = Date.Now.Subtract(TimeSpan.FromDays(30)),
.[To] = Date.Now
}
})
BarCheckboxOpenSearchInSameWindow.Checked = My.UIConfig.SearchForm.OpenSearchInSameWindow
If DatatableSearchProfiles.Rows.Count > 1 Then
cmbProfile.DataSource = DatatableSearchProfiles
cmbProfile.ValueMember = DatatableSearchProfiles.Columns("SEARCH_PROFILE_ID").ColumnName
cmbProfile.DisplayMember = DatatableSearchProfiles.Columns("TITLE").ColumnName
cmbProfile.AutoCompleteMode = AutoCompleteMode.Suggest
cmbProfile.AutoCompleteSource = AutoCompleteSource.ListItems
cmbProfile.SelectedIndex = -1
SelectedTabIndex = -1
pnlProfileChoose.Visible = True
For Each oRow As DataRow In DatatableSearchProfiles.Rows
RepositoryItemComboBox1.Items.Add(oRow.Item("TITLE"))
Next
Else
pnlProfileChoose.Visible = False
RibbonPageGroupProfiles.Visible = False
SelectedTabIndex = 0
SelectedTab = XtraTabControl1.TabPages.First
SelectedTab.PageVisible = True
SelectedTab.Text = DatatableSearchProfiles.Rows(0).Item("TITLE")
SEARCH_ID = DatatableSearchProfiles.Rows(0).Item("SEARCH_PROFILE_ID")
SEARCH_SQL = DatatableSearchProfiles.Rows(0).Item("RESULT_SQL")
SEARCH_TITLE = DatatableSearchProfiles.Rows(0).Item("TITLE")
Await Load_Search_Attributes()
BarButtonNewSearch.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
End If
SEARCH_COUNT = DatatableSearchProfiles.Rows.Count
SplitContainerControlSearch.Collapsed = True
If My.UIConfig.SearchForm.Size.Height > 0 And My.UIConfig.SearchForm.Size.Width > 0 Then
Size = My.UIConfig.SearchForm.Size
End If
If My.UIConfig.SearchForm.Location.X > 0 And My.UIConfig.SearchForm.Location.Y > 0 Then
Location = My.UIConfig.SearchForm.Location
End If
Catch ex As Exception
Logger.Error(ex.Message)
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected error while loading ProfileSearches:")
Finally
SplashScreenManager.CloseOverlayForm(oHandle)
End Try
End Sub
Async Function Load_Search_Attributes() As Task
Try
DataLoaded = False
Dim oSQL = $"SELECT * FROM VWIDB_SEARCH_PROFILE_ATTRIBUTES WHERE SEARCH_PROFIL_ID = {SEARCH_ID} ORDER BY [SEQUENCE]"
Dim oDT As DataTable = Await My.DatabaseIDB.GetDatatableAsync(oSQL)
DatatableAttributes = Nothing
DatatableAttributes = oDT.Clone()
oDT.Select("", "SEQUENCE").CopyToDataTable(DatatableAttributes, LoadOption.PreserveChanges)
Dim oControlCount As Integer = 1
Dim oControlRow As Integer = 0
Dim oControls As New ClassControlCreator(SelectedTab, Me)
Dim YMax As Integer = 0
Dim YActControlHeight As Integer = 0
Dim XActControlWidth As Integer = 0
Dim iList As New List(Of Integer) From {2, 3, 5, 6, 8, 9}
For Each oAttributeRow As DataRow In oDT.Rows
Dim oXPosition As Integer
Dim oYPositionControl As Integer
Dim oYPositionLabel As Integer
Dim oMyLastGridView As GridView
Dim oSingleResult As Boolean = False
Dim oAttriTitle As String = oAttributeRow.Item("ATTRIBUTE_TITLE").ToString
Dim oAttriID As Integer = CInt(oAttributeRow.Item("ATTRIBUTE_ID"))
Dim oAttributeType As String = oAttributeRow.Item("ATTRIBUTE_TYPE").ToString
If oControlCount = 1 Or oControlCount = 5 Or oControlCount = 9 Then
oControlRow += 1
End If
If oControlRow = 1 Then
If oControlCount = 1 Then
oXPosition = 10
oYPositionLabel = 10
oYPositionControl = oYPositionLabel + 20
End If
ElseIf oControlRow = 2 Then
If oControlCount = 5 Then
oXPosition = 10
oYPositionLabel = YActControlHeight + 10
oYPositionControl = oYPositionLabel + 20
End If
ElseIf oControlRow = 3 Then
If oControlCount = 9 Then
oXPosition = 10
End If
End If
Dim oControlHeight As Integer = CInt(oAttributeRow.Item("HEIGHT"))
Dim oControlWidth As Integer = CInt(oAttributeRow.Item("WIDTH"))
If CBool(oAttributeRow.Item("MULTISELECT")) = True Then
oControlWidth += 50
End If
addLabel(oAttriTitle, oXPosition, oYPositionLabel)
'Nun das Control mit dem entsprechenden Abstand und der Größe
Dim oCalcHeight As Integer
Dim oCalcWidth As Integer
If oAttributeType = "VARCHAR" Or oAttributeType = "BIG INTEGER" Then
oCalcHeight = oControlHeight + oYPositionControl
oCalcWidth = oControlWidth
ElseIf (oAttributeType = "DATE" Or oAttributeType = "BIT") Then
oCalcHeight = 20 + oYPositionControl
oCalcWidth = 100
End If
If oCalcHeight > YActControlHeight Then
YActControlHeight = oCalcHeight
End If
Dim oMyControl As Control = Nothing
If oAttributeType = "VARCHAR" Or oAttributeType = "BIG INTEGER" Then
oMyControl = oControls.CreateExistingGridControl(oAttributeRow, oXPosition, oYPositionControl)
Dim myDGV As GridControl = CType(oMyControl, GridControl)
Dim omyDTSource As DataTable = CType(myDGV.DataSource, DataTable)
If Not IsNothing(omyDTSource) Then
If omyDTSource.Rows.Count = 1 Then
oSingleResult = True
' AddSearchAttribute(oAttriID, oAttriTitle, omyDTSource.Rows(0).Item(oAttriTitle).ToString)
End If
End If
Dim oView As DevExpress.XtraGrid.Views.Grid.GridView
oView = CType(myDGV.MainView, GridView)
oMyLastGridView = oView
If CBool(oAttributeRow.Item("MULTISELECT")) = True Then
'AddHandler oView.SelectionChanged, AddressOf RenewSearchAttributes
Else
' AddHandler oView.FocusedRowChanged, AddressOf FocusedRowChanged
End If
oView.FocusInvalidRow()
ElseIf oAttributeType = "DATE" Then
oMyControl = oControls.CreateExistingDatepicker(oAttributeRow, oXPosition, oYPositionControl)
Dim myDTP As DateEdit = CType(oMyControl, DateEdit)
AddHandler myDTP.DisableCalendarDate, AddressOf DisableCalendarDate
AddHandler myDTP.DateTimeChanged, AddressOf CalendarChanged 'CalendarChanged
ElseIf oAttributeType = "BIT" Then
oMyControl = oControls.CreateExistingCheckbox(oAttributeRow, oXPosition, oYPositionControl)
Dim myCheckBox As CheckBox = CType(oMyControl, CheckBox)
AddHandler myCheckBox.CheckedChanged, AddressOf CheckBox_CheckedChanged
End If
oControlCount += 1
If oMyControl IsNot Nothing Then
SelectedTab.Controls.Add(oMyControl)
End If
If oAttributeType = "VARCHAR" Or oAttributeType = "BIG INTEGER" Then
oMyLastGridView.FocusInvalidRow()
End If
oXPosition += oControlWidth + 20
Next
Catch ex As Exception
Logger.Warn("Unexpected error in Load_Search_Attributes - Error: " & ex.Message)
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected error in Load_Search_Attributes:")
Finally
DataLoaded = True
End Try
End Function
Sub addLabel(pAttrName As String, pXPos As Integer, ylbl As Integer)
Dim lbl As New Label With {
.Name = "lbl" & pAttrName,
.AutoSize = True,
.Text = pAttrName,
.Location = New Point(pXPos, ylbl)
}
SelectedTab.Controls.Add(lbl)
End Sub
Private Sub XtraTabControl1_SelectedPageChanged(sender As Object, e As DevExpress.XtraTab.TabPageChangedEventArgs) Handles XtraTabControl1.SelectedPageChanged
SelectedTab = XtraTabControl1.SelectedTabPage
End Sub
Private Sub ClearSearchCriteria()
Dim oSQL = $"DELETE FROM TBIDB_USER_SEARCH_CRITERIA WHERE SEARCH_PROFIL_ID = {SEARCH_ID} AND USERID = {My.Application.User.UserId}"
My.DatabaseIDB.ExecuteNonQuery(oSQL)
End Sub
Private Sub ClearSelectedControls()
ChangedDateControls = Nothing
End Sub
Private Sub RenewSearchAttributes()
ClearSearchCriteria()
For Each oControl As Control In SelectedTab.Controls
Dim octrlType = oControl.GetType.ToString
Dim oAttrID As Integer
Dim oAttrTitle As String
Select Case oControl.GetType.ToString
Case "DevExpress.XtraGrid.GridControl"
Dim oMyGridControl As GridControl = CType(oControl, GridControl)
Dim oMyGridView As DevExpress.XtraGrid.Views.Grid.GridView = CType(oMyGridControl.MainView, GridView)
Dim oSelectedRows As Integer() = oMyGridView.GetSelectedRows()
If oSelectedRows.Count = 0 Then
Continue For
End If
oAttrID = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).AttrID
oAttrTitle = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).AttrTitle
For Each oRowHandle As Integer In oSelectedRows
Dim oResult = oMyGridView.GetRowCellValue(oRowHandle, oMyGridView.Columns(0).FieldName)
Dim oInsert = $"EXEC PRIDB_NEW_USER_SEARCH_CRITERIA {SEARCH_ID.ToString},{My.Application.User.UserId.ToString},{oAttrID.ToString},'{oResult}','{My.Application.User.UserName}'"
My.DatabaseIDB.ExecuteNonQuery(oInsert)
Next
Case "DevExpress.XtraEditors.DateEdit"
' MsgBox("Date")
Dim oDateEdit As DateEdit = CType(oControl, DateEdit)
If ChangedDateControls Is Nothing Then
Continue For
End If
If ChangedDateControls.Count = 0 Then
Continue For
End If
For Each oName As String In ChangedDateControls
If oDateEdit.Name = oName Then
If Not IsNothing(oDateEdit.EditValue) Then
oAttrID = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).AttrID
oAttrTitle = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).AttrTitle
Dim oldValue As Date
Dim validDate As Boolean = False
Dim oDateValue As Date = DirectCast(oDateEdit.EditValue, Date)
Try
validDate = Date.TryParse(oDateEdit.OldEditValue, oldValue)
Catch ex As Exception
oldValue = Date.MinValue
End Try
If Not validDate Then
oldValue = Date.MinValue
End If
If oldValue = oDateEdit.EditValue Then
Exit Sub
End If
Dim dateString = oDateValue.ToString("yyyy-MM-dd") 'hh:mm:ss.fff
Dim omydate = oDateEdit.EditValue.ToString
Dim oInsert = $"EXEC PRIDB_NEW_USER_SEARCH_CRITERIA {SEARCH_ID.ToString},{My.Application.User.UserId.ToString},{oAttrID.ToString},'{omydate}','{My.Application.User.UserName}'"
My.DatabaseIDB.ExecuteNonQuery(oInsert)
End If
End If
Next
Case "System.Windows.Forms.CheckBox"
Dim myCheckBox As CheckBox = CType(oControl, CheckBox)
If myCheckBox.CheckState <> CheckState.Indeterminate Then
oAttrID = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).AttrID
oAttrTitle = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).AttrTitle
Dim oInsert = $"EXEC PRIDB_NEW_USER_SEARCH_CRITERIA {SEARCH_ID.ToString},{My.Application.User.UserId.ToString},{oAttrID.ToString},'{myCheckBox.Checked.ToString}','{My.Application.User.UserName}'"
My.DatabaseIDB.ExecuteNonQuery(oInsert)
End If
Case Else
'MsgBox(oControl.GetType.ToString)
End Select
Next
End Sub
Private Sub FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs)
If DataLoaded = False Then Exit Sub
Dim oCurrentView As GridView = DirectCast(sender, GridView)
Dim oCurrentControl As GridControl = oCurrentView.GridControl
Dim oRowView As DataRowView = CType(oCurrentView.GetFocusedRow(), DataRowView)
If IsNothing(oRowView) = False Then
Dim oResult As String = CType(oRowView.Item(0), String)
Dim oAttrID = DirectCast(oCurrentControl.Tag, ClassControlCreator.ControlMetadata).AttrID
Dim oAttrTitle = DirectCast(oCurrentControl.Tag, ClassControlCreator.ControlMetadata).AttrTitle
' RenewSearchAttributes()
' AddSearchAttribute(oAttrID, oAttrTitle, oResult)
End If
End Sub
Private Sub CheckBox_CheckedChanged(sender As Object, e As EventArgs)
If DataLoaded = False Then Exit Sub
Dim oCurrentCB As CheckBox = DirectCast(sender, CheckBox)
Dim oChecked = oCurrentCB.Checked
Dim oAttrID = DirectCast(oCurrentCB.Tag, ClassControlCreator.ControlMetadata).AttrID
Dim oAttrTitle = DirectCast(oCurrentCB.Tag, ClassControlCreator.ControlMetadata).AttrTitle
'RenewSearchAttributes()
' AddSearchAttribute(oAttrID, oAttrTitle, oChecked.ToString)
End Sub
Private Sub frmSearchStart_Shown(sender As Object, e As EventArgs) Handles Me.Shown
DataLoaded = True
End Sub
Private Sub DisableCalendarDate(sender As Object, e As DevExpress.XtraEditors.Calendar.DisableCalendarDateEventArgs)
Dim oDateEdit As DateEdit = DirectCast(sender, DateEdit)
Dim oDTSource As DataTable = DirectCast(oDateEdit.Tag, ClassControlCreator.ControlMetadata).DTSource
If Not IsNothing(oDTSource) Then
If IsValidDate(oDTSource, e.Date) = False Then
e.IsDisabled = True
End If
End If
End Sub
Private Sub CalendarChanged(sender As Object, e As EventArgs)
If DataLoaded = False Then Exit Sub
Dim oDateEdit As DateEdit = CType(sender, DateEdit)
If Not IsNothing(oDateEdit.EditValue) Then
Dim oEditValue = oDateEdit.EditValue.ToString
Dim oList As New List(Of String) From {oDateEdit.Name}
If Not IsNothing(ChangedDateControls) Then
Dim oFound As Boolean = False
For Each oName As String In ChangedDateControls
If oDateEdit.Name = oName Then
oFound = True
Exit For
End If
Next
If oFound = False Then
ChangedDateControls.Add(oDateEdit.Name)
End If
Else
ChangedDateControls = oList
End If
End If
End Sub
Public Function IsValidDate(pCheckDT As DataTable, pDate2Check As Date) As Boolean
Dim oIsValid As Boolean = False
For Each oDateRow As DataRow In pCheckDT.Rows
If CDate(oDateRow.Item(0)) = pDate2Check Then
oIsValid = True
End If
Next
Return oIsValid
End Function
Private Async Sub BarButtonClearSearch_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonClearSearch.ItemClick
Try
ClearSearchCriteria()
ClearSelectedControls()
Catch ex As Exception
MsgBox("Unexpected Error in Clearing Search Items: " & ex.Message, MsgBoxStyle.Critical)
End Try
SelectedTab.Controls.Clear()
Await Load_Search_Attributes()
End Sub
Private Async Sub cmbProfile_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbProfile.SelectedIndexChanged
If DataLoaded = False Then Exit Sub
If cmbProfile.SelectedIndex <> -1 Then
If SelectedTabIndex = -1 Then
SelectedTabIndex = 0
Else
SelectedTabIndex += 1
End If
SelectedTab = XtraTabControl1.TabPages(SelectedTabIndex)
SelectedTab.PageVisible = True
SEARCH_ID = cmbProfile.SelectedValue
Dim oDT As New DataTable
Dim oFilter As String = $"SEARCH_PROFILE_ID = {SEARCH_ID}"
Dim oFilteredRows() As DataRow = DatatableSearchProfiles.Select(oFilter)
oDT = DatatableSearchProfiles.Clone
For Each oRow As DataRow In oFilteredRows
SEARCH_SQL = oRow.Item("RESULT_SQL").ToString
SEARCH_TITLE = cmbProfile.Text
Next
SelectedTab.Text = SEARCH_TITLE
Await Load_Search_Attributes()
BarButtonNewSearch.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
XtraTabControl1.SelectedTabPageIndex = SelectedTabIndex
End If
End Sub
Private Sub BarButtonNewSearch_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonNewSearch.ItemClick
Display_InfoItem("New Search not integrated", Color.Yellow)
End Sub
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonSaveSearch.ItemClick
Display_InfoItem("Search Save not integrated", Color.Yellow)
End Sub
Sub Display_InfoItem(pText As String, pBackColor As Color)
Display_InfoItem(pText, pBackColor, Color.Black)
End Sub
Sub Display_InfoItem(pText As String, pBackColor As Color, pForeColor As Color)
BarStaticItemInfo.Caption = pText
BarStaticItemInfo.ItemAppearance.Normal.BackColor = pBackColor
BarStaticItemInfo.ItemAppearance.Normal.ForeColor = pForeColor
End Sub
Sub Clear_InfoItem()
BarStaticItemInfo.Caption = String.Empty
BarStaticItemInfo.ItemAppearance.Normal.BackColor = Color.Transparent
End Sub
Private Sub GridViewSearchTerms_RowDeleted(sender As Object, e As DevExpress.Data.RowDeletedEventArgs)
If DataLoaded = False Then Exit Sub
Dim oCurrentView As GridView = DirectCast(sender, GridView)
Dim oCurrentControl As GridControl = oCurrentView.GridControl
Dim oRowView As DataRowView = CType(oCurrentView.GetFocusedRow(), DataRowView)
If IsNothing(oRowView) = False Then
Dim oResult As String = CType(oRowView.Item(0), String)
Dim oAttrID = DirectCast(oCurrentControl.Tag, ClassControlCreator.ControlMetadata).AttrID
Dim oAttrTitle = DirectCast(oCurrentControl.Tag, ClassControlCreator.ControlMetadata).AttrTitle
End If
End Sub
Private Sub frmSearchStart_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
My.UIConfig.SearchForm.Location = Me.Location
My.UIConfigManager.Save()
End Sub
Private Function GetSearchTermForType(pAttrID As Int16, pAttrTitle As String, pCriteria As String, pTerm As String) As String
Dim oSearchTerm As String = ""
Dim oFilter As String = $"GUID = {pAttrID}"
Dim oFilteredRows() As DataRow = My.DTAttributes.Select(oFilter)
If oFilteredRows.Length = 1 Then
For Each oRow As DataRow In oFilteredRows
Dim oType As Integer = DirectCast(oRow.Item("TYP_ID"), Integer)
If oType = 1 Or oType = 8 Then
oSearchTerm = $"{pAttrTitle} {pCriteria} '{pTerm.Replace("'", "''")}'"
ElseIf oType = 2 Or oType = 9 Then
oSearchTerm = $"{pAttrTitle} {pCriteria} {pTerm}"
ElseIf oType = 3 Then 'Float
oSearchTerm = $"{pAttrTitle} {pCriteria} Convert(float,'{pTerm.Replace(",", ".")}')"
ElseIf oType = 4 Then 'Decimal
oSearchTerm = $"{pAttrTitle} {pCriteria} Convert(decimal(19,2),'{pTerm.Replace(",", ".")}')"
ElseIf oType = 5 Then 'DATE
oSearchTerm = $"{pAttrTitle} {pCriteria} Convert(date,'{pTerm}')"
ElseIf oType = 7 Then
Dim oBit As Int16
If CBool(pTerm) = True Then
oBit = 1
Else
oBit = 0
End If
oSearchTerm = $"{pAttrTitle} {pCriteria} '{oBit.ToString}'"
End If
Next
End If
Return oSearchTerm
End Function
Private Sub BarButtonStartSearch_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonStartSearch.ItemClick
RenewSearchAttributes()
Start_Search()
End Sub
Private Sub Start_Search()
Dim oHandle As IOverlaySplashScreenHandle = Nothing
Try
oHandle = SplashScreenManager.ShowOverlayForm(Me)
Clear_InfoItem()
Dim oSearchSQL = SEARCH_SQL
oSearchSQL = oSearchSQL.Replace("@UserID", My.Application.User.UserId.ToString)
oSearchSQL = oSearchSQL.Replace("@User_ID", My.Application.User.UserId.ToString)
oSearchSQL = oSearchSQL.Replace("@UserName", My.Application.User.UserName)
oSearchSQL = oSearchSQL.Replace("@SearchID", SEARCH_ID.ToString)
Dim oEnvironment As New Modules.ZooFlow.Environment() With {
.User = My.Application.User,
.Modules = My.Application.Modules,
.Database = My.Database,
.DatabaseIDB = My.DatabaseIDB,
.Settings = My.Application.Settings
}
Dim oDTSearchResult As DataTable = My.DatabaseIDB.GetDatatable(oSearchSQL)
If oDTSearchResult.Rows.Count > 0 Then
Dim oShortGuid = Guid.NewGuid()
Dim oWindowGuid = $"{SEARCH_ID.ToString}-{My.User.Name}"
Dim oParams = New DocumentResultParams() With {
.IsIDBResult = True,
.WindowGuid = oWindowGuid,
.Results = New List(Of DocumentResult) From {
New DocumentResult() With {
.Title = SelectedTab.Text,
.Datatable = oDTSearchResult
}
}
}
If My.UIConfig.SearchForm.OpenSearchInSameWindow And LastSearchForm IsNot Nothing Then
LastSearchForm.RefreshResults(oParams.Results)
Else
Dim oForm As New frmDocumentResultList(My.LogConfig, oEnvironment, oParams)
oForm.Show()
' Position Result Window below this window
oForm.Location = GetResultFormLocation()
oForm.Size = GetResultFormSize()
AddHandler oForm.FormClosed, Sub()
LastSearchForm = Nothing
End Sub
LastSearchForm = oForm
End If
Else
Display_InfoItem("No results for this searchcombination!", Color.OrangeRed, Color.White)
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
Finally
SplashScreenManager.CloseOverlayForm(oHandle)
End Try
End Sub
Private Function GetResultFormLocation() As Point
Dim oX = Location.X
Dim oY = Location.Y + Size.Height
Return New Point(oX, oY)
End Function
Private Function GetResultFormSize() As Size
Dim oWidth = Size.Width
' TODO: Smarter height calculation, maybe depending on screen height and parent form location
Dim oHeight = 400
Return New Size(oWidth, oHeight)
End Function
Private Sub frmSearchStart_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.F2 Then
Start_Search()
End If
End Sub
Private Class FilterTimeframe
Public Property Name As String
Public Property From As Date
Public Property [To] As Date
Public Property DisableFilter As Boolean = False
Public Property CustomFilter As Boolean = False
Public Overrides Function ToString() As String
Return Name.ToString
End Function
End Class
Private Sub cmbFilterTimeframe_EditValueChanged(sender As Object, e As EventArgs) Handles cmbFilterTimeframe.EditValueChanged
Dim oTimeframe As FilterTimeframe = DirectCast(cmbFilterTimeframe.EditValue, FilterTimeframe)
If oTimeframe.DisableFilter Then
txtFilterFrom.Enabled = False
txtFilterFrom.Reset()
txtFilterTo.Enabled = False
txtFilterTo.Reset()
Else
txtFilterFrom.Enabled = True
txtFilterFrom.EditValue = oTimeframe.From
txtFilterTo.Enabled = True
txtFilterTo.EditValue = oTimeframe.[To]
End If
End Sub
Private Sub BarCheckboxOpenSearchInSameWindow_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarCheckboxOpenSearchInSameWindow.CheckedChanged
My.UIConfig.SearchForm.OpenSearchInSameWindow = BarCheckboxOpenSearchInSameWindow.Checked
My.UIConfigManager.Save()
End Sub
Private Sub frmSearchStart_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd
My.UIConfig.SearchForm.Location = Location
My.UIConfig.SearchForm.Size = Size
My.UIConfigManager.Save()
End Sub
End Class