Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Services.EDMIService

Public Class frmRelations
    Private DB As MSSQLServer
    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
        LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath)
        DB = New MSSQLServer(LogConfig, "Server=SDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM_TEST;User Id=sa;Password=dd;")

        Dim oDataSet As New DataSet()

        Dim oUsers = DB.GetDatatable("SELECT * FROM TBDD_USER")
        oUsers.TableName = "TBDD_USER"
        Dim oGroupUser = DB.GetDatatable("SELECT * FROM TBDD_GROUPS_USER")
        oGroupUser.TableName = "TBDD_GROUPS_USER"

        Dim oCronDetails As DataTable = DB.GetDatatable("SELECT * FROM TBAPPSERV_CRON_DETAIL WHERE DT_NAME = 'TBDD_USER'")
        JobListener = New JobListener(LogConfig, DB, oDataSet)

        DetailRow = oCronDetails.Rows.Item(0)
        JobResult = New JobResult() With {
            .Tables = New List(Of JobResult.ResultTable) From {
                New JobResult.ResultTable() With {
                    .Table = oUsers,
                    .TableRelationColumn = "GUID",
                    .ChildTable = oGroupUser,
                    .ChildRelationColumn = "USER_ID"
                }
            }
        }

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        JobListener.SaveDataTables(JobResult.Tables.First)
    End Sub
End Class