2025-12-11 14:22:51 +08:00
Imports System . ComponentModel
Imports BLV_Studio . EnumExtend
Imports FlexCell
Public Class ServiceAttribute
Public G_hostNode As DeviceChildNodeClass
Public G_input As String
Private g_dicComboBox1 As Dictionary ( Of String , String )
2026-03-04 11:11:16 +08:00
Public g_diaplay As Boolean
2025-12-11 14:22:51 +08:00
Public G_result As String
Enum STcolname
<Description("Input number")>
行号 = 0
<Description("Device alias")>
延时
<Description("backlight")>
单位
<Description("Open mode")>
打开方式
<Description("Service type")>
服务类型
<Description("Display service")>
显示服务
max
End Enum
Private Dic_1 , Dic_2 , Dic_3 , Dic_4 As List ( Of String )
Private Sub ServiceAttribute_Load ( sender As Object , e As EventArgs ) Handles MyBase . Load
InitTable ( )
If IsNothing ( G_hostNode ) Then
MsgBox ( " 未选择主机,请先选择主机再进行配置! " )
Me . DialogResult = System . Windows . Forms . DialogResult . Cancel
Me . Close ( )
Return
End If
'服务方式
Dic_1 = New List ( Of String )
'执行方式
Dic_2 = New List ( Of String )
'时间
Dic_3 = New List ( Of String )
'单位
Dic_4 = New List ( Of String )
2026-03-04 11:11:16 +08:00
Dim fustr As String = " 服务- "
2025-12-11 14:22:51 +08:00
For Each node In G_hostNode . Nodes
2026-03-04 11:11:16 +08:00
fustr = " service- " & node . LoopAddr
'2025 12 29 CZH 增加 判断服务是否是 是在25 到48 且名称符合 "服务-服务号"的格式 符合则不 添加
If node . LoopAddr >= 25 AndAlso node . LoopAddr <= 57 AndAlso fustr . Equals ( node . Name ) Then '
Continue For
End If
2025-12-11 14:22:51 +08:00
Dic_1 . Add ( $ " {node.LoopAddr}:{node.Name } " )
Next
2026-03-04 11:11:16 +08:00
Dic_2 . AddRange ( { " 2:close " , " 1:open " , " 3:Reset the initial power-on " , " 4:Just draw electricity " } )
2025-12-11 14:22:51 +08:00
For i = 0 To 255
Dic_3 . Add ( i )
Next
Dic_4 . AddRange ( { " ms " , " s " , " m " , " H " , " Day " } )
LoadInputText ( G_input )
End Sub
Public Shared Function CheckDataIsOk ( datastr As String , hostNode As DeviceChildNodeClass ) As Boolean
If String . IsNullOrEmpty ( datastr ) Then Return True
Dim buff ( ) As String = datastr . Split ( vbLf )
Dim isok As Boolean
For Each index In buff
2026-03-04 11:11:16 +08:00
If String . IsNullOrEmpty ( index ) Then Continue For
2025-12-11 14:22:51 +08:00
isok = False
Dim buf ( ) As String = index . Split ( " , " )
If buf . Length <> 5 Then Return False
Dim intbuf ( 3 ) As Integer
If Not ( Integer . TryParse ( buf ( 0 ) , intbuf ( 0 ) ) And Integer . TryParse ( buf ( 1 ) , intbuf ( 1 ) ) And Integer . TryParse ( buf ( 2 ) , intbuf ( 2 ) ) And Integer . TryParse ( buf ( 3 ) , intbuf ( 3 ) ) ) Then Return False
If IsNothing ( hostNode ) Then Return False
For Each node In hostNode . Nodes
If node . LoopAddr . Equals ( intbuf ( 0 ) . ToString ) Then
isok = True
2026-03-04 11:11:16 +08:00
If intbuf ( 1 ) = 2 OrElse intbuf ( 1 ) = 1 OrElse intbuf ( 1 ) = 3 OrElse intbuf ( 1 ) = 4 Then
2025-12-11 14:22:51 +08:00
If intbuf ( 2 ) >= 0 OrElse intbuf ( 2 ) <= 255 Then
If intbuf ( 3 ) >= 1 OrElse intbuf ( 3 ) <= 5 Then
Exit For
End If
Return False
End If
Return False
End If
Return False
End If
Next
If isok Then
Continue For
End If
Return False
Next
Return True
End Function
Public Shared Function Getservername ( datastr As String , hostNode As DeviceChildNodeClass ) As String
Dim result As String = String . Empty
For Each node In hostNode . Nodes
If node . LoopAddr . Equals ( datastr ) Then
Return node . Name
End If
Next
Return result
End Function
Private Sub LoadInputText ( inputstr As String )
If String . IsNullOrEmpty ( inputstr ) Then Return
Dim buff ( ) As String = inputstr . Split ( vbLf )
Dim C1 , C2 , C3 , C4 As String
For Each index In buff
2026-03-04 11:11:16 +08:00
If String . IsNullOrEmpty ( index ) Then Continue For
2025-12-11 14:22:51 +08:00
C1 = String . Empty
C2 = String . Empty
C3 = String . Empty
C4 = String . Empty
Table_Grid1 . AddItem ( " " )
Dim buf ( ) As String = index . Split ( " , " )
If buf . Length > 0 Then
For i As Integer = 0 To Dic_1 . Count - 1
If Dic_1 ( i ) . ToString . Contains ( buf ( 0 ) ) Then
C1 = Dic_1 ( i )
Table_Grid1 . Cell ( Table_Grid1 . Rows - 1 , STcolname . 服务类型 ) . Text = C1
Exit For
End If
Next
End If
If buf . Length > 1 Then
For i As Integer = 0 To Dic_2 . Count - 1
If Dic_2 ( i ) . ToString . Contains ( buf ( 1 ) ) Then
C2 = Dic_2 ( i )
Table_Grid1 . Cell ( Table_Grid1 . Rows - 1 , STcolname . 打开方式 ) . Text = C2
Exit For
End If
Next
End If
If buf . Length > 2 Then
For i As Integer = 0 To Dic_3 . Count - 1
If Dic_3 ( i ) . ToString . Contains ( buf ( 2 ) ) Then
C3 = Dic_3 ( i )
Table_Grid1 . Cell ( Table_Grid1 . Rows - 1 , STcolname . 延时 ) . Text = C3
Exit For
End If
Next
End If
If buf . Length > 3 Then
Dim cbuf As String = FGetDelayUnit ( buf ( 3 ) )
For i As Integer = 0 To Dic_4 . Count - 1
If Dic_4 ( i ) . ToString . Equals ( cbuf ) Then
C4 = cbuf
Table_Grid1 . Cell ( Table_Grid1 . Rows - 1 , STcolname . 单位 ) . Text = C4
Exit For
End If
Next
End If
If String . IsNullOrEmpty ( C1 ) OrElse String . IsNullOrEmpty ( C2 ) OrElse String . IsNullOrEmpty ( C3 ) OrElse String . IsNullOrEmpty ( C4 ) Then
If String . IsNullOrEmpty ( C1 ) Then
Table_Grid1 . Range ( Table_Grid1 . Rows - 1 , STcolname . 服务类型 , Table_Grid1 . Rows - 1 , STcolname . 服务类型 ) . BackColor = Color . OrangeRed
ElseIf String . IsNullOrEmpty ( C2 ) Then
Table_Grid1 . Range ( Table_Grid1 . Rows - 1 , STcolname . 打开方式 , Table_Grid1 . Rows - 1 , STcolname . 打开方式 ) . BackColor = Color . OrangeRed
ElseIf String . IsNullOrEmpty ( C3 ) Then
Table_Grid1 . Range ( Table_Grid1 . Rows - 1 , STcolname . 延时 , Table_Grid1 . Rows - 1 , STcolname . 延时 ) . BackColor = Color . OrangeRed
ElseIf String . IsNullOrEmpty ( C4 ) Then
Table_Grid1 . Range ( Table_Grid1 . Rows - 1 , STcolname . 单位 , Table_Grid1 . Rows - 1 , STcolname . 单位 ) . BackColor = Color . OrangeRed
End If
Continue For
Else
Table_Grid1 . Range ( Table_Grid1 . Rows - 1 , 0 , Table_Grid1 . Rows - 1 , STcolname . 服务类型 ) . BackColor = Color . White
End If
Next
End Sub
Public Function showSelectedIndexVal ( c1 As String , c2 As String , c3 As String , c4 As String , c5 As String ) As String
Dim reslit As String = String . Empty
Dim strbuf1 ( ) As String = c1 . Split ( " : " )
Dim strbuf2 ( ) As String = c2 . Split ( " : " )
Dim t As String = GetDelayUnit ( c4 )
2026-03-04 11:11:16 +08:00
reslit = $ " {strbuf1(0).Trim},{strbuf2(0).Trim},{c3.Trim},{t.Trim},{c5.Trim} "
2025-12-11 14:22:51 +08:00
Return reslit
End Function
Private Sub Button1_Click ( sender As Object , e As EventArgs ) Handles Button1 . Click
G_result = String . Empty
Dim indexstr As String = String . Empty
Dim C1 , C2 , C3 , C5 , C4 As String
For i = 1 To Table_Grid1 . Rows - 1
C1 = Table_Grid1 . Cell ( i , STcolname . 服务类型 ) . Text . Trim
C2 = Table_Grid1 . Cell ( i , STcolname . 打开方式 ) . Text . Trim
C3 = Table_Grid1 . Cell ( i , STcolname . 延时 ) . Text . Trim
C4 = Table_Grid1 . Cell ( i , STcolname . 单位 ) . Text . Trim
C5 = Table_Grid1 . Cell ( i , STcolname . 显示服务 ) . Text . Trim
If String . IsNullOrEmpty ( C1 ) OrElse String . IsNullOrEmpty ( C2 ) OrElse String . IsNullOrEmpty ( C3 ) OrElse String . IsNullOrEmpty ( C4 ) Then
MsgBox ( $ " 添加服务数据异常,行号:{i} " )
If String . IsNullOrEmpty ( C1 ) Then
Table_Grid1 . Range ( i , STcolname . 服务类型 , i , STcolname . 服务类型 ) . BackColor = Color . OrangeRed
End If
If String . IsNullOrEmpty ( C2 ) Then
Table_Grid1 . Range ( i , STcolname . 打开方式 , i , STcolname . 打开方式 ) . BackColor = Color . OrangeRed
End If
If String . IsNullOrEmpty ( C3 ) Then
Table_Grid1 . Range ( i , STcolname . 延时 , i , STcolname . 延时 ) . BackColor = Color . OrangeRed
End If
If String . IsNullOrEmpty ( C4 ) Then
Table_Grid1 . Range ( i , STcolname . 单位 , i , STcolname . 单位 ) . BackColor = Color . OrangeRed
End If
Return
End If
indexstr = showSelectedIndexVal ( C1 , C2 , C3 , C4 , C5 )
G_result = $ " {G_result}{vbLf }{indexstr} "
Next
G_result = G_result . Trim
Me . DialogResult = System . Windows . Forms . DialogResult . OK
Me . Close ( )
Return
End Sub
Private Function GetDelayUnit ( str As String ) As String
Dim result As Integer
Select Case str
Case " ms "
result = 1
Case " s "
result = 2
Case " m "
result = 3
Case " H "
result = 4
Case " Day "
result = 5
Case Else
result = 1
End Select
Return result . ToString
End Function
Private Function FGetDelayUnit ( str As String ) As String
Dim result As String = String . Empty
Select Case str
Case " 1 "
result = " ms "
Case " 2 "
result = " s "
Case " 3 "
result = " m "
Case " 4 "
result = " H "
Case " 5 "
result = " Day "
Case Else
End Select
Return result . ToString
End Function
Private Sub Button2_Click ( sender As Object , e As EventArgs ) Handles Button2 . Click
Table_Grid1 . AddItem ( " " )
Table_Grid1 . Cell ( Table_Grid1 . Rows - 1 , STcolname . 延时 ) . Text = " 0 "
Table_Grid1 . Cell ( Table_Grid1 . Rows - 1 , STcolname . 单位 ) . Text = " ms "
Table_Grid1 . Cell ( Table_Grid1 . Rows - 1 , STcolname . 打开方式 ) . Text = " 1:Open "
End Sub
Private Sub Table_Grid1_CellChange ( Sender As Object , e As Grid . CellChangeEventArgs ) Handles Table_Grid1 . CellChange
If e . Row > 0 Then
2026-03-04 11:11:16 +08:00
If e . Col = STcolname . 服务类型 Then
If Table_Grid1 . Cell ( e . Row , STcolname . 服务类型 ) . Text = " 1:Check-in service " Then
If Dic_2 . Count = 2 Then
Dic_2 . Add ( " 3:Reset the initial power-on " )
End If
Else
If Table_Grid1 . Cell ( e . Row , STcolname . 打开方式 ) . Text = " 3:Reset the initial power-on " Then
Table_Grid1 . Cell ( e . Row , STcolname . 打开方式 ) . Text = " 1 : Open "
End If
If Dic_2 . Count = 3 Then
Dic_2 . Remove ( " 3:Reset the initial power-on " )
End If
End If
End If
2025-12-11 14:22:51 +08:00
If e . Col = STcolname . 延时 Then
If String . IsNullOrEmpty ( Table_Grid1 . Cell ( e . Row , e . Col ) . Text ) Then
Table_Grid1 . Cell ( e . Row , e . Col ) . Text = 0
Return
End If
For Each node In Dic_3
If node . Equals ( Table_Grid1 . Cell ( e . Row , e . Col ) . Text ) Then
Return
End If
Next
Table_Grid1 . Cell ( e . Row , e . Col ) . Text = 0
End If
If String . IsNullOrEmpty ( Table_Grid1 . Cell ( e . Row , e . Col ) . Text ) Then Return
Table_Grid1 . Cell ( e . Row , e . Col ) . BackColor = Color . White
End If
End Sub
Private Sub InitTable ( )
Table_Grid1 . Rows = 1
Table_Grid1 . Cols = STcolname . max
Table_Grid1 . ExtendLastCol = True
For i = 0 To STcolname . max - 1
Dim colorValue As STcolname = CType ( [ Enum ] . Parse ( GetType ( STcolname ) , i ) , STcolname )
Table_Grid1 . Cell ( 0 , i ) . Text = EnumExtender . GetEnumDescription ( colorValue ) ' [Enum].GetName(GetType(STcolname), i)
Select Case i
Case STcolname . 行号
With Table_Grid1 . Column ( i )
. Width = 50
'.Visible = True
. Locked = True
End With
Case STcolname . 延时
With Table_Grid1 . Column ( i )
. Width = 50
. Alignment = FlexCell . AlignmentEnum . CenterCenter
. CellType = CellTypeEnum . ComboBox
End With
'Table_Grid1.ComboBox(i).Locked = True
Case STcolname . 单位
With Table_Grid1 . Column ( i )
. Width = 50
. Alignment = FlexCell . AlignmentEnum . CenterCenter
. CellType = CellTypeEnum . ComboBox
End With
Table_Grid1 . ComboBox ( i ) . Locked = True
Case STcolname . 打开方式
With Table_Grid1 . Column ( i )
. Width = 80
. Alignment = FlexCell . AlignmentEnum . CenterCenter
. CellType = CellTypeEnum . ComboBox
End With
Table_Grid1 . ComboBox ( i ) . Locked = True
Case STcolname . 服务类型
With Table_Grid1 . Column ( i )
. Width = 180
. Alignment = FlexCell . AlignmentEnum . CenterCenter
. CellType = CellTypeEnum . ComboBox
End With
Table_Grid1 . ComboBox ( i ) . Locked = True
Case STcolname . 显示服务
With Table_Grid1 . Column ( i )
. Width = 30
. Alignment = FlexCell . AlignmentEnum . CenterCenter
. CellType = CellTypeEnum . CheckBox
End With
Case Else
Exit For
End Select
Next
End Sub
Private Sub Button3_Click ( sender As Object , e As EventArgs ) Handles Button3 . Click
If Table_Grid1 . ActiveCell . Row > 0 Then
2026-03-04 11:11:16 +08:00
'判断选中服务是否在25 到57区间
Dim tstr As String = Table_Grid1 . Cell ( Table_Grid1 . ActiveCell . Row , STcolname . 服务类型 ) . Text . Trim
Dim arr As String ( ) = tstr . Split ( " : " )
Dim LoopAddri As Integer = Integer . Parse ( arr ( 0 ) . Trim )
If LoopAddri >= 25 AndAlso LoopAddri <= 57 Then
'弹框二次删除确认
If MessageBox . Show ( " This service is a system service. Deleting it may cause system abnormalities. Do you want to proceed with the deletion? " , " Warning " , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) = DialogResult . Yes Then
Table_Grid1 . Row ( Table_Grid1 . ActiveCell . Row ) . Delete ( )
Else
Return
End If
End If
2025-12-11 14:22:51 +08:00
Table_Grid1 . Row ( Table_Grid1 . ActiveCell . Row ) . Delete ( )
End If
End Sub
Private Sub Table_Grid1_ComboDropDown ( Sender As Object , e As Grid . ComboDropDownEventArgs ) Handles Table_Grid1 . ComboDropDown
If e . Row > 0 Then
Table_Grid1 . ComboBox ( e . Col ) . Items . Clear ( )
Select Case e . Col
Case STcolname . 行号
Return
Case STcolname . 延时
Table_Grid1 . ComboBox ( e . Col ) . Items . AddRange ( Dic_3 . ToArray )
Case STcolname . 单位
Table_Grid1 . ComboBox ( e . Col ) . Items . AddRange ( Dic_4 . ToArray )
Case STcolname . 打开方式
2026-03-04 11:11:16 +08:00
'获取服务类型 判断是否为 1: 入住服务
Dim tstr As String = Table_Grid1 . Cell ( e . Row , STcolname . 服务类型 ) . Text . Trim
If tstr . Equals ( " 1:Check-in service " ) Then
Table_Grid1 . ComboBox ( e . Col ) . Items . AddRange ( Dic_2 . ToArray )
Else
Table_Grid1 . ComboBox ( e . Col ) . Items . Add ( Dic_2 ( 0 ) )
Table_Grid1 . ComboBox ( e . Col ) . Items . Add ( Dic_2 ( 1 ) )
End If
2025-12-11 14:22:51 +08:00
Case STcolname . 服务类型
2026-03-04 11:11:16 +08:00
For Each item In Dic_1
'切割字符串(item) 提取LoopAddr
Dim arr As String ( ) = item . Split ( " : " )
'判斷 g_display
If g_diaplay Then
Else
'将arr(0)转为int
Dim LoopAddri As Integer = Integer . Parse ( arr ( 0 ) . Trim )
'過濾掉arr >= 25 AndAlso Node.LoopAddr <= 57
If LoopAddri >= 25 AndAlso LoopAddri <= 57 Then
Continue For
End If
End If
Table_Grid1 . ComboBox ( e . Col ) . Items . Add ( item )
Next
'Table_Grid1.ComboBox(e.Col).Items.AddRange(Dic_1.ToArray)
2025-12-11 14:22:51 +08:00
Case Else
End Select
End If
End Sub
End Class