Public NotInheritable Class RowNode ''' 可见节点总数 Friend _visibleCount As Integer ''' 节点等级 Private _lever As Integer ''' 动作是否执行 Private _action As Boolean Public Sub New() RowType = RowTypeEnum.DeviceEventAction _action = True Compile = True DeviceAlias = String.Empty Description = String.Empty DelayTime = "0" DelayUnit = "ms" Params = New List(Of AttributeRowNodeTag) Expanded = True Visible = True AllChildCount = 0 _lever = 0 _visibleCount = 0 Nodes = New RowNodes(Me) RowListIndex = 0 RowList = New List(Of RowNode)() RowList.Add(Me) End Sub #Region "节点特有属性" ''' ''' 事件编号 ''' ''' Public Property eventId As String ''' ''' 节点类型 ''' ''' Public Property RowType As RowTypeEnum ''' ''' 节点名称 ''' ''' Public Property Name As String ''' ''' 节点接口属性,从XML读出来,仅对设备对象有效 ''' ''' Public Property [Interface] As String ''' ''' 节点显示文本 ''' ''' Public Property Text As String ''' ''' 节点描述 ''' ''' Public Property Description As String ''' ''' 设备别名 ''' ''' Public Property DeviceAlias As String ''' ''' 设备是否具有别名 ''' ''' Public Property HasAlias As Boolean ''' ''' 设备类型 ''' ''' Public Property DeviceType As String ''' ''' 设备名称 ''' ''' Public Property DeviceName As String ''' ''' 设备方法 ''' ''' Public Property DeviceMothed As String ''' ''' 延时时间 ''' ''' Public Property DelayTime As String ''' ''' DEV_TYPE_DATA ''' ''' Public Property DEV_TYPE_DATA As String ''' ''' PROTOCOL_VER ''' ''' Public Property PROTOCOL_VER As String Public Enum CfgTypeEnum ''' ''' 0.默认类型 ''' CfgType_Default ''' ''' 1.小宝命令集 ''' CfgType_XiaoBaoCMD ''' ''' 2.设备存在 ''' CfgType_DeviceExists End Enum Public Enum RowTypeEnum ''' ''' 0.根节点 ''' RootNode ''' ''' 1.酒店组 ''' HotelGroup ''' ''' 2.酒店项目 ''' Hotel ''' ''' 3.酒店户型 ''' HotelRoomType ''' ''' 4.主机模型 ''' Model ''' ''' 5.主机模型属性集 ''' ModelAttributes ''' ''' 6.主机模型属性分组 ''' ModelAttributeGroup ''' ''' 7.主机模型属性 ''' ModelAttribute ''' ''' 8.模型外设组 ''' DeviceGroup ''' ''' 9.模型外设对象 ''' DeviceObject ''' ''' 10.模型外设属性组 ''' DeviceAttributes ''' ''' 11.模型外设方法组 ''' DeviceMothods ''' ''' 12.模型外设事件组 ''' DeviceEvents ''' ''' 13.模型外设属性 ''' DeviceAttribute ''' ''' 14.模型外设方法 ''' DeviceMothod ''' ''' 15.模型外设事件 ''' DeviceEvent ''' ''' 16.模型外设事件动作执行方式组 ''' DeviceEventActionModeGroup ''' ''' 17.模型外设事件动作执行方式 ''' DeviceEventActionMode ''' ''' 18.模型外设事件条件 ''' DeviceEventConditionItem ''' ''' 19.模型外设事件条件 ''' DeviceEventAllConditions ''' ''' 20.条件组节点 ''' DeviceEventConditions ''' ''' 21.模型外设事件执行动作组集合 ''' DeviceEventAllActions ''' ''' 22.模型外设事件执行动作组 ''' DeviceEventActions ''' ''' 23.模型外设事件执行动作 ''' DeviceEventAction ''' ''' 24.情景模式组 ''' ContextualModels ''' ''' 25.情景模式 ''' ContextualModel ''' ''' 26.外设模型 ''' ExternalModel ''' ''' 27.属性集 = XiaoBaoCMD ''' ModelAttributes_XiaoBaoCMD ''' ''' 28.属性 = XiaoBaoCMD ''' ModelAttribute_XiaoBaoCMD ''' ''' 29.属性集 = 设备存在 ''' ModelAttributes_DeviceExists ''' ''' 30.属性 = 设备存在 ''' ModelAttribute_DeviceExists End Enum ''' ''' 延时单位 ''' ''' Public Property DelayUnit As String ''' ''' 动作执行参数 ''' Public Params As List(Of AttributeRowNodeTag) ''' ''' 动作是否执行,仅代表表格上的勾选状态,参与编译属性参考Compile属性 ''' ''' Public Property Action As Boolean Get Return _action End Get Set(value As Boolean) _action = value UpdateCompile() End Set End Property ''' ''' 动作是否参与编译 ''' ''' Public Property Compile As Boolean ''' ''' 节点标签 ''' ''' Public Property Tag As Object #End Region #Region "节点公共属性" ''' ''' 节点是否处于展开状态 ''' ''' Public Property Expanded() As Boolean ''' ''' 节点是否处于可见状态 ''' ''' Public Property Visible() As Boolean ''' ''' 节点的级别,可见节点级别从0开始 ''' ''' Public Property Lever As Integer Get Return _lever End Get Set(value As Integer) _lever = value For Each node As RowNode In Nodes node.Lever = _lever + 1 Next End Set End Property ''' ''' 节点在父节点中的索引,可见节点级别从0开始 ''' ''' Public Property Index As Integer ''' ''' 下一级子节点总数 ''' ''' Public ReadOnly Property Count() As Integer Get Return Nodes.Count End Get End Property ''' ''' 所有子节点中,可见子节点总数 ''' ''' Public ReadOnly Property VisibleNodesCount() As Integer Get Return _visibleCount End Get End Property ''' ''' 所有子节点总数 ''' ''' Public Property AllChildCount() As Integer ''' ''' 当前节点树的起始节点 ''' ''' Public Property HeadNode() As RowNode ''' ''' 当前节点的父节点 ''' ''' Public Property ParentNode() As RowNode ''' ''' 当前节点的同级上一节点,若当前节点为首节点则返回nothing ''' ''' Public Property PrevNode() As RowNode ''' ''' 当前节点的同级下一节点,若当前节点为尾节点则返回nothing ''' ''' Public Property NextNode() As RowNode ''' ''' 节点所属节点数组的位置,从0开始,即头结点的的索引 ''' ''' Public Property RowListIndex As Integer ''' ''' 节点树的所有节点集合 ''' ''' Public Property RowList As List(Of RowNode) ''' ''' 子节点集合 ''' ''' Public Property Nodes As RowNodes #End Region #Region "节点操作" ''' ''' 更新节点参与编译属性 ''' Friend Sub UpdateCompile() If ParentNode Is Nothing Then Compile = Action Else Compile = Action AndAlso ParentNode.Compile End If For Each node As RowNode In Nodes node.Compile = Action AndAlso node.ParentNode.Compile node.UpdateCompile() Next End Sub ''' ''' 获取所有子节点 ''' Friend Function GetAllChildsNodeList(argRowNode As RowNode, ByVal lstChildNodeList As List(Of RowNode)) As Boolean If argRowNode.Nodes.Count < 1 Then Return False '将指定节点的所有子节点平铺加入到lstChildNodeList列表中 For Each tmpNode As RowNode In argRowNode.Nodes lstChildNodeList.Add(tmpNode) '如有子节点则递归调用,直到子节点数量为零(没有子节点) If tmpNode.Nodes.Count > 0 Then GetAllChildsNodeList(tmpNode, lstChildNodeList) Next Return True End Function ''' ''' 更新可见子节点总数 ''' ''' Friend Sub UpdateVisibleCount(count As Integer) _visibleCount += count If ParentNode IsNot Nothing Then ParentNode.UpdateVisibleCount(count) End Sub ''' ''' 更新子节点可见 ''' Friend Sub UpdateVisible(Optional isForceSetVisible As Boolean = False, Optional isVisible As Boolean = True) For Each node As RowNode In Nodes 'Momo 0416 增加强制参数,某些情况下通过传参强制设定visible状态 If isForceSetVisible = True Then node.Visible = isVisible Else node.Visible = Expanded AndAlso Visible End If node.UpdateVisible() Next End Sub ''' ''' 展开节点 ''' Public Sub Expand() If Expanded Then Return Expanded = True Dim num As Integer For Each node As RowNode In Nodes num += node.VisibleNodesCount + 1 Next UpdateVisibleCount(num) '更新子节点是否可见 UpdateVisible() End Sub ''' ''' 展开所有节点包括子节点 ''' Public Sub ExpandAll() Expand() '展开所有节点 For Each node As RowNode In Nodes node.ExpandAll() '展开的同时,设置属性为可见 node.Visible = True Next End Sub ''' ''' 折叠节点 ''' Public Sub Collapse() If Expanded = False Then Return Expanded = False '更新可见总数 Dim num As Integer For Each node As RowNode In Nodes num += node.VisibleNodesCount + 1 Next UpdateVisibleCount(0 - num) '更新子节点是否可见 UpdateVisible() End Sub ''' ''' 收缩所有节点包括子节点 ''' Public Sub CollapseAll() Collapse() '收缩所有节点 For Each node As RowNode In Nodes node.CollapseAll() Next End Sub ''' ''' 展开或折叠节点 ''' Public Sub Toggle() If Expanded Then Collapse() Else Expand() End If End Sub ''' ''' 增加子节点 ''' Public Sub AddNode(node As RowNode) Nodes.Add(node) End Sub ''' ''' 插入子节点 ''' Public Sub InsertNode(index As Integer, childNode As RowNode) Nodes.Insert(index, childNode) End Sub Public Sub RemoveChildNode(childNode As RowNode) Nodes.Remove(childNode) End Sub Public Sub RemoveChildAt(index As Integer) If index >= Nodes.Count Then Return Dim child As RowNode = CType(Nodes.Item(index), RowNode) Nodes.RemoveAt(index) End Sub ''' ''' 移除本身节点 ''' Public Function Remove() As Boolean ParentNode.Nodes.Remove(Me) Return True End Function ''' ''' 清空节点所有子节点 ''' Public Sub Clear() Nodes.Clear() End Sub ''' ''' 节点上移 ''' Public Sub MoveUp() If Index = 0 Then Return If Remove() = False Then Return ParentNode.Nodes.Insert(Index - 1, Me) End Sub ''' ''' 节点下移 ''' Public Sub MoveDown() If Index = ParentNode.Nodes.Count - 1 Then Return If Remove() = False Then Return ParentNode.Nodes.Insert(Index + 1, Me) End Sub ''' ''' 节点左移 ''' Public Sub MoveLeft() If _lever = 0 Then Return If Remove() = False Then Return ParentNode.ParentNode.Nodes.Insert(ParentNode.Index + 1, Me) '更新节点可见与可见子节点数 End Sub ''' ''' 节点右移 ''' Public Sub MoveRight() If Index = 0 Then Return If Remove() = False Then Return Dim rNode As RowNode = CType(ParentNode.Nodes(Index - 1), RowNode) rNode.Nodes.Add(Me) '更新节点可见与可见子节点数 End Sub '''' '''' 交换两个节点信息 err '''' '''' 'Public Function Exchange(ByRef argRowNode1 As RowNode, ' ByRef argRowNode2 As RowNode, ' ByRef argErrMsg As String) As Boolean ' Try ' If argRowNode1.RowType <> argRowNode2.RowType Then ' argErrMsg = "两个节点类型不同,不可进行交换!" ' Return False ' End If ' Dim tmpNode As RowNode = argRowNode1 ' argRowNode1 = argRowNode2 ' argRowNode2 = tmpNode ' Catch ex As Exception ' argErrMsg = ex.Message.ToString ' Return False ' End Try ' Return True 'End Function ''' ''' 节点深复制,创建一个完全相同信息的节点(功能待测试) ''' ''' Public Function Clone() As RowNode Dim cpNode As New RowNode With cpNode .RowType = RowType .Action = Action .Nodes = New RowNodes(cpNode) 'todo:克隆功能待重写 End With Return cpNode End Function #End Region #Region "节点类型" #End Region End Class