SQLEditor: lots of stuff
This commit is contained in:
@@ -7,16 +7,20 @@ Imports DigitalData.Modules.Patterns
|
||||
|
||||
Public Class frmSQLEditor
|
||||
|
||||
Private Patterns As ClassPatterns
|
||||
Private LogConfig As LogConfig
|
||||
Private Database As MSSQLServer
|
||||
Private ReadOnly Patterns As ClassPatterns
|
||||
Private ReadOnly LogConfig As LogConfig
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
Private ReadOnly Placeholders As Placeholders
|
||||
|
||||
Private ClearPlaceholdersAfterSuccessfulExecute As Boolean = False
|
||||
Private FormLoading As Boolean = False
|
||||
|
||||
Public Enum PlaceholderCollection
|
||||
Globix
|
||||
Zooflow
|
||||
End Enum
|
||||
|
||||
Public Sub SetPlaceholders()
|
||||
Public Sub SetPlaceholders(pCollection As PlaceholderCollection)
|
||||
|
||||
End Sub
|
||||
|
||||
@@ -27,71 +31,94 @@ Public Class frmSQLEditor
|
||||
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
||||
LogConfig = pLogConfig
|
||||
Database = pDatabase
|
||||
Patterns = New ClassPatterns(LogConfig)
|
||||
Placeholders = New Placeholders()
|
||||
End Sub
|
||||
|
||||
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
Patterns = New ClassPatterns(LogConfig)
|
||||
FormLoading = True
|
||||
Try
|
||||
Dim oConnectionGroups = LoadConnections()
|
||||
RibbonGalleryBarItem2.Gallery.Groups.AddRange(oConnectionGroups.ToArray)
|
||||
|
||||
Dim oGroup1 = New GalleryItemGroup() With {.Caption = "Gruppe 1"}
|
||||
Dim oGroup2 = New GalleryItemGroup() With {.Caption = "Gruppe 2"}
|
||||
Dim oGroup3 = New GalleryItemGroup() With {.Caption = "Gruppe 3"}
|
||||
Dim oPlaceholderGroups = LoadPlaceholders()
|
||||
RibbonGalleryBarItem1.Gallery.Groups.AddRange(oPlaceholderGroups.ToArray)
|
||||
|
||||
Dim oItems As New List(Of GalleryItem)() From {
|
||||
GetGalleryItem(New Placeholder("StringValue1", "Index", Placeholder.PlaceholderType.FileFlow, "StringValue1")),
|
||||
GetGalleryItem(New Placeholder("StringValue2", "Index", Placeholder.PlaceholderType.FileFlow, "StringValue2")),
|
||||
GetGalleryItem(New Placeholder("StringValue3", "Index", Placeholder.PlaceholderType.FileFlow, "StringValue3")),
|
||||
GetGalleryItem(New Placeholder("StringValue4", "Index", Placeholder.PlaceholderType.FileFlow, "StringValue4")),
|
||||
GetGalleryItem(New Placeholder("StringValue5", "Index", Placeholder.PlaceholderType.FileFlow, "StringValue5"))
|
||||
ConfigureRichEditControl()
|
||||
|
||||
chkClearPlaceholders.Checked = ClearPlaceholdersAfterSuccessfulExecute
|
||||
Catch ex As Exception
|
||||
Finally
|
||||
FormLoading = False
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub RibbonGalleryBarItem1_GalleryItemClick(sender As Object, e As GalleryItemClickEventArgs) Handles RibbonGalleryBarItem1.GalleryItemClick
|
||||
Dim oPlaceholder As Placeholder = e.Item.Tag
|
||||
Dim pPosition = RichEditControl1.Document.CaretPosition
|
||||
RichEditControl1.Document.InsertSingleLineText(pPosition, Patterns.WrapPatternValue(oPlaceholder.Module, oPlaceholder.Name))
|
||||
End Sub
|
||||
|
||||
Private Function LoadPlaceholders() As List(Of GalleryItemGroup)
|
||||
Dim oInternalPlaceholders = Placeholders.GetInternalGroup()
|
||||
Dim oUserPlaceholder = Placeholders.GetUserGroup()
|
||||
|
||||
Return New List(Of GalleryItemGroup)() From {
|
||||
oInternalPlaceholders,
|
||||
oUserPlaceholder
|
||||
}
|
||||
End Function
|
||||
|
||||
oGroup1.Items.AddRange(oItems.ToArray)
|
||||
oGroup2.Items.AddRange(oItems.ToArray)
|
||||
oGroup3.Items.AddRange(oItems.ToArray)
|
||||
Private Function LoadConnections() As List(Of GalleryItemGroup)
|
||||
Try
|
||||
Dim oSql = "SELECT GUID, Bezeichnung FROM [DD_ECM].[dbo].[TBDD_CONNECTION] WHERE AKTIV = 1"
|
||||
Dim oTable = Database.GetDatatable(oSql)
|
||||
Dim oConnections = New List(Of Connection)
|
||||
|
||||
RibbonGalleryBarItem1.Gallery.Groups.AddRange(New List(Of GalleryItemGroup)() From {oGroup1, oGroup2, oGroup3}.ToArray)
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
oConnections.Add(New Connection() With {
|
||||
.Id = oRow.Item("GUID"),
|
||||
.Name = oRow.Item("Bezeichnung")})
|
||||
Next
|
||||
|
||||
Dim oGroup1 = New GalleryItemGroup() With {.Caption = "Verbindungen"}
|
||||
Dim oItems As New List(Of GalleryItem)
|
||||
For Each oConnection In oConnections
|
||||
oItems.Add(GetGalleryItem(oConnection))
|
||||
Next
|
||||
oGroup1.Items.AddRange(oItems.ToArray)
|
||||
Dim oConnectionGroups = New List(Of GalleryItemGroup)() From {oGroup1}
|
||||
|
||||
Return oConnectionGroups
|
||||
Catch ex As Exception
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Sub ConfigureRichEditControl()
|
||||
RichEditControl1.Options.Search.RegExResultMaxGuaranteedLength = 500
|
||||
RichEditControl1.ReplaceService(Of ISyntaxHighlightService)(New SQLSyntaxHighlightService(RichEditControl1.Document))
|
||||
RichEditControl1.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Draft
|
||||
RichEditControl1.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Simple
|
||||
RichEditControl1.Document.Sections(0).Page.Width = DevExpress.Office.Utils.Units.InchesToDocumentsF(80.0F)
|
||||
|
||||
RichEditControl1.Document.DefaultCharacterProperties.FontName = "Courier New"
|
||||
RichEditControl1.Document.DefaultCharacterProperties.FontSize = 12
|
||||
End Sub
|
||||
|
||||
Private Sub RibbonGalleryBarItem1_GalleryItemClick(sender As Object, e As GalleryItemClickEventArgs) Handles RibbonGalleryBarItem1.GalleryItemClick
|
||||
Dim oPlaceholder As Placeholder = e.Item.Tag
|
||||
MsgBox(oPlaceholder.Name)
|
||||
|
||||
Dim pPosition = RichEditControl1.Document.CaretPosition
|
||||
RichEditControl1.Document.InsertSingleLineText(pPosition, oPlaceholder.Value)
|
||||
Private Sub ClearPlaceholders()
|
||||
GridPlaceholders.DataSource = New List(Of Placeholder)
|
||||
End Sub
|
||||
|
||||
Private Class Placeholder
|
||||
Public Type As PlaceholderType
|
||||
Public Property Name As String
|
||||
Public Property Value As String
|
||||
Public Property Pattern As Pattern
|
||||
|
||||
Public Category As String
|
||||
Public Description As String
|
||||
|
||||
Public Enum PlaceholderType
|
||||
FileFlow
|
||||
End Enum
|
||||
|
||||
Public Sub New(pName As String, pDescription As String, pType As PlaceholderType, pCategory As String)
|
||||
Name = pName
|
||||
Description = pDescription
|
||||
Type = pType
|
||||
Category = pCategory
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Private Function GetGalleryItem(pPlaceholder As Placeholder) As GalleryItem
|
||||
Return New GalleryItem(Nothing, pPlaceholder.Name, pPlaceholder.Description) With {
|
||||
.Tag = pPlaceholder
|
||||
Private Function GetGalleryItem(pConnection As Connection) As GalleryItem
|
||||
Dim oItem = New GalleryItem(Nothing, pConnection.Name, Nothing) With {
|
||||
.Tag = pConnection
|
||||
}
|
||||
|
||||
oItem.ImageOptions.SvgImage = My.Resources.actions_database
|
||||
|
||||
Return oItem
|
||||
End Function
|
||||
|
||||
Private Property LastPatterns As New List(Of Pattern)
|
||||
@@ -108,9 +135,9 @@ Public Class frmSQLEditor
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
GridControl1.DataSource = oPatterns.Select(Function(pattern)
|
||||
Return New Placeholder(pattern.Value, pattern.Type, Placeholder.PlaceholderType.FileFlow, "") With {.Pattern = pattern}
|
||||
End Function).ToList()
|
||||
GridPlaceholders.DataSource = oPatterns.Select(Function(pattern)
|
||||
Return New Placeholder(pattern.Value, pattern.Value, pattern.Type, pattern.Value) With {.Pattern = pattern}
|
||||
End Function).ToList()
|
||||
|
||||
|
||||
LastPatterns = oPatterns
|
||||
@@ -120,11 +147,46 @@ Public Class frmSQLEditor
|
||||
Private Async Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnExecuteSQL.ItemClick
|
||||
Try
|
||||
Dim oSql = RichEditControl1.Document.Text
|
||||
|
||||
Dim oPlaceholders As List(Of Placeholder) = GridPlaceholders.DataSource
|
||||
|
||||
If oPlaceholders IsNot Nothing Then
|
||||
For Each oPlaceholder In oPlaceholders
|
||||
Dim oWrapped = Patterns.WrapPatternValue(oPlaceholder.Module, oPlaceholder.Name)
|
||||
|
||||
If oPlaceholder.Value Is Nothing Then
|
||||
Throw New ApplicationException($"Der Platzhalter '{oWrapped}' wurde nicht ausgefüllt!")
|
||||
End If
|
||||
|
||||
|
||||
oSql = oSql.Replace(oWrapped, oPlaceholder.Value)
|
||||
Next
|
||||
End If
|
||||
|
||||
Dim oDatatable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oForm As New frmSQLResult(oDatatable)
|
||||
oForm.Show()
|
||||
|
||||
Catch ex As ApplicationException
|
||||
MsgBox(ex.Message, MsgBoxStyle.Exclamation, Text)
|
||||
|
||||
Catch ex As Exception
|
||||
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Class Connection
|
||||
Public Property Id As Integer
|
||||
Public Property Name As String
|
||||
End Class
|
||||
|
||||
Private Sub BarCheckItem1_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles chkClearPlaceholders.CheckedChanged
|
||||
If FormLoading = False Then
|
||||
ClearPlaceholdersAfterSuccessfulExecute = chkClearPlaceholders.Checked
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub btnClearPlaceholders_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnClearPlaceholders.ItemClick
|
||||
ClearPlaceholders()
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user