如何在USER / EMPLOYEE超时之前设置一小时? VB.NET [英] How to set an hour before USER/EMPLOYEE can timeout ? VB.NET

查看:87
本文介绍了如何在USER / EMPLOYEE超时之前设置一小时? VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题/我想要发生



1)如果员工/用户时间需要等待3或5个小时才能结束



2)如果她试图超过3或5小时的时间,她将获得一个他/她已经计时的消息框/标签



这是我的代码



 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

如果getReader.Read = True则

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

如果getReader.Read = True则

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


结束如果

getReader.Close()

如果TimeIN =那么
disableTimeOutColor()
TimeIN = Nothing
TimeOUT = Nothing
getDate = Nothing
ElseIf TimeIN<> 和TimeOUT<> 和getDate = Date.Today然后
TimeOUT = Nothing
TimeIN = Nothing
getDate = Nothing
ElseIf TimeIN<> 然后
disableTimeINColor()
TimeIN = Nothing
TimeOUT = Nothing
getDate = Nothing
ElseIf TimeOUT =然后
disableTimeINColor()
TimeOUT = Nothing
TimeIN = Nothing
getDate = Nothing
ElseIf TimeOUT<> 然后
disableTimeOutColor()
TimeOUT = Nothing
TimeIN = Nothing
getDate = Nothing
ElseIf TimeIN =And TimeOUT =getDate =然后

disableTimeOutColor()
TimeOUT = Nothing
TimeIN = Nothing
getDate = Nothing
End if





我尝试过:



我尝试过使用此代码



如果DateDiff(DateInterval.Hour,CDate(TimeIN),CDate(Date.Now))那么

getTimeOUT()
TimeOUT = Nothing
TimeIN = Nothing
getDate = Nothing

解决方案

First of所有,不要将数据直接从UI对象连接到SQL语句。这将使您对SQL注入开放。请参阅 SQL注入 - 维基百科 [ ^ ]首选方法是使用 MySqlParameter类 [ ^ ]



实际问题是什么,一个大问题是你似乎在一个角色中存储日期和时间领域。为了有效地解决问题,您应该使用datetime,请参阅 MySQL :: MySQL 8.0参考手册: :11.3.1 DATE,DATETIME和TIMESTAMP类型 [ ^ ]



如果数据是mysql中的datetime,你可以使用日期时间结构(系统) [ ^ ]在您的程序和utilizr xomparisonds和计算日期时间必须提供。



例如,如果你想检查TimeIn之后是否已经过了三个小时它可能看起来像

 < span class =code-keyword> If  System.DateTime.Now.Subtract(TimeIn).TotalHours<  3  然后 
MessageBox.Show( 尚未
结束 如果


 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 ='& 日期 .Now.ToString( yyyy-MM-dd )& '



不是解决方案你的问题,但你有另一个问题。

永远不要通过连接字符串来构建SQL查询。迟早,您将使用用户输入来执行此操作,这会打开一个名为SQL注入的漏洞,这对您的数据库很容易并且容易出错。

名称中的单引号你的程序崩溃。如果用户输入像Brian O'Conner这样的名称可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞,崩溃是最少的问题,恶意用户输入,并且它被提升为具有所有凭据的SQL命令。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]

按示例进行SQL注入攻击 [ ^ ]

PHP:SQL注入 - 手册 [ ^ ]

SQL注入预防备忘单 - OWASP [ ^ ]


Problem / I Want to happen

1) If employee/user time in she have to wait 3 or 5 hours to time out

2)if she tried to time out less than 3 or 5 hours she will get a messagebox/label that he/she have already timed in

This is my codes

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



What I have tried:

I have tried using this codes

If DateDiff(DateInterval.Hour, CDate(TimeIN), CDate(Date.Now)) Then

            getTimeOUT()
            TimeOUT = Nothing
            TimeIN = Nothing
            getDate = Nothing

解决方案

First of all, don't concatenate data directly from UI objects to SQL statements. This will leave you open to SQL injections. See SQL injection - Wikipedia[^] The preferred way is to use MySqlParameter Class[^]

What comes to the actual question, one big problem is that you seem to be storing date and time in a character field. In order to solve the problem efficiently, you should use datetime, see MySQL :: MySQL 8.0 Reference Manual :: 11.3.1 The DATE, DATETIME, and TIMESTAMP Types[^]

If the data would be datetime in mysql you could use DateTime Structure (System)[^] in your program and utilizr xomparisonds and calculations datetime has to offer.

For example if you want to check if three hours have passed after TimeIn it could look like

If System.DateTime.Now.Subtract(TimeIn).TotalHours < 3 Then
    MessageBox.Show("Not yet")
End If


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") & "'"


Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]


这篇关于如何在USER / EMPLOYEE超时之前设置一小时? VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆