Common/SQLEditor: allow hide sql connection, improve placeholder grid, auto resize placeholder grid on form resize, auto set connection id to 1, preselect sql connection

This commit is contained in:
Jonathan Jenne
2022-08-09 11:21:03 +02:00
parent 8de0d67c60
commit f3dea1e225
4 changed files with 88 additions and 47 deletions

View File

@@ -12,6 +12,8 @@ Public Class frmSQLEditor
Private ReadOnly LogConfig As LogConfig
Private ReadOnly Database As MSSQLServer
Private ReadOnly Placeholders As SQLEditor.Placeholders
Private ReadOnly FormHelper As FormHelper
Private ReadOnly GridHelper As GridBuilder
Private ClearPlaceholdersAfterSuccessfulExecute As Boolean = False
Private FormLoading As Boolean = False
@@ -19,6 +21,8 @@ Public Class frmSQLEditor
Public Property SQLCommand As String = ""
Public Property SQLConnection As Integer = 0
Public Property AllowSQLConnectionSelection As Boolean = True
Public Property LoadClipboardPlaceholders As Boolean = False
Public Property PlaceholdersManual As Dictionary(Of String, String)
@@ -31,6 +35,10 @@ Public Class frmSQLEditor
Public Property PlaceholdersWindream As List(Of String)
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
MyClass.New(pLogConfig, pDatabase, True)
End Sub
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pAllowConnectionIdSelection As Boolean)
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
@@ -39,13 +47,21 @@ Public Class frmSQLEditor
Database = pDatabase
Patterns = New ClassPatterns(LogConfig)
Placeholders = New SQLEditor.Placeholders()
FormHelper = New FormHelper(pLogConfig, Me)
GridHelper = New GridBuilder()
AllowSQLConnectionSelection = pAllowConnectionIdSelection
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FormLoading = True
txtSQLCommand.BeginUpdate()
Try
If AllowSQLConnectionSelection = False Then
GalleryConnection.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
End If
If PlaceholdersAutomatic Is Nothing Then
PlaceholdersAutomatic = New Dictionary(Of String, String)
End If
@@ -65,15 +81,19 @@ Public Class frmSQLEditor
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
' Missing/Negative connection will always result in default (DD_ECM) connection
If SQLConnection <= 0 Then
SQLConnection = 1
End If
' Select the supplied connection in the ribbon gallery
For Each oItem As GalleryItem In oConnectionGroup.Items
Dim oConnection = oItem.Tag
If SQLConnection = oConnection.id Then
oSelectedItem = oItem
End If
Next
GalleryConnection.Gallery.Groups.Add(oConnectionGroup)
If oSelectedItem IsNot Nothing Then
@@ -85,7 +105,12 @@ Public Class frmSQLEditor
ConfigureRichEditControl()
GridHelper.SetDefaults(ViewPlaceholders)
ViewPlaceholders.OptionsView.ShowAutoFilterRow = False
chkClearPlaceholders.Checked = ClearPlaceholdersAfterSuccessfulExecute
ResizePlaceholderPanel()
Catch ex As Exception
Finally
txtSQLCommand.EndUpdate()
@@ -147,9 +172,19 @@ Public Class frmSQLEditor
Dim oConnectionGroup = New GalleryItemGroup() With {.Caption = "Verbindungen"}
Dim oItems As New List(Of GalleryItem)
For Each oConnection In oConnections
oItems.Add(GetGalleryItem(oConnection))
'Preselect the first connection if no selection was made
Dim oChecked = False
If SQLConnection = 0 AndAlso oConnection.Id = oConnections.First.Id Then
oChecked = True
Else : oChecked = False
End If
oItems.Add(GetConnectionGalleryItem(oConnection, oChecked))
Next
oConnectionGroup.Items.AddRange(oItems.ToArray)
Return oConnectionGroup
@@ -177,9 +212,10 @@ Public Class frmSQLEditor
GridPlaceholders.DataSource = oPlaceholders
End Sub
Private Function GetGalleryItem(pConnection As Connection) As GalleryItem
Private Function GetConnectionGalleryItem(pConnection As Connection, Optional pChecked As Boolean = False) As GalleryItem
Dim oItem = New GalleryItem(Nothing, pConnection.Name, Nothing) With {
.Tag = pConnection
.Tag = pConnection,
.Checked = pChecked
}
oItem.ImageOptions.SvgImage = My.Resources.actions_database
@@ -298,8 +334,31 @@ Public Class frmSQLEditor
End Sub
Private Sub BarButtonItem6_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem6.ItemClick
FormResult = DialogResult.Cancel
Me.Close()
Private Sub frmSQLEditor_ResizeEnd(sender As Object, e As EventArgs) Handles MyBase.ResizeEnd
ResizePlaceholderPanel()
End Sub
Private LastWindowState As FormWindowState = FormWindowState.Normal
Private Sub frmSQLEditor_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
If LastWindowState <> WindowState Then
LastWindowState = WindowState
ResizePlaceholderPanel()
End If
End Sub
Private Sub ResizePlaceholderPanel()
Dim oSplitterPosition As Integer = SplitContainerControl1.SplitterPosition
Dim oWindowWidth As Integer = Width
Dim oPlaceholdersExpanded As Boolean = Not SplitContainerControl1.Collapsed
If oSplitterPosition > oWindowWidth Then
oSplitterPosition = oWindowWidth * 0.7
ElseIf oSplitterPosition < (oWindowWidth * 0.5) Then
oSplitterPosition = oWindowWidth * 0.7
ElseIf oSplitterPosition > (oWindowWidth * 0.9) Then
oSplitterPosition = oWindowWidth * 0.7
End If
SplitContainerControl1.SplitterPosition = oSplitterPosition
End Sub
End Class