237 lines
10 KiB
VB.net
237 lines
10 KiB
VB.net
Imports System.IO
|
|
Imports DevExpress.XtraTab
|
|
Imports DevExpress.XtraGrid
|
|
Imports DevExpress.XtraGrid.Views.Grid
|
|
Imports DevExpress.XtraGrid.Views.Base
|
|
Imports DD_LIB_Standards
|
|
Imports DD_Clipboard_Watcher.ClassProfileFilter
|
|
|
|
Public Class frmResultSQL
|
|
Implements IResultForm
|
|
|
|
Private Shared BW_DocPath As String
|
|
Private Shared BW_DocID As Integer
|
|
Private Shared CurrSearchID As Integer
|
|
Private DTDataSearchDefinition As DataTable
|
|
Private _activeGridView As GridView
|
|
Private _frmProfileMatch As frmProfileMatch
|
|
Private Current_MatchingProfiles As List(Of ProfileData)
|
|
|
|
Public Property ShouldReturnToMatchForm As Boolean = False Implements IResultForm.ShouldReturnToMatchForm
|
|
|
|
Private Class SQLSearch
|
|
Public DataTable As DataTable
|
|
Public TabIndex As Integer
|
|
Public TabCaption As String
|
|
Public ProfileId As Integer
|
|
End Class
|
|
|
|
Public Sub New(ProfileMatchForm As frmProfileMatch, MatchingProfiles As List(Of ProfileData))
|
|
' Dieser Aufruf ist für den Designer erforderlich.
|
|
InitializeComponent()
|
|
|
|
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
|
Current_MatchingProfiles = MatchingProfiles
|
|
_frmProfileMatch = ProfileMatchForm
|
|
End Sub
|
|
|
|
Private Async Sub frmResultDoc_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not ConfigManager.Config.ResultDataWindowSize.IsEmpty Then
|
|
Size = ConfigManager.Config.ResultDataWindowSize
|
|
End If
|
|
|
|
If Not ConfigManager.Config.ResultDataWindowLocation.IsEmpty Then
|
|
Location = ConfigManager.Config.ResultDataWindowLocation
|
|
End If
|
|
|
|
'Load_Searches()
|
|
|
|
GridViewDataSearch1.ShowLoadingPanel()
|
|
|
|
Dim oSearches = Await LoadSearchesAsync()
|
|
|
|
For Each oSearch In oSearches
|
|
RefreshTabData(oSearch.ProfileId, oSearch.DataTable, oSearch.TabIndex, oSearch.TabCaption)
|
|
Next
|
|
|
|
GridViewDataSearch1.HideLoadingPanel()
|
|
End Sub
|
|
|
|
Private Sub frmResultDoc_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
|
|
Try
|
|
ConfigManager.Config.ResultDataWindowSize = Size
|
|
ConfigManager.Config.ResultDataWindowLocation = Location
|
|
ConfigManager.Save()
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Logger.Info("Error in Save FormLayout: " & ex.Message)
|
|
End Try
|
|
End Sub
|
|
|
|
Sub RefreshTabData(PROFILE_ID As Integer, DataTable As DataTable, TabIndex As Integer, TabCaption As String)
|
|
Try
|
|
Dim myGridControl As GridControl
|
|
Dim myGridview As GridView
|
|
Select Case TabIndex
|
|
Case 0
|
|
GridControlDocSearch1.DataSource = Nothing
|
|
GridViewDataSearch1.Columns.Clear()
|
|
myGridview = GridViewDataSearch1
|
|
myGridControl = GridControlDocSearch1
|
|
Case 1
|
|
GridControlDocSearch2.DataSource = Nothing
|
|
GridViewDataSearch2.Columns.Clear()
|
|
myGridview = GridViewDataSearch2
|
|
myGridControl = GridControlDocSearch2
|
|
Case 2
|
|
GridControlDocSearch3.DataSource = Nothing
|
|
GridViewDataSearch3.Columns.Clear()
|
|
myGridview = GridViewDataSearch3
|
|
myGridControl = GridControlDocSearch3
|
|
Case 3
|
|
GridControlDocSearch4.DataSource = Nothing
|
|
GridViewDataSearch4.Columns.Clear()
|
|
myGridControl = GridControlDocSearch4
|
|
myGridview = GridViewDataSearch4
|
|
Case 4
|
|
GridControlDocSearch5.DataSource = Nothing
|
|
GridViewDataSearch5.Columns.Clear()
|
|
myGridControl = GridControlDocSearch5
|
|
myGridview = GridViewDataSearch5
|
|
End Select
|
|
myGridControl.ContextMenuStrip = ContextMenuStripWMFile
|
|
If Not IsNothing(DataTable) Then
|
|
XtraTabControlData.TabPages(TabIndex).Text = $"{TabCaption} ({DataTable.Rows.Count})"
|
|
clsWMDocGrid.DTDocuments = DataTable
|
|
myGridControl.DataSource = DataTable
|
|
myGridControl.ForceInitialize()
|
|
Dim oxmlPath As String = ""
|
|
oxmlPath = Get_Grid_Layout_Filename(XtraTabControlData.SelectedTabPageIndex)
|
|
|
|
If File.Exists(oxmlPath) Then
|
|
myGridview.RestoreLayoutFromXml(oxmlPath)
|
|
myGridview.GuessAutoFilterRowValuesFromFilter()
|
|
End If
|
|
tslblState.Text = $"Tab [{TabCaption}] refreshed - {Now}"
|
|
XtraTabControlData.TabPages(TabIndex).PageVisible = True
|
|
Else
|
|
clsWMDocGrid.DTDocuments = Nothing
|
|
End If
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
End Try
|
|
End Sub
|
|
Private Function Get_Grid_Layout_Filename(oIndex As Integer)
|
|
Dim oFilename As String = String.Format("GridViewData_Search-{0}-{1}-UserLayout.xml", oIndex, CurrSearchID)
|
|
Dim oPath = Path.Combine(Application.UserAppDataPath(), oFilename)
|
|
Return oPath
|
|
End Function
|
|
|
|
Private Sub GridControlDocSearch_Leave(sender As Object, e As EventArgs) Handles GridControlDocSearch1.Leave, GridControlDocSearch2.Leave, GridControlDocSearch3.Leave, GridControlDocSearch4.Leave, GridControlDocSearch5.Leave
|
|
SaveDocGridLayout()
|
|
End Sub
|
|
|
|
Private Sub GridViewDocSearch1_FocusedRowChanged(sender As GridView, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch1.FocusedRowChanged, GridViewDataSearch2.FocusedRowChanged, GridViewDataSearch3.FocusedRowChanged, GridViewDataSearch4.FocusedRowChanged, GridViewDataSearch5.FocusedRowChanged
|
|
_activeGridView = sender
|
|
End Sub
|
|
|
|
Private Sub GridViewDocSearch1_ColumnWidthChanged(sender As GridView, e As Views.Base.ColumnEventArgs) Handles GridViewDataSearch1.ColumnWidthChanged, GridViewDataSearch2.ColumnWidthChanged, GridViewDataSearch3.ColumnWidthChanged, GridViewDataSearch4.ColumnWidthChanged, GridViewDataSearch5.ColumnWidthChanged
|
|
_activeGridView = sender
|
|
SaveDocGridLayout()
|
|
End Sub
|
|
|
|
Sub SaveDocGridLayout()
|
|
Dim oXMLPath = Get_Grid_Layout_Filename(XtraTabControlData.SelectedTabPageIndex)
|
|
_activeGridView.SaveLayoutToXml(oXMLPath)
|
|
End Sub
|
|
|
|
Private Async Function LoadSearchesAsync() As Task(Of List(Of SQLSearch))
|
|
Return Await Task.Run(AddressOf DoLoadSearches)
|
|
End Function
|
|
|
|
Private Function DoLoadSearches() As List(Of SQLSearch)
|
|
Dim oMatchingIds = String.Join(",", Current_MatchingProfiles.Select(Function(p) p.Guid).ToArray())
|
|
Dim oSQL = $"SELECT * FROM TBCW_PROF_DATA_SEARCH WHERE ACTIVE = 1 AND PROFILE_ID in ({oMatchingIds}) ORDER BY TAB_INDEX"
|
|
Dim oSearchesDataTable = clsDatabase.Return_Datatable(oSQL)
|
|
Dim oSearches As New List(Of SQLSearch)
|
|
Dim oCounter As Integer = 0
|
|
|
|
DTDataSearchDefinition = oSearchesDataTable
|
|
|
|
For Each oRow As DataRow In oSearchesDataTable.Rows
|
|
Dim oProfileId As Integer = oRow.Item("PROFILE_ID")
|
|
Dim oTabTitle As String = oRow.Item("TAB_TITLE")
|
|
|
|
oSQL = oRow.Item("SQL_COMMAND")
|
|
oSQL = clsPatterns.ReplaceAllValues(oSQL, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfileId)
|
|
|
|
Dim oDatatable As DataTable = clsDatabase.Return_Datatable(oSQL)
|
|
oSearches.Add(New SQLSearch() With {
|
|
.DataTable = oDatatable,
|
|
.ProfileId = oProfileId,
|
|
.TabCaption = oTabTitle,
|
|
.TabIndex = oCounter
|
|
})
|
|
|
|
oCounter += 1
|
|
Next
|
|
|
|
Return oSearches
|
|
End Function
|
|
|
|
Private Sub MenuItemReload_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem1.Click
|
|
Reload_Active_DocumentTab()
|
|
End Sub
|
|
|
|
Private Sub MenuItemResetLayout_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem2.Click
|
|
Reset_Layout()
|
|
End Sub
|
|
Sub Reset_Layout()
|
|
Dim oXMLPath = Get_Grid_Layout_Filename(XtraTabControlData.SelectedTabPageIndex)
|
|
Try
|
|
If File.Exists(oXMLPath) Then
|
|
File.Delete(oXMLPath)
|
|
Reload_Active_DocumentTab()
|
|
tslblState.Text = "Layout has been set back!"
|
|
Else
|
|
tslblState.Text = ""
|
|
End If
|
|
Catch ex As Exception
|
|
tslblState.Text = ""
|
|
End Try
|
|
End Sub
|
|
Sub Reload_Active_DocumentTab()
|
|
If IsNothing(DTDataSearchDefinition) Then Exit Sub
|
|
|
|
Dim oTabIndex = XtraTabControlData.SelectedTabPageIndex
|
|
Dim oTabTitle = DTDataSearchDefinition.Rows(oTabIndex).Item("TAB_TITLE")
|
|
Dim oConID = DTDataSearchDefinition.Rows(oTabIndex).Item("CONN_ID")
|
|
Dim oCommand = DTDataSearchDefinition.Rows(oTabIndex).Item("SQL_COMMAND")
|
|
Dim oProfID = DTDataSearchDefinition.Rows(oTabIndex).Item("PROFILE_ID")
|
|
Dim oDatatable As DataTable
|
|
|
|
oCommand = clsPatterns.ReplaceAllValues(oCommand, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfID)
|
|
oDatatable = clsDatabase.Return_Datatable(oCommand)
|
|
|
|
|
|
RefreshTabData(oProfID, oDatatable, oTabIndex, oTabTitle)
|
|
End Sub
|
|
|
|
Private Sub XtraTabControlDocs_SelectedPageChanged(sender As Object, e As TabPageChangedEventArgs) Handles XtraTabControlData.SelectedPageChanged
|
|
'If IsNothing(DTDataSearchDefinition) Then Exit Sub
|
|
'Dim oConID = DTDataSearchDefinition.Rows(XtraTabControlData.SelectedTabPageIndex).Item("CONN_ID")
|
|
'Dim oCommand = DTDataSearchDefinition.Rows(XtraTabControlData.SelectedTabPageIndex).Item("SQL_COMMAND")
|
|
'Dim oProfileID = DTDataSearchDefinition.Rows(XtraTabControlData.SelectedTabPageIndex).Item("PROFILE_ID")
|
|
'oCommand = clsPatterns.ReplaceAllValues(oCommand, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfileID)
|
|
'Dim oTabIndex = DTDataSearchDefinition.Rows(XtraTabControlData.SelectedTabPageIndex).Item("TAB_INDEX")
|
|
'Dim oTabCaption = DTDataSearchDefinition.Rows(XtraTabControlData.SelectedTabPageIndex).Item("TAB_TITLE")
|
|
'RefreshTabData(oProfileID, oConID, oCommand, oTabIndex, oTabCaption)
|
|
Reload_Active_DocumentTab()
|
|
End Sub
|
|
|
|
Private Sub btnBackToMatchForm_Click(sender As Object, e As EventArgs) Handles btnBackToMatchForm.Click
|
|
ShouldReturnToMatchForm = True
|
|
Close()
|
|
End Sub
|
|
End Class
|