Modules/GUIs.ZooFlow/frmSearchStart.vb

231 lines
9.6 KiB
VB.net

Imports DigitalData.Modules.Logging
Imports DevExpress.XtraTab
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraEditors
Public Class frmSearchStart
Private Logger As Logger
Private DTSearchProfiles As DataTable
Private TabSelected As XtraTabPage
Private PSEARCH_ID As Integer = 0
Public FormShown As Boolean = False
Private Const DEFAULT_X As Integer = 10
Private Const DEFAULT_Y As Integer = 10
Private DTSearchTerms As DataTable
Private SEARCH_COUNT As Integer = 0
Public Sub New(pDTSearchProfiles As DataTable)
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
DTSearchProfiles = pDTSearchProfiles
Logger = My.LogConfig.GetLogger()
Dim oSearchTerms As New DataTable
' Create four typed columns in the DataTable.
oSearchTerms.Columns.Add("AttrID", GetType(Integer))
oSearchTerms.Columns.Add("AttrTitle", GetType(String))
oSearchTerms.Columns.Add("Criteria", GetType(String))
oSearchTerms.Columns.Add("SearchTerm", GetType(String))
DTSearchTerms = oSearchTerms
End Sub
Public Sub AddSearchAttribute(pAttrID As String, pAttrTitle As String, pSearchTerm As String, Optional pCriteria As String = "=")
DTSearchTerms.Rows.Add(pAttrID, pAttrTitle, pCriteria, pSearchTerm)
DTSearchTerms.AcceptChanges()
End Sub
Public Sub SearchAttribute(pAttrID As String, pAttrTitle As String, pSearchTerm As String, Optional pCriteria As String = "=")
DTSearchTerms.Rows.Add(pAttrID, pAttrTitle, pCriteria, pSearchTerm)
DTSearchTerms.AcceptChanges()
End Sub
Private Sub frmSearchStart_Load(sender As Object, e As EventArgs) Handles Me.Load
Try
Me.Panel1.Visible = False
For Each oTab As XtraTabPage In XtraTabControl1.TabPages
oTab.PageVisible = False
Next
If DTSearchProfiles.Rows.Count > 1 Then
cmbProfile.DataSource = DTSearchProfiles
cmbProfile.ValueMember = DTSearchProfiles.Columns("SEARCH_PROFILE_ID").ColumnName
cmbProfile.DisplayMember = DTSearchProfiles.Columns("TITLE").ColumnName
cmbProfile.AutoCompleteMode = AutoCompleteMode.Suggest
cmbProfile.AutoCompleteSource = AutoCompleteSource.ListItems
cmbProfile.SelectedIndex = -1
Me.Panel1.Visible = True
Else
TabSelected = XtraTabControl1.TabPages(0)
TabSelected.PageVisible = True
PSEARCH_ID = DTSearchProfiles.Rows(0).Item("SEARCH_PROFILE_ID")
TabSelected.Text = DTSearchProfiles.Rows(0).Item("TITLE")
Load_Search_Attributes()
BarButtonItemNewSearch.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
End If
SEARCH_COUNT = DTSearchProfiles.Rows.Count
Catch ex As Exception
Logger.Error(ex.Message)
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected error while loading ProfileSearches:")
End Try
End Sub
Sub Load_Search_Attributes()
Dim oSQL = $"SELECT * FROM VWIDB_SEARCH_PROFILE_ATTRIBUTES WHERE SEARCH_PROFIL_ID = {PSEARCH_ID} ORDER BY [SEQUENCE]"
Dim oDT As DataTable = My.Database_IDB.GetDatatable(oSQL)
Dim oXPosition As Integer = 10
Dim oYPosition As Integer = 10
Dim oControlXPosition As Integer = 33
Dim oControlCount As Integer = 1
Dim oControlRow As Integer = 0
Dim oControls As New ClassControlCreator(TabSelected, Me)
For Each oAttributeRow As DataRow In oDT.Rows
Dim oSingleResult As Boolean = False
Dim oAttriTitle As String = oAttributeRow.Item("ATTRIBUTE_TITLE").ToString
Dim oAttriID As String = oAttributeRow.Item("ATTRIBUTE_ID").ToString
Dim oAttriTYPE As String = oAttributeRow.Item("ATTRIBUTE_TYPE").ToString
If oControlCount = 1 Or oControlCount = 3 Or oControlCount = 5 Then
'linke Spalte
oControlRow += 1
End If
Select Case oControlCount
Case 2
oXPosition = oXPosition + 150 + 15
End Select
Select Case oControlRow
Case 1
oYPosition = DEFAULT_Y
If oControlCount > 1 Then
oXPosition = DEFAULT_X + 170
End If
Case 2
oYPosition = DEFAULT_Y + 150 + 20
If oControlCount = 4 Then
oXPosition = DEFAULT_X + 170
End If
End Select
addLabel(oAttriTitle, oXPosition, oYPosition)
Dim oMyControl As Control
Select Case oAttriTYPE
Case "VARCHAR"
oMyControl = oControls.CreateExistingGridControl(oAttributeRow, oXPosition, oYPosition + 20)
Dim myDGV As GridControl = CType(oMyControl, GridControl)
Dim omyDTSource As DataTable = CType(myDGV.DataSource, DataTable)
Dim oView As DevExpress.XtraGrid.Views.Grid.GridView
oView = CType(myDGV.MainView, GridView)
AddHandler oView.FocusedRowChanged, AddressOf FocusedRowChanged
If omyDTSource.Rows.Count = 1 Then
oSingleResult = True
AddSearchAttribute(oAttriID, oAttriTitle, omyDTSource.Rows(0).Item(oAttriTitle).ToString)
End If
Case "DATE"
oMyControl = oControls.CreateExistingDatepicker(oAttributeRow, oXPosition, oYPosition + 20)
Dim myDTP As DateEdit = CType(oMyControl, DateEdit)
AddHandler myDTP.DisableCalendarDate, AddressOf DisableCalendarDate
End Select
oControlCount += 1
TabSelected.Controls.Add(oMyControl)
Next
End Sub
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)
}
TabSelected.Controls.Add(lbl)
End Sub
Private Sub WindowsUIButtonPanel1_ButtonClick(sender As Object, e As DevExpress.XtraBars.Docking2010.ButtonEventArgs) Handles WindowsUIButtonPanel1.ButtonClick
Select Case e.Button.Properties.Tag.ToString
Case "Run"
RunSearch()
End Select
End Sub
Private Sub RunSearch()
Try
For Each oSearchTerm As DataRow In DTSearchTerms.Rows
Next
Catch ex As Exception
MsgBox("Unexpected Error in Clearing Search Items: " & ex.Message, MsgBoxStyle.Critical)
Logger.Error(ex)
End Try
End Sub
Private Sub XtraTabControl1_SelectedPageChanged(sender As Object, e As DevExpress.XtraTab.TabPageChangedEventArgs) Handles XtraTabControl1.SelectedPageChanged
TabSelected = XtraTabControl1.SelectedTabPage
End Sub
Private Sub FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs)
If FormShown = False Then Exit Sub
Dim oCurrentView As GridView = DirectCast(sender, GridView)
Dim oCurrentControl As GridControl = oCurrentView.GridControl
Dim rowView As DataRowView = CType(oCurrentView.GetFocusedRow(), DataRowView)
If IsNothing(rowView) = False Then
Dim oResult As String = CType(rowView.Item(0), String)
Dim oAttrID = DirectCast(oCurrentControl.Tag, ClassControlCreator.ControlMetadata).AttrID
Dim oAttrTitle = DirectCast(oCurrentControl.Tag, ClassControlCreator.ControlMetadata).AttrTitle
AddSearchAttribute(oAttrID, oAttrTitle, oResult)
' Return oResult
'Else : Return Nothing
End If
End Sub
Private Sub frmSearchStart_Shown(sender As Object, e As EventArgs) Handles Me.Shown
FormShown = 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
'If (e.Date.DayOfWeek = DayOfWeek.Wednesday) Then
' e.IsDisabled = True
'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 Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
Try
DTSearchTerms.Clear()
Catch ex As Exception
MsgBox("Unexpected Error in Clearing Search Items: " & ex.Message, MsgBoxStyle.Critical)
End Try
For Each oControl As Control In TabSelected.Controls
Select Case oControl.GetType.ToString
Case ""
End Select
Next
End Sub
End Class