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

Public Class DIDInquiry


    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()

    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

    End Sub

    Private Sub txtSearch_Click(sender As System.Object, e As System.EventArgs) Handles txtSearch.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()

            Dim FromDate As Date = datefrom.Text
            Dim ToDate As Date = dateto.Text

            cmd = New SqlCommand("SELECT a.SerialNum , a.IonicsPN , b.Description, b.Supplier , a.MakerCode ,b.LotNo , b.qty , b.status , b.family , b.line , b.rev , b.lastupdated , b.lastupdatedby from [Toshiba_kanban].[dbo].[PartsRecords] as a inner join PartsLog as b on a.SerialNum = b.MaterialID where b.lastupdated between Convert(date,convert(varchar,'2018-05-2',101)) AND  Convert(date,convert(varchar,'" & ToDate.Year.ToString & "-" & ToDate.Month.ToString & "-" & ToDate.Day.ToString & "',101)) and b.status <> 'Mounted' order by a.SerialNum , b.lastupdated asc", conn)
            reader = cmd.ExecuteReader()
            While reader.HasRows()
                reader.Read()
                dg.Rows.Add(reader("SerialNum").ToString, reader("IonicsPN").ToString, reader("Description").ToString, reader("Supplier").ToString, reader("MakerCode").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 Sub
  
End Class