Files
Desktop_BLVStudio_EN/BLV_Studio/Test/GridTest/ServiceAttribute.vb
2025-12-11 14:22:51 +08:00

398 lines
14 KiB
VB.net
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
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 IsNothingG_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)
For Each node In G_hostNode.Nodes
Dic_1.Add($"{node.LoopAddr}:{node.Name }")
Next
Dic_2.AddRange({"2:close", "1:open"})
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
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
If intbuf(1) = 2 OrElse intbuf(1) = 1 Then
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
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(buf0) 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(buf1) 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(buf2) 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(buf3)
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)
reslit = $"{strbuf1(0)},{strbuf2(0)},{c3},{t},{c5}"
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
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
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.打开方式
Table_Grid1.ComboBox(e.Col).Items.AddRange(Dic_2.ToArray)
Case STcolname.服务类型
Table_Grid1.ComboBox(e.Col).Items.AddRange(Dic_1.ToArray)
Case Else
End Select
End If
End Sub
End Class