SQLEditor: New Form
This commit is contained in:
@@ -1,146 +1,101 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
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
|
||||
Imports DigitalData.Modules.Language.Utils
|
||||
Imports DigitalData.GUIs.Common
|
||||
Imports DevExpress.XtraGrid.Views.Grid
|
||||
|
||||
Public Class frmSQLEditor
|
||||
Public SQLString As String
|
||||
|
||||
Private LogConfig As LogConfig
|
||||
Private SQLServer As MSSQLServer
|
||||
Private CurrentPosition As String
|
||||
|
||||
Private Placeholders As New List(Of Placeholder)
|
||||
Private Connections As New List(Of Connection)
|
||||
|
||||
Private Patterns As ClassPatterns
|
||||
Private LogConfig As LogConfig
|
||||
Private Database As MSSQLServer
|
||||
|
||||
Friend Class Placeholder
|
||||
Public Property Placeholder As String
|
||||
Public Property Replacement As String
|
||||
End Class
|
||||
Public Enum PlaceholderCollection
|
||||
Globix
|
||||
Zooflow
|
||||
End Enum
|
||||
|
||||
Friend Class Connection
|
||||
Public Property Guid As Integer
|
||||
Public Property Name As String
|
||||
Public Property Description As String
|
||||
Public Property Provider As String
|
||||
Public Property Server As String
|
||||
Public Property Database As String
|
||||
Public Property Username As String
|
||||
Public Property Password As String
|
||||
Public Sub SetPlaceholders()
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return Name
|
||||
End Function
|
||||
End Class
|
||||
End Sub
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, SQLServer As MSSQLServer)
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
|
||||
' Dieser Aufruf ist für den Designer erforderlich.
|
||||
InitializeComponent()
|
||||
|
||||
Me.LogConfig = LogConfig
|
||||
Me.SQLServer = SQLServer
|
||||
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
||||
LogConfig = pLogConfig
|
||||
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 frmSQLEditor_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
Try
|
||||
InitializeBaseForm(LogConfig)
|
||||
Private Sub RibbonGalleryBarItem1_GalleryItemClick(sender As Object, e As GalleryItemClickEventArgs) Handles RibbonGalleryBarItem1.GalleryItemClick
|
||||
Dim oPlaceholder As Placeholder = e.Item.Tag
|
||||
MsgBox(oPlaceholder.Name)
|
||||
|
||||
txtSQL.Text = SQLString
|
||||
|
||||
BindingSourcePlaceholder.DataSource = Placeholders
|
||||
Placeholders.Clear()
|
||||
|
||||
Connections = Load_SQLConnections()
|
||||
|
||||
Dim oViews As New List(Of GridView) From {GridViewResult, GridViewPlaceholder}
|
||||
Dim oGridBuilder As New GridBuilder(oViews)
|
||||
oGridBuilder.
|
||||
WithDefaults().
|
||||
WithReadOnlyOptions(GridViewResult)
|
||||
|
||||
cmbConnections.Properties.Items.Clear()
|
||||
For Each oConnection In Connections
|
||||
cmbConnections.Properties.Items.Add(oConnection)
|
||||
Next
|
||||
Catch ex As Exception
|
||||
ShowErrorMessage(ex)
|
||||
End Try
|
||||
Dim pPosition = RichEditControl1.Document.CaretPosition
|
||||
RichEditControl1.Document.InsertSingleLineText(pPosition, oPlaceholder.Value)
|
||||
End Sub
|
||||
|
||||
Private Function Load_SQLConnections()
|
||||
Try
|
||||
Dim oSQL As String = "SELECT * FROM TBDD_CONNECTION"
|
||||
Dim oTable As DataTable = SQLServer.GetDatatable(oSQL)
|
||||
Dim oConnections As New List(Of Connection)
|
||||
Private Class Placeholder
|
||||
Public Type As PlaceholderType
|
||||
Public Name As String
|
||||
Public Description As String
|
||||
Public Value As String
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
oConnections.Add(New Connection With {
|
||||
.Guid = NotNull(oRow.Item("GUID"), String.Empty),
|
||||
.Name = NotNull(oRow.Item("BEZEICHNUNG"), String.Empty),
|
||||
.Provider = NotNull(oRow.Item("SQL_PROVIDER"), String.Empty),
|
||||
.Database = NotNull(oRow.Item("DATENBANK"), String.Empty),
|
||||
.Description = NotNull(oRow.Item("BEMERKUNG"), String.Empty),
|
||||
.Password = NotNull(oRow.Item("PASSWORD"), String.Empty),
|
||||
.Server = NotNull(oRow.Item("SERVER"), String.Empty),
|
||||
.Username = NotNull(oRow.Item("USERNAME"), String.Empty)
|
||||
})
|
||||
Next
|
||||
Public Enum PlaceholderType
|
||||
FileFlow
|
||||
End Enum
|
||||
|
||||
Return oConnections
|
||||
Catch ex As Exception
|
||||
ShowErrorMessage(ex)
|
||||
Return New List(Of Connection)
|
||||
End Try
|
||||
Public Sub New(pName As String, pDescription As String, pType As PlaceholderType, pValue As String)
|
||||
Name = pName
|
||||
Description = pDescription
|
||||
Type = pType
|
||||
Value = pValue
|
||||
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 Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
|
||||
SQLString = txtSQL.Text
|
||||
DialogResult = DialogResult.OK
|
||||
Close()
|
||||
Private Sub RichEditControl1_ContentChanged(sender As Object, e As EventArgs) Handles RichEditControl1.ContentChanged
|
||||
Dim oSqlText = RichEditControl1.Document.Text
|
||||
Dim oPatterns = Patterns.GetAllPatterns(oSqlText)
|
||||
End Sub
|
||||
|
||||
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick
|
||||
If cmbConnections.SelectedItem Is Nothing Then
|
||||
ShowErrorMessage("Bitte wählen sie eine Datenbank Verbindung!")
|
||||
Exit Sub
|
||||
End If
|
||||
Private Sub RibbonControl1_Click(sender As Object, e As EventArgs) Handles RibbonControl1.Click
|
||||
|
||||
Try
|
||||
Dim oSQL As String = txtSQL.EditValue.ToString
|
||||
Dim oConnection As Connection = cmbConnections.SelectedItem
|
||||
Dim oConnectionString = SQLServer.GetConnectionString(oConnection.Server, oConnection.Database, oConnection.Username, oConnection.Password)
|
||||
Dim oTable As DataTable = SQLServer.GetDatatableWithConnection(oSQL, oConnectionString)
|
||||
|
||||
GridControlResult.DataSource = oTable
|
||||
Catch ex As Exception
|
||||
ShowErrorMessage(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub txtSQL_EditValueChanged(sender As Object, e As EventArgs) Handles txtSQL.EditValueChanged
|
||||
CurrentPosition = txtSQL.SelectionStart
|
||||
Dim oValue = txtSQL.EditValue.ToString.Trim
|
||||
|
||||
If oValue.Length > 0 Then
|
||||
GridControlPlaceholders.Enabled = True
|
||||
CheckForPlaceholders(txtSQL.EditValue)
|
||||
Else
|
||||
GridControlPlaceholders.Enabled = False
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub CheckForPlaceholders(Text As String)
|
||||
Placeholders.Clear()
|
||||
|
||||
For Each oPattern In Patterns.GetAllPatterns(Text)
|
||||
Placeholders.Add(New Placeholder With {
|
||||
.Placeholder = oPattern.ToString,
|
||||
.Replacement = ""
|
||||
})
|
||||
Next
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user