Limiting the time in and time out in a day in VB.NET?

▼魔方 西西 提交于 2019-12-08 13:32:47

问题


I have developed a time monitoring system using fingerprint where the employee will scan his/her finger then it will record the time in and time out. But my problem is logging in and logging out by the employee is unlimited. Is there a solution where the employee can log in and log out ONCE IN A DAY? Every employee will log in and log out once. Here is my code for my Daily Time Record Form: (Im using visual studio 2010/Digital Persona UareU for my scanner)

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

回答1:


This is very nice that you are developing this logic. Actually I have come a crossed YOUR question. Now I can recommend you some vb.net code using back end MS ACCESS 2007 .well You just validate when an employee logged in then put this code after log In button or what ever you are using .

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



回答2:


just follow the steps

Use normal login button which will validate for user then if the authenticate user then show his login time in another textbox in the same form.and use one more textbox to show the logout time ,now

1)use two buttons a)button1 as logintime button and b)button2 as logout time button 2)Then write code to add the login time into the data base,and for ur better understanding put one message box too which will shows the"Time in added to the database" and after that put the above code which will validate the current day attendance if the employee wants to login twice or thrice in a day this code will not allow him to login again only once he/she can ... and code the above behind the login button
note:-keep in mind that all the procedure will work after the employee log out ..Hope this will help you out..



来源:https://stackoverflow.com/questions/15314646/limiting-the-time-in-and-time-out-in-a-day-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!