Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Imports System.Text
Imports System.Data.SqlClient

Public Class DIDhistory


    Dim conn As SqlConnection
    Dim cmd As SqlCommand
    Dim reader As SqlDataReader

    Private Sub txtClear_Click(sender As System.Object, e As System.EventArgs) Handles txtClear.Click
        dg.Rows.Clear()
        txtDid.Text = ""
    End Sub

    Private Sub DIDhistory_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = mainForm
        Control.CheckForIllegalCrossThreadCalls = False
        Me.Top = 0
        Me.Left = 0

        txtDid.Focus()
    End Sub

    Private Sub txtSearch_Click(sender As System.Object, e As System.EventArgs) Handles txtSearch.Click


        If (txtDid.Text = "") Then
            txtSearch.Focus()
        Else


            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].[PartsLog] where MaterialID = '" & txtDid.Text & "' order by lastupdated asc", conn)
                reader = cmd.ExecuteReader()
                While reader.HasRows()
                    reader.Read()
                    dg.Rows.Add(reader("MaterialID").ToString, reader("IonicsPN").ToString, reader("Description").ToString, reader("Supplier").ToString, reader("LotNo").ToString, reader("qty").ToString, reader("Status").ToString, reader("family").ToString, reader("line").ToString, reader("rev").ToString, reader("lastupdated").ToString, reader("lastupdatedby").ToString)
                End While

            Catch ex As Exception

            End Try
            conn.Close()
        End If

    End Sub

    Private Sub txtDid_KeyUp(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles txtDid.KeyUp

        If Keys.Enter Then

            If (txtDid.Text = "") Then
                txtSearch.Focus()
            Else


                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].[PartsLog] where MaterialID = '" & txtDid.Text & "' order by lastupdated asc", conn)
                    reader = cmd.ExecuteReader()
                    While reader.HasRows()
                        reader.Read()
                        dg.Rows.Add(reader("MaterialID").ToString, reader("IonicsPN").ToString, reader("Description").ToString, reader("Supplier").ToString, reader("LotNo").ToString, reader("qty").ToString, reader("Status").ToString, reader("family").ToString, reader("line").ToString, reader("rev").ToString, reader("lastupdated").ToString, reader("lastupdatedby").ToString)
                    End While

                Catch ex As Exception

                End Try
                conn.Close()
            End If
        End If
    End Sub

    Private Sub dg_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg.CellContentClick
 
    End Sub
End Class