Monitor/GUIs.Monitor/frmMonitor.vb

1018 lines
37 KiB
VB.net

Imports System.ComponentModel
Imports DevExpress.Utils
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraTab
Imports DevExpress.XtraTreeList
Imports DevExpress.XtraTreeList.Columns
Imports DevExpress.XtraTreeList.Nodes
Imports DigitalData.Controls.DocumentViewer
Imports DigitalData.Controls.SQLConfig
Imports DigitalData.GUIs.Common
Imports DigitalData.GUIs.Monitor.Constants
Imports DigitalData.Modules.Config
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Language
Imports DigitalData.Modules.Language.Utils
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Patterns
Public Class frmMonitor
Private ReadOnly ColumnMarkers As New List(Of String) From {"[HTML]", "[SQL]", "[FILENAME]"}
Private ReadOnly SQLColumns As New List(Of String) From {"SELECT1", "SELECT2", "SELECT3", "SELECT4"}
Private ReadOnly DocViewColumns As New List(Of String) From {"DOCVIEW1", "DOCVIEW2"}
Private ReadOnly HtmlViewColumns As New List(Of String) From {"HTML1", "HTML2"}
Private ReadOnly DataColumns As List(Of String) = SQLColumns.
Concat(DocViewColumns).
Concat(HtmlViewColumns).
ToList
Private ReadOnly DisplayColumns As New List(Of String) From {"COLUMN1", "COLUMN2", "COLUMN3", "ADDED_WHEN", "STATE", "ICON"}
Private SQLResultGrids As List(Of GridControl)
Private SQLResultTabs As List(Of XtraTabPage)
Private SQLResultGridIndex As Integer = 0
Private ActiveSQLResultGrid As GridControl
Private FileResultViewers As List(Of DocumentViewer)
Private FileResultTabs As List(Of XtraTabPage)
Private FileResultViewerIndex As Integer = 0
Private HtmlResultViewers As List(Of RichEditControl)
Private HtmlResultTabs As List(Of XtraTabPage)
Private TreeListResults As TreeList
Private GridControlResults As GridControl
Private GridViewResults As GridView
Private Const STATE_SUCCESS As String = "SUCCESS"
Private Const STATE_FAILURE As String = "FAILURE"
Private Const STATE_WARNING As String = "WARNING"
Private Const STATE_WAITING As String = "WAITING"
Private Const STATE_HIGHLIGHT As String = "HIGHLIGHT"
Private MarkedColumns As New List(Of GridColumn)
Private ActiveSearch As Search = Nothing
Private LastSearch As Search = Nothing
Private LastLoadedSearch As Search = Nothing
Private Enum NodeImage
[Default] = 0
SQL = 1
File = 2
Mail = 3
Success = 4
Failure = 5
Warning = 6
Waiting = 7
User = 8
Highlight = 9
End Enum
Private ReadOnly StateIcons As New Dictionary(Of String, NodeImage) From {
{STATE_SUCCESS, NodeImage.Success},
{STATE_FAILURE, NodeImage.Failure}
}
Private GridBuilder As GridBuilder
Private ControlHelper As Common.ControlHelper
Private SearchLoader As SearchLoader
Private ParamLoader As ParameterLoader
Private LogConfig As LogConfig
Private Logger As Logger
Private ConfigManager As ConfigManager(Of Config)
Private Database As MSSQLServer
Private FormHelper As FormHelper
Private Patterns As Patterns2
Private Workspace As Common.DocumentResultList.Workspace(Of Config)
Private Sub frmStart_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
LogConfig = New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing, "Digital Data", "Monitor")
Logger = LogConfig.GetLogger()
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath, Application.UserAppDataPath, Application.StartupPath)
Patterns = New Patterns2(LogConfig)
FormHelper = New FormHelper(LogConfig, Me)
ControlHelper = New Common.ControlHelper(LogConfig)
Workspace = New DocumentResultList.Workspace(Of Config)(LogConfig, ConfigManager, WorkspaceManager1)
If ConfigManager.Config.ConnectionString = String.Empty Then
Dim oSQLConfig As New frmSQLConfig(LogConfig)
If oSQLConfig.ShowDialog() = DialogResult.OK Then
ConfigManager.Config.ConnectionString = oSQLConfig.ConnectionString
ConfigManager.Save()
Application.Restart()
Else
FormHelper.ShowErrorMessage(New ApplicationException("No Database configured. Application will close!"), "Form Load")
Application.Exit()
End If
End If
If ConfigManager.Config.DBPrefix <> "" Then
If ConfigManager.Config.SearchSQL.Contains("@IDB_PRAEFIX") Then
Dim oREPLACE = ConfigManager.Config.SearchSQL.Replace("@IDB_PRAEFIX", ConfigManager.Config.DBPrefix)
ConfigManager.Config.SearchSQL = oREPLACE
ConfigManager.Save()
End If
Console.WriteLine(ConfigManager.Config.SearchSQL)
End If
Dim oConnectionString = MSSQLServer.DecryptConnectionString(ConfigManager.Config.ConnectionString)
Database = New MSSQLServer(LogConfig, oConnectionString)
SearchLoader = New SearchLoader(LogConfig, ConfigManager.Config, Database)
ParamLoader = New ParameterLoader(LogConfig, Database, LayoutControl1)
GridBuilder = New GridBuilder()
InitGrid()
InitTreeList()
Dim oGrids As GridView() = New List(Of GridView) From {GridView1, GridView2, GridView3, GridView4}.ToArray
GridBuilder.SetDefaults(oGrids)
GridBuilder.SetClipboardHandler(oGrids)
GridBuilder.SetReadOnlyOptions(oGrids)
SQLResultGrids = New List(Of GridControl) From {GridControl1, GridControl2, GridControl3, GridControl4}
SQLResultTabs = New List(Of XtraTabPage) From {XtraTabPageSQL1, XtraTabPageSQL2, XtraTabPageSQL3, XtraTabPageSQL4}
FileResultViewers = New List(Of DocumentViewer) From {DocumentViewer1, DocumentViewer2}
FileResultTabs = New List(Of XtraTabPage) From {XtraTabPageFile1, XtraTabPageFile2}
HtmlResultViewers = New List(Of RichEditControl) From {RichEditControl1, RichEditControl2}
HtmlResultTabs = New List(Of XtraTabPage) From {XtraTabPageHtml1, XtraTabPageHtml2}
SearchLoader.LoadSearchParameters()
LoadSearches()
Dim oLicense = LoadGDPicture()
For Each oGrid In SQLResultGrids
AddHandler oGrid.Enter, Sub()
ActiveSQLResultGrid = oGrid
btnExportDetails.Enabled = True
End Sub
AddHandler oGrid.Leave, Sub()
ActiveSQLResultGrid = Nothing
btnExportDetails.Enabled = False
End Sub
Next
For Each oViewer As DocumentViewer In FileResultViewers
oViewer.Init(LogConfig, oLicense)
Next
SplitContainerSQL.Collapsed = True
SplitContainerFileHTML.Collapsed = True
lbResultCount.Caption = String.Format(lbResultCount.Tag, 0)
Catch ex As Exception
FormHelper.ShowErrorMessage(ex, "frmStart_Load")
End Try
End Sub
Private Function LoadGDPicture() As String
Dim oSQL = "SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE'"
Return Database.GetScalarValue(oSQL)
End Function
Private Sub buttonSearch_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles buttonSearch.ItemClick
LoadData()
End Sub
Private Function LoadData() As Boolean
Try
TreeListResults.DataSource = Nothing
GridControlResults.DataSource = Nothing
If cmbSearches.EditValue Is Nothing Then
Return False
End If
Dim oSearch As Search = cmbSearches.EditValue
Dim oMissingParams = False
If LastLoadedSearch IsNot Nothing AndAlso oSearch.Id = LastLoadedSearch.Id Then
Workspace.SaveWorkspace(oSearch.Id.ToString)
End If
MarkedColumns.Clear()
HideAllTabs()
With AdornerUIManager2.ValidationHintProperties
.State = VisualEffects.ValidationHintState.Invalid
.InvalidState.ShowBorder = True
.InvalidState.ShowBackgroundMode = VisualEffects.ValidationHintBackgroundMode.Target
End With
AdornerUIManager2.Hide()
AdornerUIManager2.Elements.Clear()
Dim oSQL As String = oSearch.SQLCommand
Dim oControls As New List(Of Control)
For Each oItem As Control In LayoutControl1.Controls
Dim oParam = oSearch.Parameters.
Where(Function(param) param.PatternTitle = oItem.Name).
FirstOrDefault()
If oParam Is Nothing Then
Continue For
End If
oControls.Add(oItem)
If oParam.Required And Not ControlHelper.HasValue(oItem) Then
AdornerUIManager2.Elements.Add(New VisualEffects.ValidationHint With {
.TargetElement = oItem,
.Visible = True
})
oMissingParams = True
End If
Next
AdornerUIManager2.Show()
If oMissingParams = True Then
Return False
End If
oSQL = Patterns.ReplaceControlValues(oSQL, oControls)
Dim oTable As DataTable = Database.GetDatatable(oSQL)
If oSearch.ReturnType = Constants.ReturnTypeEnum.TreeView Then
GridControlResults.Visible = False
GridControlResults.Dock = DockStyle.None
TreeListResults.Visible = True
TreeListResults.Dock = DockStyle.Fill
TreeListResults.DataSource = oTable
Dim oMaxLength = 0
For Each oRow As DataRow In oTable.Rows
Dim oProcess = oRow.Item("COLUMN1")
Dim oLength = oProcess.ToString.Length
If oLength > oMaxLength Then
oMaxLength = oLength
End If
Next
InitTreeListColumns(oMaxLength)
' Show all columns in DisplayColumns List
For Each oColumn In TreeListResults.Columns
oColumn.Visible = DisplayColumns.Contains(oColumn.FieldName)
If oColumn.FieldName = "ADDED_WHEN" Then
oColumn.Format.FormatType = FormatType.DateTime
oColumn.Format.FormatString = "dd.MM.yyyy HH:MM:ss"
End If
Next
Dim oStateColumn As TreeListColumn = TreeListResults.Columns.Item("STATE")
For Each oNode As TreeListNode In TreeListResults.Nodes
ExpandNodes(oNode, Function(n)
Dim oObjectValue = n.GetValue(oStateColumn)
Dim oValue As String = NotNull(oObjectValue.ToString, String.Empty)
Return oValue IsNot Nothing AndAlso (oValue = STATE_WARNING Or oValue = STATE_FAILURE)
End Function)
Next
lbResultCount.Caption = String.Format(lbResultCount.Tag, TreeListResults.AllNodesCount)
Else
GridControlResults.Visible = True
GridControlResults.Dock = DockStyle.Fill
TreeListResults.Visible = False
TreeListResults.Dock = DockStyle.None
GridControlResults.DataSource = oTable
GridViewResults.PopulateColumns()
GridBuilder.SetDateTimeColumns(GridViewResults)
MarkedColumns = GridViewResults.Columns.AsEnumerable.
Where(Function(column)
Dim oCaption = column.FieldName.ToUpper.Trim
Return ColumnMarkers.Any(Function(marker) oCaption.EndsWith(marker))
End Function).ToList()
For Each oColumn In MarkedColumns
oColumn.VisibleIndex = -1
Next
lbResultCount.Caption = String.Format(lbResultCount.Tag, GridViewResults.RowCount)
End If
GridViewResults.FocusInvalidRow()
Workspace.LoadWorkspace(oSearch.Id.ToString)
LastLoadedSearch = oSearch
btnExportMain.Enabled = True
Return True
Catch ex As Exception
FormHelper.ShowErrorMessage(ex, "LoadData")
Return False
End Try
End Function
Private Sub LoadSearches()
Try
SearchLoader.LoadSearches()
cmbSearches.Properties.Items.Clear()
cmbSearches.Properties.Items.AddRange(SearchLoader.Searches)
If cmbSearches.EditValue IsNot Nothing Then
Dim oOldSearch As Search = DirectCast(cmbSearches.EditValue, Search)
Dim oNewSearch As Search = SearchLoader.Searches.Where(Function(search) search.Id = oOldSearch.Id).SingleOrDefault()
If oNewSearch IsNot Nothing Then
cmbSearches.EditValue = oNewSearch
End If
End If
Catch ex As Exception
FormHelper.ShowErrorMessage(ex, "LoadSearches")
End Try
End Sub
Private Sub InitTreeListColumns(pMaxLength As Integer)
Dim oColumn1 = TreeListResults.Columns.Item("COLUMN1")
Dim oColumn2 = TreeListResults.Columns.Item("COLUMN2")
Dim oColumn3 = TreeListResults.Columns.Item("COLUMN3")
Dim oAddedWhenColumn = TreeListResults.Columns.Item("ADDED_WHEN")
Dim oStateColumn = TreeListResults.Columns.Item("STATE")
Dim oIconColumn = TreeListResults.Columns.Item("ICON")
Dim oStateEdit As RepositoryItemImageComboBox = GetStateEdit()
Dim oIconEdit As RepositoryItemImageComboBox = GetIconEdit()
oColumn1.VisibleIndex = 0
oStateColumn.VisibleIndex = 1
oIconColumn.VisibleIndex = 2
Dim oColumnLength = pMaxLength * 5
With oColumn1
.Caption = "Titel"
.MinWidth = oColumnLength
.MaxWidth = oColumnLength
.Width = oColumnLength
.OptionsColumn.AllowSize = False
.OptionsColumn.AllowSort = False
End With
With oColumn2
.Caption = "Wert 1"
End With
With oColumn3
.Caption = "Wert 2"
End With
With oAddedWhenColumn
.Caption = "Datum"
End With
With oStateColumn
.ColumnEdit = oStateEdit
.MaxWidth = 25
.MinWidth = 25
.Width = 25
.Caption = " "
.OptionsColumn.AllowSize = False
.OptionsColumn.AllowSort = False
.ImageOptions.Image = SvgImageCollection1.GetImage(NodeImage.Success)
End With
With oIconColumn
.ColumnEdit = oIconEdit
.MaxWidth = 25
.MinWidth = 25
.Width = 25
.Caption = " "
.OptionsColumn.AllowSize = False
.OptionsColumn.AllowSort = False
.ImageOptions.Image = SvgImageCollection1.GetImage(NodeImage.SQL)
End With
End Sub
Private Function GetIconEdit() As RepositoryItemImageComboBox
Dim oIconEdit As New RepositoryItemImageComboBox With {
.SmallImages = SvgImageCollection1,
.GlyphAlignment = HorzAlignment.Near
}
oIconEdit.Buttons.Clear()
oIconEdit.Items.AddRange(New List(Of ImageComboBoxItem) From {
New ImageComboBoxItem("Email", "MAIL", NodeImage.Mail),
New ImageComboBoxItem("SQL", "SQL", NodeImage.SQL),
New ImageComboBoxItem("File", "FILE", NodeImage.File)
})
Return oIconEdit
End Function
Private Sub cmbSearches_SelectedValueChanged(sender As Object, e As EventArgs) Handles cmbSearches.SelectedValueChanged
DisposeTreeList()
InitTreeList()
DisposeGrid()
InitGrid()
SplitContainerSQL.Collapsed = True
SplitContainerFileHTML.Collapsed = True
btnExportMain.Enabled = False
btnExportDetails.Enabled = False
lbResultCount.Caption = String.Format(lbResultCount.Tag, 0)
LoadSearch()
HideAllTabs()
End Sub
Private Sub LoadSearch()
Try
If TypeOf cmbSearches.SelectedItem IsNot Search Then
Exit Sub
End If
Dim oSearch As Search = CType(cmbSearches.SelectedItem, Search)
If ActiveSearch IsNot Nothing Then
Workspace.SaveWorkspace(ActiveSearch.Id.ToString)
End If
LastSearch = ActiveSearch
ActiveSearch = oSearch
AdornerUIManager2.Hide()
AdornerUIManager2.Elements.Clear()
Root.Clear(disposeItemAndControls:=False)
LayoutControl1.Clear(True, True)
TreeListResults.DataSource = Nothing
GridControlResults.DataSource = Nothing
If oSearch.Parameters.Count = 0 Then
lbParams.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never
Else
lbParams.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always
End If
ParamLoader.LoadParameters(oSearch)
Catch ex As Exception
Logger.Error(ex)
End Try
End Sub
Private Function GetParameterItems(pParam As SearchParameter) As Object
Select Case pParam.ItemType
Case Constants.ItemTypeEnum.List
Return pParam.ItemString.Split(";"c).ToList()
Case Constants.ItemTypeEnum.SQL
Dim oSQL = pParam.ItemString
Dim oTable = Database.GetDatatable(oSQL)
Return oTable
End Select
End Function
Private Sub TreeListResults_FocusedNodeChanged(sender As Object, e As DevExpress.XtraTreeList.FocusedNodeChangedEventArgs)
If e.Node Is Nothing Then
Exit Sub
End If
Try
Dim oValues As Dictionary(Of String, String) = GetValuesFromNode(e.Node, DataColumns)
Dim oSQLCommands = oValues.
Where(Function(v) v.Key.StartsWith("SELECT")).
Where(Function(v) v.Value IsNot Nothing).
ToDictionary(Function(v) v.Key, Function(v) v.Value)
Dim oFilePaths = oValues.
Where(Function(v) v.Key.StartsWith("DOCVIEW")).
Where(Function(v) v.Value IsNot Nothing).
ToDictionary(Function(v) v.Key, Function(v) v.Value)
Dim oHtmlDocuments = oValues.
Where(Function(v) v.Key.StartsWith("HTML")).
Where(Function(v) v.Value IsNot Nothing).
ToDictionary(Function(v) v.Key, Function(v) v.Value)
Dim oAllTabs = SQLResultTabs.
Concat(FileResultTabs).
Concat(HtmlResultTabs)
For Each oTabPage In oAllTabs
oTabPage.PageVisible = False
Next
SplitContainerSQL.Collapsed = True
SplitContainerFileHTML.Collapsed = True
For Each oSQLCommand As KeyValuePair(Of String, String) In oSQLCommands
Try
Dim oExtracted = ExtractTitle(oSQLCommand.Value)
Dim oCommand = oExtracted.Item1
Dim oTitle = oExtracted.Item2
Dim oTable As DataTable = Database.GetDatatable(oCommand)
If oTable Is Nothing Then
Continue For
End If
Dim oGridIndex = Integer.Parse(oSQLCommand.Key.Last()) - 1
Dim oGridControl As GridControl = SQLResultGrids.Item(oGridIndex)
If oGridIndex = 0 Then
ActiveSQLResultGrid = oGridControl
End If
FillResultGrid(oGridControl, oTable, oTitle)
Catch ex As Exception
Logger.Error(ex)
Continue For
End Try
Next
For Each oFile As KeyValuePair(Of String, String) In oFilePaths
Try
Dim oExtracted = ExtractTitle(oFile.Value)
Dim oPath = oExtracted.Item1
Dim oTitle = oExtracted.Item2
If oPath Is Nothing Then
Continue For
End If
If Not IO.File.Exists(oPath) Then
Continue For
End If
Dim oViewerIndex = Integer.Parse(oFile.Key.Last()) - 1
Dim oViewer As DocumentViewer = FileResultViewers.Item(oViewerIndex)
FillResultViewer(oViewer, oPath, oTitle)
Catch ex As Exception
Logger.Error(ex)
Continue For
End Try
Next
For Each oFile As KeyValuePair(Of String, String) In oHtmlDocuments
Try
Dim oExtracted = ExtractTitle(oFile.Value)
Dim oHtml = oExtracted.Item1
Dim oTitle = oExtracted.Item2
If oHtml Is Nothing Then
Continue For
End If
Dim oViewerIndex = Integer.Parse(oFile.Key.Last()) - 1
Dim oViewer As RichEditControl = HtmlResultViewers.Item(oViewerIndex)
FillResultHtmlViewer(oViewer, oHtml, oTitle)
Catch ex As Exception
Logger.Error(ex)
Continue For
End Try
Next
Catch ex As Exception
FormHelper.ShowErrorMessage(ex, "TreeListResults_FocusedNodeChanged")
End Try
End Sub
Private Function ExtractTitle(Value As String) As Tuple(Of String, String)
If Value.Contains("|"c) Then
Dim oSplit = Value.Split("|"c).ToList
Dim oValue = oSplit.First()
Dim oTitle = oSplit.Item(1)
Return New Tuple(Of String, String)(oValue, oTitle)
End If
Return New Tuple(Of String, String)(Value, Nothing)
End Function
Private Sub ExpandNodes(RootNode As TreeListNode, Condition As Predicate(Of TreeListNode))
For Each oNode As TreeListNode In RootNode.Nodes
ExpandNodes(oNode, Condition)
If Condition(oNode) = True Then
oNode.Expand()
ExpandParentNode(oNode)
End If
Next
End Sub
Private Sub ExpandParentNode(ChildNode As TreeListNode)
If ChildNode.ParentNode IsNot Nothing Then
ChildNode.ParentNode.Expand()
ExpandParentNode(ChildNode.ParentNode)
End If
End Sub
Private Sub FillResultHtmlViewer(RichEditControl As RichEditControl, Html As String, Title As String)
RichEditControl.HtmlText = Html
Dim oTabPage = DirectCast(RichEditControl.Parent, XtraTabPage)
oTabPage.PageVisible = True
oTabPage.Text = NotNull(Title, oTabPage.Text)
XtraTabControlFileHTML.SelectedTabPage = oTabPage
End Sub
Private Sub FillResultViewer(DocumentViewer As DocumentViewer, Path As String, Title As String)
DocumentViewer.LoadFile(Path)
Dim oTabPage = DirectCast(DocumentViewer.Parent, XtraTabPage)
oTabPage.PageVisible = True
oTabPage.Text = NotNull(Title, oTabPage.Text)
XtraTabControlFileHTML.SelectedTabPage = oTabPage
End Sub
Private Sub FillResultGrid(GridControl As GridControl, Table As DataTable, Title As String)
GridControl.DataSource = Table
Dim oTabPage = DirectCast(GridControl.Parent, XtraTabPage)
oTabPage.PageVisible = True
oTabPage.Text = NotNull(Title, oTabPage.Text)
XtraTabControlSQL.SelectedTabPage = oTabPage
End Sub
Private Function GetValuesFromNode(Node As TreeListNode, ColumnNames As List(Of String)) As Dictionary(Of String, String)
Dim oValues As New Dictionary(Of String, String)
For Each oColumnName In ColumnNames
Dim oValue = MaybeGetValueForColumn(Node, oColumnName)
oValues.Add(oColumnName, oValue)
Next
Return oValues
End Function
Private Function MaybeGetValueForColumn(Node As TreeListNode, FieldName As String) As String
Dim oColumn = TreeListResults.Columns.Item(FieldName)
If oColumn Is Nothing Then
Return Nothing
End If
Dim oValue = Node.GetValue(oColumn)?.ToString
If oValue Is String.Empty Then
Return Nothing
Else
Return oValue
End If
End Function
Private Sub TreeListResults_CustomDrawNodeCell(sender As Object, e As DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs)
Dim oColumn = TreeListResults.Columns.Item("STATE")
Dim oState = NotNull(e.Node.GetValue(oColumn), Nothing)
If oState Is Nothing Then
Exit Sub
End If
Dim oColor As Color = Nothing
Select Case oState.ToString
Case STATE_SUCCESS
oColor = Color.LightGreen
Case STATE_FAILURE
oColor = Color.LightCoral
Case STATE_WARNING
oColor = Color.Yellow
Case STATE_WAITING
oColor = Color.LightSkyBlue
End Select
e.Appearance.BackColor = oColor
e.Appearance.Options.UseBackColor = True
e.Handled = False
End Sub
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
Dim oSQLConfig As New frmSQLConfig(LogConfig) With {
.ConnectionString = ConfigManager.Config.ConnectionString
}
If oSQLConfig.ShowDialog() = DialogResult.OK Then
ConfigManager.Config.ConnectionString = oSQLConfig.ConnectionString
ConfigManager.Save()
Database = New MSSQLServer(LogConfig, oSQLConfig.ConnectionString)
LoadSearches()
End If
End Sub
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnExportDetails.ItemClick
If ActiveSQLResultGrid Is Nothing Then
Exit Sub
End If
XtraSaveFileDialog1.Filter = "Excel Files (*.xlsx)|*.xlsx"
XtraSaveFileDialog1.FileName = $"{ActiveSearch.Title}_Detail.xlsx"
If XtraSaveFileDialog1.ShowDialog() = DialogResult.OK Then
ActiveSQLResultGrid.ExportToXlsx(XtraSaveFileDialog1.FileName)
End If
End Sub
Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnExportMain.ItemClick
If ActiveSearch Is Nothing Then
Exit Sub
End If
XtraSaveFileDialog1.Filter = "Excel Files (*.xlsx)|*.xlsx"
XtraSaveFileDialog1.FileName = $"{ActiveSearch.Title}.xlsx"
If XtraSaveFileDialog1.ShowDialog() = DialogResult.OK Then
If ActiveSearch.ReturnType = ReturnTypeEnum.TreeView Then
TreeListResults.ExportToXlsx(XtraSaveFileDialog1.FileName)
Else
GridControlResults.ExportToXlsx(XtraSaveFileDialog1.FileName)
End If
End If
End Sub
Private Sub frmMonitor_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.F5 Then
Debug.Write("Debug.Write")
Console.WriteLine("Console.WriteLine")
Debug.Print("Debug.Print")
LoadData()
End If
End Sub
Private Sub TreeListResults_MouseClick(sender As Object, e As MouseEventArgs)
Dim oInfo As TreeListHitInfo = TreeListResults.CalcHitInfo(New Point(e.X, e.Y))
If oInfo.InRowCell Then
Dim oNode = oInfo.Node
Dim oValues As Dictionary(Of String, String) = GetValuesFromNode(oNode, DataColumns)
Console.WriteLine()
Dim oShouldToggleSQL = False
Dim oShouldToggleFile = False
For Each oValue As KeyValuePair(Of String, String) In oValues
If oValue.Key.Contains("SELECT") AndAlso oValue.Value IsNot Nothing Then
oShouldToggleSQL = True
Exit For
End If
Next
For Each oValue As KeyValuePair(Of String, String) In oValues
If oValue.Key.Contains("DOCVIEW") AndAlso oValue.Value IsNot Nothing Then
oShouldToggleFile = True
Exit For
End If
If oValue.Key.Contains("HTML") AndAlso oValue.Value IsNot Nothing Then
oShouldToggleFile = True
Exit For
End If
Next
If oShouldToggleSQL Then
SplitContainerSQL.Collapsed = Not SplitContainerSQL.Collapsed
End If
If oShouldToggleFile Then
SplitContainerFileHTML.Collapsed = Not SplitContainerFileHTML.Collapsed
End If
End If
End Sub
Private Sub BarButtonItem4_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnReloadSearches.ItemClick
SearchLoader.LoadSearchParameters()
LoadSearches()
TreeListResults.DataSource = Nothing
GridControlResults.DataSource = Nothing
End Sub
Private Sub GridViewResults_FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs)
If GridViewResults.FocusedRowHandle < 0 Then
Exit Sub
End If
HideAllTabs()
ActiveSQLResultGrid = Nothing
Try
Dim oRow As DataRow = GridViewResults.GetDataRow(GridViewResults.FocusedRowHandle)
Dim oHtmlResultViewerIndex As Integer = 0
Dim oGridResultIndex As Integer = 0
Dim oViewerResultIndex As Integer = 0
For Each oColumn As GridColumn In MarkedColumns
Dim oValue = oRow.ItemEx(oColumn.FieldName, String.Empty)
If oValue.Length > 0 Then
If oColumn.FieldName.EndsWith("[HTML]") Then
Dim oViewer As RichEditControl = HtmlResultViewers.Item(oHtmlResultViewerIndex)
Dim oTitle = oColumn.FieldName.Replace("[HTML]", "").Trim()
oHtmlResultViewerIndex += 1
FillResultHtmlViewer(oViewer, oValue, oTitle)
SplitContainerFileHTML.Collapsed = False
ElseIf oColumn.FieldName.EndsWith("[SQL]") Then
Dim oTable As DataTable = Database.GetDatatable(oValue)
If oTable Is Nothing Then
Continue For
End If
Dim oTitle = oColumn.FieldName.Replace("[SQL]", "").Trim()
Dim oGridControl As GridControl = SQLResultGrids.Item(oGridResultIndex)
If oGridResultIndex = 0 Then
ActiveSQLResultGrid = oGridControl
End If
oGridResultIndex += 1
FillResultGrid(oGridControl, oTable, oTitle)
SplitContainerSQL.Collapsed = False
ElseIf oColumn.FieldName.EndsWith("[FILENAME]") Then
If oValue Is Nothing Then
Continue For
End If
If Not IO.File.Exists(oValue) Then
Continue For
End If
Dim oViewer As DocumentViewer = FileResultViewers.Item(oViewerResultIndex)
Dim oTitle = oColumn.FieldName.Replace("[FILENAME]", "").Trim()
oViewerResultIndex += 1
FillResultViewer(oViewer, oValue, oTitle)
SplitContainerFileHTML.Collapsed = False
End If
End If
Next
If ActiveSQLResultGrid Is Nothing Then
btnExportDetails.Enabled = False
Else
btnExportDetails.Enabled = True
End If
Catch ex As Exception
Logger.Error(ex)
End Try
End Sub
Private Sub HideAllTabs()
Dim oAllTabs = SQLResultTabs.
Concat(FileResultTabs).
Concat(HtmlResultTabs)
For Each oTabPage In oAllTabs
oTabPage.PageVisible = False
Next
SplitContainerSQL.Collapsed = True
SplitContainerFileHTML.Collapsed = True
End Sub
Private Sub frmMonitor_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
If ActiveSearch IsNot Nothing Then
Workspace.SaveWorkspace(ActiveSearch.Id.ToString)
End If
End Sub
Private Sub btnResetLayout_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnResetLayout.ItemClick
If ActiveSearch IsNot Nothing Then
Workspace.ResetWorkspace(ActiveSearch.Id.ToString)
LastLoadedSearch = Nothing
ActiveSearch = Nothing
DisposeTreeList()
InitTreeList()
DisposeGrid()
InitGrid()
LoadSearch()
HideAllTabs()
lbResultCount.Caption = String.Format(lbResultCount.Tag, 0)
End If
End Sub
Private Sub DisposeGrid()
GridViewResults.Dispose()
GridViewResults = Nothing
GridControlResults.Dispose()
GridControlResults = Nothing
End Sub
Private Sub InitGrid()
GridControlResults = New GridControl() With {
.Name = "GridViewResults",
.Visible = False
}
SplitContainerSQL.Panel1.Controls.Add(GridControlResults)
GridControlResults.ForceInitialize()
GridViewResults = DirectCast(GridControlResults.DefaultView, GridView)
AddHandler GridViewResults.FocusedRowChanged, AddressOf GridViewResults_FocusedRowChanged
GridBuilder.SetDefaults(GridViewResults)
GridBuilder.SetClipboardHandler(GridViewResults)
GridBuilder.SetReadOnlyOptions(GridViewResults)
End Sub
Private Sub DisposeTreeList()
TreeListResults.Dispose()
TreeListResults = Nothing
End Sub
Private Sub InitTreeList()
TreeListResults = New TreeList() With {
.Name = "TreeListResults",
.Visible = False
}
SplitContainerSQL.Panel1.Controls.Add(TreeListResults)
TreeListResults.ForceInitialize()
TreeListResults.KeyFieldName = "GUID"
TreeListResults.ParentFieldName = "PARENT_ID"
AddHandler TreeListResults.FocusedNodeChanged, AddressOf TreeListResults_FocusedNodeChanged
AddHandler TreeListResults.MouseClick, AddressOf TreeListResults_MouseClick
AddHandler TreeListResults.CustomDrawNodeCell, AddressOf TreeListResults_CustomDrawNodeCell
GridBuilder.SetDefaults(TreeListResults)
GridBuilder.SetClipboardHandler(TreeListResults)
GridBuilder.SetReadOnlyOptions(TreeListResults)
End Sub
'Private DisallowedComponentNames As New List(Of String) From {"LayoutControlItem", "LayoutControlGroup", "LayoutControl"}
'Private Sub WorkspaceManager1_PropertyDeserializing(sender As Object, ea As PropertyCancelEventArgs) Handles WorkspaceManager1.PropertyDeserializing, WorkspaceManager1.PropertySerializing
' Dim oName = ea.Component?.GetType.Name
' If DisallowedComponentNames.Contains(oName) Then
' ea.Cancel = True
' End If
'End Sub
Private Function GetStateEdit() As RepositoryItemImageComboBox
Dim oStateEdit As New RepositoryItemImageComboBox With {
.SmallImages = SvgImageCollection1,
.GlyphAlignment = HorzAlignment.Near
}
oStateEdit.Buttons.Clear()
oStateEdit.Items.AddRange(New List(Of ImageComboBoxItem) From {
New ImageComboBoxItem("Success", "SUCCESS", NodeImage.Success),
New ImageComboBoxItem("Failure", "FAILURE", NodeImage.Failure),
New ImageComboBoxItem("Warning", "WARNING", NodeImage.Warning),
New ImageComboBoxItem("Waiting", "WAITING", NodeImage.Waiting),
New ImageComboBoxItem("Default", "DEFAULT", NodeImage.Default),
New ImageComboBoxItem("User", "USER", NodeImage.User),
New ImageComboBoxItem("Highlight", "HIGHLIGHT", NodeImage.Highlight)
})
Return oStateEdit
End Function
End Class