2013-03-09 3 views
0

직원이 지문을 스캔하고 지문을 사용하여 시간 모니터링 시스템을 개발 한 후 시간과 시간을 기록합니다. 하지만 내 문제는 로그인하고 직원이 로그 아웃하는 것이 무제한입니다. 직원이 로그인하여 로그 아웃 할 수있는 솔루션이 있습니까 하루에에 로그인 하시겠습니까? 모든 직원은 한 번 로그인하여 로그 아웃합니다. (내 스캐너 비주얼 스튜디오 2010/디지털 페르소나 UareU를 사용하여 임)VB.NET에서 하루 안에 제한 시간과 제한 시간을 제한 하시겠습니까?

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 
+0

이 코드는 SQL 주입 공격에 취약합니다. 당신은 실제로 해킹 당하고 있습니다. –

+0

또한 연결을 글로벌하게 만드는 것은 _ 실수로 _ 실수입니다. 연결 문자열을 전역으로 만들 수 있지만 매번 해당 문자열을 사용하여 새 연결 개체를 만들어야합니다. –

+0

하지만 하루에 한 번 로그인 및 로그 아웃을 제한하려면 어떻게해야합니까? –

답변

0

이이 논리를 개발하고 매우 좋은 : 여기 내 매일 시간 기록 양식에 대한 내 코드입니다. 사실 저는 당신의 질문을 건너 왔습니다. 이제는 백 엔드 MS ACCESS 2007을 사용하여 vb.net 코드를 추천 할 수 있습니다. .well 로그인 한 후 직원이 로그인했을 때 유효성을 검사하거나 로그인 버튼이나 사용중인 코드를 확인하십시오.

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 
0

바로 단계

에 따라 인증 용 사용자가 다음 같은 form.and 사용하는 또 하나의 텍스트 상자에 다른 텍스트 상자에 자신의 로그인 시간을 표시하는 경우 다음 사용자 에 대한 유효성을 검사

를 사용하여 일반 로그인 버튼 지금은 로그 아웃 시간을 표시하십시오

1) 버튼 2 개를 사용하십시오 : logintime 버튼으로 button1을 사용하고 logout time 버튼으로 button2를 사용하십시오. 2) 데이터베이스에 로그인 시간을 추가하는 코드를 작성하십시오. 하나의 메시지 상자를 두어 "Time "데이터베이스에 추가 된 후 직원이 두 번 또는 하루에 세 번 로그인하려고 할 때이 코드가 관리자 만 다시 로그인 할 수 있도록 허용하지 않으면 현재 날짜의 출석을 확인하는 위 코드를 넣습니다. 그리고 로그인 버튼 뒤에 위의 코드를 작성하십시오
참고 : 직원이 로그 아웃 한 후에 모든 절차가 작동 함을 염두에 두십시오.이 도움을 받으십시오.