Public Class frmMaintenance

    Private Sub reloadMaintenance()
        sql = "SELECT AssignedID,`Barcode`,`Description`,`Location`, `ComputerSet`,AssignedOnhandQty as 'AssignedQuantity' FROM `tblassigneditems`  a,`tbllocation` l,`tblcompset` c WHERE a.`LocationID`=l.`LocationID`  AND a.`CompSetID`=c.`CompSetID` AND AssignedOnhandQty > 0"
        reloadDtg(sql, dtgList)
        dtgList.Columns(0).Visible = False
        cleartext(GroupBox1)
        With txtUndermaintenanceQty
            .Clear()
            .Focus()
        End With
    End Sub

    Private Sub frmTranferItems_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        reloadMaintenance()
    End Sub


    Private Sub dtgList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtgList.Click
        Try
            sql = "SELECT * " &
            " FROM  `tblassigneditems` a,  `tbllocation` l,tblcompset c " _
             & "WHERE a.`LocationID`=l.`LocationID` AND a.CompSetID=c.CompSetID AND AssignedID=" & dtgList.CurrentRow.Cells(0).Value
            reloadtxt(sql)

            With dt.Rows(0)
                txtBarcode.Text = .Item("Barcode")
                'txtBrand.Text = .Item("Brand")
                txtItems.Text = .Item("Description")
                txtParts.Text = .Item("Parts")
                txtLocated.Text = .Item("Location")
                txtCompSet.Text = .Item("ComputerSet")
                txtremainingqty.Text = .Item("AssignedOnhandQty")

                txtUndermaintenanceQty.Focus()

            End With

        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnTransfer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransfer.Click


        If txtBarcode.Text = "" Then
            MsgBox("Select the equipment you want to repair.", MsgBoxStyle.Exclamation)
            Return
        End If
        If txtUndermaintenanceQty.Text = "" Then
            MsgBox("Empty field must be filled up.", MsgBoxStyle.Exclamation)
            Return
        End If

        'sql = "UPDATE `tblitems` SET `Status`='Maintenance'  WHERE `ItemID`=" & dtgList.CurrentRow.Cells(0).Value
        'updates(sql)

        sql = "UPDATE `tblassigneditems` SET `AssignedOnhandQty`=`AssignedOnhandQty`-'" & Val(txtUndermaintenanceQty.Text) & "' WHERE `AssignedID`=" & dtgList.CurrentRow.Cells(0).Value
        updates(sql)

        sql = "SELECT * FROM tblassigneditems a ,tbllocation l WHERE a.`LocationID`=l.`LocationID` AND AssignedID=" & dtgList.CurrentRow.Cells(0).Value
        reloadtxt(sql)

        With dt.Rows(0)
            sql = "INSERT INTO `tblmaintenance` (`AssignedID`, `Barcode`, `Description`, `MaintenanceQuantity`, `AssignedArea`, `DateRepair`,`MSTATUS`) " &
                    "Values ('" & .Item("AssignedID") & "','" & .Item("Barcode") & "','" & .Item("Description") & "','" & txtUndermaintenanceQty.Text & "','" & .Item("Location") &
                    "',Now(),'Maintenance')"
            create(sql)
        End With


        MsgBox("Items has been under maintenance.")
        reloadMaintenance()


    End Sub

    Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        sql = "SELECT AssignedID,`Barcode`,`Description`,`Location`, `ComputerSet`,AssignedOnhandQty as 'AssignedQuantity' " &
            " FROM `tblassigneditems`  a,`tbllocation` l,`tblcompset` c WHERE a.`LocationID`=l.`LocationID`  AND a.`CompSetID`=c.`CompSetID` AND AssignedOnhandQty > 0 " &
            " AND (Location Like '%" & txtSearch.Text & "%'   OR Barcode  LIKE '%" & txtSearch.Text & "%')"
        reloadDtg(sql, dtgList)
        dtgList.Columns(0).Visible = False
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub txtUndermaintenanceQty_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUndermaintenanceQty.KeyPress
        numbersOnly(e)
    End Sub

    Private Sub txtUndermaintenanceQty_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUndermaintenanceQty.TextChanged
        If Val(txtremainingqty.Text) < Val(txtUndermaintenanceQty.Text) Then
            MsgBox("The quantity you want to save is greater than the actual quantity!", MsgBoxStyle.Exclamation)
            txtUndermaintenanceQty.Text = ""
        ElseIf txtUndermaintenanceQty.Text = "0" Then
            MsgBox("Quantity cannot be 0!", MsgBoxStyle.Exclamation)
            txtUndermaintenanceQty.Text = ""
        End If

    End Sub
End Class