391 lines
18 KiB
VB.net
391 lines
18 KiB
VB.net
Imports Newtonsoft.Json
|
||
|
||
Public Class PowerSupplyForm
|
||
Implements FromInterface1
|
||
Private Dic_Devicemodel As Dictionary(Of String, DeviceModel)
|
||
Private Sub PowerSupplyForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||
InitIfGrid(UniqueDevice.Desc.DevDescription)
|
||
InitPortTable(NoCardNode)
|
||
End Sub
|
||
|
||
Private UniqueDevice As DeviceModel
|
||
Private NoCardNode As DeviceChildNodeClass
|
||
Private ParseDevDic As Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, List(Of (String, String)))))
|
||
Public Sub ParseDeviceList(Devicemodel As Dictionary(Of String, DeviceModel))
|
||
Dic_Devicemodel = Devicemodel
|
||
ParseDevDic = New Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, List(Of (String, String)))))
|
||
Dim typename As String
|
||
For Each index In Dic_Devicemodel.Values
|
||
For Each node In index.Nodes
|
||
If node.Name.Equals("Virtual_Card") Then
|
||
UniqueDevice = index
|
||
NoCardNode = node
|
||
Exit For
|
||
End If
|
||
If node.Interface.Equals("DI") Then
|
||
typename = GetAnotherName(node.Name)
|
||
typename = $"{node.Name}"
|
||
If String.IsNullOrEmpty(typename) Then
|
||
Continue For
|
||
Else
|
||
Dim addressdic As Dictionary(Of String, Dictionary(Of String, List(Of (String, String))))
|
||
If ParseDevDic.ContainsKey(typename) Then
|
||
addressdic = ParseDevDic.Item(typename)
|
||
Else
|
||
addressdic = New Dictionary(Of String, Dictionary(Of String, List(Of (String, String))))
|
||
ParseDevDic.Add(typename, addressdic)
|
||
End If
|
||
|
||
Dim addr As String
|
||
Dim loopdic As Dictionary(Of String, List(Of (String, String)))
|
||
Dim loopli As List(Of (String, String))
|
||
If index.Desc.Name.Equals("BLV_C12") Then
|
||
addr = 0
|
||
Else
|
||
addr = FindAttributeValueUnderModel(index, "设备存在", "拨码地址")
|
||
End If
|
||
If addressdic.ContainsKey(addr) Then
|
||
loopdic = addressdic.Item(addr)
|
||
Else
|
||
loopdic = New Dictionary(Of String, List(Of (String, String)))
|
||
addressdic.Add(addr, loopdic)
|
||
End If
|
||
If loopdic.ContainsKey(node.DEV_TYPE_DATA) Then
|
||
loopli = loopdic.Item(node.DEV_TYPE_DATA)
|
||
Else
|
||
loopli = New List(Of (String, String))
|
||
loopdic.Add(node.DEV_TYPE_DATA, loopli)
|
||
End If
|
||
For Each liindex In node.Nodes
|
||
loopli.Add((liindex.LoopAddr, liindex.DefaultAliasName))
|
||
Next
|
||
End If
|
||
Else
|
||
Continue For
|
||
End If
|
||
Next
|
||
Next
|
||
|
||
End Sub
|
||
|
||
Public Shared Function GetAnotherName(str As String) As String
|
||
Dim result As String = String.Empty
|
||
If String.IsNullOrEmpty(str) Then
|
||
Return result
|
||
Else
|
||
Select Case str
|
||
Case "CLED_FRESHAIR"
|
||
result = "CLED新风"
|
||
Case "CLEDFLOORHEAT"
|
||
result = "CLED地暖"
|
||
Case "485FloorHeat"
|
||
result = "地暖"
|
||
Case "485FreshAir"
|
||
result = "新风"
|
||
Case "485MUSIC"
|
||
result = "485音乐"
|
||
Case "CURTAIN"
|
||
result = "干接点窗帘"
|
||
Case "INFRARED_FORWARD"
|
||
result = "红外"
|
||
Case "RS485_Curtain"
|
||
result = "485窗帘"
|
||
Case "RELAY"
|
||
result = "继电器"
|
||
Case "MUSIC"
|
||
result = "音乐"
|
||
Case "Dimming"
|
||
result = "调光"
|
||
Case "DO"
|
||
result = "输出"
|
||
Case "Temp"
|
||
result = "空调"
|
||
Case "PB_LINE_CONTROL"
|
||
result = "主机恒压调光"
|
||
Case "PB_STRIP_DEVICE"
|
||
result = "PLC恒压调光"
|
||
Case "PB_RELAY_DEVICE"
|
||
result = "PLC继电器"
|
||
'Case "KEY"
|
||
' result = "普通按键"
|
||
Case Else
|
||
result = $"{str}"
|
||
End Select
|
||
|
||
End If
|
||
Return result
|
||
End Function
|
||
Private Function FindAttributeValueUnderModel(pNode As DeviceModel, groupName As String, attributeName As String) As String
|
||
For Each cnode In pNode.Config
|
||
If cnode.Name.Equals(groupName) Then
|
||
For Each ccnode In cnode.Attributes
|
||
If ccnode.Name.Equals(attributeName) Then
|
||
Return ccnode.Value
|
||
End If
|
||
Next
|
||
|
||
End If
|
||
Next
|
||
End Function
|
||
|
||
Private IfGridRowdic As Dictionary(Of String, List(Of String))
|
||
Public Sub InitIfGrid(jsonstr As String, Optional ifbn As Boolean = True)
|
||
IfGrid.NewFile()
|
||
IfGrid.ExtendLastCol = False
|
||
IfGrid.Cols = 15
|
||
IfGrid.Rows = 1
|
||
|
||
IfGrid.Cell(0, 0).Text = "条件组"
|
||
IfGrid.Cell(0, 1).Text = "条件序号"
|
||
IfGrid.Cell(0, 2).Text = "有无人标记"
|
||
IfGrid.Cell(0, 3).Text = "端口1"
|
||
IfGrid.Cell(0, 4).Text = "端口2"
|
||
IfGrid.Cell(0, 5).Text = "端口3"
|
||
IfGrid.Cell(0, 6).Text = "端口4"
|
||
IfGrid.Cell(0, 7).Text = "端口5"
|
||
IfGrid.Cell(0, 8).Text = "端口6"
|
||
IfGrid.Cell(0, 9).Text = "端口7"
|
||
IfGrid.Cell(0, 10).Text = "端口8"
|
||
IfGrid.Cell(0, 11).Text = "端口9"
|
||
IfGrid.Cell(0, 12).Text = "端口10"
|
||
IfGrid.Cell(0, 13).Text = "延时时间"
|
||
IfGrid.Cell(0, 14).Text = "延时单位"
|
||
|
||
IfGrid.Column(2).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(3).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(4).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(5).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(6).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(7).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(8).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(9).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(10).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(11).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(12).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(13).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(14).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
IfGrid.Column(0).Width = 50
|
||
IfGrid.Column(1).Width = 60
|
||
IfGrid.Column(2).Width = 60
|
||
IfGrid.Column(3).Width = 60
|
||
IfGrid.Column(4).Width = 60
|
||
IfGrid.Column(5).Width = 60
|
||
IfGrid.Column(6).Width = 60
|
||
IfGrid.Column(7).Width = 60
|
||
IfGrid.Column(8).Width = 60
|
||
IfGrid.Column(9).Width = 60
|
||
IfGrid.Column(10).Width = 60
|
||
IfGrid.Column(11).Width = 60
|
||
IfGrid.Column(12).Width = 60
|
||
IfGrid.Column(13).Width = 60
|
||
IfGrid.Column(14).Width = 60
|
||
IfGrid.Column(1).Locked = True
|
||
IfGrid.Column(0).Locked = True
|
||
IfGrid.ComboBox(2).Locked = True
|
||
IfGrid.ComboBox(3).Locked = True
|
||
IfGrid.ComboBox(5).Locked = True
|
||
IfGrid.ComboBox(6).Locked = True
|
||
IfGrid.ComboBox(7).Locked = True
|
||
IfGrid.ComboBox(11).Locked = True
|
||
IfGrid.ComboBox(12).Locked = True
|
||
IfGrid.ComboBox(4).Locked = True
|
||
IfGrid.ComboBox(8).Locked = True
|
||
IfGrid.ComboBox(9).Locked = True
|
||
IfGrid.ComboBox(10).Locked = True
|
||
IfGrid.ComboBox(13).Locked = True
|
||
IfGrid.ComboBox(14).Locked = True
|
||
|
||
IfGrid.Column(0).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(1).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(2).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(3).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(4).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(5).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(6).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(7).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(8).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(9).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(10).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(11).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(12).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(13).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
IfGrid.Column(14).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
|
||
Try
|
||
IfGridRowdic = JsonConvert.DeserializeObject(Of Dictionary(Of String, List(Of String)))(jsonstr)
|
||
If IsNothing(IfGridRowdic) OrElse IfGridRowdic.Count < 1 Then
|
||
IfGridRowdic = New Dictionary(Of String, List(Of String))
|
||
'Dim li As List(Of String) = New List(Of String)
|
||
For i = 1 To 3
|
||
Dim li As List(Of String) = New List(Of String)
|
||
IfGrid.AddItem("")
|
||
IfGrid.Cell(IfGrid.Rows - 1, 0).Text = $"{i}"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 1).Text = 1
|
||
IfGrid.Cell(IfGrid.Rows - 1, 2).Text = "1:无人至有人"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 3).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 4).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 5).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 6).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 7).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 8).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 9).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 10).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 11).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 12).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 13).Text = $"0"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 14).Text = $"秒"
|
||
|
||
li.Add($"{i},1,1,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0,秒")
|
||
IfGridRowdic.Add(i, li)
|
||
Next
|
||
Else
|
||
Dim headrow As Integer
|
||
For Each node In IfGridRowdic
|
||
IfGrid.AddItem("")
|
||
|
||
headrow = IfGrid.Rows - 1
|
||
For i = 0 To node.Value.Count - 1
|
||
If i = 0 Then
|
||
Else
|
||
IfGrid.AddItem("")
|
||
End If
|
||
IfGrid.Cell(IfGrid.Rows - 1, 0).Text = $"{node.Key}"
|
||
Dim rowstr() As String = node.Value(i).Split(",")
|
||
For j = 1 To rowstr.Length
|
||
If ifbn Then
|
||
IfGrid.Cell(IfGrid.Rows - 1, j).Text = rowstr(j - 1)
|
||
Else
|
||
If j = rowstr.Length Then Continue For
|
||
|
||
IfGrid.Cell(IfGrid.Rows - 1, j).Text = rowstr(j)
|
||
End If
|
||
|
||
Next
|
||
|
||
Next
|
||
'IfGrid.Range(headrow, 0, IfGrid.Rows - 1, 0).Merge()
|
||
Next
|
||
End If
|
||
Catch ex As Exception
|
||
|
||
IfGridRowdic = New Dictionary(Of String, List(Of String))
|
||
|
||
For i = 1 To 3
|
||
Dim li As List(Of String) = New List(Of String)
|
||
IfGrid.AddItem("")
|
||
IfGrid.Cell(IfGrid.Rows - 1, 0).Text = $"{i}"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 1).Text = 1
|
||
IfGrid.Cell(IfGrid.Rows - 1, 2).Text = "1:无人至有人"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 3).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 4).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 5).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 6).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 7).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 8).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 9).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 10).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 11).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 12).Text = $"0:不判断"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 13).Text = $"0"
|
||
IfGrid.Cell(IfGrid.Rows - 1, 14).Text = $"秒"
|
||
li.Add($"{i},1,1,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0:不判断,0,秒")
|
||
IfGridRowdic.Add(i, li)
|
||
Next
|
||
End Try
|
||
|
||
End Sub
|
||
|
||
|
||
Public isxiugai1 As Boolean = False
|
||
Public Sub InitPortTable(Node As DeviceChildNodeClass)
|
||
PortTable.NewFile()
|
||
PortTable.ExtendLastCol = False
|
||
PortTable.Cols = 6
|
||
PortTable.Rows = Node.Nodes.Count + 1
|
||
PortTable.Cell(0, 0).Text = "端口"
|
||
PortTable.Cell(0, 1).Text = "别名"
|
||
PortTable.Cell(0, 2).Text = "端口类型"
|
||
PortTable.Cell(0, 3).Text = "端口地址"
|
||
PortTable.Cell(0, 4).Text = "端口回路"
|
||
PortTable.Cell(0, 5).Text = "触发时间(百分比)阈值"
|
||
PortTable.Row(0).Locked = True
|
||
PortTable.Column(0).Width = 100
|
||
PortTable.Column(2).Width = 80
|
||
PortTable.Column(3).Width = 80
|
||
PortTable.Column(4).Width = 800
|
||
PortTable.Column(5).Width = 120
|
||
PortTable.Column(1).Width = 100
|
||
' PortTable.Column(1).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
PortTable.Column(2).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
PortTable.Column(3).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
PortTable.Column(4).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
PortTable.Column(5).CellType = FlexCell.CellTypeEnum.ComboBox
|
||
PortTable.ComboBox(5).Locked = True
|
||
'PortTable.Column(1).Locked = True
|
||
PortTable.ComboBox(2).Locked = True
|
||
PortTable.ComboBox(3).Locked = True
|
||
PortTable.ComboBox(4).Locked = True
|
||
PortTable.Column(0).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
PortTable.Column(1).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
PortTable.Column(2).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
PortTable.Column(3).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
PortTable.Column(4).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
PortTable.Column(5).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
||
|
||
isxiugai1 = False
|
||
Dim sbuf() As String
|
||
For i = 1 To Node.Nodes.Count
|
||
PortTable.Cell(i, 1).Text = " "
|
||
PortTable.Cell(i, 0).Text = Node.Nodes(i - 1).Name
|
||
sbuf = Node.Nodes(i - 1).Description.Split(",")
|
||
If sbuf.Length = 6 Then
|
||
PortTable.Cell(i, 1).Text = sbuf(0)
|
||
PortTable.Cell(i, 2).Text = sbuf(1)
|
||
PortTable.Cell(i, 3).Text = sbuf(2)
|
||
PortTable.Cell(i, 4).Text = sbuf(3)
|
||
PortTable.Cell(i, 4).Tag = sbuf(5)
|
||
PortTable.Cell(i, 5).Text = sbuf(4)
|
||
End If
|
||
Next
|
||
isxiugai1 = True
|
||
End Sub
|
||
Public Function GetPortTable() As Boolean
|
||
If IsNothing(NoCardNode) Then Return False
|
||
Dim rstr As String = String.Empty
|
||
For i = 1 To PortTable.Rows - 1
|
||
rstr = String.Empty
|
||
For j = 1 To PortTable.Cols - 1
|
||
|
||
rstr = $"{rstr},{PortTable.Cell(i, j).Text}"
|
||
Next
|
||
rstr = $"{rstr},{PortTable.Cell(i, 4).Tag}"
|
||
rstr = rstr.Remove(0, 1)
|
||
NoCardNode.Nodes(i - 1).Description = rstr
|
||
Next
|
||
Return True
|
||
End Function
|
||
|
||
Public Function SetFormPattern(ParamArray args() As Object) As Boolean Implements FromInterface1.SetFormPattern
|
||
If TypeOf args(0) Is Dictionary(Of String, DeviceModel) Then
|
||
' someObject 是 Dictionary(Of String, DeviceModel) 类型
|
||
If Not (args(0) Is Nothing) Then
|
||
Dic_Devicemodel = DirectCast(args(0), Dictionary(Of String, DeviceModel))
|
||
ParseDeviceList(Dic_Devicemodel)
|
||
Return True
|
||
Else
|
||
'MsgBox("设备加载异常")
|
||
Return False
|
||
End If
|
||
|
||
Else
|
||
' someObject 不是 Dictionary(Of String, DeviceModel) 类型
|
||
'MsgBox("设备加载异常")
|
||
Return False
|
||
End If
|
||
|
||
End Function
|
||
|
||
Public Function GetFormData() As Object Implements FromInterface1.GetFormData
|
||
Throw New NotImplementedException()
|
||
End Function
|
||
End Class |