﻿
'*******************************************************************************
'* ์ฌ๏ะ : ”ฎ๏ะ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 PMMV2000.BtScanLib
Imports BTClientLib
Imports System.IO
Imports System.Reflection
Imports BtScan2

Public Class frmPMMV2010
    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_wstrTblKey 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 wfName As WarpControl.WarpField
    'Friend WithEvents wfInput As WarpControl.WarpField
    'Friend WithEvents WarpHWBcr1 As WarpControl.WarpHWBcr
    'Friend WithEvents wfCount As WarpControl.WarpField
    'Friend WithEvents WarpField2 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.wfCount = New WarpControl.WarpField
    '    Me.WarpField2 = New WarpControl.WarpField
    '    Me.wfInput = 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.wfCount)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField2)
    '    Me.WarpFrame1.Controls.Add(Me.wfInput)
    '    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 = 54
    '    Me.WarpBox1.Text = "Echo System"
    '    '
    '    '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(126, 9)
    '    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(53, 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(80, 11)
    '    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(52, Short)
    '    Me.WarpField2.Text = "Scan:"
    '    '
    '    '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(144, 74)
    '    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(41, Short)
    '    '
    '    '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(10, Short)
    '    Me.wfName.Text = "Echo System"
    '    '
    '    '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)
    '    '
    '    'frmPMMV2010
    '    '
    '    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 = "frmPMMV2010"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region

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

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

#End Region

#Region "// Structure Area ///////////////////////////////////////////////////////////////////////////"

    'ฝรฐภฝ—๑“^
    Private Enum M_STATUS As Integer
        INIT                '๚ป
        MENUBACK            'าฦญฐสฏธ
        CANCEL              'ทฌพู
        ID_ERROR            'IDดืฐ
        LENGTH_ERROR        '…”•s๊’v
        SCANED              'ฝทฌฯ
        NOTEXIST            'รฐภศต
        DONE                'ณํQฦ
    End Enum

#End Region

#Region "// Ivent Area //"

    Private Sub frmPMMV2010_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 rtn As Integer

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

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

            Call gstructHtData.Initialize(gintStatus)

            'ๆ–ส๎•๑
            'gclsPubHT.sSetImgFName(CommonMove.clsMsgID.H2050, 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()
        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 "---- ๆ–ส•\ฆ -------------------------------------------------------------------------"

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

        '// ถณฤ
        'wfCount.Puts(gstructHtData.TotalScan.ToString.PadLeft(2))

        'ีฐปฐ–ผ
        'wfName.Puts(gclsPubHT.gstrctPPHT.strUserName)

        wfCount.Text = gstructHtData.TotalScan.ToString.PadLeft(2)
        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.NAME
                    Me.Close()
                    Exit Sub

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

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

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

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

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

                    gintStatus = MainModule.G_ENUM_STATUS.MOVE_END
                    Me.Close()
                    Exit Sub

                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.I2010, gfrmMain.WarpCtrl1, CommonMove.clsPublicHT.MsgType.Type_Info, CommonMove.clsPublicHT.MsgSelect.Btn_OK)
            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      : “—อ—@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 = ""

        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

            '// “—อ—
            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 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      : “—อ—
    ' ๘”      : 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

            '// สฐบฐฤIDมชฏธ
            If Not pstrInput.StartsWith(clsConst.G_CONST_BARCDID_JUJU) Then
                'ๆ“ชIDช•s๊’v
                mintStatus = M_STATUS.ID_ERROR
                Return True
            End If

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

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

            '// XV—
            If Not wfSetDataMain() Then Return True

            mintStatus = M_STATUS.DONE

            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      : 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_MENUBACK
                    '// OCMENUBACK
                    mintStatus = M_STATUS.MENUBACK
                    Return True

                Case clsConst.G_CONST_BARCD_CANCEL
                    '// OCCANCEL
                    mintStatus = M_STATUS.CANCEL
                    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

#End Region

#Region "-- ‘ถมชฏธ ---------------------------------------------------------------------------"

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

        Dim wblnExist As Boolean = False

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

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

            '// ฝทฌฯมชฏธ
            If mintStatus = M_STATUS.SCANED Then Return True

            '// ‘ถมชฏธส
            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 wsDivBarcode(ByVal pstrInput As String)
        gstrFuncName = "wsDivBarcode"

        Try
            'ฺ“ฎ”ิ
            gstructHtData.MoveNo = pstrInput.Substring(1, 13)

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

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

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

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

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

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

            tmpStr_wstrTblKey = tmpStr


            If tmpStr.Count > 0 Then


                vblnExist = True

                If Not wfGetDataParam(wstrTblKey) Then Return True

            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.NOTEXIST

            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_MOVEJ, G_CONST_KEY_MOVEJKEY00, 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
        '        Do
        '            '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

        '            'รฐภฬๆ“พ & ฝรฐภฝมชฏธ
        '            If Not wfGetDataParam(wstrTblKey) Then Return True

        '            'ฬฺบฐฤึ
        '            wintRet = gclsDB.Records(wstrTblKey).Read(BtLib.Operation.GetNext)
        '        Loop

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

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

        '    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[^’่
    ' ๘”      : pstrKey       String      ๕ฬจฐูฤ–ผ
    '           : pstrKeyValue  String      ๕ส฿ืาฐภ
    '           : ItemId        String      ฑฒรัID
    '           : ItemCode      String      ฑฒรับฐฤ
    ' –฿่’l    : ศต
    ' ”๕l      : 
    '*******************************************************************************
    Private Sub wsSearchKey_MoveJ(ByRef pstrKey() As String, ByRef pstrKeyValue() As String, _
                                  Optional ByVal ItemId As String = "", Optional ByVal ItemCode As String = "")
        gstrFuncName = "wsSearchKey_MoveJ"

        ReDim pstrKey(2)
        ReDim pstrKeyValue(2)

        '๕๐’่
        pstrKey(0) = "MoveNo"
        pstrKey(1) = "ItemId"
        pstrKey(2) = "ItemCode"

        pstrKeyValue(0) = gstructHtData.MoveNo
        pstrKeyValue(1) = ItemId.PadRight(1)
        pstrKeyValue(2) = ItemCode.PadRight(30)
    End Sub

    '*******************************************************************************
    ' T—v      : ๕ส๎•๑ๆ“พ
    ' ๘”      : TblKey        String      รฐฬูทฐ
    ' –฿่’l    : Boolean       True:ฝรฐภฝOK / False:ฝรฐภฝNG
    ' ”๕l      : 
    '*******************************************************************************
    Private Function wfGetDataParam(ByVal TblKey As String) As Boolean
        Dim wstrMoveStat As String = ""
        Dim wstructItem As G_STRUCT_HTSUB

        Try
            '// ือูฝทฌ๎•๑๚ป
            wstructItem.Initialize()

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemId As String = ""
            Dim sItemCode As String = ""
            Dim sMoveStat As String = ""

            If tmpStr_wstrTblKey.Count > 0 Then

                values = tmpStr(0)

                Dim result As String = Nothing
                If values.TryGetValue("ItemId", result) Then
                    sItemId = result
                End If
                If values.TryGetValue("ItemCode", result) Then
                    sItemCode = result
                End If
                If values.TryGetValue("MoveStat", result) Then
                    sMoveStat = result
                End If

                wstructItem.ItemId = sItemId.ToString.PadRight(1)
                wstructItem.ItemCode = sItemCode.ToString.PadRight(30)
                wstrMoveStat = sMoveStat.ToString.PadRight(2)

            End If


            '// รฐภๆ“พ
            'With gclsDB.Records(TblKey)
            '    wstructItem.ItemId = .Item("ItemId").ToString.PadRight(1)
            '    wstructItem.ItemCode = .Item("ItemCode").ToString.PadRight(30)
            '    wstrMoveStat = .Item("MoveStat").ToString.PadRight(2)
            'End With

            '// ฝรฐภฝมชฏธ
            If wstrMoveStat > clsConst.G_CONST_MOVEJ_STATUS_PRINT Then
                mintStatus = M_STATUS.SCANED
                Return False
            End If

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

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

            Return True

        Catch ex As Exception
            Throw ex
        End Try
    End Function

#End Region

#End Region

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

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

        Dim wblnSuccess As Boolean = False
        Dim i As Integer

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

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

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

            gstructHtData.TotalScan += 1

            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     ฒรฏธฝ
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfSetDataSub(ByVal pIndex As Integer) As Boolean
        gstrFuncName = "wfSetDataSub"

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

        Try
            '๕๐
            With gstructHtData.SUB_ITEM(pIndex)
                Call wsSearchKey_MoveJ(wstrKey, wstrKeyValue, .ItemId, .ItemCode)
            End With

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

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

            For index As Integer = 0 To wstrSetKey.Length - 1


                If index = 0 Then
                    sSql = "UPDATE " + clsBTRFile.G_CONST_TBL_MOVEJ + " SET " + wstrSetKey(index) + "='" + wstrSetKeyValue(index) + "'"

                ElseIf index = wstrSetKey.Length - 1 Then

                    sSql = sSql + " , " + wstrSetKey(index) + "='" + wstrSetKeyValue(index) + "' WHERE " + wstrWhere

                Else

                    sSql = sSql + " , " + wstrSetKey(index) + "='" + wstrSetKeyValue(index) + "'"
                End If


            Next

            affected_rows = dbClient.Execute(sSql)


            If affected_rows = 0 Then
                Return False
            End If



            'รฐภXV
            'wintRet = gclsDB.fUpdRecords(G_CONST_TBL_MOVEJ, G_CONST_KEY_MOVEJKEY00, wstrKey, wstrKeyValue, 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^ส฿ืาฐภ
    ' –฿่’l    : ศต
    ' ”๕l      : 
    '*******************************************************************************
    Private Sub wsSetKeyMoveJ(ByRef pstrKey() As String, ByRef pstrKeyValue() As String)
        gstrFuncName = "wsSetKeyMoveJ"

        ReDim pstrKey(3)
        ReDim pstrKeyValue(3)

        '๕๐’่
        pstrKey(0) = "MoveStat"
        pstrKey(1) = "MoveEEmp"
        pstrKey(2) = "MoveEDate"
        pstrKey(3) = "MoveETime"

        pstrKeyValue(0) = clsConst.G_CONST_MOVEJ_STATUS_MOVED

        With gstructHtData
            pstrKeyValue(1) = .MoveEEmp.PadRight(6)
            pstrKeyValue(2) = .MoveEDate.PadRight(8)
            pstrKeyValue(3) = .MoveETime.PadRight(6)
        End With

    End Sub

#End Region

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