Vous êtes sur la page 1sur 36

Imports System.

IO
Imports MySql.Data.MySqlClient
Imports System.Data

Public Class Form1
Dim baudrate As Integer
Dim cp As New System.IO.Ports.SerialPort
Dim showbl As Boolean = False
Dim StrSta1 As String = "@01,1,0,75#"
Dim StrSta2 As String = "@02,1,0,55#"
Dim StrSta3 As String = "@03,1,0,55#"
Dim StrSta4 As String = "@04,1,0,55#"
Dim StrSta5 As String = "@05,1,0,55#"
Dim StrSta6 As String = "@06,1,0,55#"
Dim StrSta7 As String = "@07,1,0,55#"
Dim StrSta8 As String = "@08,1,0,55#"
Dim StrSta9 As String = "@09,1,0,55#"

Dim SoTram As Integer = 9
Dim StaRecv01 As Integer = 0
Dim StaRecv02 As Integer = 0
Dim StaRecv03 As Integer = 0
Dim StaRecv04 As Integer = 0
Dim StaRecv05 As Integer = 0
Dim StaRecv06 As Integer = 0
Dim StaRecv07 As Integer = 0
Dim StaRecv08 As Integer = 0
Dim StaRecv09 As Integer = 0

Dim PerRecv01 As String = 0
Dim PerRecv02 As String = 0
Dim PerRecv03 As String = 0
Dim PerRecv04 As String = 0
Dim PerRecv05 As String = 0
Dim PerRecv06 As String = 0
Dim PerRecv07 As String = 0
Dim PerRecv08 As String = 0
Dim PerRecv09 As String = 0

Dim ConnectSta1 As Boolean = False
Dim ConnectSta2 As Boolean = False
Dim ConnectSta3 As Boolean = False
Dim ConnectSta4 As Boolean = False
Dim ConnectSta5 As Boolean = False
Dim ConnectSta6 As Boolean = False
Dim ConnectSta7 As Boolean = False
Dim ConnectSta8 As Boolean = False
Dim ConnectSta9 As Boolean = False

Dim ServerString As String = "Server=localhost;User Id=root;Password=usbw;Database=data_from_gsm"
Dim SQLConnection As MySqlConnection = New MySqlConnection
Dim ndHeader() As String = {"Thi gian", "a ch", " % tit kim", "Ch iu khin"}

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
defgui()
dhText11.Enabled = True
For i As Integer = 0 To My.Computer.Ports.SerialPortNames.Count - 1
cbbComName.Items.Add(My.Computer.Ports.SerialPortNames(i))
Next
SQLConnection.ConnectionString = ServerString
Try
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
MsgBox("Kt ni thnh cng ti c s d liu")

'UpdateStr("INSERT INTO trangthai(IdTram,Status,OnTime,Percent)VALUES('5','1','1/1/2012 00:02','55')")
Else
SQLConnection.Close()
MsgBox("ng kt ni")
End If
Catch ex As Exception
MsgBox("Khng kt ni c ti c s d liu")
End Try
End Sub

Public Sub defgui()
Label1.Text = "Cha kt ni"
Label1.ForeColor = Color.Red
rb115200.Checked = True
btnSendStr.Enabled = False
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = False
Button7.Enabled = False
Button8.Enabled = False
Button9.Enabled = False
End Sub



Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
If btnConnect.Text = "Kt ni" Then
If ComPort.IsOpen Then
ComPort.Close()
End If
Try
With ComPort
.PortName = cbbComName.Text
.BaudRate = Me.baudrate
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
End With
ComPort.Open()
btnConnect.Text = "Ngt kt ni"
MsgBox("Kt ni thnh cng")
'qua trinh thuc hien lenh gui
SendStr()
'qua trinh thuc hien lenh gui
btnSendStr.Enabled = True
Label1.Text = " kt ni"
Label1.ForeColor = Color.Blue
Catch ex As Exception
MsgBox("Bn phi chn li cng COM")
End Try
Else
Try
ComPort.Close()
btnConnect.Text = "Kt ni"
Label1.Text = "Cha kt ni"
btnSendStr.Enabled = False
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = False
Button7.Enabled = False
Button8.Enabled = False
Button9.Enabled = False
Label1.ForeColor = Color.Red
MsgBox("Ngt kt ni thnh cng")
Catch ex As Exception
MsgBox("Ngt kt ni khng thnh cng")
End Try
End If
End Sub

Private Sub SendStr(ByVal str As String)
Try
ComPort.Write(Chr(13) & str & vbCrLf)
Catch ex As Exception
'MsgBox("Li, khng gi c chui!" & ex.ToString)
End Try
End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'SendStr(Me.txtSend.Text)
End Sub

Private Sub ComPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles
ComPort.DataReceived
Try
Dim StrRecv As String = ComPort.ReadExisting
str = StrRecv
StrRecv = StrRecv.Substring(InStr(StrRecv, "@") - 1, InStr(StrRecv, "#") - InStr(StrRecv, "@") + 1)
Dim arr As Char() = {",", "@", "#"}
Dim hbuf() As String = StrRecv.Split(arr, StringSplitOptions.RemoveEmptyEntries)
Dim sqlSta As String = ""
If hbuf.Length = 4 Then
Dim t_day As String = Date.Today
Dim t_hour As String = TimeOfDay
Select Case hbuf(0)
Case "01"
StaRecv01 = hbuf(1)
PerRecv01 = hbuf(2)
ConnectSta1 = True
Case "02"
StaRecv02 = hbuf(1)
PerRecv02 = hbuf(2)
ConnectSta2 = True
Case "03"
StaRecv03 = hbuf(1)
PerRecv03 = hbuf(2)
ConnectSta3 = True
Case "04"
StaRecv04 = hbuf(1)
PerRecv04 = hbuf(2)
ConnectSta4 = True
Case "05"
StaRecv05 = hbuf(1)
PerRecv05 = hbuf(2)
ConnectSta5 = True
Case "06"
StaRecv06 = hbuf(1)
PerRecv06 = hbuf(2)
ConnectSta6 = True
Case "07"
StaRecv07 = hbuf(1)
PerRecv07 = hbuf(2)
ConnectSta7 = True
Case "08"
StaRecv08 = hbuf(1)
PerRecv08 = hbuf(2)
ConnectSta8 = True
Case "09"
StaRecv09 = hbuf(1)
PerRecv09 = hbuf(2)
ConnectSta9 = True

End Select
sqlSta = "INSERT INTO trangthai(IdTram,Status,OnTime,Percent,Mode) " & _
"VALUES('" & hbuf(0) & "','" & hbuf(1) & "','" & t_day & " " & t_hour & "','" & hbuf(3) & "','" &
hbuf(2) & "')"
UpdateStr(sqlSta)

If CheckSta(hbuf(0), hbuf(1), hbuf(2)) Then
sqlSta = "INSERT INTO rpttable(DevId,DateShow,TimeShow,StaShow,ModShow,OnTime,Percent,Mode,Status) " & _
"VALUES('" & hbuf(0) & "','" & GetTimeShow(0) & "','" & GetTimeShow(1) & "','" & GetStaModShow(0, hbuf(1)) & _
"','" & GetStaModShow(1, hbuf(2)) & "','" & GetTimeShow(2) & "','" & hbuf(3) & "','" & hbuf(2) & "','" & hbuf(1)
& "')"
UpdateStr(sqlSta)
End If

End If
Catch ex As Exception

End Try
End Sub

Public Delegate Sub myDelegate()
Public Sub UpdateStr(ByRef SQLStatement As String)
Dim cmd As MySqlCommand = New MySqlCommand
With cmd
.CommandText = SQLStatement
.CommandType = CommandType.Text
.Connection = SQLConnection
.ExecuteNonQuery()
End With
End Sub

Public Function CheckSta(ByVal DevId As Integer, ByVal Status As Integer, ByVal Mode As Integer) As Boolean
Try
Dim dhtab As New DataTable
Dim dhcom As New MySqlDataAdapter("SELECT Status,Mode,Percent FROM rpttable WHERE DevId='" & DevId & "'", SQLConnection)
dhcom.Fill(dhtab)
Dim dhInt As Integer = dhtab.Rows.Count - 1
If dhInt = -1 Then
Return True
Else
If Status <> dhtab.Rows(dhInt).Item("Status") Or Mode <> dhtab.Rows(dhInt).Item("Mode") Then
Return True
Else
Return False
End If

End If
Catch ex As Exception
Return False
End Try

End Function
Public Function GetTimeShow(ByVal dhType As Integer) As String
Select Case dhType
Case 0
Return Now.Day & "/" & Now.Month & "/" & Now.Year
Case 1
Return Now.Hour & ":" & Now.Minute
Case Else
Return Now.Year & "-" & Now.Month & "-" & Now.Day & " " & Now.Hour & ":" & Now.Minute & ":" & Now.Second '2012-01-09
09:09:19
End Select
End Function
Public Function GetStaModShow(ByVal dhType As Integer, ByVal ndSta As Integer) As String
Select Case dhType
Case 0
If ndSta = 0 Then
Return "Tat"
Else
Return "Bat"
End If
Case Else
If ndSta = 0 Then
Return "Tai cho"
Else
Return "Tu xa"
End If
End Select

End Function

Public Function GetPercent(ByVal Percent As String) As String
If Percent <> "" Then
Return Percent
Else
Return "50"
End If
End Function

Public Function GetStatus(ByVal Sta As Button) As Integer
If Sta.BackColor = Color.Blue Then
Return 1
Else
Return 0
End If
End Function
Dim str As String = ""
'Public Sub updateRcv()
' 'Dim str As String = ComPort.ReadExisting
' With txtShow
' .Font = New Font("Garamond", 13.0!, FontStyle.Regular)
' .SelectionColor = Color.Blue
' .AppendText(str & vbNewLine)
' '.Cursor.Position.
' End With
'End Sub
'Private Sub txtSend_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
' If e.KeyChar = Chr(13) Then
' SendStr(Me.txtSend.Text)
' Me.txtSend.Clear()
' End If
'End Sub
Private Sub delay()
For i As Integer = 0 To 300
Me.Label1.Text = "ang cp nht"
Console.WriteLine("ang cp nht")
Next
End Sub

Private Sub rb1200_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rb1200.CheckedChanged
Me.baudrate = 1200

End Sub
Private Sub rb2400_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rb2400.CheckedChanged
Me.baudrate = 2400
End Sub

Private Sub rb4800_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rb4800.CheckedChanged
Me.baudrate = 4800
End Sub

Private Sub rb9600_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rb9600.CheckedChanged
Me.baudrate = 9600
End Sub

Private Sub rb19200_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rb19200.CheckedChanged
Me.baudrate = 19200
End Sub

Private Sub rb115200_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rb115200.CheckedChanged
Me.baudrate = 115200
End Sub

Private Sub SendStr()
a = SoTram - 1
ndt.Start()
ndt1.Start()
End Sub

Dim a As Integer = 0
Private Sub Timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ndt.Tick
Try
If a < SoTram Then
a = a + 1
Select Case a
Case 1
If dhText11.Text <> "" Then
If Now.Hour = TimeValue(dhText11.Text).Hour And Now.Minute = TimeValue(dhText11.Text).Minute Then
ComPort.Write("@01,0,1,55")
dhText11.Clear()
Button1.BackColor = Color.Red
Exit Select
End If
End If
If dhText12.Text <> "" Then
If Now.Hour = TimeValue(dhText12.Text).Hour And Now.Minute = TimeValue(dhText12.Text).Minute Then
ComPort.Write("@01,1,1,55")
dhText12.Clear()
Button1.BackColor = Color.Blue
Exit Try
End If
End If
ComPort.Write(StrSta1)
Case 2
If dhText21.Text <> "" Then
If Now.Hour = TimeValue(dhText21.Text).Hour And Now.Minute = TimeValue(dhText21.Text).Minute Then
ComPort.Write("@02,0,1,55")
dhText21.Clear()
Button2.BackColor = Color.Red
Exit Select
End If
End If
If dhText22.Text <> "" Then
If Now.Hour = TimeValue(dhText22.Text).Hour And Now.Minute = TimeValue(dhText22.Text).Minute Then
ComPort.Write("@02,1,1,55")
dhText22.Clear()
Button2.BackColor = Color.Blue
Exit Select
End If
End If
ComPort.Write(StrSta2)
Case 3
If dhText31.Text <> "" Then
If Now.Hour = TimeValue(dhText31.Text).Hour And Now.Minute = TimeValue(dhText31.Text).Minute Then
ComPort.Write("@03,0,1,55")
dhText31.Clear()
Button3.BackColor = Color.Red
Exit Select
End If
End If
If dhText32.Text <> "" Then
If Now.Hour = TimeValue(dhText32.Text).Hour And Now.Minute = TimeValue(dhText32.Text).Minute Then
ComPort.Write("@03,1,1,55")
dhText32.Clear()
Button3.BackColor = Color.Blue
Exit Select
End If
End If
ComPort.Write(StrSta3)
Case 4
If dhText41.Text <> "" Then
If Now.Hour = TimeValue(dhText41.Text).Hour And Now.Minute = TimeValue(dhText41.Text).Minute Then
ComPort.Write("@04,0,1,55")
dhText41.Clear()
Button4.BackColor = Color.Red
Exit Select
End If
End If
If dhText42.Text <> "" Then
If Now.Hour = TimeValue(dhText42.Text).Hour And Now.Minute = TimeValue(dhText42.Text).Minute Then
ComPort.Write("@04,1,1,55")
dhText42.Clear()
Button4.BackColor = Color.Blue
Exit Select
End If
End If
ComPort.Write(StrSta4)
Case 5
If dhText51.Text <> "" Then
If Now.Hour = TimeValue(dhText51.Text).Hour And Now.Minute = TimeValue(dhText51.Text).Minute Then
ComPort.Write("@05,0,1,55")
dhText51.Clear()
Button5.BackColor = Color.Red
Exit Select
End If
End If
If dhText52.Text <> "" Then
If Now.Hour = TimeValue(dhText52.Text).Hour And Now.Minute = TimeValue(dhText52.Text).Minute Then
ComPort.Write("@05,1,1,55")
dhText52.Clear()
Button5.BackColor = Color.Blue
Exit Select
End If
End If
ComPort.Write(StrSta5)
Case 6
If dhText61.Text <> "" Then
If Now.Hour = TimeValue(dhText61.Text).Hour And Now.Minute = TimeValue(dhText61.Text).Minute Then
ComPort.Write("@06,0,1,55")
dhText61.Clear()
Button6.BackColor = Color.Red
Exit Select
End If
End If
If dhText62.Text <> "" Then
If Now.Hour = TimeValue(dhText62.Text).Hour And Now.Minute = TimeValue(dhText62.Text).Minute Then
ComPort.Write("@06,1,1,55")
dhText62.Clear()
Button6.BackColor = Color.Blue
Exit Select
End If
End If
ComPort.Write(StrSta6)
Case 7
If dhText71.Text <> "" Then
If Now.Hour = TimeValue(dhText71.Text).Hour And Now.Minute = TimeValue(dhText71.Text).Minute Then
ComPort.Write("@07,0,1,55")
dhText71.Clear()
Button7.BackColor = Color.Red
Exit Select
End If
End If
If dhText72.Text <> "" Then
If Now.Hour = TimeValue(dhText72.Text).Hour And Now.Minute = TimeValue(dhText72.Text).Minute Then
ComPort.Write("@07,1,1,55")
dhText72.Clear()
Button7.BackColor = Color.Blue
Exit Select
End If
End If
ComPort.Write(StrSta7)
Case 8
If Now.Hour = TimeValue(dhText81.Text).Hour And Now.Minute = TimeValue(dhText81.Text).Minute Then
ComPort.Write("@08,0,1,55")
dhText81.Clear()
Button8.BackColor = Color.Red
Exit Select
End If
If Now.Hour = TimeValue(dhText82.Text).Hour And Now.Minute = TimeValue(dhText82.Text).Minute Then
ComPort.Write("@08,1,1,55")
dhText82.Clear()
Button8.BackColor = Color.Blue
Exit Select
End If
ComPort.Write(StrSta8)
Case 9
If Now.Hour = TimeValue(dhText91.Text).Hour And Now.Minute = TimeValue(dhText91.Text).Minute Then
ComPort.Write("@09,0,1,55")
dhText91.Clear()
Button9.BackColor = Color.Red
Exit Select
End If
If Now.Hour = TimeValue(dhText92.Text).Hour And Now.Minute = TimeValue(dhText92.Text).Minute Then
ComPort.Write("@09,1,1,55")
dhText92.Clear()
Button9.BackColor = Color.Blue
Exit Select
End If
ComPort.Write(StrSta9)
End Select
If a = SoTram Then
a = 0
End If
End If
'Update_State()
Catch ex As Exception
End Try
End Sub

Private Sub ndt1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ndt1.Tick
If StaRecv01 = 1 Then
Button1.BackColor = Color.Blue
Else
Button1.BackColor = Color.Red
End If
If Sta1Mod0.Checked Then
TextBox1.Text = PerRecv01
End If
If ConnectSta1 Then
ndSta1.BackColor = Color.Blue
Else
ndSta1.BackColor = Color.Red
Button1.Enabled = False
dhText11.Enabled = False
dhText12.Enabled = False
End If
If ComparTime(GetTimeFromDb(1)) Then
ConnectSta1 = False
ndSta1.BackColor = Color.Red
End If

If StaRecv02 = 1 Then
Button2.BackColor = Color.Blue
Else
Button2.BackColor = Color.Red
End If
If Sta2Mod0.Checked Then
TextBox2.Text = PerRecv02
End If
If ConnectSta2 Then
ndSta2.BackColor = Color.Blue
End If
If ComparTime(GetTimeFromDb(2)) Then
ConnectSta2 = False
ndSta2.BackColor = Color.Red
End If

If StaRecv03 = 1 Then
Button3.BackColor = Color.Blue
Else
Button3.BackColor = Color.Red
End If
If Sta3Mod0.Checked Then
TextBox3.Text = PerRecv03
End If
If ConnectSta3 Then
ndSta3.BackColor = Color.Blue
End If
If ComparTime(GetTimeFromDb(3)) Then
ConnectSta3 = False
ndSta3.BackColor = Color.Red
End If

If StaRecv04 = 1 Then
Button4.BackColor = Color.Blue
Else
Button4.BackColor = Color.Red
End If
If Sta4Mod0.Checked Then
TextBox4.Text = PerRecv04
End If
If ConnectSta4 Then
ndSta4.BackColor = Color.Blue
End If
If ComparTime(GetTimeFromDb(4)) Then
ConnectSta4 = False
ndSta4.BackColor = Color.Red
End If

If StaRecv05 = 1 Then
Button5.BackColor = Color.Blue
Else
Button5.BackColor = Color.Red
End If
If Sta5Mod0.Checked Then
TextBox5.Text = PerRecv05
End If
If ConnectSta5 Then
ndSta5.BackColor = Color.Blue
End If
If ComparTime(GetTimeFromDb(5)) Then
ConnectSta5 = False
ndSta5.BackColor = Color.Red
End If

If StaRecv06 = 1 Then
Button6.BackColor = Color.Blue
Else
Button6.BackColor = Color.Red
End If
If Sta6Mod0.Checked Then
TextBox6.Text = PerRecv06
End If
If ConnectSta6 Then
ndSta6.BackColor = Color.Blue
End If
If ComparTime(GetTimeFromDb(6)) Then
ConnectSta6 = False
ndSta6.BackColor = Color.Red
End If

If StaRecv07 = 1 Then
Button7.BackColor = Color.Blue
Else
Button7.BackColor = Color.Red
End If
If Sta7Mod0.Checked Then
TextBox7.Text = PerRecv07
End If
If ConnectSta7 Then
ndSta7.BackColor = Color.Blue
End If
If ComparTime(GetTimeFromDb(7)) Then
ConnectSta7 = False
ndSta7.BackColor = Color.Red
End If

If StaRecv08 = 1 Then
Button8.BackColor = Color.Blue
Else
Button8.BackColor = Color.Red
End If
If Sta8Mod0.Checked Then
TextBox8.Text = PerRecv08
End If
If ConnectSta8 Then
ndSta8.BackColor = Color.Blue
End If
If ComparTime(GetTimeFromDb(8)) Then
ConnectSta8 = False
ndSta8.BackColor = Color.Red
End If

If StaRecv09 = 1 Then
Button9.BackColor = Color.Blue
Else
Button9.BackColor = Color.Red
End If
If Sta9Mod0.Checked Then
TextBox9.Text = PerRecv09
End If
If ConnectSta9 Then
ndSta9.BackColor = Color.Blue
End If
If ComparTime(GetTimeFromDb(9)) Then
ConnectSta9 = False
ndSta9.BackColor = Color.Red
End If
End Sub

Public Function GetTimeFromDb(ByVal Id As Integer) As String
Try
Dim dhtab As New DataTable
Dim dhcom As New MySqlDataAdapter("SELECT Ontime FROM trangthai WHERE Idtram='" & Id & "'", SQLConnection)
dhcom.Fill(dhtab)
Dim i As Integer = dhtab.Rows.Count
Return dhtab.Rows(i - 1).Item("Ontime")
Catch
Return "ndHold"
End Try
End Function

Public Function ComparTime(ByVal strTime As String) As Boolean
Try
Dim ndate As Date = Date.Parse(strTime).AddMinutes(5)
If Now.Hour = ndate.Hour And Now.Minute = ndate.Minute Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function

Private Function GetDate(ByVal Str As Date) As String
Return Str.Year & "-" & Str.Month & "-" & Str.Day
End Function



Private Sub Sta1Mod1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta1Mod1.CheckedChanged
If ConnectSta1 Then
TextBox1.Enabled = True
CheckBox1.Enabled = True
If CheckBox1.Checked Then
Button1.Enabled = False
dhText11.Enabled = True
dhText12.Enabled = True
Else
Button1.Enabled = True
dhText11.Enabled = False
dhText12.Enabled = False
End If
StrSta1 = "@01," & GetStatus(Button1) & ",1," & GetPercent(TextBox1.Text) & "#"
SendStr(StrSta1)
End If
End Sub

Private Sub Sta1Mod0_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta1Mod0.CheckedChanged
Button1.Enabled = False
TextBox1.Enabled = False
dhText11.Enabled = False
dhText12.Enabled = False
CheckBox1.Enabled = False
If ConnectSta1 Then
StrSta1 = "@01," & GetStatus(Button1) & ",0," & GetPercent(TextBox1.Text) & "#"
SendStr(StrSta1)
End If
End Sub

Private Sub Sta2Mod0_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta2Mod0.CheckedChanged
Button2.Enabled = False
TextBox2.Enabled = False
dhText21.Enabled = False
dhText22.Enabled = False
CheckBox2.Enabled = False
If ConnectSta2 Then
StrSta2 = "@02," & GetStatus(Button2) & ",0," & GetPercent(TextBox2.Text) & "#"
SendStr(StrSta2)
End If
End Sub

Private Sub Sta2Mod1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta2Mod1.CheckedChanged
If ConnectSta2 Then
TextBox2.Enabled = True
CheckBox2.Enabled = True
If CheckBox2.Checked Then
Button2.Enabled = False
dhText21.Enabled = True
dhText22.Enabled = True
Else
Button2.Enabled = True
dhText21.Enabled = False
dhText22.Enabled = False
End If
StrSta2 = "@02," & GetStatus(Button2) & ",1," & GetPercent(TextBox2.Text) & "#"
SendStr(StrSta2)
End If
End Sub

Private Sub Sta3Mod0_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta3Mod0.CheckedChanged
Button3.Enabled = False
TextBox3.Enabled = False
dhText31.Enabled = False
dhText32.Enabled = False
CheckBox3.Enabled = False
If ConnectSta3 Then
StrSta3 = "@03," & GetStatus(Button3) & ",0," & GetPercent(TextBox3.Text) & "#"
SendStr(StrSta3)
End If
End Sub

Private Sub Sta3Mod1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta3Mod1.CheckedChanged
If ConnectSta3 Then
TextBox3.Enabled = True
CheckBox3.Enabled = True
If CheckBox3.Checked Then
Button3.Enabled = False
dhText31.Enabled = True
dhText32.Enabled = True
Else
Button3.Enabled = True
dhText31.Enabled = False
dhText32.Enabled = False
End If
StrSta3 = "@03," & GetStatus(Button3) & ",1," & GetPercent(TextBox3.Text) & "#"
SendStr(StrSta3)
End If
End Sub

Private Sub Sta4Mod0_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta4Mod0.CheckedChanged
Button4.Enabled = False
TextBox4.Enabled = False
dhText41.Enabled = False
dhText42.Enabled = False
CheckBox4.Enabled = False
If ConnectSta4 Then
StrSta4 = "@04," & GetStatus(Button4) & ",0," & GetPercent(TextBox4.Text) & "#"
SendStr(StrSta4)
End If
End Sub

Private Sub Sta4Mod1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta4Mod1.CheckedChanged
If ConnectSta4 Then
TextBox4.Enabled = True
CheckBox4.Enabled = True
If CheckBox4.Checked Then
Button4.Enabled = False
dhText41.Enabled = True
dhText42.Enabled = True
Else
Button4.Enabled = True
dhText41.Enabled = False
dhText42.Enabled = False
End If
StrSta4 = "@04," & GetStatus(Button4) & ",1," & GetPercent(TextBox4.Text) & "#"
SendStr(StrSta4)
End If
End Sub

Private Sub Sta5Mod0_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta5Mod0.CheckedChanged
Button5.Enabled = False
TextBox5.Enabled = False
dhText51.Enabled = False
dhText52.Enabled = False
CheckBox5.Enabled = False
If ConnectSta5 Then
StrSta5 = "@05," & GetStatus(Button5) & ",0," & GetPercent(TextBox5.Text) & "#"
SendStr(StrSta5)
End If
End Sub

Private Sub Sta5Mod1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta5Mod1.CheckedChanged
If ConnectSta5 Then
TextBox5.Enabled = True
CheckBox5.Enabled = True
If CheckBox5.Checked Then
Button5.Enabled = False
dhText51.Enabled = True
dhText52.Enabled = True
Else
Button5.Enabled = True
dhText51.Enabled = False
dhText52.Enabled = False
End If
StrSta5 = "@05," & GetStatus(Button5) & ",1," & GetPercent(TextBox5.Text) & "#"
SendStr(StrSta5)
End If
End Sub

Private Sub Sta6Mod0_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta6Mod0.CheckedChanged
Button6.Enabled = False
TextBox6.Enabled = False
dhText61.Enabled = False
dhText62.Enabled = False
CheckBox6.Enabled = False
If ConnectSta6 Then
StrSta6 = "@06," & GetStatus(Button6) & ",0," & GetPercent(TextBox6.Text) & "#"
SendStr(StrSta6)
End If
End Sub

Private Sub Sta6Mod1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta6Mod1.CheckedChanged
If ConnectSta6 Then
TextBox6.Enabled = True
CheckBox6.Enabled = True
If CheckBox6.Checked Then
Button6.Enabled = False
dhText61.Enabled = True
dhText62.Enabled = True
Else
Button6.Enabled = True
dhText61.Enabled = False
dhText62.Enabled = False
End If
StrSta6 = "@06," & GetStatus(Button6) & ",1," & GetPercent(TextBox6.Text) & "#"
SendStr(StrSta6)
End If
End Sub

Private Sub Sta7Mod0_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta7Mod0.CheckedChanged
Button7.Enabled = False
TextBox7.Enabled = False
dhText71.Enabled = False
dhText72.Enabled = False
CheckBox7.Enabled = False
If ConnectSta7 Then
StrSta7 = "@07," & GetStatus(Button7) & ",0," & GetPercent(TextBox7.Text) & "#"
SendStr(StrSta7)
End If
End Sub

Private Sub Sta7Mod1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta7Mod1.CheckedChanged
If ConnectSta7 Then
TextBox7.Enabled = True
CheckBox7.Enabled = True
If CheckBox7.Checked Then
Button7.Enabled = False
dhText71.Enabled = True
dhText72.Enabled = True
Else
Button7.Enabled = True
dhText71.Enabled = False
dhText72.Enabled = False
End If
StrSta7 = "@07," & GetStatus(Button7) & ",1," & GetPercent(TextBox7.Text) & "#"
SendStr(StrSta7)
End If
End Sub

Private Sub Sta8Mod0_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta8Mod0.CheckedChanged
Button8.Enabled = False
TextBox8.Enabled = False
dhText81.Enabled = False
dhText82.Enabled = False
CheckBox8.Enabled = False
If ConnectSta8 Then
StrSta8 = "@08," & GetStatus(Button8) & ",0," & GetPercent(TextBox8.Text) & "#"
SendStr(StrSta8)
End If
End Sub

Private Sub Sta8Mod1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta8Mod1.CheckedChanged
If ConnectSta8 Then
TextBox8.Enabled = True
CheckBox8.Enabled = True
If CheckBox8.Checked Then
Button8.Enabled = False
dhText81.Enabled = True
dhText82.Enabled = True
Else
Button8.Enabled = True
dhText81.Enabled = False
dhText82.Enabled = False
End If
StrSta8 = "@08," & GetStatus(Button8) & ",1," & GetPercent(TextBox8.Text) & "#"
SendStr(StrSta8)
End If
End Sub

Private Sub Sta9Mod0_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta9Mod0.CheckedChanged
Button9.Enabled = False
TextBox9.Enabled = False
dhText91.Enabled = False
dhText92.Enabled = False
CheckBox9.Enabled = False
If ConnectSta9 Then
StrSta9 = "@09," & GetStatus(Button9) & ",0," & GetPercent(TextBox9.Text) & "#"
SendStr(StrSta9)
End If
End Sub

Private Sub Sta9Mod1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sta9Mod1.CheckedChanged
If ConnectSta9 Then
TextBox9.Enabled = True
CheckBox9.Enabled = True
If CheckBox9.Checked Then
Button9.Enabled = False
dhText91.Enabled = True
dhText92.Enabled = True
Else
Button9.Enabled = True
dhText91.Enabled = False
dhText92.Enabled = False
End If
StrSta9 = "@09," & GetStatus(Button9) & ",1," & GetPercent(TextBox9.Text) & "#"
SendStr(StrSta9)
End If
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
If Integer.Parse(txtSoTram.Text) < 10 Then
SoTram = Integer.Parse(txtSoTram.Text)
Else
txtSoTram.Clear()
MsgBox("Nhp s trm di 9!")
End If
Catch ex As Exception
txtSoTram.Clear()
MsgBox("Nhp s t nhin di 9!")
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.BackColor = Color.Red Then
Button1.BackColor = Color.Blue
Else
Button1.BackColor = Color.Red
End If
StrSta1 = "@01," & GetStatus(Button1) & ",1," & GetPercent(TextBox1.Text) & "#"
SendStr(StrSta1)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button2.BackColor = Color.Red Then
Button2.BackColor = Color.Blue
Else
Button2.BackColor = Color.Red
End If
StrSta2 = "@02," & GetStatus(Button2) & ",1," & GetPercent(TextBox2.Text) & "#"
SendStr(StrSta2)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button3.BackColor = Color.Red Then
Button3.BackColor = Color.Blue
Else
Button3.BackColor = Color.Red
End If
StrSta3 = "@03," & GetStatus(Button3) & ",1," & GetPercent(TextBox3.Text) & "#"
SendStr(StrSta3)
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.BackColor = Color.Red Then
Button4.BackColor = Color.Blue
Else
Button4.BackColor = Color.Red
End If
StrSta4 = "@04," & GetStatus(Button4) & ",1," & GetPercent(TextBox4.Text) & "#"
SendStr(StrSta4)
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If Button5.BackColor = Color.Red Then
Button5.BackColor = Color.Blue
Else
Button5.BackColor = Color.Red
End If
StrSta5 = "@05," & GetStatus(Button5) & ",1," & GetPercent(TextBox5.Text) & "#"
SendStr(StrSta5)
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Button6.BackColor = Color.Red Then
Button6.BackColor = Color.Blue
Else
Button6.BackColor = Color.Red
End If
StrSta6 = "@06," & GetStatus(Button6) & ",1," & GetPercent(TextBox6.Text) & "#"
SendStr(StrSta6)
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If Button7.BackColor = Color.Red Then
Button7.BackColor = Color.Blue
Else
Button7.BackColor = Color.Red
End If
StrSta7 = "@07," & GetStatus(Button7) & ",1," & GetPercent(TextBox7.Text) & "#"
SendStr(StrSta7)
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If Button8.BackColor = Color.Red Then
Button8.BackColor = Color.Blue
Else
Button8.BackColor = Color.Red
End If
StrSta8 = "@08," & GetStatus(Button8) & ",1," & GetPercent(TextBox8.Text) & "#"
SendStr(StrSta8)

End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If Button9.BackColor = Color.Red Then
Button9.BackColor = Color.Blue
Else
Button9.BackColor = Color.Red
End If
StrSta9 = "@09," & GetStatus(Button9) & ",1," & GetPercent(TextBox9.Text) & "#"
SendStr(StrSta9)

End Sub


'Public Sub Update_State()
' '-----------------------------------------------------------------------------------------------------------
' If Sta1Mod0.Checked Then
' StrSta1 = "@01,0,0," & TextBox1.Text & "#"
' If StaRecv01 = 1 Then
' Button1.BackColor = Color.Blue
' Else
' Button1.BackColor = Color.Red
' End If
' TextBox1.Text = PerRecv01 ' GIA TRI NHAN VE TU THIET BI
' End If
' If Sta1Mod1.Checked Then
' If Button1.BackColor = Color.Red Then
' StrSta1 = "@01,0,1," & TextBox1.Text & "#"
' Else
' StrSta1 = "@01,1,1," & TextBox1.Text & "#"
' End If
' End If
' '-----------------------------------------------------------------------------------------------------------
' If Sta2Mod0.Checked Then
' StrSta2 = "@02,0,0," & TextBox2.Text & "#"
' If StaRecv02 = 1 Then
' Button2.BackColor = Color.Blue
' Else
' Button2.BackColor = Color.Red
' End If
' TextBox2.Text = PerRecv02 ' GIA TRI NHAN VE TU THIET BI
' End If
' If Sta2Mod1.Checked Then
' If Button2.BackColor = Color.Red Then
' StrSta2 = "@02,0,1," & TextBox2.Text & "#"
' Else
' StrSta2 = "@02,1,1," & TextBox2.Text & "#"
' End If
' End If
' '-----------------------------------------------------------------------------------------------------------
' If Sta3Mod0.Checked Then
' StrSta3 = "@03,0,0," & TextBox3.Text & "#"
' If StaRecv03 = 1 Then
' Button3.BackColor = Color.Blue
' Else
' Button3.BackColor = Color.Red
' End If
' TextBox3.Text = PerRecv03 ' GIA TRI NHAN VE TU THIET BI
' End If
' If Sta3Mod1.Checked Then
' If Button3.BackColor = Color.Red Then
' StrSta3 = "@03,0,1," & TextBox3.Text & "#"
' Else
' StrSta3 = "@03,1,1," & TextBox3.Text & "#"
' End If
' End If
' '-----------------------------------------------------------------------------------------------------------
' If Sta4Mod0.Checked Then
' StrSta4 = "@04,0,0," & TextBox4.Text & "#"
' If StaRecv04 = 1 Then
' Button4.BackColor = Color.Blue
' Else
' Button4.BackColor = Color.Red
' End If
' TextBox4.Text = PerRecv04 ' GIA TRI NHAN VE TU THIET BI
' End If
' If Sta4Mod1.Checked Then
' If Button4.BackColor = Color.Red Then
' StrSta4 = "@04,0,1," & TextBox4.Text & "#"
' Else
' StrSta4 = "@04,1,1," & TextBox4.Text & "#"
' End If
' End If
' '-----------------------------------------------------------------------------------------------------------
' If Sta5Mod0.Checked Then
' StrSta5 = "@05,0,0," & TextBox5.Text & "#"
' If StaRecv05 = 1 Then
' Button5.BackColor = Color.Blue
' Else
' Button5.BackColor = Color.Red
' End If
' TextBox5.Text = PerRecv05 ' GIA TRI NHAN VE TU THIET BI
' End If
' If Sta5Mod1.Checked Then
' If Button5.BackColor = Color.Red Then
' StrSta5 = "@05,0,1," & TextBox5.Text & "#"
' Else
' StrSta5 = "@05,1,1," & TextBox5.Text & "#"
' End If
' End If
' '-----------------------------------------------------------------------------------------------------------
' If Sta6Mod0.Checked Then
' StrSta6 = "@06,0,0," & TextBox6.Text & "#"
' If StaRecv06 = 1 Then
' Button6.BackColor = Color.Blue
' Else
' Button6.BackColor = Color.Red
' End If
' TextBox6.Text = PerRecv06 ' GIA TRI NHAN VE TU THIET BI
' End If
' If Sta6Mod1.Checked Then
' If Button6.BackColor = Color.Red Then
' StrSta6 = "@06,0,1," & TextBox6.Text & "#"
' Else
' StrSta6 = "@06,1,1," & TextBox6.Text & "#"
' End If
' End If
' '-----------------------------------------------------------------------------------------------------------
' If Sta7Mod0.Checked Then
' StrSta7 = "@07,0,0," & TextBox7.Text & "#"
' If StaRecv07 = 1 Then
' Button7.BackColor = Color.Blue
' Else
' Button7.BackColor = Color.Red
' End If
' TextBox7.Text = PerRecv07 ' GIA TRI NHAN VE TU THIET BI
' End If
' If Sta7Mod1.Checked Then
' If Button7.BackColor = Color.Red Then
' StrSta7 = "@07,0,1," & TextBox7.Text & "#"
' Else
' StrSta7 = "@07,1,1," & TextBox7.Text & "#"
' End If
' End If
' '-----------------------------------------------------------------------------------------------------------
' If Sta8Mod0.Checked Then
' StrSta8 = "@08,0,0," & TextBox8.Text & "#"
' If StaRecv08 = 1 Then
' Button8.BackColor = Color.Blue
' Else
' Button8.BackColor = Color.Red
' End If
' TextBox8.Text = PerRecv08 ' GIA TRI NHAN VE TU THIET BI
' End If
' If Sta8Mod1.Checked Then
' If Button8.BackColor = Color.Red Then
' StrSta8 = "@08,0,1," & TextBox8.Text & "#"
' Else
' StrSta8 = "@08,1,1," & TextBox8.Text & "#"
' End If
' End If
' '-----------------------------------------------------------------------------------------------------------
' If Sta9Mod0.Checked Then
' StrSta9 = "@09,0,0," & TextBox9.Text & "#"
' If StaRecv09 = 1 Then
' Button9.BackColor = Color.Blue
' Else
' Button9.BackColor = Color.Red
' End If
' TextBox9.Text = PerRecv09 ' GIA TRI NHAN VE TU THIET BI
' End If
' If Sta9Mod1.Checked Then
' If Button9.BackColor = Color.Red Then
' StrSta9 = "@09,0,1," & TextBox9.Text & "#"
' Else
' StrSta9 = "@09,1,1," & TextBox9.Text & "#"
' End If
' End If
'End Sub

'Private Sub btnBrw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' SaveFileDialog1.ShowDialog()
' txtLnk.Text = SaveFileDialog1.FileName
'End Sub

Private Sub btnDh1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDh1.Click
If ComboBox1.SelectedIndex = -1 Then
MsgBox("Chn li thit b!")
Exit Sub
End If
DataSet1.Clear()
If ComboBox1.SelectedIndex = 9 Then
Dim dhcom As New MySqlDataAdapter("SELECT DevId,DateShow,TimeShow,StaShow,ModShow,Percent FROM rpttable WHERE OnTime
BETWEEN '" & _
GetDate(DateTimePicker1.Text) & "' AND '" & GetDate(DateTimePicker2.Text) & "' ORDER BY
OnTime,DevId", SQLConnection)
dhcom.Fill(Me.DataSet1.rptTable)
Me.ReportViewer1.RefreshReport()
Else
Dim dhcom As New MySqlDataAdapter("SELECT DevId,DateShow,TimeShow,StaShow,ModShow,Percent FROM rpttable WHERE OnTime
BETWEEN '" & _
GetDate(DateTimePicker1.Text) & "' AND '" & GetDate(DateTimePicker2.Text) & "' AND
DevId='" & ComboBox1.SelectedItem & "' ORDER BY OnTime,DevId", SQLConnection)
dhcom.Fill(Me.DataSet1.rptTable)
Me.ReportViewer1.RefreshReport()
End If
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text <> "" Then
Try
Dim i As Integer = Integer.Parse(TextBox1.Text)
If i > 55 Then
TextBox1.Clear()
MsgBox("Nhp s nh hn 55")
Else
StrSta1 = "@01," & GetStatus(Button1) & ",1," & GetPercent(TextBox1.Text) & "#"
End If
Catch ex As Exception
TextBox1.Clear()
MsgBox("Nhp s nguyn")
End Try
End If
End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
If TextBox2.Text <> "" Then
Try
Dim i As Integer = Integer.Parse(TextBox2.Text)
If i > 55 Then
TextBox2.Clear()
MsgBox("Nhp s nh hn 55")
End If
Catch ex As Exception
TextBox2.Clear()
MsgBox("Nhp s nguyn")
End Try
End If
End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
If TextBox3.Text <> "" Then
Try
Dim i As Integer = Integer.Parse(TextBox3.Text)
If i > 55 Then
TextBox3.Clear()
MsgBox("Nhp s nh hn 55")
End If
Catch ex As Exception
TextBox3.Clear()
MsgBox("Nhp s nguyn")
End Try
End If
End Sub

Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
If TextBox4.Text <> "" Then
Try
Dim i As Integer = Integer.Parse(TextBox4.Text)
If i > 55 Then
TextBox4.Clear()
MsgBox("Nhp s nh hn 55")
End If
Catch ex As Exception
TextBox4.Clear()
MsgBox("Nhp s nguyn")
End Try
End If
End Sub

Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
If TextBox5.Text <> "" Then
Try
Dim i As Integer = Integer.Parse(TextBox5.Text)
If i > 55 Then
TextBox5.Clear()
MsgBox("Nhp s nh hn 55")
End If
Catch ex As Exception
TextBox5.Clear()
MsgBox("Nhp s nguyn")
End Try
End If
End Sub

Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged
If TextBox6.Text <> "" Then
Try
Dim i As Integer = Integer.Parse(TextBox6.Text)
If i > 55 Then
TextBox6.Clear()
MsgBox("Nhp s nh hn 55")
End If
Catch ex As Exception
TextBox6.Clear()
MsgBox("Nhp s nguyn")
End Try
End If
End Sub

Private Sub TextBox7_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox7.TextChanged
If TextBox7.Text <> "" Then
Try
Dim i As Integer = Integer.Parse(TextBox7.Text)
If i > 55 Then
TextBox7.Clear()
MsgBox("Nhp s nh hn 55")
End If
Catch ex As Exception
TextBox7.Clear()
MsgBox("Nhp s nguyn")
End Try
End If
End Sub

Private Sub TextBox8_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox8.TextChanged
If TextBox8.Text <> "" Then
Try
Dim i As Integer = Integer.Parse(TextBox8.Text)
If i > 55 Then
TextBox8.Clear()
MsgBox("Nhp s nh hn 55")
End If
Catch ex As Exception
TextBox8.Clear()
MsgBox("Nhp s nguyn")
End Try
End If
End Sub

Private Sub TextBox9_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox9.TextChanged
If TextBox9.Text <> "" Then
Try
Dim i As Integer = Integer.Parse(TextBox9.Text)
If i > 55 Then
TextBox9.Clear()
MsgBox("Nhp s nh hn 55")
End If
Catch ex As Exception
TextBox9.Clear()
MsgBox("Nhp s nguyn")
End Try
End If
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
Button1.Enabled = False
dhText11.Enabled = True
dhText12.Enabled = True
Else
If ConnectSta1 Then
Button1.Enabled = True
End If
dhText11.Enabled = False
dhText12.Enabled = False
End If
End Sub

Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked Then
Button2.Enabled = False
dhText21.Enabled = True
dhText22.Enabled = True
Else
If ConnectSta2 Then
Button2.Enabled = True
End If
dhText21.Enabled = False
dhText22.Enabled = False
End If
End Sub

Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
If CheckBox3.Checked Then
Button3.Enabled = False
dhText31.Enabled = True
dhText32.Enabled = True
Else
If ConnectSta3 Then
Button3.Enabled = True
End If
dhText31.Enabled = False
dhText32.Enabled = False
End If
End Sub

Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged
If CheckBox4.Checked Then
Button4.Enabled = False
dhText41.Enabled = True
dhText42.Enabled = True
Else
If ConnectSta4 Then
Button4.Enabled = True
End If
dhText41.Enabled = False
dhText42.Enabled = False
End If
End Sub

Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged
If CheckBox5.Checked Then
Button5.Enabled = False
dhText51.Enabled = True
dhText52.Enabled = True
Else
If ConnectSta5 Then
Button5.Enabled = True
End If
dhText51.Enabled = False
dhText52.Enabled = False
End If
End Sub

Private Sub CheckBox6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox6.CheckedChanged
If CheckBox6.Checked Then
Button6.Enabled = False
dhText61.Enabled = True
dhText62.Enabled = True
Else
If ConnectSta6 Then
Button6.Enabled = True
End If
dhText61.Enabled = False
dhText62.Enabled = False
End If
End Sub

Private Sub CheckBox7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox7.CheckedChanged
If CheckBox7.Checked Then
Button7.Enabled = False
dhText71.Enabled = True
dhText72.Enabled = True
Else
If ConnectSta7 Then
Button7.Enabled = True
End If
dhText71.Enabled = False
dhText72.Enabled = False
End If
End Sub

Private Sub CheckBox8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox8.CheckedChanged
If CheckBox8.Checked Then
Button8.Enabled = False
dhText81.Enabled = True
dhText82.Enabled = True
Else
If ConnectSta8 Then
Button8.Enabled = True
End If
dhText81.Enabled = False
dhText82.Enabled = False
End If
End Sub

Private Sub CheckBox9_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox9.CheckedChanged
If CheckBox9.Checked Then
Button9.Enabled = False
dhText91.Enabled = True
dhText92.Enabled = True
Else
If ConnectSta9 Then
Button9.Enabled = True
End If
dhText91.Enabled = False
dhText92.Enabled = False
End If
End Sub

Private Function CheckHour(ByVal strTime As String) As Boolean

If strTime = "" Then
Return False
End If
Try
Dim i As DateTime = DateTime.Parse(strTime)
Return False
Catch ex As Exception
Return True
End Try
End Function

Private Sub dhText11_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText11.Validated
If CheckHour(dhText11.Text) Then
dhText11.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText12_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText12.Validated
If CheckHour(dhText12.Text) Then
dhText12.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText21_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText21.Validated
If CheckHour(dhText21.Text) Then
dhText21.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText22_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText22.Validated
If CheckHour(dhText22.Text) Then
dhText22.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText31_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText31.Validated
If CheckHour(dhText31.Text) Then
dhText31.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText32_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText32.Validated
If CheckHour(dhText32.Text) Then
dhText32.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText41_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText41.Validated
If CheckHour(dhText41.Text) Then
dhText41.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText42_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText42.Validated
If CheckHour(dhText42.Text) Then
dhText42.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText51_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText51.Validated
If CheckHour(dhText51.Text) Then
dhText51.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText52_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText52.Validated
If CheckHour(dhText52.Text) Then
dhText52.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText61_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText61.Validated
If CheckHour(dhText61.Text) Then
dhText61.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText62_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText62.Validated
If CheckHour(dhText62.Text) Then
dhText62.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText71_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText71.Validated
If CheckHour(dhText71.Text) Then
dhText71.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText72_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText72.Validated
If CheckHour(dhText72.Text) Then
dhText72.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText81_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText81.Validated
If CheckHour(dhText81.Text) Then
dhText81.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText82_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText82.Validated
If CheckHour(dhText82.Text) Then
dhText82.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText91_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText91.Validated
If CheckHour(dhText91.Text) Then
dhText91.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub

Private Sub dhText92_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dhText92.Validated
If CheckHour(dhText92.Text) Then
dhText92.Clear()
MsgBox("Nhp li thi gian tt/bt thit b!")
End If
End Sub


End Class