2019-07-15 15:09:48 +02:00

222 lines
10 KiB
VB.net

Imports System.ComponentModel
Imports System.IO
Imports System.Runtime.InteropServices
Imports DevExpress.Utils
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Imports DD_LIB_Standards
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraTab
Public Class frmResultSQL
#Region "Laufzeitvariablen & Konstanten"
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
#End Region
Public Sub New()
MyBase.New
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
End Sub
Sub RefreshTabData(PROFILE_ID As Integer, ConID As Integer, SQLCommand As String, TabIndex As Integer, TabCaption As String)
Try
SQLCommand = clsPatterns.ReplaceAllValues(SQLCommand, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, PROFILE_ID)
Dim myGridControl As DevExpress.XtraGrid.GridControl
Dim myGridview As DevExpress.XtraGrid.Views.Grid.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
Dim oDatatable As DataTable = clsDatabase.Return_Datatable(SQLCommand)
If Not IsNothing(oDatatable) Then
XtraTabControlData.TabPages(TabIndex).Text = $"{TabCaption} ({oDatatable.Rows.Count})"
clsWMDocGrid.DTDocuments = oDatatable
'Select Case TabIndex
' Case 0
' GridControlDocSearch1.DataSource = oDatatable
' Case 1
' GridControlDocSearch2.DataSource = oDatatable
' Case 2
' GridControlDocSearch3.DataSource = oDatatable
' Case 3
' GridControlDocSearch4.DataSource = oDatatable
' Case 4
' GridControlDocSearch5.DataSource = oDatatable
'End Select
myGridControl.DataSource = oDatatable
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 = System.IO.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
Sub SaveDocGridLayout()
Dim oXMLPath = Get_Grid_Layout_Filename(XtraTabControlData.SelectedTabPageIndex)
_activeGridView.SaveLayoutToXml(oXMLPath)
End Sub
Private Sub GridViewDocSearch1_ColumnWidthChanged(sender As Object, e As Views.Base.ColumnEventArgs) Handles GridViewDataSearch1.ColumnWidthChanged
_activeGridView = GridViewDataSearch1
SaveDocGridLayout()
End Sub
Private Sub frmResultDoc_Load(sender As Object, e As EventArgs) Handles Me.Load
If ConfigManager.Config.ResultDataWindowX > 0 And ConfigManager.Config.ResultDataWindowY > 0 Then
Dim oLocation As New Point(ConfigManager.Config.ResultDataWindowX, ConfigManager.Config.ResultDataWindowY)
Location = oLocation
End If
Dim oSize As New Size(ConfigManager.Config.ResultDataWindowWidth, ConfigManager.Config.ResultDataWindowHeight)
Size = oSize
Load_Searches()
End Sub
Sub Load_Searches()
If Not IsNothing(CurrDataSearch2Load) Then
Dim oSQL = $"SELECT * FROM TBCW_PROF_DATA_SEARCH WHERE ACTIVE = 1 AND PROFILE_ID in ({CurrDataSearch2Load}) ORDER BY TAB_INDEX"
DTDataSearchDefinition = clsDatabase.Return_Datatable(oSQL)
Dim oindex As Integer
Dim ocounter As Integer = 0
If CurrDataSearch2Load.ToString.Contains(",") Then
End If
For Each oRow As DataRow In DTDataSearchDefinition.Rows
RefreshTabData(oRow.Item("PROFILE_ID"), oRow.Item("CONN_ID"), oRow.Item("SQL_COMMAND"), ocounter, oRow.Item("TAB_TITLE"))
ocounter += 1
Next
Else
MsgBox("Sorry but the selection of profile went wrong. (CurrSearch2Load is nothing)", MsgBoxStyle.Critical)
Me.Close()
End If
End Sub
Private Sub frmResultDoc_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try
ConfigManager.Config.ResultDataWindowHeight = Size.Height
ConfigManager.Config.ResultDataWindowWidth = Size.Width
ConfigManager.Config.ResultDataWindowX = Location.X
ConfigManager.Config.ResultDataWindowY = Location.Y
ConfigManager.Save()
Catch ex As Exception
Logger.Error(ex)
Logger.Info("Error in Save FormLayout: " & ex.Message)
End Try
End Sub
Private Sub ToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem1.Click
ReLoad_Active_DocTab()
End Sub
Private Sub ToolStripMenuItem2_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem2.Click
Set_DoclayoutBack()
End Sub
Sub Set_DoclayoutBack()
Dim oXMLPath = Get_Grid_Layout_Filename(XtraTabControlData.SelectedTabPageIndex)
Try
If File.Exists(oXMLPath) Then
File.Delete(oXMLPath)
ReLoad_Active_DocTab()
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_DocTab()
Dim oTabIndex = XtraTabControlData.SelectedTabPageIndex
Dim oConID = DTDataSearchDefinition.Rows(oTabIndex).Item("CONN_ID")
Dim oCommand = DTDataSearchDefinition.Rows(oTabIndex).Item("SQL_COMMAND")
Dim oProfID = DTDataSearchDefinition.Rows(oTabIndex).Item("PROFILE_ID")
oCommand = clsPatterns.ReplaceAllValues(oCommand, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfID)
RefreshTabData(oProfID, oConID, oCommand, oTabIndex, DTDataSearchDefinition.Rows(oTabIndex).Item("TAB_TITLE"))
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)
End Sub
Private Sub GridViewDocSearch1_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch1.FocusedRowChanged
_activeGridView = GridViewDataSearch1
End Sub
Private Sub GridViewDocSearch2_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch2.FocusedRowChanged
_activeGridView = GridViewDataSearch2
End Sub
Private Sub GridViewDocSearch3_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch3.FocusedRowChanged
_activeGridView = GridViewDataSearch3
End Sub
Private Sub GridViewDocSearch4_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch4.FocusedRowChanged
_activeGridView = GridViewDataSearch4
End Sub
Private Sub GridViewDocSearch5_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch5.FocusedRowChanged
_activeGridView = GridViewDataSearch5
End Sub
Private Sub frmResultSQL_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Me.BringToFront()
End Sub
End Class