Imports System.IO
Imports System.Text.RegularExpressions
Imports System.Text
Imports System.Data.SqlClient

Public Class issuanceFormMobile
    Private isUpdate = False
    Dim family As String
    Dim pass As Boolean = False
    Dim proceed As Boolean = False
    Dim conn As SqlConnection
    Dim cmd As SqlCommand
    Dim reader As SqlDataReader
    Dim conn2 As SqlConnection
    Dim cmd2 As SqlCommand
    Dim reader2 As SqlDataReader

    Private Property cbopetname As Object


    Private Sub txtSerial_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSerial.KeyPress
        Dim proceed As Boolean = False
        If Asc(e.KeyChar) = 13 Then

            If Not txtSerial.Text.StartsWith("LA") Then
                txtSerial.Text = txtSerial.Text.Substring(0, 10)
            End If

            Dim parts = New PartsRecords(txtSerial.Text)
            If parts.Exist Then
                txtPN.Text = parts.IonicsPN
                txtDesc.Text = parts.Description
                txtLot.Text = parts.LotNo
                txtBox.Text = parts.Rack
                txtQuantity.Text = parts.Quantity
                SupplierTextBox.Text = parts.SupplierPN
                lblStatus.Text = parts.Status
                lblMFGDate.Text = parts.MFGDate
                lblRCVDate.Text = parts.RCVDate
                lblPDate.Text = parts.PrintedDate
                lblBy.Text = parts.PrintedBy
                txtFamily.Text = parts.Family
                txtMC.Text = parts.MakerCode


                If txtPN.Text = "M705PCIS4000" Or txtPN.Text = "GY4CS000P110" Then

                    Dim cnstr = mainForm.cnstr
                    Dim conn As New SqlConnection(cnstr)
                    Dim myQuery As String
                    myQuery = "SELECT * FROM [Toshiba_kanban].[dbo].[PartsLog] WHERE MaterialID = '" & txtSerial.Text & "' and Status = 'Issued' order by lastupdated asc"

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

                    Try
                        conn.Open()
                        Dim reader As SqlDataReader = mycommand.ExecuteReader()
                        reader.Read()
                        Dim NextTime As Date
                        NextTime = NextTime.AddDays(3)
                        spdid.Text = reader("MaterialID")
                        splotno.Text = reader("LotNo")
                        lbldo.Text = reader("lastupdated")
                        conn.Close()
                        spdate = lbldo.Text
                        lbled.Text = spdate.AddDays(3)

                        If lbled.Text <= Date.Now Then
                            proceed = True
                            NotificationForm.text = "72 HOURS EXPIRED SOLDER PASTE"
                            NotificationForm.ShowDialog()
                            btnReset.Enabled = True

                        Else
                            proceed = False
                        End If
                    Catch ex As Exception
                        'MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    End Try
                    conn.Close()


                ElseIf txtPN.Text = "M705PCIS4000" Or txtPN.Text = "GY4CS000P110" And lblStatus.Text = "SMT" Then

                    Dim cnstr = mainForm.cnstr
                    Dim conn As New SqlConnection(cnstr)
                    Dim myQuery As String
                    myQuery = "SELECT * FROM [Toshiba_kanban].[dbo].[PartsLog] WHERE MaterialID = '" & txtSerial.Text & "' and Status = 'Mounted' order by lastupdated asc"

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

                    Try
                        conn.Open()
                        Dim reader As SqlDataReader = mycommand.ExecuteReader()
                        reader.Read()
                        Dim NextTime As Date
                        NextTime = NextTime.AddDays(2)
                        spdid.Text = reader("MaterialID")
                        splotno.Text = reader("LotNo")
                        lbldo.Text = reader("lastupdated")
                        conn.Close()
                        spdate = lbldo.Text
                        lbled.Text = spdate.AddDays(2)

                        If lbled.Text <= Date.Now Then
                            proceed = True
                            NotificationForm.text = "48 HOURS EXPIRED SOLDER PASTE"
                            NotificationForm.ShowDialog()
                            btnReset.Enabled = True

                        Else
                            proceed = False
                        End If
                    Catch ex As Exception
                        'MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    End Try
                    conn.Close()
                Else
                    proceed = False

                End If


                If (proceed = False) Then
                    Dim remarks() = parts.Remarks.Split("-")
                    cmbStatus.SelectedItem = parts.Status
                    enable(parts)

                    If remarks.Length = 3 Then
                        cmbLine.Text = remarks(0)
                        cmbRev.Text = remarks(1)
                        txtOperator.Text = remarks(2)
                    End If

                    If parts.Status <> "WHS" And parts.Status <> "SMT" And parts.Status <> "INV" And parts.Status <> "INV-PDN" And parts.Status <> "INV-SMT" Then
                        btnIssue.Enabled = False
                        If loginForm.userType <> "Administrator" And loginForm.userType <> "Super Administrator" Then
                            btnUpdate.Enabled = False
                        End If
                    ElseIf parts.Status = "RTN" Or parts.Status = "SCR" Then
                        btnIssue.Enabled = False
                    End If

                    If parts.Remarks <> "" Then
                        txtRemarks.Text = parts.Remarks
                    Else
                        txtRemarks.Text = "N/A"
                    End If

                Else
                    MessageBox.Show("Item not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            End If
        End If
    End Sub

    Public Sub enable(ByVal parts As PartsRecords)
        btnIssue.Enabled = True
        btnReset.Enabled = True
        btnUpdate.Enabled = True
        cmbLine.Enabled = True
        ' cmbRev.Enabled = True
        txtOperator.ReadOnly = False

    End Sub

    Public Sub reset()
        txtSerial.Text = Nothing
        txtPN.Text = Nothing
        txtDesc.Text = Nothing
        txtLot.Text = Nothing
        txtBox.Text = Nothing
        txtQuantity.Text = Nothing
        SupplierTextBox.Text = Nothing
        txtRemarks.ReadOnly = True
        txtRemarks.Text = Nothing
        txtRemarks.Visible = False
        lblRemarks.Visible = False
        lblLine.Visible = True
        cmbLine.Visible = True
        cmbLine.Text = Nothing
        cmbLine.Enabled = False
        lblRev.Visible = True
        cmbRev.Visible = True
        cmbRev.Text = Nothing
        cmbRev.Enabled = False
        lblOperator.Visible = True
        txtOperator.Visible = True
        txtOperator.Text = Nothing
        txtOperator.ReadOnly = True
        cmbStatus.SelectedText = Nothing
        cmbStatus.Text = Nothing
        cmbStatus.Enabled = False
        lblStatus.Text = Nothing
        lblMFGDate.Text = Nothing
        lblRCVDate.Text = Nothing
        lblPDate.Text = Nothing
        lblBy.Text = Nothing
        lblupdateddate.Text = Nothing
        lblupdatedby.Text = Nothing
        btnIssue.Enabled = False
        btnReset.Enabled = False
        isUpdate = False
        btnUpdate.Text = "Update"
        btnUpdate.Enabled = False
        txtFamily.Text = Nothing
        lblFam.Text = Nothing
        txtMC.Text = Nothing
        dgPN.Rows.Clear()
        spdid.Text = Nothing
        splotno.Text = Nothing
        lbldo.Text = Nothing
        lbled.Text = Nothing
    End Sub

    Public Sub updatemode()
        txtRemarks.ReadOnly = False
        cmbStatus.Enabled = True
        btnUpdate.Text = "Save"
        btnIssue.Enabled = False
        isUpdate = True
    End Sub

    Private Sub issuanceForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = mainForm
        Control.CheckForIllegalCrossThreadCalls = False

        Dim p = New PartsRecords()
        Dim items = p.getAllModel()

        For Each i As String In items
            cmbRev.Items.Add(i)
        Next

        btnUpdate.Visible = True
        txtSerial.Focus()
    End Sub

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        reset()
        txtSerial.Focus()
    End Sub

    Private Function checkMC(ByVal mc As System.Object)
        Dim go As Boolean = False

        Dim cnstr = mainForm.cnstr
        Dim conn As New SqlConnection(cnstr)
        Dim myQuery As String
        myQuery = "SELECT * From makerCode where Ionics_PN = '" & txtPN.Text & "' and Description like '%" & txtDesc.Text & "%'"

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

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            If reader.HasRows Then
                reader.Read()
                go = True

            Else
                go = False

            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

        conn.Close()

        Return go

    End Function

    Private Sub btnIssue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIssue.Click



        If txtPN.Text = "A3GDM4600031470" And (Trim(txtDesc.Text)) = "SOC" And txtMC.Text = "NA" Then
            MsgBox("Invalid maker code!")
        ElseIf txtPN.Text = "A3GDM4600031630" And (Trim(txtDesc.Text)) = "1G(8MX16X8BANKS)BIT SDRAM" And txtMC.Text = "NA" Then
            MsgBox("Invalid maker code!")
        ElseIf txtPN.Text = "A3GDM4600031780" And (Trim(txtDesc.Text)) = "8MBIT FLASH MEMORY" And txtMC.Text = "NA" Then
            MsgBox("Invalid maker code!")
        ElseIf txtPN.Text = "A3GDM4600037620" And (Trim(txtDesc.Text)) = "MOTOR DRIVER" And txtMC.Text = "NA" Then
            MsgBox("Invalid maker code!")
        ElseIf txtPN.Text = "A3GDM4600032380" And (Trim(txtDesc.Text)) = "8M(1024KX8)BIT FLASH MEMORY" And txtMC.Text = "NA" Then
            MsgBox("Invalid maker code!")
        ElseIf txtPN.Text = "A3GDM1000004020" And (Trim(txtDesc.Text)) = "CHIP CRYSTAL RESONATOR" And txtMC.Text = "NA" Then
            MsgBox("Invalid maker code!")

        Else

            Dim i As Integer = 0
            Dim found As Boolean = False

            While i < dgPN.Rows.Count - 1
                If cmbLine.SelectedItem.ToString = "7" Or cmbLine.SelectedItem.ToString = "9" Then
                    found = True

                ElseIf (dgPN.Rows(i).Cells(0).Value = txtPN.Text) Then

                    found = True
                    Exit While
                Else

                    found = False

                End If


                i = i + 1
            End While


            If found = True Then

                Dim cnstr = mainForm.cnstr
                Dim conn As New SqlConnection(cnstr)
                Dim myQuery As String
                myQuery = "SELECT * FROM [Toshiba_cats].[dbo].[model] WHERE minRev like '%" & cmbRev.Text.Trim & "%' AND modelDesc1 like '%" & cbopetname.Text.Trim & "%'"

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

                Try
                    conn.Open()
                    Dim reader As SqlDataReader = mycommand.ExecuteReader()
                    reader.Read()
                    lblFam.Text = reader("modelFamily")
                    conn.Close()

                    If txtFamily.Text = lblFam.Text Then
                        pass = True
                    Else
                        MessageBox.Show("mobile DID is not for: " + lblFam.Text, "Error!")
                        pass = False
                    End If
                Catch ex As Exception
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try

                Dim parts = New PartsRecords(txtSerial.Text)
                Dim success As Boolean = False
                Dim success2 As Boolean = False
                Dim val As String
                Dim maker As String
                Dim mcode = New makerCode

                If pass = True Then


                    parts.Remarks = cmbLine.SelectedItem.ToString & "-" & cmbRev.Text.ToString & "-" & txtOperator.Text

                    If (parts.checkThreshold(txtPN.Text, cmbLine.SelectedItem.ToString)) Then


                        Do
                            val = InputBox("Enter part number : ", "Message", "")
                            If (val.Contains("GDM")) Then
                                val = (Trim(val).Substring(Trim(val).IndexOf("GDM"), 12))
                                If (Trim(val).Substring(Trim(val).IndexOf("GDM"), 12) = Trim(parts.ToshibaPN)) Then

                                    If checkMC(parts.ToshibaPN) = True Then
                                        success2 = True
                                    Else
                                        success = True
                                    End If
                                Else
                                    NotificationForm.text = "Part Number Mismatch"
                                    NotificationForm.ShowDialog()
                                End If
                            ElseIf (val.Contains("G5B")) Then
                                val = (Trim(val).Substring(Trim(val).IndexOf("G5B"), 12))
                                If (Trim(val).Substring(Trim(val).IndexOf("G5B"), 12) = Trim(parts.ToshibaPN)) Then

                                    If checkMC(parts.ToshibaPN) = True Then
                                        success2 = True
                                    Else
                                        success = True
                                    End If

                                Else
                                    NotificationForm.text = "Part Number Mismatch"
                                    NotificationForm.ShowDialog()
                                End If
                            ElseIf (val.Contains("G5D")) Then
                                val = (Trim(val).Substring(Trim(val).IndexOf("G5D"), 12))
                                If (Trim(val).Substring(Trim(val).IndexOf("G5D"), 12) = Trim(parts.ToshibaPN)) Then

                                    If checkMC(parts.ToshibaPN) = True Then
                                        success2 = True
                                    Else
                                        success = True
                                    End If

                                Else
                                    NotificationForm.text = "Part Number Mismatch"
                                    NotificationForm.ShowDialog()
                                End If


                            Else
                                val = Trim(val).Substring(0, 12)
                                If (Trim(val) = Trim(parts.ToshibaPN)) Then

                                    If checkMC(parts.ToshibaPN) = True Then
                                        success2 = True
                                    Else
                                        success = True
                                    End If

                                Else
                                    NotificationForm.text = "Part Number Mismatch"
                                    NotificationForm.ShowDialog()
                                End If
                            End If
                        Loop While (val <> Trim(parts.ToshibaPN)) And (val <> "")

                        If success2 Then

                            ' Do
                            maker = InputBox("Enter maker code : ", "Message", "")
                            Dim trymaker As String
                            trymaker = mcode.getmakercode(txtPN.Text, txtMC.Text).ToString
                            If (mcode.getmakercode(txtPN.Text, txtMC.Text).ToString = Trim(parts.MakerCode)) Then
                                success = True

                                'conn = New SqlConnection("data source=192.168.1.41;initial catalog=Toshiba2;Integrated Security=True")
                                'conn.Open()

                                'Dim makercode As New makerCode
                                'Dim makername As String
                                'makername = makercode.getmakercode(txtPN.Text, txtMC.Text)

                                'Dim makercode As New makerCode
                                'Dim makername As String

                                'makername = makercode.getmakercode(txtPN.Text, txtMC.Text)

                            Else
                                NotificationForm.text = "Maker Code Mismatch"
                                NotificationForm.ShowDialog()
                                reset()
                                txtSerial.Focus()



                            End If

                            ' Loop While (maker <> Trim(parts.MakerCode)) And (maker <> "")

                        End If

                        If success Then


                            If cmbLine.SelectedItem.ToString = "7" Or cmbLine.SelectedItem.ToString = "9" Then

                                Dim Partno() As Char = txtPN.Text
                                If Partno(0) = "M" Or Partno(0) = "G" Then

                                    Dim Description1 As String = txtDesc.Text
                                    Description1 = Description1.Trim()

                                    Dim csvFilePath1 As String = "\\192.168.1.54\Material ID-Toshiba\" & txtSerial.Text & ".csv"
                                    Dim outFile1 As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFilePath1, False, Encoding.ASCII)
                                    outFile1.WriteLine(txtSerial.Text + "," + txtPN.Text + "," + SupplierTextBox.Text + "," + txtLot.Text + "," + Description1 + "," + txtMC.Text + "," + " " + "," + " " + "," + " " + "," + txtQuantity.Text)
                                    outFile1.Close()

                                    Dim csvFilePath3 As String = "\\192.168.1.81\Shared\MaterialID\" & txtSerial.Text & ".csv"
                                    Dim outFile3 As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFilePath3, False, Encoding.ASCII)
                                    outFile3.WriteLine(txtSerial.Text + "," + txtPN.Text + "," + SupplierTextBox.Text + "," + txtLot.Text + "," + Description1 + "," + txtMC.Text + "," + " " + "," + " " + "," + " " + "," + txtQuantity.Text)
                                    outFile3.Close()

                                    parts.issue2(txtSerial.Text, txtPN.Text, DateTime.Parse(lblPDate.Text), loginForm.username, cmbLine.SelectedItem.ToString, cmbRev.Text.ToString, cbopetname.Text.ToString, txtOperator.Text)


                                Else

                                    Dim finalPN As String = Partno(2) + Partno(3) + Partno(4) + Partno(5) + Partno(6) + Partno(7) + Partno(8) + Partno(9) + Partno(10) + Partno(11) + Partno(12) + Partno(13)
                                    Dim Description As String = txtDesc.Text
                                    Description = Description.Trim()

                                    Dim csvFilePath As String = "\\192.168.1.54\Material ID-Toshiba\" & txtSerial.Text & ".csv"
                                    Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFilePath, False, Encoding.ASCII)
                                    outFile.WriteLine(txtSerial.Text + "," + finalPN + "," + SupplierTextBox.Text + "," + txtLot.Text + "," + Description + "," + txtMC.Text + "," + " " + "," + " " + "," + " " + "," + txtQuantity.Text)
                                    outFile.Close()

                                    Dim csvFilePath2 As String = "\\192.168.1.81\Shared\MaterialID\" & txtSerial.Text & ".csv"
                                    Dim outFile2 As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFilePath2, False, Encoding.ASCII)
                                    outFile2.WriteLine(txtSerial.Text + "," + finalPN + "," + SupplierTextBox.Text + "," + txtLot.Text + "," + Description + "," + txtMC.Text + "," + " " + "," + " " + "," + " " + "," + txtQuantity.Text)
                                    outFile2.Close()

                                    parts.issue2(txtSerial.Text, txtPN.Text, DateTime.Parse(lblPDate.Text), loginForm.username, cmbLine.SelectedItem.ToString, cmbRev.Text.ToString, cbopetname.Text.ToString, txtOperator.Text)

                                End If
                            End If

                            If Not parts.issue(txtSerial.Text, txtPN.Text, DateTime.Parse(lblPDate.Text), loginForm.username, cmbLine.SelectedItem.ToString, cmbRev.Text.ToString, txtOperator.Text) Then
                                Dim Result As String
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(txtSerial.Text, txtPN.Text)
                                If Result > 0 Then
                                    proceed = True
                                    If MessageBox.Show("There are older " & Result & " items are you sure you want to continue?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(txtSerial.Text, txtPN.Text, DateTime.Parse(lblPDate.Text), loginForm.username, cmbLine.SelectedItem.ToString, cmbRev.Text.ToString, cbopetname.Text.ToString, txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    reset()
                                    txtSerial.Focus()

                                    'If proceed = False Then
                                    '    parts.issue2(txtSerial.Text, txtPN.Text, DateTime.Parse(lblPDate.Text), loginForm.username, cmbLine.SelectedItem.ToString, cmbRev.Text.ToString, cbopetname.Text.ToString, txtOperator.Text)
                                    '    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    '    reset()
                                    '    txtSerial.Focus()
                                    'Else
                                    '    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    '    reset()
                                    '    txtSerial.Focus()
                                    'End If
                                End If
                            Else
                                MessageBox.Show("This part number is exceeding the allowed threshold per day or not exist on threshold maintenance. Please try again.")
                                reset()
                                txtSerial.Focus()
                            End If
                        End If
                        pass = False
                    End If
                Else

                    MessageBox.Show("MaterialID is not for: " + cmbRev.Text, "Error!")
                End If
            End If
        End If
    End Sub


    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        Dim parts As New PartsRecords(txtSerial.Text)
        If parts.Status = "INV" Or parts.Status = "INV-PDN" Or parts.Status = "INV-SMT" Then
            If parts.updateStatus(txtSerial.Text, "WHS", cmbLine.SelectedItem.ToString & "-" & cmbRev.Text.ToString & "-" & cbopetname.Text.ToString & "-" & txtOperator.Text) Then
                MessageBox.Show("Successfully Saved.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)

            End If

            reset()
        Else
            If isUpdate Then
                parts = New PartsRecords
                If cmbStatus.SelectedItem = "LST" And (txtRemarks.Text = "N/A" Or txtRemarks.Text = "") Then
                    MessageBox.Show("Please provide proper remarks.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

                Else
                    If parts.updateStatus(txtSerial.Text, cmbStatus.SelectedItem, cmbLine.SelectedItem.ToString & "-" & cmbRev.Text.ToString & "-" & cbopetname.Text.ToString & "-" & txtOperator.Text) Then
                        MessageBox.Show("Successfully Saved.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)

                    End If
                    reset()

                End If
            Else
                updatemode()
            End If

        End If
    End Sub

    Private Sub cmbRev_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbRev.SelectedIndexChanged

        'Try

        '    conn2 = New SqlConnection("data source=192.168.1.41;initial catalog=Toshiba2;Integrated Security=True")
        '    conn2.Open()

        '    cmd2 = New SqlCommand("SELECT * From model where minRev = '" & cmbRev.Text & "'", conn2)
        '    reader2 = cmd.ExecuteReader()
        '    If reader2.HasRows Then
        '        reader2.Read()
        '        lblFam.Text = reader("modelFamily")
        '    Else
        '        MsgBox("Model not yet enrolled!")
        '    End If

        'Catch ex As Exception

        'End Try
        'conn2.Close()

        Dim cnstr = mainForm.cnstr
        Dim conn As New SqlConnection(cnstr)
        Dim myQuery As String
        myQuery = "SELECT * FROM model WHERE minRev like '%" & cmbRev.Text & "%'" 'here

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

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            reader.Read()
            lblFam.Text = reader("modelFamily")
            conn.Close()

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


        txtOperator.Focus()

        'If cmbRev.Text = "11A0" Or cmbRev.Text = "04A0" Or cmbRev.Text = "12A0" Or cmbRev.Text = "42A0" Or cmbRev.Text = "05A0" Or cmbRev.Text = "56A0" Or cmbRev.Text = "65A0" Or cmbRev.Text = "66A0" Or cmbRev.Text = "13C0" Or cmbRev.Text = "65B0" Or cmbRev.Text = "05B0" Then
        '    lblFam.Text = "Mobile"

        'ElseIf cmbRev.Text = "FKU30B 12A0" Or cmbRev.Text = "FKR1KD 18E0" Or cmbRev.Text = "FKR1KD 19C0" Or cmbRev.Text = "FKR1WD 02D0" Or cmbRev.Text = "FKU2SD 11F0" Or cmbRev.Text = "FKU2UC 11F0" Or cmbRev.Text = "FKR1XC 03G0" Or cmbRev.Text = "FKR1TD 03G0" Or cmbRev.Text = "FKU32F 02F0" Or cmbRev.Text = "FKR24E 20C0" Or cmbRev.Text = "FKR39C 20C0" Or cmbRev.Text = "FKR39C 21C0" Or cmbRev.Text = "FKR39C" Or cmbRev.Text = "FKR24E" Or cmbRev.Text = "21C0" Or cmbRev.Text = "20C0" Or cmbRev.Text = "FKR1KD" Or cmbRev.Text = "19C0" Then
        '    lblFam.Text = "Enterprise"

        'End If

        'If txtPN.Text = "M705PCIS4000" And txtPN.Text = "A3G5B0043220000" Then
        '    lblFam.Text = txtFamily.Text
        'End If

    End Sub

    Private Sub cmbLine_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbLine.SelectedIndexChanged
        If cmbLine.Text <> Nothing Then
            dgPN.Rows.Clear()
            cmbRev.Text = New Mounting().getSettings(cmbLine.SelectedItem.ToString)
            getSeq.Text = New Mounting().getKseq(cmbLine.SelectedItem.ToString)
            Dim arrayseq() = New Mounting().getSequencePN(cmbLine.SelectedItem.ToString)
            Try

                For x = 0 To arrayseq.Length - 1
                    If (arrayseq(x) <> "") Then
                        dgPN.Rows.Add(arrayseq(x))
                    End If
                Next
            Catch ex As Exception

            End Try

        End If


        'If cmbRev.Text = "11A0" Or cmbRev.Text = "04A0" Or cmbRev.Text = "12A0" Or cmbRev.Text = "42A0" Or cmbRev.Text = "05A0" Or cmbRev.Text = "56A0" Or cmbRev.Text = "65A0" Or cmbRev.Text = "66A0" Or cmbRev.Text = "13C0" Or cmbRev.Text = "65B0" Or cmbRev.Text = "05B0" Or cmbRev.Text = "13D0" Then
        '    lblFam.Text = "Mobile"
        'ElseIf cmbRev.Text = "FKU30B 11A0" Or cmbRev.Text = "FKR1KD 18E0" Or cmbRev.Text = "FKR1KD 19C0" Or cmbRev.Text = "FKR1WD 02D0" Or cmbRev.Text = "FKU2SD 11F0" Or cmbRev.Text = "FKU2UC 11F0" Or cmbRev.Text = "FKR1XC 03G0" Or cmbRev.Text = "FKR1TD 03G0" Or cmbRev.Text = "FKU32F 02F0" Or cmbRev.Text = "FKR24E 20C0" Or cmbRev.Text = "FKR39C 20C0" Or cmbRev.Text = "FKR39C 21C0" Or cmbRev.Text = "FKR39C" Or cmbRev.Text = "FKR24E" Or cmbRev.Text = "21C0" Or cmbRev.Text = "20C0" Or cmbRev.Text = "FKR1KD" Or cmbRev.Text = "19C0" Then
        '    lblFam.Text = "Enterprise"
        'End If

        Dim cnstr = mainForm.cnstr
        Dim conn As New SqlConnection(cnstr)
        Dim myQuery As String
        myQuery = "SELECT * FROM [Toshiba_cats].[dbo].[model] WHERE minRev like '%" & cmbRev.Text & "%'"

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

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            reader.Read()
            lblFam.Text = reader("modelFamily")
            conn.Close()

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

        If txtPN.Text = "M705PCIS4000" Or txtPN.Text = "GY4CS000P110" Then
            txtFamily.Text = lblFam.Text
        End If

        updateDG()
    End Sub

    Private Sub getExpirationDate()

        Dim cnstr = mainForm.cnstr
        Dim conn As New SqlConnection(cnstr)

        Dim myQuery As String
        myQuery = "SELECT * FROM [Toshiba_kanban].[dbo].[PartsLog] WHERE IonicsPN = 'M705PCIS4000' or IonicsPN = 'GY4CS000P110'  AND  line = '" & cmbLine.Text & "' AND Status  = 'Issued' ORDER BY lastupdated DESC"

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

        Try
            conn.Open()
            Dim reader As SqlDataReader = mycommand.ExecuteReader()
            reader.Read()
            Dim NextTime As Date
            NextTime = NextTime.AddDays(4)
            spdid.Text = reader("MaterialID")
            splotno.Text = reader("LotNo")
            lbldo.Text = reader("lastupdated")
            conn.Close()

            spdate = lbldo.Text
            lbled.Text = spdate.AddDays(3)

            If txtPN.Text = "M705PCIS4000" Or txtPN.Text = "GY4CS000P110" And lbled.Text <= Date.Now Then
                NotificationForm.text = "EXPIRED SOLDER PASTE"
                NotificationForm.ShowDialog()
            End If


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


    End Sub

    Private Sub updateDG()

        Dim i As Integer = 0

        While i < dgPN.Rows.Count - 1

            If (dgPN.Rows(i).Cells(0).Value <> "") Then

                If (dgPN.Rows(i).Cells(0).Value = txtPN.Text) Then
                    dgPN.Rows(i).Cells(0).Style.BackColor = Color.Green

                    dgPN.CurrentCell = dgPN(0, i)

                Else
                    dgPN.Rows(i).Cells(0).Style.BackColor = Color.White
                End If
            End If


            i = i + 1
        End While
    End Sub



  
End Class