1291 lines
50 KiB
VB.net
1291 lines
50 KiB
VB.net
Imports System.Text
|
||
Imports BLV_Studio.GridModel
|
||
Imports BLV_Studio.GridModel.DeviceEventModel
|
||
Imports FlexCell
|
||
|
||
Public Class MoveUpCommand
|
||
Inherits GridCommand
|
||
|
||
Private _model As DeviceEventModel
|
||
|
||
Private _selectFirstRow As Integer
|
||
Private _selectLastRow As Integer
|
||
Private _selectFirstCol As Integer
|
||
Private _selectLastCol As Integer
|
||
|
||
Private _grd As FlexCell.Grid
|
||
|
||
Sub New(model As DeviceEventModel)
|
||
_model = model
|
||
_grd = model.Grid
|
||
|
||
_selectFirstRow = _grd.Selection.FirstRow
|
||
_selectLastRow = _grd.Selection.LastRow
|
||
_selectFirstCol = _grd.Selection.FirstCol
|
||
_selectLastCol = _grd.Selection.LastCol
|
||
End Sub
|
||
|
||
Public Overrides Sub Redo()
|
||
Dim startRow As Integer = _selectFirstRow
|
||
Dim selectCount As Integer = _selectLastRow - _selectFirstRow + 1
|
||
|
||
Dim moveDownRow As Integer '下移动前起始位置
|
||
Dim moveDownCount As Integer '下移动总量
|
||
Dim moveUpRow As Integer '上移动前起始位置
|
||
Dim moveUpCount As Integer '上移动总量
|
||
|
||
Dim nodeCount As Integer
|
||
Dim node As RowNode = _model.FindRowNode(startRow)
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.ContextualModel
|
||
|
||
Case RowNode.RowTypeEnum.DeviceEventActions
|
||
|
||
|
||
|
||
Case RowNode.RowTypeEnum.DeviceEventAction
|
||
|
||
Case Else
|
||
Throw New Exception($"当前行[{node.RowListIndex}]不允许移动,移动已终止")
|
||
End Select
|
||
moveUpRow = node.RowListIndex
|
||
|
||
Dim preNode As RowNode = node.PrevNode
|
||
If preNode Is Nothing Then Return '初始节点不允许上移
|
||
moveDownRow = preNode.RowListIndex '下移动前起始位置
|
||
moveDownCount = preNode.AllChildCount + 1 '下移动总量
|
||
|
||
Dim nextNode As RowNode = node
|
||
While nextNode IsNot Nothing AndAlso moveUpCount < selectCount
|
||
If nextNode.RowType <> node.RowType Then Exit While '跨类型
|
||
moveUpCount += nextNode.AllChildCount + 1
|
||
nodeCount += 1
|
||
nextNode = nextNode.NextNode
|
||
End While
|
||
|
||
'更新内存
|
||
While nodeCount > 0
|
||
preNode.MoveDown()
|
||
nodeCount -= 1
|
||
End While
|
||
|
||
|
||
'更新表格
|
||
_model.UpdateGrid(moveDownRow, moveDownCount, moveUpRow, moveUpCount)
|
||
|
||
_selectFirstRow = _selectFirstRow - moveDownCount
|
||
_selectLastRow = _selectFirstRow + selectCount - 1
|
||
|
||
_grd.Range(_selectFirstRow, _selectFirstCol, _selectLastRow, _selectLastCol).SelectCells()
|
||
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
|
||
End Sub
|
||
|
||
Public Overrides Sub Undo()
|
||
Dim startRow As Integer = _selectFirstRow
|
||
Dim selectCount As Integer = _selectLastRow - _selectFirstRow + 1
|
||
|
||
Dim moveDownRow As Integer '下移动前起始位置
|
||
Dim moveDownCount As Integer '下移动总量
|
||
Dim moveUpRow As Integer '上移动前起始位置
|
||
Dim moveUpCount As Integer '上移动总量
|
||
|
||
Dim nodeCount As Integer
|
||
Dim node As RowNode = _model.FindRowNode(startRow)
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.ContextualModel
|
||
|
||
Case RowNode.RowTypeEnum.DeviceEventActions
|
||
|
||
|
||
|
||
Case RowNode.RowTypeEnum.DeviceEventAction
|
||
|
||
Case Else
|
||
Throw New Exception($"当前行[{node.RowListIndex}]不允许移动,移动已终止")
|
||
End Select
|
||
moveDownRow = node.RowListIndex
|
||
|
||
Dim nextNode As RowNode = node
|
||
While nextNode IsNot Nothing AndAlso moveDownCount < selectCount
|
||
If nextNode.RowType <> node.RowType Then Exit While '跨类型
|
||
moveDownCount += nextNode.AllChildCount + 1
|
||
nodeCount += 1
|
||
nextNode = nextNode.NextNode
|
||
End While
|
||
|
||
If nextNode Is Nothing Then Return
|
||
moveUpRow = nextNode.RowListIndex
|
||
moveUpCount = nextNode.AllChildCount + 1
|
||
|
||
'更新内存
|
||
While nodeCount > 0
|
||
nextNode.MoveUp()
|
||
nodeCount -= 1
|
||
End While
|
||
|
||
'更新表格
|
||
_model.UpdateGrid(moveDownRow, moveDownCount, moveUpRow, moveUpCount)
|
||
|
||
_selectFirstRow = _selectFirstRow + moveUpCount
|
||
_selectLastRow = _selectFirstRow + selectCount - 1
|
||
|
||
_grd.Range(_selectFirstRow, _selectFirstCol, _selectLastRow, _selectLastCol).SelectCells()
|
||
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
End Sub
|
||
End Class
|
||
|
||
Public Class MoveDownCommand
|
||
Inherits GridCommand
|
||
|
||
Private _model As DeviceEventModel
|
||
|
||
Private _selectFirstRow As Integer
|
||
Private _selectLastRow As Integer
|
||
Private _selectFirstCol As Integer
|
||
Private _selectLastCol As Integer
|
||
|
||
Private _grd As FlexCell.Grid
|
||
|
||
Sub New(model As DeviceEventModel)
|
||
_model = model
|
||
_grd = model.Grid
|
||
|
||
_selectFirstRow = _grd.Selection.FirstRow
|
||
_selectLastRow = _grd.Selection.LastRow
|
||
_selectFirstCol = _grd.Selection.FirstCol
|
||
_selectLastCol = _grd.Selection.LastCol
|
||
End Sub
|
||
|
||
Public Overrides Sub Undo()
|
||
Dim startRow As Integer = _selectFirstRow
|
||
Dim selectCount As Integer = _selectLastRow - _selectFirstRow + 1
|
||
|
||
Dim moveDownRow As Integer '下移动前起始位置
|
||
Dim moveDownCount As Integer '下移动总量
|
||
Dim moveUpRow As Integer '上移动前起始位置
|
||
Dim moveUpCount As Integer '上移动总量
|
||
|
||
Dim nodeCount As Integer
|
||
Dim node As RowNode = _model.FindRowNode(startRow)
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.ContextualModel
|
||
|
||
Case RowNode.RowTypeEnum.DeviceEventActions
|
||
|
||
|
||
Case RowNode.RowTypeEnum.DeviceEventAction
|
||
|
||
Case Else
|
||
Throw New Exception($"当前行[{node.RowListIndex}]不允许移动,移动已终止")
|
||
End Select
|
||
moveUpRow = node.RowListIndex
|
||
|
||
Dim preNode As RowNode = node.PrevNode
|
||
If preNode Is Nothing Then Return '初始节点不允许上移
|
||
moveDownRow = preNode.RowListIndex '下移动前起始位置
|
||
moveDownCount = preNode.AllChildCount + 1 '下移动总量
|
||
|
||
Dim nextNode As RowNode = node
|
||
While nextNode IsNot Nothing AndAlso moveUpCount < selectCount
|
||
If nextNode.RowType <> node.RowType Then Exit While '跨类型
|
||
moveUpCount += nextNode.AllChildCount + 1
|
||
nodeCount += 1
|
||
nextNode = nextNode.NextNode
|
||
End While
|
||
|
||
'更新内存
|
||
While nodeCount > 0
|
||
preNode.MoveDown()
|
||
nodeCount -= 1
|
||
End While
|
||
|
||
'更新表格
|
||
_model.UpdateGrid(moveDownRow, moveDownCount, moveUpRow, moveUpCount)
|
||
|
||
_selectFirstRow = _selectFirstRow - moveDownCount
|
||
_selectLastRow = _selectFirstRow + selectCount - 1
|
||
_grd.Range(_selectFirstRow, _selectFirstCol, _selectLastRow, _selectLastCol).SelectCells()
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
End Sub
|
||
|
||
Public Overrides Sub Redo()
|
||
Dim startRow As Integer = _selectFirstRow
|
||
Dim selectCount As Integer = _selectLastRow - _selectFirstRow + 1
|
||
|
||
Dim moveDownRow As Integer '下移动前起始位置
|
||
Dim moveDownCount As Integer '下移动总量
|
||
Dim moveUpRow As Integer '上移动前起始位置
|
||
Dim moveUpCount As Integer '上移动总量
|
||
|
||
Dim nodeCount As Integer
|
||
Dim node As RowNode = _model.FindRowNode(startRow)
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.ContextualModel
|
||
|
||
Case RowNode.RowTypeEnum.DeviceEventActions
|
||
|
||
|
||
Case RowNode.RowTypeEnum.DeviceEventAction
|
||
|
||
Case Else
|
||
Throw New Exception($"当前行[{node.RowListIndex}]不允许移动,移动已终止")
|
||
End Select
|
||
moveDownRow = node.RowListIndex
|
||
|
||
Dim nextNode As RowNode = node
|
||
While nextNode IsNot Nothing AndAlso moveDownCount < selectCount
|
||
If nextNode.RowType <> node.RowType Then Exit While '跨类型
|
||
moveDownCount += nextNode.AllChildCount + 1
|
||
nodeCount += 1
|
||
nextNode = nextNode.NextNode
|
||
End While
|
||
|
||
If nextNode Is Nothing Then Return
|
||
moveUpRow = nextNode.RowListIndex
|
||
moveUpCount = nextNode.AllChildCount + 1
|
||
|
||
'更新内存
|
||
While nodeCount > 0
|
||
nextNode.MoveUp()
|
||
nodeCount -= 1
|
||
End While
|
||
|
||
'更新表格
|
||
_model.UpdateGrid(moveDownRow, moveDownCount, moveUpRow, moveUpCount)
|
||
|
||
_selectFirstRow = _selectFirstRow + moveUpCount
|
||
_selectLastRow = _selectFirstRow + selectCount - 1
|
||
|
||
_grd.Range(_selectFirstRow, _selectFirstCol, _selectLastRow, _selectLastCol).SelectCells()
|
||
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
End Sub
|
||
End Class
|
||
|
||
Public Class AddNodeRowsCommand
|
||
Inherits GridCommand
|
||
|
||
Private _model As DeviceEventModel
|
||
|
||
Private _selectFirstRow As Integer
|
||
Private _selectLastRow As Integer
|
||
Private _selectFirstCol As Integer
|
||
Private _selectLastCol As Integer
|
||
|
||
Private _grd As FlexCell.Grid
|
||
Private _nodes As List(Of RowNode)
|
||
|
||
Sub New(model As DeviceEventModel, nodes As List(Of RowNode))
|
||
_model = model
|
||
_grd = model.Grid
|
||
|
||
_selectFirstRow = _grd.Selection.FirstRow
|
||
_selectLastRow = _grd.Selection.LastRow
|
||
_selectFirstCol = _grd.Selection.FirstCol
|
||
_selectLastCol = _grd.Selection.LastCol
|
||
|
||
_nodes = nodes
|
||
End Sub
|
||
|
||
Public Overrides Sub Undo()
|
||
_model.LockGridAutoRedraw()
|
||
For i = 0 To _nodes.Count - 1
|
||
_model.RemoveNodeRow(_nodes(i))
|
||
Next
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
_model.UnLockGridAutoRedraw()
|
||
End Sub
|
||
|
||
|
||
Public Overrides Sub Redo()
|
||
Dim node As RowNode = _model.FindRowNode(_selectFirstRow)
|
||
|
||
_model.LockGridAutoRedraw()
|
||
_model.SkipCellChange = True
|
||
For i = 0 To _nodes.Count - 1
|
||
'添加内存行
|
||
node.AddNode(_nodes(i))
|
||
|
||
'添加数据行
|
||
_model.AddNodeRow(_nodes(i), True)
|
||
Next
|
||
If node.Count > 0 Then node.Expand()
|
||
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
|
||
_model.SkipCellChange = False
|
||
_model.UnLockGridAutoRedraw()
|
||
End Sub
|
||
End Class
|
||
|
||
Public Class DeleteRowsCommand
|
||
Inherits GridCommand
|
||
|
||
Private _model As DeviceEventModel
|
||
|
||
Private _selectFirstRow As Integer
|
||
Private _selectLastRow As Integer
|
||
Private _selectFirstCol As Integer
|
||
Private _selectLastCol As Integer
|
||
|
||
Private _grd As FlexCell.Grid
|
||
Private _nodes As List(Of RowNode)
|
||
|
||
|
||
Sub New(model As DeviceEventModel)
|
||
_model = model
|
||
_grd = model.Grid
|
||
|
||
_selectFirstRow = _grd.Selection.FirstRow
|
||
_selectLastRow = _grd.Selection.LastRow
|
||
_selectFirstCol = _grd.Selection.FirstCol
|
||
_selectLastCol = _grd.Selection.LastCol
|
||
|
||
_nodes = New List(Of RowNode)
|
||
End Sub
|
||
|
||
Public Overrides Sub Undo()
|
||
_model.LockGridAutoRedraw()
|
||
_model.SkipCellChange = True
|
||
Dim pNode, node As RowNode
|
||
For i As Integer = _nodes.Count - 1 To 0 Step -1
|
||
node = _nodes(i)
|
||
pNode = node.ParentNode
|
||
If pNode.Count <= node.Index Then
|
||
pNode.AddNode(node)
|
||
Else
|
||
pNode.InsertNode(node.Index, node)
|
||
End If
|
||
|
||
_model.AddUsedTypes(node)
|
||
_model.AddNodeRow(node, True)
|
||
_model.UpdateActionCnt(node)
|
||
Next
|
||
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
|
||
_model.SkipCellChange = False
|
||
_model.UnLockGridAutoRedraw()
|
||
_nodes.Clear()
|
||
End Sub
|
||
|
||
Public Overrides Sub Redo()
|
||
'检测选择单元格的位置,是否为可以插入节点的位置
|
||
|
||
Dim startRow As Integer = _selectFirstRow
|
||
Dim count As Integer = _selectLastRow - _selectFirstRow + 1
|
||
|
||
Dim node As RowNode
|
||
|
||
_model.LockGridAutoRedraw()
|
||
_model.SkipCellChange = True
|
||
For i = 0 To count - 1
|
||
node = _model.FindRowNode(startRow)
|
||
|
||
If node Is Nothing Then
|
||
_model.UnLockGridAutoRedraw()
|
||
Throw New Exception($"未获取到行[{startRow}]的节点信息")
|
||
End If
|
||
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.ExternalModel
|
||
If MsgBox("请确认是否要外设设备?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "正在删除设备") = MsgBoxResult.No Then Exit Select
|
||
_model.RemoveNodeRow(node)
|
||
_nodes.Add(node)
|
||
i += node.AllChildCount
|
||
Case RowNode.RowTypeEnum.ContextualModel
|
||
If MsgBox("请确认是否要删除场景?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "正在删除场景") = MsgBoxResult.No Then Exit Select
|
||
_nodes.Add(node)
|
||
_model.RemoveNodeRow(node)
|
||
i += node.AllChildCount
|
||
Case RowNode.RowTypeEnum.DeviceEventActions
|
||
If MsgBox("请确认是否要动作组?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "正在删除动作组") = MsgBoxResult.No Then Exit Select
|
||
_nodes.Add(node)
|
||
_model.RemoveNodeRow(node)
|
||
i += node.AllChildCount
|
||
Case RowNode.RowTypeEnum.DeviceEventConditionItem
|
||
If MsgBox("请确认是否要条件?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "正在删除条件") = MsgBoxResult.No Then Exit Select
|
||
_nodes.Add(node)
|
||
_model.RemoveNodeRow(node)
|
||
i += node.AllChildCount
|
||
Case RowNode.RowTypeEnum.DeviceEventAction
|
||
If MsgBox("请确认是否要动作?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "正在删除动作") = MsgBoxResult.No Then Exit Select
|
||
_nodes.Add(node)
|
||
_model.RemoveNodeRow(node)
|
||
i += node.AllChildCount
|
||
Case Else
|
||
_model.UnLockGridAutoRedraw()
|
||
Throw New Exception($"当前行[{node.RowListIndex}]不允许被移除,移除已终止")
|
||
End Select
|
||
_model.RemoveUsedTypes(node)
|
||
_model.UpdateActionCnt(node)
|
||
Next
|
||
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
_model.SkipCellChange = False
|
||
_model.UnLockGridAutoRedraw()
|
||
End Sub
|
||
|
||
End Class
|
||
|
||
|
||
Public Class InsertRowsCommand
|
||
Inherits GridCommand
|
||
|
||
Private _model As DeviceEventModel
|
||
|
||
Private _selectFirstRow As Integer
|
||
Private _selectLastRow As Integer
|
||
Private _selectFirstCol As Integer
|
||
Private _selectLastCol As Integer
|
||
|
||
Private _grd As FlexCell.Grid
|
||
Private _nodes As List(Of RowNode)
|
||
|
||
|
||
Sub New(model As DeviceEventModel)
|
||
_model = model
|
||
_grd = model.Grid
|
||
|
||
_selectFirstRow = _grd.Selection.FirstRow
|
||
_selectLastRow = _grd.Selection.LastRow
|
||
_selectFirstCol = _grd.Selection.FirstCol
|
||
_selectLastCol = _grd.Selection.LastCol
|
||
|
||
_nodes = New List(Of RowNode)
|
||
|
||
|
||
'准备工作
|
||
End Sub
|
||
|
||
Public Overrides Sub Undo()
|
||
_model.LockGridAutoRedraw()
|
||
For Each node As RowNode In _nodes
|
||
_model.RemoveNodeRow(node)
|
||
_model.UpdateActionCnt(node)
|
||
Next
|
||
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
_model.UnLockGridAutoRedraw()
|
||
|
||
_nodes.Clear()
|
||
End Sub
|
||
|
||
Public Overrides Sub Redo()
|
||
'检测选择单元格的位置,是否为可以插入节点的位置
|
||
|
||
Dim node As RowNode = _model.FindRowNode(_selectFirstRow)
|
||
If node Is Nothing Then Throw New Exception($"未获取到节点信息")
|
||
|
||
'仅提供插入动作
|
||
Dim count As Integer = _selectLastRow - _selectFirstRow + 1
|
||
''Momo 2022-06-30 插入时根据选中行有多少行可见来决定插入多少行
|
||
'Dim count As Integer = 0
|
||
'For i = _selectFirstRow To _selectLastRow Step 1
|
||
' Dim tmpNode As RowNode = _model.FindRowNode(i)
|
||
' If node.Visible = True Then count += 1
|
||
'Next
|
||
|
||
|
||
_model.LockGridAutoRedraw()
|
||
Dim pNode As RowNode
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.DeviceEventActions
|
||
pNode = node
|
||
Case RowNode.RowTypeEnum.DeviceEventAction
|
||
pNode = node.ParentNode
|
||
Case Else
|
||
_model.UnLockGridAutoRedraw()
|
||
Throw New Exception($"当前选择节点类型[{node.RowType}]不允许当前操作")
|
||
End Select
|
||
|
||
Dim cNode As RowNode
|
||
For i = 0 To count - 1
|
||
'添加内存行
|
||
cNode = _model.CreateRowNode(RowNode.RowTypeEnum.DeviceEventAction)
|
||
pNode.AddNode(cNode)
|
||
|
||
'添加数据行
|
||
_model.AddNodeRow(cNode, True)
|
||
|
||
_nodes.Add(cNode)
|
||
|
||
'_grd.Row(cNode.RowListIndex).Visible = True 'Momo 0416 在父节点收缩的情况下插入行,要把新插入的行显示出来
|
||
cNode.ParentNode.Expand()
|
||
_model.UpdateActionCnt(cNode)
|
||
Next
|
||
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
|
||
_model.UnLockGridAutoRedraw()
|
||
End Sub
|
||
End Class
|
||
|
||
|
||
Public Class CutRowsCommand
|
||
Inherits GridCommand
|
||
|
||
Private _model As DeviceEventModel
|
||
|
||
Private _selectFirstRow As Integer
|
||
Private _selectLastRow As Integer
|
||
Private _selectFirstCol As Integer
|
||
Private _selectLastCol As Integer
|
||
|
||
Private _grd As FlexCell.Grid
|
||
|
||
Private _beforeText As String
|
||
Private _afterText As String
|
||
|
||
Private _cmdGroup As List(Of ICommand)
|
||
|
||
Sub New(model As DeviceEventModel)
|
||
_model = model
|
||
_grd = model.Grid
|
||
|
||
_selectFirstRow = _grd.Selection.FirstRow
|
||
_selectLastRow = _grd.Selection.LastRow
|
||
_selectFirstCol = _grd.Selection.FirstCol
|
||
_selectLastCol = _grd.Selection.LastCol
|
||
|
||
Dim sb As New StringBuilder
|
||
_cmdGroup = New List(Of ICommand)
|
||
For i = _selectFirstRow To _selectLastRow
|
||
sb.Append(_grd.Cell(i, _selectFirstCol).Text)
|
||
_cmdGroup.Add(New TextChangedCommand(_model, i, _selectFirstCol, ""))
|
||
For j = _selectFirstCol + 1 To _selectLastCol
|
||
sb.Append(vbTab & _grd.Cell(i, j).Text)
|
||
_cmdGroup.Add(New TextChangedCommand(_model, i, j, ""))
|
||
Next
|
||
sb.Append(vbCrLf)
|
||
Next
|
||
Clipboard.SetText(sb.ToString)
|
||
|
||
''记录选中单元格的内容
|
||
'Dim sb As New StringBuilder
|
||
'For i = _selectFirstRow To _selectLastRow
|
||
' sb.Append(_grd.Cell(i, _selectFirstCol).Text)
|
||
|
||
' For j = _selectFirstCol + 1 To _selectLastCol
|
||
' sb.Append(vbTab & _grd.Cell(i, j).Text)
|
||
' Next
|
||
' sb.Append(vbCrLf)
|
||
'Next
|
||
'_beforeText = sb.ToString
|
||
|
||
''将选择区域的内容拷贝至剪切板
|
||
'Clipboard.SetText(_beforeText)
|
||
|
||
''记录剪切后单元格的内容
|
||
'Dim sb2 As New StringBuilder
|
||
'For i = _selectFirstRow To _selectLastRow
|
||
' sb2.Append("")
|
||
|
||
' For j = _selectFirstCol + 1 To _selectLastCol
|
||
' sb2.Append(vbTab & "")
|
||
' Next
|
||
' sb2.Append(vbCrLf)
|
||
'Next
|
||
'_afterText = sb2.ToString
|
||
End Sub
|
||
|
||
Public Overrides Sub Undo()
|
||
_model.LockGridAutoRedraw()
|
||
_model.SkipCellChange = True
|
||
For Each cmd As ICommand In _cmdGroup
|
||
cmd.Undo()
|
||
Next
|
||
_model.SkipCellChange = False
|
||
_model.UnLockGridAutoRedraw()
|
||
Return
|
||
'还原选择区域内容
|
||
PasteData(_beforeText, _selectFirstRow, _selectFirstCol)
|
||
End Sub
|
||
|
||
Public Overrides Sub Redo()
|
||
_model.LockGridAutoRedraw()
|
||
_model.SkipCellChange = True
|
||
For Each cmd As ICommand In _cmdGroup
|
||
cmd.Redo()
|
||
Next
|
||
_model.SkipCellChange = False
|
||
_model.UnLockGridAutoRedraw()
|
||
Return
|
||
|
||
'清空选择区域的内容
|
||
PasteData(_afterText, _selectFirstRow, _selectFirstCol)
|
||
End Sub
|
||
|
||
|
||
Private Sub PasteData(str As String, startRow As Integer, startCol As Integer)
|
||
Dim result As List(Of List(Of String))
|
||
result = DealPasteData(str)
|
||
|
||
If result.Count = 0 Then Return
|
||
If startRow + result.Count - 1 > _grd.Rows Then Throw New Exception("数据越界")
|
||
|
||
_model.LockGridAutoRedraw()
|
||
' _model.SkipCellChange = True
|
||
For i = 0 To result.Count - 2
|
||
For j = 0 To result(i).Count - 1
|
||
_grd.Cell(startRow + i, startCol + j).Text = result(i)(j)
|
||
|
||
'todo内容检测
|
||
Next
|
||
Next
|
||
' _model.SkipCellChange = False
|
||
_model.UnLockGridAutoRedraw()
|
||
End Sub
|
||
|
||
Private Function DealPasteData(str As String) As List(Of List(Of String))
|
||
Dim result As New List(Of List(Of String))
|
||
|
||
Dim tmpStrings() As String = str.Split(New String() {vbCrLf}, StringSplitOptions.None)
|
||
For Each tmpStr As String In tmpStrings
|
||
Dim lst As New List(Of String)
|
||
lst.AddRange(tmpStr.Split(vbTab))
|
||
|
||
result.Add(lst)
|
||
Next
|
||
|
||
Return result
|
||
End Function
|
||
End Class
|
||
|
||
Public Class PasteRowsCommand
|
||
Inherits GridCommand
|
||
|
||
Private _model As DeviceEventModel
|
||
|
||
Private _selectFirstRow As Integer
|
||
Private _selectLastRow As Integer
|
||
Private _selectFirstCol As Integer
|
||
Private _selectLastCol As Integer
|
||
|
||
Private _grd As FlexCell.Grid
|
||
|
||
Private _beforeText As String
|
||
Private _afterText As String
|
||
|
||
Private _cmdGroup As List(Of ICommand)
|
||
|
||
Sub New(model As DeviceEventModel)
|
||
_model = model
|
||
_grd = model.Grid
|
||
|
||
_selectFirstRow = _grd.Selection.FirstRow
|
||
_selectLastRow = _grd.Selection.LastRow
|
||
_selectFirstCol = _grd.Selection.FirstCol
|
||
_selectLastCol = _grd.Selection.LastCol
|
||
|
||
'获取剪切板的内容
|
||
Dim str As String = Clipboard.GetText
|
||
|
||
'记录粘贴后的内容
|
||
_afterText = str
|
||
|
||
Dim result As List(Of List(Of String)) = DealPasteData(_afterText)
|
||
_cmdGroup = New List(Of ICommand)
|
||
|
||
'记录粘贴前的内容
|
||
Dim sb As New StringBuilder
|
||
For i = 0 To result.Count - 1
|
||
sb.Append(_grd.Cell(_selectFirstRow + i, _selectFirstCol).Text)
|
||
_cmdGroup.Add(New TextChangedCommand(_model, _selectFirstRow + i, _selectFirstCol, result(i)(0)))
|
||
For j = 1 To result(i).Count - 1
|
||
sb.Append(vbTab & _grd.Cell(_selectFirstRow + i, _selectFirstCol + j).Text)
|
||
_cmdGroup.Add(New TextChangedCommand(_model, _selectFirstRow + i, _selectFirstCol + j, result(i)(j)))
|
||
Next
|
||
sb.Append(vbCrLf)
|
||
Next
|
||
_beforeText = sb.ToString
|
||
End Sub
|
||
|
||
Public Overrides Sub Undo()
|
||
_model.LockGridAutoRedraw()
|
||
_model.SkipCellChange = True
|
||
For Each cmd As ICommand In _cmdGroup
|
||
cmd.Undo()
|
||
Next
|
||
_model.SkipCellChange = False
|
||
_model.UnLockGridAutoRedraw()
|
||
Return
|
||
|
||
'移除
|
||
PasteData(_beforeText, _selectFirstRow, _selectFirstCol)
|
||
End Sub
|
||
|
||
Public Overrides Sub Redo()
|
||
_model.LockGridAutoRedraw()
|
||
_model.SkipCellChange = True
|
||
For Each cmd As ICommand In _cmdGroup
|
||
cmd.Redo()
|
||
Next
|
||
_model.SkipCellChange = False
|
||
_model.UnLockGridAutoRedraw()
|
||
Return
|
||
|
||
'粘贴
|
||
PasteData(_afterText, _selectFirstRow, _selectFirstCol)
|
||
|
||
End Sub
|
||
|
||
Private Sub PasteData(str As String, startRow As Integer, startCol As Integer)
|
||
Dim result As List(Of List(Of String))
|
||
result = DealPasteData(str)
|
||
|
||
If result.Count = 0 Then Return
|
||
If startRow + result.Count - 1 > _grd.Rows Then Throw New Exception("数据越界")
|
||
_model.LockGridAutoRedraw()
|
||
_model.SkipCellChange = True
|
||
For i = 0 To result.Count - 2
|
||
For j = 0 To result(i).Count - 1
|
||
_grd.Cell(startRow + i, startCol + j).Text = result(i)(j)
|
||
|
||
'todo内容检测
|
||
Next
|
||
Next
|
||
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
|
||
_model.SkipCellChange = True
|
||
_model.UnLockGridAutoRedraw()
|
||
End Sub
|
||
|
||
Private Function DealPasteData(str As String) As List(Of List(Of String))
|
||
Dim result As New List(Of List(Of String))
|
||
|
||
Dim tmpStrings() As String = str.Split(New String() {vbCrLf}, StringSplitOptions.None)
|
||
For Each tmpStr As String In tmpStrings
|
||
Dim lst As New List(Of String)
|
||
lst.AddRange(tmpStr.Split(vbTab))
|
||
|
||
result.Add(lst)
|
||
Next
|
||
If result.Count > 0 Then result.RemoveAt(result.Count - 1)
|
||
Return result
|
||
End Function
|
||
End Class
|
||
|
||
Public Class TextChangedCommand
|
||
Inherits GridCommand
|
||
|
||
Private _model As DeviceEventModel
|
||
|
||
Private _row As Integer
|
||
Private _col As Integer
|
||
Private _afterText As String
|
||
Private _beforText As String
|
||
|
||
|
||
Private _grd As FlexCell.Grid
|
||
Private _nodes As List(Of RowNode)
|
||
|
||
|
||
Sub New(model As DeviceEventModel, row As Integer, col As Integer, text As String)
|
||
_model = model
|
||
_grd = model.Grid
|
||
|
||
_row = row
|
||
_col = col
|
||
_afterText = text
|
||
_beforText = FindNodeTextByCol(_row, _col)
|
||
_nodes = New List(Of RowNode)
|
||
|
||
If col <> ColNames.DeviceType Then Return
|
||
|
||
Dim node As RowNode = _model.FindRowNode(_row)
|
||
If node.RowType = RowNode.RowTypeEnum.DeviceObject Then
|
||
Dim tmpNode As New RowNode With {.RowType = node.RowType, .DeviceType = text, .DeviceAlias = node.DeviceAlias, .HasAlias = node.HasAlias}
|
||
_model.FillDeviceObjectNode(tmpNode, False)
|
||
|
||
For i = 0 To tmpNode.Count - 1
|
||
_nodes.Add(tmpNode.Nodes(i))
|
||
Next
|
||
End If
|
||
End Sub
|
||
|
||
Public Function FindNodeTextByCol(row As Integer, col As Integer) As String
|
||
Dim result As String = ""
|
||
Dim node As RowNode = _model.FindRowNode(row)
|
||
If node Is Nothing Then Return result
|
||
|
||
Select Case col
|
||
Case ColNames.Action
|
||
result = node.Action
|
||
Case ColNames.DeviceAlias
|
||
result = node.DeviceAlias
|
||
Case ColNames.Node
|
||
result = node.Text
|
||
Case ColNames.DeviceType
|
||
result = node.DeviceType
|
||
Case ColNames.DeviceName
|
||
result = node.DeviceName
|
||
Case ColNames.DeviceMothed
|
||
result = node.DeviceMothed
|
||
Case ColNames.DelayTime
|
||
result = node.DelayTime
|
||
Case ColNames.DelayUnit
|
||
result = node.DelayUnit
|
||
Case ColNames.ParamValue1, ColNames.ParamValue2, ColNames.ParamValue3, ColNames.ParamValue4, ColNames.ParamValue5, ColNames.ParamValue6
|
||
Dim index As Integer = (_col - ColNames.ParamValue1) \ 2
|
||
If index >= node.Params.Count Then Exit Select
|
||
result = node.Params(index).Value
|
||
Case Else
|
||
result = ""
|
||
End Select
|
||
Return result
|
||
End Function
|
||
|
||
Public Overrides Sub Undo()
|
||
_model.SkipCellChange = True
|
||
|
||
'文本修改处理
|
||
Dim node As RowNode = _model.FindRowNode(_row)
|
||
If node Is Nothing Then Return
|
||
|
||
_model.LockGridAutoRedraw()
|
||
_grd.Cell(_row, _col).Text = _beforText
|
||
_grd.Cell(_row, _col).BackColor = Color.White '背景色复位为白色
|
||
Select Case _col
|
||
Case ColNames.Action
|
||
node.Action = _grd.Cell(_row, _col).BooleanValue
|
||
|
||
'添加筛选
|
||
If node.Action = False Then
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.DeviceEvent,
|
||
RowNode.RowTypeEnum.ContextualModel,
|
||
RowNode.RowTypeEnum.DeviceGroup,
|
||
RowNode.RowTypeEnum.DeviceObject,
|
||
RowNode.RowTypeEnum.DeviceEventAction,
|
||
RowNode.RowTypeEnum.DeviceEventActions
|
||
|
||
'以上类型允许修改
|
||
Case Else
|
||
'除上述类型则不允许修改
|
||
node.Action = True
|
||
_grd.Cell(_row, _col).Text = "1"
|
||
End Select
|
||
End If
|
||
|
||
_model.FillRowStyle(node)
|
||
For i = 1 To node.AllChildCount
|
||
_model.FillRowStyle(_model.FindRowNode(_row + i))
|
||
Next
|
||
|
||
Case ColNames.DeviceAlias
|
||
node.DeviceAlias = _beforText
|
||
node.HasAlias = Not String.IsNullOrEmpty(node.DeviceAlias)
|
||
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.ContextualModel
|
||
node.Text = $"场景:{node.DeviceAlias}"
|
||
Case RowNode.RowTypeEnum.DeviceEventActions
|
||
node.Text = $"动作组:{node.DeviceAlias}"
|
||
Case RowNode.RowTypeEnum.DeviceEventConditionItem
|
||
node.Text = $"条件:{node.DeviceAlias}"
|
||
Case RowNode.RowTypeEnum.DeviceEventAction
|
||
node.Text = $"动作:{node.DeviceAlias}"
|
||
End Select
|
||
_grd.Cell(_row, ColNames.Node).Text = node.Text
|
||
|
||
'更新action行对别名的调用
|
||
Dim tmpCnt As Integer = _model.UpdateDeviceAliceName(node, _afterText, _beforText)
|
||
If tmpCnt > 0 Then
|
||
Dim msgPrompt As String = "别名修改:" & vbCrLf & vbCrLf &
|
||
" 位置:" & node.RowListIndex & " - " & node.Text & " - " & node.DeviceType & " - " & node.DeviceName & vbCrLf &
|
||
" 修改前: " & _afterText & vbCrLf &
|
||
" 修改后: " & _beforText & vbCrLf & vbCrLf &
|
||
" 影响修改项:" & tmpCnt
|
||
|
||
Dim msgTitle As String = "别名修改"
|
||
MsgBox(msgPrompt, MsgBoxStyle.OkOnly + MsgBoxStyle.Information, msgTitle)
|
||
End If
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
|
||
Case ColNames.DeviceType
|
||
Dim devType As String = _beforText
|
||
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.ModelAttribute, '模型属性
|
||
RowNode.RowTypeEnum.DeviceAttribute, '设备属性
|
||
RowNode.RowTypeEnum.DeviceEventConditions, '条件
|
||
RowNode.RowTypeEnum.DeviceEventActionMode '动作执行方式
|
||
|
||
node.DeviceType = devType
|
||
|
||
Dim tag As AttributeRowNodeTag = node.Tag
|
||
tag.Value = node.DeviceType
|
||
Case RowNode.RowTypeEnum.DeviceObject '设备对象
|
||
'设备类型更新
|
||
If String.Compare(devType, node.DeviceType, True) = 0 Then Exit Select
|
||
|
||
'记录移除的节点
|
||
Dim nodes As New List(Of RowNode)
|
||
For i = 0 To node.Count - 1
|
||
nodes.Add(node.Nodes(i))
|
||
Next
|
||
|
||
'移除行
|
||
_model.RemoveNodeChildRow(node)
|
||
|
||
node.DeviceType = devType
|
||
_model.AddUsedTypes(node)
|
||
|
||
'添加行
|
||
For i = 0 To _nodes.Count - 1
|
||
node.AddNode(_nodes(i)) '记录中的行
|
||
Next
|
||
_model.AddNodeChildRow(node, True)
|
||
|
||
_nodes.Clear()
|
||
_nodes.AddRange(nodes.ToArray)
|
||
Case RowNode.RowTypeEnum.DeviceEventAction, '动作
|
||
RowNode.RowTypeEnum.ModelAttribute_XiaoBaoCMD '小宝命令集
|
||
'设备类型变更
|
||
node.DeviceType = devType
|
||
|
||
node.DeviceName = ""
|
||
_grd.Cell(_row, ColNames.DeviceName).Text = ""
|
||
|
||
node.DeviceMothed = ""
|
||
_grd.Cell(_row, ColNames.DeviceMothed).Text = ""
|
||
|
||
node.Params.Clear()
|
||
For i = ColNames.ParamDesc1 To _grd.Cols - 1
|
||
_grd.Cell(_row, i).Text = ""
|
||
Next
|
||
|
||
_model.UpdateActionCnt(node) '更新动作数量显示(显示在DeviceName列)
|
||
Case Else
|
||
node.DeviceType = devType
|
||
End Select
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
|
||
Case ColNames.DeviceName
|
||
node.DeviceName = _beforText
|
||
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.DeviceEventAction, ' 23.模型外设事件执行动作
|
||
RowNode.RowTypeEnum.DeviceEventActions, ' 22.模型外设事件执行动作组
|
||
RowNode.RowTypeEnum.DeviceEvent ' 15.模型外设事件
|
||
_model.UpdateActionCnt(node) '更新动作数量显示(显示在DeviceName列)
|
||
|
||
End Select
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
|
||
Case ColNames.DeviceMothed
|
||
node.DeviceMothed = _beforText
|
||
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.DeviceEventAction '事件动作
|
||
'清空节点参数
|
||
node.Params.Clear()
|
||
For i = ColNames.ParamDesc1 To _grd.Cols - 1
|
||
_grd.Cell(_row, i).Text = ""
|
||
Next
|
||
|
||
'更新参数提示
|
||
If String.IsNullOrEmpty(node.DeviceType) Then Exit Select
|
||
If String.IsNullOrEmpty(node.DeviceMothed) Then Exit Select
|
||
|
||
Dim cs As DeviceObjectType = _model.BasicClasses.FindDeviceClass(node.DeviceType)
|
||
If cs Is Nothing Then Exit Select
|
||
|
||
For Each method As DeviceChildNodeMethod In cs.Methods
|
||
If method.Name <> node.DeviceMothed Then Continue For
|
||
|
||
'填充参数值
|
||
For i As Integer = 0 To 5
|
||
If i < method.Params.Count Then
|
||
Dim param As New AttributeRowNodeTag(method.Params(i).Name,
|
||
method.Params(i).DataType,
|
||
method.Params(i).DataRange,
|
||
method.Params(i).DataRangeValue,
|
||
method.Params(i).Desc,
|
||
method.Params(i).DataDefault)
|
||
node.Params.Add(param)
|
||
|
||
_grd.Cell(_row, ColNames.ParamDesc1 + i * 2).Text = param.Name
|
||
_grd.Cell(_row, ColNames.ParamDesc1 + i * 2).Locked = True
|
||
|
||
If param.Type = AttributeRowNodeTag.DataTypes.List Then
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).CellType = CellTypeEnum.ComboBox
|
||
_grd.ComboBox(0).Locked = True
|
||
_grd.ComboBox(0).Sorted = True
|
||
_grd.ComboBox(0).DropDownWidth = 124
|
||
ElseIf param.Type = AttributeRowNodeTag.DataTypes.Boolean Then
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).CellType = CellTypeEnum.CheckBox
|
||
Else
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).CellType = CellTypeEnum.TextBox
|
||
End If
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).Text = param.DefalutValue
|
||
Else
|
||
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).CellType = CellTypeEnum.TextBox
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).Text = ""
|
||
|
||
_grd.Cell(_row, ColNames.ParamDesc1 + i * 2).Text = ""
|
||
End If
|
||
Next
|
||
Exit For
|
||
Next
|
||
End Select
|
||
|
||
Case ColNames.DelayTime
|
||
node.DelayTime = _beforText
|
||
|
||
Case ColNames.DelayUnit
|
||
node.DelayUnit = _beforText
|
||
|
||
Case ColNames.ParamValue1, ColNames.ParamValue2, ColNames.ParamValue3, ColNames.ParamValue4, ColNames.ParamValue5, ColNames.ParamValue6
|
||
Dim index As Integer = (_col - ColNames.ParamValue1) \ 2
|
||
If index >= node.Params.Count Then Exit Select
|
||
Dim value As String = _beforText
|
||
If node.Params(index).IsRange(value) Then
|
||
node.Params(index).Value = value
|
||
Else
|
||
_grd.Cell(_row, _col).Text = node.Params(index).Value
|
||
MsgBox($"当前数值[{value}],不在范围[{node.Params(index).RangeString}]中,设置失败")
|
||
End If
|
||
End Select
|
||
|
||
Dim errCnt As Integer = 0
|
||
Dim warningCnt As Integer = 0
|
||
_model.StartGobleRuleCheck(errCnt, warningCnt) '规则检查’
|
||
_model.FillRowStyle(node)
|
||
|
||
_model.UnLockGridAutoRedraw()
|
||
_model.SkipCellChange = False
|
||
End Sub
|
||
Public Overrides Sub Redo()
|
||
_model.SkipCellChange = True
|
||
'文本修改处理
|
||
Dim node As RowNode = _model.FindRowNode(_row)
|
||
If node Is Nothing Then Return
|
||
_model.LockGridAutoRedraw()
|
||
_grd.Cell(_row, _col).Text = _afterText
|
||
_grd.Cell(_row, _col).BackColor = Color.White '背景色复位为白色
|
||
Select Case _col
|
||
Case ColNames.Action
|
||
node.Action = _grd.Cell(_row, _col).BooleanValue
|
||
|
||
'添加筛选
|
||
If node.Action = False Then
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.DeviceEvent,
|
||
RowNode.RowTypeEnum.ContextualModel,
|
||
RowNode.RowTypeEnum.DeviceGroup,
|
||
RowNode.RowTypeEnum.DeviceObject,
|
||
RowNode.RowTypeEnum.DeviceEventAction,
|
||
RowNode.RowTypeEnum.DeviceEventActions
|
||
|
||
'以上类型允许修改
|
||
Case Else
|
||
'除上述类型则不允许修改
|
||
node.Action = True
|
||
_grd.Cell(_row, _col).Text = "1"
|
||
End Select
|
||
End If
|
||
|
||
_model.FillRowStyle(node)
|
||
For i = 1 To node.AllChildCount
|
||
_model.FillRowStyle(_model.FindRowNode(_row + i))
|
||
Next
|
||
|
||
Case ColNames.DeviceAlias
|
||
node.DeviceAlias = _afterText
|
||
node.HasAlias = Not String.IsNullOrEmpty(node.DeviceAlias)
|
||
'更新action行对别名的调用
|
||
Dim tmpCnt As Integer = _model.UpdateDeviceAliceName(node, _beforText, _afterText)
|
||
If tmpCnt > 0 Then
|
||
Dim msgPrompt As String = "别名修改:" & vbCrLf & vbCrLf &
|
||
" 位置:" & node.RowListIndex & " - " & node.Text & " - " & node.RowType & vbCrLf &
|
||
" 修改前: " & _beforText & vbCrLf &
|
||
" 修改后: " & _afterText & vbCrLf & vbCrLf &
|
||
" 影响修改项:" & tmpCnt
|
||
|
||
Dim msgTitle As String = "别名修改"
|
||
MsgBox(msgPrompt, MsgBoxStyle.OkOnly + MsgBoxStyle.Information, msgTitle)
|
||
End If
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.ContextualModel
|
||
node.Text = $"场景:{node.DeviceAlias}"
|
||
|
||
Case RowNode.RowTypeEnum.DeviceEventActions
|
||
node.Text = $"动作组:{node.DeviceAlias}"
|
||
|
||
Case RowNode.RowTypeEnum.DeviceEventConditionItem
|
||
node.Text = $"条件:{node.DeviceAlias}"
|
||
Case RowNode.RowTypeEnum.DeviceEventAction
|
||
node.Text = $"动作:{node.DeviceAlias}"
|
||
Case Else
|
||
|
||
End Select
|
||
|
||
_grd.Cell(_row, ColNames.Node).Text = node.Text
|
||
Case ColNames.DeviceType
|
||
Dim devType As String = _afterText
|
||
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.ModelAttribute, '模型属性
|
||
RowNode.RowTypeEnum.DeviceAttribute, '设备属性
|
||
RowNode.RowTypeEnum.DeviceEventConditions, '条件
|
||
RowNode.RowTypeEnum.DeviceEventActionMode '动作执行方式
|
||
|
||
node.DeviceType = devType
|
||
|
||
Dim tag As AttributeRowNodeTag = node.Tag
|
||
tag.Value = node.DeviceType
|
||
Case RowNode.RowTypeEnum.DeviceAttribute '设备属性
|
||
node.DeviceType = devType
|
||
Case RowNode.RowTypeEnum.DeviceObject '设备对象
|
||
'设备类型更新
|
||
If String.Compare(devType, node.DeviceType, True) = 0 Then Exit Select
|
||
'记录移除的节点
|
||
Dim nodes As New List(Of RowNode)
|
||
For i = 0 To node.Count - 1
|
||
nodes.Add(node.Nodes(i))
|
||
Next
|
||
|
||
'移除行
|
||
_model.RemoveNodeChildRow(node)
|
||
|
||
node.DeviceType = devType
|
||
_model.AddUsedTypes(node)
|
||
'添加行
|
||
For i = 0 To _nodes.Count - 1
|
||
node.AddNode(_nodes(i)) '记录中的行
|
||
Next
|
||
_model.AddNodeChildRow(node, True)
|
||
|
||
_nodes.Clear()
|
||
_nodes.AddRange(nodes.ToArray)
|
||
Case RowNode.RowTypeEnum.DeviceEventAction, '动作
|
||
RowNode.RowTypeEnum.ModelAttribute_XiaoBaoCMD '小宝命令集
|
||
'设备类型变更
|
||
node.DeviceType = devType
|
||
|
||
node.DeviceName = ""
|
||
_grd.Cell(_row, ColNames.DeviceName).Text = ""
|
||
|
||
node.DeviceMothed = ""
|
||
_grd.Cell(_row, ColNames.DeviceMothed).Text = ""
|
||
|
||
node.Params.Clear()
|
||
For i = ColNames.ParamDesc1 To _grd.Cols - 1
|
||
_grd.Cell(_row, i).Text = ""
|
||
Next
|
||
_model.UpdateActionCnt(node) '更新动作数量显示(显示在DeviceName列)
|
||
Case Else
|
||
node.DeviceType = devType
|
||
End Select
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
|
||
Case ColNames.DeviceName
|
||
node.DeviceName = _afterText
|
||
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.DeviceEventAction, ' 23.模型外设事件执行动作
|
||
RowNode.RowTypeEnum.DeviceEventActions, ' 22.模型外设事件执行动作组
|
||
RowNode.RowTypeEnum.DeviceEvent ' 15.模型外设事件
|
||
_model.UpdateActionCnt(node) '更新动作数量显示(显示在DeviceName列)
|
||
|
||
End Select
|
||
_model.UpdateAllResourceList() '暴力更新资源管理器内容,有时间再逐条更新 Momo 0422
|
||
|
||
Case ColNames.DeviceMothed
|
||
node.DeviceMothed = _afterText
|
||
|
||
Select Case node.RowType
|
||
Case RowNode.RowTypeEnum.DeviceEventAction '事件动作
|
||
'清空节点参数
|
||
node.Params.Clear()
|
||
For i = ColNames.ParamDesc1 To _grd.Cols - 1
|
||
_grd.Cell(_row, i).Text = ""
|
||
Next
|
||
|
||
'更新参数提示
|
||
If String.IsNullOrEmpty(node.DeviceType) Then Exit Select
|
||
If String.IsNullOrEmpty(node.DeviceMothed) Then Exit Select
|
||
|
||
Dim cs As DeviceObjectType = _model.BasicClasses.FindDeviceClass(node.DeviceType)
|
||
If cs Is Nothing Then Exit Select
|
||
|
||
For Each method As DeviceChildNodeMethod In cs.Methods
|
||
If method.Name <> node.DeviceMothed Then Continue For
|
||
|
||
'填充参数值
|
||
For i As Integer = 0 To 5
|
||
If i < method.Params.Count Then
|
||
Dim param As New AttributeRowNodeTag(method.Params(i).Name,
|
||
method.Params(i).DataType,
|
||
method.Params(i).DataRange,
|
||
method.Params(i).DataRangeValue,
|
||
method.Params(i).Desc,
|
||
method.Params(i).DataDefault)
|
||
node.Params.Add(param)
|
||
|
||
_grd.Cell(_row, ColNames.ParamDesc1 + i * 2).Text = param.Name
|
||
_grd.Cell(_row, ColNames.ParamDesc1 + i * 2).Locked = True
|
||
|
||
If param.Type = AttributeRowNodeTag.DataTypes.List Then
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).CellType = CellTypeEnum.ComboBox
|
||
_grd.ComboBox(0).Locked = True
|
||
_grd.ComboBox(0).Sorted = True
|
||
_grd.ComboBox(0).DropDownWidth = 124
|
||
ElseIf param.Type = AttributeRowNodeTag.DataTypes.Boolean Then
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).CellType = CellTypeEnum.CheckBox
|
||
Else
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).CellType = CellTypeEnum.TextBox
|
||
End If
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).Text = param.DefalutValue
|
||
|
||
Else
|
||
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).CellType = CellTypeEnum.TextBox
|
||
_grd.Cell(_row, ColNames.ParamValue1 + i * 2).Text = ""
|
||
|
||
_grd.Cell(_row, ColNames.ParamDesc1 + i * 2).Text = ""
|
||
End If
|
||
Next
|
||
Exit For
|
||
Next
|
||
End Select
|
||
|
||
Case ColNames.DelayTime
|
||
node.DelayTime = _afterText
|
||
|
||
Case ColNames.DelayUnit
|
||
node.DelayUnit = _afterText
|
||
|
||
Case ColNames.ParamValue1, ColNames.ParamValue2, ColNames.ParamValue3, ColNames.ParamValue4, ColNames.ParamValue5, ColNames.ParamValue6
|
||
Dim index As Integer = (_col - ColNames.ParamValue1) \ 2
|
||
If index >= node.Params.Count Then Exit Select
|
||
Dim value As String = _afterText
|
||
If node.Params(index).IsRange(value) Then
|
||
node.Params(index).Value = value
|
||
Else
|
||
_grd.Cell(_row, _col).Text = node.Params(index).Value
|
||
MsgBox($"当前数值[{value}],不在范围[{node.Params(index).RangeString}]中,设置失败")
|
||
End If
|
||
End Select
|
||
|
||
|
||
|
||
Dim errCnt As Integer = 0
|
||
Dim warningCnt As Integer = 0
|
||
_model.StartGobleRuleCheck(errCnt, warningCnt) '规则检查
|
||
_model.FillRowStyle(node)
|
||
|
||
_model.UnLockGridAutoRedraw()
|
||
_model.SkipCellChange = False
|
||
End Sub
|
||
|
||
End Class |