Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If sConnection.State = ConnectionState.Closed Then
sConnection.ConnectionString = "SERVER = localhost; USERID=root; PASSWORD=123456; DATABASE=attc;"
sConnection.Open()
End If
Dim intNumRows As Integer
Dim sqlQuery As String = "SELECT COUNT(*) FROM tbl_time WHERE id = '" & txtid.Text & "' and date = '" & Format(Now, "dd-MM-yyyy") & "'"
Dim objCmd = New MySqlCommand(sqlQuery, sConnection)
intNumRows = objCmd.ExecuteScalar()
If intNumRows > 0 Then
MsgBox("รหัสนักศึกษาซ้ำค่ะ.")
Else
If Label5.Text < "08:00:00" Then
Label6.Text = "เก่งมว๊าก"
Else
If Label5.Text >= "08:00:00" Then
Label6.Text = "มาสาย"
End If
End If
sqlQuery = "INSERT INTO tbl_time(id ,date, time, status) VALUES('" & txtid.Text & "','" & Format(Now, "dd-MM-yyyy") & "','" & Format(Now, "h:mm:ss") & "','" & Label6.Text & "')"
Dim sqlCommand As New MySqlCommand
With sqlCommand
.CommandText = sqlQuery
.Connection = sConnection
.ExecuteNonQuery()
End With
MsgBox("คุณได้บันทึกเวลาแล้วค่ะ")
txtid.Clear()
Refresh()
End If
End Sub