在VB.NET中限制一天的时间进出



我开发了一个使用指纹的时间监控系统,员工将扫描他/她的手指,然后它将记录时间进入和超时。但我的问题是登录和登出的员工是无限制的。是否有一个解决方案,员工可以登录和注销一天一次?每个员工都会登录和注销一次。这是我的代码我的每日时间记录形式:(我使用visual studio 2010/Digital Persona UareU为我的扫描仪)

Imports MySql.Data.MySqlClient
Imports System.Windows.Forms
Imports DPFP
Public Class frmDTR
Dim counter As Integer = 0
Dim oConn As New MySqlConnection(ConnectionString.ConnString)
Private matcher As DPFP.Verification.Verification
Private matchResult As DPFP.Verification.Verification.Result
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
    Me.Close()
End Sub
Public Sub SEARCH_EMPLOYEE()
    Try
        'Load From DB
        GlobalFunctions.db_connect()
        Dim reader As MySqlDataReader
        Dim command As MySqlCommand = connection.CreateCommand()
        command.CommandText = "SELECT * FROM employee_records WHERE ID_Number='" & strid & "'" 'check tag number if existing
        reader = command.ExecuteReader()
        If (reader.HasRows) Then
            While (reader.Read())
                With Me
                    'plot the data into controls
                    .txtID.Text = reader(1).ToString
                    .txtFirst.Text = reader(2).ToString
                    .txtMiddle.Text = reader(3).ToString
                    .txtLast.Text = reader(4).ToString
                    .txtAge.Text = reader(5).ToString
                    .txtBday.Text = reader(6).ToString
                    .txtDepartment.Text = reader(7).ToString
                    .txtYear.Text = reader(8).ToString
                    .txtGender.Text = reader(9).ToString
                    .txtContact.Text = reader(10).ToString
                    .txtMobile.Text = reader(11).ToString
                    .txtEmail.Text = reader(12).ToString
                    'fetch image from database
                    Dim imgBytes() As Byte = reader("image") 'image field
                    Dim image As Bitmap = New Bitmap(New System.IO.MemoryStream(imgBytes)) 'convert binary to image
                    .ProfilePic.Image = image 'show picture to picture box
                End With
                Call LOG_EMP()    'look up if login /log out
                Timer1.Enabled = True
            End While
        Else
            'Me.lblStatus.Text = "ID not recognized!"
        End If
    Catch ex As Exception
        MessageBox.Show("Error scanning: " & ex.Message)
    End Try
    GlobalFunctions.connection.Close()
End Sub

Public Sub LOG_EMP()
    Try
        ' Load From DB
        GlobalFunctions.db_connect()
        Dim reader As MySqlDataReader
        Dim command As MySqlCommand = connection.CreateCommand()
        command.CommandText = "SELECT * FROM employee_logs WHERE ID_Number='" & strid & "' AND Time_Out='Null'"
        reader = command.ExecuteReader()
        If (reader.HasRows) Then
            While (reader.Read())
            End While
            'logout
            Call EMP_LOGOUT()

        Else
            'log in
            Call EMPT_LOGIN()
        End If
    Catch ex As Exception
        MessageBox.Show("Error scanning: " & ex.Message)
    End Try
    GlobalFunctions.connection.Close()
End Sub
'insert login data
Public Sub EMPT_LOGIN()
    ' Connect to Database
    GlobalFunctions.db_connect()
    Dim command As MySqlCommand
    Dim transaction As MySqlTransaction
    transaction = GlobalFunctions.connection.BeginTransaction()
    Try
        command = New MySqlCommand("INSERT INTO employee_logs values('','" & txtID.Text & "','" & txtFirst.Text & "','" & txtMiddle.Text & "','" & txtLast.Text & "','" & txtDepartment.Text & "','" & Date.Today & "','" & TimeOfDay & "','Null') ", GlobalFunctions.connection, transaction)
        command.ExecuteNonQuery()
        transaction.Commit()
        'sms = txtFirst.Text & " Enter the Building Premises @" & Now 'actual sms
        lblStatus.ForeColor = Color.Lime
        Dim SAPI
        SAPI = CreateObject("SAPI.spvoice")
        SAPI.Speak("Welcome!" & txtFirst.Text)
        Me.lblStatus.Text = "Successfully Logged IN! Welcome!" 'set status to login
        'Will_SendSMS()    'send sms to number
    Catch ex As MySqlException
        MessageBox.Show("Error in inserting new record! Error: " & ex.Message, "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        transaction.Rollback()
    End Try
    'close connections
    GlobalFunctions.connection.Close()
End Sub
Public Sub EMP_LOGOUT()
    ' Connect to Database
    GlobalFunctions.db_connect()
    ' Dim command As MySqlCommand
    Dim transaction As MySqlTransaction
    transaction = GlobalFunctions.connection.BeginTransaction()
    Try
        GlobalFunctions.execute_nonquery("Update employee_logs set Time_Out='" & TimeOfDay & "' WHERE ID_Number='" & strid & "' AND Time_Out='Null' AND Date='" & Date.Today & "'")
        transaction.Commit()
        'sms = txtFirst.Text & " Left the Building Premises @" & Now & "Powered by: " ' actual sms to be sent
        lblStatus.ForeColor = Color.Lime
        Dim SAPI
        SAPI = CreateObject("SAPI.spvoice")
        SAPI.Speak("Goodbye!" & txtFirst.Text)
        lblStatus.Text = "Successfully Logged OUT! Goodbye!" ' set status to logout
        'Will_SendSMS()  'send sms

    Catch ex As MySqlException
        MessageBox.Show("Error in updating a record! Error: " & ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
        transaction.Rollback()
    End Try
    '  close connections
    GlobalFunctions.connection.Close()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    'counter for display
    counter += 1
    If counter = 6 Then
        Call ClearTextBox(Me)
        lblStatus.ForeColor = Color.Lime
        Me.lblStatus.Text = "Please scan your finger....."
        Lblverify.ForeColor = Color.Black
        Lblverify.Text = "Status"
        ProfilePic.Image = Nothing
        Timer1.Enabled = False
        counter = 0
    End If
End Sub
Private Sub frmDTR_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
    Try
        Me.VerificationControl.Focus()
    Catch ex As MySqlException
        MessageBox.Show("System Error: " & ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub
Private Sub frmDTR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    matcher = New Verification.Verification()
    matchResult = New Verification.Verification.Result
    Me.VerificationControl.Focus()
    Dim SAPI
    SAPI = CreateObject("SAPI.spvoice")
    SAPI.Speak("Please scan your finger")
End Sub
Private Sub VerificationControl_OnComplete(ByVal Control As Object, ByVal FeatureSet As DPFP.FeatureSet, ByRef EventHandlerStatus As DPFP.Gui.EventHandlerStatus) Handles VerificationControl.OnComplete
    Dim strSQL As String = "Select * from finger_template"
    Dim oDa As New MySqlDataAdapter(strSQL, oConn)
    Dim dt As New DataTable
    Dim dr As DataRow
    Try
        oDa.Fill(dt)
        For Each dr In dt.Rows
            Lblverify.ForeColor = Color.Red
            Lblverify.Visible = True
            Dim bytes As Byte() = Nothing
            bytes = dr.Item("byte_template")
            Dim tmplate = New DPFP.Template()
            tmplate.DeSerialize(bytes)
            matcher.Verify(FeatureSet, tmplate, matchResult)
            If matchResult.Verified Then
                EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Success
                strid = dr.Item("Account_ID")
                Call SEARCH_EMPLOYEE()

                Exit For ' success
            End If
            If Not matchResult.Verified Then EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Failure
            Lblverify.Text = "Status"
            lblStatus.Text = "Unrecognize fingerprint....."
            Lblverify.ForeColor = Color.Red
            lblStatus.ForeColor = Color.Red

            Timer1.Start()
        Next
    Catch ex As Exception
    End Try
End Sub
End Class

很好,您正在开发这个逻辑。实际上我已经回答了你的问题。现在我可以向你推荐一些使用后台MS ACCESS 2007的vb.net代码。你只需在员工登录时进行验证,然后在登录按钮或任何你正在使用的按钮后放置这些代码。

Dim cmd1 as oledbcommond
cmd1 = New OleDbCommand("SELECT * FROM LOGTIME WHERE timein<>null  and timeout<>null and dt='" & Label8.Text & "' and eid='" & txtemid.Text & "' ", cn)
    dr = cmd1.ExecuteReader()
    If dr.Read Then
        MessageBox.Show("Already this Employee ID contains today's attendance,now you can't Log again", "Information On Your ID", MessageBoxButtons.OK, MessageBoxIcon.Information)
        cmd1.Dispose()
        cn.Close()
        Exit Sub
    End If

按步骤操作

使用正常的登录按钮,将验证用户然后,如果认证用户,那么在同一表单的另一个文本框中显示他的登录时间使用另一个文本框显示注销时间,现在

1)使用两个按钮a)button1作为登录时间按钮,b)button2作为注销时间按钮2)然后编写代码,将登录时间添加到数据库中,并且为了更好地理解,也放入一个消息框,该消息框将显示"添加到数据库中的时间",然后放入上述代码,如果员工想在一天内登录两次或三次,则该代码将验证当前的出勤情况,此代码将不允许他再次登录,只有一次他/她可以…并在login按钮
后面编写上述代码注意:-请记住,所有的程序将在员工注销后工作。

相关内容

  • 没有找到相关文章

最新更新