WIP: EDM Designer, create table
This commit is contained in:
parent
77c20440d8
commit
720b6955fd
@ -8,37 +8,40 @@ Public Class FrmMain
|
||||
Private _logConfig As LogConfig
|
||||
Private DBFirebird As Firebird
|
||||
|
||||
Private Sub CreateTableNodesFromDatatable(dt As DataTable)
|
||||
Private Sub CreateTableNodesFromDatatable(DataTable As DataTable, DatabaseName As String)
|
||||
treeViewMain.Nodes.Clear()
|
||||
|
||||
' Node der Datenbank erstellen
|
||||
Dim dbNode As New TreeNode With {
|
||||
.Text = My.Settings.fbDatabaseLocation,
|
||||
Dim oDbNode As New TreeNode With {
|
||||
.Text = DatabaseName,
|
||||
.Name = "DATABASE"
|
||||
}
|
||||
|
||||
' Übernode für Tabellen erstellen
|
||||
Dim tablesNode As New TreeNode With {
|
||||
Dim oTablesNode As New TreeNode With {
|
||||
.Text = "Tabellen",
|
||||
.Name = "TABLES"
|
||||
}
|
||||
|
||||
' Nodes für Tabellen erstellen
|
||||
Dim tableNodeList As New List(Of TreeNode)
|
||||
Dim oTableNodeList As New List(Of TreeNode)
|
||||
|
||||
For Each row As DataRow In dt.Rows
|
||||
Dim node As New TreeNode With {
|
||||
For Each row As DataRow In DataTable.Rows
|
||||
Dim oNode As New TreeNode With {
|
||||
.Text = row.Item("TABLE"),
|
||||
.Tag = row.Item("TABLE_ID")
|
||||
}
|
||||
|
||||
tableNodeList.Add(node)
|
||||
oTableNodeList.Add(oNode)
|
||||
Next
|
||||
|
||||
' Nodes zusammenfügen
|
||||
tablesNode.Nodes.AddRange(tableNodeList.ToArray)
|
||||
dbNode.Nodes.Add(tablesNode)
|
||||
oTablesNode.Nodes.AddRange(oTableNodeList.ToArray)
|
||||
oDbNode.Nodes.Add(oTablesNode)
|
||||
|
||||
' Nodes einhängen
|
||||
treeViewMain.Nodes.Add(dbNode)
|
||||
treeViewMain.Nodes.Add(oDbNode)
|
||||
treeViewMain.ExpandAll()
|
||||
End Sub
|
||||
|
||||
Private Function LoadTables()
|
||||
@ -61,7 +64,8 @@ Public Class FrmMain
|
||||
'CurrentUser = New ClassCurrentUser(DBFirebird)
|
||||
|
||||
Dim dt As DataTable = LoadTables()
|
||||
CreateTableNodesFromDatatable(dt)
|
||||
CreateTableNodesFromDatatable(dt, DBFirebird.DatabaseName)
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
@ -99,6 +103,8 @@ Public Class FrmMain
|
||||
Case "TABLES"
|
||||
SelectedTable = e.Node.Tag
|
||||
contextMenuTable.Show(MousePosition)
|
||||
Case "DATABASE"
|
||||
contextMenuDatabase.Show(MousePosition)
|
||||
End Select
|
||||
|
||||
treeViewMain.SelectedNode = e.Node
|
||||
@ -133,7 +139,10 @@ Public Class FrmMain
|
||||
End Sub
|
||||
|
||||
Private Sub NeueTabelleToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NeueTabelleToolStripMenuItem.Click
|
||||
Dim frm As New FrmNewTable(_logConfig.LogFactory)
|
||||
frm.ShowDialog()
|
||||
Dim oForm As New FrmNewTable(_logConfig.LogFactory)
|
||||
oForm.ShowDialog()
|
||||
|
||||
Dim oTables As DataTable = LoadTables()
|
||||
CreateTableNodesFromDatatable(oTables, DBFirebird.DatabaseName)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
16
EDMDesigner/FrmNewTable.Designer.vb
generated
16
EDMDesigner/FrmNewTable.Designer.vb
generated
@ -23,7 +23,7 @@ Partial Class FrmNewTable
|
||||
<System.Diagnostics.DebuggerStepThrough()> _
|
||||
Private Sub InitializeComponent()
|
||||
Me.btnOK = New System.Windows.Forms.Button()
|
||||
Me.TextBox1 = New System.Windows.Forms.TextBox()
|
||||
Me.txtTablename = New System.Windows.Forms.TextBox()
|
||||
Me.Label1 = New System.Windows.Forms.Label()
|
||||
Me.SuspendLayout()
|
||||
'
|
||||
@ -36,12 +36,12 @@ Partial Class FrmNewTable
|
||||
Me.btnOK.Text = "OK"
|
||||
Me.btnOK.UseVisualStyleBackColor = True
|
||||
'
|
||||
'TextBox1
|
||||
'txtTablename
|
||||
'
|
||||
Me.TextBox1.Location = New System.Drawing.Point(12, 25)
|
||||
Me.TextBox1.Name = "TextBox1"
|
||||
Me.TextBox1.Size = New System.Drawing.Size(374, 20)
|
||||
Me.TextBox1.TabIndex = 1
|
||||
Me.txtTablename.Location = New System.Drawing.Point(12, 25)
|
||||
Me.txtTablename.Name = "txtTablename"
|
||||
Me.txtTablename.Size = New System.Drawing.Size(374, 20)
|
||||
Me.txtTablename.TabIndex = 1
|
||||
'
|
||||
'Label1
|
||||
'
|
||||
@ -58,7 +58,7 @@ Partial Class FrmNewTable
|
||||
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
|
||||
Me.ClientSize = New System.Drawing.Size(398, 98)
|
||||
Me.Controls.Add(Me.Label1)
|
||||
Me.Controls.Add(Me.TextBox1)
|
||||
Me.Controls.Add(Me.txtTablename)
|
||||
Me.Controls.Add(Me.btnOK)
|
||||
Me.Name = "FrmNewTable"
|
||||
Me.Text = "Neue Tabelle"
|
||||
@ -68,6 +68,6 @@ Partial Class FrmNewTable
|
||||
End Sub
|
||||
|
||||
Friend WithEvents btnOK As Button
|
||||
Friend WithEvents TextBox1 As TextBox
|
||||
Friend WithEvents txtTablename As TextBox
|
||||
Friend WithEvents Label1 As Label
|
||||
End Class
|
||||
|
||||
@ -16,7 +16,7 @@ Public Class FrmNewTable
|
||||
_logger = _logFactory.GetCurrentClassLogger()
|
||||
End Sub
|
||||
|
||||
Private Sub FrmNewTable_Load(sender As Object, e As KeyEventArgs) Handles Me.Load
|
||||
Private Sub FrmNewTable_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
Try
|
||||
_db = New Firebird(_logFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
|
||||
Catch ex As Exception
|
||||
@ -26,6 +26,26 @@ Public Class FrmNewTable
|
||||
End Sub
|
||||
|
||||
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
|
||||
Dim oTableName As String = txtTablename.Text
|
||||
|
||||
If oTableName.Trim() = String.Empty Then
|
||||
MsgBox("Table name cannot be empty!", MsgBoxStyle.Exclamation)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oExistingTableId = _db.GetScalarValue($"SELECT GUID FROM TBEDM_TABLE WHERE DESCRIPTION = '{oTableName}'")
|
||||
|
||||
If oExistingTableId IsNot Nothing Then
|
||||
MsgBox("Table already exists!", MsgBoxStyle.Exclamation)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oResult = _db.GetScalarValue($"SELECT FNCREATE_TABLE('{oTableName}','{Environment.UserName}') FROM rdb$database;")
|
||||
|
||||
If oResult >= 0 Then
|
||||
Close()
|
||||
Else
|
||||
MsgBox("An error occurred while creating the table. Check the log", MsgBoxStyle.Critical)
|
||||
End If
|
||||
End Sub
|
||||
End Class
|
||||
Loading…
x
Reference in New Issue
Block a user