0

我开发了一个使用指纹的时间监控系统,员工将扫描他/她的手指,然后记录时间和超时。但我的问题是员工的登录和注销是无限的。是否有员工可以在一天内登录和注销一次的解决方案?每个员工将登录和注销一次。这是我的每日时间记录表的代码:(我使用 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
4

2 回答 2

0

您正在开发此逻辑非常好。实际上,我遇到了您的问题。现在我可以向您推荐一些使用后端 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
于 2013-03-20T07:48:30.633 回答
0

只需按照步骤

使用将验证用户的普通登录按钮,然后如果经过身份验证的用户然后在另一个文本框中以相同的形式显示他的登录时间。现在再使用一个文本框来显示注销时间

1)使用两个按钮a)按钮1作为登录时间按钮,b)按钮2作为注销时间按钮2)然后编写代码将登录时间添加到数据库中,为了更好地理解,也放置一个显示“时间”的消息框添加到数据库中”,然后输入上面的代码,如果员工想在一天内登录两次或三次,则该代码将验证当天的出勤率,该代码将不允许他再次登录,只有一次他/她可以......并在登录按钮后面对上面的代码进行编码
注意:-请记住,员工注销后所有程序都将起作用..希望这对您有所帮助..

于 2013-03-20T08:10:09.947 回答