Imports System.ComponentModel Imports System.IO Imports DevExpress.Utils Imports DevExpress.XtraGrid Imports DevExpress.XtraPrinting Public Class frmMonitor Dim DT_MONITOR_KONFIG As DataTable Dim GRID1_TITLE As String Dim GRID2_TITLE As String Dim GRID2_SQL As String Dim GRID3_TITLE As String Dim GRID3_SQL As String Dim GRID4_TITLE As String Dim GRID4_SQL As String Private _ActiveGrid As GridControl = Nothing ' Private _frmDocView As frmDocView 'You need a reference to Form1 Dim FormShown As Boolean = False Private Sub GridView1_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles GridView1.FocusedRowChanged If FormShown = False Then Exit Sub Load_Detail() End Sub Sub Load_Detail() If FormShown = False Then Exit Sub Dim oDocPath As String = String.Empty Try Dim oDocID Try oDocID = GridView1.GetFocusedRowCellValue(GridView1.Columns("DocID")) Catch ex As Exception Try oDocID = GridView1.GetFocusedRowCellValue(GridView1.Columns("ObjectID")) Catch ex1 As Exception LOGGER.Warn("Could not get Doc/ObjectReference: " & ex.Message) MsgBox("Could not get Doc/ObjectReference: " & ex.Message, MsgBoxStyle.Critical, "Load_Detail") Exit Sub End Try End Try If IsNothing(oDocID) Then Exit Sub End If Try oDocPath = GridView1.GetFocusedRowCellValue(GridView1.Columns("FULL_FILE_PATH")) Catch ex As Exception LOGGER.Warn($"Error getting DocPath in Monitor: {ex.Message}") oDocPath = String.Empty End Try BarStaticItemInfoDoc.Caption = $"DocID: {oDocID} - Docpath: {oDocPath}" If Not IsNothing(GRID2_SQL) Then Dim oDetailSQL = GRID2_SQL oDetailSQL = oDetailSQL.Replace("@DocID", oDocID) oDetailSQL = oDetailSQL.Replace("@IDBOBJID", oDocID) oDetailSQL = oDetailSQL.Replace("@UserID", USER_ID) oDetailSQL = oDetailSQL.Replace("@UserName", USER_USERNAME) Dim oDT2 As DataTable = Database_ECM.GetDatatable(oDetailSQL) ', "Monitor_Detail1") If Not IsNothing(oDT2) Then LOGGER.Debug($"Found {oDT2.Rows.Count} rows for GridView2") GridView2.Columns.Clear() GridControl2.DataSource = oDT2 Try GridView2.Columns("Wann").DisplayFormat.FormatType = FormatType.DateTime GridView2.Columns("Wann").DisplayFormat.FormatString = "dd.MM.yyyy HH:MM:ss" Catch ex As Exception GridView2.Columns("When").DisplayFormat.FormatType = FormatType.DateTime GridView2.Columns("When").DisplayFormat.FormatString = "dd.MM.yyyy HH:MM:ss" End Try End If If DT_MONITOR_KONFIG.Rows.Count > 2 Then LOGGER.Debug($"DT_MONITOR_KONFIG.Rows.Count > 2") oDetailSQL = GRID3_SQL oDetailSQL = oDetailSQL.Replace("@DocID", oDocID) oDetailSQL = oDetailSQL.Replace("@IDBOBJID", oDocID) oDetailSQL = oDetailSQL.Replace("@UserID", USER_ID) oDetailSQL = oDetailSQL.Replace("@UserName", USER_USERNAME) Dim oDT3 As DataTable = Database_ECM.GetDatatable(oDetailSQL) ', "Monitor_Detail2") LOGGER.Debug($"oDetailSQL for Grid 3: {oDetailSQL}") If Not IsNothing(oDT3) Then LOGGER.Debug($"Found {oDT3.Rows.Count} rows for GridView3") GridView3.Columns.Clear() GridControl3.DataSource = oDT3 End If If DT_MONITOR_KONFIG.Rows.Count = 4 Then LOGGER.Debug($"DT_MONITOR_KONFIG.Rows.Count = 4") oDetailSQL = GRID4_SQL oDetailSQL = oDetailSQL.Replace("@DocID", oDocID) oDetailSQL = oDetailSQL.Replace("@IDBOBJID", oDocID) oDetailSQL = oDetailSQL.Replace("@UserID", USER_ID) oDetailSQL = oDetailSQL.Replace("@UserName", USER_USERNAME) LOGGER.Debug($"oDetailSQL for Grid 4: {oDetailSQL}") Dim oDT4 As DataTable = Database_ECM.GetDatatable(oDetailSQL) ', "Monitor_Detail3") If Not IsNothing(oDT4) Then LOGGER.Debug($"Found {oDT4.Rows.Count} rows for GridView4") GridView4.Columns.Clear() GridControl4.DataSource = oDT4 Try GridView4.Columns("Geändert wann").DisplayFormat.FormatType = FormatType.DateTime GridView4.Columns("Geändert wann").DisplayFormat.FormatString = "dd.MM.yyyy HH:MM:ss" Catch ex As Exception GridView4.Columns("Changed when").DisplayFormat.FormatType = FormatType.DateTime GridView4.Columns("Changed when").DisplayFormat.FormatString = "dd.MM.yyyy HH:MM:ss" End Try End If End If End If End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Error GridView1.FocusedRowChanged:") Finally If oDocPath <> String.Empty Then Load_Doc(oDocPath) End If End Try End Sub Sub Load_Doc(oDocPath As String) Try If SplitContainerControlMain.Collapsed = False And oDocPath <> String.Empty Then 'If Not Application.OpenForms().OfType(Of frmValidator).Any Then ' frmDocView.Show() ' _frmDocView = frmDocView 'End If '_frmDocView.LoadFile(oDocPath) If File.Exists(oDocPath) Then DocumentViewerMonitor.LoadFile(oDocPath) BarStaticItemInfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never DocumentViewerMonitor.Visible = True ' DocumentViewerMonitor.RightOnlyView(USER_RIGHT_VIEW_ONLY) Else BarStaticItemInfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Always BarStaticItemInfo.Caption = $"File is not existing or accessible!" DocumentViewerMonitor.Visible = False End If End If Catch ex As Exception LOGGER.Error(ex.Message) MsgBox(ex.Message, MsgBoxStyle.Critical, "Error in LoadDoc:") End Try End Sub Private Async Sub frmMonitor_Load(sender As Object, e As EventArgs) Handles Me.Load SplitContainerControlMain.Collapsed = True GridView1.ShowLoadingPanel() Await Load_Grid_Data() GridView1.HideLoadingPanel() Select Case DT_MONITOR_KONFIG.Rows.Count Case 2 LoadGrid1Layout() LoadGrid2Layout() SplitContainerControl1.SplitterPosition = CONFIG.Config.MonitorSplitter1_Distance Case 3 LoadGrid1Layout() LoadGrid2Layout() LoadGrid3Layout() SplitContainerControl1.SplitterPosition = CONFIG.Config.MonitorSplitter1_Distance SplitContainerControl2.SplitterPosition = CONFIG.Config.MonitorSplitter2_Distance Case 4 LoadGrid1Layout() LoadGrid2Layout() LoadGrid3Layout() LoadGrid4Layout() SplitContainerControl1.SplitterPosition = CONFIG.Config.MonitorSplitter1_Distance SplitContainerControl2.SplitterPosition = CONFIG.Config.MonitorSplitter2_Distance SplitContainerControl3.SplitterPosition = CONFIG.Config.MonitorSplitter3_Distance End Select Try DocumentViewerMonitor.Init(LOGCONFIG, GDPICTURE_LICENSE) Catch ex As Exception LOGGER.Error(ex) End Try End Sub Async Function Load_Grid_Data() As Threading.Tasks.Task Try FormShown = False Dim oSQL = "SELECT * FROM TBPM_MONITOR_KONFIG" DT_MONITOR_KONFIG = Database_ECM.GetDatatable(oSQL) ', "Monitor-Load_Grid_Data1") If Not IsNothing(DT_MONITOR_KONFIG) Then If DT_MONITOR_KONFIG.Rows.Count >= 1 Then oSQL = DT_MONITOR_KONFIG.Rows(0).Item("GRID_SQL") GridView1.Columns.Clear() Dim oDTGRID1 As DataTable = Await Database_ECM.GetDatatableAsync(oSQL) ', "Monitor-Load_Grid_Data2") GridControl1.DataSource = oDTGRID1 GRID1_TITLE = DT_MONITOR_KONFIG.Rows(0).Item("GRID_TITLE") GridView1.ViewCaption = GRID1_TITLE Try 'GridView1.Columns.Item("FULL_FILE_PATH").Visible = False Catch ex As Exception LOGGER.Info($"Attention: No Column FULL_FILE_PATH in GridView1") End Try Select Case DT_MONITOR_KONFIG.Rows.Count Case 2 SplitContainerControl2.Collapsed = True Case 3 SplitContainerControl3.Collapsed = True Case Else SplitContainerControl2.Collapsed = False SplitContainerControl3.Collapsed = False End Select If DT_MONITOR_KONFIG.Rows.Count > 1 Then GRID2_TITLE = DT_MONITOR_KONFIG.Rows(1).Item("GRID_TITLE") GRID2_SQL = DT_MONITOR_KONFIG.Rows(1).Item("GRID_SQL") GridView2.ViewCaption = GRID2_TITLE Select Case DT_MONITOR_KONFIG.Rows.Count Case 3 GRID3_TITLE = DT_MONITOR_KONFIG.Rows(2).Item("GRID_TITLE") GRID3_SQL = DT_MONITOR_KONFIG.Rows(2).Item("GRID_SQL") GridView3.ViewCaption = GRID3_TITLE Case 4 GRID3_TITLE = DT_MONITOR_KONFIG.Rows(2).Item("GRID_TITLE") GRID3_SQL = DT_MONITOR_KONFIG.Rows(2).Item("GRID_SQL") GridView3.ViewCaption = GRID3_TITLE GRID4_TITLE = DT_MONITOR_KONFIG.Rows(3).Item("GRID_TITLE") GRID4_SQL = DT_MONITOR_KONFIG.Rows(3).Item("GRID_SQL") GridView4.ViewCaption = GRID4_TITLE End Select End If End If End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Error in Load_Grid_Data:") Finally FormShown = True End Try End Function Sub LoadGrid1Layout() Try Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid1.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) If File.Exists(xml) Then GridView1.RestoreLayoutFromXml(xml, OptionsLayoutBase.FullLayout) End If Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while restoring layout 1: " & ex.Message) End Try End Sub Sub LoadGrid2Layout() Try Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid2.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) If File.Exists(xml) Then GridView2.RestoreLayoutFromXml(xml, OptionsLayoutBase.FullLayout) End If Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while restoring layout 2: " & ex.Message) End Try End Sub Sub LoadGrid3Layout() Try Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid3.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) If File.Exists(xml) Then GridView3.RestoreLayoutFromXml(xml, OptionsLayoutBase.FullLayout) End If Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while restoring layout 3: " & ex.Message) End Try End Sub Sub LoadGrid4Layout() Try Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid4.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) If File.Exists(xml) Then GridView4.RestoreLayoutFromXml(xml, OptionsLayoutBase.FullLayout) End If Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while restoring layout 4: " & ex.Message) End Try End Sub Sub SaveGrid1layout() Try Dim o = CONFIG.UserConfigPath.Replace("UserConfig.xml", "") Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid1.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) GridView1.SaveLayoutToXml(xml, OptionsLayoutBase.FullLayout) Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while saving Grid1Layout: " & ex.Message) End Try End Sub Sub RemoveLayout() Try Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid1.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) IO.File.Delete(xml) Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while saving RemoveLayout1: " & ex.Message) End Try End Sub Sub SaveGrid2layout() Try Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid2.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) GridView2.SaveLayoutToXml(xml, OptionsLayoutBase.FullLayout) Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while saving Grid2Layout: " & ex.Message) End Try End Sub Sub RemoveLayout2() Try Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid2.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) IO.File.Delete(xml) Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while saving RemoveLayout2: " & ex.Message) End Try End Sub Sub SaveGrid3layout() Try Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid3.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) GridView3.SaveLayoutToXml(xml, OptionsLayoutBase.FullLayout) Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while saving Grid3Layout: " & ex.Message) End Try End Sub Sub RemoveLayout3() Try Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid3.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) IO.File.Delete(xml) Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while saving RemoveLayout3: " & ex.Message) End Try End Sub Sub SaveGrid4layout() Try Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid4.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) GridView4.SaveLayoutToXml(xml, OptionsLayoutBase.FullLayout) Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while saving Grid4Layout: " & ex.Message) End Try End Sub Sub RemoveLayout4() Try Dim Filename As String = String.Format("DevExpressGridViewMonitor_UserLayout_Grid4.xml") Dim xml As String = System.IO.Path.Combine(CONFIG.UserConfigPath.Replace("UserConfig.xml", ""), Filename) IO.File.Delete(xml) Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error while saving RemoveLayout4: " & ex.Message) End Try End Sub Private Sub frmMonitor_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing Select Case DT_MONITOR_KONFIG.Rows.Count Case 2 SaveGrid1layout() SaveGrid2layout() Case 3 SaveGrid1layout() SaveGrid2layout() SaveGrid3layout() CONFIG.Config.MonitorSplitter1_Distance = SplitContainerControl1.SplitterPosition CONFIG.Config.MonitorSplitter2_Distance = SplitContainerControl2.SplitterPosition Case 4 SaveGrid1layout() SaveGrid2layout() SaveGrid3layout() SaveGrid4layout() CONFIG.Config.MonitorSplitter1_Distance = SplitContainerControl1.SplitterPosition CONFIG.Config.MonitorSplitter2_Distance = SplitContainerControl2.SplitterPosition CONFIG.Config.MonitorSplitter3_Distance = SplitContainerControl3.SplitterPosition End Select CONFIG.Save() Try DocumentViewerMonitor.Done() '_frmDocView.Close() Catch ex As Exception LOGGER.Error(ex) End Try End Sub Private Sub frmMonitor_Shown(sender As Object, e As EventArgs) Handles Me.Shown FormShown = True Load_Detail() End Sub Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick Dim oActiveGrid = GetActiveGridControl() If oActiveGrid IsNot Nothing Then XtraSaveFileDialog1.FileName = oActiveGrid.Name XtraSaveFileDialog1.Filter = "Excel documents (.xlsx)|*.xlsx" XtraSaveFileDialog1.DefaultExt = ".xlsx" If XtraSaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim oOptions As New XlsxExportOptions() With { .ExportMode = XlsxExportMode.SingleFile } oActiveGrid.ExportToXlsx(XtraSaveFileDialog1.FileName, oOptions) End If Else MessageBox.Show("Bitte wählen Sie eine Tabelle aus, die Sie exportieren möchten", Text, MessageBoxButtons.OK) End If End Sub Private Function GetActiveGridControl() As GridControl If _ActiveGrid Is Nothing Then Return Nothing End If Return _ActiveGrid End Function Private Sub GridControl1_Enter(sender As Object, e As EventArgs) Handles GridControl1.Enter, GridControl1.Enter, GridControl2.Enter, GridControl3.Enter, GridControl4.Enter _ActiveGrid = sender End Sub Private Sub frmMonitor_HelpButtonClicked(sender As Object, e As CancelEventArgs) Handles Me.HelpButtonClicked End Sub Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem3.ItemClick If SplitContainerControlMain.Collapsed = True Then SplitContainerControlMain.Collapsed = False If USER_LANGUAGE = "de-DE" Then BarButtonItem3.Caption = "DocView deaktivieren" Else BarButtonItem3.Caption = "Deactivate DocView" End If BarButtonItem3.Down = True Dim oDocPath Try oDocPath = GridView1.GetFocusedRowCellValue(GridView1.Columns("FULL_FILE_PATH")) Catch ex As Exception LOGGER.Warn($"Error getting DocPath in Monitor: {ex.Message}") Exit Sub End Try DocumentViewerMonitor?.LoadFile(oDocPath) 'If oDocPath <> "" Then ' If Not Application.OpenForms().OfType(Of frmValidator).Any Then ' frmDocView.Show() ' _frmDocView = frmDocView ' End If ' _frmDocView.LoadFile(oDocPath) ' Me.SendToBack() 'End If Else SplitContainerControlMain.Collapsed = True If USER_LANGUAGE = "de-DE" Then BarButtonItem3.Caption = "DocView aktivieren" Else BarButtonItem3.Caption = "Activate DocView" End If BarButtonItem3.Down = False End If End Sub Private Async Sub BarButtonItem4_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem4.ItemClick Select Case DT_MONITOR_KONFIG.Rows.Count Case 2 RemoveLayout() RemoveLayout2() Case 3 RemoveLayout() RemoveLayout2() RemoveLayout3() Case 4 RemoveLayout() RemoveLayout2() RemoveLayout3() RemoveLayout4() End Select GridView1.ShowLoadingPanel() Await Load_Grid_Data() GridView1.HideLoadingPanel() End Sub End Class