Public Class frmOvertime1
    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
    Private Sub txtEmployeesCode_TextChanged(sender As Object, e As EventArgs) Handles txtEmployeesCode.TextChanged
        If txtEmployeesCode.Text = "" Then
            txtEmpID.Text = ""
            txtEmployeesName.Text = ""
            txtFathersName.Text = ""
            txtShiftName.Text = ""
            PictureBox1.Image = PayrollManagementSystem.My.Resources.no_image
        End If
    End Sub
    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        If txtEmployeesCode.Text = "" Then
            ErrorProvider1.SetError(txtEmployeesCode, "Mandatory field.")
        Else
            ErrorProvider1.Clear()
            ExecuteSQLQuery(" SELECT        Employee_Information.EMPLOYEE_ID, Employee_Information.EmployeesName, Employee_Information.FathersName, WorkingHours.ShiftName, Employee_Information.PHOTO_FILE_NAME " &
                            " FROM            Employee_Information LEFT OUTER JOIN  WorkingHours ON Employee_Information.ShiftID = WorkingHours.ShiftID  WHERE  (Employee_Information.EMP_CODE = '" + str_repl(txtEmployeesCode.Text) + "') ")
            If sqlDT.Rows.Count > 0 Then
                txtEmpID.Text = sqlDT.Rows(0)("EMPLOYEE_ID")
                txtEmployeesName.Text = sqlDT.Rows(0)("EmployeesName")
                txtFathersName.Text = sqlDT.Rows(0)("FathersName")
                txtShiftName.Text = sqlDT.Rows(0)("ShiftName")
                Try
                    PictureBox1.ImageLocation = Application.StartupPath + "\Upload\Employee\" + sqlDT.Rows(0)("PHOTO_FILE_NAME")
                Catch ex As Exception
                    PictureBox1.Image = PayrollManagementSystem.My.Resources.no_image
                End Try
            Else
                txtEmpID.Text = ""
                txtEmployeesName.Text = ""
                txtFathersName.Text = ""
                txtShiftName.Text = ""
                PictureBox1.Image = PayrollManagementSystem.My.Resources.no_image
                MsgBox("No Record Found.", MsgBoxStyle.Information, "Information")
            End If
        End If
    End Sub
    Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
        If txtEmpID.Text = "" Or txtOvertimeRate.Text = "" Then
            ErrorProvider1.SetError(txtEmployeesCode, "Mandatory field.")
            ErrorProvider1.SetError(txtOvertimeRate, "Mandatory field.")
        ElseIf Not IsNumeric(txtOvertimeRate.Text) Then
            ErrorProvider1.SetError(txtOvertimeRate, "Numeric input only!")
        Else
            ErrorProvider1.Clear()
            Dim Overtime_Mins As Double = DateDiff(DateInterval.Minute, dtpStartTime.Value, dtpEndTime.Value)
            If btnSubmit.Text = "SAVE" Then
                ExecuteSQLQuery(" INSERT INTO Overtime (EMPLOYEE_ID, EnrollDate, StartTime, EndTime, Overtime_Mins, OvertimeRate) VALUES " &
                                " (" & num_fltr(txtEmpID.Text) & ", '" & Format(dtpEnrollDate.Value, "yyyy-MM-dd") & "', '" & Format(dtpStartTime.Value, "HH:mm") & "', '" & Format(dtpEndTime.Value, "HH:mm") & "', " & num_fltr(Math.Abs(Overtime_Mins)) & ", " & num_fltr(txtOvertimeRate.Text) & ") ")
            ElseIf btnSubmit.Text = "UPDATE" Then
                ExecuteSQLQuery(" UPDATE Overtime SET  EMPLOYEE_ID=" & num_fltr(txtEmpID.Text) & ", EnrollDate='" & Format(dtpEnrollDate.Value, "yyyy-MM-dd") & "', StartTime='" & Format(dtpStartTime.Value, "HH:mm") & "', EndTime='" & Format(dtpEndTime.Value, "HH:mm") & "', Overtime_Mins=" & num_fltr(Math.Abs(Overtime_Mins)) & ", OvertimeRate= " & num_fltr(txtOvertimeRate.Text) & " " &
                                " WHERE OVTM_ENROLL_ID=" & num_fltr(txtOVTM_ENROLL_ID.Text) & " ")
            End If
            txtEmpID.Text = ""
            txtEmployeesName.Text = ""
            txtFathersName.Text = ""
            txtShiftName.Text = ""
            txtOvertimeRate.Text = ""
            txtOVTM_ENROLL_ID.Text = ""
            dtpEndTime.Value = Now
            dtpEnrollDate.Value = Now
            dtpStartTime.Value = Now
            btnSubmit.Text = "SAVE"
            PictureBox1.Image = PayrollManagementSystem.My.Resources.no_image
            MsgBox("Record has been saved successfully.", MsgBoxStyle.Information, "Information")
        End If
    End Sub

    Private Sub frmOvertime1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class