﻿'*******************************************************************************
'* ์ฌา   : ”ฎ๏ะGR[EVXe€ 
'* ์ฌ“๚   : 2005/11/30
'* T—v     : PICS2004 p^CY—
'* XV——๐ : 
'* สฐผฎ  : 1.0
'*******************************************************************************
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 KDPL1000.BtScanLib
Imports BTClientLib
Imports System.IO
Imports System.Reflection
Imports Newtonsoft
Imports Microsoft.WindowsCE.Forms
Imports BtScan2

Public Class frm1030
    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 WarpBox1 As WarpControl.WarpBox
    'Friend WithEvents wfName As WarpControl.WarpField
    'Friend WithEvents WarpHWBcr1 As WarpControl.WarpHWBcr
    'Friend WithEvents wfKey As WarpControl.WarpField
    'Friend WithEvents wfCheck As WarpControl.WarpField
    'Friend WithEvents wfTotal As WarpControl.WarpField
    'Friend WithEvents wfMSC As WarpControl.WarpField
    'Friend WithEvents wfPNT As WarpControl.WarpField
    'Friend WithEvents wfTrm As WarpControl.WarpField
    'Friend WithEvents wfCaseNo As WarpControl.WarpField
    'Friend WithEvents wfSerial As WarpControl.WarpField
    'Friend WithEvents wfPartNo As WarpControl.WarpField
    'Friend WithEvents wfCrtnNo As WarpControl.WarpField
    'Friend WithEvents wfCaseNo2 As WarpControl.WarpField
    'Friend WithEvents wfTrm2 As WarpControl.WarpField
    'Friend WithEvents wfPNT2 As WarpControl.WarpField
    'Friend WithEvents wfMSC2 As WarpControl.WarpField
    'Friend WithEvents wfLine As WarpControl.WarpField
    'Friend WithEvents wfLine2 As WarpControl.WarpField
    'Friend WithEvents WarpField1 As WarpControl.WarpField
    'Friend WithEvents wfSeq As WarpControl.WarpField
    'Friend WithEvents wfKLine As WarpControl.WarpField
    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame()
    '    Me.wfKLine = New WarpControl.WarpField()
    '    Me.wfSeq = New WarpControl.WarpField()
    '    Me.WarpField1 = New WarpControl.WarpField()
    '    Me.wfLine2 = New WarpControl.WarpField()
    '    Me.wfLine = New WarpControl.WarpField()
    '    Me.wfCaseNo2 = New WarpControl.WarpField()
    '    Me.wfTrm2 = New WarpControl.WarpField()
    '    Me.wfPNT2 = New WarpControl.WarpField()
    '    Me.wfMSC2 = New WarpControl.WarpField()
    '    Me.wfSerial = New WarpControl.WarpField()
    '    Me.wfPartNo = New WarpControl.WarpField()
    '    Me.wfCrtnNo = New WarpControl.WarpField()
    '    Me.wfCaseNo = New WarpControl.WarpField()
    '    Me.wfTrm = New WarpControl.WarpField()
    '    Me.wfPNT = New WarpControl.WarpField()
    '    Me.wfMSC = New WarpControl.WarpField()
    '    Me.wfTotal = New WarpControl.WarpField()
    '    Me.wfCheck = New WarpControl.WarpField()
    '    Me.wfName = New WarpControl.WarpField()
    '    Me.WarpBox1 = New WarpControl.WarpBox()
    '    Me.wfKey = New WarpControl.WarpField()
    '    Me.WarpHWBcr1 = New WarpControl.WarpHWBcr()
    '    Me.WarpFrame1.SuspendLayout()
    '    Me.SuspendLayout()
    '
    'WarpFrame1
    '
    'Me.WarpFrame1.Controls.Add(Me.wfKLine)
    'Me.WarpFrame1.Controls.Add(Me.wfSeq)
    'Me.WarpFrame1.Controls.Add(Me.WarpField1)
    'Me.WarpFrame1.Controls.Add(Me.wfLine2)
    'Me.WarpFrame1.Controls.Add(Me.wfLine)
    'Me.WarpFrame1.Controls.Add(Me.wfCaseNo2)
    'Me.WarpFrame1.Controls.Add(Me.wfTrm2)
    'Me.WarpFrame1.Controls.Add(Me.wfPNT2)
    'Me.WarpFrame1.Controls.Add(Me.wfMSC2)
    'Me.WarpFrame1.Controls.Add(Me.wfSerial)
    'Me.WarpFrame1.Controls.Add(Me.wfPartNo)
    'Me.WarpFrame1.Controls.Add(Me.wfCrtnNo)
    'Me.WarpFrame1.Controls.Add(Me.wfCaseNo)
    'Me.WarpFrame1.Controls.Add(Me.wfTrm)
    'Me.WarpFrame1.Controls.Add(Me.wfPNT)
    'Me.WarpFrame1.Controls.Add(Me.wfMSC)
    'Me.WarpFrame1.Controls.Add(Me.wfTotal)
    'Me.WarpFrame1.Controls.Add(Me.wfCheck)
    'Me.WarpFrame1.Controls.Add(Me.wfName)
    'Me.WarpFrame1.Controls.Add(Me.WarpBox1)
    'Me.WarpFrame1.Controls.Add(Me.wfKey)
    '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 = ""
    '
    'wfKLine
    '
    'Me.wfKLine.DecimalPointPosition = CType(0, Short)
    'Me.wfKLine.DisplayAttribute.Reverse = True
    'Me.wfKLine.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfKLine.FontSize = WarpControl.FontSizes.Small
    'Me.wfKLine.Format = ""
    'Me.wfKLine.InputAttribute.Reverse = True
    'Me.wfKLine.Length = CType(2, Short)
    'Me.wfKLine.Location = New System.Drawing.Point(33, 1)
    'Me.wfKLine.MacroBcr = ""
    'Me.wfKLine.MacroIn = ""
    'Me.wfKLine.MacroKey = ""
    'Me.wfKLine.MacroOut = ""
    'Me.wfKLine.Name = "wfKLine"
    'Me.wfKLine.Size = New System.Drawing.Size(30, 30)
    'Me.wfKLine.TabIndex = CType(73, Short)
    'Me.wfKLine.Text = "XX"
    '
    'wfSeq
    '
    'Me.wfSeq.DecimalPointPosition = CType(0, Short)
    'Me.wfSeq.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfSeq.FontSize = WarpControl.FontSizes.Small
    'Me.wfSeq.Format = ""
    'Me.wfSeq.InputMode.Right = True
    'Me.wfSeq.Length = CType(3, Short)
    'Me.wfSeq.Location = New System.Drawing.Point(60, 1)
    'Me.wfSeq.MacroBcr = ""
    'Me.wfSeq.MacroIn = ""
    'Me.wfSeq.MacroKey = ""
    'Me.wfSeq.MacroOut = ""
    'Me.wfSeq.Name = "wfSeq"
    'Me.wfSeq.Size = New System.Drawing.Size(45, 30)
    'Me.wfSeq.TabIndex = CType(72, Short)
    'Me.wfSeq.Text = "999"
    '
    '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(1, Short)
    'Me.WarpField1.Location = New System.Drawing.Point(165, 0)
    'Me.WarpField1.MacroBcr = ""
    'Me.WarpField1.MacroIn = ""
    'Me.WarpField1.MacroKey = ""
    'Me.WarpField1.MacroOut = ""
    'Me.WarpField1.Name = "WarpField1"
    'Me.WarpField1.Size = New System.Drawing.Size(12, 24)
    'Me.WarpField1.TabIndex = CType(71, Short)
    'Me.WarpField1.Text = "/"
    '
    'wfLine2
    '
    'Me.wfLine2.DecimalPointPosition = CType(0, Short)
    'Me.wfLine2.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfLine2.Format = ""
    'Me.wfLine2.Length = CType(2, Short)
    'Me.wfLine2.Location = New System.Drawing.Point(0, 88)
    'Me.wfLine2.MacroBcr = ""
    'Me.wfLine2.MacroIn = ""
    'Me.wfLine2.MacroKey = ""
    'Me.wfLine2.MacroOut = ""
    'Me.wfLine2.Name = "wfLine2"
    'Me.wfLine2.Size = New System.Drawing.Size(36, 36)
    'Me.wfLine2.TabIndex = CType(70, Short)
    'Me.wfLine2.Text = "XX"
    '
    'wfLine
    '
    'Me.wfLine.DecimalPointPosition = CType(0, Short)
    'Me.wfLine.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfLine.FontSize = WarpControl.FontSizes.Small
    'Me.wfLine.Format = ""
    'Me.wfLine.Length = CType(2, Short)
    'Me.wfLine.Location = New System.Drawing.Point(1, 1)
    'Me.wfLine.MacroBcr = ""
    'Me.wfLine.MacroIn = ""
    'Me.wfLine.MacroKey = ""
    'Me.wfLine.MacroOut = ""
    'Me.wfLine.Name = "wfLine"
    'Me.wfLine.Size = New System.Drawing.Size(30, 30)
    'Me.wfLine.TabIndex = CType(69, Short)
    'Me.wfLine.Text = "XX"
    '
    'wfCaseNo2
    '
    'Me.wfCaseNo2.DecimalPointPosition = CType(0, Short)
    'Me.wfCaseNo2.Font = New System.Drawing.Font("lr SVbN", 16.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfCaseNo2.FontSize = WarpControl.FontSizes.Small4
    'Me.wfCaseNo2.Format = ""
    'Me.wfCaseNo2.Length = CType(9, Short)
    'Me.wfCaseNo2.Location = New System.Drawing.Point(156, 124)
    'Me.wfCaseNo2.MacroBcr = ""
    'Me.wfCaseNo2.MacroIn = ""
    'Me.wfCaseNo2.MacroKey = ""
    'Me.wfCaseNo2.MacroOut = ""
    'Me.wfCaseNo2.Name = "wfCaseNo2"
    'Me.wfCaseNo2.Size = New System.Drawing.Size(81, 18)
    'Me.wfCaseNo2.TabIndex = CType(68, Short)
    'Me.wfCaseNo2.Text = "XXX-XX-XX"
    '
    'wfTrm2
    '
    'Me.wfTrm2.DecimalPointPosition = CType(0, Short)
    'Me.wfTrm2.Font = New System.Drawing.Font("lr SVbN", 16.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfTrm2.FontSize = WarpControl.FontSizes.Small4
    'Me.wfTrm2.Format = ""
    'Me.wfTrm2.Length = CType(3, Short)
    'Me.wfTrm2.Location = New System.Drawing.Point(112, 124)
    'Me.wfTrm2.MacroBcr = ""
    'Me.wfTrm2.MacroIn = ""
    'Me.wfTrm2.MacroKey = ""
    'Me.wfTrm2.MacroOut = ""
    'Me.wfTrm2.Name = "wfTrm2"
    'Me.wfTrm2.Size = New System.Drawing.Size(27, 18)
    'Me.wfTrm2.TabIndex = CType(67, Short)
    'Me.wfTrm2.Text = "XXX"
    '
    'wfPNT2
    '
    'Me.wfPNT2.DecimalPointPosition = CType(0, Short)
    'Me.wfPNT2.Font = New System.Drawing.Font("lr SVbN", 16.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfPNT2.FontSize = WarpControl.FontSizes.Small4
    'Me.wfPNT2.Format = ""
    'Me.wfPNT2.Length = CType(3, Short)
    'Me.wfPNT2.Location = New System.Drawing.Point(78, 124)
    'Me.wfPNT2.MacroBcr = ""
    'Me.wfPNT2.MacroIn = ""
    'Me.wfPNT2.MacroKey = ""
    'Me.wfPNT2.MacroOut = ""
    'Me.wfPNT2.Name = "wfPNT2"
    'Me.wfPNT2.Size = New System.Drawing.Size(27, 18)
    'Me.wfPNT2.TabIndex = CType(66, Short)
    'Me.wfPNT2.Text = "XXX"
    '
    'wfMSC2
    '
    'Me.wfMSC2.DecimalPointPosition = CType(0, Short)
    'Me.wfMSC2.Font = New System.Drawing.Font("lr SVbN", 16.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfMSC2.FontSize = WarpControl.FontSizes.Small4
    'Me.wfMSC2.Format = ""
    'Me.wfMSC2.Length = CType(8, Short)
    'Me.wfMSC2.Location = New System.Drawing.Point(0, 124)
    'Me.wfMSC2.MacroBcr = ""
    'Me.wfMSC2.MacroIn = ""
    'Me.wfMSC2.MacroKey = ""
    'Me.wfMSC2.MacroOut = ""
    'Me.wfMSC2.Name = "wfMSC2"
    'Me.wfMSC2.Size = New System.Drawing.Size(72, 18)
    'Me.wfMSC2.TabIndex = CType(65, Short)
    'Me.wfMSC2.Text = "XXXX-XXX"
    '
    'wfSerial
    '
    'Me.wfSerial.DecimalPointPosition = CType(0, Short)
    'Me.wfSerial.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfSerial.FontSize = WarpControl.FontSizes.Small2
    'Me.wfSerial.Format = ""
    'Me.wfSerial.Length = CType(6, Short)
    'Me.wfSerial.Location = New System.Drawing.Point(160, 165)
    'Me.wfSerial.MacroBcr = ""
    'Me.wfSerial.MacroIn = ""
    'Me.wfSerial.MacroKey = ""
    'Me.wfSerial.MacroOut = ""
    'Me.wfSerial.Name = "wfSerial"
    'Me.wfSerial.Size = New System.Drawing.Size(72, 24)
    'Me.wfSerial.TabIndex = CType(64, Short)
    'Me.wfSerial.Text = "XXXXXX"
    '
    'wfPartNo
    '
    'Me.wfPartNo.DecimalPointPosition = CType(0, Short)
    'Me.wfPartNo.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfPartNo.FontSize = WarpControl.FontSizes.Small2
    'Me.wfPartNo.Format = ""
    'Me.wfPartNo.Length = CType(13, Short)
    'Me.wfPartNo.Location = New System.Drawing.Point(0, 166)
    'Me.wfPartNo.MacroBcr = ""
    'Me.wfPartNo.MacroIn = ""
    'Me.wfPartNo.MacroKey = ""
    'Me.wfPartNo.MacroOut = ""
    'Me.wfPartNo.Name = "wfPartNo"
    'Me.wfPartNo.Size = New System.Drawing.Size(156, 24)
    'Me.wfPartNo.TabIndex = CType(62, Short)
    'Me.wfPartNo.Text = "XXX-XX-XX"
    '
    'wfCrtnNo
    '
    'Me.wfCrtnNo.DecimalPointPosition = CType(0, Short)
    'Me.wfCrtnNo.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfCrtnNo.FontSize = WarpControl.FontSizes.Small2
    'Me.wfCrtnNo.Format = ""
    'Me.wfCrtnNo.Length = CType(8, Short)
    'Me.wfCrtnNo.Location = New System.Drawing.Point(0, 142)
    'Me.wfCrtnNo.MacroBcr = ""
    'Me.wfCrtnNo.MacroIn = ""
    'Me.wfCrtnNo.MacroKey = ""
    'Me.wfCrtnNo.MacroOut = ""
    'Me.wfCrtnNo.Name = "wfCrtnNo"
    'Me.wfCrtnNo.Size = New System.Drawing.Size(96, 24)
    'Me.wfCrtnNo.TabIndex = CType(59, Short)
    'Me.wfCrtnNo.Text = "XXXX-XXX"
    '
    'wfCaseNo
    '
    'Me.wfCaseNo.DecimalPointPosition = CType(0, Short)
    'Me.wfCaseNo.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfCaseNo.FontSize = WarpControl.FontSizes.Small2
    'Me.wfCaseNo.Format = ""
    'Me.wfCaseNo.Length = CType(9, Short)
    'Me.wfCaseNo.Location = New System.Drawing.Point(0, 66)
    'Me.wfCaseNo.MacroBcr = ""
    'Me.wfCaseNo.MacroIn = ""
    'Me.wfCaseNo.MacroKey = ""
    'Me.wfCaseNo.MacroOut = ""
    'Me.wfCaseNo.Name = "wfCaseNo"
    'Me.wfCaseNo.Size = New System.Drawing.Size(108, 24)
    'Me.wfCaseNo.TabIndex = CType(56, Short)
    'Me.wfCaseNo.Text = "XXX-XX-XX"
    '
    'wfTrm
    '
    'Me.wfTrm.DecimalPointPosition = CType(0, Short)
    'Me.wfTrm.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfTrm.FontSize = WarpControl.FontSizes.Small2
    'Me.wfTrm.Format = ""
    'Me.wfTrm.Length = CType(3, Short)
    'Me.wfTrm.Location = New System.Drawing.Point(156, 40)
    'Me.wfTrm.MacroBcr = ""
    'Me.wfTrm.MacroIn = ""
    'Me.wfTrm.MacroKey = ""
    'Me.wfTrm.MacroOut = ""
    'Me.wfTrm.Name = "wfTrm"
    'Me.wfTrm.Size = New System.Drawing.Size(36, 24)
    'Me.wfTrm.TabIndex = CType(55, Short)
    'Me.wfTrm.Text = "XXX"
    '
    'wfPNT
    '
    'Me.wfPNT.DecimalPointPosition = CType(0, Short)
    'Me.wfPNT.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfPNT.FontSize = WarpControl.FontSizes.Small2
    'Me.wfPNT.Format = ""
    'Me.wfPNT.Length = CType(3, Short)
    'Me.wfPNT.Location = New System.Drawing.Point(108, 40)
    'Me.wfPNT.MacroBcr = ""
    'Me.wfPNT.MacroIn = ""
    'Me.wfPNT.MacroKey = ""
    'Me.wfPNT.MacroOut = ""
    'Me.wfPNT.Name = "wfPNT"
    'Me.wfPNT.Size = New System.Drawing.Size(36, 24)
    'Me.wfPNT.TabIndex = CType(54, Short)
    'Me.wfPNT.Text = "XXX"
    '
    'wfMSC
    '
    'Me.wfMSC.DecimalPointPosition = CType(0, Short)
    'Me.wfMSC.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfMSC.FontSize = WarpControl.FontSizes.Small2
    'Me.wfMSC.Format = ""
    'Me.wfMSC.Length = CType(8, Short)
    'Me.wfMSC.Location = New System.Drawing.Point(0, 42)
    'Me.wfMSC.MacroBcr = ""
    'Me.wfMSC.MacroIn = ""
    'Me.wfMSC.MacroKey = ""
    'Me.wfMSC.MacroOut = ""
    'Me.wfMSC.Name = "wfMSC"
    'Me.wfMSC.Size = New System.Drawing.Size(96, 24)
    'Me.wfMSC.TabIndex = CType(53, Short)
    'Me.wfMSC.Text = "XXXX-XXX"
    '
    'wfTotal
    '
    'Me.wfTotal.DecimalPointPosition = CType(0, Short)
    'Me.wfTotal.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfTotal.FontSize = WarpControl.FontSizes.Small2
    'Me.wfTotal.Format = ""
    'Me.wfTotal.InputMode.Right = True
    'Me.wfTotal.Length = CType(5, Short)
    'Me.wfTotal.Location = New System.Drawing.Point(178, 0)
    'Me.wfTotal.MacroBcr = ""
    'Me.wfTotal.MacroIn = ""
    'Me.wfTotal.MacroKey = ""
    'Me.wfTotal.MacroOut = ""
    'Me.wfTotal.Name = "wfTotal"
    'Me.wfTotal.Size = New System.Drawing.Size(60, 24)
    'Me.wfTotal.TabIndex = CType(49, Short)
    'Me.wfTotal.Text = "ZZZZ9"
    '
    'wfCheck
    '
    'Me.wfCheck.DecimalPointPosition = CType(0, Short)
    'Me.wfCheck.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfCheck.FontSize = WarpControl.FontSizes.Small2
    'Me.wfCheck.Format = ""
    'Me.wfCheck.InputMode.Right = True
    'Me.wfCheck.Length = CType(5, Short)
    'Me.wfCheck.Location = New System.Drawing.Point(103, 0)
    'Me.wfCheck.MacroBcr = ""
    'Me.wfCheck.MacroIn = ""
    'Me.wfCheck.MacroKey = ""
    'Me.wfCheck.MacroOut = ""
    'Me.wfCheck.Name = "wfCheck"
    'Me.wfCheck.Size = New System.Drawing.Size(60, 24)
    'Me.wfCheck.TabIndex = CType(47, Short)
    'Me.wfCheck.Text = "ZZZZ9"
    '
    '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(1, Short)
    '
    'WarpBox1
    '
    'Me.WarpBox1.BoxType = WarpControl.BoxTypes.Box
    'Me.WarpBox1.DrawMode = WarpControl.DrawModes.Line
    '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 = "C:\081-0030.jpg"
    'Me.WarpBox1.Location = New System.Drawing.Point(0, 192)
    'Me.WarpBox1.Name = "WarpBox1"
    'Me.WarpBox1.Size = New System.Drawing.Size(240, 24)
    'Me.WarpBox1.TabIndex = 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.ForeColor = CType(15, Short)
    'Me.wfKey.Format = ""
    'Me.wfKey.InputMode.Secret = True
    'Me.wfKey.Length = CType(1, Short)
    'Me.wfKey.Location = New System.Drawing.Point(204, 36)
    '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(45, 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)
    '
    'frm1030
    '
    '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 = "frm1030"
    'Me.Text = "Form1"
    'Me.WarpFrame1.ResumeLayout(False)
    'Me.ResumeLayout(False)

    'End Sub

#End Region

    Private Enum M1030_STATUS As Integer
        INIT = 0
        MENUBACK = 1
        NOTCD = 2
        DSCAN = 3
        DONE = 4
        NOTPACK = 5
        CANCEL = 6
        CMPLTDATA = 7
        CMPLTCHK = 8
        ESCAICCASE = 9
        ZANINFO = 10
        NOTFOUND = 11
        DEFPALT = 12
        RESET = 13
        NOSRCHKEY = 14
        CHGPALT = 15
        SHOWLIST = 16
    End Enum
    Private mint1030status As Integer
    Private Const KEY_PACKAP2 = "KEY_PACKAP2"
    Private Sub frm1030_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
            mint1030status = M1030_STATUS.INIT

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

#If Not Debug Then
            'sSetImgFName(G_CONST_MID_H1030, WarpBox1)
#End If

            sDisp1030()
            ' 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
            sErrLog(gAppName, "", ex.ToString)
        End Try

    End Sub

    '/*
    '|| ึ”–ผFsDisp1030
    '|| T—v  F1030ๆ–ส•\ฆ
    '*/
    Private Sub sDisp1030()
        Dim tmp As String
        With gstrctPLDispData
            'wfCheck.Puts(.intCheckCnt)
            'wfTotal.Puts(.intTotalCnt)

            wfCheck.Text = .intCheckCnt
            wfTotal.Text = .intTotalCnt

        End With
        With gstrctAicCase
            'wfLine.Puts(.Line)
            'wfKLine.Puts(.KasoLine)
            'wfSeq.Puts(CInt(.PackSeq))
            'wfMSC.Puts(.Msc_Disp)
            'wfPNT.Puts(.Pnt)
            'wfTrm.Puts(.Trm)
            'wfCaseNo.Puts(.CaseNo)

            wfLine.Text = .Line
            wfKLine.Text = .KasoLine
            wfSeq.Text = CInt(.PackSeq)
            wfMSC.Text = .Msc_Disp
            wfPNT.Text = .Pnt
            wfTrm.Text = .Trm
            wfCaseNo.Text = .CaseNo

        End With
        'wfCrtnNo.Puts("")
        'wfPartNo.Puts("")
        'wfSerial.Puts("")

        wfCrtnNo.Text = ""
        wfPartNo.Text = ""
        wfSerial.Text = ""

        With gstrctPLDispData
            If .strCartonNo = "" Then
                'wfMSC2.Puts("")
                'wfPNT2.Puts("")
                'wfTrm2.Puts("")
                'wfCaseNo2.Puts("")
                'wfLine2.Puts("")

                wfMSC2.Text = ""
                wfPNT2.Text = ""
                wfTrm2.Text = ""
                wfCaseNo2.Text = ""
                wfLine2.Text = ""

            Else

                'wfLine2.Puts("")

                wfLine2.Text = ""

                If .strCartonNo = "00000" Then
                    'wfMSC2.Puts("")
                    'wfPNT2.Puts("")
                    'wfTrm2.Puts("")
                    'wfCaseNo2.Puts("")
                    'wfCrtnNo.Puts("")
                    'tmp = fDispItemChg(modConst.DispItemChg.ToMazda, .strItemCode)
                    'wfPartNo.Puts(tmp)
                    'wfSerial.Puts(.strSerial)
                    'wfLine2.Puts(.strLine)

                    wfMSC2.Text = ""
                    wfPNT2.Text = ""
                    wfTrm2.Text = ""
                    wfCaseNo2.Text = ""
                    wfCrtnNo.Text = ""
                    tmp = fDispItemChg(modConst.DispItemChg.ToMazda, .strItemCode)
                    wfPartNo.Text = tmp
                    wfSerial.Text = .strSerial
                    wfLine2.Text = .strLine

                Else
                    'wfMSC2.Puts(Mid(.strAicCaseNo, 1, 4) & "-" & Mid(.strAicCaseNo, 5, 3))
                    'wfPNT2.Puts(Mid(.strAicCaseNo, 8, 3))
                    'wfTrm2.Puts(Mid(.strAicCaseNo, 11, 3))
                    'wfCaseNo2.Puts(Mid(.strAicCaseNo, 14, 3) & "-" & Mid(.strAicCaseNo, 17, 2) & "-" & Mid(.strAicCaseNo, 19, 2))
                    'wfCrtnNo.Puts(.strCartonNo)
                    'wfPartNo.Puts("")
                    'wfSerial.Puts("")
                    'wfLine2.Puts(.strLine)

                    wfMSC2.Text = Mid(.strAicCaseNo, 1, 4) & "-" & Mid(.strAicCaseNo, 5, 3)
                    wfPNT2.Text = Mid(.strAicCaseNo, 8, 3)
                    wfTrm2.Text = Mid(.strAicCaseNo, 11, 3)
                    wfCaseNo2.Text = Mid(.strAicCaseNo, 14, 3) & "-" & Mid(.strAicCaseNo, 17, 2) & "-" & Mid(.strAicCaseNo, 19, 2)
                    wfCrtnNo.Text = .strCartonNo
                    wfPartNo.Text = ""
                    wfSerial.Text = ""
                    wfLine2.Text = .strLine

                End If
            End If
        End With

        'wfName.Puts(gstrctKDHT.strUserName)
        wfName.Text = gstrctKDHT.strUserName
    End Sub

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

        If (Not fCheckCode(buf)) Then
            sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
#If Not Debug Then      'J[g“A•”•ixลอ ่น๑B
                                fFnc_WrpMsg("E", G_CONST_MID_E1E30)
#End If
            Exit Sub
        End If
        '“—อ—
        rtn = fProcInput(RTrim(buf))

        If rtn = 0 Then
            Select Case mint1030status
                Case M1030_STATUS.DONE

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    gintStatus = PL_STATUS.PCSCAN
                    Me.Close()

                Case M1030_STATUS.CMPLTCHK  'มชฏธฎ—น

                    rtn = fClearSKey2()
                    If rtn <> 0 Then
                        'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(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

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    'pbg”ธZ
                    gintStatus = PL_STATUS.PALETTESCN
                    fMakeCommandFile(G_CONST_PROCESS_PAL_DEL, G_CONST_SPEECH_COMPPAL)
                    Me.Close()

                Case M1030_STATUS.MENUBACK
                    rtn = fClearSKey()
                    If rtn <> 0 Then
                        'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(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

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    'pbg”ธZ
                    gintStatus = PL_STATUS.PALETTESCN
                    fMakeCommandFile(G_CONST_PROCESS_HT_DEL)
                    Me.Close()

                Case M1030_STATUS.ESCAICCASE  'HTฺ‘ฑ๐
MENU_BACK:          'ส฿ฺฏฤ–—e—สตฐสฐเ“ฏถ—(GoTo MENU_BACKๆ่j

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    gintStatus = PL_STATUS.PALETTESCN
                    rtn = fClearSKey()
                    If rtn <> 0 Then
                        'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(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
                    fMakeCommandFile(G_CONST_PROCESS_HT_DEL)
                    Me.Close()

                Case M1030_STATUS.CHGPALT  'ส฿ฺฏฤ•ฯX
                    rtn2 = fSearchPlan(wstrctSPM)
                    Select Case rtn2
                        Case 3
                            'ๆ–สฤ•\ฆ
                            gstrctPLDispHead.initialize()
                            gstrctPLDispData.initialize()

                            'SearchKeyช ๊ฮPackAP๕A–ณฏ๊ฮPlanฬถYฬืธ๕
                            'rtn = fSearchPackAP2("1", "1")
                            rtn = fSearchPackAP3("1")
                            If rtn = 1 Then
                                gstrctKDPL.strSearchKey = gstrctAicCase.KeyData
                                'HTCTRLษ—f[^๐’วม
                                'BtLib.Transaction.BeginConCurrent()
                                rtn = fUpdateHTCTRL4PL()
                                If rtn = -1 Then
                                    'BtLib.Transaction.Abort()
                                    Exit Sub
                                End If
                                'BtLib.Transaction.End()

                                RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                                btScanLib.Disable()

                                gintStatus = PL_STATUS.PCSCAN
                                fMakeCommandFile(G_CONST_PROCESS_HT_CHG, G_CONST_SPEECH_CHGPALT)
                                Me.Close()
                            ElseIf rtn <> 0 Then
                                'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(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
                        Case 5
                            sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                            fMakeCommandFile(G_CONST_PROCESS_PAL_DEL)
#If Not Debug Then
                                                fFnc_WrpMsg("E", G_CONST_MID_E1E40)
#End If

                            RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                            btScanLib.Disable()

                            gintStatus = PL_STATUS.PALETTESCN
                            Me.Close()
                        Case 4
                            sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                            fMakeCommandFile(G_CONST_PROCESS_PAL_DEL)
#If Not Debug Then
                                                fFnc_WrpMsg("E", G_CONST_MID_E1E20)
#End If

                            RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                            btScanLib.Disable()

                            gintStatus = PL_STATUS.PALETTESCN
                            Me.Close()
                        Case 2
                            fMakeCommandFile(G_CONST_PROCESS_PAL_DEL)
                            rtn = fClearSKey2()
                            If rtn <> 0 Then
                                'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(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

                            RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                            btScanLib.Disable()

                            gintStatus = PL_STATUS.CHKBGN
                            Me.Close()
                            Exit Sub

                        Case 0 'VK์ฌ
                            'BtLib.Transaction.BeginConCurrent()
                            'pbg”มZ
                            rtn2 = fUpdPaletteQty(1)
                            If rtn2 = -1 Then
                                'BtLib.Transaction.Abort()
                                'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
                                MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                                Exit Sub
                            ElseIf rtn2 = 0 Then 'ส฿ฺฏฤ–—e—สตฐสฐ
                                'BtLib.Transaction.Abort()
                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
#If Not Debug Then
                                                    fFnc_WrpMsg("E", G_CONST_MID_E1E19)
#End If
                                GoTo MENU_BACK  'HTฺ‘ฑ๐—ึ
                            End If
                            If fSetPlan("1", "", 1) = -1 Then
                                'BtLib.Transaction.Abort()
                                Exit Sub
                            End If
                            'BtLib.Transaction.End()
#If Not Debug Then
                                                sSetImgFName(G_CONST_MID_H1015, WarpBox1)
                                                WarpFrame1.Flush()
#End If
                            gstrctPLDispHead.initialize()
                            gstrctPLDispData.initialize()
                            'BtLib.Transaction.BeginConCurrent()
                            rtn2 = fMakePackAP(wstrctSPM)
                            If rtn2 = -1 Then
                                'ฬงฒูดืฐ
                                'BtLib.Transaction.Abort()
                                Exit Sub
                            End If
                            'BtLib.Transaction.End()
                            gstrctKDPL.strSearchKey = gstrctAicCase.KeyData
                            'HTCTRLษ—f[^๐’วม
                            'BtLib.Transaction.BeginConCurrent()
                            rtn = fUpdateHTCTRL4PL()
                            If rtn = -1 Then
                                'BtLib.Transaction.Abort()
                                Exit Sub
                            End If
                            'BtLib.Transaction.End()
                            mint1030status = M1030_STATUS.DONE
                            fMakeCommandFile(G_CONST_PROCESS_PAL_DSP, G_CONST_SPEECH_STRTPAL)
                            sBeepSound(modPublicHT.BEEP_TYPE.B, modPublicHT.BEEP_SELECTION.NG)
                        Case -1
                            'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(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 Select

                Case M1030_STATUS.NOTCD              'ูศ้o[R[h
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    sOutputLog(gstrctPicsIni.strOutput_KDPL, "KDPL1E30", G_CONST_BC_PART, buf)
#If Not Debug Then
                                        fFnc_WrpMsg("E", G_CONST_MID_E1E30)
#End If

                Case M1030_STATUS.DSCAN              '_uXL“
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fMakeCommandFile(G_CONST_PROCESS_VOICE, G_CONST_SPEECH_DBLSCAN)
#If Not Debug Then
                                        fFnc_WrpMsg("E", G_CONST_MID_E1E32)
#End If

                Case M1030_STATUS.NOSRCHKEY          'SearchKeyช–ณข
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fMakeCommandFile(G_CONST_PROCESS_HT_DEL)
#If Not Debug Then
                                        fFnc_WrpMsg("E", G_CONST_MID_E1E36)
#End If
                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    gintStatus = PL_STATUS.PALETTESCN
                    Me.Close()

                Case M1030_STATUS.NOTFOUND           'ซ•๏vๆษ–ณข

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    gintStatus = PL_STATUS.SUSPEND
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fMakeCommandFile(G_CONST_PROCESS_HT_ERR, G_CONST_SPEECH_NOTPALT)
                    Me.Close()
                Case M1030_STATUS.DEFPALT            'ส฿ฺฏฤ

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    gintStatus = PL_STATUS.SUSPEND
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fMakeCommandFile(G_CONST_PROCESS_HT_ERR, G_CONST_SPEECH_NOTPALT)
                    Me.Close()
                Case M1030_STATUS.ZANINFO
                    fMakeCommandFile(G_CONST_PROCESS_LIST)

                Case M1030_STATUS.RESET
                    fMakeCommandFile(G_CONST_PROCESS_HT_RTN, G_CONST_SPEECH_HTRESME)

                Case M1030_STATUS.NOTPACK

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    gintStatus = PL_STATUS.NOTPACK
                    Me.Close()

                Case M1030_STATUS.CANCEL

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    gintStatus = PL_STATUS.CANCEL
                    Me.Close()

            End Select

        ElseIf rtn = -1 Then

            'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(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
        '        Dim rtn2 As Integer
        '        Dim rtn3 As Integer
        '        Dim wstrctSPM As STRCT_KEY_SPM2
        '        Dim stat As Integer

        '        Try

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

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

        '                If WKey = WKY_ENT Then
        '                    'SearchKeyฬ๕
        '                    If fSearchKey(gstrctKDHT.strHdNo, gstrctKDPL.strSearchKey) <> 0 Then
        '                        f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                        Exit Do
        '                    End If

        '                    'ๆ–สฤ•\ฆ
        '                    gstrctPLDispHead.initialize()
        '                    gstrctPLDispData.initialize()

        '                    'SearchKeyช ๊ฮPackAP๕
        '                    If gstrctKDPL.strSearchKey <> "" Then
        '                        'rtn = fSearchPackAP2("1", "1")
        '                        rtn = fSearchPackAP3("1")
        '                        If rtn = 1 Then
        '                            gintStatus = PL_STATUS.PCSCAN
        '                            Exit Do
        '                        ElseIf rtn <> 0 Then
        '                            f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                            Exit Do
        '                        End If
        '                    End If
        '                    'SearchKeyช–ณข
        '#If Not Debug Then
        '                    fFnc_WrpMsg("E", G_CONST_MID_E1E36)
        '#End If
        '                    gintStatus = PL_STATUS.PALETTESCN
        '                    Exit Do

        '                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
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '#If Not Debug Then      'J[g“A•”•ixลอ ่น๑B
        '                        fFnc_WrpMsg("E", G_CONST_MID_E1E30)
        '#End If
        '                        Exit Do
        '                    End If
        '                    '“—อ—
        '                    rtn = fProcInput(RTrim(buf))

        '                    If rtn = 0 Then
        '                        Select Case mint1030status
        '                            Case M1030_STATUS.DONE

        '                                gintStatus = PL_STATUS.PCSCAN
        '                                Exit Do

        '                            Case M1030_STATUS.CMPLTCHK  'มชฏธฎ—น

        '                                rtn = fClearSKey2()
        '                                If rtn <> 0 Then
        '                                    f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                                End If
        '                                'pbg”ธZ
        '                                gintStatus = PL_STATUS.PALETTESCN
        '                                fMakeCommandFile(G_CONST_PROCESS_PAL_DEL, G_CONST_SPEECH_COMPPAL)
        '                                Exit Do

        '                            Case M1030_STATUS.MENUBACK
        '                                rtn = fClearSKey()
        '                                If rtn <> 0 Then
        '                                    f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                                End If
        '                                'pbg”ธZ
        '                                gintStatus = PL_STATUS.PALETTESCN
        '                                fMakeCommandFile(G_CONST_PROCESS_HT_DEL)
        '                                Exit Do

        '                            Case M1030_STATUS.ESCAICCASE  'HTฺ‘ฑ๐
        'MENU_BACK:                      'ส฿ฺฏฤ–—e—สตฐสฐเ“ฏถ—(GoTo MENU_BACKๆ่j
        '                                gintStatus = PL_STATUS.PALETTESCN
        '                                rtn = fClearSKey()
        '                                If rtn <> 0 Then
        '                                    f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                                End If
        '                                fMakeCommandFile(G_CONST_PROCESS_HT_DEL)
        '                                Exit Do

        '                            Case M1030_STATUS.CHGPALT  'ส฿ฺฏฤ•ฯX
        '                                rtn2 = fSearchPlan(wstrctSPM)
        '                                Select Case rtn2
        '                                    Case 3
        '                                        'ๆ–สฤ•\ฆ
        '                                        gstrctPLDispHead.initialize()
        '                                        gstrctPLDispData.initialize()

        '                                        'SearchKeyช ๊ฮPackAP๕A–ณฏ๊ฮPlanฬถYฬืธ๕
        '                                        'rtn = fSearchPackAP2("1", "1")
        '                                        rtn = fSearchPackAP3("1")
        '                                        If rtn = 1 Then
        '                                            gstrctKDPL.strSearchKey = gstrctAicCase.KeyData
        '                                            'HTCTRLษ—f[^๐’วม
        '                                            BtLib.Transaction.BeginConCurrent()
        '                                            rtn = fUpdateHTCTRL4PL()
        '                                            If rtn = -1 Then
        '                                                BtLib.Transaction.Abort()
        '                                                Exit Sub
        '                                            End If
        '                                            BtLib.Transaction.End()
        '                                            gintStatus = PL_STATUS.PCSCAN
        '                                            fMakeCommandFile(G_CONST_PROCESS_HT_CHG, G_CONST_SPEECH_CHGPALT)
        '                                            Exit Do
        '                                        ElseIf rtn <> 0 Then
        '                                            f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                                            Exit Do
        '                                        End If
        '                                    Case 5
        '                                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                                        fMakeCommandFile(G_CONST_PROCESS_PAL_DEL)
        '#If Not Debug Then
        '                                        fFnc_WrpMsg("E", G_CONST_MID_E1E40)
        '#End If
        '                                        gintStatus = PL_STATUS.PALETTESCN
        '                                        Exit Do
        '                                    Case 4
        '                                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                                        fMakeCommandFile(G_CONST_PROCESS_PAL_DEL)
        '#If Not Debug Then
        '                                        fFnc_WrpMsg("E", G_CONST_MID_E1E20)
        '#End If
        '                                        gintStatus = PL_STATUS.PALETTESCN
        '                                        Exit Do
        '                                    Case 2
        '                                        fMakeCommandFile(G_CONST_PROCESS_PAL_DEL)
        '                                        rtn = fClearSKey2()
        '                                        If rtn <> 0 Then
        '                                            f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                                        End If
        '                                        gintStatus = PL_STATUS.CHKBGN
        '                                        Exit Sub

        '                                    Case 0 'VK์ฌ
        '                                        BtLib.Transaction.BeginConCurrent()
        '                                        'pbg”มZ
        '                                        rtn2 = fUpdPaletteQty(1)
        '                                        If rtn2 = -1 Then
        '                                            BtLib.Transaction.Abort()
        '                                            f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                                            Exit Sub
        '                                        ElseIf rtn2 = 0 Then 'ส฿ฺฏฤ–—e—สตฐสฐ
        '                                            BtLib.Transaction.Abort()
        '                                            sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '#If Not Debug Then
        '                                            fFnc_WrpMsg("E", G_CONST_MID_E1E19)
        '#End If
        '                                            GoTo MENU_BACK  'HTฺ‘ฑ๐—ึ
        '                                        End If
        '                                        If fSetPlan("1", "", 1) = -1 Then
        '                                            BtLib.Transaction.Abort()
        '                                            Exit Sub
        '                                        End If
        '                                        BtLib.Transaction.End()
        '#If Not Debug Then
        '                                        sSetImgFName(G_CONST_MID_H1015, WarpBox1)
        '                                        WarpFrame1.Flush()
        '#End If
        '                                        gstrctPLDispHead.initialize()
        '                                        gstrctPLDispData.initialize()
        '                                        BtLib.Transaction.BeginConCurrent()
        '                                        rtn2 = fMakePackAP(wstrctSPM)
        '                                        If rtn2 = -1 Then
        '                                            'ฬงฒูดืฐ
        '                                            BtLib.Transaction.Abort()
        '                                            Exit Sub
        '                                        End If
        '                                        BtLib.Transaction.End()
        '                                        gstrctKDPL.strSearchKey = gstrctAicCase.KeyData
        '                                        'HTCTRLษ—f[^๐’วม
        '                                        BtLib.Transaction.BeginConCurrent()
        '                                        rtn = fUpdateHTCTRL4PL()
        '                                        If rtn = -1 Then
        '                                            BtLib.Transaction.Abort()
        '                                            Exit Sub
        '                                        End If
        '                                        BtLib.Transaction.End()
        '                                        mint1030status = M1030_STATUS.DONE
        '                                        fMakeCommandFile(G_CONST_PROCESS_PAL_DSP, G_CONST_SPEECH_STRTPAL)
        '                                        sBeepSound(modPublicHT.BEEP_TYPE.B, modPublicHT.BEEP_SELECTION.NG)
        '                                        Exit Do
        '                                    Case -1
        '                                        f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                                        Exit Do
        '                                End Select

        '                            Case M1030_STATUS.NOTCD              'ูศ้o[R[h
        '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                                sOutputLog(gstrctPicsIni.strOutput_KDPL, "KDPL1E30", G_CONST_BC_PART, buf)
        '#If Not Debug Then
        '                                fFnc_WrpMsg("E", G_CONST_MID_E1E30)
        '#End If

        '                            Case M1030_STATUS.DSCAN              '_uXL“
        '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                                fMakeCommandFile(G_CONST_PROCESS_VOICE, G_CONST_SPEECH_DBLSCAN)
        '#If Not Debug Then
        '                                fFnc_WrpMsg("E", G_CONST_MID_E1E32)
        '#End If

        '                            Case M1030_STATUS.NOSRCHKEY          'SearchKeyช–ณข
        '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                                fMakeCommandFile(G_CONST_PROCESS_HT_DEL)
        '#If Not Debug Then
        '                                fFnc_WrpMsg("E", G_CONST_MID_E1E36)
        '#End If
        '                                gintStatus = PL_STATUS.PALETTESCN
        '                                Exit Do

        '                            Case M1030_STATUS.NOTFOUND           'ซ•๏vๆษ–ณข
        '                                gintStatus = PL_STATUS.SUSPEND
        '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                                fMakeCommandFile(G_CONST_PROCESS_HT_ERR, G_CONST_SPEECH_NOTPALT)
        '                                Exit Do

        '                            Case M1030_STATUS.DEFPALT            'ส฿ฺฏฤ
        '                                gintStatus = PL_STATUS.SUSPEND
        '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                                fMakeCommandFile(G_CONST_PROCESS_HT_ERR, G_CONST_SPEECH_NOTPALT)
        '                                Exit Do

        '                            Case M1030_STATUS.ZANINFO
        '                                fMakeCommandFile(G_CONST_PROCESS_LIST)

        '                            Case M1030_STATUS.RESET
        '                                fMakeCommandFile(G_CONST_PROCESS_HT_RTN, G_CONST_SPEECH_HTRESME)

        '                            Case M1030_STATUS.NOTPACK

        '                                gintStatus = PL_STATUS.NOTPACK
        '                                Exit Do

        '                            Case M1030_STATUS.CANCEL
        '                                gintStatus = PL_STATUS.CANCEL
        '                                Exit Do

        '                        End Select

        '                    ElseIf rtn = -1 Then

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

        '                    End If

        '                ElseIf WKey = WKY_ERROR Then

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

        '                ElseIf WKey = WKY_F2 Then 'c”ฦ๏
        '                    'SearchKeyฬ๕
        '                    If fSearchKey(gstrctKDHT.strHdNo, gstrctKDPL.strSearchKey) <> 0 Then
        '                        f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                        Exit Do
        '                    End If
        '                    '>>> ADD ST  2006.03.07 >>>
        '                    'SearchKeyช ๊ฮPackAP๕
        '                    If gstrctKDPL.strSearchKey <> "" Then
        '                        'rtn = fSearchPackAP2("1", "1")
        '                        rtn = fSearchPackAP3("1")
        '                        If rtn = 1 Then
        '                            'gintStatus = PL_STATUS.PCSCAN
        '                            'Exit Do
        '                            gintStatus = PL_STATUS.SHOWLIST
        '                            Exit Do
        '                        ElseIf rtn <> 0 Then
        '                            f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                            Exit Do
        '                        End If
        '                    End If
        '#If Not Debug Then
        '                    fFnc_WrpMsg("E", G_CONST_MID_E1E36)
        '#End If
        '                    gintStatus = PL_STATUS.PALETTESCN
        '                    Exit Do
        '                    '<<< ADD END 2006.03.07 <<<
        '                End If

        '            Loop

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

    Private Function fDecodeScnData(ByVal pstrFlag As String, ByVal pstrScanData As String, ByRef pstrctData As KDPL_DISP_DATA) As Boolean
        fDecodeScnData = False
        Try
            If pstrFlag = "C" OrElse pstrFlag = "B" Then
                With pstrctData
                    .strItemID = Space(1)
                    .strItemCode = Space(30)
                    .strSerial = Space(6)
                    .strCartonNo = RTrim(Mid(pstrScanData, 22, 5))
                    .strAicCaseNo = RTrim(Mid(pstrScanData, 2, 20))
                    .strQty = Space(5)
                    .strLine = gstrctAicCase.Line
                End With
            ElseIf pstrFlag = "P" Then
                With pstrctData
                    .strCartonNo = "00000"
                    .strItemID = "P"
                    .strItemCode = RTrim(Mid(pstrScanData, 2, 13))
                    .strQty = RTrim(Mid(pstrScanData, 15, 5))
                    .strSerial = RTrim(Mid(pstrScanData, 20, 6))
                    .strAicCaseNo = ""
                End With
            End If
            fDecodeScnData = True
        Catch ex As Exception
            sErrLog(gAppName, "sDecodeScnData", ex.ToString)
        End Try
    End Function

    '/*
    '|| ึ”–ผFfProcInput
    '|| T—v  F“—อ—
    '*/
    Private Function fProcInput(ByVal pstrInput As String) As Integer
        Dim rtn As Integer
        Dim rtn2 As Integer
        Dim rtn3 As Integer
        Dim wintAjRtn As Integer
        Dim wstrApKey(7), wstrApKeyValue(7) As String
        Dim wstrApKey2(8), wstrApKeyValue2(8) As String
        Dim wstrctAicCase As STRCT_KEY_AICCASE
        Const KEY01 = "UPD_KEY01"     '—\–๑ฬR[h
        Dim wintFlag As Integer
        Dim tmp As String
        Dim wstrWhere As String

        fProcInput = -1

        Try
            If pstrInput.Length = 19 Then
                wintFlag = 2
            ElseIf pstrInput.Length = 25 Then
                wintFlag = 0
            Else
                wintFlag = -1
            End If

            If pstrInput.StartsWith("C") OrElse pstrInput.StartsWith("P") OrElse pstrInput.StartsWith("B") Then


                If fSearchKey(gstrctKDHT.strHdNo, gstrctKDPL.strSearchKey) <> 0 Then
                    'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
                    MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                    Exit Function
                Else
                    If gstrctKDPL.strSearchKey = "" OrElse gstrctKDPL.strSearchKey Is Nothing Then
                        mint1030status = M1030_STATUS.NOSRCHKEY
                        fProcInput = 0
                        Exit Function
                    End If
                End If

                If pstrInput.StartsWith("P") Then  'ฝทฌ—i•”•ij
                    tmp = Mid(pstrInput, 1, 1) & fBackDispItem(Mid(pstrInput, 2, 10), True) & Mid(pstrInput, 12)
                    pstrInput = tmp
                End If
                If Not fDecodeScnData(Mid(pstrInput, 1, 1), pstrInput, gstrctPLDispData) Then
                    mint1030status = M1030_STATUS.NOTCD
                    fProcInput = 0
                    Exit Function
                End If

                If (pstrInput.StartsWith("C") OrElse pstrInput.StartsWith("B")) AndAlso (gstrctAicCase.AicCaseNo <> gstrctPLDispData.strAicCaseNo) Then
                    mint1030status = M1030_STATUS.DEFPALT
                    fProcInput = 0
                    Exit Function
                End If

                If pstrInput.StartsWith("B") Then  'TuJ[g“อภัมชฏธ–ณต
                    'BtLib.Transaction.BeginConCurrent()
                    rtn = fSearchSubSPM(gstrctPLDispData, wintFlag)
                    If rtn = 1 Then
                        rtn2 = fSearchPackAP("1")
                        fProcInput = fSearchNextData()
                        If fProcInput = 0 Then
                            'BtLib.Transaction.End()
                            Exit Function
                        Else
                            'BtLib.Transaction.Abort()
                            Exit Function
                        End If
                    ElseIf rtn = 0 Then
                        'BtLib.Transaction.Abort()
                        mint1030status = M1030_STATUS.NOTFOUND 'ซ•๏vๆษ–ณขเฬ๐ฝทฌ
                        fProcInput = 0
                        Exit Function
                    Else
                        'BtLib.Transaction.Abort()
                        'gclsDB.fCloseRecord(KEY01)
                        fProcInput = -1
                        Exit Function
                    End If
                Else
                    If pstrInput.StartsWith("C") AndAlso gstrctPLDispData.strCartonNo = "00000" Then
                        'BtLib.Transaction.BeginConCurrent()
                        rtn = fSearchPackAPEx()
                        If rtn = 1 Then
                            rtn2 = fSearchPackAP("1")
                            fProcInput = fSearchNextData()
                            If fProcInput = 0 Then
                                'BtLib.Transaction.End()
                                Exit Function
                            Else
                                'BtLib.Transaction.Abort()
                                Exit Function
                            End If
                        ElseIf rtn = 9 Then
                            'BtLib.Transaction.Abort()
                            mint1030status = M1030_STATUS.NOTFOUND 'ซ•๏vๆษ–ณขเฬ๐ฝทฌ
                            fProcInput = 0
                            Exit Function
                        ElseIf rtn = -1 Then
                            'BtLib.Transaction.Abort()
                            'gclsDB.fCloseRecord(KEY01)
                            If rtn = -1 Then
                                fProcInput = -1
                            ElseIf rtn = -2 Then
                                fProcInput = -2
                            End If
                            Exit Function
                        End If
                    Else
                        wstrApKey(0) = "PaletteID" : wstrApKeyValue(0) = "A"
                        wstrApKey(1) = "ItemGr" : wstrApKeyValue(1) = gstrctAicCase.AicCaseNo & gstrctAicCase.YYYYMMDD & Space(2)
                        wstrApKey(2) = "ItemInID"
                        wstrApKey(3) = "ItemInCode"
                        wstrApKey(4) = "ItemCode"
                        wstrApKey(5) = "ItemID"
                        wstrApKey(6) = "SerialNo"
                        wstrApKey(7) = "TempSerial"
                        If wintFlag = -1 Then
                            wstrApKeyValue(2) = Space(1)
                            wstrApKeyValue(3) = Space(30)
                            wstrApKeyValue(4) = gstrctAicCase.AicCaseNo & gstrctPLDispData.strCartonNo & Space(5)
                            wstrApKeyValue(5) = "C"
                            wstrApKeyValue(6) = Space(6)
                            wstrApKeyValue(7) = Space(6)
                        Else '•”•iตข
                            wstrApKeyValue(2) = "P"
                            wstrApKeyValue(3) = gstrctPLDispData.strItemCode.PadRight(30)
                            wstrApKeyValue(4) = gstrctAicCase.AicCaseNo & gstrctPLDispData.strCartonNo & Space(5)
                            wstrApKeyValue(5) = Space(1)
                            wstrApKeyValue(6) = gstrctPLDispData.strSerial.PadRight(6)
                            wstrApKeyValue(7) = Space(6)
                        End If


                        'ภัm”F
                        wintAjRtn = fSearchPackAJ(wstrApKey, wstrApKeyValue, wintFlag)
                        'wintAjRtn = fSearchPackAJ(wstrApKey, wstrApKeyValue)
                        If wintAjRtn = 1 Then
                            If pstrInput.StartsWith("C") Then
                                '_uฝทฌ
                                mint1030status = M1030_STATUS.DSCAN
                                fProcInput = 0
                                Exit Function
                            End If
                            If wintFlag = 0 Then
                                '_uฝทฌ
                                mint1030status = M1030_STATUS.DSCAN
                                fProcInput = 0
                                Exit Function
                            End If
                        ElseIf wintAjRtn = -1 Then
                            fProcInput = -1
                            Exit Function
                        End If
                        wstrApKey2(0) = "Flag"
                        wstrApKey2(1) = "PaletteID"
                        wstrApKey2(2) = "ItemGr"
                        wstrApKey2(3) = "ItemID"
                        wstrApKey2(4) = "ItemCode"
                        wstrApKey2(5) = "ItemInID"
                        wstrApKey2(6) = "ItemInCode"
                        wstrApKey2(7) = "BunkatuJ"
                        wstrApKey2(8) = "TempSerial"
                        With gstrctAicCase
                            wstrApKeyValue2(0) = "1"
                            wstrApKeyValue2(1) = "A"
                            wstrApKeyValue2(2) = .AicCaseNo & .YYYYMMDD & Space(2)
                            'wstrApKeyValue2(3) = "C"
                            '<--- ADD ST 2006/02/07 --->
                            If wintFlag = -1 Then
                                wstrApKeyValue2(3) = "C"
                            Else  '•”•iตข
                                wstrApKeyValue2(3) = "B"
                            End If
                            '<--- ADD END 2006/02/07 --->
                            wstrApKeyValue2(4) = .AicCaseNo & gstrctPLDispData.strCartonNo & Space(5)
                            wstrApKeyValue2(5) = gstrctPLDispData.strItemID.PadRight(1)
                            wstrApKeyValue2(6) = gstrctPLDispData.strItemCode.PadRight(30)
                            wstrApKeyValue2(7) = gstrctPLDispData.strQty.PadRight(5)
                            wstrApKeyValue2(8) = Space(6)
                        End With
                        rtn = fOpenPackAP(G_CONST_KEY_PACKAPKEY02, KEY01, wstrApKey2, wstrApKeyValue2, wintFlag)
                        If rtn = 1 Then
                            'BtLib.Transaction.BeginConCurrent()
                            rtn2 = fUpdProc(KEY01, wintFlag)
                            If rtn2 = 1 Then
                                fProcInput = fSearchNextData()
                                If fProcInput = 0 Then
                                    'BtLib.Transaction.End()
                                    Exit Function
                                Else
                                    'BtLib.Transaction.Abort()
                                    Exit Function
                                End If
                            Else
                                'BtLib.Transaction.Abort()
                                'gclsDB.fCloseRecord(KEY01)
                                If rtn2 = -2 Then
                                    fProcInput = -2
                                Else
                                    fProcInput = -1
                                End If
                                Exit Function
                            End If
                        ElseIf rtn = 0 Then
                            'gclsDB.fCloseRecord(KEY01)
                            If wintFlag = 0 Then
                                mint1030status = M1030_STATUS.NOTFOUND 'ซ•๏vๆษ–ณขเฬ๐ฝทฌ
                                fProcInput = 0
                                Exit Function
                            ElseIf wintFlag = 2 Then
                                If wintAjRtn = 1 Then
                                    mint1030status = M1030_STATUS.DSCAN
                                    fProcInput = 0
                                    Exit Function
                                ElseIf wintAjRtn = 0 Then
                                    mint1030status = M1030_STATUS.NOTFOUND 'ซ•๏vๆษ–ณขเฬ๐ฝทฌ
                                    fProcInput = 0
                                    Exit Function
                                End If
                            End If
                        ElseIf rtn = -1 Then
                            fProcInput = -1
                            Exit Function
                        End If
                    End If
                End If

            ElseIf pstrInput.StartsWith("A") Then
                'pbg”ฒฏ—
                sDecodeScanData2AicCase(wstrctAicCase, pstrInput)
                If gstrctAicCase.AicCaseNo = wstrctAicCase.AicCaseNo Then
                    mint1030status = M1030_STATUS.ESCAICCASE
                    fProcInput = 0
                    Exit Function
                Else
                    With gstrctAicCase
                        .AicCaseNo = wstrctAicCase.AicCaseNo
                        .CaseNo = wstrctAicCase.CaseNo
                        .Gr = wstrctAicCase.Gr
                        .KeyData = Mid(pstrInput, 2)
                        .Line = wstrctAicCase.Line
                        .Lot = wstrctAicCase.Lot
                        .Msc = wstrctAicCase.Msc
                        .Msc_Disp = wstrctAicCase.Msc_Disp
                        .PackSeq = wstrctAicCase.PackSeq
                        .Trm = wstrctAicCase.Trm
                        .Pnt = wstrctAicCase.Pnt
                        .Seq = wstrctAicCase.Seq
                        .YYYYMMDD = wstrctAicCase.YYYYMMDD
                    End With
                    mint1030status = M1030_STATUS.CHGPALT
                    fProcInput = 0
                    Exit Function
                End If

            ElseIf pstrInput = "OCZANINFO" Then
                mint1030status = M1030_STATUS.ZANINFO
                fProcInput = 0
                Exit Function

            ElseIf pstrInput = "OCMENUBACK" Then

                mint1030status = M1030_STATUS.MENUBACK
                fProcInput = 0
                Exit Function

            ElseIf pstrInput = "OCRESET" Then
                mint1030status = M1030_STATUS.RESET
                fProcInput = 0
                Exit Function

            ElseIf pstrInput = "OCNOTPACK" Then
                mint1030status = M1030_STATUS.NOTPACK
                fProcInput = 0
                Exit Function

            ElseIf pstrInput = "OCCANCEL" Then
                mint1030status = M1030_STATUS.CANCEL
                fProcInput = 0
                Exit Function

            Else
                mint1030status = M1030_STATUS.NOTCD
                fProcInput = 0
            End If

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

    Private Function fSearchSubSPM(ByVal pstrctPLData As KDPL_DISP_DATA, Optional ByVal pstrKeyFlag As Integer = 0) As Integer
        Dim wstrKey(8), wstrKeyValue(8) As String
        Dim wintRet, wintRet2 As Integer
        Dim wstrItemGr, wstrItemInCode As String
        Dim wstrWhere As String
        fSearchSubSPM = -1

        wstrKey(0) = "Flag" : wstrKeyValue(0) = "1"
        wstrKey(1) = "PaletteID" : wstrKeyValue(1) = "A"
        wstrKey(2) = "ItemGr" : wstrKeyValue(2) = gstrctAicCase.AicCaseNo & gstrctAicCase.YYYYMMDD
        wstrKey(3) = "ItemID" : wstrKeyValue(3) = "B"
        wstrKey(4) = "ItemCode" : wstrKeyValue(4) = gstrctAicCase.AicCaseNo & gstrctPLDispData.strCartonNo
        wstrKey(5) = "ItemInID" : wstrKeyValue(5) = Space(1)
        wstrKey(6) = "ItemInCode" : wstrKeyValue(6) = Space(30)
        wstrKey(7) = "BunkatuJ" : wstrKeyValue(7) = Space(5)
        wstrKey(8) = "TempSerial" : wstrKeyValue(8) = Space(6)

        wintRet = -1
        Try
            wstrWhere = ""
            wstrWhere = wstrKey(0) & " = '" & wstrKeyValue(0) & "'"
            wstrWhere &= " and " & wstrKey(1) & " = '" & wstrKeyValue(1) & "'"
            wstrWhere &= " and " & wstrKey(2) & " = '" & wstrKeyValue(2) & "'"
            wstrWhere &= " and " & wstrKey(3) & " = '" & wstrKeyValue(3) & "'"
            wstrWhere &= " and " & wstrKey(4) & " = '" & wstrKeyValue(4) & "'"
            wstrWhere &= " and " & wstrKey(5) & " = '" & wstrKeyValue(5) & "'"
            wstrWhere &= " and " & wstrKey(6) & " = '" & wstrKeyValue(6) & "'"
            wstrWhere &= " and " & wstrKey(7) & " = '" & wstrKeyValue(7) & "'"
            wstrWhere &= " and " & wstrKey(8) & " = '" & wstrKeyValue(8) & "'"

            tmpStr = dbClient.Query("SELECT * FROM " + G_CONST_TBL_PACKAP + " WHERE " + wstrWhere)

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sKey0 As String = ""
            Dim sKey1 As String = ""
            Dim sKey2 As String = ""
            Dim sKey3 As String = ""
            Dim sKey4 As String = ""
            Dim i As Integer = 0

            If tmpStr.Count > 0 Then
                Try

                    Do
                        values = tmpStr(i)

                        Dim result As String = Nothing
                        If values.TryGetValue(wstrKey(0), result) Then
                            sKey0 = RTrim(result)
                        End If
                        If values.TryGetValue(wstrKey(1), result) Then
                            sKey1 = RTrim(result)
                        End If
                        If values.TryGetValue(wstrKey(2), result) Then
                            sKey2 = RTrim(result)
                        End If
                        If values.TryGetValue(wstrKey(3), result) Then
                            sKey3 = RTrim(result)
                        End If
                        If values.TryGetValue(wstrKey(4), result) Then
                            sKey4 = RTrim(result)
                        End If

                        If RTrim(wstrKeyValue(0)) = RTrim(sKey0) AndAlso RTrim(wstrKeyValue(1)) = RTrim(sKey1) AndAlso _
                           RTrim(wstrKeyValue(2)) = RTrim(sKey2) AndAlso RTrim(wstrKeyValue(3)) = RTrim(sKey3) AndAlso _
                           RTrim(wstrKeyValue(4)) = RTrim(sKey4) Then


                            If fUpdProc2(KEY_PACKAP2, pstrKeyFlag) = -1 Then Exit Function
                            fSearchSubSPM = 1

                        Else

                            Exit Function

                        End If


                        i = i + 1

                        If tmpStr.Count = i Then
                            Exit Do
                        End If

                    Loop

                Catch ex As Exception
                    Exit Function
                End Try

            End If

        Catch ex As Exception
            fSearchSubSPM = -1
            'If wintRet <> -1 Then
            '    gclsDB.fCloseRecord(KEY_PACKAP2)
            '    wintRet = -1
            'End If
            sErrLog(gAppName, "fSearchSubSPM", ex.ToString)
        Finally
            'If wintRet <> -1 Then
            '    gclsDB.fCloseRecord(KEY_PACKAP2)
            If fSearchSubSPM <> 1 Then fSearchSubSPM = 0
            'End If
        End Try




        'PackAPฉ็PackAJึ
        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKAP, G_CONST_KEY_PACKAPKEY02, KEY_PACKAP2, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'If wintRet <> 0 Then
        '    Exit Function
        'Else
        '    Do
        '        With gclsDB.Records(KEY_PACKAP2)
        '            If RTrim(wstrKeyValue(0)) = RTrim(.Item(wstrKey(0))) AndAlso RTrim(wstrKeyValue(1)) = RTrim(.Item(wstrKey(1))) AndAlso _
        '               RTrim(wstrKeyValue(2)) = RTrim(.Item(wstrKey(2))) AndAlso RTrim(wstrKeyValue(3)) = RTrim(.Item(wstrKey(3))) AndAlso _
        '               RTrim(wstrKeyValue(4)) = RTrim(.Item(wstrKey(4))) Then
        '                'XV—
        '                If fUpdProc2(KEY_PACKAP2, pstrKeyFlag) = -1 Then Exit Function
        '                fSearchSubSPM = 1
        '                If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Function
        '            Else
        '                Exit Function
        '            End If
        '        End With
        '    Loop
        'End If
        'Catch ex As Exception
        '    fSearchSubSPM = -1
        '    If wintRet <> -1 Then
        '        gclsDB.fCloseRecord(KEY_PACKAP2)
        '        wintRet = -1
        '    End If
        '    sErrLog(gAppName, "fSearchSubSPM", ex.ToString)
        'Finally
        '    If wintRet <> -1 Then
        '        gclsDB.fCloseRecord(KEY_PACKAP2)
        '        If fSearchSubSPM <> 1 Then fSearchSubSPM = 0
        '    End If
        'End Try
    End Function

    Private Function fSearchNextData() As Integer
        Dim rtn, rtn3, rtn2 As Integer
        fSearchNextData = -1
        rtn = fSearchPackAP()
        Select Case rtn
            Case 0 'PACKAPI—น
                'PLANฬXV
                rtn2 = fSetPlan("4", "", 2)
                If rtn2 <> 1 Then
                    Exit Function
                End If
                'VanPJฬXV
                rtn3 = fSetVanPJ("5")
                If rtn3 = -1 Then
                    Exit Function
                End If
                'ส฿ฺฏฤ”ฬธZ
                rtn3 = fUpdPaletteQty(0)
                If rtn3 = -1 Then
                    Exit Function
                End If
                mint1030status = M1030_STATUS.CMPLTCHK
                fSearchNextData = 0
            Case 1
                mint1030status = M1030_STATUS.DONE
                gstrctPLDispData.intCheckCnt += 1
                fSearchNextData = 0
            Case Else
                fSearchNextData = -1
        End Select
    End Function

    Private Sub frm1030_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Dim rtn As Integer
        Select Case e.KeyCode.ToString()
            Case "Return"
                If fSearchKey(gstrctKDHT.strHdNo, gstrctKDPL.strSearchKey) <> 0 Then
                    'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(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

                'ๆ–สฤ•\ฆ
                gstrctPLDispHead.initialize()
                gstrctPLDispData.initialize()

                'SearchKeyช ๊ฮPackAP๕
                If gstrctKDPL.strSearchKey <> "" Then
                    'rtn = fSearchPackAP2("1", "1")

                    rtn = fSearchPackAP3("1")
                    If rtn = 1 Then

                        RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                        btScanLib.Disable()

                        gintStatus = PL_STATUS.PCSCAN
                        Me.Close()
                        'Exit Do
                    ElseIf rtn <> 0 Then
                        'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
                        MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                        'Exit Do
                    End If
                End If
                'SearchKeyช–ณข
#If Not Debug Then
                    fFnc_WrpMsg("E", G_CONST_MID_E1E36)
#End If

                RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                btScanLib.Disable()

                gintStatus = PL_STATUS.PALETTESCN
                Me.Close()
                Exit Sub
            Case "F1"
            Case "F2"
                If fSearchKey(gstrctKDHT.strHdNo, gstrctKDPL.strSearchKey) <> 0 Then
                    'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
                    MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                    'Exit Do
                End If
                '>>> ADD ST  2006.03.07 >>>
                'SearchKeyช ๊ฮPackAP๕
                If gstrctKDPL.strSearchKey <> "" Then
                    'rtn = fSearchPackAP2("1", "1")
                    rtn = fSearchPackAP3("1")
                    If rtn = 1 Then
                        'gintStatus = PL_STATUS.PCSCAN
                        'Exit Do

                        RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                        btScanLib.Disable()

                        gintStatus = PL_STATUS.SHOWLIST
                        Me.Close()
                        'Exit Do
                    ElseIf rtn <> 0 Then
                        'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
                        MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                        'Exit Do
                    End If
                End If
#If Not Debug Then
                    fFnc_WrpMsg("E", G_CONST_MID_E1E36)
#End If
                RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                btScanLib.Disable()

                gintStatus = PL_STATUS.PALETTESCN
                Me.Close()
                Exit Sub
        End Select
    End Sub

    Private Sub frm1030_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


