Vb.net 记录进入时间后的超时-RFID学生通行证ID系统

Vb.net 记录进入时间后的超时-RFID学生通行证ID系统,vb.net,Vb.net,我正在使用VB.Net和MySql。 我有3个名为RFIDTag、TimeIn、TimeOut的表 当我点击一次时,它将记录到TimeIn,然后当我点击两次时,时间必须记录到超时 我的工作已经在记录TimeIn中完成,这是我记录TimeIn的逻辑 If (Count from the table where RFIDTag matches the textbox from vb.net) > 1 then If TimeOut = "" records Time

我正在使用VB.Net和MySql。 我有3个名为RFIDTag、TimeIn、TimeOut的表

当我点击一次时,它将记录到TimeIn,然后当我点击两次时,时间必须记录到超时

我的工作已经在记录TimeIn中完成,这是我记录TimeIn的逻辑

If (Count from the table where RFIDTag matches the textbox from vb.net) > 1 then
    If TimeOut = ""
          records Time into the TimeOut
    Else
          INSERT new record NEW row of TimeIn
Else
    INSERT new record NEW TimeIn

这是我记录时间的代码

    Using sqlcommand As New MySqlCommand
        With sqlcommand
            .CommandText = "INSERT INTO userrecord (RFIDTag, TimeIn) VALUES (@RFIDTag, @TimeIn)"
            .Connection = con
            .CommandType = CommandType.Text
            .Parameters.AddWithValue("@RFIDTag", TextBoxTag.Text)
            .Parameters.AddWithValue("@TimeIn", TimeIn)
        End With

        sqlcommand.ExecuteNonQuery()
    End Using

    sqlreader = query.ExecuteReader
    sqlreader.Read()

    LabelName.Text = sqlreader.Item("FullName")
    LabelYearCourse.Text = sqlreader.Item("YearCourse")
    LabelIDNum.Text = sqlreader.Item("IDNumber")
    sqlreader.Close()


    TextBoxTag.Text = ""
    LabelStatus.Text = "IN"
    con.Close()
End If

这是我的学校项目,我是唯一一个使用VB.Net的人,所以我不能问我的同学。我也做了很多研究,但我再也受不了了。我将在3天后介绍这个系统,但它仍然没有完成=(我希望有人能给我一些帮助。

数据库中的两个表如何。表RFIDTag以IDNumber列为主键,然后是FullName和YearCourse。表TimeInOut以IDNumber列为外键,然后是TimeIn和TimeOut

If (Count from the table where RFIDTag matches the textbox from vb.net) > 1 then
    If TimeOut = ""
          records Time into the TimeOut
    Else
          INSERT new record NEW row of TimeIn
Else
    INSERT new record NEW TimeIn
现在,在学生登录时保存一本本地词典

Private LoggedInDictionary As Dictionary(Of Integer,DateTime)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoggedInDictionary = New Dictionary(Of Integer, DateTime)
End Sub
根据学生是否在LoggedDictionary中,从Record按钮调用RecordLogIn或RecordLogOut

Private Sub btnRecord_Click(sender As Object, e As EventArgs) Handles btnRecord.Click
        Dim key As Integer = CInt(TextBoxTag.Text)
        Dim value As DateTime
        'If the student is not in the dictionary
        If Not LoggedInDictionary.TryGetValue(key, value) Then
            RecordLogIn(key)
        Else
            RecordLogOut(key, value)
        End If
        ListBox1.Items.Clear()
        DisplayLoggedInStudents()
    End Sub

Private Sub RecordLogIn(StudentId As Integer)
        Dim ID As Integer = StudentId
        Dim LogInTime As DateTime = DateTime.Now
        LoggedInDictionary.Add(ID, LogInTime)
    End Sub

Private Sub RecordLogOut(ID As Integer, TimeIn As DateTime)
        Dim InsertQuery As String = "Insert into TimeInOut (IDNumber, TimeIn, TimeOut) Values (@ID, @TimeIn, @TimeOut);"
        Using con As New MySqlConnection("Your connection string")
            Using cmd As New MySqlCommand(InsertQuery, con)
                cmd.Parameters.AddWithValue("@ID", ID)
                cmd.Parameters.AddWithValue("@TimeIn", TimeIn)
                cmd.Parameters.AddWithValue("@TimeOut", DateTime.Now)
                con.Open()
                cmd.ExecuteNonQuery()
            End Using
        End Using
        LoggedInDictionary.Remove(ID)
    End Sub
在btnRecord子项的末尾,更新已登录学生的显示

Private Sub DisplayLoggedInStudents()
        For Each item As KeyValuePair(Of Integer, DateTime) In LoggedInDictionary
            Dim LoggedInStudents As String = $"Student Name: {GetStudentNameByID(item.Key)}, Student ID: {item.Key} Logged In Time: {item.Value}"
            ListBox1.Items.Add(LoggedInStudents)
        Next
    End Sub
显示使用GetStudentNameByID

Private Function GetStudentNameByID(StudentID As Integer) As String
        Dim StudentName As String = ""
        Using con As New MySqlConnection("Your Connection String")
            Using cmd As New MySqlCommand("Select FullName From RFIDTag Where IDNumber = @ID;")
                cmd.Parameters.Add(@ID, StudentID)
                con.Open()
                StudentName = cmd.ExecuteScalar.ToString
            End Using
        End Using
        Return StudentName
    End Function

您可以查看登录的学生列表,并在一天结束时将他们注销。有一些边缘案例不适用于此系统。此代码未经测试,因为您没有数据库。

Ok-您的具体问题是什么?什么没有按预期工作?如果正常工作,您会期望什么。不是一般程序大纲,但是具体的代码部分?使用
Option Explicit
Option Strict On
。在那些不起作用的部分,向我们展示您使用的代码,而不仅仅是一些暗示您希望我们为您写作业的伪代码。我几十年前就放弃了作业。在If-Else语句中添加断点。检查是否您的陈述是正确的。问题可能不在
记录时间中
。此外,请输入实际代码,而不仅仅是一些伪代码,以便我们确定出错的原因。