Imports DevExpress.XtraLayout
Imports DigitalData.GUIs.ClientSuite.Controls

Public Class frmWorkflowStep
    Private _ControlLoader As ControlLoader
    Private _ControlData As ControlData

    Private _FormId As Int64
    Private _ProcessRequestId As Int64
    Private _ProcessName As String
    Private _RequestName As String

    Private _HeaderGroup As LayoutControlGroup
    Private _BodyGroup As LayoutControlGroup

    Public Sub New(ProcessRequestId As Int64)
        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        _ProcessRequestId = ProcessRequestId
    End Sub

    Private Async Function GetRequestData(RequestId) As Task
        Await My.Channel.CreateDatabaseRequestAsync("Get Request Data", True)
        Dim oSQL = $"SELECT RECORD_ID,PROCESS_NAME, REQUEST_TITLE, FORMID FROM VWIDB_PROCESS_REQUEST WHERE RECORD_ID = {RequestId}"
        If My.Application.Service.Online = False Then

        End If
        Dim oResult = Await My.Channel.ReturnDatatableAsync(oSQL)

        If Not oResult.OK Then
            Throw New ApplicationException("Request data could not be fetched!")
            ShowErrorMessage(oResult.ErrorMessage)
        End If

        My.Channel.CloseDatabaseRequest()

        Dim oRows = oResult.Table.Rows

        If oRows.Count = 1 Then
            _FormId = oRows.Item(0).Item("FORMID")
            _ProcessName = oRows.Item(0).Item("PROCESS_NAME")
            _RequestName = oRows.Item(0).Item("REQUEST_TITLE")
        Else
            Throw New ApplicationException("Request data could not be fetched!")
        End If
    End Function


    Private Async Sub frmWorkflowStep_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Await GetRequestData(_ProcessRequestId)

        Dim oControlTable = Await My.Common.Views.VWIDB_FORM_CONTROL(_FormId)
        Dim oControlData = Await My.Common.Views.VWIDB_CONTROL_DATA(_ProcessRequestId)

        _HeaderGroup = LayoutControlGroupMain.AddGroup("Request Header")
        _BodyGroup = LayoutControlGroupMain.AddGroup("Control Body")

        _ControlLoader = New ControlLoader(My.LogConfig, _BodyGroup)
        _ControlData = New ControlData(My.LogConfig)

        LayoutControl1.BeginUpdate()

        _ControlLoader.LoadControls(oControlTable)
        _ControlData.LoadControlData(_ControlLoader.LayoutControls, oControlData)

        LayoutControl1.EndUpdate()

        _ControlLoader.AddControl("Process Name", _ProcessName, _HeaderGroup)
        _ControlLoader.AddControl("Request Name", _RequestName, _HeaderGroup)
    End Sub

    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

    End Sub
End Class