MS SearchForm Dev

This commit is contained in:
2020-08-21 11:34:35 +02:00
parent 50d82dc1fd
commit d96882ce77
8 changed files with 334 additions and 156 deletions

View File

@@ -1,13 +1,19 @@
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 FormLoaded As Boolean = False
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.
@@ -16,11 +22,28 @@ Public Class frmSearchStart
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
DTSearchProfiles = pDTSearchProfiles
Logger = My.LogConfig.GetLogger()
End Sub
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
Private Sub WindowsUIButtonPanel1_Click(sender As Object, e As EventArgs) Handles WindowsUIButtonPanel1.Click
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
@@ -42,13 +65,14 @@ Public Class frmSearchStart
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
FormLoaded = True
End Sub
Sub Load_Search_Attributes()
Dim oSQL = $"SELECT * FROM VWIDB_SEARCH_PROFILE_ATTRIBUTES WHERE SEARCH_PROFIL_ID = {PSEARCH_ID} ORDER BY [SEQUENCE]"
@@ -60,7 +84,8 @@ Public Class frmSearchStart
Dim oControlRow As Integer = 0
Dim oControls As New ClassControlCreator(TabSelected, Me)
For Each oAttributeRow As DataRow In oDT.Rows
Dim oAttriName As String = oAttributeRow.Item("ATTRIBUTE_TITLE").ToString
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
@@ -69,7 +94,7 @@ Public Class frmSearchStart
End If
Select Case oControlCount
Case 2
oXPosition = oXPosition + 150 + 20
oXPosition = oXPosition + 150 + 15
End Select
Select Case oControlRow
Case 1
@@ -85,21 +110,32 @@ Public Class frmSearchStart
End Select
addLabel(oAttriName, oXPosition, oYPosition)
addLabel(oAttriTitle, oXPosition, oYPosition)
Dim oMyControl As Control
Select Case oAttriTYPE
Case "VARCHAR"
oMyControl = oControls.CreateExistingGridControl(oAttributeRow, oXPosition, oYPosition + 25)
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)
oControlCount += 1
Next
End Sub
Sub addLabel(pAttrName As String, pXPos As Integer, ylbl As Integer)
@@ -115,11 +151,81 @@ Public Class frmSearchStart
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"
MsgBox("Start Search")
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