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

Public Class frm5010
    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 WarpCtrl1 As WarpControl.WarpCtrl
    'Friend WithEvents WarpHWBcr1 As WarpControl.WarpHWBcr
    'Friend WithEvents WarpBox1 As WarpControl.WarpBox
    'Friend WithEvents wfKey As WarpControl.WarpField
    'Friend WithEvents WarpFrame1 As WarpControl.WarpFrame
    'Friend WithEvents WarpField3 As WarpControl.WarpField
    'Friend WithEvents wfName As WarpControl.WarpField
    'Friend WithEvents wfLocation As WarpControl.WarpField
    'Friend WithEvents wfTitle As WarpControl.WarpField

    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame()
    '    Me.wfTitle = New WarpControl.WarpField()
    '    Me.wfLocation = New WarpControl.WarpField()
    '    Me.WarpField3 = New WarpControl.WarpField()
    '    Me.wfKey = New WarpControl.WarpField()
    '    Me.WarpBox1 = New WarpControl.WarpBox()
    '    Me.wfName = New WarpControl.WarpField()
    '    Me.WarpHWBcr1 = New WarpControl.WarpHWBcr()
    '    Me.WarpFrame1.SuspendLayout()
    '    Me.SuspendLayout()
    '    '
    '    'WarpFrame1
    '    '
    '    Me.WarpFrame1.Controls.Add(Me.wfTitle)
    '    Me.WarpFrame1.Controls.Add(Me.wfLocation)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField3)
    '    Me.WarpFrame1.Controls.Add(Me.wfKey)
    '    Me.WarpFrame1.Controls.Add(Me.WarpBox1)
    '    Me.WarpFrame1.Controls.Add(Me.wfName)
    '    Me.WarpFrame1.Font = New System.Drawing.Font("MS UI Gothic", 9.0!)
    '    Me.WarpFrame1.Location = New System.Drawing.Point(0, 0)
    '    Me.WarpFrame1.Name = "WarpFrame1"
    '    Me.WarpFrame1.Size = New System.Drawing.Size(240, 296)
    '    Me.WarpFrame1.TabIndex = 1
    '    Me.WarpFrame1.Text = "WarpFrame1"
    '    Me.WarpFrame1.UseMacro = False
    '    Me.WarpFrame1.UseMacroFileName = ""
    '    '
    '    'wfTitle
    '    '
    '    Me.wfTitle.BcrFlag = True
    '    Me.wfTitle.DecimalPointPosition = CType(0, Short)
    '    Me.wfTitle.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfTitle.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfTitle.Format = ""
    '    Me.wfTitle.InputAttribute.Reverse = True
    '    Me.wfTitle.InputMode.Clear = True
    '    Me.wfTitle.Length = CType(12, Short)
    '    Me.wfTitle.Location = New System.Drawing.Point(60, 0)
    '    Me.wfTitle.MacroBcr = ""
    '    Me.wfTitle.MacroIn = ""
    '    Me.wfTitle.MacroKey = ""
    '    Me.wfTitle.MacroOut = ""
    '    Me.wfTitle.Name = "wfTitle"
    '    Me.wfTitle.Size = New System.Drawing.Size(144, 24)
    '    Me.wfTitle.TabIndex = CType(12, Short)
    '    '
    '    'wfLocation
    '    '
    '    Me.wfLocation.BcrFlag = True
    '    Me.wfLocation.DecimalPointPosition = CType(0, Short)
    '    Me.wfLocation.DisplayAttribute.Bold = True
    '    Me.wfLocation.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfLocation.Format = ""
    '    Me.wfLocation.InputMode.Clear = True
    '    Me.wfLocation.Length = CType(8, Short)
    '    Me.wfLocation.Location = New System.Drawing.Point(36, 72)
    '    Me.wfLocation.MacroBcr = ""
    '    Me.wfLocation.MacroIn = ""
    '    Me.wfLocation.MacroKey = ""
    '    Me.wfLocation.MacroOut = ""
    '    Me.wfLocation.Name = "wfLocation"
    '    Me.wfLocation.Size = New System.Drawing.Size(144, 36)
    '    Me.wfLocation.TabIndex = CType(9, Short)
    '    Me.wfLocation.Text = "X - XXXX"
    '    '
    '    'WarpField3
    '    '
    '    Me.WarpField3.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField3.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField3.FontSize = WarpControl.FontSizes.Small
    '    Me.WarpField3.Format = ""
    '    Me.WarpField3.Length = CType(8, Short)
    '    Me.WarpField3.Location = New System.Drawing.Point(12, 36)
    '    Me.WarpField3.MacroBcr = ""
    '    Me.WarpField3.MacroIn = ""
    '    Me.WarpField3.MacroKey = ""
    '    Me.WarpField3.MacroOut = ""
    '    Me.WarpField3.Name = "WarpField3"
    '    Me.WarpField3.Size = New System.Drawing.Size(120, 30)
    '    Me.WarpField3.TabIndex = CType(8, Short)
    '    Me.WarpField3.Text = "Location"
    '    '
    '    'wfKey
    '    '
    '    Me.wfKey.BcrFlag = True
    '    Me.wfKey.DecimalPointPosition = CType(0, Short)
    '    Me.wfKey.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfKey.Format = ""
    '    Me.wfKey.InputMode.Secret = True
    '    Me.wfKey.Length = CType(1, Short)
    '    Me.wfKey.Location = New System.Drawing.Point(204, 96)
    '    Me.wfKey.MacroBcr = ""
    '    Me.wfKey.MacroIn = ""
    '    Me.wfKey.MacroKey = ""
    '    Me.wfKey.MacroOut = ""
    '    Me.wfKey.Name = "wfKey"
    '    Me.wfKey.Size = New System.Drawing.Size(18, 36)
    '    Me.wfKey.TabIndex = CType(4, Short)
    '    '
    '    'WarpBox1
    '    '
    '    Me.WarpBox1.BoxType = WarpControl.BoxTypes.Box
    '    Me.WarpBox1.DrawMode = WarpControl.DrawModes.Paint
    '    Me.WarpBox1.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpBox1.ForeColor = CType(15, Short)
    '    Me.WarpBox1.Image = "C:\H081-0010.jpg"
    '    Me.WarpBox1.Location = New System.Drawing.Point(0, 192)
    '    Me.WarpBox1.Name = "WarpBox1"
    '    Me.WarpBox1.Size = New System.Drawing.Size(240, 24)
    '    Me.WarpBox1.TabIndex = 3
    '    '
    '    'wfName
    '    '
    '    Me.wfName.DecimalPointPosition = CType(0, Short)
    '    Me.wfName.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfName.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfName.Format = ""
    '    Me.wfName.Length = CType(20, Short)
    '    Me.wfName.Location = New System.Drawing.Point(0, 216)
    '    Me.wfName.MacroBcr = ""
    '    Me.wfName.MacroIn = ""
    '    Me.wfName.MacroKey = ""
    '    Me.wfName.MacroOut = ""
    '    Me.wfName.Name = "wfName"
    '    Me.wfName.Size = New System.Drawing.Size(240, 24)
    '    Me.wfName.TabIndex = CType(2, Short)
    '    '
    '    'WarpHWBcr1
    '    '
    '    Me.WarpHWBcr1.Decode.Code39 = True
    '    Me.WarpHWBcr1.Decode.UPC_EAN_JAN = True
    '    Me.WarpHWBcr1.DiscreteFirstLen = CType(0, Short)
    '    Me.WarpHWBcr1.DiscreteSecondLen = CType(0, Short)
    '    Me.WarpHWBcr1.InterleavedFirstLen = CType(0, Short)
    '    Me.WarpHWBcr1.InterleavedSecondLen = CType(0, Short)
    '    '
    '    'frm5010
    '    '
    '    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
    '    Me.ClientSize = New System.Drawing.Size(240, 296)
    '    Me.Controls.Add(Me.WarpFrame1)
    '    Me.Font = New System.Drawing.Font("MS UI Gothic", 9.0!)
    '    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
    '    Me.Name = "frm5010"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region

    Public Enum M5010_STATUS As Integer
        INIT = 0
        SHUTDOWN = 1
        MENUBACK = 2
        NOTCODE = 3
        NOTEXIST = 4
        NOTITEM = 5
        DONE = 6
    End Enum

    Public mint5010status As Integer

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

    Private Sub frm5010_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        '// Case QVGA -> resolution to 1/2
        If System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width = 240 Then
            Call resolution.VGAtoQVGA(Me)
        End If

        Dim wstrImage As String
        Dim rtn As Integer

        Try

            mint5010status = M5010_STATUS.INIT

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

            'sSetImgFName(G_CONST_MID_H5010, WarpBox1)

            gstrctS5000.initialize()
            sDisp5010()

            ' tH[€EC“ ภs
            sMain()

            ' t[€ฬN[Y
            'rtn = WarpFrame1.Close()
            'If (rtn <> 0) Then
            '    Err.Raise(vbObjectError + 1, gAppName, "WarpError")
            'End If

            ' tH[€EN[Y
            'Me.Close()

            Exit Sub

        Catch ex As Exception
            gintStatus = LOCA_STATUS.QUIT
            sErrLog(gAppName, "frm5010_Load", ex.ToString)
            Me.Close()
        End Try

    End Sub

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

        If (Not fCheckCode(buf)) Then
            sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
            fFnc_WrpMsg("E", G_CONST_MID_E5E11)
            Exit Sub
        End If

        '“—อ—
        rtn = fProcInput(buf)

        If rtn = 0 Then
            Select Case mint5010status
                Case M5010_STATUS.INIT

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

                    gintStatus = LOCA_STATUS.LOCATION
                    Me.Close()
                    Exit Sub

                Case M5010_STATUS.SHUTDOWN          'HTCTRL.ExeName๐มตฤI—น
                    sFinishApp()
                    gintStatus = LOCA_STATUS.QUIT
                    Me.Close()
                    Exit Sub

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

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

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

                Case M5010_STATUS.NOTCODE              'w’่บฐฤศOศฬลดืฐาฏพฐผ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E5E11)
                    Exit Sub
                Case M5010_STATUS.NOTEXIST              'Qฦรฐภษ–ณขฬลดืฐาฏพฐผ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E5E12)
                    Exit Sub
                Case M5010_STATUS.NOTITEM              '๓ฬนฐผฎฬ“วฬฝ฿ดืฐาฏพฐผ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E5E13)
                    Exit Sub
                Case M5010_STATUS.DONE              'ณํษQฦลซฝ

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

                    gintStatus = LOCA_STATUS.SHOW
                    Me.Close()
                    Exit Sub

            End Select

        Else

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

        End If

    End Sub


    ' t[€EC“
    Public Sub sMain()

        'Dim WKey As Short
        'Dim buf As String
        'Dim rtn As Integer
        'Try

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

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

        '        If WKey = WKY_ENT Then

        '        ElseIf WKey = WKY_BCR Then
        '            rtn = WarpHWBcr1.Get(buf)
        '            sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.OK)
        '            If (rtn <> 0) Then
        '                Err.Raise(vbObjectError + 1, gAppName, "WarpError")
        '            End If
        '            If (Not fCheckCode(buf)) Then
        '                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                fFnc_WrpMsg("E", G_CONST_MID_E5E11)

        '                Exit Do
        '            End If

        '            '“—อ—
        '            rtn = fProcInput(buf)

        '            If rtn = 0 Then
        '                Select Case mint5010status
        '                    Case M5010_STATUS.INIT

        '                        gintStatus = LOCA_STATUS.LOCATION

        '                    Case M5010_STATUS.SHUTDOWN          'HTCTRL.ExeName๐มตฤI—น
        '                        sFinishApp()
        '                        gintStatus = LOCA_STATUS.QUIT

        '                    Case M5010_STATUS.MENUBACK          'าฦญฐสฏธ
        '                        gintStatus = LOCA_STATUS.NAME

        '                    Case M5010_STATUS.NOTCODE              'w’่บฐฤศOศฬลดืฐาฏพฐผ
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                        fFnc_WrpMsg("E", G_CONST_MID_E5E11)

        '                    Case M5010_STATUS.NOTEXIST              'Qฦรฐภษ–ณขฬลดืฐาฏพฐผ
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                        fFnc_WrpMsg("E", G_CONST_MID_E5E12)

        '                    Case M5010_STATUS.NOTITEM              '๓ฬนฐผฎฬ“วฬฝ฿ดืฐาฏพฐผ
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                        fFnc_WrpMsg("E", G_CONST_MID_E5E13)

        '                    Case M5010_STATUS.DONE              'ณํษQฦลซฝ
        '                        gintStatus = LOCA_STATUS.SHOW

        '                End Select

        '            Else

        '                f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, MWA_DB_WARNING, MWA_DB_OK)

        '            End If
        '            Exit Do

        '        ElseIf WKey = WKY_F1 Then

        '        ElseIf WKey = WKY_F2 Then

        '        ElseIf WKey = WKY_ERROR Then

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

        '        End If

        '    Loop

        '    Exit Sub

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

    End Sub

    '/*
    '|| ึ”–ผFsDisp5010
    '|| T—v  F5010ๆ–ส•\ฆ
    '*/
    Private Sub sDisp5010()

        'wfLocation.Clr()
        'wfTitle.Puts(gstrctKDHT.strTitle)
        'wfName.Puts(gstrctKDHT.strUserName)

        wfLocation.Text = ""
        wfTitle.Text = gstrctKDHT.strTitle
        wfName.Text = gstrctKDHT.strUserName

    End Sub


    '/*
    '|| ึ”–ผFfProcInput
    '|| T—v  F“—อ—
    '*/
    Private Function fProcInput(ByVal pstrInput As String) As Integer

        Dim rtn As Integer
        Dim wintRet1 As Integer
        Dim wintRet2 As Integer

        fProcInput = -1

        Try

            If RTrim(pstrInput) = "OCMENUBACK" Then             'OCMENUBACKศ็ฮ
                mint5010status = M5010_STATUS.MENUBACK
                fProcInput = 0
                Exit Function

            ElseIf RTrim(pstrInput) = "OCSHUTDOWN" Then         'OCSHUTDOWNศ็ฮ
                mint5010status = M5010_STATUS.SHUTDOWN
                fProcInput = 0
                Exit Function

            ElseIf pstrInput.StartsWith("T") Then
                rtn = pstrInput.Length
                If rtn <> 9 Then                    '9…ศOศ็ฮ
                    mint5010status = M5010_STATUS.NOTCODE
                    fProcInput = 0
                    Exit Function
                End If

            Else
                mint5010status = M5010_STATUS.NOTCODE 'R[hแข
                fProcInput = 0
                Exit Function

            End If

            'RL2RL๐๕
            wintRet1 = fProcSearch(pstrInput)

            If wintRet1 = 0 Then
                wintRet2 = fSearchLocation()
                If wintRet2 = 1 Then
                    mint5010status = M5010_STATUS.DONE
                ElseIf wintRet2 = 0 Then
                    mint5010status = M5010_STATUS.NOTEXIST
                Else
                    Exit Function
                End If

            ElseIf wintRet1 = -2 Then    '๕ส@P[V“ิแข
                mint5010status = M5010_STATUS.NOTEXIST
                fProcInput = 0
                Exit Function
            ElseIf wintRet1 = -1 Then    'DBดืฐ
                Exit Function
            End If
            fProcInput = 0

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

        End Try

    End Function
    '/*
    '|| ึ”–ผFfProcSearch
    '|| T—v  F๕—(RL2RL)
    '*/

    Private Function fProcSearch(ByVal pstrInput As String) As Integer
        Dim wstrBhk As String
        Dim wstrLocation As String
        Dim wintCnt As Integer
        Dim wstrWhere As String
        Dim wstrKey(2) As String
        Dim wstrKeyValue(2) As String

        fProcSearch = -1

        'RL2RL๐๕
        wintCnt = 0

        wstrBhk = pstrInput.Substring(1, 3)
        wstrLocation = pstrInput.Substring(4)
        'wstrWhere = ""
        'wstrWhere = "@Bhk = " & wstrBhk

        wstrWhere = ""
        wstrWhere = "Bhk = '" & wstrBhk & "'"

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

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

        If tmpStr.Count > 0 Then

            values = tmpStr(0)

            Dim result As String = Nothing
            If values.TryGetValue("Bhk", result) Then
                sBhk = result
            End If
            If values.TryGetValue("CenterCode", result) Then
                sCenterCode = result
            End If

            gstrctS5000.strBhk = sBhk
            gstrctS5000.strCenterCode = sCenterCode
            gstrctS5000.strLocation = wstrLocation

        Else

            fProcSearch = -2
            Exit Function


        End If

        fProcSearch = 0



        'wintCnt = gclsDB.fGetData(G_CONST_TBL_RL2RL, G_CONST_KEY_RL2RLKEY00, wstrWhere, "RL2RL1")

        'If wintCnt > 0 Then         '๕ส@—L่

        '    With gclsDB.Extended("RL2RL1")
        '        gstrctS5000.strBhk = .Item("Bhk")
        '        gstrctS5000.strCenterCode = .Item("CenterCode")
        '        gstrctS5000.strLocation = wstrLocation
        '    End With
        'ElseIf wintCnt = 0 Then     '๕ส@–ณต
        '    fProcSearch = -2
        '    gclsDB.fCloseRecord("RL2RL1")
        '    Exit Function

        'ElseIf wintCnt = -1 Then
        '    gclsDB.fCloseRecord("RL2RL1")
        '    Exit Function

        'End If
        'fProcSearch = 0
        'gclsDB.fCloseRecord("RL2RL1")

    End Function

    '/*
    '|| ึ”–ผFfSearchLocation
    '|| T—v  Fนฐผฎ๕
    '|| ๘”@F–ณต
    '|| –฿่’lF-1(NG),1(OK),0(รฐภ–ณต)   
    '*/
    Private Function fSearchLocation() As Integer
        Dim wstrKey(3) As String
        Dim wstrKeyValue(3) As String
        Dim wintRet As Integer
        Dim wstrWhere As String
        fSearchLocation = -1
        Try
            wstrKey(0) = "CenterCode" : wstrKeyValue(0) = gstrctS5000.strCenterCode
            wstrKey(1) = "Bhk" : wstrKeyValue(1) = gstrctS5000.strBhk
            wstrKey(2) = "Location" : wstrKeyValue(2) = gstrctS5000.strLocation
            'wstrKey(3) = "Product" : wstrKeyValue(3) = "999999"
            '>>> ADD ST  20060303 >>>
            wstrKey(3) = "Product" : wstrKeyValue(3) = "200603"
            '<<< ADD END 20060303 <<<

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

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


            If tmpStr.Count > 0 Then


                fSearchLocation = 1

            Else

                fSearchLocation = 0

            End If

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

        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_LOCATION, G_CONST_KEY_LOCATIONKEY00, "LOC01", wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)
        'If wintRet = -1 Then
        '    Exit Function
        'ElseIf wintRet = 0 Then
        '    fSearchLocation = 1
        'Else
        '    fSearchLocation = 0
        'End If
        'gclsDB.fCloseRecord("LOC01")
        'Catch ex As Exception
        '    sErrLog(gAppName, "fSearchLocation", ex.ToString)
        'End Try
    End Function

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