Search code examples
vb.netrfid

How to: Time-in and time-out status on vb.net


`Public Sub updateTextBox()

    s = s + SerialPort1.ReadExisting()

    If Len(s) > 12 Then
        Try

            txtReceived.Text = Microsoft.VisualBasic.Mid(s, 1, 12)

            strSql = "SELECT * FROM stud WHERE tag = '" & txtReceived.Text & "';"
            command.CommandText = strSql
            command.Connection = SQLConnection
            datapter.SelectCommand = command
            datardr = command.ExecuteReader
            Dim img() As Byte
            If datardr.HasRows Then
                datardr.Read()
                img = datardr("picture")
                Dim ms As New MemoryStream(img)
                txtFname.Text = datardr("fname").ToString
                txtLname.Text = datardr("lname").ToString
                PictureBox1.Image = Image.FromStream(ms)
                SQLConnection.Close()
            End If

            SQLConnection.Open()
        Catch ex As Exception
        End Try
        Try

            Dim i As Integer
            Dim newtag As Boolean = True
            Dim stringfix As String
            Dim string1 As String
            Dim string2 As String

            For i = 0 To (grid.Rows.Count - 1)
                stringfix = grid.Rows.Item(i).Cells(0).Value
                string1 = Microsoft.VisualBasic.Mid(stringfix, 1, 10)
                string2 = Microsoft.VisualBasic.Mid(stringfix, 2, 10)
                If string1 = string2 Then
                    newtag = False
                    Exit For
                Else
                    newtag = True
                End If
            Next
            If newtag = True Then
                Dim dr As Integer
                dr = grid.Rows.Add()
                grid.Rows.Item(dr).Cells.Item(0).Value = Microsoft.VisualBasic.Mid(s, 1, 12)
                grid.Rows.Item(dr).Cells(1).Value = txtFname.Text
                grid.Rows.Item(dr).Cells(2).Value = txtLname.Text
                grid.Rows.Item(dr).Cells.Item(3).Value = txtDate.Text + " " + txtTime.Text
                grid.Rows.Item(dr).Cells.Item(4).Value = "TIME IN"
            ElseIf newtag = False Then
                grid.Rows.Item(i).Cells.Item(3).Value = txtDate.Text + " " + txtTime.Text
                grid.Rows.Item(i).Selected = True

            End If


        Catch ex As Exception
        End Try
        Dim timeOut As DateTimeOffset = Now.AddMilliseconds(1500)

        Do
            Application.DoEvents()

        Loop Until Now > timeOut

        s = SerialPort1.ReadExisting()
        SerialPort1.DiscardOutBuffer()
        s = String.Empty
        SerialPort1.DtrEnable = True
        txtReceived.Text = ""
        txtFname.Text = ""
        txtLname.Text = ""
        PictureBox1.Image = Nothing

    End If
End Sub`

Good day! I've been working on an RFID based Daily-Time-Record of a school for our Thesis. My problem is how to set the "status" of the student when he/she 1st tapped the RFID card it should be status = Time-In and when he/she tapped it for the 2nd time the status should be Time-out. Every student has a limit of one Time-In and one Time-out a day. Any idea on how to do this? Hope you guys get what im pointing out.


Solution

  • There are so many ways this could be done it's almost too broad. One simple way would be to add two columns to your database and increment respectively when the RFID is scanned in or out. Then when you SELECT from your database you can reference those columns and if both are > 1, then so something.

    Another way would be with arrays of all the student TAG's. And you can keep track of the counters locally that way instead of within the database. So right after scanning a tag...

    If inCounter(tag) > 1 or outCounter(tag) > 1 Then
        msgbox("User has reached the quota.")
    Else
        inCounter(tag) += 1
        outCounter(tag) += 1
    End If
    

    Then you would need to implement a DateTime class that resets those counters each day.