Imports System.Data.OleDb

Public Class AdminForm
    Private dbc As New OleDbConnection(conStr)


    Public Sub showStocks()
        Dim dba As New OleDbDataAdapter("SELECT tbStocks.StockID,tbProduct.ProdName as [Product Name],tbStocks.Unit,tbStocks.Price,tbStocks.Quantity,tbStocks.ExpirationDate,tbProduct.ProdMan FROM tbStocks INNER JOIN tbProduct ON tbStocks.ProdID=tbProduct.ProdID WHERE ExpirationDate>=#" & Now() & "#;", dbc)
        Dim dbset As New DataSet
        dba.Fill(dbset)
        Me.DataGridView1.DataSource = dbset.Tables(0).DefaultView

    End Sub



    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        showStocks()
        'Me.GroupBox3.Visible = False
        'Me.DataGridView2.Visible = False
        'Me.DataGridView3.Visible = False

        
        

    End Sub








    Private Sub Form3_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Me.Hide()
        Login.Show()

    End Sub

    Private Sub ADDNEWPRODUCTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ADDNEWPRODUCTToolStripMenuItem.Click
        AddnewProduct.Show()
    End Sub

    Private Sub ADDNEWSUPPLIERToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ADDNEWSUPPLIERToolStripMenuItem.Click
        SupplierForm.Show()
    End Sub

    

    Private Sub StockOutsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        outofStocks.Show()
    End Sub

    Private Sub StocksRunningToBeEmptyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StocksRunningToBeEmptyToolStripMenuItem.Click
        Form9.Show()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Me.Button1.Text = "Edit Quantity" Then
            Me.Button1.Text = "SAVE"

            Me.quantity.ReadOnly = False


        ElseIf Me.Button1.Text = "SAVE" Then

            If Me.quantity.Text = "" Then
                MessageBox.Show("EMPTY", "EMPTY", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub

            End If
            If Me.quantity.Text = "0" Then
                MessageBox.Show("The Quantity is Zero", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub

            End If
            Me.Button1.Text = "Edit Quantity"



            'Dim incmd As New OleDbCommand("INSERT INTO tbStockOut(StockID,ProdName,Unit,Quantity,Price,OutDate, ExpirationDate) VALUES(" & Me.DataGridView1.CurrentRow.Cells(0).Value & ",'" & Me.TextBox1.Text & "','" & Me.TextBox2.Text & "'," & Me.TextBox3.Text & "," & Me.DataGridView1.CurrentRow.Cells(2).Value * Me.TextBox3.Text & ",#" & Now() & "#, '" & Me.TextBox4.Text & "')", dbc)
            'dbc.Open()
            'incmd.ExecuteNonQuery()
            'dbc.Close()

            Dim upcmd As New OleDbCommand("UPDATE tbStocks SET Quantity=" & Me.quantity.Text & " WHERE StockID=" & Me.DataGridView1.CurrentRow.Cells(0).Value & ";", dbc)
            dbc.Open()
            upcmd.ExecuteNonQuery()
            dbc.Close()

            showStocks()

            MessageBox.Show("Quantity Updated", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information)

            Me.quantity.ReadOnly = True

        End If

    End Sub

    Private Sub PutINTOINVENTORYToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PutINTOINVENTORYToolStripMenuItem.Click
        Inventory.Show()

    End Sub

    Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim i As Integer = DataGridView1.CurrentRow.Index
        pname.Text = DataGridView1.Item(1, i).Value
        unit.Text = DataGridView1.Item(2, i).Value
        price.Text = DataGridView1.Item(3, i).Value
        quantity.Text = DataGridView1.Item(4, i).Value
        expire.Text = DataGridView1.Item(5, i).Value
        manu.Text = DataGridView1.Item(6, i).Value
    End Sub

    Private Sub ExpiredStocksToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExpiredStocksToolStripMenuItem.Click
        ExpiredProds.Show()

    End Sub

    Private Sub GroupBox3_Enter(sender As Object, e As EventArgs) Handles GroupBox3.Enter

    End Sub

    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub

    Private Sub AdminForm_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        Dim dba As New OleDbDataAdapter("SELECT tbStocks.StockID,tbProduct.ProdName,tbStocks.Unit,tbStocks.Price,tbStocks.Quantity,tbStocks.ExpirationDate FROM tbStocks INNER JOIN tbProduct ON tbStocks.ProdID=tbProduct.ProdID WHERE ExpirationDate>=#" & Now() & "#;", dbc)
        Dim dbset As New DataSet
        dba.Fill(dbset)
        If dbset.Tables(0).DefaultView.Count > 0 Then
            If MessageBox.Show("Want to check if there is/are stocks that are expired?", "Expired Products", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
                ExpiredProds.Show()
            End If
        End If
    End Sub

    Private Sub ClientsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClientsToolStripMenuItem.Click
        ClientsReport.Show()
    End Sub

    Private Sub ProductToolStripMenuItem_Click(sender As Object, e As EventArgs)
        ExpiredReport.Show()

    End Sub

    Private Sub MonthlySalesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MonthlySalesToolStripMenuItem.Click
        Report.Show()
    End Sub

    Private Sub INCOMEToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles INCOMEToolStripMenuItem1.Click

    End Sub

    Private Sub ExpiredStocksRemovedFromInventoryToolStripMenuItem_Click(sender As Object, e As EventArgs)
        ExpireRem.Show()

    End Sub

    Private Sub AdminToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AdminToolStripMenuItem.Click
        Adminpw.Show()

    End Sub

    Private Sub ClerkToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClerkToolStripMenuItem.Click
        ClerkPw.show()

    End Sub

    Private Sub ExpiredStocksRemovedFromInventoryToolStripMenuItem_Click_1(sender As Object, e As EventArgs) Handles ExpiredStocksRemovedFromInventoryToolStripMenuItem.Click
        ExpiredReport.Show()


    End Sub

    Private Sub TextBox8_TextChanged(sender As Object, e As EventArgs) Handles TextBox8.TextChanged
        Dim se As New OleDbDataAdapter("SELECT tbStocks.StockID,tbProduct.ProdName,tbStocks.Price,tbStocks.Quantity,tbStocks.ExpirationDate FROM tbStocks INNER JOIN tbProduct ON tbStocks.ProdID=tbProduct.ProdID WHERE ExpirationDate>=#" & Now() & "# AND tbProduct.ProdName LIKE '%" & Me.TextBox8.Text & "%';", dbc)
        Dim dbset As New DataSet
        se.Fill(dbset)
        Me.DataGridView1.DataSource = dbset.Tables(0).DefaultView


    End Sub

    Private Sub InventoryToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles InventoryToolStripMenuItem.Click

    End Sub

   
End Class