如何设置用户/员工超时前一小时?vb.net mysql

2o7dmzc5  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(248)

问题/我想发生
1) 如果员工/用户超时,她必须等待3或5个小时才能超时
2) 如果她试图超时不到3或5小时,她将得到一个messagebox/标签,他/她已经超时
这是我的密码

getQuery = "SELECT dtr.time_in, dtr.date FROM dtr, employee WHERE employee.employee_id ='" & empid.Text & _
       "'AND dtr.employee_id ='" & empid.Text & "' AND dtr.rfid ='" & txtRFID.Text & "' AND dtr.date ='" & Date.Now.ToString("yyyy-MM-dd") & "'"
 getCommand = New MySqlCommand(getQuery, MySQLConnection)
 getReader = getCommand.ExecuteReader

 If getReader.Read = True Then

     TimeIN = (getReader.Item("time_in").ToString)
     getDate = (getReader.Item("date"))

 End If

 getReader.Close()

 getQuery = "SELECT dtr.time_out, dtr.date FROM dtr, employee WHERE employee.employee_id ='" & empid.Text & "' AND dtr.employee_id ='" & _
     empid.Text & "' AND dtr.rfid ='" & txtRFID.Text & "' AND dtr.date ='" & Date.Now.ToString("yyyy-MM-dd") & "'"
 getCommand = New MySqlCommand(getQuery, MySQLConnection)
 getReader = getCommand.ExecuteReader

 If getReader.Read = True Then

     TimeOUT = (getReader.Item("time_out").ToString)
     getDate = (getReader.Item("date"))

 End If

 getReader.Close()

 If TimeIN = "" Then
     disableTimeOutColor()
     TimeIN = Nothing
     TimeOUT = Nothing
     getDate = Nothing
 ElseIf TimeIN <> "" And TimeOUT <> "" And getDate = Date.Today Then
     TimeOUT = Nothing
     TimeIN = Nothing
     getDate = Nothing
 ElseIf TimeIN <> "" Then
     disableTimeINColor()
     TimeIN = Nothing
     TimeOUT = Nothing
     getDate = Nothing
 ElseIf TimeOUT = "" Then
     disableTimeINColor()
     TimeOUT = Nothing
     TimeIN = Nothing
     getDate = Nothing
 ElseIf TimeOUT <> "" Then
     disableTimeOutColor()
     TimeOUT = Nothing
     TimeIN = Nothing
     getDate = Nothing
 ElseIf TimeIN = "" And TimeOUT = "" And getDate = "" Then

     disableTimeOutColor()
     TimeOUT = Nothing
     TimeIN = Nothing
     getDate = Nothing
 End If
hwazgwia

hwazgwia1#

在“编译”选项卡上的“项目属性”中启用“选项严格”。这将在您运行代码之前捕获许多潜在的错误。
首先,你的问题。您只从一个表中进行选择,因此似乎没有任何理由引用employee表。使用参数重写代码是非常重要的;否则,您很容易受到sql注入的攻击。

Using cn As New MySqlConnection("Your connection string")
            Dim getQuery As String = "SELECT dtr.time_out, dtr.date FROM dtr WHERE  dtr.employee_id = @Id AND dtr.rfid = @rfid  AND dtr.date = @date;"
            Using cmd As New MySqlCommand(getQuery, cn)
                cmd.Parameters.Add("@Id", MySqlDbType.Int32).Value = empid.Text
                cmd.Parameters.Add("@rfid", MySqlDbType.Int32).Value = txtRFID.Text
                cmd.Parameters.Add("@date", MySqlDbType.VarChar).Value = Date.Now.ToString("yyyy-MM-dd")
                cn.Open()
                Using dr As MySqlDataReader = cmd.ExecuteReader
                    If dr.Read Then
                        TimeOut = dr.Item("time_out").ToString
                        getDate = dr.Item("date")
                    End If
                End Using
            End Using
    End Using

我猜测了数据类型。检查数据库中的正确类型。似乎您正在将数据值存储为字符串。日期实际上应该存储为日期。
using语句可确保即使出现错误,也能正确关闭和释放对象。
我真的不能再往前走了,不知道时间。

相关问题