SQLEditor: Improve editor, add support for connections
This commit is contained in:
@@ -15,6 +15,9 @@ Public Class frmSQLEditor
|
||||
Private ClearPlaceholdersAfterSuccessfulExecute As Boolean = False
|
||||
Private FormLoading As Boolean = False
|
||||
|
||||
Public Property SQLCommand As String = ""
|
||||
Public Property SQLConnection As Integer = 0
|
||||
|
||||
Public Enum PlaceholderCollection
|
||||
Globix
|
||||
Zooflow
|
||||
@@ -38,11 +41,29 @@ Public Class frmSQLEditor
|
||||
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
FormLoading = True
|
||||
Try
|
||||
Dim oConnectionGroups = LoadConnections()
|
||||
RibbonGalleryBarItem2.Gallery.Groups.AddRange(oConnectionGroups.ToArray)
|
||||
If SQLCommand <> String.Empty Then
|
||||
txtSQLCommand.Document.Text = SQLCommand
|
||||
End If
|
||||
|
||||
Dim oConnectionGroup = LoadConnections()
|
||||
Dim oSelectedItem = Nothing
|
||||
|
||||
If SQLConnection > 0 Then
|
||||
For Each oItem As GalleryItem In oConnectionGroup.Items
|
||||
Dim oConnection = oItem.Tag
|
||||
If SQLConnection = oConnection.id Then
|
||||
oSelectedItem = oItem
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
GalleryConnection.Gallery.Groups.Add(oConnectionGroup)
|
||||
GalleryConnection.Gallery.SetItemCheck(oSelectedItem, True)
|
||||
|
||||
Dim oPlaceholderGroups = LoadPlaceholders()
|
||||
RibbonGalleryBarItem1.Gallery.Groups.AddRange(oPlaceholderGroups.ToArray)
|
||||
GalleryPlaceholders.Gallery.Groups.AddRange(oPlaceholderGroups.ToArray)
|
||||
|
||||
|
||||
|
||||
ConfigureRichEditControl()
|
||||
|
||||
@@ -54,12 +75,19 @@ Public Class frmSQLEditor
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub RibbonGalleryBarItem1_GalleryItemClick(sender As Object, e As GalleryItemClickEventArgs) Handles RibbonGalleryBarItem1.GalleryItemClick
|
||||
Private Sub RibbonGalleryBarItem1_GalleryItemClick(sender As Object, e As GalleryItemClickEventArgs) Handles GalleryPlaceholders.GalleryItemClick
|
||||
Dim oPlaceholder As Placeholder = e.Item.Tag
|
||||
Dim pPosition = RichEditControl1.Document.CaretPosition
|
||||
RichEditControl1.Document.InsertSingleLineText(pPosition, Patterns.WrapPatternValue(oPlaceholder.Module, oPlaceholder.Name))
|
||||
Dim pPosition = txtSQLCommand.Document.CaretPosition
|
||||
txtSQLCommand.Document.InsertSingleLineText(pPosition, Patterns.WrapPatternValue(oPlaceholder.Module, oPlaceholder.Name))
|
||||
End Sub
|
||||
|
||||
Private Sub RibbonGalleryBarItem2_GalleryItemClick(sender As Object, e As GalleryItemClickEventArgs) Handles GalleryConnection.GalleryItemClick
|
||||
Dim oConnection As Connection = e.Item.Tag
|
||||
SQLConnection = oConnection.Id
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
Private Function LoadPlaceholders() As List(Of GalleryItemGroup)
|
||||
Dim oInternalPlaceholders = Placeholders.GetInternalGroup()
|
||||
Dim oUserPlaceholder = Placeholders.GetUserGroup()
|
||||
@@ -70,7 +98,7 @@ Public Class frmSQLEditor
|
||||
}
|
||||
End Function
|
||||
|
||||
Private Function LoadConnections() As List(Of GalleryItemGroup)
|
||||
Private Function LoadConnections() As GalleryItemGroup
|
||||
Try
|
||||
Dim oSql = "SELECT GUID, Bezeichnung FROM [DD_ECM].[dbo].[TBDD_CONNECTION] WHERE AKTIV = 1"
|
||||
Dim oTable = Database.GetDatatable(oSql)
|
||||
@@ -82,28 +110,27 @@ Public Class frmSQLEditor
|
||||
.Name = oRow.Item("Bezeichnung")})
|
||||
Next
|
||||
|
||||
Dim oGroup1 = New GalleryItemGroup() With {.Caption = "Verbindungen"}
|
||||
Dim oConnectionGroup = 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}
|
||||
oConnectionGroup.Items.AddRange(oItems.ToArray)
|
||||
|
||||
Return oConnectionGroups
|
||||
Return oConnectionGroup
|
||||
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.Simple
|
||||
RichEditControl1.Document.Sections(0).Page.Width = DevExpress.Office.Utils.Units.InchesToDocumentsF(80.0F)
|
||||
txtSQLCommand.Options.Search.RegExResultMaxGuaranteedLength = 500
|
||||
txtSQLCommand.ReplaceService(Of ISyntaxHighlightService)(New SQLSyntaxHighlightService(txtSQLCommand.Document))
|
||||
txtSQLCommand.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Simple
|
||||
txtSQLCommand.Document.Sections(0).Page.Width = DevExpress.Office.Utils.Units.InchesToDocumentsF(80.0F)
|
||||
|
||||
RichEditControl1.Document.DefaultCharacterProperties.FontName = "Courier New"
|
||||
RichEditControl1.Document.DefaultCharacterProperties.FontSize = 12
|
||||
txtSQLCommand.Document.DefaultCharacterProperties.FontName = "Courier New"
|
||||
txtSQLCommand.Document.DefaultCharacterProperties.FontSize = 12
|
||||
End Sub
|
||||
|
||||
|
||||
@@ -123,30 +150,27 @@ Public Class frmSQLEditor
|
||||
|
||||
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
|
||||
Private Sub RichEditControl1_ContentChanged(sender As Object, e As EventArgs) Handles txtSQLCommand.ContentChanged
|
||||
Dim oSqlText = txtSQLCommand.Document.Text
|
||||
Dim oPatterns = Patterns.GetAllPatterns(oSqlText)
|
||||
|
||||
If oPatterns.Count = 0 Then
|
||||
Exit Sub
|
||||
GridPlaceholders.DataSource = New List(Of Placeholder)
|
||||
ElseIf oPatterns.Count.Equals(LastPatterns.Count) Then
|
||||
' noop
|
||||
Else
|
||||
Dim oPlaceholders = oPatterns.
|
||||
Select(Function(pattern) New Placeholder(pattern.Value, pattern.Value, pattern.Type, pattern.Value) With {.Pattern = pattern}).
|
||||
ToList()
|
||||
GridPlaceholders.DataSource = oPlaceholders
|
||||
End If
|
||||
|
||||
If oPatterns.SequenceEqual(LastPatterns) Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
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
|
||||
|
||||
End Sub
|
||||
|
||||
Private Async Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnExecuteSQL.ItemClick
|
||||
Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnExecuteSQL.ItemClick
|
||||
Try
|
||||
Dim oSql = RichEditControl1.Document.Text
|
||||
Dim oSql = txtSQLCommand.Document.Text
|
||||
|
||||
Dim oPlaceholders As List(Of Placeholder) = GridPlaceholders.DataSource
|
||||
|
||||
@@ -163,7 +187,16 @@ Public Class frmSQLEditor
|
||||
Next
|
||||
End If
|
||||
|
||||
Dim oDatatable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oDatatable As DataTable
|
||||
|
||||
If SQLConnection > 0 Then
|
||||
Dim oConnectionString = Database.GetConnectionStringForId(SQLConnection)
|
||||
oDatatable = Database.GetDatatableWithConnection(oSql, oConnectionString)
|
||||
Else
|
||||
oDatatable = Database.GetDatatable(oSql)
|
||||
End If
|
||||
|
||||
|
||||
Dim oForm As New frmSQLResult(oDatatable)
|
||||
oForm.Show()
|
||||
|
||||
@@ -189,4 +222,8 @@ Public Class frmSQLEditor
|
||||
Private Sub btnClearPlaceholders_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnClearPlaceholders.ItemClick
|
||||
ClearPlaceholders()
|
||||
End Sub
|
||||
|
||||
Private Sub chkShowPlaceholders_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles chkShowPlaceholders.CheckedChanged
|
||||
SplitContainerControl1.Collapsed = Not chkShowPlaceholders.Checked
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user