Public Class frmLost
    Private Sub reloadLost()
        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 txtLostQuantity
            .Clear()
            .Focus()
        End With
    End Sub

    Private Sub frmTranferItems_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        reloadLost()
    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")
                txtAcutalQuantity.Text = .Item("AssignedOnhandQty")
                txtLostQuantity.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 lost equipment.", MsgBoxStyle.Exclamation)
            Return
        End If


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

        sql = "UPDATE `tblassigneditems` SET `AssignedOnhandQty`=`AssignedOnhandQty`-'" & Val(txtLostQuantity.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 `tbllost` (`AssignedID`, `Barcode`, `Description`, `LostQuantity`, `AsignedArea`, `DateLost`) " &
                    "Values ('" & .Item("AssignedID") & "','" & .Item("Barcode") & "','" & .Item("Description") & "','" & Val(txtLostQuantity.Text) & "','" & .Item("Location") &
                    "',Now())"
            create(sql)
        End With

        MsgBox("Items has been lost.")
        reloadLost()

    End Sub

    Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        sql = "SELECT ItemID, `Parts`,`Location`, `ComputerSet` " _
        & "FROM `tblbrand` b,`tblitems` i, `tblparts` p, `tbllocation` l,tblcompset c " _
        & "WHERE b.`BrandID`=i.`BrandID` AND i.`PartsID`=p.`PartsID` AND i.`LocationID`=l.`LocationID` " _
        & "AND i.CompSetID=c.CompSetID AND Status in ('Good','Damaged','Maintenance') AND (Parts Like '%" & txtSearch.Text _
        & "%' OR Location Like '%" & txtSearch.Text & "%' OR ComputerSet Like '%" & txtSearch.Text _
        & "%' OR CONCAT(Parts,' ',ComputerSet,' ', Location) 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 txtLostQuantity_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLostQuantity.KeyPress
        numbersOnly(e)
    End Sub

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