-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmRelays.vb
78 lines (67 loc) · 3.64 KB
/
frmRelays.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Imports System.Windows.Forms
Imports System.Text.RegularExpressions
Public Class frmRelays
Public theDevice As Dictionary(Of String, Object)
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
' Check that all fields have been entered correctly
' check that at least one relay port was selected
Dim count As Integer = 0
For Each aRow As DataGridViewRow In dgvPorts.Rows
If aRow.Cells(0).Value = True Then
count += 1
If aRow.Cells(2).Value.ToString = "PULSE" AndAlso aRow.Cells(3).Value.ToString < 100 Then
MsgBox("A minimum of 100 milliseconds is required for pulsing a relay.")
Exit Sub
End If
End If
Next
If count = 0 Then
MsgBox("You must select at least one relay port to manipulate via it's checkbox. Otherwise press cancel to go back.")
Exit Sub
End If
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub cboModules_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboModules.SelectedIndexChanged
dgvPorts.Rows.Clear()
' Get the selected module from the device object
Dim theRegex As New Regex("M(\d+)")
If theRegex.IsMatch(cboModules.SelectedItem) Then
Dim moduleNum As Integer = theRegex.Match(cboModules.SelectedItem).Groups(1).Value
Dim theModule As Dictionary(Of String, Object) = theDevice("Modules")(moduleNum - 1)
For i As Integer = 1 To theModule("NumPorts")
dgvPorts.Rows.Add(False, PadZero(i), "OPEN", 0)
Next
End If
End Sub
Private Sub dgvPorts_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles dgvPorts.CellValueChanged
If dgvPorts.CurrentCell IsNot Nothing Then
If e.ColumnIndex = 2 Then
' Dropdown list change
If dgvPorts.CurrentCell.Value.ToString = "PULSE" Then
dgvPorts.CurrentRow.Cells(3).ReadOnly = False
dgvPorts.CurrentRow.Cells(3).Style.ForeColor = Drawing.SystemColors.ControlText
dgvPorts.CurrentRow.Cells(3).Style.BackColor = Drawing.SystemColors.Window
dgvPorts.CurrentRow.Cells(3).Style.SelectionForeColor = Drawing.SystemColors.HighlightText
dgvPorts.CurrentRow.Cells(3).Style.SelectionBackColor = Drawing.SystemColors.Highlight
Else
dgvPorts.CurrentRow.Cells(3).ReadOnly = True
dgvPorts.CurrentRow.Cells(3).Style.ForeColor = Drawing.Color.Gray
dgvPorts.CurrentRow.Cells(3).Style.BackColor = Drawing.Color.LightGray
dgvPorts.CurrentRow.Cells(3).Style.SelectionForeColor = Drawing.Color.Gray
dgvPorts.CurrentRow.Cells(3).Style.SelectionBackColor = Drawing.Color.LightGray
End If
ElseIf e.ColumnIndex = 3 Then
' Pulse time change
If dgvPorts.CurrentCell.Value.ToString < 100 Then
MsgBox("A minimum of 100 milliseconds is required.")
dgvPorts.CurrentCell.Value = 100
End If
End If
End If
End Sub
End Class