Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Security
Imports System.Security.Cryptography
Imports System.Text
Public Class partsstock
    Private cnstr As String
    Dim conn As SqlConnection
    Dim cmd As SqlCommand
    Dim reader As SqlDataReader

    Private Sub btnview_Click(sender As System.Object, e As System.EventArgs) Handles btnview.Click

        dg.Rows.Clear()
        Try
            conn = New SqlConnection("data source=192.168.1.41;initial catalog=Toshiba_kanban;user=cats;password=dogs;Integrated Security=false")
            conn.Open()
            cmd = New SqlCommand("SELECT * from [Toshiba_kanban].[dbo].[PartsRecords] WHERE ToshibaPN = '" & txtpn.Text & "' AND Status = 'WHS' AND Family = '" & cmbfamily.Text & "' ORDER BY PrintedDate desc", conn)
            reader = cmd.ExecuteReader()
            While reader.HasRows()
                reader.Read()
                dg.Rows.Add(reader("SerialNum").ToString, reader("ToshibaPN").ToString, reader("SupplierPN").ToString, reader("MakerCode").ToString, reader("Description").ToString, reader("LotNO").ToString, reader("PrintedDate").ToString, reader("PrintedBy").ToString, reader("Status").ToString, reader("Qty").ToString, reader("InvoiceNum").ToString, reader("Family").ToString)
            End While

        Catch ex As Exception

        End Try
        conn.Close()
    End Sub

    Private Sub btnreset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnreset.Click
        dg.Rows.Clear()
        cmbfamily.SelectedIndex = -1
        txtpn.Text = Nothing
    End Sub

    Private Sub txtpn_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpn.TextChanged

    End Sub

    Private Sub partsstock_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtpn.Focus()
    End Sub

    Private Sub txtpn_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtpn.KeyUp
        If e.KeyCode = Keys.Enter Then
            If txtpn.Text.Length >= 13 Then
                txtpn.Text = txtpn.Text.Trim.Substring(0, 12)
            End If

            dg.Rows.Clear()
            Try
                conn = New SqlConnection("data source=192.168.1.41;initial catalog=Toshiba_kanban;user=cats;password=dogs;Integrated Security=false")
                conn.Open()
                cmd = New SqlCommand("SELECT * from [Toshiba_kanban].[dbo].[PartsRecords] WHERE ToshibaPN = '" & txtpn.Text & "' AND Status = 'WHS' AND Family = '" & cmbfamily.Text & "' ORDER BY PrintedDate desc", conn)
                reader = cmd.ExecuteReader()
                While reader.HasRows()
                    reader.Read()
                    dg.Rows.Add(reader("SerialNum").ToString, reader("ToshibaPN").ToString, reader("SupplierPN").ToString, reader("MakerCode").ToString, reader("Description").ToString, reader("LotNO").ToString, reader("PrintedDate").ToString, reader("PrintedBy").ToString, reader("Status").ToString, reader("Qty").ToString, reader("InvoiceNum").ToString, reader("Family").ToString)
                End While

            Catch ex As Exception

            End Try
            conn.Close()

        End If
    End Sub
End Class