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

Public Class frm3010
    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)
    '    '
    '    'frm3010
    '    '
    '    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 = "frm3010"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region

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

    Public mint3010status As Integer

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

            mint3010status = M3010_STATUS.INIT

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

            'sSetImgFName(G_CONST_MID_H3010, WarpBox1)

            sDisp3010()

            ' 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, "frm3010_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_E3E15)
            Exit Sub
        End If

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

        If rtn = 0 Then
            Select Case mint3010status
                Case M3010_STATUS.INIT

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

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

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

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

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

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

                Case M3010_STATUS.NOTCODE              'w’่บฐฤศOศฬลดืฐาฏพฐผ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E3E15)
                    Exit Sub
                Case M3010_STATUS.NOTEXIST              'Qฦรฐภษ–ณขฬลดืฐาฏพฐผ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E3E20)
                    Exit Sub
                Case M3010_STATUS.NOTITEM              '๓ฬนฐผฎฬ“วฬฝ฿ดืฐาฏพฐผ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E3E25)
                    Exit Sub
                Case M3010_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_E3E15)

        '                Exit Do
        '            End If

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

        '            If rtn = 0 Then
        '                Select Case mint3010status
        '                    Case M3010_STATUS.INIT

        '                        gintStatus = LOCA_STATUS.LOCATION

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

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

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

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

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

        '                    Case M3010_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

    '/*
    '|| ึ”–ผFsDisp3010
    '|| T—v  F3010ๆ–ส•\ฆ
    '*/
    Private Sub sDisp3010()

        '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 wintCnt As Integer
        Dim wintCnt1 As Integer

        fProcInput = -1

        Try

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

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

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

            Else
                mint3010status = M3010_STATUS.NOTCODE 'ๆ“ชชTศ็ฮ
                fProcInput = 0
                Exit Function

            End If

            'RL2RL๐๕
            wintCnt = fProcSearch(pstrInput)

            If wintCnt = 0 Then
                '”m”FiSTOCK๐๕j
                wintCnt1 = fProcSearchItem()

                If wintCnt1 = 0 Then    '๕ส@ษ—L่



                ElseIf wintCnt1 = -2 Then   '๕ส@ษ–ณต
                    mint3010status = M3010_STATUS.NOTITEM
                    fProcInput = 0
                    Exit Function
                ElseIf wintCnt1 = -1 Then   'DBดืฐ
                    Exit Function
                End If

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

            mint3010status = M3010_STATUS.DONE
            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


            gstrctS3000.strBhk = sBhk
            gstrctS3000.strCenterCode = sCenterCode
            gstrctS3000.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")
        '        gstrctS3000.strBhk = .Item("Bhk")
        '        gstrctS3000.strCenterCode = .Item("CenterCode")
        '        gstrctS3000.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
    '/*
    '|| ึ”–ผFfProcSearchItem
    '|| T—v  F๕—(ํ—ฬm”FA”ถณฤ)
    '*/
    Private Function fProcSearchItem() As Integer
        Dim wintCnt As Integer
        Dim wlngCnt As Long
        Dim wstrKey(7) As String
        Dim wstrKeyValue(7) As String
        Dim i, s As Long
        Dim wstrItemCode As String
        Dim wstrWhere As String


        'ReDim gstrctS3000.strItemId(0)
        'ReDim gstrctS3000.strItemCode(0)
        'ReDim gstrctS3000.strSerial(0)

        fProcSearchItem = -1

        wstrKey(0) = "PicsType" : wstrKeyValue(0) = gstrctKDHT.strPackType
        wstrKey(1) = "Cstmid" : wstrKeyValue(1) = gstrctKDHT.strCstmid
        wstrKey(2) = "CstmCode" : wstrKeyValue(2) = gstrctKDHT.strCstmCode
        wstrKey(3) = "CenterCode" : wstrKeyValue(3) = gstrctS3000.strCenterCode
        wstrKey(4) = "Bhk" : wstrKeyValue(4) = gstrctS3000.strBhk
        wstrKey(5) = "Location" : wstrKeyValue(5) = gstrctS3000.strLocation
        wstrKey(6) = "ItemCode" : wstrKeyValue(6) = Space(30)
        wstrKey(7) = "SerialNo" : wstrKeyValue(7) = Space(6)


        wstrWhere = ""
        wstrWhere = wstrKey(0) & " = '" & wstrKeyValue(0) & "'"
        wstrWhere &= " and " & wstrKey(1) & " = '" & wstrKeyValue(1) & "'"
        wstrWhere &= " and " & wstrKey(2) & " = '" & wstrKeyValue(2) & "'"
        wstrWhere &= " and " & wstrKey(3) & " = '" & wstrKeyValue(3) & "'"
        wstrWhere &= " and " & wstrKey(4) & " = '" & wstrKeyValue(4) & "'"
        wstrWhere &= " and " & wstrKey(5) & " = '" & wstrKeyValue(5) & "'"
        wstrWhere &= " and " & wstrKey(6) & " = '" & wstrKeyValue(6) & "'"
        wstrWhere &= " and " & wstrKey(7) & " = '" & wstrKeyValue(7) & "'"

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

        Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
        Dim sPicsType As String = ""
        Dim sCstmid As String = ""
        Dim sCenterCode As String = ""
        Dim sBhk As String = ""
        Dim sLocation As String = ""
        Dim sZaikoStatus As String = ""
        Dim sItemid As String = ""
        Dim sItemCode As String = ""
        Dim sSerialNo As String = ""
       
        Dim i1 As Integer = 0

        If tmpStr.Count > 0 Then


            Do

                values = tmpStr(i1)

                Dim result As String = Nothing
                If values.TryGetValue("PicsType", result) Then
                    sPicsType = RTrim(result)
                End If
                If values.TryGetValue("Cstmid", result) Then
                    sCstmid = RTrim(result)
                End If
                If values.TryGetValue("CenterCode", result) Then
                    sCenterCode = RTrim(result)
                End If
                If values.TryGetValue("Bhk", result) Then
                    sBhk = RTrim(result)
                End If
                If values.TryGetValue("Location", result) Then
                    sLocation = RTrim(result)
                End If
                If values.TryGetValue("ZaikoStatus", result) Then
                    sZaikoStatus = RTrim(result)
                End If
                If values.TryGetValue("Itemid", result) Then
                    sItemid = RTrim(result)
                End If
                If values.TryGetValue("ItemCode", result) Then
                    sItemCode = RTrim(result)
                End If
                If values.TryGetValue("SerialNo", result) Then
                    sSerialNo = RTrim(result)
                End If

                If (RTrim(gstrctKDHT.strPackType) = RTrim(sPicsType) And _
                        RTrim(gstrctKDHT.strCstmid) = RTrim(sCstmid) And _
                        RTrim(gstrctS3000.strCenterCode) = RTrim(sCenterCode) And _
                        RTrim(gstrctS3000.strBhk) = RTrim(sBhk) And _
                        RTrim(gstrctS3000.strLocation) = RTrim(sLocation)) Then

                    If sZaikoStatus = "3" Or sZaikoStatus = "4" Or sZaikoStatus = "5" Then
                        ReDim Preserve gstrctS3000.strItemId(i)
                        ReDim Preserve gstrctS3000.strItemCode(i)
                        ReDim Preserve gstrctS3000.strSerial(i)

                        gstrctS3000.strItemId(i) = sItemid
                        gstrctS3000.strItemCode(i) = sItemCode
                        gstrctS3000.strSerial(i) = sSerialNo
                        i += 1


                        If wstrItemCode <> sItemCode Then
                            wstrItemCode = sItemCode
                            s += 1
                        End If
                    End If
                Else
                    Exit Do
                End If


                i1 = i1 + 1

                If tmpStr.Count = i Then
                    Exit Do
                End If


            Loop

            If i = 0 Then
                fProcSearchItem = -2
            Else
                gstrctS3000.lngCntItem = s
                gstrctS3000.lngCntnumber = i
                fProcSearchItem = 0
            End If

        Else

            Exit Function


        End If







        'wintCnt = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY04, "STOCK1", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)

        'If wintCnt = 0 Then
        '    With gclsDB.Records("STOCK1")
        '        i = 0 : s = 0
        '        Do
        '            If (RTrim(gstrctKDHT.strPackType) = RTrim(.Item("PicsType")) And _
        '                RTrim(gstrctKDHT.strCstmid) = RTrim(.Item("Cstmid")) And _
        '                RTrim(gstrctS3000.strCenterCode) = RTrim(.Item("CenterCode")) And _
        '                RTrim(gstrctS3000.strBhk) = RTrim(.Item("Bhk")) And _
        '                RTrim(gstrctS3000.strLocation) = RTrim(.Item("Location"))) Then

        '                If .Item("ZaikoStatus") = "3" Or .Item("ZaikoStatus") = "4" Or .Item("ZaikoStatus") = "5" Then
        '                    ReDim Preserve gstrctS3000.strItemId(i)
        '                    ReDim Preserve gstrctS3000.strItemCode(i)
        '                    ReDim Preserve gstrctS3000.strSerial(i)

        '                    gstrctS3000.strItemId(i) = .Item("Itemid")
        '                    gstrctS3000.strItemCode(i) = .Item("ItemCode")
        '                    gstrctS3000.strSerial(i) = .Item("SerialNo")
        '                    i += 1


        '                    If wstrItemCode <> .Item("ItemCode") Then
        '                        wstrItemCode = .Item("ItemCode")
        '                        s += 1
        '                    End If
        '                End If
        '            Else
        '                Exit Do
        '            End If
        '            If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do
        '        Loop
        '    End With
        '    If i = 0 Then
        '        fProcSearchItem = -2
        '    Else
        '        gstrctS3000.lngCntItem = s
        '        gstrctS3000.lngCntnumber = i
        '        fProcSearchItem = 0
        '    End If
        'ElseIf wintCnt = 9 Then '๕สช–ณฉมฝ
        '    fProcSearchItem = -2
        'Else        'ปฬ‘ผฬดืฐ
        '    gclsDB.fCloseRecord("STOCK1")
        '    Exit Function
        'End If
        'gclsDB.fCloseRecord("STOCK1")

    End Function

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