-2

`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.

  • You need to provide more information and hopefully some code. What have you tried? Are you using a database or hard coded "students"? Keeping track of a counter for each student is not difficult by any means, so this question is quite broad. – TheValyreanGroup Oct 18 '16 at 15:14
  • This is really just a very broad specification - it's not really suited to the Stack Overflow Q&A format. Also - what if a student nicks another's card and taps out, with a limit of 1 in/out a day, are they now going to get in trouble? – James Thorpe Oct 18 '16 at 15:14
  • @TheValyreanGroup Yes, I am using database. What should I do with the counter? Sorry for asking, im just new to RFID and vb.net hope u guys understand. I will add up some of the codes i used. The progress of this code is it can retrieve data from a database. Dont mind the DataGrid. I just dont know what should i do to make the Time-In and Time-Out on the status. – Alvin Tuazon Oct 18 '16 at 15:31
  • Hope you guys understand :( im just new to vb.net and RFID. I found this code here in stackoverflow and recode it. – Alvin Tuazon Oct 18 '16 at 15:35

1 Answers1

0

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.

TheValyreanGroup
  • 3,554
  • 2
  • 12
  • 30
  • What if i added two columns on the database (time_in and time_out), what should be the proper way to put the TimeOfDay to time_in when I first tapped he RFID and put on time_out when i tapped it for the 2nd time? Im getting the logic but I dont know how to start and code it :( – Alvin Tuazon Oct 18 '16 at 15:52
  • SO is not a code writing service. I'm not going to do it for you. If you make the 2 new columns in the database a TIMESTAMP column, and set it's default to CURRENT_TIMESTAMP, it will automatically put the time of the server in that entry each time the row is updated. – TheValyreanGroup Oct 18 '16 at 16:11
  • Thank you so much @TheValyreanGroup! I resolved the issue. Thank you for sharing your thoughts. I got the idea on how to increment the counter everytime the RFID is scanned. – Alvin Tuazon Oct 19 '16 at 06:08