Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Security
Imports System.Security.Cryptography
Imports System.Text
Public Class Sequence
    Private _ksqaccount As String
    Private _ksqmodel As String
    Private _ksqline As String
    Private _ksqpcbside As String
    Private _ksqpartno As String
    Private _ksqmachine As String
    Private _ksqrevision As String
    Private _ksqtopsdloc As String
    Private _ksqfsbsqty As String
    Private _ksqdesc1 As String
    Private _ksqdesc2 As String
    Private _ksqtopmark As String
    Private _ksqmodule As String
    Private _ksqfeeder As String
    Private _ksqfeederType As String
    Private _ksqprepby As String
    Private _ksqupdtime As String
    Private _ksqcheckby As String
    Private _ksqchkdate As String
    Private _ksqremarks As String
    Private _ksqStatus As Integer
    Private _kseqno As String
    Private cnstr As String

#Region "Properties"

    Public Property sequenceno() As String
        Get
            Return _kseqno
        End Get
        Set(ByVal value As String)
            _kseqno = value
        End Set
    End Property

    Public Property account() As String
        Get
            Return _ksqaccount
        End Get
        Set(ByVal value As String)
            _ksqaccount = value
        End Set
    End Property

    Public Property line() As String
        Get
            Return _ksqline
        End Get
        Set(ByVal value As String)
            _ksqline = value
        End Set
    End Property

    Public Property model() As String
        Get
            Return _ksqmodel
        End Get
        Set(ByVal value As String)
            _ksqmodel = value
        End Set
    End Property

    Public Property pcbside() As String
        Get
            Return _ksqpcbside
        End Get
        Set(ByVal value As String)
            _ksqpcbside = value
        End Set
    End Property

    Public Property partno() As String
        Get
            Return _ksqpartno
        End Get
        Set(ByVal value As String)
            _ksqpartno = value
        End Set
    End Property

    Public Property machine() As String
        Get
            Return _ksqmachine
        End Get
        Set(ByVal value As String)
            _ksqmachine = value
        End Set
    End Property

    Public Property revision() As String
        Get
            Return _ksqrevision
        End Get
        Set(ByVal value As String)
            _ksqrevision = value
        End Set
    End Property

    Public Property topsdloc() As String
        Get
            Return _ksqtopsdloc
        End Get
        Set(ByVal value As String)
            _ksqtopsdloc = value
        End Set
    End Property

    Public Property fsbsqty() As String
        Get
            Return _ksqfsbsqty
        End Get
        Set(ByVal value As String)
            _ksqfsbsqty = value
        End Set
    End Property

    Public Property desc1() As String
        Get
            Return _ksqdesc1
        End Get
        Set(ByVal value As String)
            _ksqdesc1 = value
        End Set
    End Property

    Public Property desc2() As String
        Get
            Return _ksqdesc2
        End Get
        Set(ByVal value As String)
            _ksqdesc2 = value
        End Set
    End Property

    Public Property topmark() As String
        Get
            Return _ksqtopmark
        End Get
        Set(ByVal value As String)
            _ksqtopmark = value
        End Set
    End Property

    Public Property modules() As String
        Get
            Return _ksqmodule
        End Get
        Set(ByVal value As String)
            _ksqmodule = value
        End Set
    End Property

    Public Property feeder() As String
        Get
            Return _ksqfeeder
        End Get
        Set(ByVal value As String)
            _ksqfeeder = value
        End Set
    End Property

    Public Property feederType() As String
        Get
            Return _ksqfeederType
        End Get
        Set(ByVal value As String)
            _ksqfeederType = value
        End Set
    End Property

    Public Property prepby() As String
        Get
            Return _ksqprepby
        End Get
        Set(ByVal value As String)
            _ksqprepby = value
        End Set
    End Property

    Public Property updtime() As String
        Get
            Return _ksqupdtime
        End Get
        Set(ByVal value As String)
            _ksqupdtime = value
        End Set
    End Property

    Public Property checkby() As String
        Get
            Return _ksqcheckby
        End Get
        Set(ByVal value As String)
            _ksqcheckby = value
        End Set
    End Property

    Public Property chkdate() As String
        Get
            Return _ksqchkdate
        End Get
        Set(ByVal value As String)
            _ksqchkdate = value
        End Set
    End Property

    Public Property remarks() As String
        Get
            Return _ksqremarks
        End Get
        Set(ByVal value As String)
            _ksqremarks = value
        End Set
    End Property

    Public Property status() As Integer
        Get
            Return _ksqStatus
        End Get
        Set(ByVal value As Integer)
            _ksqStatus = value
        End Set
    End Property

#End Region

#Region "Methods"
    Public Sub New()
        cnstr = mainForm.cnstr
    End Sub

    Public Function addHeader() As Boolean
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "INSERT INTO [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER]  " & _
                  "VALUES(" & "'" & _ksqaccount & "'," & _
                  "'" & _ksqrevision & "'," & _
                  "'" & _ksqmachine & "'," & _
                  "'" & _ksqpcbside & "'," & _
                  "'" & _ksqprepby & "'," & _
                  "'" & _ksqcheckby & "'," & _
                  "'" & _ksqchkdate & "'," & _
                  "'" & _ksqmodel & "'," & _
                  "'" & DateTime.Now & "'," & _
                  "0," & _
                  "'" & _ksqline & "'," & _
                  "'" & _kseqno & "')"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            mycommand.ExecuteNonQuery()
            addHeader = True
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            addHeader = False
            Exit Function
        Finally
            conn.Close()
            conn.Dispose()
        End Try
    End Function

    Public Function addDetail() As Boolean
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "INSERT INTO [Toshiba_kanban].[dbo].[KSEQUENCE_DETAIL] " & _
                  "VALUES('" & _ksqmodule & "'," & _
                  "'" & _ksqfeeder & "'," & _
                  "'" & _ksqfeederType & "'," & _
                  "'" & _ksqpartno & "'," & _
                  "'" & _ksqtopsdloc & "'," & _
                  "'" & _ksqfsbsqty & "'," & _
                  "'" & _ksqdesc1 & "'," & _
                  "'" & _ksqdesc2 & "'," & _
                  "'" & _ksqtopmark & "'," & _
                  "'" & _ksqremarks & "'," & _
                  "'" & _kseqno & "')"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            mycommand.ExecuteNonQuery()
            addDetail = True
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            addDetail = False
            Exit Function
        Finally
            conn.Close()
            conn.Dispose()
        End Try
    End Function

    Public Function generateNo(ByVal code As String) As String
        Dim conn As New SqlConnection(cnstr)
        Dim last As String = String.Empty
        Dim myQuery As String
        myQuery = "SELECT TOP 1 KSEQUENCENO FROM [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] WHERE KSEQUENCENO LIKE '" & code & "%' ORDER BY KSEQUENCENO DESC"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader = mycommand.ExecuteReader()
            If reader.HasRows Then

                reader.Read()

                last = reader("KSEQUENCENO").ToString.Split("-")(1)
                Dim seq As Integer = Integer.Parse(last) + 1
                If seq.ToString.Length = 1 Then
                    last = code & "-0000" & seq
                ElseIf seq.ToString.Length = 2 Then
                    last = code & "-000" & seq
                ElseIf seq.ToString.Length = 3 Then
                    last = code & "-00" & seq
                ElseIf seq.ToString.Length = 4 Then
                    last = code & "-0" & seq
                Else
                    last = code & "-" & seq
                End If

            Else
                last = code & "-00001"
            End If

            reader.Close()

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            conn.Close()
            conn.Dispose()
        End Try

        Return last
    End Function

    Public Sub deleteHeader()
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "DELETE FROM [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER]" & _
                  " WHERE KSEQUENCENO = '" & Me.sequenceno & "'"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            mycommand.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        Finally
            conn.Close()
            conn.Dispose()
        End Try
    End Sub

    Public Sub deleteDetail()
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "DELETE FROM [Toshiba_kanban].[dbo].[KSEQUENCE_DETAIL]" & _
                  " WHERE KSEQUENCENO = '" & Me.sequenceno & "'"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            mycommand.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        Finally
            conn.Close()
            conn.Dispose()
        End Try
    End Sub


    Public Function verify(ByVal partNo As String, ByVal sqModule As String, ByVal feeder As String) As Boolean
        Dim conn As New SqlConnection(cnstr)
        Dim status As Boolean = False

        Dim myQuery As String
        myQuery = "SELECT * FROM [Toshiba_kanban].[dbo].[KSEQUENCE_DETAIL]" & _
                  " WHERE KSEQUENCENO = '" & Me.sequenceno & "'" & _
                  " AND KSQPARTNO = '" & partNo & "'" & _
                  " AND KSQMODULE = '" & sqModule & "'" & _
                  " AND KSQFEEDERNO = '" & feeder & "'"


        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader
            If reader.HasRows Then
                status = True
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            conn.Close()
            conn.Dispose()
        End Try
        Return status
    End Function


    Public Function Part(ByVal sequenceno As String, ByVal sqModule As String, ByVal feeder As String)
        Dim conn As New SqlConnection(cnstr)
        Dim partno As String = ""

        Dim myQuery As String
        myQuery = "SELECT * FROM [Toshiba_kanban].[dbo].[KSEQUENCE_DETAIL]" & _
                  " WHERE KSEQUENCENO = '" & sequenceno & "'" & _
                  " AND KSQMODULE = '" & sqModule & "'" & _
                  " AND KSQFEEDERNO = '" & feeder & "'"


        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader
            If reader.HasRows Then
                reader.Read()
                partno = reader("KSQPARTNO")
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            conn.Close()
            conn.Dispose()
        End Try
        Return partno
    End Function

    Public Function approve() As Boolean
        Dim conn As New SqlConnection(cnstr)
        Dim approved As Boolean = False

        Dim myQuery As String
        myQuery = "UPDATE [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] SET KSQSTATUS = 1," & _
                  "KSQCHECKBY = '" & Me.checkby & "'," & _
                  "KSQCHKDATE = '" & Me.chkdate & "'" & _
                  "WHERE KSEQUENCENO = '" & Me.sequenceno & "' "

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            mycommand.ExecuteNonQuery()
            approved = 1
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            conn.Close()
            conn.Dispose()
        End Try
        Return approved
    End Function

    Public Function disApprove() As Boolean
        Dim conn As New SqlConnection(cnstr)
        Dim myQuery As String

        myQuery = "UPDATE [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] SET KSQSTATUS = 0," & _
                  "KSQCHECKBY = '" & Me.checkby & "'," & _
                  "KSQCHKDATE = '" & Me.chkdate & "'" & _
                  " WHERE KSACCOUNT = '" & Me.account & "'" & _
                  " AND KSQREVISION = '" & Me.revision & "'"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            mycommand.ExecuteNonQuery()
            disApprove = 1
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            conn.Close()
            conn.Dispose()
        End Try
    End Function

    Public Function getValidSequence() As List(Of String)
        Dim sequenceList As New List(Of String)
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "SELECT DISTINCT KSACCOUNT FROM [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] " & _
                  " WHERE KSQSTATUS = 1 " & _
                  " ORDER BY KSACCOUNT"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            While reader.Read
                sequenceList.Add(reader("KSACCOUNT"))
            End While
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return sequenceList
    End Function

    Public Function getAllSequence() As List(Of String)
        Dim sequenceList As New List(Of String)
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "SELECT DISTINCT KSACCOUNT FROM [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER]"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            While reader.Read
                sequenceList.Add(reader("KSACCOUNT"))
            End While
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return sequenceList
    End Function

    Public Function getRevisions() As List(Of String)
        Dim revList As New List(Of String)
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "SELECT DISTINCT KSQREVISION FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] " & _
                  "ORDER BY KSQREVISION"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            While reader.Read
                revList.Add(reader("KSQREVISION"))
            End While
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return revList
    End Function

    Public Function getLines(ByVal sequence As String) As List(Of String)
        Dim revList As New List(Of String)
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "SELECT DISTINCT KSQLINE FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] " & _
                  "WHERE KSACCOUNT = '" & sequence & "' " & _
                  "ORDER BY KSQLINE"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            While reader.Read
                revList.Add(reader("KSQLINE"))
            End While
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return revList
    End Function

    Public Function getRevisions(ByVal sequence As String, ByVal line As String, ByVal model As String, ByVal type As String) As List(Of String)
        Dim revList As New List(Of String)
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "SELECT DISTINCT KSQREVISION FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] " & _
                  "WHERE KSACCOUNT = '" & sequence & "' " & _
                  "AND KSQLINE = '" & line & "' " & _
                  "AND KSQMODEL = '" & model & "' " & _
                  "AND KSQPCBSIDE = '" & type & "' " & _
                  "ORDER BY KSQREVISION"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            While reader.Read
                revList.Add(reader("KSQREVISION"))
            End While
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return revList
    End Function


    Public Function getPartno(ByVal sequence As String, ByVal machine As String, ByVal feeder As String) As String
        Dim revList As String = ""
        Dim conn As New SqlConnection(cnstr)
        'MsgBox(sequence & " " & line & " " & model & " " & type & " " & rev)
        Dim myQuery As String
        myQuery = "SELECT DISTINCT KSQPARTNO FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_DETAIL] " & _
                  "WHERE KSEQUENCENO = '" & sequence & "' AND KSQMODULE = '" & machine & "' AND KSQFEEDERNO = '" & feeder & "'"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            While reader.Read
                revList = reader("KSQPARTNO")
            End While
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return revList
    End Function

    Public Function getSeq(ByVal sequence As String, ByVal line As String, ByVal model As String, ByVal type As String, ByVal rev As String) As String
        Dim revList As String = ""
        Dim conn As New SqlConnection(cnstr)
        'MsgBox(sequence & " " & line & " " & model & " " & type & " " & rev)
        Dim myQuery As String
        myQuery = "SELECT DISTINCT KSEQUENCENO FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] " & _
                  "WHERE KSACCOUNT = '" & sequence & "' " & _
                  "AND KSQLINE = '" & line & "' " & _
                  "AND KSQMODEL = '" & model & "' " & _
                  "AND KSQPCBSIDE = '" & type & "' " & _
                  "AND KSQREVISION = '" & rev & "' " & _
                  "AND KSQSTATUS = '1' " & _
                  "ORDER BY KSEQUENCENO"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            If reader.HasRows Then
                reader.Read()
                revList = reader("KSEQUENCENO")
            End If
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return revList
    End Function



    Public Function getFeederno(ByVal feeder As String) As List(Of String)
        Dim revList As New List(Of String)
        Dim conn As New SqlConnection(cnstr)
        'MsgBox(sequence & " " & line & " " & model & " " & type & " " & rev)
        Dim myQuery As String
        myQuery = "SELECT DISTINCT [KSQMODULE], [KSQFEEDERNO] FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_DETAIL] " & _
                  "WHERE KSEQUENCENO = '" & feeder & "' order by KSQMODULE, KSQFEEDERNO ASC "

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            While reader.Read
                revList.Add(reader("KSQMODULE") & "-" & reader("KSQFEEDERNO"))
            End While
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return revList
    End Function
    


    Public Function getModel(ByVal sequence As String, ByVal line As String) As List(Of String)
        Dim revList As New List(Of String)
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "SELECT DISTINCT KSQMODEL FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] " & _
                  "WHERE KSACCOUNT = '" & sequence & "' " & _
                  "AND KSQLINE = '" & line & "' " & _
                  "ORDER BY KSQMODEL"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            While reader.Read
                revList.Add(reader("KSQMODEL"))
            End While
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return revList
    End Function

    Public Function getTypes(ByVal sequence As String, ByVal line As String, ByVal model As String) As List(Of String)
        Dim revList As New List(Of String)
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "SELECT DISTINCT KSQPCBSIDE FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] " & _
                  "WHERE KSACCOUNT = '" & sequence & "' " & _
                  "AND KSQLINE = '" & line & "' " & _
                  "AND KSQMODEL = '" & model & "' " & _
                  "ORDER BY KSQPCBSIDE"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            While reader.Read
                revList.Add(reader("KSQPCBSIDE"))
            End While
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return revList
    End Function

    Public Function getMachine(ByVal sequence As String, ByVal line As String, ByVal rev As String, ByVal model As String) As List(Of String)
        Dim revList As New List(Of String)
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "SELECT DISTINCT KSQMACHINE FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] " & _
                  "WHERE KSACCOUNT = '" & sequence & "' AND KSQREVISION = '" & rev & "' AND KSQMODEL = '" & model & "' " & _
                  "AND KSQLINE = '" & line & "' " & _
                  "ORDER BY KSQMACHINE"

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            While reader.Read
                revList.Add(reader("KSQMACHINE"))
            End While
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return revList
    End Function

    Public Function isVerified(ByVal account As String, ByVal line As String, ByVal model As String, ByVal type As String, ByVal revision As String) As Boolean
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "SELECT KSQSTATUS FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] " & _
                  "WHERE KSACCOUNT = '" & account & "' " & _
                  "AND KSQLINE = " & line & " " & _
                  "AND KSQMODEL = '" & model & "' " & _
                  "AND KSQPCBSIDE = '" & type & "' " & _
                  "AND KSQREVISION = '" & revision & "' "

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            reader.Read()
            If reader("KSQSTATUS") = 1 Then
                isVerified = True
            Else
                isVerified = False
            End If
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Verification Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
    End Function

    Public Function getSequenceNo(ByVal account As String, ByVal line As String, ByVal model As String, ByVal type As String, ByVal revision As String)
        Dim conn As New SqlConnection(cnstr)
        Dim kseq As String = ""
        Dim myQuery As String
        myQuery = "SELECT KSEQUENCENO FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] " & _
                  "WHERE KSACCOUNT = '" & account & "' " & _
                  "AND KSQLINE = " & line & " " & _
                  "AND KSQMODEL = '" & model & "' " & _
                  "AND KSQPCBSIDE = '" & type & "' " & _
                  "AND KSQREVISION = '" & revision & "' "

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            If reader.HasRows Then
                reader.Read()
                kseq = reader("KSEQUENCENO")
            End If
            reader.Close()
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Sequence No Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try

        Return kseq
    End Function



    Public Function verificationDetails(ByVal sequence As String, ByVal line As String, ByVal model As String, ByVal type As String, ByVal rev As String) As List(Of String)
        Dim verDetails As New List(Of String)
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "SELECT * FROM  [Toshiba_kanban].[dbo].[KSEQUENCE_HEADER] " & _
                   "WHERE KSACCOUNT = '" & sequence & "' " & _
                  "AND KSQLINE = " & line & " " & _
                  "AND KSQMODEL = '" & model & "' " & _
                  "AND KSQPCBSIDE = '" & type & "' " & _
                  "AND KSQREVISION = '" & rev & "' "

        Dim mycommand As SqlCommand
        mycommand = New SqlCommand(myQuery, conn)

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            While reader.Read
                verDetails.Add(reader("KSQCHECKBY"))
                verDetails.Add(reader("KSQCHKDATE"))
            End While
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Verification Detail Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            conn.Close()
        End Try
        Return verDetails
    End Function
#End Region
End Class
