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


Public Class verifypn
    Dim proceed As Boolean = False
    Dim conn As SqlConnection
    Dim cmd As SqlCommand
 
    Private Sub txtsecret_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles txtsecret.KeyDown
        If e.KeyCode = Keys.Enter Then

            Dim Partno1() As Char = txtsecret.Text
            Dim parts = New PartsRecords(txtsecret.Text)
            Dim go As Boolean = False
            Dim mcode = New makerCode

            txtshow.Text = txtsecret.Text

            If (txtsecret.Text.Contains("GDM")) Then
                txtsecret.Text = (Trim(txtsecret.Text).Substring(Trim(txtsecret.Text).IndexOf("GDM"), 12))
                If (Trim(txtsecret.Text).Substring(Trim(txtsecret.Text).IndexOf("GDM"), 12) = txtpn.Text.Trim) Then

                    If Partno1(3) = "4" And Partno1(4) = "6" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    ElseIf Partno1(3) = "4" And Partno1(4) = "7" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    ElseIf Partno1(3) = "1" And Partno1(4) = "0" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    Else
                        If issuanceForm.cmbLine.Text.ToString() = "7" Or issuanceForm.cmbLine.Text.ToString() = "9" Or issuanceForm.cmbLine.Text.ToString() = "10" Or issuanceForm.cmbLine.Text.ToString() = "11" Or issuanceForm.cmbLine.Text.ToString() = "12" Or issuanceForm.cmbLine.Text.ToString() = "13" Then

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

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

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

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

                                Dim Result As String
                                Dim proceed As Boolean = False
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    issuanceForm.txtSerial.Focus()
                                    Me.Close()
                                End If

                            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 = issuanceForm.txtDesc.Text
                                Description = Description.Trim()

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

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

                                Dim Result As String
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    Me.Close()
                                    issuanceForm.txtSerial.Focus()
                                End If

                            End If

                        Else
                            'MsgBox(issuanceForm.txtSerial.Text)
                            'MsgBox(issuanceForm.txtPN.Text)
                            'MsgBox(DateTime.Parse(issuanceForm.lblPDate.Text))
                            'MsgBox(loginForm.username, , )
                            'MsgBox(issuanceForm.cmbLine.Text.ToString)
                            'MsgBox(issuanceForm.cmbRev.Text.ToString)
                            'MsgBox(issuanceForm.txtOperator.Text)
                            If Not parts.issue(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.Text.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.txtOperator.Text) Then
                                Dim Result As String
                                Dim proceed As Boolean = False
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    Me.Close()
                                    issuanceForm.txtSerial.Focus()
                                End If

                                'If proceed = False Then
                                '    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                '    MessageBox.Show("Parts Successfully Issued.", "Success")
                                '    issuanceForm.reset()
                                '    Me.Close()
                                '    issuanceForm.txtSerial.Focus()
                                'End If
                            End If
                        End If
                    End If
                Else
                    NotificationForm.text = "Part Number Mismatch"
                    NotificationForm.ShowDialog()
                    txtsecret.Text = ""
                    txtsecret.Focus()
                End If
            ElseIf (txtsecret.Text.Contains("G5B")) Then
                txtsecret.Text = (Trim(txtsecret.Text).Substring(Trim(txtsecret.Text).IndexOf("G5B"), 12))
                If (Trim(txtsecret.Text).Substring(Trim(txtsecret.Text).IndexOf("G5B"), 12) = txtpn.Text.Trim) Then

                    '  If checkMC(parts.ToshibaPN) = True Then
                    If Partno1(3) = "4" And Partno1(4) = "6" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    ElseIf Partno1(3) = "4" And Partno1(4) = "7" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    ElseIf Partno1(3) = "1" And Partno1(4) = "0" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    Else
                        If issuanceForm.cmbLine.Text.ToString() = "7" Or issuanceForm.cmbLine.Text.ToString() = "9" Or issuanceForm.cmbLine.Text.ToString() = "10" Or issuanceForm.cmbLine.Text.ToString() = "11" Or issuanceForm.cmbLine.Text.ToString() = "12" Or issuanceForm.cmbLine.Text.ToString() = "13" Then

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

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

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

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

                                Dim Result As String
                                Dim proceed As Boolean = False
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    Me.Close()
                                    issuanceForm.txtSerial.Focus()
                                End If

                            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 = issuanceForm.txtDesc.Text
                                Description = Description.Trim()

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

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

                                Dim Result As String
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    Me.Close()
                                    issuanceForm.txtSerial.Focus()
                                End If

                            End If

                        Else
                            If Not parts.issue(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.Text.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.txtOperator.Text) Then
                                Dim Result As String
                                Dim proceed As Boolean = False
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    Me.Close()
                                    issuanceForm.txtSerial.Focus()
                                End If

                                'If proceed = False Then
                                '    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                '    MessageBox.Show("Parts Successfully Issued.", "Success")
                                '    issuanceForm.reset()
                                '    Me.Close()
                                '    issuanceForm.txtSerial.Focus()
                                'End If
                            End If
                        End If
                    End If
                Else

                    NotificationForm.text = "Part Number Mismatch"
                    NotificationForm.ShowDialog()
                    txtsecret.Text = ""
                    txtsecret.Focus()
                End If
            ElseIf (txtsecret.Text.Contains("G5D")) Then
                txtsecret.Text = (Trim(txtsecret.Text).Substring(Trim(txtsecret.Text).IndexOf("G5D"), 12))
                If (Trim(txtsecret.Text).Substring(Trim(txtsecret.Text).IndexOf("G5D"), 12) = txtpn.Text.Trim) Then

                    ' If checkMC(parts.ToshibaPN) = True Then
                    If Partno1(3) = "4" And Partno1(4) = "6" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    ElseIf Partno1(3) = "4" And Partno1(4) = "7" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    ElseIf Partno1(3) = "1" And Partno1(4) = "0" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    Else
                        If issuanceForm.cmbLine.Text.ToString() = "7" Or issuanceForm.cmbLine.Text.ToString() = "9" Or issuanceForm.cmbLine.Text.ToString() = "10" Or issuanceForm.cmbLine.Text.ToString() = "11" Or issuanceForm.cmbLine.Text.ToString() = "12" Or issuanceForm.cmbLine.Text.ToString() = "13" Then

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

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

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

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

                                Dim Result As String
                                Dim proceed As Boolean = False
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    Me.Close()
                                    issuanceForm.txtSerial.Focus()
                                End If

                            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 = issuanceForm.txtDesc.Text
                                Description = Description.Trim()

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

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

                                Dim Result As String
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    Me.Close()
                                    issuanceForm.txtSerial.Focus()
                                End If

                            End If

                        Else
                            If Not parts.issue(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.txtOperator.Text) Then
                                Dim Result As String
                                Dim proceed As Boolean = False
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    Me.Close()
                                    issuanceForm.txtSerial.Focus()
                                End If

                                'If proceed = False Then
                                '    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                '    MessageBox.Show("Parts Successfully Issued.", "Success")
                                '    issuanceForm.reset()
                                '    Me.Close()
                                '    issuanceForm.txtSerial.Focus()
                                'End If
                            End If
                        End If
                    End If

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


            Else
                txtsecret.Text = Trim(txtsecret.Text).Substring(0, 12)
                If (Trim(txtsecret.Text) = txtpn.Text.Trim) Then

                    If Partno1(3) = "4" And Partno1(4) = "6" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    ElseIf Partno1(3) = "4" And Partno1(4) = "7" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    ElseIf Partno1(3) = "1" And Partno1(4) = "0" And issuanceForm.txtFamily.Text = "Enterprise" Then
                        verifymc.Show()
                        Me.Hide()
                    Else
                        If issuanceForm.cmbLine.Text.ToString() = "7" Or issuanceForm.cmbLine.Text.ToString() = "9" Or issuanceForm.cmbLine.Text.ToString() = "10" Or issuanceForm.cmbLine.Text.ToString() = "11" Or issuanceForm.cmbLine.Text.ToString() = "12" Or issuanceForm.cmbLine.Text.ToString() = "13" Then

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

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

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

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

                                Dim Result As String
                                Dim proceed As Boolean = False
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    issuanceForm.txtSerial.Focus()
                                    Me.Close()
                                End If

                            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 = issuanceForm.txtDesc.Text
                                Description = Description.Trim()

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

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

                                Dim Result As String
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    issuanceForm.txtSerial.Focus()
                                    Me.Close()
                                End If

                            End If

                        Else
                            If Not parts.issue(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.Text.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.txtOperator.Text) Then
                                Dim Result As String
                                Dim proceed As Boolean = False
                                'parts.checkFifo(txtSerial.Text, txtPN.Text)
                                Result = parts.checkFifo(issuanceForm.txtSerial.Text, issuanceForm.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.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                                        fifoverify.Show()
                                    End If
                                Else
                                    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                    MessageBox.Show("Parts Successfully Issued.", "Success")
                                    issuanceForm.reset()
                                    Me.Close()
                                    issuanceForm.txtSerial.Focus()
                                End If

                                'If proceed = False Then


                                '    parts.issue2(issuanceForm.txtSerial.Text, issuanceForm.txtPN.Text, DateTime.Parse(issuanceForm.lblPDate.Text), loginForm.username, issuanceForm.cmbLine.SelectedItem.ToString, issuanceForm.cmbRev.Text.ToString, issuanceForm.cbopetname.Text.ToString, issuanceForm.txtOperator.Text)
                                '    MessageBox.Show("Parts Successfully Issued.", "Success")
                                '    issuanceForm.reset()
                                '    Me.Close()
                                '    issuanceForm.txtSerial.Focus()
                                'End If
                            End If
                        End If
                    End If

                Else
                    NotificationForm.text = "Part Number Mismatch"
                    NotificationForm.ShowDialog()
                    txtsecret.Text = ""
                    txtsecret.Focus()
                End If
            End If
        End If
    End Sub

    Private Sub verifypn_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        txtsecret.Focus()
    End Sub

 

End Class