﻿Imports System
Imports System.Linq
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports Bt
Imports Bt.ScanLib
'Imports KDPP5000.BtScanLib
Imports BTClientLib
Imports System.IO
Imports System.Reflection
Imports BtScan2

Public Class frm5060
    Inherits System.Windows.Forms.Form
    Private btScanLib As BtScanLib
    Private scanHandler As Boolean = False
    'Private dbClient As BtrieveDbClient
    Private tmpStr As List(Of Dictionary(Of String, String))
    Private affected_rows As Integer

#Region " Windows tH[€ fUCiลถฌณ๊ฝR[h "

    Public Sub New()
        MyBase.New()

        ' ฑฬฤัoตอ Windows tH[€ fUCiล•K—vลทB
        InitializeComponent()

        ' InitializeComponent() ฤัoตฬใษ๚ป๐’วมตทB

    End Sub

    ' Form อAR“|[l“g๊——ษใ—๐ภsท้ฝ฿ษ dispose ๐I[o[ChตทB
    'Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    '    If disposing Then
    '        If Not (components Is Nothing) Then
    '            components.Dispose()
    '        End If
    '    End If
    '    MyBase.Dispose(disposing)
    'End Sub

    ' Windows tH[€ fUCiล•K—vลทB
    'Private components As System.ComponentModel.IContainer

    '  : ศบฬvV[WอAWindows tH[€ fUCiล•K—vลทB
    'Windows tH[€ fUCi๐gมฤ•ฯXตฤญพณขB  
    ' R[h GfB^๐gมฤ•ฯXตศขลญพณขB
    'Friend WithEvents WarpFrame1 As WarpControl.WarpFrame
    'Friend WithEvents wfName As WarpControl.WarpField
    'Friend WithEvents WarpField1 As WarpControl.WarpField
    'Friend WithEvents WarpBox1 As WarpControl.WarpBox
    'Friend WithEvents WarpHWBcr1 As WarpControl.WarpHWBcr
    'Friend WithEvents wfKey As WarpControl.WarpField
    'Friend WithEvents wfPrtCnt As WarpControl.WarpField
    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame()
    '    Me.wfPrtCnt = New WarpControl.WarpField()
    '    Me.wfKey = New WarpControl.WarpField()
    '    Me.WarpBox1 = New WarpControl.WarpBox()
    '    Me.WarpField1 = New WarpControl.WarpField()
    '    Me.wfName = New WarpControl.WarpField()
    '    Me.WarpHWBcr1 = New WarpControl.WarpHWBcr()
    '    Me.WarpFrame1.SuspendLayout()
    '    Me.SuspendLayout()
    '    '
    '    'WarpFrame1
    '    '
    '    Me.WarpFrame1.Controls.Add(Me.wfPrtCnt)
    '    Me.WarpFrame1.Controls.Add(Me.wfKey)
    '    Me.WarpFrame1.Controls.Add(Me.WarpBox1)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField1)
    '    Me.WarpFrame1.Controls.Add(Me.wfName)
    '    Me.WarpFrame1.Font = New System.Drawing.Font("MS UI Gothic", 9.0!)
    '    Me.WarpFrame1.Location = New System.Drawing.Point(0, 0)
    '    Me.WarpFrame1.Name = "WarpFrame1"
    '    Me.WarpFrame1.Size = New System.Drawing.Size(240, 296)
    '    Me.WarpFrame1.TabIndex = 1
    '    Me.WarpFrame1.Text = "WarpFrame1"
    '    Me.WarpFrame1.UseMacro = False
    '    Me.WarpFrame1.UseMacroFileName = ""
    '    '
    '    'wfPrtCnt
    '    '
    '    Me.wfPrtCnt.DecimalPointPosition = CType(0, Short)
    '    Me.wfPrtCnt.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfPrtCnt.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfPrtCnt.Format = ""
    '    Me.wfPrtCnt.InputMode.NumericOnly = True
    '    Me.wfPrtCnt.InputMode.Right = True
    '    Me.wfPrtCnt.Length = CType(3, Short)
    '    Me.wfPrtCnt.Location = New System.Drawing.Point(186, 171)
    '    Me.wfPrtCnt.MacroBcr = ""
    '    Me.wfPrtCnt.MacroIn = ""
    '    Me.wfPrtCnt.MacroKey = ""
    '    Me.wfPrtCnt.MacroOut = ""
    '    Me.wfPrtCnt.Name = "wfPrtCnt"
    '    Me.wfPrtCnt.Size = New System.Drawing.Size(36, 24)
    '    Me.wfPrtCnt.TabIndex = CType(4, Short)
    '    Me.wfPrtCnt.Text = "0"
    '    '
    '    'wfKey
    '    '
    '    Me.wfKey.BcrFlag = True
    '    Me.wfKey.DecimalPointPosition = CType(0, Short)
    '    Me.wfKey.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfKey.Format = ""
    '    Me.wfKey.InputMode.Secret = True
    '    Me.wfKey.Length = CType(1, Short)
    '    Me.wfKey.Location = New System.Drawing.Point(156, 144)
    '    Me.wfKey.MacroBcr = ""
    '    Me.wfKey.MacroIn = ""
    '    Me.wfKey.MacroKey = ""
    '    Me.wfKey.MacroOut = ""
    '    Me.wfKey.Name = "wfKey"
    '    Me.wfKey.Size = New System.Drawing.Size(18, 36)
    '    Me.wfKey.TabIndex = CType(6, Short)
    '    '
    '    'WarpBox1
    '    '
    '    Me.WarpBox1.BoxType = WarpControl.BoxTypes.Box
    '    Me.WarpBox1.DrawMode = WarpControl.DrawModes.Paint
    '    Me.WarpBox1.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpBox1.ForeColor = CType(15, Short)
    '    Me.WarpBox1.Image = ""
    '    Me.WarpBox1.Location = New System.Drawing.Point(0, 36)
    '    Me.WarpBox1.Name = "WarpBox1"
    '    Me.WarpBox1.Size = New System.Drawing.Size(240, 96)
    '    Me.WarpBox1.TabIndex = 5
    '    '
    '    'WarpField1
    '    '
    '    Me.WarpField1.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField1.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField1.FontSize = WarpControl.FontSizes.Small2
    '    Me.WarpField1.Format = ""
    '    Me.WarpField1.Length = CType(9, Short)
    '    Me.WarpField1.Location = New System.Drawing.Point(12, 171)
    '    Me.WarpField1.MacroBcr = ""
    '    Me.WarpField1.MacroIn = ""
    '    Me.WarpField1.MacroKey = ""
    '    Me.WarpField1.MacroOut = ""
    '    Me.WarpField1.Name = "WarpField1"
    '    Me.WarpField1.Size = New System.Drawing.Size(108, 24)
    '    Me.WarpField1.TabIndex = CType(3, Short)
    '    Me.WarpField1.Text = "#ofLabels"
    '    '
    '    'wfName
    '    '
    '    Me.wfName.DecimalPointPosition = CType(0, Short)
    '    Me.wfName.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfName.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfName.Format = ""
    '    Me.wfName.Length = CType(20, Short)
    '    Me.wfName.Location = New System.Drawing.Point(0, 216)
    '    Me.wfName.MacroBcr = ""
    '    Me.wfName.MacroIn = ""
    '    Me.wfName.MacroKey = ""
    '    Me.wfName.MacroOut = ""
    '    Me.wfName.Name = "wfName"
    '    Me.wfName.Size = New System.Drawing.Size(240, 24)
    '    Me.wfName.TabIndex = CType(2, Short)
    '    '
    '    'WarpHWBcr1
    '    '
    '    Me.WarpHWBcr1.Decode.Code39 = True
    '    Me.WarpHWBcr1.DiscreteFirstLen = CType(0, Short)
    '    Me.WarpHWBcr1.DiscreteSecondLen = CType(0, Short)
    '    Me.WarpHWBcr1.InterleavedFirstLen = CType(0, Short)
    '    Me.WarpHWBcr1.InterleavedSecondLen = CType(0, Short)
    '    '
    '    'frm5060
    '    '
    '    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
    '    Me.ClientSize = New System.Drawing.Size(240, 296)
    '    Me.Controls.Add(Me.WarpFrame1)
    '    Me.Font = New System.Drawing.Font("MS UI Gothic", 9.0!)
    '    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
    '    Me.Name = "frm5060"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region


    Public Enum M5060_STATUS As Integer
        INIT = 0
        MENUBACK = 1
        NOTCD = 2
        DONE = 3
    End Enum

    Public mint5060status As Integer

    Private Sub frm5060_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Select Case e.KeyCode.ToString()
            Case "F1"
            Case "F2"
                gintStatus = TR_STATUS.QUIT
                Me.Close()
                Exit Sub
        End Select
    End Sub

    Private Sub frm5060_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        '// Case QVGA -> resolution to 1/2
        If System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width = 240 Then
            Call resolution.VGAtoQVGA(Me)
        End If

        Dim wstrImage As String
        Dim rtn As Integer

        Try
            mint5060status = M5060_STATUS.INIT
            't[€ฬI[v“
            'rtn = WarpFrame1.Open
            'If (rtn <> 0) Then
            '    Err.Raise(vbObjectError + 1, gAppName, "WarpError")
            'End If

            sDisp5060()

#If Not Debug Then
            'sSetImgFName(G_CONST_MID_H2050, WarpBox1)
#Else
            'WarpBox1.Text = "€”๕ชลซฝ็ENTL["
#End If
            ' tH[€EC“ ภs
            sMain()

            ' t[€ฬN[Y
            'rtn = WarpFrame1.Close()
            'If (rtn <> 0) Then
            '    Err.Raise(vbObjectError + 1, gAppName, "WarpError")
            'End If

            ' tH[€EN[Y
            'Me.Close()

            Exit Sub


        Catch ex As Exception
            gintStatus = TR_STATUS.QUIT
            sErrLog(gAppName, "frm5060_Load", ex.ToString)
            Me.Close()
            Exit Sub
        End Try

    End Sub
    '/*
    '|| ึ”–ผFsDisp5060
    '|| T—v  F5060ๆ–ส•\ฆ
    '*/
    Private Sub sDisp5060()

        'wfPrtCnt.Puts(gstrctPPDisp.intNumOfCase)
        'wfName.Puts(gstrctKDHT.strUserName)

        wfPrtCnt.Text = gstrctPPDisp.intNumOfCase
        wfName.Text = gstrctKDHT.strUserName

    End Sub

    Private Sub btScanLib_OnScan(ByVal result As String)
        Dim buf As String = result
        Dim rtn As Integer

        If (Not fCheckCode(buf)) Then
#If Not Debug Then
            sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
            fFnc_WrpMsg("E", G_CONST_MID_E5E85)
#End If
            Exit Sub
        End If

        '“—อ—
        rtn = fProcInput(RTrim(buf))

        If rtn = 0 Then
            Select Case mint5060status
                Case M5060_STATUS.INIT

                Case M5060_STATUS.NOTCD              'ูศ้o[R[h
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    sOutputLog(gstrctPicsIni.strOutput_KDPP, "KDPP5E85", G_CONST_BC_IP, buf)
#If Not Debug Then
                    fFnc_WrpMsg("E", G_CONST_MID_E5E85)
#End If
                    Exit Sub
                Case M5060_STATUS.DONE
                    rtn = fClearSKey()
                    If rtn <> 0 Then
                        'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, MWA_DB_WARNING, MWA_DB_OK)
                        'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
                        MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
                        RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                        btScanLib.Disable()
                        gintStatus = TR_STATUS.CLABEL
                        Me.Close()
                        Exit Sub
                    End If
                    'gstrctKDPP.intIndex = 0
                    rtn = fSearchPackCP()
                    Select Case rtn
                        Case -1
                            'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
                            MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                            gstrctKDPP.intIndex -= 1
                            Exit Sub
                        Case 0
                            Select Case fCheckDelivery()
                                Case 0 'fo[–ณต
                                    rtn = fCheckPackCP(gstrctKDPP.strItemGr)
                                    If rtn = 1 Then
                                        RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                                        btScanLib.Disable()
                                        gintStatus = TR_STATUS.PART
                                        Me.Close()
                                        Exit Sub
                                    ElseIf rtn = -1 Then
                                        'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
                                        MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                                        gstrctKDPP.intIndex -= 1
                                        Exit Sub
                                    Else '‘Sf[^xแ
                                        RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                                        btScanLib.Disable()
                                        gintStatus = TR_STATUS.PRINT4
                                        Me.Close()
                                        Exit Sub
                                    End If
                                Case 1 'fo[ ่
                                    rtn = fSearchPackCP4Delv()
                                    If rtn = -1 Then Exit Sub
                                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                                    btScanLib.Disable()
                                    gintStatus = TR_STATUS.PART2
                                    Me.Close()
                                    Exit Sub
                                Case Else
                                    'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
                                    MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                                    gstrctKDPP.intIndex -= 1
                                    Exit Sub
                            End Select
                        Case -2
                            fUpdatePackPlan()
                            'APXV—()
                            If gstrctKDHT.bLinkFlag Then
                                If fUpdateAP(gstrctKDPP.strItemGr) = -1 Then
                                    'รฐภXVG[
#If Not Debug Then
                                    fFnc_WrpMsg("E", G_CONST_MID_E2E94)
#End If
                                    Exit Sub
                                End If
                            End If
                            RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                            btScanLib.Disable()
                            gintStatus = TR_STATUS.CLABEL

                            Me.Close()
                            Exit Sub

                    End Select
            End Select
        Else

            'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, MWA_DB_WARNING, MWA_DB_OK)
            'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
            MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

        End If


    End Sub



    ' t[€EC“
    Public Sub sMain()

        '        Dim WKey As Short
        '        Dim buf As String
        '        Dim rtn As Integer

        '        Try

        '            ' t[€ฬ—๐ฑฑษLqตทB
        '            Do While (True)

        '                ' R[h“—อ
        '                WKey = WarpFrame1.Input(wfKey)
        '                If WKey = WKY_ENT Then


        '                ElseIf WKey = WKY_BCR Then

        '                    'สฐบฐฤ“—อฬๆ“พ
        '                    rtn = WarpHWBcr1.Get(buf)
        '                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.OK)
        '                    If (rtn <> 0) Then
        '                        Err.Raise(vbObjectError + 1, gAppName, "WarpError")
        '                    End If

        '                    'มชฏธรจผฏฤ
        '                    If (Not fCheckCode(buf)) Then
        '#If Not Debug Then
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                        fFnc_WrpMsg("E", G_CONST_MID_E5E85)
        '#End If
        '                        Exit Do
        '                    End If

        '                    '“—อ—
        '                    rtn = fProcInput(RTrim(buf))

        '                    If rtn = 0 Then
        '                        Select Case mint5060status
        '                            Case M5060_STATUS.INIT

        '                            Case M5060_STATUS.NOTCD              'ูศ้o[R[h
        '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                                sOutputLog(gstrctPicsIni.strOutput_KDPP, "KDPP5E85", G_CONST_BC_IP, buf)
        '#If Not Debug Then
        '                                fFnc_WrpMsg("E", G_CONST_MID_E5E85)
        '#End If
        '                            Case M5060_STATUS.DONE
        '                                rtn = fClearSKey()
        '                                If rtn <> 0 Then
        '                                    'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, MWA_DB_WARNING, MWA_DB_OK)
        '                                    f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
        '                                    gintStatus = TR_STATUS.CLABEL
        '                                    Exit Do
        '                                End If
        '                                'gstrctKDPP.intIndex = 0
        '                                rtn = fSearchPackCP()
        '                                Select Case rtn
        '                                    Case -1
        '                                        f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
        '                                        gstrctKDPP.intIndex -= 1
        '                                        Exit Do
        '                                    Case 0
        '                                        Select Case fCheckDelivery()
        '                                            Case 0 'fo[–ณต
        '                                                rtn = fCheckPackCP(gstrctKDPP.strItemGr)
        '                                                If rtn = 1 Then
        '                                                    gintStatus = TR_STATUS.PART
        '                                                    Exit Do
        '                                                ElseIf rtn = -1 Then
        '                                                    f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
        '                                                    gstrctKDPP.intIndex -= 1
        '                                                    Exit Do
        '                                                Else '‘Sf[^xแ
        '                                                    gintStatus = TR_STATUS.PRINT4
        '                                                    Exit Do
        '                                                End If
        '                                            Case 1 'fo[ ่
        '                                                rtn = fSearchPackCP4Delv()
        '                                                If rtn = -1 Then Exit Sub
        '                                                gintStatus = TR_STATUS.PART2
        '                                                Exit Do
        '                                            Case Else
        '                                                f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
        '                                                gstrctKDPP.intIndex -= 1
        '                                                Exit Do
        '                                        End Select
        '                                    Case -2
        '                                        fUpdatePackPlan()
        '                                        'APXV—()
        '                                        If gstrctKDHT.bLinkFlag Then
        '                                            If fUpdateAP(gstrctKDPP.strItemGr) = -1 Then
        '                                                'รฐภXVG[
        '#If Not Debug Then
        '                                                fFnc_WrpMsg("E", G_CONST_MID_E2E94)
        '#End If
        '                                            End If
        '                                        End If

        '                                        gintStatus = TR_STATUS.CLABEL

        '                                        Exit Do
        '                                End Select
        '                        End Select
        '                    Else

        '                        'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, MWA_DB_WARNING, MWA_DB_OK)
        '                        f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)

        '                    End If

        '                ElseIf WKey = WKY_F1 Then


        '                ElseIf WKey = WKY_F2 Then


        '                ElseIf WKey = WKY_ERROR Then

        '                    f0.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, G_CONST_EM_WARP, MWA_DB_WARNING, MWA_DB_OK)

        '                End If

        '            Loop

        '            Exit Sub

        '        Catch ex As Exception
        '            sErrLog(gAppName, "sMain", ex.ToString)
        '        End Try

    End Sub
    '/*
    '|| ึ”–ผFfProcInput
    '|| T—v  F“—อ—
    '*/
    Private Function fProcInput(ByVal pstrInput As String) As Integer
        Dim rtn As Integer
        Dim rtn2 As Integer
        Dim wstrEmplCode As String
        Dim wstrSecKey(2) As String
        Dim wstrSecKeyValue(2) As String
        Dim wstrCenterCode As String
        Dim wstrFilePath As String
        Dim wstrSendIPAddress As String
        Dim wintCnt As Integer
        Dim wintCnt2 As Integer
        Dim wstrWhere As String
        Dim wstrKey(0) As String, wstrKeyValue(0) As String

        fProcInput = -1

        Try

            If pstrInput.StartsWith("OP") Then              'OPศ็ฮ
                If pstrInput = "OP999999999999" Then

                    'G[—
                    mint5060status = M5060_STATUS.NOTCD

                Else
                    If pstrInput.Length = 14 Then
                        'FTP“]‘—
                        wstrSendIPAddress = Mid(pstrInput, 3)
                        If fEditIPAddress(wstrSendIPAddress) = 0 Then
                            'fBNg‘ถ`FbN
                            wstrFilePath = fgetAppPath() & "FTP"
                            rtn = fMakeFolder(wstrFilePath, vbNormal)
                            wstrFilePath += "\" & Mid(pstrInput, 3) & gstrctKDHT.strHdNo & ".DAT"

                            If rtn = -1 Then 'tH_์ฌธ”s
#If Not Debug Then
                                fFnc_WrpMsg("E", G_CONST_MID_E2E93)
#End If
                                fProcInput = 0
                                Exit Function
                            Else
                                rtn2 = fMakeLabelData3(wstrFilePath)
                                If rtn2 = 0 Then
                                    mint5060status = M5060_STATUS.DONE
                                Else
                                    'f[^์ฌG[
#If Not Debug Then
                                    fFnc_WrpMsg("E", G_CONST_MID_E2E91)
#End If
                                End If
                                fProcInput = 0
                                Exit Function
                            End If
                        Else
                            'x•sณ
                            mint5060status = M5060_STATUS.NOTCD
                        End If
                    Else
                        'x•sณ
                        mint5060status = M5060_STATUS.NOTCD
                        fProcInput = 0
                        Exit Function
                    End If
                End If

            Else
                mint5060status = M5060_STATUS.NOTCD
            End If

            fProcInput = 0

        Catch ex As Exception
            sErrLog(gAppName, "fProcInput", ex.ToString)
        End Try

    End Function

    Public Function fMakeLabelData3(ByVal pstrFilePath) As Integer
        fMakeLabelData3 = -1
        Dim intType() As PRINT_TYPE
        Dim strRecDat() As String
        Dim wstrctRec As LABEL_DATA_STR
        Dim lngIndex As Long
        Dim i, j As Long
        Dim rtn1, rtn2, rtn3 As Integer
        Dim wlngStartNo, wlngEndNo As Long
        Dim wstrKeyPKCP = "KEY1"
        Dim wstrKeyPKCJ = "KEY2"
        Dim wstrItemCode As String
        Dim wstrKey(6), wstrKeyValue(6) As String
        Dim wstrKey2(2), wstrKeyValue2(2) As String
        Dim wbUpdAPFlag As Boolean = False

        fMakeLabelData3 = -1

        Try
            fPrintInit(pstrFilePath)
            '•”•ixf[^ฬ์ฌ
            ReDim Preserve intType(0)
            intType(0) = modPrint.PRINT_TYPE.PartsLabel
            ReDim Preserve strRecDat(0)
            With gstrctDelvLabelData
                strRecDat(0) = .strItemCode & .strPQty & .strPSerial & .strPLoctn & .strPHosoYou & .strPHosoZai & .strPCartonType & .strKasoLine & _
                              .strYYYYMMDDS & .strPackSeq & .strAic & .strCase
            End With
            If gstrctDelvLabelData.strDLoctn <> "" Then
                ReDim Preserve intType(1)
                intType(1) = modPrint.PRINT_TYPE.DeliveryLabel
                'foxฬ์ฌ
                ReDim Preserve strRecDat(1)
                With gstrctDelvLabelData
                    strRecDat(1) = .strItemCode & .strDQty & .strDSerial & .strDLoctn & .strDHosoYou & .strDHosoZai & .strDCartonType
                End With
            End If


            rtn3 = fPrintProc2(intType, strRecDat, pstrFilePath)
            If rtn3 = 0 Then
                fMakeLabelData3 = 0
            End If
        Catch ex As Exception
            sErrLog(gAppName, "fProcInput", ex.ToString)
        End Try
    End Function

    Private Sub frm5060_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        ' Enable BTScanLib
        If Not scanHandler Then
            btScanLib = btScanLib.getInstance()
            AddHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
            scanHandler = True
            btScanLib.Debug = False
            btScanLib.Enable()
        End If
    End Sub
End Class
