Public Class ClassConstructors
    Public Shared ConstructorsTuple_TreeView As Object
    Public Shared Function Init_Tuple()

    Dim ConstructTreeViewTuple = New Dictionary(Of Tuple(Of TreeView), Integer)()
        Dim sql = String.Format("Select DISTINCT T.GUID, T2.ENTITY_ID FROM TBPMO_FORM_CONSTRUCTOR T, TBPMO_FORM_CONSTRUCTOR_DETAIL T1, " &
                                "TBPMO_STRUCTURE_NODES_CONFIGURATION T2 WHERE T.GUID = T1.CONSTRUCT_ID And T1.FORM_ID = T2.ENTITY_ID " &
                                "And T.GUID In (Select CONSTRUCT_ID FROM TBPMO_CONSTRUCTOR_USER WHERE USER_ID = {0})", USER_GUID)
        Dim DT As DataTable = MYDB_ECM.GetDatatable(sql)
        For Each rowconstruct As DataRow In DT.Rows
            Try
                Dim sqlnodes = String.Format("select * from VWPMO_STRUCTURE_NODES where ENTITY_ID IN (SELECT FORM_ID FROM VWPMO_CONSTRUCTOR_FORMS WHERE CONSTRUCT_ID = {0})", rowconstruct.Item(0))
                Dim DTNODES As DataTable = MYDB_ECM.GetDatatable(sqlnodes)

                Dim sqlimage = String.Format("select * from TBPMO_STRUCTURE_NODES_CONFIGURATION where ENTITY_ID IN (SELECT FORM_ID FROM VWPMO_CONSTRUCTOR_FORMS WHERE CONSTRUCT_ID = {0})", rowconstruct.Item(0))
                Dim DT_TREEVIEW_CONFIGURATION = MYDB_ECM.GetDatatable(sql)
                Dim TREEVIEW_IMAGELIST = New ImageList

                For Each row As DataRow In DT_TREEVIEW_CONFIGURATION.Rows
                    Try
                        Dim bimage = row.Item("NODE_IMAGE")
                        If Not IsDBNull(bimage) Then
                            Dim Node_image = ByteArrayToBitmap(bimage)
                            TREEVIEW_IMAGELIST.Images.Add(row.Item("GUID").ToString, Node_image) 'row.Item("GUID").ToString & "#" & row.Item("ENTITY_ID")
                        End If
                    Catch ex As Exception

                    End Try

                Next

                'Dim async As New ClassAsyncNodeBuild(DTNODES, TREEVIEW_IMAGELIST)
                'async.bw.RunWorkerAsync()
                'While async.bw.IsBusy
                '    Application.DoEvents()
                'End While
                Dim MyTreeview As TreeView = ClassNodeNavigation.CreateTreeViewNodes(DTNODES, TREEVIEW_IMAGELIST)
                ConstructTreeViewTuple.Add(Tuple.Create(MyTreeview), rowconstruct.Item(0))
            Catch ex As Exception
                ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error", ex.Message, "Error in Adding TreeView to Dictionary: ")
            End Try



        Next

        ConstructorsTuple_TreeView = ConstructTreeViewTuple

    End Function



    Public Shared Function Check_TreeViewLoaded(CONSTRUCTID As Integer)
        Try
            For Each constrid As Integer In ConstructorsTuple_TreeView.keys
                If constrid = CONSTRUCTID Then
                    Return True
                End If
            Next
            Return False
        Catch ex As Exception
            LOGGER.Warn("Error in Check_TreeViewLoaded: " & ex.Message)
            Return False
        End Try
    End Function

End Class
