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 _logConfig As LogConfig
|
||||||
Private DBFirebird As Firebird
|
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
|
' Node der Datenbank erstellen
|
||||||
Dim dbNode As New TreeNode With {
|
Dim oDbNode As New TreeNode With {
|
||||||
.Text = My.Settings.fbDatabaseLocation,
|
.Text = DatabaseName,
|
||||||
.Name = "DATABASE"
|
.Name = "DATABASE"
|
||||||
}
|
}
|
||||||
|
|
||||||
' Übernode für Tabellen erstellen
|
' Übernode für Tabellen erstellen
|
||||||
Dim tablesNode As New TreeNode With {
|
Dim oTablesNode As New TreeNode With {
|
||||||
.Text = "Tabellen",
|
.Text = "Tabellen",
|
||||||
.Name = "TABLES"
|
.Name = "TABLES"
|
||||||
}
|
}
|
||||||
|
|
||||||
' Nodes für Tabellen erstellen
|
' 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
|
For Each row As DataRow In DataTable.Rows
|
||||||
Dim node As New TreeNode With {
|
Dim oNode As New TreeNode With {
|
||||||
.Text = row.Item("TABLE"),
|
.Text = row.Item("TABLE"),
|
||||||
.Tag = row.Item("TABLE_ID")
|
.Tag = row.Item("TABLE_ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
tableNodeList.Add(node)
|
oTableNodeList.Add(oNode)
|
||||||
Next
|
Next
|
||||||
|
|
||||||
' Nodes zusammenfügen
|
' Nodes zusammenfügen
|
||||||
tablesNode.Nodes.AddRange(tableNodeList.ToArray)
|
oTablesNode.Nodes.AddRange(oTableNodeList.ToArray)
|
||||||
dbNode.Nodes.Add(tablesNode)
|
oDbNode.Nodes.Add(oTablesNode)
|
||||||
|
|
||||||
' Nodes einhängen
|
' Nodes einhängen
|
||||||
treeViewMain.Nodes.Add(dbNode)
|
treeViewMain.Nodes.Add(oDbNode)
|
||||||
|
treeViewMain.ExpandAll()
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Function LoadTables()
|
Private Function LoadTables()
|
||||||
@ -61,7 +64,8 @@ Public Class FrmMain
|
|||||||
'CurrentUser = New ClassCurrentUser(DBFirebird)
|
'CurrentUser = New ClassCurrentUser(DBFirebird)
|
||||||
|
|
||||||
Dim dt As DataTable = LoadTables()
|
Dim dt As DataTable = LoadTables()
|
||||||
CreateTableNodesFromDatatable(dt)
|
CreateTableNodesFromDatatable(dt, DBFirebird.DatabaseName)
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
|
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||||
@ -99,6 +103,8 @@ Public Class FrmMain
|
|||||||
Case "TABLES"
|
Case "TABLES"
|
||||||
SelectedTable = e.Node.Tag
|
SelectedTable = e.Node.Tag
|
||||||
contextMenuTable.Show(MousePosition)
|
contextMenuTable.Show(MousePosition)
|
||||||
|
Case "DATABASE"
|
||||||
|
contextMenuDatabase.Show(MousePosition)
|
||||||
End Select
|
End Select
|
||||||
|
|
||||||
treeViewMain.SelectedNode = e.Node
|
treeViewMain.SelectedNode = e.Node
|
||||||
@ -133,7 +139,10 @@ Public Class FrmMain
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub NeueTabelleToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NeueTabelleToolStripMenuItem.Click
|
Private Sub NeueTabelleToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NeueTabelleToolStripMenuItem.Click
|
||||||
Dim frm As New FrmNewTable(_logConfig.LogFactory)
|
Dim oForm As New FrmNewTable(_logConfig.LogFactory)
|
||||||
frm.ShowDialog()
|
oForm.ShowDialog()
|
||||||
|
|
||||||
|
Dim oTables As DataTable = LoadTables()
|
||||||
|
CreateTableNodesFromDatatable(oTables, DBFirebird.DatabaseName)
|
||||||
End Sub
|
End Sub
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
16
EDMDesigner/FrmNewTable.Designer.vb
generated
16
EDMDesigner/FrmNewTable.Designer.vb
generated
@ -23,7 +23,7 @@ Partial Class FrmNewTable
|
|||||||
<System.Diagnostics.DebuggerStepThrough()> _
|
<System.Diagnostics.DebuggerStepThrough()> _
|
||||||
Private Sub InitializeComponent()
|
Private Sub InitializeComponent()
|
||||||
Me.btnOK = New System.Windows.Forms.Button()
|
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.Label1 = New System.Windows.Forms.Label()
|
||||||
Me.SuspendLayout()
|
Me.SuspendLayout()
|
||||||
'
|
'
|
||||||
@ -36,12 +36,12 @@ Partial Class FrmNewTable
|
|||||||
Me.btnOK.Text = "OK"
|
Me.btnOK.Text = "OK"
|
||||||
Me.btnOK.UseVisualStyleBackColor = True
|
Me.btnOK.UseVisualStyleBackColor = True
|
||||||
'
|
'
|
||||||
'TextBox1
|
'txtTablename
|
||||||
'
|
'
|
||||||
Me.TextBox1.Location = New System.Drawing.Point(12, 25)
|
Me.txtTablename.Location = New System.Drawing.Point(12, 25)
|
||||||
Me.TextBox1.Name = "TextBox1"
|
Me.txtTablename.Name = "txtTablename"
|
||||||
Me.TextBox1.Size = New System.Drawing.Size(374, 20)
|
Me.txtTablename.Size = New System.Drawing.Size(374, 20)
|
||||||
Me.TextBox1.TabIndex = 1
|
Me.txtTablename.TabIndex = 1
|
||||||
'
|
'
|
||||||
'Label1
|
'Label1
|
||||||
'
|
'
|
||||||
@ -58,7 +58,7 @@ Partial Class FrmNewTable
|
|||||||
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
|
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
|
||||||
Me.ClientSize = New System.Drawing.Size(398, 98)
|
Me.ClientSize = New System.Drawing.Size(398, 98)
|
||||||
Me.Controls.Add(Me.Label1)
|
Me.Controls.Add(Me.Label1)
|
||||||
Me.Controls.Add(Me.TextBox1)
|
Me.Controls.Add(Me.txtTablename)
|
||||||
Me.Controls.Add(Me.btnOK)
|
Me.Controls.Add(Me.btnOK)
|
||||||
Me.Name = "FrmNewTable"
|
Me.Name = "FrmNewTable"
|
||||||
Me.Text = "Neue Tabelle"
|
Me.Text = "Neue Tabelle"
|
||||||
@ -68,6 +68,6 @@ Partial Class FrmNewTable
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Friend WithEvents btnOK As Button
|
Friend WithEvents btnOK As Button
|
||||||
Friend WithEvents TextBox1 As TextBox
|
Friend WithEvents txtTablename As TextBox
|
||||||
Friend WithEvents Label1 As Label
|
Friend WithEvents Label1 As Label
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
@ -16,7 +16,7 @@ Public Class FrmNewTable
|
|||||||
_logger = _logFactory.GetCurrentClassLogger()
|
_logger = _logFactory.GetCurrentClassLogger()
|
||||||
End Sub
|
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
|
Try
|
||||||
_db = New Firebird(_logFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
|
_db = New Firebird(_logFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
@ -26,6 +26,26 @@ Public Class FrmNewTable
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
|
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 Sub
|
||||||
End Class
|
End Class
|
||||||
Loading…
x
Reference in New Issue
Block a user