Imports System
Imports System.Linq
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports Microsoft.WindowsCE.Forms
Imports System.Runtime.InteropServices
Imports Bt
Imports Bt.ScanLib
'Imports KDPA2000.BtScanLib
Imports BTClientLib
Imports System.IO
Imports System.Reflection
Imports BtScan2

Public Class frm2015
    Inherits System.Windows.Forms.Form
    Private btScanLib As BtScanLib
    Public Shared _frm2015 As frm2015
    Private scanHandler As Boolean = False
    'Private dbClient As BtrieveDbClient
    Private tmpStr As List(Of Dictionary(Of String, String))
    Private affected_rows As Integer

    Public Enum M2015_STATUS As Integer
        INIT = 0
        OCEND = 1
        CANCEL = 2
        MENUBACK = 3
        NA = 4
        NOLOC = 5
        NOSTATUS7 = 6
        NOSTATUS3 = 7
        NOSTATUS5 = 8
        LOCMATCHED = 9
        LOCUNMATCHED = 10
        SECOND = 11
        PNOTEXIST = 12
        SNOTEXIST = 13
        DONE = 14
    End Enum
    Public mint2015status As Integer

    Public mintCnt As Integer
    Public mintTotal As Integer

    Private gstrScanItem() As String

    Public mhtScanPart As New Hashtable

    Private Sub frm2015()
        InitializeComponent()
    End Sub

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

    Public Function fgetAppPath() As String
        ' Get the directory of the currently executing assembly (the application)
        Return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
    End Function

    Private Sub btScanLib_OnScan(ByVal result As String)
        Dim buf As String = result
        Dim rtn As Integer = 0
        Dim fE32 As New frm2E32
        Try
            '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)
#If Not Debug Then
                fFnc_WrpMsg("E", G_CONST_MID_E0060)
#End If
                rtn = 0
                mint2015status = M2015_STATUS.INIT
            Else
                '“—อ—
                rtn = fProcInput(buf)

            End If

            If rtn = 0 Then
                Select Case mint2015status
                    Case M2015_STATUS.INIT

                        'Case M2015_STATUS.OCEND

                        '    gintStatus = ALL_STATUS.QUIT
                        '    BtLib.Transaction.Abort()
                        '    sFinishApp()
                        '    Exit Do

                    Case M2015_STATUS.CANCEL            'ทฌพู

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

                        gintStatus = ALL_STATUS.LOCATION
                        ' BtLib.Transaction.Abort()
                        Me.Close()
                        Exit Sub

                    Case M2015_STATUS.NA                'T,P,ZศOศฬลดืฐาฏพฐผ
                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                        sOutputLog(gstrctPicsIni.strOutput_KDPA, "KDPA2E30", G_CONST_BC_PART, buf)
#If Not Debug Then
                        fFnc_WrpMsg("E", G_CONST_MID_E2E30)
#End If
                    Case M2015_STATUS.NOLOC              'STOCKฬLocationช}b`นธ
                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                        sOutputLog(gstrctPicsIni.strOutput_KDPA, "KDPA2E35", gstrctP2000.strLctnStart, gstrctP2000.strLctnM)
#If Not Debug Then
                        fFnc_WrpMsg("E", G_CONST_MID_E2E35)
#End If

                    Case M2015_STATUS.NOSTATUS7             '
                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                        sOutputLog(gstrctPicsIni.strOutput_KDPA, "KDPA2E37", gstrctP2000.strLctnStart, gstrctP2000.strLctnM)
#If Not Debug Then
                        fFnc_WrpMsg("E", G_CONST_MID_E2E37)
#End If

                    Case M2015_STATUS.NOSTATUS3             '2005/03/17’วม
                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                        sOutputLog(gstrctPicsIni.strOutput_KDPA, "KDPA2E38", gstrctP2000.strLctnStart, gstrctP2000.strLctnM)
#If Not Debug Then
                        fFnc_WrpMsg("E", G_CONST_MID_E2E38)
#End If

                    Case M2015_STATUS.NOSTATUS5             '2005/03/17’วม
                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                        sOutputLog(gstrctPicsIni.strOutput_KDPA, "KDPA2E39", gstrctP2000.strLctnStart, gstrctP2000.strLctnM)
#If Not Debug Then
                        fFnc_WrpMsg("E", G_CONST_MID_E2E39)
#End If

                    Case M2015_STATUS.LOCMATCHED        '

                        'BtLib.Transaction.End()

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

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

                    Case M2015_STATUS.LOCUNMATCHED      '
                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                        sOutputLog(gstrctPicsIni.strOutput_KDPA, "KDPA2E32", gstrctP2000.strLctnStart, gstrctP2000.strLctnM)
#If Not Debug Then
                        fFnc_WrpMsg("E", G_CONST_MID_E2E40)
#End If
                    Case M2015_STATUS.SECOND
                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
#If Not Debug Then
                        fFnc_WrpMsg("E", G_CONST_MID_E2E42)
#End If

                    Case M2015_STATUS.PNOTEXIST          '
                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)

                        fE32 = New frm2E32
                        fE32.pPartLabel = buf
                        ' tH[€E[h
                        fE32.Show()
                        fE32.Dispose()

                        'BtLib.Transaction.Abort()
                        Exit Sub

                    Case M2015_STATUS.SNOTEXIST          '
                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)

#If Not Debug Then
                        fFnc_WrpMsg("E", G_CONST_MID_E2E33)
#End If

                    Case M2015_STATUS.DONE              'ณํษQฦลซฝ

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

                        sUpdateScreen(result)

                End Select

            Else

                'BtLib.Transaction.Abort()
                '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)
                'f0.Show()
                Exit Sub

            End If
        Catch ex As Exception

        End Try
    End Sub
    '/*
    '|| Function Name: sUpdateScreen
    '|| Version: 4015 screen update
    '*/
    Private Sub sUpdateScreen(ByVal buf As String)
        wfPut.Text = mintCnt
        wfPutTotal.Text = mintTotal
        wfPart.Text = (fstrDivision(7, fstrDivision(4, Mid(buf, 2, 10))))
        wfCL.Text = (Mid(buf, 12, 2))
        wfZnc.Text = (Mid(buf, 14, 1))

        wfLocation.Text = gstrctP2000.strLctnM

    End Sub
    '/*
    '|| Function Name: fProcInput
    '|| Version: 
    '*/
    Private Function fProcInput(ByVal pstrInput As String) As Integer
        Dim rtn As Integer
        Dim wintRet As Integer
        Dim tmp As String
        Dim i As Integer

        fProcInput = -1

        Try

            'mintCnt = 0
            'mintTotal = 0

            'If pstrInput = "OCEND" Then             'OCENDศ็ฮ

            '    mint2015status = M2015_STATUS.OCEND
            '    fProcInput = 0
            '    Exit Function

            If RTrim(pstrInput) = "OCCANCEL" Then             'OCCANCELศ็ฮ

                mint2015status = M2015_STATUS.CANCEL
                fProcInput = 0
                Exit Function

            ElseIf pstrInput.StartsWith("T") Then        'ๆ“ชชTศ็ฮ

                gstrctP2000.strLctnM = Mid(pstrInput, 5)


                If gstrctP2000.strLctnStart = Mid(pstrInput, 5) Then                    '9…ศOศ็ฮ

                    '0ศ็Iํ้
                    If mintCnt = 0 Then
                        mint2015status = M2015_STATUS.LOCMATCHED
                        fProcInput = 0
                        Exit Function

                    End If

                    'XV—

                    'BtLib.Transaction.BeginConCurrent()

                    i = 0
                    Do
                        If i > mintCnt - 1 Then
                            Exit Do
                        End If
                        rtn = fUpdateStock(gstrScanItem(i))
                        If (rtn = -1) Then
                            'BtLib.Transaction.Abort()
                            Exit Function
                        ElseIf (rtn = -2) Then
                            'BtLib.Transaction.Abort()
                            fProcInput = 0
                            Exit Function
                        End If
                        If Mid(gstrScanItem(i), 1, 1) = "P" Then
                            'PACKPLANฬXV
                            rtn = fUpdatePP(gstrScanItem(i))
                            If (rtn = -1) Then
                                'BtLib.Transaction.Abort()
                                Exit Function

                                'PackPlanฬดืฐลฦ฿ศขB@2005/03/16
                                'ElseIf (rtn = -2) Then
                                '    mint2015status = M2015_STATUS.PNOTEXIST
                                '    fProcInput = 0
                                '    Exit Function
                            End If

                        End If

                        i += 1
                    Loop

                    'BtLib.Transaction.End()

                    mint2015status = M2015_STATUS.LOCMATCHED
                    fProcInput = 0
                    Exit Function
                Else
                    mint2015status = M2015_STATUS.LOCUNMATCHED
                    fProcInput = 0
                    Exit Function
                End If

            ElseIf pstrInput.StartsWith("P") OrElse pstrInput.StartsWith("Z") OrElse pstrInput.StartsWith("D") Then        ' Check P, Z completed

                '>>> 2006.04.25 Check completed >>>

                If mhtScanPart.Item(pstrInput) Then

                    mint2015status = M2015_STATUS.SECOND
                    fProcInput = 0
                    Exit Function
                    'ElseIf pstrInput.Length() = G_CONST_LLEN_PRT1 Then
                    '    gstrctP2000.strScanSerial = RTrim(Mid(pstrInput, 14))
                ElseIf pstrInput.Length() = G_CONST_LLEN_PRT2 Then

                    gstrctP2000.strScanSerial = RTrim(Mid(pstrInput, 20))
                Else

                    mint2015status = M2015_STATUS.NA
                    fProcInput = 0
                    Exit Function
                End If

                'gstrctP2000.strScanItemID = RTrim(Mid(pstrInput, 1, 1))
                'gstrctP2000.strPartScan = RTrim(Mid(pstrInput, 2, 13))

                ' 2005/03/07 - Retrieves information based on the specified code.
                gstrctP2000.strScanItemID = RTrim(Mid(pstrInput, 1, 1))
                tmp = RTrim(Mid(pstrInput, 2, 13))
                gstrctP2000.strPartScan = fBackDispItem(tmp, True)

            Else

                mint2015status = M2015_STATUS.NA
                fProcInput = 0
                Exit Function

            End If

            ' Check inventory record

            rtn = fCheckStock()
            If (rtn = -1) Then
                Exit Function
            ElseIf (rtn = -2) Then
                mint2015status = M2015_STATUS.SNOTEXIST
                fProcInput = 0
                Exit Function
            ElseIf (rtn = -3) Then
                mint2015status = M2015_STATUS.NOLOC
                fProcInput = 0
                Exit Function
            ElseIf (rtn = -4) Then
                mint2015status = M2015_STATUS.NOSTATUS3
                fProcInput = 0
                Exit Function
            ElseIf (rtn = -5) Then
                mint2015status = M2015_STATUS.NOSTATUS5
                fProcInput = 0
                Exit Function
            ElseIf (rtn = -6) Then
                mint2015status = M2015_STATUS.NOSTATUS7
                fProcInput = 0
                Exit Function

            End If

            ReDim Preserve gstrScanItem(mintCnt - 1)
            gstrScanItem(mintCnt - 1) = pstrInput

            mhtScanPart.Add(pstrInput, True)
            mint2015status = M2015_STATUS.DONE

            fProcInput = 0

        Catch ex As Exception
            'gintStatus = FREE_STATUS.QUIT
            sErrLog(gAppName, "fProcInput", ex.ToString)

        End Try

    End Function
    '/*
    '|| Function Name: fUpdateStock
    '|| Version: STOCK update completed
    '*/
    Private Function fUpdateStock(ByVal wstrInput As String) As Integer

        Dim rtn As Integer
        Dim wintRet As Integer
        Dim wstrKey(7) As String
        Dim wstrKeyValue(7) As String
        Dim wstrItemCode As String
        Dim tmp As String
        Dim wstrWhere As String = ""
        fUpdateStock = -1

        Try

            tmp = Mid(wstrInput, 2, 13)
            wstrItemCode = fBackDispItem(tmp, True)

            'XV—
            wstrKey(0) = "PicsType"
            wstrKey(1) = "Cstmid"
            wstrKey(2) = "CstmCode"
            wstrKey(3) = "CenterCode"
            wstrKey(4) = "Bhk"
            wstrKey(5) = "Itemid"
            wstrKey(6) = "ItemCode"
            wstrKey(7) = "SerialNo"
            wstrKeyValue(0) = gstrctKDHT.strPackType
            wstrKeyValue(1) = gstrctKDHT.strCstmid
            wstrKeyValue(2) = gstrctKDHT.strCstmCode
            wstrKeyValue(3) = gstrctP2000.strCenterCode
            wstrKeyValue(4) = gstrctP2000.strBhk
            'wstrKeyValue(5) = gstrctP2000.strScanItemID
            'wstrKeyValue(6) = gstrctP2000.strPartScan
            'wstrKeyValue(7) = gstrctP2000.strScanSerial

            wstrKeyValue(5) = Mid(wstrInput, 1, 1)
            wstrKeyValue(6) = wstrItemCode
            wstrKeyValue(7) = Mid(wstrInput, 20, 6)


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

           
            affected_rows = dbClient.Execute("UPDATE " + G_CONST_TBL_STOCK _
                                            + " SET ZaikoStatus='" + "3" _
                                            + "' StockDate='" + fgetDefaultDate() _
                                            + "' StockTime='" + Mid(fgetDefaultTime(), 1, 4) _
                                            + "' StockEmp='" + gstrctKDHT.strUserNo _
                                            + "' WHERE " + wstrWhere)



            'gclsDB.Setcolumn = ("ZaikoStatus,StockDate,StockTime,StockEmp")          '“o^/XV‘ฮ—๑–ผ
            'gclsDB.SetData = ("3," & fgetDefaultDate() & "," & Mid(fgetDefaultTime(), 1, 4) & "," & gstrctKDHT.strUserNo)    '“o^/XVf[^

            If affected_rows = 0 Then
                Exit Function
            End If

            'If gclsDB.fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, wstrKey, wstrKeyValue) = -1 Then
            '    Exit Function

            'End If

            'mint2015status = M2015_STATUS.DONE

            fUpdateStock = 0

        Catch ex As Exception
            'gintStatus = FREE_STATUS.QUIT
            sErrLog(gAppName, "fUpdateStock", ex.ToString)

        End Try

    End Function
    '/*
    '|| Function Name: fUpdatePP
    '|| Version: PackPlan update completed
    '*/
    Private Function fUpdatePP(ByVal wstrInput As String) As Integer
        Dim wstrKey(9) As String
        Dim wstrKeyValue(9) As String
        Dim wintRet As Integer
        Dim wstrTime As String
        Dim wstrDate As String
        Dim wstrItemCode As String
        Dim tmp As String
        Dim wstrWhere As String = ""


        Try
            tmp = Mid(wstrInput, 2, 13)
            wstrItemCode = fBackDispItem(tmp, True)

            fUpdatePP = -1

            wstrKey(0) = "PicsType" : wstrKeyValue(0) = gstrctKDHT.strPackType
            wstrKey(1) = "Cstmid" : wstrKeyValue(1) = gstrctKDHT.strCstmid
            wstrKey(2) = "CstmCode" : wstrKeyValue(2) = gstrctKDHT.strCstmCode
            wstrKey(3) = "Bhk" : wstrKeyValue(3) = gstrctP2000.strBhk
            'wstrKey(4) = "ItemID" : wstrKeyValue(4) = gstrctP2000.strScanItemID
            'wstrKey(5) = "ItemCode" : wstrKeyValue(5) = gstrctP2000.strPartScan
            wstrKey(4) = "ItemID" : wstrKeyValue(4) = Mid(wstrInput, 1, 1)
            wstrKey(5) = "ItemCode" : wstrKeyValue(5) = wstrItemCode
            'wstrKey(6) = "SerialNo" : wstrKeyValue(6) = Space(6)
            'wstrKey(7) = "TempSerial" : wstrKeyValue(7) = Space(6)
            wstrKey(6) = "TempSerial" : wstrKeyValue(6) = Mid(wstrInput, 20, 6)
            wstrKey(7) = "SerialNo" : wstrKeyValue(7) = Space(6)
            wstrKey(8) = "Aic" : wstrKeyValue(8) = Space(13)
            wstrKey(9) = "CaseNo" : wstrKeyValue(9) = Space(7)


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


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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim i As Integer = 0

            If tmpStr.Count > 0 Then

                Do

                    values = tmpStr(i)

                    Dim result As String = Nothing
                    Dim sPicsType As String = Nothing
                    Dim sCstmid As String = Nothing
                    Dim sCstmCode As String = Nothing
                    Dim sCenterCode As String = Nothing
                    Dim sBhk As String = Nothing
                    Dim sLocation As String = Nothing
                    Dim sItemid As String = Nothing
                    Dim sItemCode As String = Nothing
                    Dim sZaikoStatus As String = Nothing
                    Dim sSerialNo As String = Nothing
                    Dim sAic As String = Nothing
                    Dim sCaseNo As String = Nothing
                    Dim sStatus 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("CstmCode", result) Then
                        sCstmCode = 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("Itemid", result) Then
                        sItemid = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("ZaikoStatus", result) Then
                        sZaikoStatus = RTrim(result)
                    End If
                    If values.TryGetValue("SerialNo", result) Then
                        sSerialNo = RTrim(result)
                    End If
                    If values.TryGetValue("Aic", result) Then
                        sAic = RTrim(result)
                    End If
                    If values.TryGetValue("CaseNo", result) Then
                        sCaseNo = RTrim(result)
                    End If
                    If values.TryGetValue("Status", result) Then
                        sStatus = RTrim(result)
                    End If


                    If (RTrim(wstrKeyValue(0)) = RTrim(sPicsType) And _
                                        RTrim(wstrKeyValue(1)) = RTrim(sCstmid) And _
                                        RTrim(wstrKeyValue(2)) = RTrim(sCstmCode) And _
                                        RTrim(wstrKeyValue(3)) = RTrim(sBhk) And _
                                        RTrim(wstrKeyValue(4)) = RTrim(sItemid) And _
                                        RTrim(wstrKeyValue(5)) = RTrim(sItemCode) And _
                                        RTrim(wstrKeyValue(6)) = RTrim(sSerialNo)) Then

                        If RTrim(wstrKeyValue(5)) <> RTrim(sItemCode) Then
                            Exit Do
                        End If

                        wstrKeyValue(7) = sSerialNo
                        wstrKeyValue(8) = sAic
                        wstrKeyValue(9) = sCaseNo

                        wstrDate = fgetDefaultDate()                    'Format as "yyyymmdd"
                        wstrTime = fgetDefaultTime().Substring(0, 4)    'Format as "hhmmss"

                        If RTrim(sStatus) > "20" Then

                            affected_rows = dbClient.Execute("UPDATE " + G_CONST_TBL_PACKPLAN _
                                            + " SET StockLctn='" + gstrctP2000.strLctnStart _
                                            + "' StockDate='" + wstrDate _
                                            + "' StockTime='" + wstrTime _
                                            + "' StockEmp='" + gstrctKDHT.strUserNo _
                                            + "' WHERE " + wstrWhere)

                            'gclsDB.Setcolumn = ("StockLctn,StockDate,StockTime,StockEmp")          '“o^/XV‘ฮ—๑–ผ
                            'gclsDB.SetData = (gstrctP2000.strLctnStart & "," & wstrDate & "," & wstrTime & "," & gstrctKDHT.strUserNo)           '“o^/XVf[^

                        Else

                            affected_rows = dbClient.Execute("UPDATE " + G_CONST_TBL_PACKPLAN _
                                            + " SET Status='" + 20 _
                                            + "' StockLctn='" + gstrctP2000.strLctnStart _
                                            + "' StockDate='" + wstrDate _
                                            + "' StockTime='" + wstrTime _
                                            + "' StockEmp='" + gstrctKDHT.strUserNo _
                                            + "' WHERE " + wstrWhere)


                            'gclsDB.Setcolumn = ("Status,StockLctn,StockDate,StockTime,StockEmp")          '“o^/XV‘ฮ—๑–ผ
                            'gclsDB.SetData = ("20," & gstrctP2000.strLctnStart & "," & wstrDate & "," & wstrTime & "," & gstrctKDHT.strUserNo)        '“o^/XVf[^

                        End If


                        If affected_rows = 0 Then
                            Exit Function
                        End If

                        'If gclsDB.fUpdRecords(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY07, wstrKey, wstrKeyValue) = -1 Then
                        '    gclsDB.fCloseRecord("PACK1")
                        '    Exit Function
                        'End If

                        Exit Do
                        'End If

                    Else
                        fUpdatePP = -2
                        'gclsDB.fCloseRecord("PACK1")
                        Exit Function
                    End If

                    i = i + 1

                    If i = tmpStr.Count Then
                        Exit Do
                    End If

                    'If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do
                Loop
                'gclsDB.fCloseRecord("PACK1")
                fUpdatePP = 0


            ElseIf wintRet = 9 Then     '๕สช–ณฉมฝ
                fUpdatePP = -2

            Else        'ปฬ‘ผฬดืฐ
                'gclsDB.fCloseRecord("PACK1")
                Exit Function
            End If

        Catch ex As Exception

        End Try




                        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY02, "PACK1", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        '                wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY07, "PACK1", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)


        '                If wintRet = 0 Then
        '                    With gclsDB.Records("PACK1")
        '                        Do

        '                            If (RTrim(wstrKeyValue(0)) = RTrim(.Item("PicsType")) And _
        '                                RTrim(wstrKeyValue(1)) = RTrim(.Item("Cstmid")) And _
        '                                RTrim(wstrKeyValue(2)) = RTrim(.Item("CstmCode")) And _
        '                                RTrim(wstrKeyValue(3)) = RTrim(.Item("Bhk")) And _
        '                                RTrim(wstrKeyValue(4)) = RTrim(.Item("ItemID")) And _
        '                                RTrim(wstrKeyValue(5)) = RTrim(.Item("ItemCode")) And _
        '                                RTrim(wstrKeyValue(6)) = RTrim(.Item("TempSerial"))) Then

        '                                If RTrim(wstrKeyValue(5)) <> RTrim(.Item("ItemCode")) Then
        '                                    Exit Do
        '                                End If

        '                                'If RTrim(.Item("TempSerial")) = gstrctP2000.strScanSerial Then
        '                                'If RTrim(.Item("TempSerial")) = Mid(wstrInput, 20, 6) Then


        '                                'wstrKeyValue(6) = .Item("SerialNo")
        '                                'wstrKeyValue(7) = .Item("TempSerial")
        '                                wstrKeyValue(7) = .Item("SerialNo")
        '                                wstrKeyValue(8) = .Item("Aic")
        '                                wstrKeyValue(9) = .Item("CaseNo")

        '                                wstrDate = fgetDefaultDate()                    'Format as "yyyymmdd"
        '                                wstrTime = fgetDefaultTime().Substring(0, 4)    'Format as "hhmmss"

        '                                'Initialize with "20" if it is not already initialized.

        '                                If RTrim(.Item("Status")) > "20" Then

        '                                    gclsDB.Setcolumn = ("StockLctn,StockDate,StockTime,StockEmp")          '“o^/XV‘ฮ—๑–ผ
        '                                    gclsDB.SetData = (gstrctP2000.strLctnStart & "," & wstrDate & "," & wstrTime & "," & gstrctKDHT.strUserNo)           '“o^/XVf[^

        '                                Else

        '                                    gclsDB.Setcolumn = ("Status,StockLctn,StockDate,StockTime,StockEmp")          '“o^/XV‘ฮ—๑–ผ
        '                                    gclsDB.SetData = ("20," & gstrctP2000.strLctnStart & "," & wstrDate & "," & wstrTime & "," & gstrctKDHT.strUserNo)        '“o^/XVf[^

        '                                End If

        '                                If gclsDB.fUpdRecords(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY07, wstrKey, wstrKeyValue) = -1 Then
        '                                    gclsDB.fCloseRecord("PACK1")
        '                                    Exit Function
        '                                End If

        '                                Exit Do
        '                                'End If

        '                            Else
        '                                fUpdatePP = -2
        '                                gclsDB.fCloseRecord("PACK1")
        '                                Exit Function
        '                            End If
        '                            If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do
        '                        Loop
        '                        gclsDB.fCloseRecord("PACK1")
        '                        fUpdatePP = 0

        '                    End With

        '                ElseIf wintRet = 9 Then     '๕สช–ณฉมฝ
        '                    fUpdatePP = -2

        '                Else        'ปฬ‘ผฬดืฐ
        '                    gclsDB.fCloseRecord("PACK1")
        '                    Exit Function
        '                End If

        'Catch ex As Exception

        'End Try

    End Function


    '/*
    '|| Function Name: fCheckStock
    '|| Version: Inventory record retrieval
    '*/
    Private Function fCheckStock() As Integer

        Dim rtn As Integer
        Dim wintRet As Integer
        Dim wstrKey(7) As String
        Dim wstrKeyValue(7) As String
        Dim wstrKey2(9) As String
        Dim wstrKeyValue2(9) As String
        Dim wstrWhere As String = ""

        fCheckStock = -1

        Try
            ' Check if registration is complete
            wstrKey(0) = "PicsType"
            wstrKey(1) = "Cstmid"
            wstrKey(2) = "CstmCode"
            wstrKey(3) = "CenterCode"
            wstrKey(4) = "Bhk"
            wstrKey(5) = "Itemid"
            wstrKey(6) = "ItemCode"
            wstrKey(7) = "SerialNo"
            wstrKeyValue(0) = gstrctKDHT.strPackType
            wstrKeyValue(1) = gstrctKDHT.strCstmid
            wstrKeyValue(2) = gstrctKDHT.strCstmCode
            wstrKeyValue(3) = gstrctP2000.strCenterCode
            wstrKeyValue(4) = gstrctP2000.strBhk
            wstrKeyValue(5) = gstrctP2000.strScanItemID
            wstrKeyValue(6) = gstrctP2000.strPartScan
            wstrKeyValue(7) = gstrctP2000.strScanSerial


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


            'MessageBox.Show("SELECT * FROM " + G_CONST_TBL_STOCK + " WHERE " + wstrWhere)


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


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

            'MessageBox.Show(tmpStr.Count)

            If tmpStr.Count > 0 Then

                values = tmpStr(0)

                Dim result As String = Nothing
                Dim sPicsType As String = Nothing
                Dim sCstmid As String = Nothing
                Dim sCstmCode As String = Nothing
                Dim sCenterCode As String = Nothing
                Dim sBhk As String = Nothing
                Dim sLocation As String = Nothing
                Dim sItemid As String = Nothing
                Dim sItemCode As String = Nothing
                Dim sZaikoStatus As String = Nothing
                Dim sSerialNo 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("CstmCode", result) Then
                    sCstmCode = 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("Itemid", result) Then
                    sItemid = RTrim(result)
                End If
                If values.TryGetValue("ItemCode", result) Then
                    sItemCode = RTrim(result)
                End If
                If values.TryGetValue("ZaikoStatus", result) Then
                    sZaikoStatus = 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(gstrctKDHT.strCstmCode) = RTrim(sCstmCode) And _
                            RTrim(gstrctP2000.strCenterCode) = RTrim(sCenterCode) And _
                            RTrim(gstrctP2000.strBhk) = RTrim(sBhk) And _
                            RTrim(gstrctP2000.strScanItemID) = RTrim(sItemid) And _
                            RTrim(gstrctP2000.strPartScan) = RTrim(sItemCode) And _
                            RTrim(gstrctP2000.strScanSerial) = RTrim(sSerialNo)) Then


                    ' Invalid character
                    If RTrim(sZaikoStatus) = "3" Then
                        fCheckStock = -4
                        Exit Function

                    End If
                    ' Invalid data
                    If RTrim(sZaikoStatus) = "5" Then
                        fCheckStock = -5
                        Exit Function

                    End If

                    ' Invalid data
                    If RTrim(sZaikoStatus) = "7" Then
                        fCheckStock = -6
                        Exit Function

                    End If

                    gstrctP2000.strLctnM = RTrim(sLocation)


                    'MessageBox.Show(RTrim(gstrctP2000.strLctnStart) + " | " + RTrim(sLocation))

                    If (RTrim(gstrctP2000.strLctnStart) <> RTrim(sLocation)) Then

                        fCheckStock = -3
                        Exit Function

                    End If

                    If mintCnt = 0 Then
                        fChecknumber()
                    End If

                    mintCnt += 1

                Else

                    fCheckStock = -2
                    Exit Function

                End If

            Else

                Exit Function

            End If

            fCheckStock = 0

        Catch ex As Exception
            'gintStatus = FREE_STATUS.QUIT
            sErrLog(gAppName, "fCheckStock", ex.ToString)

        End Try


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

        'If wintRet = 0 Then

        '    With gclsDB.Records("STOCK1")

        '        If (RTrim(gstrctKDHT.strPackType) = RTrim(.Item("PicsType")) And _
        '            RTrim(gstrctKDHT.strCstmid) = RTrim(.Item("Cstmid")) And _
        '            RTrim(gstrctKDHT.strCstmCode) = RTrim(.Item("CstmCode")) And _
        '            RTrim(gstrctP2000.strCenterCode) = RTrim(.Item("CenterCode")) And _
        '            RTrim(gstrctP2000.strBhk) = RTrim(.Item("Bhk")) And _
        '            RTrim(gstrctP2000.strScanItemID) = RTrim(.Item("Itemid")) And _
        '            RTrim(gstrctP2000.strPartScan) = RTrim(.Item("ItemCode")) And _
        '            RTrim(gstrctP2000.strScanSerial) = RTrim(.Item("SerialNo"))) Then

        '            'If CLng(RTrim(.Item("ZaikoStatus"))) > 3 Then
        '            '    gclsDB.fCloseRecord("STOCK1")
        '            '    fCheckStock = -4
        '            '    Exit Function

        '            'End If

        '            ' Invalid character
        '            If RTrim(.Item("ZaikoStatus")) = "3" Then
        '                gclsDB.fCloseRecord("STOCK1")
        '                fCheckStock = -4
        '                Exit Function

        '            End If
        '            ' Invalid data
        '            If RTrim(.Item("ZaikoStatus")) = "5" Then
        '                gclsDB.fCloseRecord("STOCK1")
        '                fCheckStock = -5
        '                Exit Function

        '            End If

        '            ' Invalid data
        '            If RTrim(.Item("ZaikoStatus")) = "7" Then
        '                gclsDB.fCloseRecord("STOCK1")
        '                fCheckStock = -6
        '                Exit Function

        '            End If

        '            gstrctP2000.strLctnM = RTrim(.Item("Location"))
        '            If (RTrim(gstrctP2000.strLctnStart) <> RTrim(.Item("Location"))) Then

        '                gclsDB.fCloseRecord("STOCK1")
        '                fCheckStock = -3
        '                Exit Function

        '            End If

        '            'If ("3" <> RTrim(.Item("ZaikoStatus"))) Then
        '            '    mintCnt += 1
        '            'End If

        '            If mintCnt = 0 Then
        '                fChecknumber()
        '            End If

        '            mintCnt += 1


        '        Else

        '            gclsDB.fCloseRecord("STOCK1")
        '            fCheckStock = -2
        '            Exit Function

        '        End If
        '    End With

        'ElseIf wintRet = 9 Then

        '    gclsDB.fCloseRecord("STOCK1")
        '    fCheckStock = -2
        '    Exit Function

        'Else

        '    gclsDB.fCloseRecord("STOCK1")
        '    Exit Function

        'End If

        'gclsDB.fCloseRecord("STOCK1")


        'fCheckStock = 0

        'Catch ex As Exception
        '    'gintStatus = FREE_STATUS.QUIT
        '    sErrLog(gAppName, "fCheckStock", ex.ToString)

        'End Try

    End Function
    '/*
    '|| Function Name: fChecknumber
    '|| Version: Number validation
    '*/
    Private Function fChecknumber() As Integer

        Dim rtn As Integer
        Dim wintRet As Integer
        Dim wstrKey(7) As String
        Dim wstrKeyValue(7) As String
        Dim wstrKey2(9) As String
        Dim wstrKeyValue2(9) As String
        Dim wstrWhere As String = ""

        Try

            ' Input check P
            wstrKey2(0) = "PicsType"
            wstrKey2(1) = "Cstmid"
            wstrKey2(2) = "CstmCode"
            wstrKey2(3) = "CenterCode"
            wstrKey2(4) = "Bhk"
            wstrKey2(5) = "Location"
            wstrKey2(6) = "Itemid"
            wstrKey2(7) = "ItemCode"
            wstrKey2(8) = "Qty"
            wstrKey2(9) = "SerialNo"
            wstrKeyValue2(0) = gstrctKDHT.strPackType
            wstrKeyValue2(1) = gstrctKDHT.strCstmid
            wstrKeyValue2(2) = gstrctKDHT.strCstmCode
            wstrKeyValue2(3) = gstrctP2000.strCenterCode
            wstrKeyValue2(4) = gstrctP2000.strBhk
            wstrKeyValue2(5) = gstrctP2000.strLctnStart
            '>>> Del 2006.04.25  ST >>>
            'wstrKeyValue2(6) = "P"
            '>>> Del 2006.04.25 END >>>
            '>>> Add 2006.04.25  ST >>>
            wstrKeyValue2(6) = gstrctP2000.strScanItemID
            '>>> Add 2006.04.25 END >>>
            wstrKeyValue2(7) = gstrctP2000.strPartScan
            wstrKeyValue2(8) = Space(5)
            wstrKeyValue2(9) = Space(6)

            wstrWhere = ""
            wstrWhere = wstrKey2(0) & " = '" & wstrKeyValue2(0) & "' and "
            wstrWhere = wstrWhere & wstrKey2(1) & " = '" & wstrKeyValue2(1) & "' and "
            wstrWhere = wstrWhere & wstrKey2(2) & " = '" & wstrKeyValue2(2) & "' and "
            wstrWhere = wstrWhere & wstrKey2(3) & " = '" & wstrKeyValue2(3) & "' and "
            wstrWhere = wstrWhere & wstrKey2(4) & " = '" & wstrKeyValue2(4) & "' and "
            wstrWhere = wstrWhere & wstrKey2(5) & " = '" & wstrKeyValue2(5) & "' and "
            wstrWhere = wstrWhere & wstrKey2(6) & " = '" & wstrKeyValue2(6) & "' and "
            wstrWhere = wstrWhere & wstrKey2(7) & " = '" & wstrKeyValue2(7) & "' and "
            wstrWhere = wstrWhere & wstrKey2(8) & " = '" & wstrKeyValue2(8) & "' and "
            wstrWhere = wstrWhere & wstrKey2(9) & " = '" & wstrKeyValue2(9) & "'"


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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim i As Integer = 0

            If tmpStr.Count > 0 Then

                Do

                    values = tmpStr(i)

                    Dim result As String = Nothing
                    Dim sPicsType As String = Nothing
                    Dim sCstmid As String = Nothing
                    Dim sCstmCode As String = Nothing
                    Dim sCenterCode As String = Nothing
                    Dim sBhk As String = Nothing
                    Dim sLocation As String = Nothing
                    Dim sItemid As String = Nothing
                    Dim sItemCode As String = Nothing
                    Dim sZaikoStatus 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("CstmCode", result) Then
                        sCstmCode = 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("Itemid", result) Then
                        sItemid = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("ZaikoStatus", result) Then
                        sZaikoStatus = RTrim(result)
                    End If


                    If (RTrim(gstrctKDHT.strPackType) = RTrim(sPicsType) And _
                                RTrim(gstrctKDHT.strCstmid) = RTrim(sCstmid) And _
                                RTrim(gstrctKDHT.strCstmCode) = RTrim(sCstmCode) And _
                                RTrim(gstrctP2000.strCenterCode) = RTrim(sCenterCode) And _
                                RTrim(gstrctP2000.strBhk) = RTrim(sBhk) And _
                                RTrim(gstrctP2000.strLctnStart) = RTrim(sLocation) And _
                                RTrim(gstrctP2000.strScanItemID) = RTrim(sItemid) And _
                                RTrim(gstrctP2000.strPartScan) = RTrim(sItemCode)) Then


                        If ("0" = RTrim(sZaikoStatus)) Then

                            mintTotal += 1

                        End If

                        i = i + 1
                        If (i = 9) Or (i > tmpStr.Count) Then Exit Do

                        'wintRet = .Read(BtLib.Operation.GetNext)
                        'If wintRet = 9 Then Exit Do

                    Else

                        Exit Do

                    End If
                    '<<< Add 2006.04.25 END <<<
                Loop

            Else
                Exit Function

            End If

            If wstrKeyValue2(6) = "P" Then
                '”๐”ฆ้ Z
                wstrKeyValue2(6) = "Z"

                wstrWhere = ""
                wstrWhere = wstrKey2(0) & " = '" & wstrKeyValue2(0) & "' and "
                wstrWhere = wstrWhere & wstrKey2(1) & " = '" & wstrKeyValue2(1) & "' and "
                wstrWhere = wstrWhere & wstrKey2(2) & " = '" & wstrKeyValue2(2) & "' and "
                wstrWhere = wstrWhere & wstrKey2(3) & " = '" & wstrKeyValue2(3) & "' and "
                wstrWhere = wstrWhere & wstrKey2(4) & " = '" & wstrKeyValue2(4) & "' and "
                wstrWhere = wstrWhere & wstrKey2(5) & " = '" & wstrKeyValue2(5) & "' and "
                wstrWhere = wstrWhere & wstrKey2(6) & " = '" & wstrKeyValue2(6) & "' and "
                wstrWhere = wstrWhere & wstrKey2(7) & " = '" & wstrKeyValue2(7) & "' and "
                wstrWhere = wstrWhere & wstrKey2(8) & " = '" & wstrKeyValue2(8) & "' and "
                wstrWhere = wstrWhere & wstrKey2(9) & " = '" & wstrKeyValue2(9) & "'"

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

                values = New Dictionary(Of String, String)
                i = 0

                If tmpStr.Count > 0 Then

                    Do

                        values = tmpStr(i)

                        Dim result As String = Nothing
                        Dim sPicsType As String = Nothing
                        Dim sCstmid As String = Nothing
                        Dim sCstmCode As String = Nothing
                        Dim sCenterCode As String = Nothing
                        Dim sBhk As String = Nothing
                        Dim sLocation As String = Nothing
                        Dim sItemid As String = Nothing
                        Dim sItemCode As String = Nothing
                        Dim sZaikoStatus 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("CstmCode", result) Then
                            sCstmCode = 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("Itemid", result) Then
                            sItemid = RTrim(result)
                        End If
                        If values.TryGetValue("ItemCode", result) Then
                            sItemCode = RTrim(result)
                        End If
                        If values.TryGetValue("ZaikoStatus", result) Then
                            sZaikoStatus = RTrim(result)
                        End If


                        If (RTrim(gstrctKDHT.strPackType) = RTrim(sPicsType) And _
                                    RTrim(gstrctKDHT.strCstmid) = RTrim(sCstmid) And _
                                    RTrim(gstrctKDHT.strCstmCode) = RTrim(sCstmCode) And _
                                    RTrim(gstrctP2000.strCenterCode) = RTrim(sCenterCode) And _
                                    RTrim(gstrctP2000.strBhk) = RTrim(sBhk) And _
                                    RTrim(gstrctP2000.strLctnStart) = RTrim(sLocation) And _
                                    "Z" = RTrim(sItemid) And _
                                    RTrim(gstrctP2000.strPartScan) = RTrim(sItemCode)) Then


                            If ("0" = RTrim(sZaikoStatus)) Then

                                mintTotal += 1

                            End If

                            i = i + 1
                            If (i = 9) Or (i > tmpStr.Count) Then Exit Do

                            'wintRet = .Read(BtLib.Operation.GetNext)
                            'If wintRet = 9 Then Exit Do

                        Else

                            Exit Do

                        End If
                        '<<< Add 2006.04.25 END <<<
                    Loop

                Else
                    Exit Function

                End If

            End If


            fChecknumber = 0

        Catch ex As Exception
            'gintStatus = FREE_STATUS.QUIT
            sErrLog(gAppName, "fCheckStock", ex.ToString)

        End Try






        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY01, "STOCK2", wstrKey2, wstrKeyValue2, BtLib.Operation.GetGreaterOrEqual)

        'If wintRet = 0 Then

        '    With gclsDB.Records("STOCK2")
        '        Do  '>>> Del 2006.04.25  ST >>>
        '            'If (RTrim(gstrctKDHT.strPackType) = RTrim(.Item("PicsType")) And _
        '            '    RTrim(gstrctKDHT.strCstmid) = RTrim(.Item("Cstmid")) And _
        '            '    RTrim(gstrctKDHT.strCstmCode) = RTrim(.Item("CstmCode")) And _
        '            '    RTrim(gstrctP2000.strCenterCode) = RTrim(.Item("CenterCode")) And _
        '            '    RTrim(gstrctP2000.strBhk) = RTrim(.Item("Bhk")) And _
        '            '    RTrim(gstrctP2000.strLctnStart) = RTrim(.Item("Location")) And _
        '            '    "P" = RTrim(.Item("Itemid")) And _
        '            '    RTrim(gstrctP2000.strPartScan) = RTrim(.Item("ItemCode"))) Then

        '            '    'mintTotal += 1

        '            '    'If ("3" = RTrim(.Item("ZaikoStatus"))) Then

        '            '    '    mintCnt += 1

        '            '    'End If

        '            '    'ฝรฐภฝ"0"ฬ๐ถณฤ@2005/03/17
        '            '    If ("0" = RTrim(.Item("ZaikoStatus"))) Then

        '            '        mintTotal += 1

        '            '    End If

        '            '    wintRet = .Read(BtLib.Operation.GetNext)
        '            '    If wintRet = 9 Then Exit Do

        '            'Else

        '            '    Exit Do

        '            'End If '<<< Del 2006.04.25 END <<<
        '            '>>> Add 2006.04.25  ST >>>
        '            If (RTrim(gstrctKDHT.strPackType) = RTrim(.Item("PicsType")) And _
        '                RTrim(gstrctKDHT.strCstmid) = RTrim(.Item("Cstmid")) And _
        '                RTrim(gstrctKDHT.strCstmCode) = RTrim(.Item("CstmCode")) And _
        '                RTrim(gstrctP2000.strCenterCode) = RTrim(.Item("CenterCode")) And _
        '                RTrim(gstrctP2000.strBhk) = RTrim(.Item("Bhk")) And _
        '                RTrim(gstrctP2000.strLctnStart) = RTrim(.Item("Location")) And _
        '                RTrim(gstrctP2000.strScanItemID) = RTrim(.Item("Itemid")) And _
        '                RTrim(gstrctP2000.strPartScan) = RTrim(.Item("ItemCode"))) Then

        '                'mintTotal += 1

        '                'If ("3" = RTrim(.Item("ZaikoStatus"))) Then

        '                '    mintCnt += 1

        '                'End If

        '                ' Initialize with "0" if empty 2005/03/17
        '                If ("0" = RTrim(.Item("ZaikoStatus"))) Then

        '                    mintTotal += 1

        '                End If

        '                wintRet = .Read(BtLib.Operation.GetNext)
        '                If wintRet = 9 Then Exit Do

        '            Else

        '                Exit Do

        '            End If
        '            '<<< Add 2006.04.25 END <<<
        '        Loop
        '    End With

        'ElseIf wintRet = 9 Then

        'Else

        '    gclsDB.fCloseRecord("STOCK2")
        '    Exit Function

        'End If

        '    If wstrKeyValue2(6) = "P" Then
        '        gclsDB.fCloseRecord("STOCK2")
        '        '”๐”ฆ้ Z
        '        wstrKeyValue2(6) = "Z"

        '        wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY01, "STOCK2", wstrKey2, wstrKeyValue2, BtLib.Operation.GetGreaterOrEqual)

        '        If wintRet = 0 Then

        '            With gclsDB.Records("STOCK2")
        '                Do
        '                    If (RTrim(gstrctKDHT.strPackType) = RTrim(.Item("PicsType")) And _
        '                        RTrim(gstrctKDHT.strCstmid) = RTrim(.Item("Cstmid")) And _
        '                        RTrim(gstrctKDHT.strCstmCode) = RTrim(.Item("CstmCode")) And _
        '                        RTrim(gstrctP2000.strCenterCode) = RTrim(.Item("CenterCode")) And _
        '                        RTrim(gstrctP2000.strBhk) = RTrim(.Item("Bhk")) And _
        '                        RTrim(gstrctP2000.strLctnStart) = RTrim(.Item("Location")) And _
        '                        "Z" = RTrim(.Item("Itemid")) And _
        '                        RTrim(gstrctP2000.strPartScan) = RTrim(.Item("ItemCode"))) Then

        '                        'mintTotal += 1

        '                        'If ("3" = RTrim(.Item("ZaikoStatus"))) Then

        '                        '    mintCnt += 1

        '                        'End If

        '                        ' Initialize with "0" if empty 2005/03/17
        '                        If ("0" = RTrim(.Item("ZaikoStatus"))) Then

        '                            mintTotal += 1

        '                        End If


        '                        wintRet = .Read(BtLib.Operation.GetNext)
        '                        If wintRet = 9 Then Exit Do

        '                    Else

        '                        Exit Do

        '                    End If
        '                Loop
        '            End With

        '        ElseIf wintRet = 9 Then

        '        Else

        '            gclsDB.fCloseRecord("STOCK2")
        '            Exit Function

        '        End If

        '    End If

        '    gclsDB.fCloseRecord("STOCK2")

        '    fChecknumber = 0

        'Catch ex As Exception
        '    'gintStatus = FREE_STATUS.QUIT
        '    sErrLog(gAppName, "fCheckStock", ex.ToString)

        'End Try

    End Function

    Private Sub frm2015_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 = ALL_STATUS.QUIT
                Me.Close()
                Exit Sub
        End Select
    End Sub

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

        _frm2015 = Me

        Try
            'Dim fileloc As String = "Setting.ini"

            'Dim appPath As String = fgetAppPath() ' Assuming fgetAppPath() retrieves the application directory
            'Dim filePath As String = Path.Combine(appPath, fileloc)

            'Dim i As Integer = 0
            'Dim strIP As String = "192.168.1.1"
            'Dim intPort As Integer = 11433
            'Dim strDatabase As String = "demodata"

            'If File.Exists(filePath) Then

            '    Dim sr As StreamReader = New StreamReader(filePath)
            '    Dim s As String = sr.ReadToEnd()
            '    Dim words As String() = s.Split(New Char() {","c})

            '    Dim word As String

            '    For Each word In words

            '        If i = 0 Then
            '            strIP = word
            '        ElseIf i = 1 Then

            '            If IsNumeric(word) Then
            '                intPort = Convert.ToInt32(word)
            '            End If

            '        ElseIf i = 2 Then
            '            strDatabase = word
            '        End If

            '        i = i + 1

            '    Next

            'End If

            'dbClient = New BtrieveDbClient(strIP, intPort, strDatabase)
        Catch ex As Exception
            sErrLog(gAppName, "fLoad", ex.ToString)
        End Try
    End Sub
End Class