如何:vb.net 上的入场和出场状态

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

`Public 子 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`

美好的一天!我一直在为我们的论文研究基于 RFID 的学校每日时间记录。我的问题是如何在 he/she 第一次点击 RFID 卡时设置学生的 "status" 它应该是 status = Time-In 并且当 he/she 第二次点击它时状态应该超时。每个学生每天有一次进场和一次暂停的限制。关于如何执行此操作的任何想法?希望你们明白我所指出的。

有很多方法可以做到这一点,几乎太宽泛了。一种简单的方法是在数据库中添加两列,并在扫描进或扫描出 RFID 时分别递增。然后,当您从数据库中 SELECT 时,您可以引用这些列,如果两者都 > 1,那么就可以了。

另一种方法是使用所有学生标签的数组。您可以通过这种方式在本地而不是在数据库中跟踪计数器。所以在扫描标签后...

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

然后您需要实施 DateTime class 来每天重置这些计数器。