⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maintreecode.bas

📁 Data monkey是一个强大的是数据传输和转换应用程序。使用DataMonkey用户可以把复杂的文本文件格式
💻 BAS
📖 第 1 页 / 共 3 页
字号:
            Set tiGetTreeItem = di.GetActions(siKey)
            
        Case etiType.tioutputlinks
            Set tiGetTreeItem = GImport.GetOutputLinksManager(siKey)
        Case Else
            Set tiGetTreeItem = .Nodes(siKey)
    End Select
    End With
    
    ' Release all our references.
    Set act = Nothing
    Set cp = Nothing
    Set di = Nothing
    
    Exit Function
eHandler:
    LogError "MainTreeCode", "tiGetTreeItem", Error(Err), False
'
End Function

' This function figures out the correct way to add an item to a tree.
' Usually called when Paste'ing a new item into the tree.
Public Sub AutoAddTreeItem(ParentKey As String, NewObject As Object, _
                            NewObjectType As etiType)
    On Error GoTo eHandler
    
    Dim ParentType As etiType
    Dim cp As CInputRecord
    Dim di As CInputField
    Dim act As Object
    Dim TempKey As String
    
    ParentType = frmDocument.TreeView1.Nodes(ParentKey).tag
    With frmDocument.TreeView1
    Select Case NewObjectType
    
        Case etiType.ticheckpoint
            If ParentType = tiLinesFolder Then
                Set cp = NewObject
                AddTreeItem ParentKey, cp.GetID, cp.name, _
                            NewObjectType, "CheckPoint"
                
                ' Add a fields folder for this checkpoint.
                TempKey = GetUniqueID()
                AddTreeItem cp.GetID, TempKey, "Fields", _
                    etiType.tiFieldsFolder, "ClosedFolder"
                
                ' Fill in the actions for the checkpoint.
                For Each act In cp.GetActions()
                    ' Add the action item.
                    AutoAddTreeItem cp.GetID, act, tiCheckpointAction
                Next act
                
                ' Add the fields.
                For Each di In cp.GetDataPoints
                    AutoAddTreeItem TempKey, di, tidataitem
                Next di
            Else
                LogError "MainTreeCode", "AutoAddTreeItem", _
                    "A CheckPoint object can only be added to a CheckPoint folder", False
            End If
            
        Case etiType.tidataitem
            If ParentType = tiFieldsFolder Then
                Set di = NewObject

                AddTreeItem ParentKey, di.GetID, di.name, _
                            NewObjectType, "DataItem"
                
                ' Fill in the actions for the checkpoint.
                For Each act In di.GetActions()
                    ' Add the action item.
                    AutoAddTreeItem di.GetID, act, tiDataItemAction
                Next act
            
            Else
                LogError "MainTreeCode", "AutoAddTreeItem", _
                    "A DataItem object can only be added to a DataItem folder", False
            End If
        
        Case etiType.tioutputlinks
            If ParentType = tiOutputFolder Then
                ' Add output links object.
                AddTreeItem ParentKey, NewObject.GetID, _
                            NewObject.name, _
                            NewObjectType, "Output"
            
                ' Add Schema object.
                AddTreeItem NewObject.GetID, GetUniqueID, _
                            NewObject.OutputSourceName, _
                            tioutputobject, "OutputSchema"
            Else
                LogError "MainTreeCode", "AutoAddTreeItem", _
                    "A OutputLinks object can only be added to a OutputLinks folder", False
            End If
        
        Case etiType.tiCheckpointAction, etiType.tiDataItemAction, _
            etiType.tiImportAction
                        
    ' Also need to make sure that the action being added is a valid
    ' action type for the type of folder being added to.
            
            If ParentType = ticheckpoint Or _
                ParentType = tiInputFolder Then

                ' Add as the next to last item (the item before the "Fields" folder.
                TempKey = .Nodes(ParentKey).Child.LastSibling.key
                tiAddTreeItemBefore TempKey, NewObject.GetID, _
                            NewObject.GetSpecificDescription, _
                            NewObjectType, "Action"

            ElseIf ParentType = tidataitem Then
                AddTreeItem ParentKey, NewObject.GetID, _
                            NewObject.GetSpecificDescription, _
                            NewObjectType, "Action"
            
            Else
                LogError "MainTreeCode", "AutoAddTreeItem", _
                    "An Action object can only be added to an Action folder", False
            End If

        Case Else
            LogError "MainTreeCode", "AutoAddTreeItem", _
                "Can't add indicated type to tree using AutoAdd", False
    End Select
    End With
    
    Exit Sub

eHandler:
    LogError "MainTreeCode", "AutoAddTreeItem", Error(Err), False
    
End Sub

Public Sub AddTreeItem(ParentKey As String, key As Variant, _
                        DisplayText As String, _
                        tag As Variant, ImageTag As String)
    On Error GoTo eHandler
    Dim newItem As ComctlLib.node
    
    With frmDocument.TreeView1
        If ParentKey = "" Then
            ' Add a root item.
            Set newItem = .Nodes.Add(, , key, DisplayText)
        Else
            Set newItem = .Nodes.Add(ParentKey, _
                tvwChild, key, DisplayText)
        End If

        newItem.Image = ImageTag
        newItem.tag = tag

    End With
    
    Set newItem = Nothing
    Exit Sub
eHandler:
    LogError "MainTreeCode", "AddTreeItem", Error(Err), False
'
End Sub


' Add a tree item below another tree item.
Public Sub tiAddTreeItemBefore(SiblingKey As String, key As Variant, _
                        DisplayText As String, _
                        tag As Variant, ImageTag As String)
    On Error GoTo eHandler
    Dim newItem As ComctlLib.node
    
    With frmDocument.TreeView1
        Set newItem = .Nodes.Add(SiblingKey, _
            tvwPrevious, key, DisplayText)
        
        newItem.Image = ImageTag
        newItem.tag = tag

    End With
    
    Set newItem = Nothing
    Exit Sub
eHandler:
    LogError "MainTreeCode", "AddTreeItemBefore", Error(Err), False
'
End Sub

' Add a tree item below another tree item.
Public Sub tiAddTreeItemAfter(SiblingKey As String, key As Variant, _
                        DisplayText As String, _
                        tag As Variant, ImageTag As String)
    On Error GoTo eHandler
    Dim newItem As ComctlLib.node
    
    With frmDocument.TreeView1
        Set newItem = .Nodes.Add(SiblingKey, _
            tvwNext, key, DisplayText)
        
        newItem.Image = ImageTag
        newItem.tag = tag

    End With
    
    Set newItem = Nothing
    Exit Sub
eHandler:
    LogError "MainTreeCode", "AddTreeItemBefore", Error(Err), False
'
End Sub

Public Sub FillCheckPointTree()

    On Error GoTo eHandler
    
    Dim newItem As node
    Dim di As CInputField
    Dim cp As CInputRecord
    Dim act As Object
    Dim ol As COutputLinks
    
    ' Not the best place for this, but until we start loading
    ' new projects into new windows, this is the easiest thing.
    frmDocument.SetTitle
    
    ' Delete any existing items from the tree.
    frmDocument.TreeView1.Nodes.Clear

    ' Import name.
    AddTreeItem "", GImport.GetID, GImport.name, tiimport, "Import"

    ' Add the 'Input' folder.
    Dim InputFolderKey As String
    InputFolderKey = GetUniqueID()
    AddTreeItem GImport.GetID, InputFolderKey, "Input", _
        tiInputFolder, "ClosedFolder"
    
    ' Fill in the actions for the import.
    For Each act In GImport.GetActions()
        AddTreeItem InputFolderKey, act.GetID, _
            act.GetSpecificDescription, tiImportAction, "Action"
    Next act
    
    ' Add the 'Records' folder.
    Dim LinesFolderKey As String
    LinesFolderKey = GetUniqueID()
    AddTreeItem InputFolderKey, LinesFolderKey, "Records", _
        etiType.tiLinesFolder, "ClosedFolder"

    ' Fill in the checkpoints for the import.
    For Each cp In GImport.GetCheckPoints()
        
        ' Add the checkpoint item.
        AddTreeItem LinesFolderKey, cp.GetID, cp.name, ticheckpoint, "CheckPoint"

        ' Fill in the actions for the checkpoint.
        For Each act In cp.GetActions()
            ' Add the action item.
            AddTreeItem cp.GetID, act.GetID, _
                    act.GetSpecificDescription, tiCheckpointAction, "Action"
        Next act
        
        ' Add the 'Fields' folder.
        Dim FieldsFolderKey As String
        FieldsFolderKey = GetUniqueID
        AddTreeItem cp.GetID, FieldsFolderKey, "Fields", _
            etiType.tiFieldsFolder, "ClosedFolder"
                
        ' Display the datapoints for each checkpoint.
        For Each di In cp.GetDataPoints()

            AddTreeItem FieldsFolderKey, di.GetID, di.name, tidataitem, "DataItem"
            
            ' Fill in the actions for the dataitem.
            For Each act In di.GetActions()
                AddTreeItem di.GetID, act.GetID, act.GetSpecificDescription, _
                    tiDataItemAction, "Action"
            Next act
        Next di
    Next cp
    
    ' Add the 'Output' folder.
    Dim OutputFolderKey As String
    OutputFolderKey = GetUniqueID()
    AddTreeItem GImport.GetID, OutputFolderKey, "Output", _
        tiOutputFolder, "ClosedFolder"

    ' Fill in the output objects.
    For Each ol In GImport.GetOutputLinksManager()
        AddTreeItem OutputFolderKey, ol.GetID, _
            ol.name, tioutputlinks, "Output"
            
        AddTreeItem ol.GetID, GetUniqueID, ol.OutputSourceName, _
                        tioutputobject, "OutputSchema"
    Next ol

    Exit Sub
    
eHandler:
    LogError "frmDocument", "FillCheckPointTree", Error(Err)
    
End Sub


Public Sub AddNewAction()
    On Error GoTo eHandler

    Dim act As Object
    Dim cp As CInputRecord
    Dim di As CInputField

    Dim pKey As String  ' Parent key
    Dim key As String
    Dim tag As String
    
    With frmDocument.TreeView1
    Select Case tiGetSelectedItemType()

        Case etiType.tiInputFolder
    
            ' Load the form which will add the new action object.
            frmSelectActionType.Initialize _
                eCmdApplications.appIMPORT, GImport.name, GImport.GetActions
            frmSelectActionType.Show vbModal
            
            ' If we added a new action, add it to the tree.
            If GFormReturnValue = vbOK Then
            
                ' Get the key for the next to the last item in the
                ' particular sublist we are adding to. The LAST item
                ' is a folder.
                key = .SelectedItem.Child.LastSibling.key
                
                ' Get a reference to the new action.
                Set act = GImport.GetAction(GImport.GetActions.Count)
                tiAddTreeItemBefore key, act.GetID, act.GetSpecificDescription, _
                            etiType.tiImportAction, "Action"
            End If
            
        
        Case etiType.ticheckpoint
    
            ' Get the checkpoint we are working with.
            Set cp = GImport.GetCheckPoint(.SelectedItem.key)

            ' Load the form which will add the new action object.
            frmSelectActionType.Initialize _
                eCmdApplications.appCheckPoint, cp.name, cp.GetActions
            
            frmSelectActionType.Show vbModal
            If GFormReturnValue = vbOK Then
                ' Get a reference to the new action.
                Set act = cp.GetAction(cp.GetActions.Count)

                ' Get the key for the next to the last item in the
                ' particular sublist we are adding to. The LAST item
                ' is a folder.
                key = .SelectedItem.Child.LastSibling.key
                
                ' Add the new item to the tree.
                tiAddTreeItemBefore key, act.GetID, act.GetSpecificDescription, _
                            etiType.tiCheckpointAction, "Action"

            End If
            
        Case etiType.tidataitem
    
            ' Get the checkpoint we are working with.
            Set cp = GImport.GetCheckPoint(.SelectedItem.parent.parent.key)
            Set di = cp.GetDataPoint(.SelectedItem.key)

            ' Load the form which will add the new action object.
            frmSelectActionType.Initialize _
                eCmdApplications.appDataItem, di.name, di.GetActions
            frmSelectActionType.Show vbModal

            ' If we have a new item, add it to the tree.
            If GFormReturnValue = vbOK Then
                ' Get a reference to the new action.
                Set act = di.GetAction(di.GetActions.Count)
                key = .SelectedItem.key
                AddTreeItem key, act.GetID, act.GetSpecificDescription, _
                            etiType.tiDataItemAction, "Action"
            End If
        Case Else
            Exit Sub
    End Select
    End With
    
    If GFormReturnValue = vbOK Then
        GImport.dirty = True
    End If
    
    ' Release all our references.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -