﻿
'*******************************************************************************
'* ์ฌ๏ะ : ”ฎ๏ะ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 frmPMMV1005
    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 wfTitle As WarpControl.WarpField
    'Friend WithEvents wfInput As WarpControl.WarpField
    'Friend WithEvents WarpHWBcr1 As WarpControl.WarpHWBcr
    '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.wfTitle = 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.wfTitle)
    '    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 = 10
    '    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(144, 7)
    '    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(8, Short)
    '    '
    '    'wfTitle
    '    '
    '    Me.wfTitle.BackColor = CType(3, Short)
    '    Me.wfTitle.DecimalPointPosition = CType(0, Short)
    '    Me.wfTitle.Font = New System.Drawing.Font("Lucida Console", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfTitle.FontSize = WarpControl.FontSizes.Small
    '    Me.wfTitle.Format = ""
    '    Me.wfTitle.Length = CType(15, Short)
    '    Me.wfTitle.Location = New System.Drawing.Point(5, 43)
    '    Me.wfTitle.MacroBcr = ""
    '    Me.wfTitle.MacroIn = ""
    '    Me.wfTitle.MacroKey = ""
    '    Me.wfTitle.MacroOut = ""
    '    Me.wfTitle.Name = "wfTitle"
    '    Me.wfTitle.Size = New System.Drawing.Size(150, 20)
    '    Me.wfTitle.TabIndex = CType(7, Short)
    '    Me.wfTitle.Text = "XXXXXXXXXXXXXXX"
    '    '
    '    '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.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(5, Short)
    '    '
    '    'WarpHWBcr1
    '    '
    '    Me.WarpHWBcr1.Decode.Code39 = True
    '    Me.WarpHWBcr1.DiscreteFirstLen = CType(0, Short)
    '    Me.WarpHWBcr1.DiscreteSecondLen = CType(0, Short)
    '    Me.WarpHWBcr1.InterleavedFirstLen = CType(0, Short)
    '    Me.WarpHWBcr1.InterleavedSecondLen = CType(0, Short)
    '    '
    '    'frmPMMV1005
    '    '
    '    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 = "frmPMMV1005"
    '    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 "// Enum Area ///////////////////////////////////////////////////////////////////////////"

    'ฝรฐภฝ—๑“^
    Private Enum M_STATUS As Integer
        INIT                '๚ป
        MENUBACK            'าฦญฐสฏธ
        NOTJ                'ๆ“ชชJลอศข
        NOT7                'ีฐปฐบฐฤช7…ลอศข
        NOTEXIST            'ีฐปฐช“o^ณ๊ฤขศข
        DONE                'ณํQฦ
    End Enum

#End Region

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

    '*******************************************************************************
    ' 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

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

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

            'ๆ–ส–ผพฏฤ (–ผD๐ฝทฌ)
            'gclsPubHT.sSetImgFName(CommonMove.clsMsgID.H0010, 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
            sErrLog(gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_WARNING, MWA_DB_OK)
            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()
        'ภฒฤู๐พฏฤ
        'wfTitle.Puts(gclsPubHT.gstrctPPHT.strTitle)

        'ีฐปฐ–ผ๐ธุฑ
        'gclsPubHT.gstrctPPHT.strUserName = ""
        'wfName.Puts(gclsPubHT.gstrctPPHT.strUserName)

        wfTitle.Text = gclsPubHT.gstrctPPHT.strTitle
        gclsPubHT.gstrctPPHT.strUserName = ""
        wfName.Text = gclsPubHT.gstrctPPHT.strUserName



    End Sub

    '*******************************************************************************
    ' T—v      : ๆ–ส’่
    ' ๘”      : buf       String      สฐบฐฤ“—อ’l
    ' –฿่’l    : ศต
    ' ”๕l      : ศต
    '*******************************************************************************

    Public Sub sFinishApp()

        Dim rut As Integer
        Dim wintCnt As Integer
        Dim wstrWhere As String
        Dim wstrKey(0) As String, wstrKeyValue(0) As String
        Dim sSQL As String

        Try

            'BtLib.Transaction.BeginConCurrent()

            'wstrWhere = "@HTNumber = " & gstrctKDHT.strHdNo

            wstrWhere = ""
            wstrWhere = "HTNumber" & " = '" & gclsPubHT.gstrctPPHT.strHdNo & "'"

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

            If tmpStr.Count > 0 Then

            Else
                'fFnc_WrpMsg("S", G_CONST_MID_S0010, "001")
                Exit Sub


            End If

            wstrKey(0) = "HTNumber"
            wstrKeyValue(0) = gclsPubHT.gstrctPPHT.strHdNo

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

            sSQL = "UPDATE " + G_CONST_TBL_VANPJ + " SET ExeName='" _
                                                         + Space(8) _
                                                         + "' , SearchKey='" _
                                                         + Space(30) _
                                                         + "' WHERE " + wstrWhere


            affected_rows = dbClient.Execute(sSQL)


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

    End Sub


    Private Sub wsSetNextStatus()
        gstrFuncName = "wsSetNextStatus"

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

                Case M_STATUS.MENUBACK
                    '// HTCTRL.ExeName๐มตI—น
                    sFinishApp()
                    gintStatus = G_ENUM_STATUS.QUIT
                    Me.Close()

                Case M_STATUS.NOT7, M_STATUS.NOTJ
                    '// 7…ศOฝอJศOศฬลดืฐาฏพฐผ•\ฆ
                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E0010, gfrmMain.WarpCtrl1)

                Case M_STATUS.NOTEXIST
                    '// Qฦรฐภษ–ณขฬลดืฐาฏพฐผ•\ฆ
                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E0020, gfrmMain.WarpCtrl1)

                Case M_STATUS.DONE
                    '// ณํQฦ
                    gintStatus = G_ENUM_STATUS.MOVE_FROM
                    Me.Close()
            End Select

        Catch ex As Exception
            'gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            sErrLog(gAppName, gstrFuncName, ex.ToString)
            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
        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, 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
            sErrLog(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
            Me.Close()
        End Try
    End Function

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

        wfGetCode = -1

        For i = 0 To UBound(mstrChr)
            If mstrChr(i) = pstrValue Then
                wfGetCode = mintChr(i)
                Exit Function
            End If
        Next

    End Function

    Private Function wfGetValue(ByVal pintValue As Integer) As String
        Dim i As Integer

        wfGetValue = -1

        For i = 0 To UBound(mintChr)
            If mintChr(i) = pintValue Then
                wfGetValue = mstrChr(i)
                Exit Function
            End If
        Next

    End Function

    Public Function fCheckCode(ByRef pstrBarCode As String) As Boolean
        Dim i As Integer
        Dim wintChr() As Integer
        Dim wintSum As Integer
        Dim wintAmari As Integer
        Dim wstrBarCode As String
        Dim wstrDigit As String

        fCheckCode = False

        If Len(pstrBarCode) = 0 Then Exit Function

        wstrBarCode = Mid(pstrBarCode, 2, Len(pstrBarCode) - 2)
        wstrDigit = Mid(pstrBarCode, Len(pstrBarCode), 1)

        '// มชฏธรผฏฤ(M43)ฬฎซ๐mฉ฿้
        ReDim wintChr(Len(wstrBarCode) - 1)
        For i = 1 To Len(wstrBarCode)
            wintChr(i - 1) = wfGetCode(Mid(wstrBarCode, i, 1))
        Next

        wintSum = 0
        For i = 0 To UBound(wintChr)
            wintSum = wintSum + wintChr(i)
        Next

        wintAmari = wintSum Mod 43

        If wfGetValue(wintAmari) <> wstrDigit Then
            'มชฏธรผฏฤช•sณลท
            'fFnc_Msg("0304", "3")
            Exit Function
        End If

        pstrBarCode = wstrBarCode
        fCheckCode = True

    End Function

    Private Function wfCheckBarcode(ByRef pstrInput As String) As Boolean
        gstrFuncName = "wfCheckBarcode"

        Dim rtn As Integer

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

            Return True

        Catch ex As Exception
            sErrLog(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
            Me.Close()
        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 wblnExist As Boolean = False

        Try
            '// OCMENUBACK
            'If pstrInput = CommonMove.clsConst.G_CONST_BARCD_MENUBACK Then
            '    mintStatus = M_STATUS.MENUBACK
            '    Return True
            'End If

            '// สฐบฐฤIDมชฏธ
            'If Not pstrInput.StartsWith(G_CONST_BARCDID_USER) Then
            '    'ๆ“ชชJลอศข
            '    mintStatus = M_STATUS.NOTJ
            '    Return True
            'End If

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

            '// ๕—
            If Not wfSearchUser(pstrInput, wblnExist) Then Return False

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

            '// XV—
            If Not wfUpdProcInput() Then Return False

            Return True

        Catch ex As Exception
            sErrLog(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
            Me.Close()
        End Try

    End Function

#End Region

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

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

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

        Try
            '‘ถฬืธฬ๚’l’่
            vblnExist = False

            '์ฦาบฐฤฬๆ“พ
            wstrEmplCode = Mid(pstrInput, 2)

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

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

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

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

            If tmpStr.Count > 0 Then

                values = tmpStr(0)

                Dim result As String = Nothing
                If values.TryGetValue("EmplCode", result) Then
                    gclsPubHT.gstrctPPHT.strUserNo = result
                End If
                If values.TryGetValue("EmplName", result) Then
                    gclsPubHT.gstrctPPHT.strUserName = result
                End If

                gstructHtData.Employer = gclsPubHT.gstrctPPHT.strUserNo
                gstructHtData.UserName = gclsPubHT.gstrctPPHT.strUserName

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


            End If

            If Not vblnExist Then mintStatus = M_STATUS.NOTEXIST

            Return True





            '๕
            'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PICSUSER, G_CONST_KEY_PICSUSERKEY00, wstrTblKey, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
            'If wintRet = CommonMove.clsDBStatus.DB_STATUS.DB_ERROR Then
            '    'ดืฐฬ๊A—๐”ฒฏ้
            '    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

            '    'รฐภฬๆ“พ
            '    With gclsDB.Records(wstrTblKey)
            '        gclsPubHT.gstrctPPHT.strUserNo = .Item("EmplCode").ToString
            '        gclsPubHT.gstrctPPHT.strUserName = .Item("EmplName").ToString
            '    End With

            '    gstructHtData.Employer = gclsPubHT.gstrctPPHT.strUserNo
            '    gstructHtData.UserName = gclsPubHT.gstrctPPHT.strUserName

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

            '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
            sErrLog(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()
        End Try
    End Function

#End Region

#Region "-- Control Area -----------------------------------------------------------------"

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

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

        Try
            '๕๐’่
            Call gclsCheck.wsSearchKey_HTCTRL(wstrKey, wstrKeyValue)

            '“o^f[^’่
            Call gclsCheck.wsSetKey_HTCTRL(wstrSetKey, wstrSetKeyValue)

            wstrWhere = ""
            wstrWhere = wstrKey(0) & " = '" & wstrKeyValue(0) & "'"
            sSql = ""

            For index As Integer = 0 To wstrSetKey.Count


                If index = 0 Then
                    sSql = "UPDATE " + G_CONST_TBL_HTCTRL + " SET " + wstrSetKey(index) + "='" + wstrSetKeyValue(index) + "'"

                ElseIf index = wstrSetKey.Count 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รฐภ๐DBษ“o^
            'wintRet = gclsDB.fUpdRecords(G_CONST_TBL_HTCTRL, G_CONST_KEY_HTCTRLKEY00, 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

            'ฝรฐภฝพฏฤ
            mintStatus = M_STATUS.DONE

            '–฿่’lTrue๐•ิท
            Return True

        Catch ex As Exception
            sErrLog(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
            Me.Close()
        End Try
    End Function

#End Region

#End Region

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

    '*******************************************************************************
    ' T—v      : ๕—pp[^’่
    ' ๘”      : pstrKey       String      ๕ฬจฐูฤ–ผ
    '           : pstrKeyValue  String      ๕ส฿ืาฐภ
    '           : vstrUserNo    String      ทฐ€–ฺ(ีฐปฐ”ิ)
    ' –฿่’l    : ศต
    ' ”๕l      : 
    '*******************************************************************************
    Public Sub wsSearchKey(ByRef pstrKey() As String, ByRef pstrKeyValue() As String, ByVal vstrUserNo As String)
        gstrFuncName = "wsSearchKey"

        ReDim pstrKey(1)
        ReDim pstrKeyValue(1)

        '๕๐’่
        pstrKey(0) = "EmplCode"
        pstrKey(1) = "System"

        pstrKeyValue(0) = vstrUserNo.PadRight(6)
        pstrKeyValue(1) = Space(4)
    End Sub

#End Region

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

    Private Sub frmPMMV1005_KeyDown(ByVal sender As System.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
End Class
