Imports System.IO
Imports System.Byte
Imports System.Drawing
Imports System.IO.MemoryMappedFiles
Imports System.IO.StreamReader

Imports System.Data.OleDb
Public Class frmEmployee
    Dim imgName As String
    Dim daImage As OleDbDataAdapter
    Dim dsImage As DataSet
    Dim cn As New OleDbConnection
    Dim cmd As New OleDbCommand
    Dim dr As OleDbDataReader
    Dim db As String = "EmployeeData.mdb"
    Dim cnstring As String = "PRovider=Microsoft.ace.oledb.12.0;data source=" & db & ""
    Private Sub TblEmployeeBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.TblEmployeeBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.EmployeeDataDataSet)

    End Sub

    Private Sub frmEmployee_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'EmployeeDataDataSet.tblEmployee' table. You can move, or remove it, as needed.
        Me.TblEmployeeTableAdapter.Fill(Me.EmployeeDataDataSet.tblEmployee)

    End Sub

    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        Try
            Dim dlgImage As FileDialog = New OpenFileDialog()

            dlgImage.Filter = "Image File (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif"

            If dlgImage.ShowDialog() = DialogResult.OK Then
                imgName = dlgImage.FileName

                Dim newimg As New Bitmap(imgName)

                TblPhotoPictureBox.SizeMode = PictureBoxSizeMode.StretchImage
                TblPhotoPictureBox.Image = DirectCast(newimg, Image)
            End If

            dlgImage = Nothing
        Catch ae As System.ArgumentException
            imgName = " "

            MessageBox.Show(ae.Message.ToString())
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())
        End Try
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        TblEmployeeBindingSource.AddNew()
        MessageBox.Show("You can now input.")
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If Len(Trim(EmployeeNumberTextBox.Text)) = 0 Then
            MessageBox.Show("Please Fill Empty Fields", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            EmployeeNumberTextBox.Focus()
            Exit Sub
        End If


        Try
            Me.Validate()
            Me.TblEmployeeBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.EmployeeDataDataSet)
            MessageBox.Show("Data Updated")
            EmployeeNumberTextBox.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Try
            If EmployeeNumberTextBox.Text = "" Then
                MessageBox.Show("Please select employee no.", "Entry", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                Exit Sub
            End If
            If EmployeeNumberTextBox.Text.Count > 0 Then
                If MessageBox.Show("Do you really want to delete the record?" & vbCrLf & "You can not restore the record" & vbCrLf & "It will delete record permanently" & vbCrLf & "related to selected item", "Warning!!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
                    TblEmployeeBindingSource.RemoveCurrent()
                    Me.TableAdapterManager.UpdateAll(Me.EmployeeDataDataSet)
                End If
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        e.Graphics.DrawString(txtReceipt.Text, Font, Brushes.Black, 140, 140)
        e.Graphics.DrawImage(Me.PictureBox1.Image, 490, 130, PictureBox1.Width - 15, PictureBox1.Height - 25)
        Try
            e.Graphics.DrawImage(Me.TblPhotoPictureBox.Image, 500, 144, TblPhotoPictureBox.Width - 15, TblPhotoPictureBox.Height - 25)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

        txtReceipt.Text = ""
        txtReceipt.AppendText("                     Personal Information                       " + vbNewLine)
        txtReceipt.AppendText("" + vbNewLine)
        txtReceipt.AppendText("Employee ID: " + vbTab & EmployeeNumberTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Department: " + vbTab & DepartmentComboBox.Text + vbNewLine)
        txtReceipt.AppendText("First Name: " + vbTab & FirstNameTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Middle Name: " + vbTab & MiddleNameTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Last Name: " + vbTab & LastNameTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Birth Date: " + vbTab & BirthDateDateTimePicker.Text + vbNewLine)
        txtReceipt.AppendText("Age: " + vbTab + vbTab & AgeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Address: " + vbTab & PAddressTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Citizenship: " + vbTab & CitizenShipTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Contact Number: " & ContactNumberTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Place of Birth: " + vbTab & PlaceOfBirthTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Height: " + vbTab + vbTab & HeightTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Weight: " + vbTab + vbTab & WeightTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Blood Type: " + vbTab & BloodTypeComboBox.Text + vbNewLine)
        txtReceipt.AppendText("Gender: " + vbTab + vbTab & GenderComboBox.Text + vbNewLine)
        txtReceipt.AppendText("Status: " + vbTab + vbTab & STATUSLComboBox.Text + vbNewLine)
        txtReceipt.AppendText("Email: " + vbTab + vbTab & EmailAddressTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Pag-IBIG #: " + vbTab & Pag_IBIGIDNumberTextBox.Text + vbNewLine)
        txtReceipt.AppendText("GSIS ID: " + vbTab & GSISIDTextBox.Text + vbNewLine)
        txtReceipt.AppendText("PhilHealth: " + vbTab & PhilHealthTextBox.Text + vbNewLine)
        txtReceipt.AppendText("SSS: " + vbTab + vbTab & SSSTextBox.Text + vbNewLine)
        txtReceipt.AppendText("TIN: " + vbTab + vbTab & TINTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Employee Status: " & EmployeeStatusComboBox.Text + vbNewLine)
        txtReceipt.AppendText("___________________________________________________________________________________________________________" + vbNewLine)

        txtReceipt.AppendText("                     Educational Attainment                       " + vbNewLine)
        txtReceipt.AppendText("" + vbNewLine)
        txtReceipt.AppendText("Elementary: " + vbTab + vbTab & ElementaryTextBox.Text + vbNewLine)
        txtReceipt.AppendText("High School: " + vbTab + vbTab & HighSchoolTextBox.Text + vbNewLine)
        txtReceipt.AppendText("College: " + vbTab + vbTab & CollegeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Vocational Trade Course: " + vbTab & VocationalTradeCourseTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Degree Course: " + vbTab + vbTab & DegreeCourseTextBox.Text + vbNewLine)
        txtReceipt.AppendText("* " + vbTab + vbTab + vbTab & DegreeCourse1TextBox.Text + vbNewLine)
        txtReceipt.AppendText("* " + vbTab + vbTab + vbTab & DegreeCourse2TextBox.Text + vbNewLine)
        txtReceipt.AppendText("* " + vbTab + vbTab + vbTab & DegreeCourse3TextBox.Text + vbNewLine)
        txtReceipt.AppendText("* " + vbTab + vbTab + vbTab & DegreeCourse4TextBox.Text + vbNewLine)
        txtReceipt.AppendText("___________________________________________________________________________________________________________" + vbNewLine)

        txtReceipt.AppendText("                     Name of Children ( Full List )                       " + vbNewLine)
        txtReceipt.AppendText("" + vbNewLine)
        txtReceipt.AppendText("1 :" + vbTab & ChildName1AgeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("2 :" + vbTab & ChildName2AgeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("3 :" + vbTab & ChildName3AgeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("4 :" + vbTab & ChildName4AgeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("5 :" + vbTab & ChildName5AgeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("6 :" + vbTab & ChildName6AgeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("7 :" + vbTab & ChildName7AgeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("8 :" + vbTab & ChildName8AgeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("9 :" + vbTab & ChildName9AgeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("10 :" + vbTab & ChildName10AgeTextBox.Text + vbNewLine)
        txtReceipt.AppendText("___________________________________________________________________________________________________________" + vbNewLine)

        txtReceipt.AppendText("                     Family Background                       " + vbNewLine)
        txtReceipt.AppendText("" + vbNewLine)
        txtReceipt.AppendText(" Spouse Name                       " + vbNewLine)
        txtReceipt.AppendText("" + vbNewLine)
        txtReceipt.AppendText("First Name: " + vbTab & SecFirstNameTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Name Extension: " & SecNameExtensionTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Middle Name: " + vbTab & SecMiddleNameTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Last Name: " + vbTab & SecLastNameTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Birth Date: " + vbTab & SecBirthdateDateTimePicker.Text + vbNewLine)
        txtReceipt.AppendText("Occupation: " + vbTab & SecOccupationTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Contact Number: " & SecContactNumberTextBox.Text + vbNewLine)
        txtReceipt.AppendText("" + vbNewLine)
        txtReceipt.AppendText(" Mother`s Maiden Name                             Fathers Name " + vbNewLine)
        txtReceipt.AppendText("" + vbNewLine)
        txtReceipt.AppendText("First Name: " + vbTab & MoFirstNameTextBox.Text + vbTab + vbTab + vbTab & " First Name: " + vbTab & FaFirstNameTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Middle Name: " + vbTab & MoMiddleNameTextBox.Text + vbTab + vbTab + vbTab & " Name Extension: " & FaNameExtensionTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Last Name: " + vbTab & MoLastNameTextBox.Text + vbTab + vbTab + vbTab & " Middle Name: " + vbTab & FaNameExtensionTextBox.Text + vbNewLine)
        txtReceipt.AppendText("Occupation: " + vbTab & MoOccupationTextBox.Text + vbTab + vbTab + vbTab & " Last Name: " + vbTab & FaLastNameTextBox.Text + vbNewLine)
        txtReceipt.AppendText("" + vbTab + vbTab + vbTab + vbTab + vbTab & " Occupation: " + vbTab & FaOccupationTextBox.Text + vbNewLine)
        txtReceipt.AppendText("" + vbNewLine)
        txtReceipt.AppendText("___________________________________________________________________________________________________________" + vbNewLine)

        PrintPreviewDialog1.ShowDialog()
    End Sub

    Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        Me.TblEmployeeBindingSource.Filter = "LastName LIKE '" & txtSearch.Text & "%'"
    End Sub

    Private Sub frmEmployee_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        Form3.Show()
    End Sub

    Private Sub frmEmployee_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        Form3.Show()
    End Sub
End Class