﻿
'*******************************************************************************
'* ์ฌ๏ะ : ”ฎ๏ะ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 frmPMMV1010
    Inherits System.Windows.Forms.Form
    Private btScanLib As BtScanLib
    Private scanHandler As Boolean = False
    'Private dbClient As BtrieveDbClient
    Private tmpStr As List(Of Dictionary(Of String, String))
    Private affected_rows As Integer

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

    Public Sub New()
        MyBase.New()

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

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

    End Sub

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

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

    '  : ศบฬvV[WอAWindows tH[€ fUCiล•K—vลทB
    'Windows tH[€ fUCi๐gมฤ•ฯXตฤญพณขB  
    ' R[h GfB^๐gมฤ•ฯXตศขลญพณขB
    'Friend WithEvents WarpFrame1 As WarpControl.WarpFrame
    'Friend WithEvents wfName As WarpControl.WarpField
    'Friend WithEvents wfInput As WarpControl.WarpField
    'Friend WithEvents WarpHWBcr1 As WarpControl.WarpHWBcr
    'Friend WithEvents wfFrom As WarpControl.WarpField
    'Friend WithEvents wfFromLbl 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.wfFromLbl = New WarpControl.WarpField
    '    Me.wfFrom = 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.wfFromLbl)
    '    Me.WarpFrame1.Controls.Add(Me.wfFrom)
    '    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 = 51
    '    Me.WarpBox1.Text = "Echo System"
    '    '
    '    'wfFromLbl
    '    '
    '    Me.wfFromLbl.BackColor = CType(3, Short)
    '    Me.wfFromLbl.DecimalPointPosition = CType(0, Short)
    '    Me.wfFromLbl.Font = New System.Drawing.Font("Lucida Console", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfFromLbl.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfFromLbl.Format = ""
    '    Me.wfFromLbl.Length = CType(4, Short)
    '    Me.wfFromLbl.Location = New System.Drawing.Point(20, 30)
    '    Me.wfFromLbl.MacroBcr = ""
    '    Me.wfFromLbl.MacroIn = ""
    '    Me.wfFromLbl.MacroKey = ""
    '    Me.wfFromLbl.MacroOut = ""
    '    Me.wfFromLbl.Name = "wfFromLbl"
    '    Me.wfFromLbl.Size = New System.Drawing.Size(32, 16)
    '    Me.wfFromLbl.TabIndex = CType(50, Short)
    '    Me.wfFromLbl.Text = "From"
    '    '
    '    'wfFrom
    '    '
    '    Me.wfFrom.BackColor = CType(3, Short)
    '    Me.wfFrom.DecimalPointPosition = CType(0, Short)
    '    Me.wfFrom.Font = New System.Drawing.Font("Lucida Console", 14.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfFrom.Format = ""
    '    Me.wfFrom.Length = CType(10, Short)
    '    Me.wfFrom.Location = New System.Drawing.Point(20, 52)
    '    Me.wfFrom.MacroBcr = ""
    '    Me.wfFrom.MacroIn = ""
    '    Me.wfFrom.MacroKey = ""
    '    Me.wfFrom.MacroOut = ""
    '    Me.wfFrom.Name = "wfFrom"
    '    Me.wfFrom.Size = New System.Drawing.Size(120, 24)
    '    Me.wfFrom.TabIndex = CType(49, Short)
    '    Me.wfFrom.Text = "XXXXXXXXXX"
    '    '
    '    '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(146, 9)
    '    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)
    '    '
    '    'frmPMMV1010
    '    '
    '    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 = "frmPMMV1010"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region

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

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

    ''•ถ—๑
    'Private Const M_CONST_FROM As String = "Scan From Label"
    'Private Const M_CONST_TO As String = " Scan To Label"

#End Region

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

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

#End Region

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

    Private Sub frmPMMV1010_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)

            'ๆ–ส๎•๑
            If gintStatus = MainModule.G_ENUM_STATUS.MOVE_FROM Then
                'Fromฝทฌ
                'gclsPubHT.sSetImgFName(CommonMove.clsMsgID.H2010, WarpBox1)
            Else
                'Toฝทฌ
                'gclsPubHT.sSetImgFName(CommonMove.clsMsgID.H2020, WarpBox1)
            End If

            'ๆ–ส•\ฆ—
            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
        '    ' ฬฺฐัฬ—๐ฑฑษLqตทก
        '    Do While (True)
        '        ' บฐฤ“—อ
        '        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()

        If gintStatus = MainModule.G_ENUM_STATUS.MOVE_FROM Then
            'From
            wfFromLbl.Text = ""
            wfFrom.Text = ""
        Else
            'To
            wfFromLbl.Text = "From"
            wfFrom.Text = gstructHtData.MoveFrom
        End If

        'ีฐปฐ–ผ
        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
                    '// ทฌพู
                    If gintStatus = MainModule.G_ENUM_STATUS.MOVE_FROM Then
                        'From

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

                        gintStatus = MainModule.G_ENUM_STATUS.NAME
                        Me.Close()
                        Exit Sub
                    Else
                        'To

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

                        gintStatus = MainModule.G_ENUM_STATUS.MOVE_FROM
                        Me.Close()
                        Exit Sub
                    End If

                Case M_STATUS.LENGTH_ERROR, M_STATUS.ID_ERROR
                    '// สฐบฐฤ“เ—eดืฐ
                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E2010, gfrmMain.WarpCtrl1)

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

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

                    gintStatus = G_ENUM_STATUS.MOVE_FROM
                    Me.Close()
                    Exit Sub
                Case M_STATUS.SAME_MOVE
                    '// “ฏถฺ“ฎๆ
                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E2030, gfrmMain.WarpCtrl1)

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

                    gintStatus = G_ENUM_STATUS.MOVE_FROM
                    Me.Close()
                    Exit Sub
                Case M_STATUS.DONE
                    '// ณํQฦ
                    If gintStatus = MainModule.G_ENUM_STATUS.MOVE_FROM Then
                        'From

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

                        gintStatus = MainModule.G_ENUM_STATUS.MOVE_TO
                        Me.Close()
                        Exit Sub
                    Else
                        'To

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

                        gintStatus = MainModule.G_ENUM_STATUS.ITEM_FIRST
                        Me.Close()
                        Exit Sub
                    End If
            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 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 rtn As Integer

        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

            '// สฐบฐฤIDมชฏธ
            If Not pstrInput.StartsWith(clsConst.G_CONST_BARCDID_MOVE) Then
                'ๆ“ชชแค
                mintStatus = M_STATUS.ID_ERROR
                Return True
            End If

            '// …”มชฏธ
            If pstrInput.Length <> 11 Then
                '11…ศOษฝรฐภฝพฏฤ
                mintStatus = M_STATUS.LENGTH_ERROR
                Return True
            End If

            '// ๎•๑ๆ“พ
            If Not wfGetMoveParam(pstrInput) Then Return True

            '// Fromฝทฌฬ๊อึ
            If gintStatus = MainModule.G_ENUM_STATUS.MOVE_FROM Then Return True

            '// ๕—
            If Not wfCheckExist() Then Return False

            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

#End Region

#Region "-- Move control -----------------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : f[^ๆ“พ
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    ' –฿่’l    : Boolean       True:ณํ / False:ดืฐ
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfGetMoveParam(ByVal pstrInput As String) As Boolean
        gstrFuncName = "wsGetMoveParam"

        Try
            '\‘ข‘ฬึ’่
            If gintStatus = MainModule.G_ENUM_STATUS.MOVE_FROM Then
                'From
                gstructHtData.MoveFrom = pstrInput.Substring(1, 10)

                'ฝรฐภฝ(ึ)
                mintStatus = M_STATUS.DONE
            Else
                'To
                gstructHtData.MoveTo = pstrInput.Substring(1, 10)

                'ฺ“ฎๆมชฏธ
                If gstructHtData.MoveFrom = gstructHtData.MoveTo Then
                    'ฺ“ฎๆช“ฏถ
                    mintStatus = M_STATUS.SAME_MOVE
                    Return False
                End If
            End If

            Return True

        Catch ex As Exception
            Throw ex
        End Try
    End Function

#End Region

#Region "-- User Area -----------------------------------------------------------------"

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

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

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

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

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

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

            If tmpStr.Count > 0 Then

                values = tmpStr(0)
                Dim result As String = Nothing
                If values.TryGetValue("GrNo", result) Then
                    sGrNo = RTrim(result)
                End If
                If values.TryGetValue("BhkFrom", result) Then
                    sBhkFrom = RTrim(result)
                End If

                gstructHtData.GrNo = sGrNo.ToString.PadRight(2)
                gstructHtData.Bhk = sBhkFrom.ToString.PadRight(3)

                wblnGet = True


            End If




            '๕
            'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_MOVEGR, G_CONST_KEY_MOVEGRKEY00, wstrTblKey, wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)

            ''ดืฐฬ๊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

            '    '่”ิๆ“พ
            '    gstructHtData.GrNo = gclsDB.Records(wstrTblKey).Item("GrNo").ToString.PadRight(2)
            '    gstructHtData.Bhk = gclsDB.Records(wstrTblKey).Item("BhkFrom").ToString.PadRight(3)

            '    wblnGet = True

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

            If wblnGet Then
                'รฐภ ่
                mintStatus = M_STATUS.DONE
            Else
                'รฐภศต
                mintStatus = M_STATUS.NOTEXIST
            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      : ๕—pp[^’่
    ' ๘”      : pstrKey       String      ๕ฬจฐูฤ–ผ
    '           : pstrKeyValue  String      ๕ส฿ืาฐภ
    ' –฿่’l    : ศต
    ' ”๕l      : 
    '*******************************************************************************
    Public Sub wsSearchKey(ByRef pstrKey() As String, ByRef pstrKeyValue() As String)
        gstrFuncName = "wsSearchKey"

        ReDim pstrKey(1)
        ReDim pstrKeyValue(1)

        '๕๐’่
        pstrKey(0) = "MoveFrom"
        pstrKey(1) = "MoveTo"

        With gstructHtData
            pstrKeyValue(0) = .MoveFrom.PadRight(10)
            pstrKeyValue(1) = .MoveTo.PadRight(10)
        End With
    End Sub

#End Region

#End Region

    Private Sub frmPMMV1010_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 frmPMMV1010_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    End Sub
End Class
