Monorepo/Controls.SQLEditor/frmSQLEditor.vb
2022-05-04 16:50:04 +02:00

131 lines
5.1 KiB
VB.net

Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.XtraRichEdit.Services
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Patterns
Public Class frmSQLEditor
Private Patterns As ClassPatterns
Private LogConfig As LogConfig
Private Database As MSSQLServer
Public Enum PlaceholderCollection
Globix
Zooflow
End Enum
Public Sub SetPlaceholders()
End Sub
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
LogConfig = pLogConfig
Database = pDatabase
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Patterns = New ClassPatterns(LogConfig)
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 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"))
}
oGroup1.Items.AddRange(oItems.ToArray)
oGroup2.Items.AddRange(oItems.ToArray)
oGroup3.Items.AddRange(oItems.ToArray)
RibbonGalleryBarItem1.Gallery.Groups.AddRange(New List(Of GalleryItemGroup)() From {oGroup1, oGroup2, oGroup3}.ToArray)
RichEditControl1.Options.Search.RegExResultMaxGuaranteedLength = 500
RichEditControl1.ReplaceService(Of ISyntaxHighlightService)(New SQLSyntaxHighlightService(RichEditControl1.Document))
RichEditControl1.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Draft
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)
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
}
End Function
Private Property LastPatterns As New List(Of Pattern)
Private Sub RichEditControl1_ContentChanged(sender As Object, e As EventArgs) Handles RichEditControl1.ContentChanged
Dim oSqlText = RichEditControl1.Document.Text
Dim oPatterns = Patterns.GetAllPatterns(oSqlText)
If oPatterns.Count = 0 Then
Exit Sub
End If
If oPatterns.SequenceEqual(LastPatterns) Then
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()
LastPatterns = oPatterns
End Sub
Private Async Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnExecuteSQL.ItemClick
Try
Dim oSql = RichEditControl1.Document.Text
Dim oDatatable = Await Database.GetDatatableAsync(oSql)
Dim oForm As New frmSQLResult(oDatatable)
oForm.Show()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
End Try
End Sub
End Class