EDMIService: Fix replacing tables
This commit is contained in:
13
GUIs.Test.TestGUI/frmRelations.Designer.vb
generated
13
GUIs.Test.TestGUI/frmRelations.Designer.vb
generated
@@ -22,16 +22,29 @@ Partial Class frmRelations
|
|||||||
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
|
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
|
||||||
<System.Diagnostics.DebuggerStepThrough()> _
|
<System.Diagnostics.DebuggerStepThrough()> _
|
||||||
Private Sub InitializeComponent()
|
Private Sub InitializeComponent()
|
||||||
|
Me.Button1 = New System.Windows.Forms.Button()
|
||||||
Me.SuspendLayout()
|
Me.SuspendLayout()
|
||||||
'
|
'
|
||||||
|
'Button1
|
||||||
|
'
|
||||||
|
Me.Button1.Location = New System.Drawing.Point(12, 12)
|
||||||
|
Me.Button1.Name = "Button1"
|
||||||
|
Me.Button1.Size = New System.Drawing.Size(75, 23)
|
||||||
|
Me.Button1.TabIndex = 0
|
||||||
|
Me.Button1.Text = "Button1"
|
||||||
|
Me.Button1.UseVisualStyleBackColor = True
|
||||||
|
'
|
||||||
'frmRelations
|
'frmRelations
|
||||||
'
|
'
|
||||||
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
|
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
|
||||||
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
|
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
|
||||||
Me.ClientSize = New System.Drawing.Size(800, 450)
|
Me.ClientSize = New System.Drawing.Size(800, 450)
|
||||||
|
Me.Controls.Add(Me.Button1)
|
||||||
Me.Name = "frmRelations"
|
Me.Name = "frmRelations"
|
||||||
Me.Text = "frmRelations"
|
Me.Text = "frmRelations"
|
||||||
Me.ResumeLayout(False)
|
Me.ResumeLayout(False)
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Friend WithEvents Button1 As Button
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ Imports DigitalData.Services.EDMIService
|
|||||||
Public Class frmRelations
|
Public Class frmRelations
|
||||||
Private DB As MSSQLServer
|
Private DB As MSSQLServer
|
||||||
Private LogConfig As LogConfig
|
Private LogConfig As LogConfig
|
||||||
|
Private JobResult As JobResult
|
||||||
|
Private JobListener As JobListener
|
||||||
|
Private DetailRow As DataRow
|
||||||
|
|
||||||
Private Sub frmRelations_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
Private Sub frmRelations_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||||
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath)
|
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath)
|
||||||
@@ -18,13 +21,18 @@ Public Class frmRelations
|
|||||||
oGroupUser.TableName = "TBDD_GROUPS_USER"
|
oGroupUser.TableName = "TBDD_GROUPS_USER"
|
||||||
|
|
||||||
Dim oCronDetails As DataTable = DB.GetDatatable("SELECT * FROM TBAPPSERV_CRON_DETAIL WHERE DT_NAME = 'TBDD_USER'")
|
Dim oCronDetails As DataTable = DB.GetDatatable("SELECT * FROM TBAPPSERV_CRON_DETAIL WHERE DT_NAME = 'TBDD_USER'")
|
||||||
|
JobListener = New JobListener(LogConfig, DB, oDataSet)
|
||||||
|
|
||||||
Dim oListener As New DigitalData.Services.EDMIService.JobListener(LogConfig, DB, oDataSet)
|
DetailRow = oCronDetails.Rows.Item(0)
|
||||||
oListener.SaveDataTables(New DigitalData.Services.EDMIService.JobResult() With {
|
JobResult = New JobResult() With {
|
||||||
.Table = oUsers,
|
.Table = oUsers,
|
||||||
.TableRelationColumn = "GUID",
|
.TableRelationColumn = "GUID",
|
||||||
.ChildTable = oGroupUser,
|
.ChildTable = oGroupUser,
|
||||||
.ChildRelationColumn = "USER_ID"
|
.ChildRelationColumn = "USER_ID"
|
||||||
}, oCronDetails.Rows.Item(0))
|
}
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
||||||
|
JobListener.SaveDataTables(JobResult, DetailRow)
|
||||||
End Sub
|
End Sub
|
||||||
End Class
|
End Class
|
||||||
@@ -26,16 +26,35 @@ Public Class JobListener
|
|||||||
Dataset = ResultDataSet
|
Dataset = ResultDataSet
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Public Sub ReplaceExistingTable(Name As String, Table As DataTable, DataSet As DataSet)
|
Public Sub ReplaceExistingTable(Name As String, Table As DataTable, DataSet As DataSet, Optional ChildTable As DataTable = Nothing)
|
||||||
Dim oDatatableNameTemp As String = Name & "-TEMP"
|
Dim oDatatableNameTemp As String = Name & "-TEMP"
|
||||||
|
|
||||||
_Logger.Debug("DataTable [{0}] exists, renaming and replacing in DataSet", Name)
|
_Logger.Debug("DataTable [{0}] exists, renaming and replacing in DataSet", Name)
|
||||||
' Rename the new table, add TEMP suffix
|
' Rename the new table, add TEMP suffix
|
||||||
Table.TableName = oDatatableNameTemp
|
Table.TableName = oDatatableNameTemp
|
||||||
|
|
||||||
|
' If child table exists, remove all connections to it
|
||||||
|
If ChildTable IsNot Nothing Then
|
||||||
|
' Get name for relations and constraints
|
||||||
|
Dim oRelationName = GetRelationName(Name, ChildTable.TableName)
|
||||||
|
|
||||||
|
' Remove the relation
|
||||||
|
Dim oRelation As DataRelation = DataSet.Relations.Item(oRelationName)
|
||||||
|
DataSet.Relations.Remove(oRelation)
|
||||||
|
|
||||||
|
' Remove the constraint
|
||||||
|
Dim oConstraint As Constraint = ChildTable.Constraints.Item(oRelationName)
|
||||||
|
ChildTable.Constraints.Remove(oConstraint)
|
||||||
|
End If
|
||||||
|
|
||||||
|
' Remove the temp table if it exists
|
||||||
|
If DataSet.Tables.Contains(oDatatableNameTemp) Then
|
||||||
|
DataSet.Tables.Remove(Table)
|
||||||
|
End If
|
||||||
|
|
||||||
' Add the new table to the dataset
|
' Add the new table to the dataset
|
||||||
DataSet.Tables.Add(Table)
|
DataSet.Tables.Add(Table)
|
||||||
' Remove the old table
|
|
||||||
DataSet.Tables.Remove(Name)
|
|
||||||
' Rename the new table
|
' Rename the new table
|
||||||
DataSet.Tables.Item(oDatatableNameTemp).TableName = Name
|
DataSet.Tables.Item(oDatatableNameTemp).TableName = Name
|
||||||
End Sub
|
End Sub
|
||||||
@@ -46,11 +65,15 @@ Public Class JobListener
|
|||||||
DataSet.Tables.Add(Table)
|
DataSet.Tables.Add(Table)
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Public Function GetRelationName(ParentTableName As String, ChildTableName As String) As String
|
||||||
|
Return $"{ParentTableName}-{ChildTableName}"
|
||||||
|
End Function
|
||||||
|
|
||||||
Public Sub AddRelation(ParentTableName As String, ParentColumnName As String, ChildTableName As String, ChildColumnName As String)
|
Public Sub AddRelation(ParentTableName As String, ParentColumnName As String, ChildTableName As String, ChildColumnName As String)
|
||||||
Dim oChild As DataTable = Dataset.Tables.Item(ChildTableName)
|
Dim oChild As DataTable = Dataset.Tables.Item(ChildTableName)
|
||||||
Dim oParent As DataTable = Dataset.Tables.Item(ParentTableName)
|
Dim oParent As DataTable = Dataset.Tables.Item(ParentTableName)
|
||||||
|
|
||||||
Dim oRelationName As String = $"{ParentTableName}-{ChildTableName}"
|
Dim oRelationName As String = GetRelationName(ParentTableName, ChildTableName)
|
||||||
Dim oParentColumn As DataColumn = oParent.Columns.Item(ParentColumnName)
|
Dim oParentColumn As DataColumn = oParent.Columns.Item(ParentColumnName)
|
||||||
Dim oChildColumn As DataColumn = oChild.Columns.Item(ChildColumnName)
|
Dim oChildColumn As DataColumn = oChild.Columns.Item(ChildColumnName)
|
||||||
|
|
||||||
@@ -90,24 +113,18 @@ Public Class JobListener
|
|||||||
Public Sub SaveDataTables(Result As JobResult, DetailRow As DataRow)
|
Public Sub SaveDataTables(Result As JobResult, DetailRow As DataRow)
|
||||||
Try
|
Try
|
||||||
Dim oTable As DataTable = Result.Table
|
Dim oTable As DataTable = Result.Table
|
||||||
|
|
||||||
Dim oName As String = DetailRow.Item("DT_NAME")
|
Dim oName As String = DetailRow.Item("DT_NAME")
|
||||||
Dim oDetailId As Integer = DetailRow.Item("GUID")
|
Dim oDetailId As Integer = DetailRow.Item("GUID")
|
||||||
Dim oDatatableNameTemp As String = oName & "-TEMP"
|
Dim oDatatableNameTemp As String = oName & "-TEMP"
|
||||||
|
|
||||||
If Dataset.Tables.Contains(oName) Then
|
If Dataset.Tables.Contains(oName) Then
|
||||||
|
' Replace existing table
|
||||||
If Result.ChildTable IsNot Nothing Then
|
If Result.ChildTable IsNot Nothing Then
|
||||||
ReplaceExistingTable(Result.ChildTable.TableName, Result.ChildTable, Dataset)
|
ReplaceExistingTable(oName, oTable, Dataset, Result.ChildTable)
|
||||||
End If
|
|
||||||
ReplaceExistingTable(oName, oTable, Dataset)
|
|
||||||
|
|
||||||
If Result.ChildTable IsNot Nothing Then
|
|
||||||
Dim oRelation = Dataset.Relations.Item($"{oTable.TableName}-{Result.ChildTable.TableName}")
|
|
||||||
|
|
||||||
If oRelation IsNot Nothing Then
|
|
||||||
Dataset.Relations.Remove(oRelation)
|
|
||||||
End If
|
|
||||||
|
|
||||||
AddRelation(oName, Result.TableRelationColumn, Result.ChildTable.TableName, Result.ChildRelationColumn)
|
AddRelation(oName, Result.TableRelationColumn, Result.ChildTable.TableName, Result.ChildRelationColumn)
|
||||||
|
Else
|
||||||
|
ReplaceExistingTable(oName, oTable, Dataset)
|
||||||
End If
|
End If
|
||||||
Else
|
Else
|
||||||
AddNewTable(oName, oTable, Dataset)
|
AddNewTable(oName, oTable, Dataset)
|
||||||
|
|||||||
Reference in New Issue
Block a user