Imports System.Data.SqlClient
Imports MetroFramework
Imports MetroFramework.Forms
Public Class frmCustomDialogX1
    Sub LogOut()
        Try
            frmFrontOffice.Hide()
            Dim st As String = "Successfully clocked out"
            LogFunc(lblUser.Text, st)
            Me.Hide()
            frmLogin.Show()
            frmLogin.UserID.Text = ""
            frmLogin.Password.PasswordChar = ""
            frmLogin.Password.Text = "ENTER PIN"
            frmLogin.UserID.Focus()
        Catch ex As Exception
            MetroMessageBox.Show(Me, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
        End Try
    End Sub
    Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
        Try
            con = New SqlConnection(cs)
            con.Open()
            cmd = con.CreateCommand()
            cmd.CommandText = "SELECT Top 1 ClockIN.ID from ClockIN where UserID=@d1 order by ClockIN.ID Desc"
            cmd.Parameters.AddWithValue("@d1", lblUser.Text)
            rdr = cmd.ExecuteReader()
            If rdr.Read() Then
                txtClockInID.Text = rdr.GetValue(0)
                ClockOUTSave(txtClockInID.Text)
                LogOut()
            End If
            If (rdr IsNot Nothing) Then
                rdr.Close()
            End If
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
        Catch ex As Exception
            MetroMessageBox.Show(Me, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
        End Try

    End Sub

    Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
End Class