﻿
'*******************************************************************************
'* ์ฌ๏ะ : ”ฎ๏ะGR[EVXe€
'* ์ฌา   : บv• ‘s—Y
'* ์ฌ“๚   : 2010/08/09
'* T—v     : •จ•i๖๓ ฺ“ฎ
'* XV——๐ : 
'* สฐผฎ  : 1.0
'*******************************************************************************
'Imports WarpControl.WarpApi2
'Imports CommonMove.clsBTRFile
'Imports CommonMove.clsConst

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 PMMV1000.BtScanLib
Imports BTClientLib
Imports System.IO
Imports System.Reflection
Imports BtScan2

Public Class frmPMMV1015
    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
    Public tmpStr_TBLKEY As List(Of Dictionary(Of String, String))

#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 WarpHWBcr1 As WarpControl.WarpHWBcr
    'Friend WithEvents wfName As WarpControl.WarpField
    'Friend WithEvents WarpField2 As WarpControl.WarpField
    'Friend WithEvents wfCount As WarpControl.WarpField
    'Friend WithEvents wfInfo1 As WarpControl.WarpField
    'Friend WithEvents wfInfo2 As WarpControl.WarpField
    'Friend WithEvents wfType As WarpControl.WarpField
    'Friend WithEvents wfInput As WarpControl.WarpField
    'Friend WithEvents WarpBox1 As WarpControl.WarpBox

    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame
    '    Me.WarpBox1 = New WarpControl.WarpBox
    '    Me.wfInput = New WarpControl.WarpField
    '    Me.wfType = New WarpControl.WarpField
    '    Me.wfInfo2 = New WarpControl.WarpField
    '    Me.wfInfo1 = New WarpControl.WarpField
    '    Me.wfCount = New WarpControl.WarpField
    '    Me.WarpField2 = New WarpControl.WarpField
    '    Me.wfName = New WarpControl.WarpField
    '    Me.WarpHWBcr1 = New WarpControl.WarpHWBcr
    '    Me.WarpFrame1.SuspendLayout()
    '    Me.SuspendLayout()
    '    '
    '    'WarpFrame1
    '    '
    '    Me.WarpFrame1.BackColor = CType(3, Short)
    '    Me.WarpFrame1.Controls.Add(Me.WarpBox1)
    '    Me.WarpFrame1.Controls.Add(Me.wfInput)
    '    Me.WarpFrame1.Controls.Add(Me.wfType)
    '    Me.WarpFrame1.Controls.Add(Me.wfInfo2)
    '    Me.WarpFrame1.Controls.Add(Me.wfInfo1)
    '    Me.WarpFrame1.Controls.Add(Me.wfCount)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField2)
    '    Me.WarpFrame1.Controls.Add(Me.wfName)
    '    Me.WarpFrame1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
    '    Me.WarpFrame1.Location = New System.Drawing.Point(0, 0)
    '    Me.WarpFrame1.Name = "WarpFrame1"
    '    Me.WarpFrame1.Size = New System.Drawing.Size(160, 160)
    '    Me.WarpFrame1.TabIndex = 1
    '    Me.WarpFrame1.Text = "WarpFrame1"
    '    Me.WarpFrame1.UseMacro = False
    '    Me.WarpFrame1.UseMacroFileName = ""
    '    '
    '    'WarpBox1
    '    '
    '    Me.WarpBox1.BackColor = CType(3, Short)
    '    Me.WarpBox1.BoxType = WarpControl.BoxTypes.Box
    '    Me.WarpBox1.DrawMode = WarpControl.DrawModes.Paint
    '    Me.WarpBox1.Font = New System.Drawing.Font("Lucida Console", 14.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpBox1.ForeColor = CType(3, Short)
    '    Me.WarpBox1.Image = ""
    '    Me.WarpBox1.Location = New System.Drawing.Point(0, 122)
    '    Me.WarpBox1.Name = "WarpBox1"
    '    Me.WarpBox1.Size = New System.Drawing.Size(160, 17)
    '    Me.WarpBox1.TabIndex = 53
    '    Me.WarpBox1.Text = "Echo System"
    '    '
    '    'wfInput
    '    '
    '    Me.wfInput.BackColor = CType(3, Short)
    '    Me.wfInput.BcrFlag = True
    '    Me.wfInput.DecimalPointPosition = CType(0, Short)
    '    Me.wfInput.Font = New System.Drawing.Font("Lucida Console", 14.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfInput.Format = ""
    '    Me.wfInput.InputMode.Secret = True
    '    Me.wfInput.Length = CType(1, Short)
    '    Me.wfInput.Location = New System.Drawing.Point(6, 4)
    '    Me.wfInput.MacroBcr = ""
    '    Me.wfInput.MacroIn = ""
    '    Me.wfInput.MacroKey = ""
    '    Me.wfInput.MacroOut = ""
    '    Me.wfInput.Name = "wfInput"
    '    Me.wfInput.Size = New System.Drawing.Size(12, 24)
    '    Me.wfInput.TabIndex = CType(52, Short)
    '    '
    '    'wfType
    '    '
    '    Me.wfType.BackColor = CType(3, Short)
    '    Me.wfType.DecimalPointPosition = CType(0, Short)
    '    Me.wfType.Font = New System.Drawing.Font("Lucida Console", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfType.FontSize = WarpControl.FontSizes.Small
    '    Me.wfType.Format = ""
    '    Me.wfType.Length = CType(16, Short)
    '    Me.wfType.Location = New System.Drawing.Point(0, 52)
    '    Me.wfType.MacroBcr = ""
    '    Me.wfType.MacroIn = ""
    '    Me.wfType.MacroKey = ""
    '    Me.wfType.MacroOut = ""
    '    Me.wfType.Name = "wfType"
    '    Me.wfType.Size = New System.Drawing.Size(160, 20)
    '    Me.wfType.TabIndex = CType(51, Short)
    '    Me.wfType.Text = "[Parts]"
    '    '
    '    'wfInfo2
    '    '
    '    Me.wfInfo2.BackColor = CType(3, Short)
    '    Me.wfInfo2.DecimalPointPosition = CType(0, Short)
    '    Me.wfInfo2.Font = New System.Drawing.Font("Lucida Console", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfInfo2.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfInfo2.Format = ""
    '    Me.wfInfo2.Length = CType(20, Short)
    '    Me.wfInfo2.Location = New System.Drawing.Point(0, 102)
    '    Me.wfInfo2.MacroBcr = ""
    '    Me.wfInfo2.MacroIn = ""
    '    Me.wfInfo2.MacroKey = ""
    '    Me.wfInfo2.MacroOut = ""
    '    Me.wfInfo2.Name = "wfInfo2"
    '    Me.wfInfo2.Size = New System.Drawing.Size(160, 16)
    '    Me.wfInfo2.TabIndex = CType(50, Short)
    '    Me.wfInfo2.Text = "XXXXXXX-XX-XX"
    '    '
    '    'wfInfo1
    '    '
    '    Me.wfInfo1.BackColor = CType(3, Short)
    '    Me.wfInfo1.DecimalPointPosition = CType(0, Short)
    '    Me.wfInfo1.Font = New System.Drawing.Font("Lucida Console", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfInfo1.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfInfo1.Format = ""
    '    Me.wfInfo1.Length = CType(20, Short)
    '    Me.wfInfo1.Location = New System.Drawing.Point(0, 78)
    '    Me.wfInfo1.MacroBcr = ""
    '    Me.wfInfo1.MacroIn = ""
    '    Me.wfInfo1.MacroKey = ""
    '    Me.wfInfo1.MacroOut = ""
    '    Me.wfInfo1.Name = "wfInfo1"
    '    Me.wfInfo1.Size = New System.Drawing.Size(160, 16)
    '    Me.wfInfo1.TabIndex = CType(49, Short)
    '    Me.wfInfo1.Text = "XXXX-XX-XXXX XX X"
    '    '
    '    'wfCount
    '    '
    '    Me.wfCount.BackColor = CType(3, Short)
    '    Me.wfCount.DecimalPointPosition = CType(0, Short)
    '    Me.wfCount.Font = New System.Drawing.Font("Lucida Console", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfCount.FontSize = WarpControl.FontSizes.Small
    '    Me.wfCount.Format = ""
    '    Me.wfCount.Length = CType(3, Short)
    '    Me.wfCount.Location = New System.Drawing.Point(124, 4)
    '    Me.wfCount.MacroBcr = ""
    '    Me.wfCount.MacroIn = ""
    '    Me.wfCount.MacroKey = ""
    '    Me.wfCount.MacroOut = ""
    '    Me.wfCount.Name = "wfCount"
    '    Me.wfCount.Size = New System.Drawing.Size(30, 20)
    '    Me.wfCount.TabIndex = CType(48, Short)
    '    Me.wfCount.Text = "999"
    '    '
    '    'WarpField2
    '    '
    '    Me.WarpField2.BackColor = CType(3, Short)
    '    Me.WarpField2.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField2.Font = New System.Drawing.Font("Lucida Console", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField2.FontSize = WarpControl.FontSizes.Small2
    '    Me.WarpField2.Format = ""
    '    Me.WarpField2.Length = CType(5, Short)
    '    Me.WarpField2.Location = New System.Drawing.Point(78, 7)
    '    Me.WarpField2.MacroBcr = ""
    '    Me.WarpField2.MacroIn = ""
    '    Me.WarpField2.MacroKey = ""
    '    Me.WarpField2.MacroOut = ""
    '    Me.WarpField2.Name = "WarpField2"
    '    Me.WarpField2.Size = New System.Drawing.Size(40, 16)
    '    Me.WarpField2.TabIndex = CType(47, Short)
    '    Me.WarpField2.Text = "Scan:"
    '    '
    '    'wfName
    '    '
    '    Me.wfName.BackColor = CType(3, Short)
    '    Me.wfName.DecimalPointPosition = CType(0, Short)
    '    Me.wfName.Font = New System.Drawing.Font("Lucida Console", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfName.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfName.Format = ""
    '    Me.wfName.InputAttribute.Reverse = True
    '    Me.wfName.InputMode.Clear = True
    '    Me.wfName.Length = CType(12, Short)
    '    Me.wfName.Location = New System.Drawing.Point(32, 144)
    '    Me.wfName.MacroBcr = ""
    '    Me.wfName.MacroIn = ""
    '    Me.wfName.MacroKey = ""
    '    Me.wfName.MacroOut = ""
    '    Me.wfName.Name = "wfName"
    '    Me.wfName.Size = New System.Drawing.Size(96, 16)
    '    Me.wfName.TabIndex = CType(44, Short)
    '    Me.wfName.Text = "Echo System"
    '    '
    '    'WarpHWBcr1
    '    '
    '    Me.WarpHWBcr1.Decode.Code39 = True
    '    Me.WarpHWBcr1.Decode.UPC_EAN_JAN = 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)
    '    '
    '    'frmPMMV1015
    '    '
    '    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    '    Me.ClientSize = New System.Drawing.Size(160, 160)
    '    Me.Controls.Add(Me.WarpFrame1)
    '    Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
    '    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
    '    Me.Name = "frmPMMV1015"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region

#Region "// Param Area /////////////////////////////////////////////////////////////////////////////"

    Private mintStatus As M_STATUS              'ฝรฐภฝ๎•๑

    Private mstructItem As G_STRUCT_HTSUB       'ือูฝทฌ๎•๑

#End Region

#Region "// Enum Area ///////////////////////////////////////////////////////////////////////////"

    'ฝรฐภฝ—๑“^
    Private Enum M_STATUS As Integer
        INIT                '๚ป
        MENUBACK            'าฦญฐสฏธ
        CANCEL              'ทฌพู
        ERROR_ID            'IDดืฐ
        DATA_NOT            'รฐภ–ณต
        DBL_SCAN            'ภฬูฝทฌ
        ERROR_OTHER         'ปฬ‘ผฝทฌดืฐ
        SCAN_OTHER          'ปฬ‘ผ
        SCAN_ZERO           '–ขฝทฌ
        SCAN_OK             'OKฝทฌ
        SCAN_NEXT           'ฬฑฒรัฝทฌ
    End Enum

#End Region

#Region "// Ivent Area /////////////////////////////////////////////////////////////////////////"

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

    '*******************************************************************************
    ' T—v      : tH[€[h—
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Sub frm_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

        gstrFuncName = "frm_Load"

        Dim wstrImage As String
        Dim rtn As Integer

        Try
            '๚ฝรฐภฝ
            mintStatus = M_STATUS.INIT

            '•ฯ”๚ป
            Call gstructHtData.Initialize(gintStatus)

            'ฬฺฐัฬตฐฬ฿
            'rtn = Me.WarpFrame1.Open()
            'If (rtn <> 0) Then Err.Raise(vbObjectError + 1, gclsPub.gAppName, "WarpError")

            'ๆ–ส–ผพฏฤ (ฺ“ฎ‘ฮ๐ฝทฌ)
            'gclsPubHT.sSetImgFName(CommonMove.clsMsgID.H2030, WarpBox1)

            'ๆ–ส•\ฆ—
            Call wsDisp()

            'ฬซฐัฅาฒ ภs
            Call wsMain()

            'ฬฺฐัฬธฐฝ
            'rtn = Me.WarpFrame1.Close()
            'If (rtn <> 0) Then Err.Raise(vbObjectError + 1, gclsPub.gAppName, "WarpError")

            'ฬซฐัฅธฐฝ
            'Me.Close()

        Catch ex As Exception
            gintStatus = G_ENUM_STATUS.QUIT
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_WARNING, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
            Me.Close()
            Exit Sub
        End Try
    End Sub

#End Region

#Region "// \bh—GA /////////////////////////////////////////////////////////////////////////"

#Region "-- Main -------------------------------------------------------------------------------"

#Region "--Input Area -------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : t[€EC“—
    ' ๘”      : ศต
    ' –฿่’l    : ศต
    ' ”๕l      : ศต
    '*******************************************************************************

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

        Call wfBarcodeMain(buf)


    End Sub

    Public Sub wsMain()
        'gstrFuncName = "wsMain"

        'Dim WKey As Short

        'Try
        '    ' t[€ฬ—๐ฑฑษLqตทB
        '    Do While (True)
        '        ' R[h“—อ
        '        WKey = WarpFrame1.Input(wfInput)
        '        gclsPubHT.sBeepSound(CommonMove.clsPublicHT.BEEP_TYPE.A, CommonMove.clsPublicHT.BEEP_SELECTION.OK, gfrmMain.WarpCtrl1)

        '        Select Case WKey
        '            Case WKY_BCR
        '                '// สฐบฐฤ“—อ
        '                Call wfBarcodeMain()
        '                Exit Do

        '            Case WKY_ERROR
        '                'ดืฐาฏพฐผ•\ฆ
        '                gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, G_CONST_EM_WARP, MWA_DB_WARNING, MWA_DB_OK)
        '                Exit Do
        '        End Select
        '    Loop

        'Catch ex As Exception
        '    gintStatus = G_ENUM_STATUS.QUIT
        '    gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
        '    gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_WARNING, MWA_DB_OK)
        'End Try
    End Sub

#End Region

#Region "---- ๆ–ส•\ฆ -------------------------------------------------------------------------"

    Private Const M_CONST_TYPE_PARTS As String = "[Parts]"
    Private Const M_CONST_TYPE_CASE As String = "[Case]"
    Private Const M_CONST_TYPE_CARTON As String = "[Carton]"
    Private Const M_CONST_TYPE_OTHER As String = "[Other]"

    '*******************************************************************************
    ' T—v      : ๆ–ส•\ฆ
    ' ๘”      : ศต
    ' –฿่’l    : ศต
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Sub wsDisp()
        Dim wstrType As String = ""

        '// ถณฤ
        wfCount.Text = gstructHtData.ITEM_COUNT.ToString.PadLeft(2)

        '// ‘O๑ฝทฌ๎•๑
        Select Case gstructHtData.LastID
            Case clsConst.G_CONST_BARCDID_PARTS
                '•”•i
                wstrType = M_CONST_TYPE_PARTS

            Case clsConst.G_CONST_BARCDID_CASE
                'นฐฝ
                wstrType = M_CONST_TYPE_CASE

            Case clsConst.G_CONST_BARCDID_CARTON
                'ถฐฤ
                wstrType = M_CONST_TYPE_CARTON

            Case clsConst.G_CONST_BARCD_OTHER
                'ปฬ‘ผ
                wstrType = M_CONST_TYPE_OTHER
        End Select

        If gstructHtData.OtherScan Then
            'ปฬ‘ผ(0ลเ•\ฆ)
            wstrType = M_CONST_TYPE_OTHER
        End If

        wfType.Text = wstrType
        wfInfo1.Text = Space(1) & gstructHtData.LastInfo1
        wfInfo2.Text = Space(1) & gstructHtData.LastInfo2

        'ีฐปฐ–ผ
        wfName.Text = gclsPubHT.gstrctPPHT.strUserName
    End Sub

    '*******************************************************************************
    ' T—v      : ๆ–ส’่
    ' ๘”      : buf       String      สฐบฐฤ“—อ’l
    ' –฿่’l    : ศต
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Sub wsSetNextStatus()
        gstrFuncName = "wsSetNextStatus"

        Try
            'eดืฐๆ–สฬ•\ฆ
            Select Case mintStatus
                Case M_STATUS.INIT
                    '// ฉๆ–ส

                Case M_STATUS.MENUBACK
                    '// าฦญฐสฏธ

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

                    gintStatus = G_ENUM_STATUS.NAME
                    Me.Close()
                    Exit Sub

                Case M_STATUS.CANCEL
                    '// ทฌพู

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

                    gintStatus = G_ENUM_STATUS.ITEM_FIRST
                    Me.Close()
                    Exit Sub

                Case M_STATUS.ERROR_ID
                    '// •sณศสฐบฐฤลท
                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E2010, gfrmMain.WarpCtrl1)

                Case M_STATUS.DATA_NOT
                    '// Y“–รฐภศต
                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E2020, gfrmMain.WarpCtrl1)

                Case M_STATUS.DBL_SCAN
                    '// ภฬูฝทฌ
                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E0230, gfrmMain.WarpCtrl1)

                Case M_STATUS.SCAN_ZERO
                    '// –ขฝทฌ
                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E2040, gfrmMain.WarpCtrl1)

                Case M_STATUS.SCAN_OTHER
                    '// ปฬ‘ผฝทฌำฐฤึ
                    'gintStatus = G_ENUM_STATUS.ITEM_OTHER

                Case M_STATUS.ERROR_OTHER
                    '// ปฬ‘ผฝทฌดืฐ
                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E2010, gfrmMain.WarpCtrl1)

                Case M_STATUS.SCAN_OK
                    '// ฝทฌOK

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

                    gintStatus = G_ENUM_STATUS.IP_SCAN
                    Me.Close()
                    Exit Sub

                Case M_STATUS.SCAN_NEXT
                    '// ฬฑฒรั

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

                    gintStatus = G_ENUM_STATUS.ITEM_SCAN
                    Me.Close()
                    Exit Sub
            End Select

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Sub
        End Try
    End Sub
#End Region

#End Region

#Region "-- Barcode Area ---------------------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : Barcode Area@C“
    ' ๘”      : 
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfBarcodeMain(ByVal result As String) As Boolean
        gstrFuncName = "wfBarcodeMain"

        Dim wintRet As Integer
        Dim wstrBuf As String = result

        Try
            '// สฐบฐฤ“—อ
            'wintRet = WarpHWBcr1.Get(wstrBuf)
            'If wintRet <> 0 Then
            '    gintStatus = MainModule.G_ENUM_STATUS.QUIT
            '    Err.Raise(vbObjectError + 1, gclsPub.gAppName, "WarpError")
            '    Return False
            'End If

            '// สฐบฐฤ“เ—eมชฏธ
            If Not wfCheckBarcode(wstrBuf) Then Return False

            '// Barcode Area
            If Not wfProcInput(wstrBuf) Then Return False

            '// ๆ–ส’่
            Call wsSetNextStatus()

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : สฐบฐฤ“เ—eมชฏธ
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfCheckBarcode(ByRef pstrInput As String) As Boolean
        gstrFuncName = "wfCheckBarcode"

        Dim rtn As Integer

        Try
            '// ปฬ‘ผสฐบฐฤฝทฌำฐฤฬ๊
            If gstructHtData.OtherScan Then
                If pstrInput.Length > 2 AndAlso pstrInput.Substring(1, 2) = clsConst.G_CONST_BARCDID_OC Then
                    '// OCสฐบฐฤ
                    'มชฏธรจผฏฤมชฏธ
                    If Not gclsPubHT.fCheckCode(pstrInput) Then
                        'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E2050, gfrmMain.WarpCtrl1)
                        Return False
                    End If
                Else
                    '// ปฬ‘ผสฐบฐฤ
                    If pstrInput.StartsWith("B") Then pstrInput = pstrInput.Substring(1)
                End If

                Return True
            End If

            '// นฐฝือู(16…สฐบฐฤ)อมชฏธตศข
            If pstrInput.StartsWith("B") AndAlso pstrInput.Length = 17 Then pstrInput = pstrInput.Substring(1, 16)
            If pstrInput.StartsWith(clsConst.G_CONST_BARCDID_CASE) AndAlso pstrInput.Length = 16 Then Return True

            '// มชฏธรจผฏฤ
            If Not gclsPubHT.fCheckCode(pstrInput) Then
                'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E2050, gfrmMain.WarpCtrl1)
                Return False
            End If

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : Barcode Area
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    '           : vblnExist     Boolean     ๕ส(True:‘ถ / False:–ข‘ถ)
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfProcInput(ByVal pstrInput As String) As Boolean
        gstrFuncName = "wfProcInput"

        Dim wblnScanOK As Boolean = False
        Dim rtn As Integer

        Try
            '// OCสฐบฐฤ
            If wfOCBarcode(pstrInput) Then Return True

            '// ภฬูฝทฌมชฏธ
            If Not wfCheckDoubleScan(pstrInput) Then Return True

            '// สฐบฐฤIDมชฏธ
            If wfCheckBarcodeID(pstrInput) = gstructHtData.OtherScan Then
                '’สํฝทฌอP/J/Cฦ•s๊’vAปฬ‘ผสฐบฐฤฝทฌำฐฤอ๊’vท้ฦดืฐ
                mintStatus = M_STATUS.ERROR_ID
                Return True
            End If

            '// ID•ส—
            Select Case True
                Case pstrInput.StartsWith(clsConst.G_CONST_BARCDID_PARTS)
                    '•”•i
                    If Not wfCheckPartsMain(pstrInput, wblnScanOK) Then Return False

                Case pstrInput.StartsWith(clsConst.G_CONST_BARCDID_CASE)
                    'นฐฝ
                    If Not wfCheckCaseMain(pstrInput, wblnScanOK) Then Return False

                Case pstrInput.StartsWith(clsConst.G_CONST_BARCDID_CARTON)
                    'ถฐฤ
                    If Not wfCheckCartonMain(pstrInput, wblnScanOK) Then Return False

                Case Else
                    'ปฬ‘ผ
                    If Not wfCheckOtherMain(pstrInput, wblnScanOK) Then Return False
            End Select

            '// ฝทฌOKมชฏธ
            If Not wblnScanOK Then Return True

            '// ๎•๑ๆ“พ
            Call wsGetScanData()

            mintStatus = M_STATUS.SCAN_NEXT

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : สฐบฐฤIDมชฏธ
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    ' –฿่’l    : Boolean       True:‘ฮสฐบฐฤ / False:ปฬ‘ผสฐบฐฤ
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfCheckBarcodeID(ByVal pstrInput As String) As Boolean
        gstrFuncName = "wfCheckBarcodeID"

        Try
            '// •”•i
            If pstrInput.StartsWith(clsConst.G_CONST_BARCDID_PARTS) Then Return True

            '// นฐฝ
            If pstrInput.StartsWith(clsConst.G_CONST_BARCDID_CASE) Then Return True

            '// ถฐฤ
            If pstrInput.StartsWith(clsConst.G_CONST_BARCDID_CARTON) Then Return True

            Return False

        Catch ex As Exception
            Throw ex
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : OCo[R[h—
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    ' –฿่’l    : Boolean       True:OCสฐบฐฤ / False:ึ
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfOCBarcode(ByVal pstrInput As String) As Boolean
        gstrFuncName = "wfOCBarcode"

        Try
            '// OCสฐบฐฤ
            Select Case pstrInput.TrimEnd
                Case clsConst.G_CONST_BARCD_OTHER
                    '// ปฬ‘ผสฐบฐฤ
                    If Not wfOtherMain() Then Return True
                    mintStatus = M_STATUS.SCAN_OTHER
                    Return True

                Case clsConst.G_CONST_BARCD_MENUBACK
                    '// OCMENUBACK
                    mintStatus = M_STATUS.MENUBACK
                    Return True

                Case clsConst.G_CONST_BARCD_CANCEL
                    '// OCCANCEL
                    mintStatus = M_STATUS.CANCEL
                    Return True

                Case clsConst.G_CONST_BARCD_OK
                    '// OCOK
                    If Not wfOKMain() Then Return True
                    mintStatus = M_STATUS.SCAN_OK
                    Return True
            End Select

            Return False

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : _uXL“`FbN
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    ' –฿่’l    : Boolean       True:OK / False:๊’vสฐบฐฤ ่
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfCheckDoubleScan(ByVal pstrInput As String) As Boolean
        gstrFuncName = "wfCheckDoubleScan"

        Dim i As Integer

        Try
            'สฐบฐฤ๊’vมชฏธ
            For i = 0 To gstructHtData.ITEM_COUNT - 1
                'ฝทฌ๎•๑ฬ”ไr๐ต“ฏถศ็ดืฐ
                If gstructHtData.SUB_ITEM(i).ScanBarcode = pstrInput Then
                    mintStatus = M_STATUS.DBL_SCAN
                    Return False
                End If
            Next

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : XL“๎•๑ๆ“พ
    ' ๘”      : 
    ' –฿่’l    : 
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Sub wsGetScanData()
        'ฺ“ฎJn“๚•tพฏฤ
        mstructItem.MoveSDate = DateTime.Today.ToString("yyyyMMdd")
        mstructItem.MoveSTime = Now.ToString("HHmmss")

        'ฝทฌ๎•๑พฏฤ
        ReDim Preserve gstructHtData.SUB_ITEM(gstructHtData.ITEM_COUNT)

        gstructHtData.SUB_ITEM(gstructHtData.ITEM_COUNT) = mstructItem
        gstructHtData.ITEM_COUNT += 1

        'ลIฝทฌ๎•๑ฦตฤๆ“พ
        Select Case mstructItem.ItemId
            Case clsConst.G_CONST_ITEMID_PARTS
                '•”•i
                gstructHtData.LastID = clsConst.G_CONST_BARCDID_PARTS
                gstructHtData.LastInfo1 = gclsPub.fItemCodeDispChg(mstructItem.PartNo & mstructItem.PartCL & mstructItem.Znc).TrimEnd
                gstructHtData.LastInfo2 = (" Qty:" & mstructItem.Qty).PadRight(13) & mstructItem.SerialNo

            Case clsConst.G_CONST_ITEMID_CASE
                'นฐฝ
                gstructHtData.LastID = clsConst.G_CONST_BARCDID_CASE
                gstructHtData.LastInfo1 = gclsPubHT.DispCode_Aic(mstructItem.Msc, mstructItem.Pnt, mstructItem.Trm)
                gstructHtData.LastInfo2 = gclsPubHT.DispCode_CaseNo(mstructItem.Lot, mstructItem.Gr, mstructItem.Seq)

            Case clsConst.G_CONST_ITEMID_CARTON
                'ถฐฤ
                gstructHtData.LastID = clsConst.G_CONST_BARCDID_CARTON
                gstructHtData.LastInfo1 = gclsPubHT.DispCode_Aic(mstructItem.Msc, mstructItem.Pnt, mstructItem.Trm)
                gstructHtData.LastInfo2 = gclsPubHT.DispCode_CaseNo(mstructItem.Lot, mstructItem.Gr, mstructItem.Seq).PadRight(13) & mstructItem.CartonNo

            Case Else
                'ถฐฤ
                gstructHtData.LastID = clsConst.G_CONST_BARCD_OTHER
                gstructHtData.LastInfo1 = ""
                gstructHtData.LastInfo2 = ""
        End Select
    End Sub

#End Region

#Region "-- Check Area ---------------------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : •”•i`FbN C“
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    '           : pOK           Boolean     มชฏOKฬืธ
    ' –฿่’l    : Boolean       True:ณํ / False:ูํ
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfCheckPartsMain(ByVal pstrInput As String, ByRef pOK As Boolean) As Boolean
        gstrFuncName = "wfCheckPartsMain"

        Dim wblnExist As Boolean = False

        Try
            '// ๎•๑ๆ“พ•ฯ”๚ป
            mstructItem.Initialize()

            '// ฝทฌ๎•๑•
            mstructItem.ScanBarcode = pstrInput

            '// สฐบฐฤ•ช๐
            Call wsDivBarcodeParts(pstrInput)

            '// ‘ถมชฏธ
            If Not wfExistPackPlan(pstrInput, wblnExist) Then Return False

            '// ‘ถมชฏธส
            If Not wblnExist Then Return True

            '// OK
            pOK = True

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : o[R[h•ช๐ (•”•iือู)
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    ' –฿่’l    : 
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Sub wsDivBarcodeParts(ByVal pstrInput As String)
        gstrFuncName = "wsDivBarcodeParts"

        Try
            With mstructItem
                .ItemId = clsConst.G_CONST_ITEMID_PARTS
                .ItemCode = pstrInput
                .PartCL = gclsPubHT.BarcodeDiv_Parts(pstrInput, clsPublicHT.Barcode_GetType_Parts.PartCL)
                .PartNo = gclsPubHT.fPartNo_DispToCode(gclsPubHT.BarcodeDiv_Parts(pstrInput, clsPublicHT.Barcode_GetType_Parts.PartNo)).PadRight(10).Substring(0, 10)
                .Znc = gclsPubHT.BarcodeDiv_Parts(pstrInput, clsPublicHT.Barcode_GetType_Parts.Znc)
                .SerialNo = gclsPubHT.BarcodeDiv_Parts(pstrInput, clsPublicHT.Barcode_GetType_Parts.SerialNo)
                .Qty = gclsPubHT.BarcodeDiv_Parts(pstrInput, clsPublicHT.Barcode_GetType_Parts.Qty)
                If Not IsNumeric(.Qty) Then .Qty = "0"
                .Qty = gclsPub.fParamShow(.Qty, clsPublic.SHOW_PARAM.Num)
                .Bhk = gstructHtData.Bhk
                .DisplayItem = gclsPub.fItemCodeDispChg(.PartNo & .PartCL & .Znc).TrimEnd
            End With

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Sub
        End Try
    End Sub

    '*******************************************************************************
    ' T—v      : User Area (•”•iือู)
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    '           : vblnExist     Boolean     ๕ส(True:‘ถ / False:–ข‘ถ)
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfExistPackPlan(ByVal pstrInput As String, ByRef vblnExist As Boolean) As Boolean
        gstrFuncName = "wfExistPackPlan"

        Dim wstrKey() As String
        Dim wstrKeyValue() As String
        Dim wstrTblKey As String = "TBLKEY"
        'Dim wintRet As clsDBStatus.DB_STATUS
        Dim wstrWhere As String

        Try
            '๕๐’่
            Call wsSearchKey_PackPlan_Key07(wstrKey, wstrKeyValue)

            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) & "'"
            wstrWhere &= " and " & wstrKey(9) & " = '" & wstrKeyValue(9) & "'"

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


            If tmpStr.Count > 0 Then

                Try
                    'Keyช ้๊
                    'If wintRet <> CommonMove.clsDBStatus.DB_STATUS.GET_DATA Then Exit Try
                    'If Not gclsPub.fCheckReadKey(wstrKey, wstrKeyValue, 6, wstrTblKey) Then Exit Try

                    '‘ถฬืธ๐Trueษ’่
                    vblnExist = True

                    'รฐภฬๆ“พ
                    Call wsGetData_Parts(wstrTblKey)

                Catch ex As Exception
                    Throw ex
                Finally
                    'รฐฬูธฐฝ
                    'gclsDB.fCloseRecord(wstrTblKey)
                End Try


            Else

                'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EMT_DB, MWA_DB_STOP, MWA_DB_OK)
                MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                gintStatus = MainModule.G_ENUM_STATUS.QUIT
                Me.Close()
                Exit Function
                Return False

            End If

            If Not vblnExist Then mintStatus = M_STATUS.DATA_NOT

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try



            '๕
        '    wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY07, wstrTblKey, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)

        '    'ดืฐฬ๊A—๐”ฒฏ้
        '    If wintRet = CommonMove.clsDBStatus.DB_STATUS.DB_ERROR Then
        '        gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EMT_DB, MWA_DB_STOP, MWA_DB_OK)
        '        gintStatus = MainModule.G_ENUM_STATUS.QUIT
        '        Return False
        '    End If

        '    Try
        '        'Keyช ้๊
        '        If wintRet <> CommonMove.clsDBStatus.DB_STATUS.GET_DATA Then Exit Try
        '        If Not gclsPub.fCheckReadKey(wstrKey, wstrKeyValue, 6, wstrTblKey) Then Exit Try

        '        '‘ถฬืธ๐Trueษ’่
        '        vblnExist = True

        '        'รฐภฬๆ“พ
        '        Call wsGetData_Parts(wstrTblKey)

        '    Catch ex As Exception
        '        Throw ex
        '    Finally
        '        'รฐฬูธฐฝ
        '        gclsDB.fCloseRecord(wstrTblKey)
        '    End Try

        '    'รฐภช‘ถตศข๊ ‘ถตศขษ’่
        '    If Not vblnExist Then mintStatus = M_STATUS.DATA_NOT

        '    Return True

        'Catch ex As Exception
        '    gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
        '    gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
        '    gintStatus = MainModule.G_ENUM_STATUS.QUIT
        'End Try
    End Function

    '*******************************************************************************
    ' T—v      : ๕—pp[^’่ (•”•iือู—p)
    ' ๘”      : pstrKey       String      ๕ฬจฐูฤ–ผ
    '           : pstrKeyValue  String      ๕ส฿ืาฐภ
    ' –฿่’l    : ศต
    ' ”๕l      : 
    '*******************************************************************************
    Private Sub wsSearchKey_PackPlan_Key07(ByRef pstrKey() As String, ByRef pstrKeyValue() As String)
        gstrFuncName = "wsSearchKey_PackPlan_Key07"

        ReDim pstrKey(9)
        ReDim pstrKeyValue(9)

        '๕๐’่
        pstrKey(0) = "PicsType"
        pstrKey(1) = "Cstmid"
        pstrKey(2) = "CstmCode"
        pstrKey(3) = "Bhk"
        pstrKey(4) = "ItemID"
        pstrKey(5) = "ItemCode"
        pstrKey(6) = "TempSerial"
        pstrKey(7) = "SerialNo"
        pstrKey(8) = "Aic"
        pstrKey(9) = "CaseNo"

        pstrKeyValue(0) = gclsPubHT.gstrctPPHT.strPackType
        pstrKeyValue(1) = gclsPubHT.gstrctPPHT.strCstmid
        pstrKeyValue(2) = gclsPubHT.gstrctPPHT.strCstmCode
        pstrKeyValue(3) = mstructItem.Bhk
        pstrKeyValue(4) = mstructItem.ItemId
        pstrKeyValue(5) = mstructItem.ItemCode_Parts
        pstrKeyValue(6) = mstructItem.SerialNo
        pstrKeyValue(7) = Space(6)
        pstrKeyValue(8) = Space(13)
        pstrKeyValue(9) = Space(7)
    End Sub

    '*******************************************************************************
    ' T—v      : ๕ส๎•๑ๆ“พ (•”•iือู—p)
    ' ๘”      : TblKey        String      รฐฬูทฐ
    ' –฿่’l    : ศต
    ' ”๕l      : 
    '*******************************************************************************
    Private Sub wsGetData_Parts(ByVal TblKey As String)
        Dim wstrCaseNo As String = ""
        Dim wstrAic As String = ""

        Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
        Dim sCaseNo As String = ""
        Dim sAic As String = ""
        Dim sWkSumDate As String = ""
        Dim sLabelLctn As String = ""
        Dim sProduct As String = ""
        Dim sPartName As String = ""
        Dim sPartID As String = ""

        If tmpStr_TBLKEY.Count > 0 Then

            values = tmpStr_TBLKEY(0)

            Dim result As String = Nothing
            If values.TryGetValue("CaseNo", result) Then
                sCaseNo = RTrim(result)
            End If
            If values.TryGetValue("Aic", result) Then
                sAic = RTrim(result)
            End If
            If values.TryGetValue("WkSumDate", result) Then
                sWkSumDate = RTrim(result)
            End If
            If values.TryGetValue("LabelLctn", result) Then
                sLabelLctn = RTrim(result)
            End If
            If values.TryGetValue("Product", result) Then
                sProduct = RTrim(result)
            End If
            If values.TryGetValue("PartName", result) Then
                sPartName = RTrim(result)
            End If
            If values.TryGetValue("PartID", result) Then
                sPartID = RTrim(result)
            End If

            wstrCaseNo = sCaseNo.ToString.PadRight(7)
            wstrAic = sAic.ToString.PadRight(13)

            mstructItem.Kukuri = sWkSumDate.ToString.PadRight(8)
            mstructItem.Location = sLabelLctn.ToString.PadRight(5)

            'CaseNo
            mstructItem.Lot = gclsPubHT.ParamDiv_CaseNo(wstrCaseNo, clsPublicHT.Param_GetType_CaseNo.Lot)
            mstructItem.Gr = gclsPubHT.ParamDiv_CaseNo(wstrCaseNo, clsPublicHT.Param_GetType_CaseNo.Gr)
            mstructItem.Seq = gclsPubHT.ParamDiv_CaseNo(wstrCaseNo, clsPublicHT.Param_GetType_CaseNo.Seq)

            'Aic
            mstructItem.Msc = gclsPubHT.ParamDiv_Aic(wstrAic, clsPublicHT.Param_GetType_Aic.Msc)
            mstructItem.Pnt = gclsPubHT.ParamDiv_Aic(wstrAic, clsPublicHT.Param_GetType_Aic.Pnt)
            mstructItem.Trm = gclsPubHT.ParamDiv_Aic(wstrAic, clsPublicHT.Param_GetType_Aic.Trm)

            mstructItem.YYYYMMDD = sProduct.ToString.PadRight(8)
            mstructItem.PartName = sPartName.ToString.PadRight(40)
            mstructItem.PartID = sPartID.ToString.PadRight(2)



        End If



        'With gclsDB.Records(TblKey)
        '    wstrCaseNo = .Item("CaseNo").ToString.PadRight(7)
        '    wstrAic = .Item("Aic").ToString.PadRight(13)

        '    mstructItem.Kukuri = .Item("WkSumDate").ToString.PadRight(8)
        '    mstructItem.Location = .Item("LabelLctn").ToString.PadRight(5)

        '    'CaseNo
        '    mstructItem.Lot = gclsPubHT.ParamDiv_CaseNo(wstrCaseNo, CommonMove.clsPublicHT.Param_GetType_CaseNo.Lot)
        '    mstructItem.Gr = gclsPubHT.ParamDiv_CaseNo(wstrCaseNo, CommonMove.clsPublicHT.Param_GetType_CaseNo.Gr)
        '    mstructItem.Seq = gclsPubHT.ParamDiv_CaseNo(wstrCaseNo, CommonMove.clsPublicHT.Param_GetType_CaseNo.Seq)

        '    'Aic
        '    mstructItem.Msc = gclsPubHT.ParamDiv_Aic(wstrAic, CommonMove.clsPublicHT.Param_GetType_Aic.Msc)
        '    mstructItem.Pnt = gclsPubHT.ParamDiv_Aic(wstrAic, CommonMove.clsPublicHT.Param_GetType_Aic.Pnt)
        '    mstructItem.Trm = gclsPubHT.ParamDiv_Aic(wstrAic, CommonMove.clsPublicHT.Param_GetType_Aic.Trm)

        '    mstructItem.YYYYMMDD = .Item("Product").ToString.PadRight(8)
        '    mstructItem.PartName = .Item("PartName").ToString.PadRight(40)
        '    mstructItem.PartID = .Item("PartID").ToString.PadRight(2)
        'End With
    End Sub

#End Region

#Region "-- นฐฝมชฏธ ----------------------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : P[X`FbN C“
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    '           : pOK           Boolean     มชฏOKฬืธ
    ' –฿่’l    : Boolean       True:ณํ / False:ูํ
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfCheckCaseMain(ByVal pstrInput As String, ByRef pOK As Boolean) As Boolean
        gstrFuncName = "wfCheckCaseMain"

        Dim wblnExist As Boolean = False

        Try
            '// ๎•๑ๆ“พ•ฯ”๚ป
            mstructItem.Initialize()

            '// ฝทฌ๎•๑•
            mstructItem.ScanBarcode = pstrInput

            '// สฐบฐฤ•ช๐
            Call wsDivBarcodeCase(pstrInput)

            '// ‘ถมชฏธ
            If Not wfExistVanpj(pstrInput, wblnExist) Then Return False

            '// ‘ถมชฏธส
            If Not wblnExist Then Return True

            '// OK
            pOK = True

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : o[R[h•ช๐ (นฐฝือู)
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    ' –฿่’l    : 
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Sub wsDivBarcodeCase(ByVal pstrInput As String)
        gstrFuncName = "wsDivBarcodeCase"

        Try
            With mstructItem
                .ItemId = clsConst.G_CONST_ITEMID_CASE
                .ItemCode = pstrInput
                .Msc = gclsPubHT.BarcodeDiv_Case(pstrInput, clsPublicHT.Barcode_GetType_Case.Msc)

                '–wวชPnt, Trmฬ–ณขสฐบฐฤ
                .Pnt = gclsPubHT.BarcodeDiv_Case(pstrInput, clsPublicHT.Barcode_GetType_Case.Pnt)
                .Trm = gclsPubHT.BarcodeDiv_Case(pstrInput, clsPublicHT.Barcode_GetType_Case.Trm)

                .Lot = gclsPubHT.BarcodeDiv_Case(pstrInput, clsPublicHT.Barcode_GetType_Case.Lot)
                .Gr = gclsPubHT.BarcodeDiv_Case(pstrInput, clsPublicHT.Barcode_GetType_Case.Gr)
                .Seq = gclsPubHT.BarcodeDiv_Case(pstrInput, clsPublicHT.Barcode_GetType_Case.Seq)
            End With

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Sub
        End Try
    End Sub

    '*******************************************************************************
    ' T—v      : User Area (นฐฝือู)
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    '           : vblnExist     Boolean     ๕ส(True:‘ถ / False:–ข‘ถ)
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfExistVanpj(ByVal pstrInput As String, ByRef vblnExist As Boolean) As Boolean
        gstrFuncName = "wfExistVanpj"

        Dim wstrKey() As String
        Dim wstrKeyValue() As String
        Dim wstrTblKey As String = "TBLKEY"
        'Dim wintRet As CommonMove.clsDBStatus.DB_STATUS
        Dim wblnSearchAicAll As Boolean = False
        Dim wstrWhere As String
        'Dim wOpenMode As BtLib.Operation

        Try
            '๕๐’่
            'Call wsSearchKey_Vanpj_Key18(wstrKey, wstrKeyValue, wblnSearchAicAll, wOpenMode)
            Call wsSearchKey_Vanpj_Key18(wstrKey, wstrKeyValue, wblnSearchAicAll)

            wstrWhere = ""
            wstrWhere = wstrKey(0) & " = '" & wstrKeyValue(0) & "'"
            wstrWhere &= " and " & wstrKey(1) & " = '" & wstrKeyValue(1) & "'"

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

            tmpStr_TBLKEY = tmpStr

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sAic As String = ""

            If tmpStr.Count > 0 Then

                values = tmpStr(0)

                Dim result As String = Nothing
                If values.TryGetValue(wstrKey(0), result) Then
                    sAic = result
                End If

                Try
                    'Keyช ้๊
                    'If wintRet <> CommonMove.clsDBStatus.DB_STATUS.GET_DATA Then Exit Try

                    'If Not wblnSearchAicAll Then
                    'Mscฬ
                    'If Not gclsPub.fCheckReadKey(wstrKey, wstrKeyValue, 0, wstrTblKey) Then Exit Try
                    If sAic.ToString.PadRight(7).Substring(0, 7) <> mstructItem.Msc Then Exit Try
                    'End If

                    '‘ถฬืธ๐Trueษ’่
                    vblnExist = True

                    'รฐภฬๆ“พ
                    Call wsGetData_Case(wstrTblKey)

                Catch ex As Exception
                    Throw ex
                Finally
                    'รฐฬูธฐฝ
                    'gclsDB.fCloseRecord(wstrTblKey)
                End Try

            End If



            '๕
            'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_VANPJ, G_CONST_KEY_VANPJKEY18, wstrTblKey, wstrKey, wstrKeyValue, wOpenMode)

            ''ดืฐฬ๊A—๐”ฒฏ้
            'If wintRet = CommonMove.clsDBStatus.DB_STATUS.DB_ERROR Then
            '    gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EMT_DB, MWA_DB_STOP, MWA_DB_OK)
            '    gintStatus = MainModule.G_ENUM_STATUS.QUIT
            '    Return False
            'End If

            'Try
            '    'Keyช ้๊
            '    If wintRet <> CommonMove.clsDBStatus.DB_STATUS.GET_DATA Then Exit Try

            '    If Not wblnSearchAicAll Then
            '        'Mscฬ
            '        If Not gclsPub.fCheckReadKey(wstrKey, wstrKeyValue, 0, wstrTblKey) Then Exit Try
            '        If gclsDB.Records(wstrTblKey).Item("Aic").ToString.PadRight(7).Substring(0, 7) <> mstructItem.Msc Then Exit Try
            '    End If

            '    '‘ถฬืธ๐Trueษ’่
            '    vblnExist = True

            '    'รฐภฬๆ“พ
            '    Call wsGetData_Case(wstrTblKey)

            'Catch ex As Exception
            '    Throw ex
            'Finally
            '    'รฐฬูธฐฝ
            '    gclsDB.fCloseRecord(wstrTblKey)
            'End Try

            'รฐภช‘ถตศข๊ ‘ถตศขษ’่
            If Not vblnExist Then mintStatus = M_STATUS.DATA_NOT

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : ๕—pp[^’่ (นฐฝือู—p)
    ' ๘”      : pstrKey       String      ๕ฬจฐูฤ–ผ
    '           : pstrKeyValue  String      ๕ส฿ืาฐภ
    '           : SearchAicAll  Boolean     AICฎ‘S๊’v๕
    '           : pOpenMode     Operation   ตฐฬ฿ำฐฤ
    ' –฿่’l    : ศต
    ' ”๕l      : 
    '*******************************************************************************
    'Private Sub wsSearchKey_Vanpj_Key18(ByRef pstrKey() As String, ByRef pstrKeyValue() As String, ByRef SearchAicAll As Boolean, ByRef pOpenMode As BtLib.Operation)
    Private Sub wsSearchKey_Vanpj_Key18(ByRef pstrKey() As String, ByRef pstrKeyValue() As String, ByRef SearchAicAll As Boolean)

        gstrFuncName = "wsSearchKey_Vanpj_Key18"

        ReDim pstrKey(1)
        ReDim pstrKeyValue(1)

        '๕๐’่
        pstrKey(0) = "CaseNo"
        pstrKey(1) = "Aic"

        With mstructItem
            pstrKeyValue(0) = gclsPubHT.ParamCombine_CaseNo(.Lot, .Gr, .Seq)
            pstrKeyValue(1) = gclsPubHT.ParamCombine_Aic(.Msc, .Pnt, .Trm)

            '๊’v”ป’่
            If .Pnt.Trim.Length = 0 AndAlso .Trm.Trim.Length = 0 Then
                'Mscฬ
                SearchAicAll = False
                'pOpenMode = BtLib.Operation.GetGreaterOrEqual
            Else
                'Aic
                SearchAicAll = True
                'pOpenMode = BtLib.Operation.GetEqual
            End If
        End With
    End Sub

    '*******************************************************************************
    ' T—v      : ๕ส๎•๑ๆ“พ (นฐฝือู—p)
    ' ๘”      : TblKey        String      รฐฬูทฐ
    ' –฿่’l    : ศต
    ' ”๕l      : 
    '*******************************************************************************
    Private Sub wsGetData_Case(ByVal TblKey As String)
        Dim wstrCaseNo As String = ""
        Dim wstrAic As String = ""

        Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
        Dim sCaseNo As String = ""
        Dim sAic As String = ""
        Dim sKukuri As String = ""
        Dim sNisugata As String = ""
        Dim sPreContenaNo As String = ""
        Dim sYYYYMMDD As String = ""

        If tmpStr_TBLKEY.Count > 0 Then

            values = tmpStr_TBLKEY(0)

            Dim result As String = Nothing
            If values.TryGetValue("CaseNo", result) Then
                sCaseNo = RTrim(result)
            End If
            If values.TryGetValue("Aic", result) Then
                sAic = RTrim(result)
            End If
            If values.TryGetValue("Kukuri", result) Then
                sKukuri = RTrim(result)
            End If
            If values.TryGetValue("Nisugata", result) Then
                sNisugata = RTrim(result)
            End If
            If values.TryGetValue("PreContenaNo", result) Then
                sPreContenaNo = RTrim(result)
            End If
            If values.TryGetValue("YYYYMMDD", result) Then
                sYYYYMMDD = RTrim(result)
            End If

        End If



        'With gclsDB.Records(TblKey)
        wstrCaseNo = sCaseNo.ToString.PadRight(7)
        wstrAic = sAic.ToString.PadRight(13)

        mstructItem.Kukuri = sKukuri.ToString.PadRight(8)
        mstructItem.Nisugata = sNisugata.ToString.PadRight(3)
        mstructItem.PreContenaNo = sPreContenaNo.ToString.PadRight(6)

        mstructItem.Pnt = gclsPubHT.ParamDiv_Aic(wstrAic, clsPublicHT.Param_GetType_Aic.Pnt)
        mstructItem.Trm = gclsPubHT.ParamDiv_Aic(wstrAic, clsPublicHT.Param_GetType_Aic.Trm)

        mstructItem.YYYYMMDD = sYYYYMMDD.ToString.PadRight(8)
        'End With
    End Sub

#End Region

#Region "-- ถฐฤมชฏธ ---------------------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : ถฐฤ`FbN C“
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    '           : pOK           Boolean     มชฏOKฬืธ
    ' –฿่’l    : Boolean       True:ณํ / False:ูํ
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfCheckCartonMain(ByVal pstrInput As String, ByRef pOK As Boolean) As Boolean
        gstrFuncName = "wfCheckCartonMain"

        Dim wblnExist As Boolean = False

        Try
            '// ๎•๑ๆ“พ•ฯ”๚ป
            mstructItem.Initialize()

            '// ฝทฌ๎•๑•
            mstructItem.ScanBarcode = pstrInput

            '// สฐบฐฤ•ช๐
            Call wsDivBarcodeCarton(pstrInput)

            '// ‘ถมชฏธ
            If Not wfExistPackCj(pstrInput, wblnExist) Then Return False

            '// ‘ถมชฏธส
            If Not wblnExist Then Return True

            '// OK
            pOK = True

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : o[R[h•ช๐ (ถฐฤือู)
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    ' –฿่’l    : 
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Sub wsDivBarcodeCarton(ByVal pstrInput As String)
        gstrFuncName = "wsDivBarcodeCarton"

        Try
            With mstructItem
                .ItemId = clsConst.G_CONST_ITEMID_CARTON
                .ItemCode = pstrInput
                .Bhk = gstructHtData.Bhk
                .Msc = gclsPubHT.BarcodeDiv_Carton(pstrInput, clsPublicHT.Barcode_GetType_Carton.Msc)
                .Pnt = gclsPubHT.BarcodeDiv_Carton(pstrInput, clsPublicHT.Barcode_GetType_Carton.Pnt)
                .Trm = gclsPubHT.BarcodeDiv_Carton(pstrInput, clsPublicHT.Barcode_GetType_Carton.Trm)
                .Lot = gclsPubHT.BarcodeDiv_Carton(pstrInput, clsPublicHT.Barcode_GetType_Carton.Lot)
                .Gr = gclsPubHT.BarcodeDiv_Carton(pstrInput, clsPublicHT.Barcode_GetType_Carton.Gr)
                .Seq = gclsPubHT.BarcodeDiv_Carton(pstrInput, clsPublicHT.Barcode_GetType_Carton.Seq)
                .CartonNo = gclsPubHT.BarcodeDiv_Carton(pstrInput, clsPublicHT.Barcode_GetType_Carton.CartonNo)
            End With

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Sub
        End Try
    End Sub

    '*******************************************************************************
    ' T—v      : User Area (ถฐฤือู)
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    '           : vblnExist     Boolean     ๕ส(True:‘ถ / False:–ข‘ถ)
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfExistPackCj(ByVal pstrInput As String, ByRef vblnExist As Boolean) As Boolean
        gstrFuncName = "wfExistPackCj"

        Dim wstrKey() As String
        Dim wstrKeyValue() As String
        Dim wstrTblKey As String = "TBLKEY"
        'Dim wintRet As CommonMove.clsDBStatus.DB_STATUS
        Dim wstrWhere As String

        Try
            '๕๐’่
            Call wsSearchKey_PackCj_Key06(wstrKey, wstrKeyValue)

            wstrWhere = ""
            wstrWhere = wstrKey(0) & " = '" & wstrKeyValue(0) & "'"
            wstrWhere &= " and " & wstrKey(1) & " = '" & wstrKeyValue(1) & "'"
            wstrWhere &= " and " & wstrKey(2) & " = '" & wstrKeyValue(2) & "'"

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

            tmpStr_TBLKEY = tmpStr

            If tmpStr.Count > 0 Then


                Try
                    'Keyช ้๊
                    'If wintRet <> CommonMove.clsDBStatus.DB_STATUS.GET_DATA Then Exit Try
                    'If Not gclsPub.fCheckReadKey(wstrKey, wstrKeyValue, 0, wstrTblKey) Then Exit Try

                    '‘ถฬืธ๐Trueษ’่
                    vblnExist = True

                    'รฐภฬๆ“พ
                    Call wsGetData_Carton(wstrTblKey)

                Catch ex As Exception
                    Throw ex
                Finally
                    'รฐฬูธฐฝ
                    'gclsDB.fCloseRecord(wstrTblKey)
                End Try


            Else


                'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EMT_DB, MWA_DB_STOP, MWA_DB_OK)
                MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                gintStatus = MainModule.G_ENUM_STATUS.QUIT
                Me.Close()
                Exit Function
                Return False



            End If

            If Not vblnExist Then mintStatus = M_STATUS.DATA_NOT

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try



            '๕
        '    wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY06, wstrTblKey, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)

        '    'ดืฐฬ๊A—๐”ฒฏ้
        '    If wintRet = CommonMove.clsDBStatus.DB_STATUS.DB_ERROR Then
        '        gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EMT_DB, MWA_DB_STOP, MWA_DB_OK)
        '        gintStatus = MainModule.G_ENUM_STATUS.QUIT
        '        Return False
        '    End If

        '    Try
        '        'Keyช ้๊
        '        If wintRet <> CommonMove.clsDBStatus.DB_STATUS.GET_DATA Then Exit Try
        '        If Not gclsPub.fCheckReadKey(wstrKey, wstrKeyValue, 0, wstrTblKey) Then Exit Try

        '        '‘ถฬืธ๐Trueษ’่
        '        vblnExist = True

        '        'รฐภฬๆ“พ
        '        Call wsGetData_Carton(wstrTblKey)

        '    Catch ex As Exception
        '        Throw ex
        '    Finally
        '        'รฐฬูธฐฝ
        '        gclsDB.fCloseRecord(wstrTblKey)
        '    End Try

        '    'รฐภช‘ถตศข๊ ‘ถตศขษ’่
        '    If Not vblnExist Then mintStatus = M_STATUS.DATA_NOT

        '    Return True

        'Catch ex As Exception
        '    gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
        '    gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
        '    gintStatus = MainModule.G_ENUM_STATUS.QUIT
        'End Try
    End Function

    '*******************************************************************************
    ' T—v      : ๕—pp[^’่ (ถฐฤือู—p)
    ' ๘”      : pstrKey       String      ๕ฬจฐูฤ–ผ
    '           : pstrKeyValue  String      ๕ส฿ืาฐภ
    ' –฿่’l    : ศต
    ' ”๕l      : 
    '*******************************************************************************
    Private Sub wsSearchKey_PackCj_Key06(ByRef pstrKey() As String, ByRef pstrKeyValue() As String)
        gstrFuncName = "wsSearchKey_PackCj_Key06"

        Dim wstrAic As String = ""
        Dim wstrCaseNo As String = ""

        ReDim pstrKey(2)
        ReDim pstrKeyValue(2)

        '๕๐’่
        pstrKey(0) = "ItemCode"
        pstrKey(1) = "ItemInCode"
        pstrKey(2) = "PlanSerial"

        With mstructItem
            wstrAic = gclsPubHT.ParamCombine_Aic(.Msc, .Pnt, .Trm)
            wstrCaseNo = gclsPubHT.ParamCombine_CaseNo(.Lot, .Gr, .Seq)
            pstrKeyValue(0) = gclsPubHT.ParamCombine_ItemCodeCarton(wstrAic, wstrCaseNo, .CartonNo)
        End With

        pstrKeyValue(1) = Space(30)
        pstrKeyValue(2) = Space(6)
    End Sub

    '*******************************************************************************
    ' T—v      : ๕ส๎•๑ๆ“พ (ถฐฤือู—p)
    ' ๘”      : TblKey        String      รฐฬูทฐ
    ' –฿่’l    : ศต
    ' ”๕l      : 
    '*******************************************************************************
    Private Sub wsGetData_Carton(ByVal TblKey As String)

        Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
        Dim sProductDate As String = ""
        Dim sWKSumDate As String = ""

        If tmpStr_TBLKEY.Count > 0 Then
            values = tmpStr_TBLKEY(0)

            Dim result As String = Nothing
            If values.TryGetValue("ProductDate", result) Then
                sProductDate = RTrim(result)
            End If
            If values.TryGetValue("WKSumDate", result) Then
                sWKSumDate = RTrim(result)
            End If

            mstructItem.YYYYMMDD = sProductDate.ToString.PadRight(8)
            mstructItem.Kukuri = sWKSumDate.ToString.PadRight(8)


        End If


        'With gclsDB.Records(TblKey)
        '    mstructItem.YYYYMMDD = .Item("ProductDate").ToString.PadRight(8)
        '    mstructItem.Kukuri = .Item("WKSumDate").ToString.PadRight(8)
        'End With
    End Sub

#End Region

#Region "-- ปฬ‘ผมชฏธ -----------------------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : ปฬ‘ผ`FbN C“
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    '           : pOK           Boolean     มชฏOKฬืธ
    ' –฿่’l    : Boolean       True:ณํ / False:ูํ
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfCheckOtherMain(ByVal pstrInput As String, ByRef pOK As Boolean) As Boolean
        gstrFuncName = "wfCheckOtherMain"

        Dim wblnExist As Boolean = False

        Try
            '// ๎•๑ๆ“พ•ฯ”๚ป
            mstructItem.Initialize()

            '// ฝทฌ๎•๑•
            mstructItem.ScanBarcode = pstrInput

            '// สฐบฐฤ•ช๐
            Call wsDivBarcodeOther(pstrInput)

            '// OK
            pOK = True

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : o[R[h•ช๐ (ปฬ‘ผือู)
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    ' –฿่’l    : 
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Sub wsDivBarcodeOther(ByVal pstrInput As String)
        gstrFuncName = "wsDivBarcodeOther"

        Try
            With mstructItem
                .ItemId = clsConst.G_CONST_ITEMID_OTHER
                .ItemCode = pstrInput
                .Bhk = gstructHtData.Bhk
            End With

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Sub
        End Try
    End Sub

#End Region

#Region "-- OKฝทฌ -----------------------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : OKXL“C“
    ' ๘”      : 
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfOKMain() As Boolean
        gstrFuncName = "wfOKMain"

        Dim wstrMoveNo As String = ""

        Try
            '// –ขฝทฌมชฏธ
            If gstructHtData.ITEM_COUNT = 0 Then
                'ฝรฐภฝพฏฤ(–ขฝทฌ)
                mintStatus = M_STATUS.SCAN_ZERO
                Return False
            End If

            '// ฺ“ฎ”ิXV/ๆ“พ
            If Not wfGetMoveNo(wstrMoveNo) Then Return False

            '// “o^—
            If Not wfSetDataMain(wstrMoveNo) Then Return False

            Return True

        Catch ex As Exception
            Throw ex
        End Try
    End Function

#End Region

#Region "-- ปฬ‘ผฝทฌ -------------------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : ปฬ‘ผo[R[hXL“C“
    ' ๘”      : 
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfOtherMain() As Boolean
        gstrFuncName = "wfOtherMain"

        Try
            '// –ขฝทฌมชฏธ
            If gstructHtData.ITEM_COUNT > 0 Then
                'ฝรฐภฝพฏฤ(ณํือูฝทฌฯ)
                mintStatus = M_STATUS.ERROR_OTHER
                Return False
            End If

            '// ปฬ‘ผฝทฌำฐฤON
            gstructHtData.OtherScan = True

            Return True

        Catch ex As Exception
            Throw ex
        End Try
    End Function

#End Region

#End Region

#Region "// DB Area ///////////////////////////////////////////////////////////////////////////"

    '*******************************************************************************
    ' T—v      : ฺ“ฎ”ิๆ“พ
    ' ๘”      : MoveNo        String      ฺ“ฎ”ิ
    ' –฿่’l    : Boolean       True:ณํ / False:ูํ
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfGetMoveNo(ByRef MoveNo As String) As Boolean
        gstrFuncName = "wfGetMoveNo"

        Dim wclsGetSeq As New clsGetSeq

        Try
            '// ฬ฿ส฿รจ’่
            With wclsGetSeq
                .Set_GrNo = gstructHtData.GrNo
            End With

            '// ’ว”ิ’่
            If Not wclsGetSeq.Run Then Return False

            '// ฺ“ฎ”ิๆ“พ
            MoveNo = wclsGetSeq.Get_MoveNo

            '// ฺ“ฎ”ิ(ธฐสู)
            gstructHtData.MoveNo = MoveNo

            Return True

        Catch ex As Exception
            Throw ex
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : “o^— C“
    ' ๘”      : pIndex        Integer     ฒรฏธฝ
    '           : MoveNo        String      ฺ“ฎ”ิ
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfSetDataMain(ByVal MoveNo As String) As Boolean
        gstrFuncName = "wfSetDataMain"

        Dim wblnSuccess As Boolean = False
        Dim i As Integer

        Try
            '// ฤืปธผฎ—Jn
            'BtLib.Transaction.BeginConCurrent()

            '// ๓“๚•tพฏฤ
            gstructHtData.PrintDate = DateTime.Today.ToString("yyyyMMdd")
            gstructHtData.PrintTime = Now.ToString("HHmmss")

            '// ฝทฌ๎•๑“o^
            For i = 0 To gstructHtData.ITEM_COUNT - 1
                If Not wfSetDataSub(i, MoveNo) Then Return False
            Next

            wblnSuccess = True

            Return True

        Catch ex As Exception
            Throw ex
        Finally
            If wblnSuccess Then
                'ณํI—น
                'BtLib.Transaction.End()
            Else
                'ูํI—น
                'BtLib.Transaction.Abort()
            End If
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : “—อรฐภฬ“o^
    ' ๘”      : pIndex        Integer     ฒรฏธฝ
    '           : MoveNo        String      ฺ“ฎ”ิ
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfSetDataSub(ByVal pIndex As Integer, ByVal MoveNo As String) As Boolean
        gstrFuncName = "wfSetDataSub"

        Dim wstrSetKey() As String
        Dim wstrSetKeyValue() As String
        Dim wstrTblKey As String = "TBLKEY"
        'Dim wintRet As CommonMove.clsDBStatus.DB_STATUS
        Dim sqlInsert As String

        Try
            'รฐภ’่
            Call wsSetKeyMoveJ(wstrSetKey, wstrSetKeyValue, pIndex, MoveNo)

            sqlInsert = "INSERT INTO " & G_CONST_TBL_PACKCP & " ("


            For index As Integer = 0 To 38
                sqlInsert = sqlInsert & wstrSetKey(index) & ","
            Next

            sqlInsert = sqlInsert & " ) VALUES ("

            For index As Integer = 0 To 38

                If index <> 38 Then
                    sqlInsert = sqlInsert & "'" & wstrSetKeyValue(index) & "',"
                Else
                    sqlInsert = sqlInsert & "'" & wstrSetKeyValue(index) & "'"
                End If

            Next

            sqlInsert = sqlInsert & ")"

            affected_rows = dbClient.Execute(sqlInsert)

            If affected_rows = 0 Then

                Return False

            End If



            'รฐภ๐DBษ“o^
            'wintRet = gclsDB.fInsRecord(G_CONST_TBL_MOVEJ, wstrSetKey, wstrSetKeyValue)

            ''ดืฐฬ๊A—๐”ฒฏ้
            'If wintRet = CommonMove.clsDBStatus.DB_STATUS.DB_ERROR Then
            '    gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EMT_DB, MWA_DB_STOP, MWA_DB_OK)
            '    gintStatus = MainModule.G_ENUM_STATUS.QUIT
            '    Return False
            'End If

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : “o^๎•๑์ฌ
    ' ๘”      : pstrKey       String      “o^ฬจฐูฤ–ผ
    '           : pstrKeyValue  String      “o^ส฿ืาฐภ
    '           : pIndex        Integer     ฒรฏธฝ
    '           : MoveNo        String      ฺ“ฎ”ิ
    ' –฿่’l    : ศต
    ' ”๕l      : 
    '*******************************************************************************
    Private Sub wsSetKeyMoveJ(ByRef pstrKey() As String, ByRef pstrKeyValue() As String, ByVal pIndex As Integer, ByVal MoveNo As String)
        gstrFuncName = "wsSetKeyMoveJ"

        ReDim pstrKey(38)
        ReDim pstrKeyValue(38)

        '๕๐’่
        pstrKey(0) = "MoveNo"
        pstrKey(1) = "YYYYMMDD"
        pstrKey(2) = "Kukuri"
        pstrKey(3) = "Bhk"
        pstrKey(4) = "PreContenaNo"
        pstrKey(5) = "Msc"
        pstrKey(6) = "Pnt"
        pstrKey(7) = "Trm"
        pstrKey(8) = "Lot"
        pstrKey(9) = "Gr"
        pstrKey(10) = "Seq"
        pstrKey(11) = "ItemId"
        pstrKey(12) = "ItemCode"
        pstrKey(13) = "PartNo"
        pstrKey(14) = "PartCL"
        pstrKey(15) = "Znc"
        pstrKey(16) = "PartID"
        pstrKey(17) = "PartName"
        pstrKey(18) = "DisplayItem"
        pstrKey(19) = "CartonNo"
        pstrKey(20) = "Nisugata"
        pstrKey(21) = "GrNo"
        pstrKey(22) = "Location"
        pstrKey(23) = "MoveFrom"
        pstrKey(24) = "MoveTo"
        pstrKey(25) = "MoveStat"
        pstrKey(26) = "Employer"
        pstrKey(27) = "MoveSDate"
        pstrKey(28) = "MoveSTime"
        pstrKey(29) = "PrintEmp"
        pstrKey(30) = "PrintDate"
        pstrKey(31) = "PrintTime"
        pstrKey(32) = "MoveEEmp"
        pstrKey(33) = "MoveEDate"
        pstrKey(34) = "MoveETime"
        pstrKey(35) = "SendFlag"
        pstrKey(36) = "SendDate"
        pstrKey(37) = "SendTime"
        pstrKey(38) = "Filler"

        With gstructHtData.SUB_ITEM(pIndex)
            pstrKeyValue(0) = MoveNo
            pstrKeyValue(1) = .YYYYMMDD.PadRight(8)
            pstrKeyValue(2) = .Kukuri.PadRight(8)
            pstrKeyValue(3) = .Bhk.PadRight(3)
            pstrKeyValue(4) = .PreContenaNo.PadRight(6)
            pstrKeyValue(5) = .Msc.PadRight(6)
            pstrKeyValue(6) = .Pnt.PadRight(3)
            pstrKeyValue(7) = .Trm.PadRight(3)
            pstrKeyValue(8) = .Lot.PadRight(3)
            pstrKeyValue(9) = .Gr.PadRight(2)
            pstrKeyValue(10) = .Seq.PadRight(2)
            pstrKeyValue(11) = .ItemId.PadRight(1)
            pstrKeyValue(12) = .ItemCode.PadRight(30)
            pstrKeyValue(13) = .PartNo.PadRight(10)
            pstrKeyValue(14) = .PartCL.PadRight(2)
            pstrKeyValue(15) = .Znc.PadRight(1)
            pstrKeyValue(16) = .PartID.PadRight(2)
            pstrKeyValue(17) = .PartName.PadRight(40)
            pstrKeyValue(18) = .DisplayItem.PadRight(30)
            pstrKeyValue(19) = .CartonNo.PadRight(5)
            pstrKeyValue(20) = .Nisugata.PadRight(3)
        End With

        With gstructHtData
            pstrKeyValue(21) = .GrNo.PadRight(3)
            pstrKeyValue(22) = gstructHtData.SUB_ITEM(pIndex).Location.PadRight(5)
            pstrKeyValue(23) = .MoveFrom.PadRight(10)
            pstrKeyValue(24) = .MoveTo.PadRight(10)
            pstrKeyValue(25) = clsConst.G_CONST_MOVEJ_STATUS_PRINT
            pstrKeyValue(26) = .Employer.PadRight(6)
            pstrKeyValue(27) = gstructHtData.SUB_ITEM(pIndex).MoveSDate.PadRight(8)
            pstrKeyValue(28) = gstructHtData.SUB_ITEM(pIndex).MoveSTime.PadRight(6)
            pstrKeyValue(29) = .Employer.PadRight(6)
            pstrKeyValue(30) = .PrintDate.PadRight(8)
            pstrKeyValue(31) = .PrintTime.PadRight(6)
        End With
        pstrKeyValue(32) = Space(6)
        pstrKeyValue(33) = Space(8)
        pstrKeyValue(34) = Space(6)
        pstrKeyValue(35) = clsConst.G_CONST_FLAG_OFF
        pstrKeyValue(36) = Space(8)
        pstrKeyValue(37) = Space(6)
        pstrKeyValue(38) = Space(14)

    End Sub

#End Region

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

    Private Sub frmPMMV1015_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    End Sub
End Class
