Imports System.Data.OleDb
Imports System.Object
Public Class frmstocktorecord

    Private Sub frmstocktorecord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call connectDatabase()
        Call loadsearchresult()
        If Form1.ComboBox1.Text = "Admin" Then
            Button1.Enabled = True
        Else
            Button1.Enabled = False

        End If
    End Sub
    Private Sub loadProducts()
        Dim oleDBC As New OleDbCommand
        Dim oleDBDR As OleDbDataReader
        Dim c As Integer
        c = 0
        If ComboBox1.Text = "Barcode" Then
            With oleDBC
                .Connection = conn
                .CommandText = "SELECT * FROM tblStock WHERE Barcode='" & TextBox1.Text & "'"

            End With
        ElseIf ComboBox1.Text = "Category" Then
            With oleDBC
                .Connection = conn
                .CommandText = "SELECT * FROM tblStock WHERE Category='" & TextBox1.Text & "'"
            End With
        ElseIf ComboBox1.Text = "Name" Then
            With oleDBC
                .Connection = conn
                .CommandText = "SELECT * FROM tblStock WHERE ItemName='" & TextBox1.Text & "'"
            End With
        Else
            MsgBox("RECORD DOES NOT EXIST")
        End If
        oleDBDR = oleDBC.ExecuteReader
        DataGridView1.Rows.Clear()
        If oleDBDR.HasRows Then
            While oleDBDR.Read
                DataGridView1.Rows.Add()
                DataGridView1.Item(0, c).Value = oleDBDR.Item(1)
                DataGridView1.Item(1, c).Value = oleDBDR.Item(2)
                DataGridView1.Item(2, c).Value = oleDBDR.Item(3)
                DataGridView1.Item(3, c).Value = oleDBDR.Item(4)
                DataGridView1.Item(4, c).Value = oleDBDR.Item(5)
                DataGridView1.Item(5, c).Value = oleDBDR.Item(6)
                DataGridView1.Item(6, c).Value = oleDBDR.Item(7)
                DataGridView1.Item(7, c).Value = oleDBDR.Item(8)
                'DataGridView1.Item(8, c).Value = oleDBDR.Item(9)
                c = c + 1
            End While
        Else

        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Call DisconnectDatabase()
        Me.Hide()
    End Sub
    Private Sub loadsearchresult()
        Dim OleDBC As New OleDbCommand
        Dim OleDBDR As OleDbDataReader
        Dim c As Integer
        c = 0
        With OleDBC

            .Connection = conn
            .CommandText = "SELECT * FROM tblStock "

        End With
        OleDBDR = OleDBC.ExecuteReader
        DataGridView1.Rows.Clear()
        If OleDBDR.HasRows Then
            While OleDBDR.Read
                DataGridView1.Rows.Add()
                DataGridView1.Item(0, c).Value = OleDBDR.Item(1)
                DataGridView1.Item(1, c).Value = OleDBDR.Item(2)
                DataGridView1.Item(2, c).Value = OleDBDR.Item(3)
                DataGridView1.Item(3, c).Value = OleDBDR.Item(4)
                DataGridView1.Item(4, c).Value = OleDBDR.Item(5)
                DataGridView1.Item(5, c).Value = OleDBDR.Item(6)
                DataGridView1.Item(6, c).Value = OleDBDR.Item(7)
                DataGridView1.Item(7, c).Value = OleDBDR.Item(8)
                ' DataGridView1.Item(8, c).Value = OleDBDR.Item(9)
               
                c = c + 1
            End While
        End If
    End Sub
    Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
        If e.RowIndex < 0 Then Exit Sub
        invoices.Barcode1.Text = DataGridView1.Item(0, e.RowIndex).Value
        invoices.TextBox1.Text = DataGridView1.Item(1, e.RowIndex).Value
        invoices.ItemNameTextBox.Text = DataGridView1.Item(2, e.RowIndex).Value
        invoices.PriceTextBox.Text = DataGridView1.Item(5, e.RowIndex).Value


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Hide()
        invoices.Show()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Call loadProducts()
    End Sub

    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Call loadsearchresult()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Call callme()
    End Sub
    Private Sub callme()

        If TextBox1.Text = "" Then
            MsgBox("magtype ka muna ng isesearch mo")
            Me.Focus()
        Else
            Call loadProducts()
        End If
    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click

    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub

    Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
        Me.Hide()
        invoices.Show()

    End Sub
End Class