Public Class frmDeductions
    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 btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.Close()
    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 txtAmount.Text = "" Then
            ErrorProvider1.SetError(txtEmployeesCode, "Mandatory field.")
            ErrorProvider1.SetError(txtAmount, "Mandatory field.")
        ElseIf Not IsNumeric(txtAmount.Text) Then
            ErrorProvider1.SetError(txtAmount, "Numeric input only!")
        Else
            ErrorProvider1.Clear()
            If btnSubmit.Text = "SAVE" Then
                ExecuteSQLQuery(" INSERT INTO Deduction (EMPLOYEE_ID, EnrollDate, DeductionFactor, DeductAmount) VALUES " &
                                " (" & num_fltr(txtEmpID.Text) & ", '" & Format(dtpEnrollDate.Value, "yyyy-MM-dd") & "', '" + str_repl(txtDeductionFactor.Text) + "' ,  " & num_fltr(txtAmount.Text) & ") ")
            ElseIf btnSubmit.Text = "UPDATE" Then
                ExecuteSQLQuery(" UPDATE Deduction  SET EMPLOYEE_ID=" & num_fltr(txtEmpID.Text) & ", EnrollDate='" & Format(dtpEnrollDate.Value, "yyyy-MM-dd") & "', DeductionFactor='" + str_repl(txtDeductionFactor.Text) + "', DeductAmount=" & num_fltr(txtAmount.Text) & " " &
                                " WHERE DCTON_ENROLL_ID=" & num_fltr(txtDCTON_ENROLL_ID.Text) & " ")
            End If
            txtEmpID.Text = ""
            txtEmployeesName.Text = ""
            txtFathersName.Text = ""
            txtShiftName.Text = ""
            txtDeductionFactor.Text = ""
            txtAmount.Text = ""
            txtDCTON_ENROLL_ID.Text = ""
            dtpEnrollDate.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
End Class