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 BTClientLib
Imports System.IO
Imports System.Reflection
Imports Newtonsoft

Module modPublic025

    Private dbClient As BtrieveDbClient
    Private tmpStr As List(Of Dictionary(Of String, String))
    Private affected_rows As Integer

    '/*
    '|| 関数名：fCheckStock
    '|| 概要　：在庫のチェック
    '|| 引数  ：
    '*/
    Public Function fCheckStock(ByVal pstrSerial As String, Optional ByVal pintFlag As Integer = 0) As Integer

        Dim wstrKey(7) As String
        Dim wstrKeyValue(7) As String
        Dim wintRet As Integer
        Dim wstrWhere As String
        Const STK_KEY1 = "STK01"

        fCheckStock = -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) = gstrctKDPP.strCenterCode
        wstrKey(4) = "Bhk" : wstrKeyValue(4) = gstrctKDPP.strBhk
        With gstrctPPDispPart
            wstrKey(5) = "Itemid" : wstrKeyValue(5) = .strItemInID
            wstrKey(6) = "ItemCode" : wstrKeyValue(6) = .strItemInCode
            wstrKey(7) = "SerialNo" : wstrKeyValue(7) = pstrSerial
        End With

        Try

            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) & "'"

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            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(wstrKeyValue(0)) = RTrim(sPicsType) And _
                   RTrim(wstrKeyValue(1)) = RTrim(sCstmid) And _
                   RTrim(wstrKeyValue(2)) = RTrim(sCstmCode) And _
                   RTrim(wstrKeyValue(3)) = RTrim(sCenterCode) And _
                   RTrim(wstrKeyValue(4)) = RTrim(sBhk) And _
                   RTrim(wstrKeyValue(5)) = RTrim(sItemid) And _
                   RTrim(wstrKeyValue(6)) = RTrim(sItemCode) And _
                   RTrim(wstrKeyValue(7)) = RTrim(sSerialNo) Then

                If G_CONST_ST_STOCK_PICKED = RTrim(sZaikoStatus) And pintFlag <> 2 Then
                    fCheckStock = 1
                    Exit Function
                ElseIf (G_CONST_ST_STOCK_INSTOCK <> RTrim(sZaikoStatus) And G_CONST_ST_STOCK_RESERVED1 <> RTrim(sZaikoStatus) And _
                        G_CONST_ST_STOCK_RESERVED2 <> RTrim(sZaikoStatus)) Or _
                       (G_CONST_ST_STOCK_PICKED = RTrim(sZaikoStatus) And pintFlag <> 2) Then
                    fCheckStock = 2
                    Exit Function
                End If

                If gstrctPPDispPart.strLocation <> RTrim(sLocation) Then
                    fCheckStock = 3
                    Exit Function
                End If

            Else
                fCheckStock = 4
                Exit Function
            End If

            fCheckStock = 0
            Exit Function

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


        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, STK_KEY1, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'If wintRet <> 0 Then
        '    gclsDB.fCloseRecord(STK_KEY1)
        '    Exit Function
        'End If

        'With gclsDB.Records(STK_KEY1)
        '    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("CenterCode")) And _
        '       RTrim(wstrKeyValue(4)) = RTrim(.Item("Bhk")) And _
        '       RTrim(wstrKeyValue(5)) = RTrim(.Item("Itemid")) And _
        '       RTrim(wstrKeyValue(6)) = RTrim(.Item("ItemCode")) And _
        '       RTrim(wstrKeyValue(7)) = RTrim(.Item("SerialNo")) Then

        '        If G_CONST_ST_STOCK_PICKED = RTrim(.Item("ZaikoStatus")) And pintFlag <> 2 Then
        '            gclsDB.fCloseRecord(STK_KEY1)
        '            fCheckStock = 1
        '            Exit Function
        '        ElseIf (G_CONST_ST_STOCK_INSTOCK <> RTrim(.Item("ZaikoStatus")) And G_CONST_ST_STOCK_RESERVED1 <> RTrim(.Item("ZaikoStatus")) And _
        '                G_CONST_ST_STOCK_RESERVED2 <> RTrim(.Item("ZaikoStatus"))) Or _
        '               (G_CONST_ST_STOCK_PICKED = RTrim(.Item("ZaikoStatus")) And pintFlag <> 2) Then
        '            gclsDB.fCloseRecord(STK_KEY1)
        '            fCheckStock = 2
        '            Exit Function
        '        End If

        '        If gstrctPPDispPart.strLocation <> RTrim(.Item("Location")) Then
        '            gclsDB.fCloseRecord(STK_KEY1)
        '            fCheckStock = 3
        '            Exit Function
        '        End If

        '    Else
        '        gclsDB.fCloseRecord(STK_KEY1)
        '        fCheckStock = 4
        '        Exit Function
        '    End If

        'End With

        'gclsDB.fCloseRecord(STK_KEY1)
        'fCheckStock = 0
        'Exit Function

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

    '/*
    '|| 関数名：fCheckDScan
    '|| 概要  ：大物用ダブルスキャンチェック
    '*/
    Public Function fCheckDScan(ByVal pstrSerial) As Integer

        'Dim rtn As Integer
        'Dim wstrKey(6) As String
        'Dim wstrKeyValue(6) As String
        'Dim wintCnt As Integer

        'fCheckDScan = -1

        'Try

        '    wstrKey(0) = "ItemGr"
        '    wstrKey(1) = "ItemCode"
        '    wstrKey(2) = "SortLctn1"
        '    wstrKey(3) = "SortLctn2"
        '    wstrKey(4) = "SortLctn3"
        '    wstrKey(5) = "ItemInCode"
        '    wstrKey(6) = "TempSerial"
        '    wstrKeyValue(0) = gstrctKDPP.strItemGr
        '    wstrKeyValue(1) = Space(30)
        '    wstrKeyValue(2) = Space(5)
        '    wstrKeyValue(3) = Space(5)
        '    wstrKeyValue(4) = Space(5)
        '    wstrKeyValue(5) = Space(30)
        '    wstrKeyValue(6) = Space(6)

        '    rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY03, "PKCP01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        '    If rtn = 9 Then
        '        fCheckDScan = -2
        '        gclsDB.fCloseRecord("PKCP01")
        '        Exit Function
        '    ElseIf rtn <> 0 Then
        '        gclsDB.fCloseRecord("PKCP01")
        '        Exit Function
        '    End If

        '    If rtn = 0 Then
        '        Do
        '            With gclsDB.Records("PKCP01")
        '                If wstrKeyValue(0) = RTrim(.Item("ItemGr")) And gstrctPPDispPart.strItemInCode = RTrim(.Item("ItemInCode")) Then

        '                    If pstrSerial = RTrim(.Item("SerialNo")) Then
        '                        gclsDB.fCloseRecord("PKCP01")
        '                        fCheckDScan = 1
        '                        Exit Function
        '                    End If

        '                Else
        '                    Exit Do
        '                End If

        '                '次レコードを取得する
        '                If gclsDB.Records("PKCP01").Read(BtLib.Operation.GetNext) <> 0 Then
        '                    'レコードがなくなれば終了する
        '                    Exit Do
        '                End If

        '            End With
        '        Loop
        '    End If

        '    gclsDB.fCloseRecord("PKCP01")
        '    fCheckDScan = 0
        '    Exit Function

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

    End Function

    '*******************************************************************************
    '* 機能     : PACKCP取得処理
    '* 引数     : なし
    '*          : 
    '* 戻り値   : -1:NG　-2:0件  0:1件以上 1:区分"D"
    '* 備考     : なし
    '*******************************************************************************
    Public Function fSearchPackCP(Optional ByVal pintDirection As Integer = 0)
        Dim rtn As Integer
        Dim wintCnt As Integer
        Dim wstrKey(6) As String
        Dim wstrKeyValue(6) As String
        Dim wstrLctnItemCode As String
        Dim wstrItemInCodeDisp As String
        Dim wstrWork As String
        Dim wstrPrevCrtnNo As String
        Dim bFound As Boolean
        Dim wstrItemID As String
        Dim wstrWhere As String

        fSearchPackCP = -1

        wstrPrevCrtnNo = gstrctPPDisp.strCrtnNo

        wstrKey(0) = "ItemGr"
        wstrKey(1) = "ItemCode"
        wstrKey(2) = "SortLctn1"
        wstrKey(3) = "SortLctn2"
        wstrKey(4) = "SortLctn3"
        wstrKey(5) = "ItemInCode"
        wstrKey(6) = "TempSerial"

        bFound = False
        Try
            'ItemGrとItemCodeでサーチ
            Do Until bFound
                With gstrctKDPP
                    wstrKeyValue(0) = .strItemGr
                    wstrKeyValue(1) = Mid(.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
                    wstrKeyValue(2) = Space(5)
                    wstrKeyValue(3) = Space(5)
                    wstrKeyValue(4) = Space(5)
                    wstrKeyValue(5) = Space(30)
                    wstrKeyValue(6) = Space(6)
                End With

                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) & "'"

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


                Dim values1 As Dictionary(Of String, String) = New Dictionary(Of String, String)
                Dim sItemGr1 As String = ""
                Dim sItemCode1 As String = ""
                Dim sStockLctn1 As String = ""
                Dim sItemID1 As String = ""
                Dim sItemInID1 As String = ""
                Dim sItemInCode1 As String = ""
                Dim sItemInCodeDisp1 As String = ""
                Dim sPlanSerial1 As String = ""
                Dim sBunkatuJ1 As String = ""
                Dim i1 As Integer = 0


                If tmpStr.Count > 0 Then

                    Do Until bFound

                        values1 = tmpStr(i1)

                        Dim result As String = Nothing
                        If values1.TryGetValue("ItemGr", result) Then
                            sItemGr1 = RTrim(result)
                        End If
                        If values1.TryGetValue("ItemCode", result) Then
                            sItemCode1 = RTrim(result)
                        End If
                        If values1.TryGetValue("StockLctn", result) Then
                            sStockLctn1 = RTrim(result)
                        End If
                        If values1.TryGetValue("ItemID", result) Then
                            sItemID1 = RTrim(result)
                        End If
                        If values1.TryGetValue("ItemInID", result) Then
                            sItemInID1 = RTrim(result)
                        End If
                        If values1.TryGetValue("ItemInCode", result) Then
                            sItemInCode1 = RTrim(result)
                        End If
                        If values1.TryGetValue("ItemInCodeDisp", result) Then
                            sItemInCodeDisp1 = RTrim(result)
                        End If
                        If values1.TryGetValue("PlanSerial", result) Then
                            sPlanSerial1 = RTrim(result)
                        End If
                        If values1.TryGetValue("BunkatuJ", result) Then
                            sBunkatuJ1 = RTrim(result)
                        End If

                        If wstrKeyValue(0) = RTrim(sItemGr1) And wstrKeyValue(1) = RTrim(sItemCode1) Then
                            If wintCnt = gstrctKDPP.intIndex Then
                                With gstrctPPDisp
                                    .strItemCode = RTrim(sItemCode1)
                                    .strCrtnNo = Mid(RTrim(sItemCode1), 21, 5)
                                End With
                                With gstrctPPDispPart
                                    wstrWork = sStockLctn1
                                    wstrLctnItemCode = wstrWork.PadRight(5, " ")
                                    .strLocation = RTrim(sStockLctn1)
                                    .strLocation1 = RTrim(Mid(sStockLctn1, 1, 2))
                                    .strLocation2 = RTrim(Mid(sStockLctn1, 3))
                                    .strID = RTrim(sItemID1)
                                    .strItemCode = RTrim(sItemCode1)
                                    .strItemInID = RTrim(sItemInID1)
                                    .strItemInCode = RTrim(sItemInCode1)
                                    wstrLctnItemCode &= .strItemInCode

                                    '表示用部品番号の編集
                                    wstrItemInCodeDisp = RTrim(sItemInCodeDisp1)
                                    .strPartNoDisp = Mid(wstrItemInCodeDisp, 1, 12)

                                    .strCL = RTrim(Mid(sItemInCode1, 11, 2))
                                    .strZ = RTrim(Mid(sItemInCode1, 13, 1))
                                    .strSerial = RTrim(sPlanSerial1)
                                    .strPackQty = RTrim(sBunkatuJ1)
                                    bFound = True
                                End With
                            End If
                            wintCnt += 1
                        Else
                            Exit Do
                        End If

                        i1 = i1 + 1

                        If tmpStr.Count = i1 Then
                            Exit Do
                        End If

                    Loop

                Else

                    fSearchPackCP = -1
                    'gclsDB.fCloseRecord("PKCP01")
                    Exit Function

                End If

                If Not bFound Then
                    'If FORWARD Then
                    If pintDirection = G_CONST_DIR_GOFORWARD And (gstrctPPDisp.strCrtnNo < Mid(gstrctKDPP.strItemGr, 26, 5)) Then
                        gstrctPPDisp.strCrtnNo = CStr(CInt(gstrctPPDisp.strCrtnNo) + 1).PadLeft(5, "0")
                        gstrctKDPP.intIndex = 0
                    ElseIf pintDirection = G_CONST_DIR_GOBACKWARD And (gstrctPPDisp.strCrtnNo > Mid(gstrctKDPP.strItemGr, 21, 5)) Then
                        gstrctPPDisp.strCrtnNo = CStr(CInt(gstrctPPDisp.strCrtnNo) - 1).PadLeft(5, "0")
                        gstrctKDPP.intIndex = 0
                    Else
                        gstrctKDPP.intIndex = 0
                        Exit Do
                    End If
                    'else

                    'End If
                Else
                    Exit Do
                End If
            Loop

            If bFound Then
                If gstrctPPDisp.strCrtnNo <> wstrPrevCrtnNo Then
                    gstrctPPDispPart.bNextCarton = True
                End If
                fSearchPackCP = 0
                Exit Function
            End If

            'ItemGrで再チェック
            With gstrctKDPP
                wstrKeyValue(0) = .strItemGr
                If pintDirection = 2 Then
                    wstrKeyValue(1) = Mid(.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
                Else
                    wstrKeyValue(1) = Space(30)
                End If

                wstrKeyValue(2) = Space(5)
                wstrKeyValue(3) = Space(5)
                wstrKeyValue(4) = Space(5)
                wstrKeyValue(5) = Space(30)
                wstrKeyValue(6) = Space(6)
            End With

            gstrctKDPP.intIndex = 0

            For index As Integer = 1 To 7 'wstrKey.Count

                If index = 1 Then
                    wstrWhere = wstrKey(index - 1) & " = '" & wstrKeyValue(index - 1) & "'"
                Else
                    wstrWhere = wstrWhere & " and " & wstrKey(index - 1) & " = '" & wstrKeyValue(index - 1) & "'"
                End If


            Next

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemGr As String = ""
            Dim sItemCode As String = ""
            Dim sStockLctn As String = ""
            Dim sItemID As String = ""
            Dim sItemInID As String = ""
            Dim sItemInCode As String = ""
            Dim sItemInCodeDisp As String = ""
            Dim sPlanSerial As String = ""
            Dim sBunkatuJ As String = ""
            Dim i As Integer = 0


            If tmpStr.Count > 0 Then

                Do Until bFound

                    values = tmpStr(i)

                    Dim result As String = Nothing
                    If values.TryGetValue("ItemGr", result) Then
                        sItemGr = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("StockLctn", result) Then
                        sStockLctn = RTrim(result)
                    End If
                    If values.TryGetValue("ItemID", result) Then
                        sItemID = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInID", result) Then
                        sItemInID = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCodeDisp", result) Then
                        sItemInCodeDisp = RTrim(result)
                    End If
                    If values.TryGetValue("PlanSerial", result) Then
                        sPlanSerial = RTrim(result)
                    End If
                    If values.TryGetValue("BunkatuJ", result) Then
                        sBunkatuJ = RTrim(result)
                    End If

                    If (pintDirection <> 2 And wstrKeyValue(0) = RTrim(sItemGr)) Or _
                           (wstrKeyValue(0) = RTrim(sItemGr) And wstrKeyValue(1) = RTrim(sItemCode)) Then
                        With gstrctPPDisp
                            .strItemCode = RTrim(sItemCode)
                            .strCrtnNo = Mid(RTrim(sItemCode), 21, 5)
                        End With
                        '>>> ADD ST  2006.03.06 >>>
                        wstrItemID = sItemID
                        '<<< ADD END 2006.03.06 <<<
                        ''>>> ADD 2006.03.17  ST >>>
                        'If gstrctKDHT.bLinkFlag AndAlso (gstrctAicCase.YYYYMMDD Is Nothing OrElse gstrctAicCase.YYYYMMDD = "") Then
                        '    gstrctAicCase.YYYYMMDD = RTrim(.Item("WKSumDate"))
                        'End If
                        ''<<< ADD 2006.03.17 END <<<
                        With gstrctPPDispPart
                            wstrWork = sStockLctn
                            wstrLctnItemCode = wstrWork.PadRight(5, " ")
                            .strLocation = RTrim(sStockLctn)
                            .strLocation1 = RTrim(Mid(sStockLctn, 1, 2))
                            .strLocation2 = RTrim(Mid(sStockLctn, 3))
                            .strID = RTrim(sItemID)
                            .strItemCode = RTrim(sItemCode)
                            .strItemInID = RTrim(sItemInID)
                            .strItemInCode = RTrim(sItemInCode)
                            wstrLctnItemCode &= .strItemInCode

                            '表示用部品番号の編集
                            wstrItemInCodeDisp = RTrim(sItemInCodeDisp)
                            .strPartNoDisp = Mid(wstrItemInCodeDisp, 1, 12)

                            .strCL = RTrim(Mid(sItemInCode, 11, 2))
                            .strZ = RTrim(Mid(sItemInCode, 13, 1))
                            .strSerial = RTrim(sPlanSerial)
                            .strPackQty = RTrim(sBunkatuJ)
                        End With
                        bFound = True
                    Else
                        Exit Do
                    End If


                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If

                Loop




            End If

            If bFound Then
                If gstrctPPDisp.strCrtnNo <> wstrPrevCrtnNo Then
                    gstrctPPDispPart.bNextCarton = True
                End If
                fSearchPackCP = 0
                ''>>> ADD ST  2006.03.06 >>>
                'If wstrItemID = "D" Then
                '    fSearchPackCP = 1
                'Else
                '    fSearchPackCP = 0
                'End If
                ''<<< ADD END 2006.03.06 <<<
            Else
                fSearchPackCP = -2
            End If

            Exit Function

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



            'rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY03, "PKCP01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
            'If rtn = 9 Then
            '    gclsDB.fCloseRecord("PKCP01")
            '    Exit Do
            'ElseIf rtn <> 0 Then
            '    fSearchPackCP = -1
            '    gclsDB.fCloseRecord("PKCP01")
            '    Exit Function
            'ElseIf rtn = 0 Then
            '    wintCnt = 0
            '    With gclsDB.Records("PKCP01")
            '        Do Until bFound
            '            If wstrKeyValue(0) = RTrim(.Item("ItemGr")) And wstrKeyValue(1) = RTrim(.Item("ItemCode")) Then
            '                If wintCnt = gstrctKDPP.intIndex Then
            '                    With gstrctPPDisp
            '                        .strItemCode = RTrim(gclsDB.Records("PKCP01").Item("ItemCode"))
            '                        .strCrtnNo = Mid(RTrim(gclsDB.Records("PKCP01").Item("ItemCode")), 21, 5)
            '                    End With
            '                    With gstrctPPDispPart
            '                        wstrWork = gclsDB.Records("PKCP01").Item("StockLctn")
            '                        wstrLctnItemCode = wstrWork.PadRight(5, " ")
            '                        .strLocation = RTrim(gclsDB.Records("PKCP01").Item("StockLctn"))
            '                        .strLocation1 = RTrim(Mid(gclsDB.Records("PKCP01").Item("StockLctn"), 1, 2))
            '                        .strLocation2 = RTrim(Mid(gclsDB.Records("PKCP01").Item("StockLctn"), 3))
            '                        .strID = RTrim(gclsDB.Records("PKCP01").Item("ItemID"))
            '                        .strItemCode = RTrim(gclsDB.Records("PKCP01").Item("ItemCode"))
            '                        .strItemInID = RTrim(gclsDB.Records("PKCP01").Item("ItemInID"))
            '                        .strItemInCode = RTrim(gclsDB.Records("PKCP01").Item("ItemInCode"))
            '                        wstrLctnItemCode &= .strItemInCode

            '                        '表示用部品番号の編集
            '                        wstrItemInCodeDisp = RTrim(gclsDB.Records("PKCP01").Item("ItemInCodeDisp"))
            '                        .strPartNoDisp = Mid(wstrItemInCodeDisp, 1, 12)

            '                        .strCL = RTrim(Mid(gclsDB.Records("PKCP01").Item("ItemInCode"), 11, 2))
            '                        .strZ = RTrim(Mid(gclsDB.Records("PKCP01").Item("ItemInCode"), 13, 1))
            '                        .strSerial = RTrim(gclsDB.Records("PKCP01").Item("PlanSerial"))
            '                        .strPackQty = RTrim(gclsDB.Records("PKCP01").Item("BunkatuJ"))
            '                        bFound = True
            '                    End With
            '                End If
            '                wintCnt += 1
            '            Else
            '                Exit Do
            '            End If

            '            If .Read(BtLib.Operation.GetNext) <> 0 Then
            '                'レコードがなくなれば終了する
            '                Exit Do
            '            End If
            '        Loop
            '    End With
            'End If
            'gclsDB.fCloseRecord("PKCP01")

            'If Not bFound Then
            '    'If FORWARD Then
            '    If pintDirection = G_CONST_DIR_GOFORWARD And (gstrctPPDisp.strCrtnNo < Mid(gstrctKDPP.strItemGr, 26, 5)) Then
            '        gstrctPPDisp.strCrtnNo = CStr(CInt(gstrctPPDisp.strCrtnNo) + 1).PadLeft(5, "0")
            '        gstrctKDPP.intIndex = 0
            '    ElseIf pintDirection = G_CONST_DIR_GOBACKWARD And (gstrctPPDisp.strCrtnNo > Mid(gstrctKDPP.strItemGr, 21, 5)) Then
            '        gstrctPPDisp.strCrtnNo = CStr(CInt(gstrctPPDisp.strCrtnNo) - 1).PadLeft(5, "0")
            '        gstrctKDPP.intIndex = 0
            '    Else
            '        gstrctKDPP.intIndex = 0
            '        Exit Do
            '    End If
            '    'else

            '    'End If
            'Else
            '    Exit Do
            'End If
            'Loop

            'If bFound Then
            '    If gstrctPPDisp.strCrtnNo <> wstrPrevCrtnNo Then
            '        gstrctPPDispPart.bNextCarton = True
            '    End If
            '    fSearchPackCP = 0
            '    Exit Function
            'End If

            ''ItemGrで再チェック
            'With gstrctKDPP
            '    wstrKeyValue(0) = .strItemGr
            '    If pintDirection = 2 Then
            '        wstrKeyValue(1) = Mid(.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
            '    Else
            '        wstrKeyValue(1) = Space(30)
            '    End If

            '    wstrKeyValue(2) = Space(5)
            '    wstrKeyValue(3) = Space(5)
            '    wstrKeyValue(4) = Space(5)
            '    wstrKeyValue(5) = Space(30)
            '    wstrKeyValue(6) = Space(6)
            'End With

            'gstrctKDPP.intIndex = 0
            'rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY03, "PKCP01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
            'If rtn = 9 Then
            '    gclsDB.fCloseRecord("PKCP01")
            '    fSearchPackCP = -2
            '    Exit Function
            'ElseIf rtn <> 0 Then
            '    fSearchPackCP = -1
            '    gclsDB.fCloseRecord("PKCP01")
            '    Exit Function
            'ElseIf rtn = 0 Then
            '    With gclsDB.Records("PKCP01")
            '        Do Until bFound
            '            If (pintDirection <> 2 And wstrKeyValue(0) = RTrim(.Item("ItemGr"))) Or _
            '               (wstrKeyValue(0) = RTrim(.Item("ItemGr")) And wstrKeyValue(1) = RTrim(.Item("ItemCode"))) Then
            '                With gstrctPPDisp
            '                    .strItemCode = RTrim(gclsDB.Records("PKCP01").Item("ItemCode"))
            '                    .strCrtnNo = Mid(RTrim(gclsDB.Records("PKCP01").Item("ItemCode")), 21, 5)
            '                End With
            '                '>>> ADD ST  2006.03.06 >>>
            '                wstrItemID = gclsDB.Records("PKCP01").Item("ItemID")
            '                '<<< ADD END 2006.03.06 <<<
            '                ''>>> ADD 2006.03.17  ST >>>
            '                'If gstrctKDHT.bLinkFlag AndAlso (gstrctAicCase.YYYYMMDD Is Nothing OrElse gstrctAicCase.YYYYMMDD = "") Then
            '                '    gstrctAicCase.YYYYMMDD = RTrim(.Item("WKSumDate"))
            '                'End If
            '                ''<<< ADD 2006.03.17 END <<<
            '                With gstrctPPDispPart
            '                    wstrWork = gclsDB.Records("PKCP01").Item("StockLctn")
            '                    wstrLctnItemCode = wstrWork.PadRight(5, " ")
            '                    .strLocation = RTrim(gclsDB.Records("PKCP01").Item("StockLctn"))
            '                    .strLocation1 = RTrim(Mid(gclsDB.Records("PKCP01").Item("StockLctn"), 1, 2))
            '                    .strLocation2 = RTrim(Mid(gclsDB.Records("PKCP01").Item("StockLctn"), 3))
            '                    .strID = RTrim(gclsDB.Records("PKCP01").Item("ItemID"))
            '                    .strItemCode = RTrim(gclsDB.Records("PKCP01").Item("ItemCode"))
            '                    .strItemInID = RTrim(gclsDB.Records("PKCP01").Item("ItemInID"))
            '                    .strItemInCode = RTrim(gclsDB.Records("PKCP01").Item("ItemInCode"))
            '                    wstrLctnItemCode &= .strItemInCode

            '                    '表示用部品番号の編集
            '                    wstrItemInCodeDisp = RTrim(gclsDB.Records("PKCP01").Item("ItemInCodeDisp"))
            '                    .strPartNoDisp = Mid(wstrItemInCodeDisp, 1, 12)

            '                    .strCL = RTrim(Mid(gclsDB.Records("PKCP01").Item("ItemInCode"), 11, 2))
            '                    .strZ = RTrim(Mid(gclsDB.Records("PKCP01").Item("ItemInCode"), 13, 1))
            '                    .strSerial = RTrim(gclsDB.Records("PKCP01").Item("PlanSerial"))
            '                    .strPackQty = RTrim(gclsDB.Records("PKCP01").Item("BunkatuJ"))
            '                End With
            '                bFound = True
            '            Else
            '                Exit Do
            '            End If

            '            If .Read(BtLib.Operation.GetNext) <> 0 Then
            '                'レコードがなくなれば終了する
            '                Exit Do
            '            End If
            '        Loop
            '    End With
            'End If

            'gclsDB.fCloseRecord("PKCP01")
        '    If bFound Then
        '        If gstrctPPDisp.strCrtnNo <> wstrPrevCrtnNo Then
        '            gstrctPPDispPart.bNextCarton = True
        '        End If
        '        fSearchPackCP = 0
        '        ''>>> ADD ST  2006.03.06 >>>
        '        'If wstrItemID = "D" Then
        '        '    fSearchPackCP = 1
        '        'Else
        '        '    fSearchPackCP = 0
        '        'End If
        '        ''<<< ADD END 2006.03.06 <<<
        '    Else
        '        fSearchPackCP = -2
        '    End If

        '    Exit Function

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


    '*******************************************************************************
    '* 機能     : PACKCJ書き込み
    '* 引数     : 1:キー
    '*            2:ゼロ完了OKフラグ( 0: 通常出荷、1: ゼロ完了)
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fMakePackCJ(ByVal pstrKey As String, ByVal pstrKey2 As String, Optional ByVal intZeroFlg As Integer = 0) As Integer

        Dim wstrCol, wstrValue As String
        Dim wstrQty, wstrSerial, wstrPickFlag, wstrStockLctn As String
        Dim wstrScnDate, wstrScnTime, wstrScnNo As String
        Dim wstrKey(53), wstrKeyValue(53) As String

        fMakePackCJ = -1

        Try

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sBunkatuJ As String = ""
            Dim sStockLctn As String = ""
            Dim sPlanSerial As String = ""
            Dim sTempSerial As String = ""

            Dim sHandyNo As String = ""
            Dim sPicsType As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""

            Dim sTrSectionId As String = ""
            Dim sTrSection As String = ""
            Dim sWKSumDate As String = ""
            Dim sProductDate As String = ""
            Dim sShift As String = ""
            Dim sLine As String = ""
            Dim sPackNo As String = ""
            Dim sItemID As String = ""
            Dim sItemGr As String = ""
            Dim sItemCode As String = ""
            Dim sItemMCode As String = ""
            Dim sItemInID As String = ""
            Dim sItemInCode As String = ""
            Dim sPackQtyP As String = ""
            Dim sCaseQty As String = ""

            Dim sCenterCode As String = ""
            Dim sBhk As String = ""
            Dim sSortLctn1 As String = ""
            Dim sSortLctn2 As String = ""
            Dim sSortLctn3 As String = ""
            Dim sPairLctn As String = ""
            Dim sDisplayLctn As String = ""
            Dim sPartID As String = ""
            Dim sHosoYou As String = ""
            Dim sHosoTan As String = ""
            Dim sHosoZai As String = ""
            Dim sInz As String = ""
            Dim sSetDaisu As String = ""

            Dim sPalLctn As String = ""
            Dim sOffDate As String = ""
            Dim sOffTime As String = ""
            Dim sS6030 As String = ""
            Dim sPartName As String = ""

            Dim sItemCodeDisp As String = ""
            Dim sItemInCodeDisp As String = ""

            Dim sqlInsert As String = ""


            If tmpStrCP.Count > 0 Then

                values = tmpStrCP(0)

                Dim result As String = Nothing
                If values.TryGetValue("BunkatuJ", result) Then
                    sBunkatuJ = RTrim(result)
                End If
                If values.TryGetValue("StockLctn", result) Then
                    sStockLctn = RTrim(result)
                End If
                If values.TryGetValue("PlanSerial", result) Then
                    sPlanSerial = RTrim(result)
                End If
                If values.TryGetValue("TempSerial", result) Then
                    sTempSerial = RTrim(result)
                End If

                If values.TryGetValue("HandyNo", result) Then
                    sHandyNo = RTrim(result)
                End If
                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("TrSectionId", result) Then
                    sTrSectionId = RTrim(result)
                End If
                If values.TryGetValue("TrSection", result) Then
                    sTrSection = RTrim(result)
                End If
                If values.TryGetValue("WKSumDate", result) Then
                    sWKSumDate = RTrim(result)
                End If
                If values.TryGetValue("ProductDate", result) Then
                    sProductDate = RTrim(result)
                End If
                If values.TryGetValue("Shift", result) Then
                    sShift = RTrim(result)
                End If
                If values.TryGetValue("Line", result) Then
                    sLine = RTrim(result)
                End If
                If values.TryGetValue("PackNo", result) Then
                    sPackNo = RTrim(result)
                End If
                If values.TryGetValue("ItemID", result) Then
                    sItemID = RTrim(result)
                End If

                If values.TryGetValue("ItemGr", result) Then
                    sItemGr = RTrim(result)
                End If
                If values.TryGetValue("ItemCode", result) Then
                    sItemCode = RTrim(result)
                End If
                If values.TryGetValue("ItemMCode", result) Then
                    sItemMCode = RTrim(result)
                End If
                If values.TryGetValue("ItemInID", result) Then
                    sItemInID = RTrim(result)
                End If
                If values.TryGetValue("ItemInCode", result) Then
                    sItemInCode = RTrim(result)
                End If
                If values.TryGetValue("PackQtyP", result) Then
                    sPackQtyP = RTrim(result)
                End If
                If values.TryGetValue("CaseQty", result) Then
                    sCaseQty = RTrim(result)
                End If

                If values.TryGetValue("Bhk", result) Then
                    sBhk = RTrim(result)
                End If
                If values.TryGetValue("SortLctn1", result) Then
                    sSortLctn1 = RTrim(result)
                End If
                If values.TryGetValue("SortLctn2", result) Then
                    sSortLctn2 = RTrim(result)
                End If
                If values.TryGetValue("SortLctn3", result) Then
                    sSortLctn3 = RTrim(result)
                End If
                If values.TryGetValue("PairLctn", result) Then
                    sPairLctn = RTrim(result)
                End If
                If values.TryGetValue("DisplayLctn", result) Then
                    sDisplayLctn = RTrim(result)
                End If
                If values.TryGetValue("PlanSerial", result) Then
                    sPlanSerial = RTrim(result)
                End If
                If values.TryGetValue("TempSerial", result) Then
                    sTempSerial = RTrim(result)
                End If

                If values.TryGetValue("PartID", result) Then
                    sPartID = RTrim(result)
                End If
                If values.TryGetValue("HosoYou", result) Then
                    sHosoYou = RTrim(result)
                End If
                If values.TryGetValue("HosoTan", result) Then
                    sHosoTan = RTrim(result)
                End If
                If values.TryGetValue("HosoZai", result) Then
                    sHosoZai = RTrim(result)
                End If
                If values.TryGetValue("Inz", result) Then
                    sInz = RTrim(result)
                End If
                If values.TryGetValue("SetDaisu", result) Then
                    sSetDaisu = RTrim(result)
                End If

                If values.TryGetValue("PalLctn", result) Then
                    sPalLctn = RTrim(result)
                End If
                If values.TryGetValue("OffDate", result) Then
                    sOffDate = RTrim(result)
                End If
                If values.TryGetValue("OffTime", result) Then
                    sOffTime = RTrim(result)
                End If
                If values.TryGetValue("S6030", result) Then
                    sS6030 = RTrim(result)
                End If
                If values.TryGetValue("PartName", result) Then
                    sPartName = RTrim(result)
                End If

                If values.TryGetValue("ItemCodeDisp", result) Then
                    sItemCodeDisp = RTrim(result)
                End If
                If values.TryGetValue("ItemInCodeDisp", result) Then
                    sItemInCodeDisp = RTrim(result)
                End If

                Dim sSerialNo As String = ""

                If tmpStrSTOCK.Count > 0 Then

                    values = tmpStrSTOCK(0)

                    result = Nothing
                    sSerialNo = ""

                    If values.TryGetValue("SerialNo", result) Then
                        sSerialNo = RTrim(result)
                    End If

                End If


                If intZeroFlg = 0 Then
                    wstrQty = sBunkatuJ
                    '// ピックした在庫のシリアルをいれる
                    wstrSerial = sSerialNo
                    wstrPickFlag = "7"
                    wstrStockLctn = sStockLctn
                ElseIf intZeroFlg = 1 Or intZeroFlg = 3 Then
                    wstrQty = "00000"
                    'wstrSerial = "000000"
                    If intZeroFlg = 3 Then '在庫無し
                        wstrSerial = sPlanSerial
                    Else
                        wstrSerial = fGetNewSerialNo(sTempSerial).PadLeft(6, "0")
                    End If
                    wstrPickFlag = "7"
                    wstrStockLctn = "?????"
                Else
                    wstrQty = sBunkatuJ
                    wstrSerial = gstrctPPDispPart.strSerial
                    wstrPickFlag = "7"
                    wstrStockLctn = sStockLctn
                End If
                wstrScnDate = fgetDefaultDate()
                wstrScnTime = fgetDefaultTime()
                wstrScnNo = gstrctKDHT.strUserNo

                '// 追加ﾃﾞｰﾀ生成
                wstrKey(0) = "HandyNo" : wstrKeyValue(0) = sHandyNo & " "
                wstrKey(1) = "PicsType" : wstrKeyValue(1) = sPicsType & " "
                wstrKey(2) = "Cstmid" : wstrKeyValue(2) = sCstmid & " "
                wstrKey(3) = "CstmCode" : wstrKeyValue(3) = sCstmCode & " "
                wstrKey(4) = "TrSectionId" : wstrKeyValue(4) = sTrSectionId & " "
                wstrKey(5) = "TrSection" : wstrKeyValue(5) = sTrSection & " "
                wstrKey(6) = "PickFlag" : wstrKeyValue(6) = wstrPickFlag & " "
                wstrKey(7) = "WKSumDate" : wstrKeyValue(7) = sWKSumDate & " "
                wstrKey(8) = "ProductDate" : wstrKeyValue(8) = sProductDate & " "
                wstrKey(9) = "Shift" : wstrKeyValue(9) = sShift & " "
                wstrKey(10) = "Line" : wstrKeyValue(10) = sLine & " "
                wstrKey(11) = "PackNo" : wstrKeyValue(11) = sPackNo & " "
                wstrKey(12) = "ItemID" : wstrKeyValue(12) = sItemID & " "
                wstrKey(13) = "ItemGr" : wstrKeyValue(13) = sItemGr & " "
                wstrKey(14) = "ItemCode" : wstrKeyValue(14) = sItemCode & " "
                wstrKey(15) = "ItemMCode" : wstrKeyValue(15) = sItemMCode & " "
                wstrKey(16) = "ItemCodeDisp" : wstrKeyValue(16) = sItemCodeDisp & " "
                wstrKey(17) = "ItemInID" : wstrKeyValue(17) = sItemInID & " "
                wstrKey(18) = "ItemInCode" : wstrKeyValue(18) = sItemInCode & " "
                wstrKey(19) = "ItemInCodeDisp" : wstrKeyValue(19) = sItemInCodeDisp & " "
                wstrKey(20) = "PackQtyP" : wstrKeyValue(20) = sPackQtyP & " "
                wstrKey(21) = "PackQtyJ" : wstrKeyValue(21) = wstrQty & " "
                wstrKey(22) = "CaseQty" : wstrKeyValue(22) = sCaseQty & " "
                wstrKey(23) = "CenterCode" : wstrKeyValue(23) = sCenterCode & " "
                wstrKey(24) = "Bhk" : wstrKeyValue(24) = sBhk & " "
                wstrKey(25) = "SortLctn1" : wstrKeyValue(25) = sSortLctn1 & " "
                wstrKey(26) = "SortLctn2" : wstrKeyValue(26) = sSortLctn2 & " "
                wstrKey(27) = "SortLctn3" : wstrKeyValue(27) = sSortLctn3 & " "
                wstrKey(28) = "DisplayLctn" : wstrKeyValue(28) = sDisplayLctn & " "
                wstrKey(29) = "PairLctn" : wstrKeyValue(29) = sPairLctn & " "
                wstrKey(30) = "StockLctn" : wstrKeyValue(30) = wstrStockLctn & " "
                If intZeroFlg = "1" Then
                    wstrKey(31) = "PlanSerial" : wstrKeyValue(31) = wstrSerial & " "
                Else
                    wstrKey(31) = "PlanSerial" : wstrKeyValue(31) = sPlanSerial & " "
                End If
                wstrKey(32) = "SerialNo" : wstrKeyValue(32) = wstrSerial & " "
                wstrKey(33) = "TempSerial" : wstrKeyValue(33) = sTempSerial & " "
                wstrKey(34) = "ScanDate" : wstrKeyValue(34) = wstrScnDate & " "
                wstrKey(35) = "ScanTime" : wstrKeyValue(35) = wstrScnTime & " "
                wstrKey(36) = "UserNo" : wstrKeyValue(36) = wstrScnNo & " "
                wstrKey(37) = "StartDate" : wstrKeyValue(37) = fgetDefaultDate() & " "
                wstrKey(38) = "StartTime" : wstrKeyValue(38) = fgetDefaultTime() & " "
                wstrKey(39) = "EndDate" : wstrKeyValue(39) = fgetDefaultDate() & " "
                wstrKey(40) = "EndTime" : wstrKeyValue(40) = fgetDefaultTime() & " "
                wstrKey(41) = "PartID" : wstrKeyValue(41) = sPartID & " "
                wstrKey(42) = "HosoYou" : wstrKeyValue(42) = sHosoYou & " "
                wstrKey(43) = "HosoTan" : wstrKeyValue(43) = sHosoTan & " "
                wstrKey(44) = "HosoZai" : wstrKeyValue(44) = sHosoZai & " "
                wstrKey(45) = "Inz" : wstrKeyValue(45) = sInz & " "
                wstrKey(46) = "SetDaisu" : wstrKeyValue(46) = sSetDaisu & " "
                wstrKey(47) = "PalLctn" : wstrKeyValue(47) = sPalLctn & " "
                wstrKey(48) = "OffDate" : wstrKeyValue(48) = sOffDate & " "
                wstrKey(49) = "OffTime" : wstrKeyValue(49) = sOffTime & " "
                wstrKey(50) = "S6030" : wstrKeyValue(50) = sS6030 & " "
                wstrKey(51) = "PartName" : wstrKeyValue(51) = sPartName & " "
                wstrKey(52) = "BunkatuJ" : wstrKeyValue(52) = sBunkatuJ & " "
                wstrKey(53) = "Filler" : wstrKeyValue(53) = Space(107)

                sqlInsert = "INSERT INTO " & G_CONST_TBL_PACKCJ & " ("


                For index As Integer = 0 To 53
                    sqlInsert = sqlInsert & wstrKey(index) & ","
                Next

                sqlInsert = sqlInsert & " ) VALUES ("

                For index As Integer = 0 To 53

                    If index <> 53 Then
                        sqlInsert = sqlInsert & "'" & wstrKeyValue(index) & "',"
                    Else
                        sqlInsert = sqlInsert & "'" & wstrKeyValue(index) & "'"
                    End If

                Next

                sqlInsert = sqlInsert & ")"

                affected_rows = dbClient.Execute(sqlInsert)


                If affected_rows = 0 Then

                    sErrLog(gAppName, "fMakePackCJ", "Error")
                    Exit Function

                End If


            End If

            'With gclsDB
            '    If .fInsRecord(G_CONST_TBL_PACKCJ, wstrKey, wstrKeyValue) <> 0 Then
            '        sErrLog(gAppName, "fMakePackCJ", gclsDB.ErrMsg)
            '        Exit Function
            '    End If
            'End With

            fMakePackCJ = 0
            Exit Function

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


            '// PACKCPのﾃﾞｰﾀをPACKCJに移行する
            'With gclsDB.Records(pstrKey)

            '    If intZeroFlg = 0 Then
            '        wstrQty = .Item("BunkatuJ")
            '        '// ピックした在庫のシリアルをいれる
            '        wstrSerial = gclsDB.Records(pstrKey2).Item("SerialNo")
            '        wstrPickFlag = "7"
            '        wstrStockLctn = .Item("StockLctn")
            '    ElseIf intZeroFlg = 1 Or intZeroFlg = 3 Then
            '        wstrQty = "00000"
            '        'wstrSerial = "000000"
            '        If intZeroFlg = 3 Then '在庫無し
            '            wstrSerial = .Item("PlanSerial")
            '        Else
            '            wstrSerial = fGetNewSerialNo(.Item("TempSerial")).PadLeft(6, "0")
            '        End If
            '        wstrPickFlag = "7"
            '        wstrStockLctn = "?????"
            '    Else
            '        wstrQty = .Item("BunkatuJ")
            '        wstrSerial = gstrctPPDispPart.strSerial
            '        wstrPickFlag = "7"
            '        wstrStockLctn = .Item("StockLctn")
            '    End If
            '    wstrScnDate = fgetDefaultDate()
            '    wstrScnTime = fgetDefaultTime()
            '    wstrScnNo = gstrctKDHT.strUserNo

            '    '// 追加ﾃﾞｰﾀ生成
            '    wstrKey(0) = "HandyNo" : wstrKeyValue(0) = .Item("HandyNo") & " "
            '    wstrKey(1) = "PicsType" : wstrKeyValue(1) = .Item("PicsType") & " "
            '    wstrKey(2) = "Cstmid" : wstrKeyValue(2) = .Item("Cstmid") & " "
            '    wstrKey(3) = "CstmCode" : wstrKeyValue(3) = .Item("CstmCode") & " "
            '    wstrKey(4) = "TrSectionId" : wstrKeyValue(4) = .Item("TrSectionId") & " "
            '    wstrKey(5) = "TrSection" : wstrKeyValue(5) = .Item("TrSection") & " "
            '    wstrKey(6) = "PickFlag" : wstrKeyValue(6) = wstrPickFlag & " "
            '    wstrKey(7) = "WKSumDate" : wstrKeyValue(7) = .Item("WKSumDate") & " "
            '    wstrKey(8) = "ProductDate" : wstrKeyValue(8) = .Item("ProductDate") & " "
            '    wstrKey(9) = "Shift" : wstrKeyValue(9) = .Item("Shift") & " "
            '    wstrKey(10) = "Line" : wstrKeyValue(10) = .Item("Line") & " "
            '    wstrKey(11) = "PackNo" : wstrKeyValue(11) = .Item("PackNo") & " "
            '    wstrKey(12) = "ItemID" : wstrKeyValue(12) = .Item("ItemID") & " "
            '    wstrKey(13) = "ItemGr" : wstrKeyValue(13) = .Item("ItemGr") & " "
            '    wstrKey(14) = "ItemCode" : wstrKeyValue(14) = .Item("ItemCode") & " "
            '    wstrKey(15) = "ItemMCode" : wstrKeyValue(15) = .Item("ItemMCode") & " "
            '    wstrKey(16) = "ItemCodeDisp" : wstrKeyValue(16) = .Item("ItemCodeDisp") & " "
            '    wstrKey(17) = "ItemInID" : wstrKeyValue(17) = .Item("ItemInID") & " "
            '    wstrKey(18) = "ItemInCode" : wstrKeyValue(18) = .Item("ItemInCode") & " "
            '    wstrKey(19) = "ItemInCodeDisp" : wstrKeyValue(19) = .Item("ItemInCodeDisp") & " "
            '    wstrKey(20) = "PackQtyP" : wstrKeyValue(20) = .Item("PackQtyP") & " "
            '    wstrKey(21) = "PackQtyJ" : wstrKeyValue(21) = wstrQty & " "
            '    wstrKey(22) = "CaseQty" : wstrKeyValue(22) = .Item("CaseQty") & " "
            '    wstrKey(23) = "CenterCode" : wstrKeyValue(23) = .Item("CenterCode") & " "
            '    wstrKey(24) = "Bhk" : wstrKeyValue(24) = .Item("Bhk") & " "
            '    wstrKey(25) = "SortLctn1" : wstrKeyValue(25) = .Item("SortLctn1") & " "
            '    wstrKey(26) = "SortLctn2" : wstrKeyValue(26) = .Item("SortLctn2") & " "
            '    wstrKey(27) = "SortLctn3" : wstrKeyValue(27) = .Item("SortLctn3") & " "
            '    wstrKey(28) = "DisplayLctn" : wstrKeyValue(28) = .Item("DisplayLctn") & " "
            '    wstrKey(29) = "PairLctn" : wstrKeyValue(29) = .Item("PairLctn") & " "
            '    wstrKey(30) = "StockLctn" : wstrKeyValue(30) = wstrStockLctn & " "
            '    If intZeroFlg = "1" Then
            '        wstrKey(31) = "PlanSerial" : wstrKeyValue(31) = wstrSerial & " "
            '    Else
            '        wstrKey(31) = "PlanSerial" : wstrKeyValue(31) = .Item("PlanSerial") & " "
            '    End If
            '    wstrKey(32) = "SerialNo" : wstrKeyValue(32) = wstrSerial & " "
            '    wstrKey(33) = "TempSerial" : wstrKeyValue(33) = .Item("TempSerial") & " "
            '    wstrKey(34) = "ScanDate" : wstrKeyValue(34) = wstrScnDate & " "
            '    wstrKey(35) = "ScanTime" : wstrKeyValue(35) = wstrScnTime & " "
            '    wstrKey(36) = "UserNo" : wstrKeyValue(36) = wstrScnNo & " "
            '    wstrKey(37) = "StartDate" : wstrKeyValue(37) = fgetDefaultDate() & " "
            '    wstrKey(38) = "StartTime" : wstrKeyValue(38) = fgetDefaultTime() & " "
            '    wstrKey(39) = "EndDate" : wstrKeyValue(39) = fgetDefaultDate() & " "
            '    wstrKey(40) = "EndTime" : wstrKeyValue(40) = fgetDefaultTime() & " "
            '    wstrKey(41) = "PartID" : wstrKeyValue(41) = .Item("PartID") & " "
            '    wstrKey(42) = "HosoYou" : wstrKeyValue(42) = .Item("HosoYou") & " "
            '    wstrKey(43) = "HosoTan" : wstrKeyValue(43) = .Item("HosoTan") & " "
            '    wstrKey(44) = "HosoZai" : wstrKeyValue(44) = .Item("HosoZai") & " "
            '    wstrKey(45) = "Inz" : wstrKeyValue(45) = .Item("Inz") & " "
            '    wstrKey(46) = "SetDaisu" : wstrKeyValue(46) = .Item("SetDaisu") & " "
            '    wstrKey(47) = "PalLctn" : wstrKeyValue(47) = .Item("PalLctn") & " "
            '    wstrKey(48) = "OffDate" : wstrKeyValue(48) = .Item("OffDate") & " "
            '    wstrKey(49) = "OffTime" : wstrKeyValue(49) = .Item("OffTime") & " "
            '    wstrKey(50) = "S6030" : wstrKeyValue(50) = .Item("S6030") & " "
            '    wstrKey(51) = "PartName" : wstrKeyValue(51) = .Item("PartName") & " "
            '    wstrKey(52) = "BunkatuJ" : wstrKeyValue(52) = .Item("BunkatuJ") & " "
            '    wstrKey(53) = "Filler" : wstrKeyValue(53) = Space(107)

            'End With

        '    With gclsDB
        '        If .fInsRecord(G_CONST_TBL_PACKCJ, wstrKey, wstrKeyValue) <> 0 Then
        '            sErrLog(gAppName, "fMakePackCJ", gclsDB.ErrMsg)
        '            Exit Function
        '        End If
        '    End With

        '    fMakePackCJ = 0
        '    Exit Function

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

    End Function

    '*******************************************************************************
    '* 機能     : STOCK更新
    '* 引数     : 1:キー（予約）
    '*            2:キー（ピック）
    '*            3:ゼロ出庫フラグ (0:通常出庫, 1:ゼロ個出庫, 2:19桁, 3:ゼロ出庫でロケが?????)
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fUpdateStock(ByVal pstrKey As String, ByVal pstrKey2 As String, ByVal intZeroFlg As Integer, Optional ByVal pbTranSw As Boolean = True)

        Dim wstrCrntStat As String
        Dim wstrPickStat As String
        Dim wstrCrntSerial As String
        Dim wstrPickSerial As String
        Dim wintRet As Integer

        fUpdateStock = -1

        '// ﾄﾗﾝｻﾞｸｼｮﾝ開始
        'If pbTranSw Then BtLib.Transaction.BeginConCurrent()
        Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
        Dim sPlanSerial As String = ""
        Dim sSerialNo As String = ""

        If pbTranSw Then


            If pstrKey = "KEY03" Then

                If modPublicKDPP.tmpStrCJ.Count > 0 Then

                    values = modPublicKDPP.tmpStrCJ(0)

                    Dim result As String = Nothing
                    If values.TryGetValue("PlanSerial", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sPlanSerial = result
                    End If


                End If


            ElseIf pstrKey = "KEY01" Then

                If tmpStrCP.Count > 0 Then

                    values = tmpStrCP(0)

                    Dim result As String = Nothing
                    If values.TryGetValue("PlanSerial", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sPlanSerial = result
                    End If


                End If


            End If


            If tmpStrSTOCK.Count > 0 Then

                values = tmpStrSTOCK(0)

                Dim result As String = Nothing
                If values.TryGetValue("SerialNo", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sSerialNo = result
                End If

            End If


        End If

        wintRet = -1
        wstrCrntSerial = sPlanSerial
        wstrPickSerial = sSerialNo

        If intZeroFlg = 4 Then
            If fGetStockStatus(wstrCrntStat, pstrKey2, 2) <> 0 Then
                'If pbTranSw Then BtLib.Transaction.Abort()
                Exit Function
            End If

            If wstrCrntStat = "5" OrElse wstrCrntStat = "3" Then
                wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
            Else
                '在庫ステータス異常
                wintRet = -1
            End If

        ElseIf intZeroFlg = 1 Then
            '0件出庫（ロケが?????ケースはここではなし）
            '在庫ステータスの取得
            If fGetStockStatus(wstrCrntStat, pstrKey2, 2) <> 0 Then
                'If pbTranSw Then BtLib.Transaction.Abort()
                Exit Function
            End If

            If wstrCrntStat = G_CONST_ST_STOCK_RESERVED2 Then
                wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_INSTOCK, 2)
            Else
                wintRet = fFreeZaikoStatus(pstrKey2)
            End If

        ElseIf intZeroFlg = 2 Then
            '19桁部品ラベルケース
            '在庫ステータスの取得
            If fGetStockStatus(wstrCrntStat, pstrKey2, 2) <> 0 Then
                'If pbTranSw Then BtLib.Transaction.Abort()
                Exit Function
            End If

            If wstrCrntStat = G_CONST_ST_STOCK_RESERVED2 Then
                wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
            ElseIf wstrCrntStat = G_CONST_ST_STOCK_PICKED Then
                wintRet = fFreeZaikoStatus(pstrKey2, 1)
            End If

        ElseIf wstrCrntSerial = wstrPickSerial Then
            '同一シリアルケース(ゼロ出庫のロケが?????のケースを含む）
            '在庫ステータスの取得
            If fGetStockStatus(wstrCrntStat, pstrKey2, 2) <> 0 Then
                'If pbTranSw Then BtLib.Transaction.Abort()
                Exit Function
            End If

            If wstrCrntStat = "3" Then
                'ステータス５を一つ解放
                wintRet = fFreeZaikoStatus(pstrKey2)
            End If
            If wstrCrntStat = "5" OrElse wstrCrntStat = "3" Then
                wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
            Else
                '在庫ステータス異常
                wintRet = -1
            End If

        Else
            '異なるシリアル：予約したシリアル(pstrKey)とピックしたシリアル(pstrKey2)の両方を処理
            '在庫ステータスの取得
            If fGetStockStatus(wstrPickStat, pstrKey2, 2) = 0 Then
                If fGetStockStatus(wstrCrntStat, pstrKey, 1) <> 0 Then
                    'If pbTranSw Then BtLib.Transaction.Abort()
                    Exit Function
                End If
            Else
                'If pbTranSw Then BtLib.Transaction.Abort()
                Exit Function
            End If

            Select Case wstrCrntStat
                Case "5"
                    If wstrPickStat = "3" Then
                        wintRet = fUpdStock(pstrKey, G_CONST_ST_STOCK_INSTOCK, 1)
                        If wintRet = 0 Then
                            wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
                        End If
                    ElseIf wstrPickStat = "5" Then
                        wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
                    Else
                        '在庫ステータス異常
                        wintRet = -1
                    End If
                Case "3", "7"
                    If wstrPickStat = "3" Then
                        'ステータス５を一つ解放
                        wintRet = fFreeZaikoStatus(pstrKey2)
                        If wintRet = 0 Then wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
                    ElseIf wstrPickStat = "5" Then
                        wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
                    Else
                        '在庫ステータス異常
                        wintRet = -1
                    End If
                Case Else
                    '在庫ステータス異常
                    wintRet = -1
            End Select
        End If








        'wintRet = -1
        'wstrCrntSerial = gclsDB.Records(pstrKey).Item("PlanSerial")
        'wstrPickSerial = gclsDB.Records(pstrKey2).Item("SerialNo")
        'If intZeroFlg = 4 Then
        '    If fGetStockStatus(wstrCrntStat, pstrKey2, 2) <> 0 Then
        '        If pbTranSw Then BtLib.Transaction.Abort()
        '        Exit Function
        '    End If

        '    If wstrCrntStat = "5" OrElse wstrCrntStat = "3" Then
        '        wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
        '    Else
        '        '在庫ステータス異常
        '        wintRet = -1
        '    End If

        'ElseIf intZeroFlg = 1 Then
        '    '0件出庫（ロケが?????ケースはここではなし）
        '    '在庫ステータスの取得
        '    If fGetStockStatus(wstrCrntStat, pstrKey2, 2) <> 0 Then
        '        If pbTranSw Then BtLib.Transaction.Abort()
        '        Exit Function
        '    End If

        '    If wstrCrntStat = G_CONST_ST_STOCK_RESERVED2 Then
        '        wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_INSTOCK, 2)
        '    Else
        '        wintRet = fFreeZaikoStatus(pstrKey2)
        '    End If

        'ElseIf intZeroFlg = 2 Then
        '    '19桁部品ラベルケース
        '    '在庫ステータスの取得
        '    If fGetStockStatus(wstrCrntStat, pstrKey2, 2) <> 0 Then
        '        If pbTranSw Then BtLib.Transaction.Abort()
        '        Exit Function
        '    End If

        '    If wstrCrntStat = G_CONST_ST_STOCK_RESERVED2 Then
        '        wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
        '    ElseIf wstrCrntStat = G_CONST_ST_STOCK_PICKED Then
        '        wintRet = fFreeZaikoStatus(pstrKey2, 1)
        '    End If

        'ElseIf wstrCrntSerial = wstrPickSerial Then
        '    '同一シリアルケース(ゼロ出庫のロケが?????のケースを含む）
        '    '在庫ステータスの取得
        '    If fGetStockStatus(wstrCrntStat, pstrKey2, 2) <> 0 Then
        '        If pbTranSw Then BtLib.Transaction.Abort()
        '        Exit Function
        '    End If

        '    If wstrCrntStat = "3" Then
        '        'ステータス５を一つ解放
        '        wintRet = fFreeZaikoStatus(pstrKey2)
        '    End If
        '    If wstrCrntStat = "5" OrElse wstrCrntStat = "3" Then
        '        wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
        '    Else
        '        '在庫ステータス異常
        '        wintRet = -1
        '    End If

        'Else
        '    '異なるシリアル：予約したシリアル(pstrKey)とピックしたシリアル(pstrKey2)の両方を処理
        '    '在庫ステータスの取得
        '    If fGetStockStatus(wstrPickStat, pstrKey2, 2) = 0 Then
        '        If fGetStockStatus(wstrCrntStat, pstrKey, 1) <> 0 Then
        '            If pbTranSw Then BtLib.Transaction.Abort()
        '            Exit Function
        '        End If
        '    Else
        '        If pbTranSw Then BtLib.Transaction.Abort()
        '        Exit Function
        '    End If

        '    Select Case wstrCrntStat
        '        Case "5"
        '            If wstrPickStat = "3" Then
        '                wintRet = fUpdStock(pstrKey, G_CONST_ST_STOCK_INSTOCK, 1)
        '                If wintRet = 0 Then
        '                    wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
        '                End If
        '            ElseIf wstrPickStat = "5" Then
        '                wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
        '            Else
        '                '在庫ステータス異常
        '                wintRet = -1
        '            End If
        '        Case "3", "7"
        '            If wstrPickStat = "3" Then
        '                'ステータス５を一つ解放
        '                wintRet = fFreeZaikoStatus(pstrKey2)
        '                If wintRet = 0 Then wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
        '            ElseIf wstrPickStat = "5" Then
        '                wintRet = fUpdStock(pstrKey2, G_CONST_ST_STOCK_PICKED, 2)
        '            Else
        '                '在庫ステータス異常
        '                wintRet = -1
        '            End If
        '        Case Else
        '            '在庫ステータス異常
        '            wintRet = -1
        '    End Select
        'End If

        'If wintRet = 0 Then
        '    '// ﾄﾗﾝｻﾞｸｼｮﾝ終了
        '    If pbTranSw Then BtLib.Transaction.End()
        'Else
        '    If pbTranSw Then BtLib.Transaction.Abort()
        'End If
        fUpdateStock = wintRet

    End Function

    '/*
    '|| 関数名 : fGetZaikoStatus
    '|| 概要　 : 在庫ステータスの取得
    '|| 引数　 : 1.在庫ステータス
    '||          2.検索キー
    '|| 戻り値 : 0:OK -1:NG
    '*/
    Public Function fGetStockStatus(ByRef strStatus As String, ByVal pstrKey As String, ByVal pintFlag As Integer) As Integer
        Dim wstrKey(7) As String
        Dim wstrKeyValue(7) As String
        Dim wintRet As Integer
        Dim wstrWhere As String
        Const STK_KEY00 = "G_CONST_KEY_STOCKKEY00"

        strStatus = "-1"
        fGetStockStatus = -1
        '検索キーの設定

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

        If tmpStrCP.Count > 0 Then

            values = tmpStr(0)

            Dim result As String = Nothing
            Dim sPicsType As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""
            Dim sCenterCode As String = ""
            Dim sBhk As String = ""
            Dim sItemInID As String = ""
            Dim sItemInCode As String = ""
            Dim sPlanSerial As String = ""
            Dim sItemid As String = ""
            Dim sItemCode As String = ""
            Dim sSerialNo As String = ""

            If values.TryGetValue("PicsType", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sPicsType = result
            End If
            If values.TryGetValue("Cstmid", result) Then
                sCstmid = result
            End If
            If values.TryGetValue("CstmCode", result) Then
                sCstmCode = result
            End If
            If values.TryGetValue("CenterCode", result) Then
                sCenterCode = result
            End If
            If values.TryGetValue("Bhk", result) Then
                sBhk = result
            End If
            If values.TryGetValue("ItemInID", result) Then
                sItemInID = result
            End If
            If values.TryGetValue("ItemInCode", result) Then
                sItemInCode = result
            End If
            If values.TryGetValue("PlanSerial", result) Then
                sPlanSerial = result
            End If
            If values.TryGetValue("Itemid", result) Then
                sItemid = result
            End If
            If values.TryGetValue("ItemCode", result) Then
                sItemCode = result
            End If
            If values.TryGetValue("SerialNo", result) Then
                sSerialNo = result
            End If



            'With gclsDB.Records(pstrKey)
            wstrKey(0) = "PicsType" : wstrKeyValue(0) = RTrim(sPicsType)
            wstrKey(1) = "Cstmid" : wstrKeyValue(1) = RTrim(sCstmid)
            wstrKey(2) = "CstmCode" : wstrKeyValue(2) = RTrim(sCstmCode)
            wstrKey(3) = "CenterCode" : wstrKeyValue(3) = RTrim(sCenterCode)
            wstrKey(4) = "Bhk" : wstrKeyValue(4) = RTrim(sBhk)
            If pintFlag = 1 Then
                wstrKey(5) = "Itemid" : wstrKeyValue(5) = RTrim(sItemInID)
                wstrKey(6) = "ItemCode" : wstrKeyValue(6) = RTrim(sItemInCode)
                wstrKey(7) = "SerialNo" : wstrKeyValue(7) = RTrim(sPlanSerial)
            Else
                wstrKey(5) = "Itemid" : wstrKeyValue(5) = RTrim(sItemid)
                wstrKey(6) = "ItemCode" : wstrKeyValue(6) = RTrim(sItemCode)
                wstrKey(7) = "SerialNo" : wstrKeyValue(7) = RTrim(sSerialNo)
            End If
            'End With

        End If

        Try

            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 values1 As Dictionary(Of String, String) = New Dictionary(Of String, String)


            If tmpStr.Count > 0 Then

                values1 = 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 values1.TryGetValue("PicsType", result) Then
                    sPicsType = RTrim(result)
                End If
                If values1.TryGetValue("Cstmid", result) Then
                    sCstmid = RTrim(result)
                End If
                If values1.TryGetValue("CstmCode", result) Then
                    sCstmCode = RTrim(result)
                End If
                If values1.TryGetValue("CenterCode", result) Then
                    sCenterCode = RTrim(result)
                End If
                If values1.TryGetValue("Bhk", result) Then
                    sBhk = RTrim(result)
                End If
                If values1.TryGetValue("Location", result) Then
                    sLocation = RTrim(result)
                End If
                If values1.TryGetValue("Itemid", result) Then
                    sItemid = RTrim(result)
                End If
                If values1.TryGetValue("ItemCode", result) Then
                    sItemCode = RTrim(result)
                End If
                If values1.TryGetValue("ZaikoStatus", result) Then
                    sZaikoStatus = RTrim(result)
                End If
                If values1.TryGetValue("SerialNo", result) Then
                    sSerialNo = RTrim(result)
                End If

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

                    strStatus = RTrim(sZaikoStatus)

                End If

            Else

                Exit Function

            End If

            fGetStockStatus = 0
            Exit Function

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



        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, STK_KEY00, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'If wintRet = 9 Then
        '    gclsDB.fCloseRecord(STK_KEY00)
        '    Exit Function
        'ElseIf wintRet <> 0 Then
        '    gclsDB.fCloseRecord(STK_KEY00)
        '    Exit Function
        'End If

        'If wintRet = 0 Then
        '    With gclsDB.Records(STK_KEY00)

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

        '            strStatus = RTrim(.Item("ZaikoStatus"))

        '        End If
        '    End With
        'End If

        'gclsDB.fCloseRecord(STK_KEY00)
        'fGetStockStatus = 0
        'Exit Function

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

    '/*
    '|| 関数名：fUpdStock
    '|| 概要  ：ストック更新処理
    '|| 引数  ：1.キー値 2.ステータス
    '|| 戻り値 : 0:OK -1:ERROR
    '*/
    Public Function fUpdStock(ByVal pstrKey As String, ByVal Status As String, ByVal pintFlag As Integer) As Integer
        Dim wintRet As Integer
        Dim wstrKey(7), wstrKeyValue(7) As String

        fUpdStock = -1
        'キー設定

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

        If tmpStrCP.Count > 0 Then

            values = tmpStr(0)

            Dim result As String = Nothing
            Dim sPicsType As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""
            Dim sCenterCode As String = ""
            Dim sBhk As String = ""
            Dim sItemInID As String = ""
            Dim sItemInCode As String = ""
            Dim sPlanSerial As String = ""
            Dim sItemid As String = ""
            Dim sItemCode As String = ""
            Dim sSerialNo As String = ""

            If values.TryGetValue("PicsType", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sPicsType = result
            End If
            If values.TryGetValue("Cstmid", result) Then
                sCstmid = result
            End If
            If values.TryGetValue("CstmCode", result) Then
                sCstmCode = result
            End If
            If values.TryGetValue("CenterCode", result) Then
                sCenterCode = result
            End If
            If values.TryGetValue("Bhk", result) Then
                sBhk = result
            End If
            If values.TryGetValue("ItemInID", result) Then
                sItemInID = result
            End If
            If values.TryGetValue("ItemInCode", result) Then
                sItemInCode = result
            End If
            If values.TryGetValue("PlanSerial", result) Then
                sPlanSerial = result
            End If
            If values.TryGetValue("Itemid", result) Then
                sItemid = result
            End If
            If values.TryGetValue("ItemCode", result) Then
                sItemCode = result
            End If
            If values.TryGetValue("SerialNo", result) Then
                sSerialNo = result
            End If


            'With gclsDB.Records(pstrKey)
            wstrKey(0) = "PicsType" : wstrKeyValue(0) = RTrim(sPicsType)
            wstrKey(1) = "Cstmid" : wstrKeyValue(1) = RTrim(sCstmid)
            wstrKey(2) = "CstmCode" : wstrKeyValue(2) = RTrim(sCstmCode)
            wstrKey(3) = "CenterCode" : wstrKeyValue(3) = RTrim(sCenterCode)
            wstrKey(4) = "Bhk" : wstrKeyValue(4) = RTrim(sBhk)
            If pintFlag = 1 Then
                wstrKey(5) = "Itemid" : wstrKeyValue(5) = RTrim(sItemInID)
                wstrKey(6) = "ItemCode" : wstrKeyValue(6) = RTrim(sItemInCode)
                wstrKey(7) = "SerialNo" : wstrKeyValue(7) = RTrim(sPlanSerial)
            Else
                wstrKey(5) = "Itemid" : wstrKeyValue(5) = RTrim(sItemid)
                wstrKey(6) = "ItemCode" : wstrKeyValue(6) = RTrim(sItemCode)
                wstrKey(7) = "SerialNo" : wstrKeyValue(7) = RTrim(sSerialNo)
            End If
            'End With

        End If

        Try

            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='" + Status _
                                           + "' WHERE " + wstrWhere)


            If affected_rows = 0 Then
                Exit Function
            End If



            '//DB更新
            'With gclsDB
            '    .Setcolumn = "ZaikoStatus"
            '    .SetData = Status
            '    wintRet = .fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, wstrKey, wstrKeyValue)
            '    If wintRet = -1 Then
            '        sErrLog(gAppName, "fUpdStock", gclsDB.ErrMsg)
            '        Exit Function
            '    ElseIf wintRet <> 0 Then
            '        Exit Function
            '    End If
            'End With

            fUpdStock = 0
            Exit Function

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

    End Function

    '/*
    '|| 関数名：fUpdateLocation
    '|| 概要  ：ロケーション更新処理
    '|| 引数  ：1.キー値 2.処理された袋数
    '|| 戻り値 : 0:OK -1:ERROR
    '*/
    Public Function fUpdateLocation(ByVal pstrKey As String, ByVal pstrKey2 As String, ByVal pintMovedQty As Integer, _
                                     Optional ByVal pbTranSw As Boolean = True, Optional ByVal pstrKeepLctn As String = "", _
                                     Optional ByVal pbKeepKbn As Boolean = False) As Integer

        Dim wintFlag As Integer
        Dim wstrProduct As String
        Dim wintCrntQty As Integer
        Dim wstrNewQty As String
        Dim wintRet As Integer
        Dim wstrKey(9), wstrKeyValue(9) As String
        Dim wstrKey2(3), wstrKeyValue2(3) As String
        Dim sSQL As String
        Dim wstrWhere As String

        fUpdateLocation = -1

        '// ﾄﾗﾝｻﾞｸｼｮﾝ開始
        'If pbTranSw Then BtLib.Transaction.BeginConCurrent()

        Try

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

            If tmpStrSTOCK.Count > 0 Then

                values = tmpStrSTOCK(0)
                Dim result As String = Nothing
                Dim sCenterCode As String = Nothing
                Dim sBhk As String = Nothing
                Dim sLocation As String = Nothing

                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
               

                wstrKey2(0) = "CenterCode" : wstrKeyValue2(0) = RTrim(sCenterCode)
                wstrKey2(1) = "Bhk" : wstrKeyValue2(1) = RTrim(sBhk)
                wstrKey2(2) = "Location" : wstrKeyValue2(2) = RTrim(sLocation)
                wstrKey2(3) = "Product" : wstrKeyValue2(3) = Space(6)


            End If

            If pstrKey = "KEY03" Then

                If tmpStrCJ.Count > 0 Then

                    values = tmpStrCJ(0)
                    Dim result As String = Nothing
                    Dim sProductDate As String = Nothing

                    If values.TryGetValue("ProductDate", result) Then
                        sProductDate = RTrim(result)
                    End If

                    wstrProduct = Mid(RTrim(sProductDate), 1, 6)


                End If


            ElseIf pstrKey = "KEY01" Then

                If tmpStrCP.Count > 0 Then

                    values = tmpStrCP(0)
                    Dim result As String = Nothing
                    Dim sProductDate As String = Nothing

                    If values.TryGetValue("ProductDate", result) Then
                        sProductDate = RTrim(result)
                    End If

                    wstrProduct = Mid(RTrim(sProductDate), 1, 6)


                End If


            End If


            wintFlag = 0

            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) & "'"

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

            values = 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 sCenterCode As String = Nothing
                    Dim sBhk As String = Nothing
                    Dim sLocation As String = Nothing
                    Dim sProduct As String = Nothing
                    Dim sQty As String = Nothing

                    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("Product", result) Then
                        sProduct = RTrim(result)
                    End If
                    If values.TryGetValue("Qty", result) Then
                        sQty = RTrim(result)
                    End If


                    If wstrKeyValue2(0) = RTrim(sCenterCode) And _
                            wstrKeyValue2(1) = RTrim(sBhk) And _
                            wstrKeyValue2(2) = RTrim(sLocation) Then

                        If "999999" = RTrim(sProduct) Then
                            wintFlag = 1
                            wintCrntQty = CInt(RTrim(sQty))
                            wstrKeyValue2(3) = RTrim(sProduct)
                            Exit Do
                        ElseIf wstrProduct = RTrim(sProduct) Then
                            wintFlag = 2
                            wintCrntQty = CInt(RTrim(sQty))
                            wstrKeyValue2(3) = RTrim(sProduct)
                            Exit Do
                        End If

                    Else
                        Exit Do
                    End If


                    i = i + 1

                    If i = tmpStr.Count Then
                        Exit Do
                    End If

                Loop


            Else

                Exit Function

            End If

            If wintCrntQty - pintMovedQty < 0 Then
                wstrNewQty = 0
            Else
                wstrNewQty = CStr(wintCrntQty - pintMovedQty)
            End If
            wstrNewQty = wstrNewQty.PadLeft(6, "0")

            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) & "'"

            'With gclsDB
            If wintFlag = 1 And wstrNewQty = "000000" Then
                If pbKeepKbn Then
                    '.Setcolumn = "Qty,AkiKB"
                    '.SetData = wstrNewQty & "," & "1"

                    sSQL = "UPDATE " + G_CONST_TBL_LOCATION _
                                        + " SET Qty='" + wstrNewQty _
                                        + "' AkiKB='" + "1" _
                                        + "' WHERE " + wstrWhere

                Else
                    If pstrKeepLctn = "" Then
                        '.Setcolumn = "Qty,AkiKB"
                        '.SetData = wstrNewQty & "," & "0"

                        sSQL = "UPDATE " + G_CONST_TBL_LOCATION _
                                        + " SET Qty='" + wstrNewQty _
                                        + "' AkiKB='" + "0" _
                                        + "' WHERE " + wstrWhere


                    Else 'ロケーション保持
                        '.Setcolumn = "Qty,AkiKB"
                        '.SetData = wstrNewQty & "," & "1"

                        sSQL = "UPDATE " + G_CONST_TBL_LOCATION _
                                        + " SET Qty='" + wstrNewQty _
                                        + "' AkiKB='" + "1" _
                                        + "' WHERE " + wstrWhere

                    End If
                End If
            ElseIf wintFlag <> 0 Then
                '.Setcolumn = "Qty"
                '.SetData = wstrNewQty

                sSQL = "UPDATE " + G_CONST_TBL_LOCATION _
                                        + " SET Qty='" + wstrNewQty _
                                        + "' WHERE " + wstrWhere
            Else
                'If pbTranSw Then BtLib.Transaction.Abort()
                Exit Function
            End If

            affected_rows = dbClient.Execute(sSQL)


            If affected_rows = 0 Then
                Exit Function
            End If



            'wintRet = .fUpdRecords(G_CONST_TBL_LOCATION, G_CONST_KEY_LOCATIONKEY00, wstrKey2, wstrKeyValue2)
            'If wintRet = -1 Then
            '    sErrLog(gAppName, "fUpdateLocation", gclsDB.ErrMsg)
            '    If pbTranSw Then BtLib.Transaction.Abort()
            '    Exit Function
            'ElseIf wintRet <> 0 Then
            '    If pbTranSw Then BtLib.Transaction.Abort()
            '    Exit Function
            'End If
            'End With





            'キー設定
            'With gclsDB.Records(pstrKey2)
            '    wstrKey2(0) = "CenterCode" : wstrKeyValue2(0) = RTrim(.Item("CenterCode"))
            '    wstrKey2(1) = "Bhk" : wstrKeyValue2(1) = RTrim(.Item("Bhk"))
            '    wstrKey2(2) = "Location" : wstrKeyValue2(2) = RTrim(.Item("Location"))
            '    wstrKey2(3) = "Product" : wstrKeyValue2(3) = Space(6)

            '    wstrProduct = Mid(RTrim(gclsDB.Records(pstrKey).Item("ProductDate")), 1, 6)
            'End With

            'wintFlag = 0
            'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_LOCATION, G_CONST_KEY_LOCATIONKEY00, "LCTN1", wstrKey2, wstrKeyValue2, BtLib.Operation.GetGreaterOrEqual)
            'If wintRet = 9 Then
            '    gclsDB.fCloseRecord("LCTN1")
            '    If pbTranSw Then BtLib.Transaction.Abort()
            '    Exit Function
            'ElseIf wintRet <> 0 Then
            '    gclsDB.fCloseRecord("LCTN1")
            '    If pbTranSw Then BtLib.Transaction.Abort()
            '    Exit Function
            'End If

            'If wintRet = 0 Then
            '    Do

            '        With gclsDB.Records("LCTN1")

            '            If wstrKeyValue2(0) = RTrim(.Item("CenterCode")) And _
            '                wstrKeyValue2(1) = RTrim(.Item("Bhk")) And _
            '                wstrKeyValue2(2) = RTrim(.Item("Location")) Then

            '                If "999999" = RTrim(.Item("Product")) Then
            '                    wintFlag = 1
            '                    wintCrntQty = CInt(RTrim(.Item("Qty")))
            '                    wstrKeyValue2(3) = RTrim(.Item("Product"))
            '                    Exit Do
            '                ElseIf wstrProduct = RTrim(.Item("Product")) Then
            '                    wintFlag = 2
            '                    wintCrntQty = CInt(RTrim(.Item("Qty")))
            '                    wstrKeyValue2(3) = RTrim(.Item("Product"))
            '                    Exit Do
            '                End If

            '            Else
            '                Exit Do
            '            End If

            '            If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do

            '        End With

            '    Loop
            'End If

            'gclsDB.fCloseRecord("LCTN1")
            'If wintCrntQty - pintMovedQty < 0 Then
            '    wstrNewQty = 0
            'Else
            '    wstrNewQty = CStr(wintCrntQty - pintMovedQty)
            'End If
            'wstrNewQty = wstrNewQty.PadLeft(6, "0")

            '//DB更新
            'With gclsDB
            '    If wintFlag = 1 And wstrNewQty = "000000" Then
            '        If pbKeepKbn Then
            '            .Setcolumn = "Qty,AkiKB"
            '            .SetData = wstrNewQty & "," & "1"
            '        Else
            '            If pstrKeepLctn = "" Then
            '                .Setcolumn = "Qty,AkiKB"
            '                .SetData = wstrNewQty & "," & "0"
            '            Else 'ロケーション保持
            '                .Setcolumn = "Qty,AkiKB"
            '                .SetData = wstrNewQty & "," & "1"
            '            End If
            '        End If
            '    ElseIf wintFlag <> 0 Then
            '        .Setcolumn = "Qty"
            '        .SetData = wstrNewQty
            '    Else
            '        If pbTranSw Then BtLib.Transaction.Abort()
            '        Exit Function
            '    End If

            '    wintRet = .fUpdRecords(G_CONST_TBL_LOCATION, G_CONST_KEY_LOCATIONKEY00, wstrKey2, wstrKeyValue2)
            '    If wintRet = -1 Then
            '        sErrLog(gAppName, "fUpdateLocation", gclsDB.ErrMsg)
            '        If pbTranSw Then BtLib.Transaction.Abort()
            '        Exit Function
            '    ElseIf wintRet <> 0 Then
            '        If pbTranSw Then BtLib.Transaction.Abort()
            '        Exit Function
            '    End If
            'End With

            '// ﾄﾗﾝｻﾞｸｼｮﾝ終了
            'If pbTranSw Then BtLib.Transaction.End()
            fUpdateLocation = 0
            Exit Function

        Catch ex As Exception
            'BtLib.Transaction.Abort()
            sErrLog(gAppName, "fUpdateLocation", ex.ToString)
        End Try

    End Function

    '*******************************************************************************
    '* 機能     : 出庫ﾃﾞｰﾀ更新制御
    '* 引数     : 1 pstrKey:予約レコードのPACKCPキー 
    '             2 pstrKey:ピックレコードのSTOCKキー (但し、intZeroFlg=3のときは予約レコードのSTOCKキー）
    '             3 intZeroFlg:ゼロ出庫フラグ (0:通常出庫, 1:ゼロ個出庫, 2:19桁, 3:ゼロ出庫でロケが?????)
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fUpdProc(ByVal pstrKey As String, ByVal pstrKey2 As String, Optional ByVal intZeroFlg As Integer = 0) As Integer

        Dim wlntRet As Integer
        Dim wstrKey(2) As String
        Dim wstrKeyValue(2) As String
        Dim wstrWhere As String
        Const KEY03 = "UPD_KEY03"

        fUpdProc = -1
        Try
            '// ﾄﾗﾝｻﾞｸｼｮﾝ開始
            'BtLib.Transaction.BeginConCurrent()

            '// PACKCJ生成
            wlntRet = fMakePackCJ(pstrKey, pstrKey2, intZeroFlg)

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemCode As String = ""
            Dim sItemInCode As String = ""
            Dim sPlanSerial As String = ""

            If tmpStrCP.Count > 0 Then

                values = tmpStr(0)

                Dim result As String = Nothing
                If values.TryGetValue("ItemCode", result) Then
                    sItemCode = RTrim(result)
                End If
                If values.TryGetValue("ItemInCode", result) Then
                    sItemInCode = RTrim(result)
                End If
                If values.TryGetValue("sPlanSerial", result) Then
                    sPlanSerial = RTrim(result)
                End If

                wstrKey(0) = "ItemCode" : wstrKeyValue(0) = sItemCode
                wstrKey(1) = "ItemInCode" : wstrKeyValue(1) = sItemInCode
                wstrKey(2) = "PlanSerial" : wstrKeyValue(2) = sPlanSerial

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


                If wlntRet = 0 Then wlntRet = fDeletePackCP(pstrKey, wstrWhere)

                If wlntRet <> 0 Then
                    'BtLib.Transaction.Abort()
                    Exit Function
                Else
                    '// ﾄﾗﾝｻﾞｸｼｮﾝ終了
                    'BtLib.Transaction.End()
                End If


            End If

            wlntRet = fOpenPackCJ(G_CONST_KEY_PACKCJKEY06, KEY03, wstrKey, wstrKeyValue)
            If wlntRet <> 0 Then
                'DBエラー
                'gclsDB.fCloseRecord(KEY03)
                Exit Function
            End If

            '// STOCK更新
            'ゼロ件出庫でロケが?????の場合はストックの更新必要なし
            If intZeroFlg <> 3 Then wlntRet = fUpdateStock(KEY03, pstrKey2, intZeroFlg)

            '// ﾛｹｰｼｮﾝ更新
            'ゼロ件出庫はロケの更新必要なし
            If intZeroFlg <> 1 And intZeroFlg <> 3 Then wlntRet = fUpdateLocation(KEY03, pstrKey2, 1)

            'gclsDB.fCloseRecord(KEY03)
            fUpdProc = 0
            Exit Function

        Catch ex As Exception
            sErrLog(gAppName, "fUpdProc", ex.ToString)
            'BtLib.Transaction.Abort()
        End Try



            '// PACKCPデータの退避
            'With gclsDB.Records(pstrKey)
            '    wstrKey(0) = "ItemCode" : wstrKeyValue(0) = .Item("ItemCode")
            '    wstrKey(1) = "ItemInCode" : wstrKeyValue(1) = .Item("ItemInCode")
            '    wstrKey(2) = "PlanSerial" : wstrKeyValue(2) = .Item("PlanSerial")
            'End With

            '// PACKCP削除
            'If wlntRet = 0 Then wlntRet = fDeletePackCP(pstrKey)

            'If wlntRet <> 0 Then
            '    BtLib.Transaction.Abort()
            '    Exit Function
            'Else
            '    '// ﾄﾗﾝｻﾞｸｼｮﾝ終了
            '    BtLib.Transaction.End()
            'End If

            '// PACKCJへのキーの持ち替え
        '    wlntRet = fOpenPackCJ(G_CONST_KEY_PACKCJKEY06, KEY03, wstrKey, wstrKeyValue)
        '    If wlntRet <> 0 Then
        '        'DBエラー
        '        gclsDB.fCloseRecord(KEY03)
        '        Exit Function
        '    End If

        '    '// STOCK更新
        '    'ゼロ件出庫でロケが?????の場合はストックの更新必要なし
        '    If intZeroFlg <> 3 Then wlntRet = fUpdateStock(KEY03, pstrKey2, intZeroFlg)

        '    '// ﾛｹｰｼｮﾝ更新
        '    'ゼロ件出庫はロケの更新必要なし
        '    If intZeroFlg <> 1 And intZeroFlg <> 3 Then wlntRet = fUpdateLocation(KEY03, pstrKey2, 1)

        '    gclsDB.fCloseRecord(KEY03)
        '    fUpdProc = 0
        '    Exit Function

        'Catch ex As Exception
        '    sErrLog(gAppName, "fUpdProc", ex.ToString)
        '    BtLib.Transaction.Abort()
        'End Try


    End Function

    '*******************************************************************************
    '* 機能     : 出庫ﾃﾞｰﾀ更新制御(大物出庫)
    '* 引数     : 1:PACKCP用キー 2:STOCK用キー 3:ログデータ 
    '*            4:0件出庫フラグ intZeroFlg:ゼロ出庫フラグ (0:通常出庫, 1:ゼロ個出庫, 2:19桁, 3:ゼロ出庫でロケが?????)
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fUpdProc2(ByVal pstrKey As String, ByVal pstrKey2 As String, ByRef pstrData As String, _
                              Optional ByVal intZeroFlg As Integer = 0) As Integer
        'Dim wlntRet As Integer

        'fUpdProc2 = -1
        'Try

        '    '// PACKCPの更新
        '    wlntRet = fUpdatePackCP(pstrKey, pstrKey2, intZeroFlg)

        '    If wlntRet <> 0 Then
        '        Exit Function
        '    End If

        '    ''// STOCK更新
        '    ''ゼロ件出庫でロケが?????の場合はストックの更新必要なし
        '    'If intZeroFlg <> 3 Then wlntRet = fUpdateStock(pstrKey, pstrKey2, intZeroFlg)

        '    ''// ﾛｹｰｼｮﾝ更新
        '    ''ゼロ件出庫はロケの更新必要なし
        '    'If (intZeroFlg <> 1 And intZeroFlg <> 3) Then wlntRet = fUpdateLocation(pstrKey, pstrKey2, 1)

        '    '// ログ作成用データ取得
        '    fGetGHData(pstrKey, pstrData)

        '    fUpdProc2 = 0

        'Catch ex As Exception
        '    sErrLog(gAppName, "fUpdProc2", ex.ToString)
        '    'BtLib.Transaction.Abort()
        'End Try

    End Function
    '*******************************************************************************
    '* 機能     : PACKCP更新制御(大物出庫)
    '* 引数     : 1.PACKCPキー 2.SOTCKキー
    '*            3:0件出庫フラグ intZeroFlg:ゼロ出庫フラグ (0:通常出庫, 1:ゼロ個出庫, 2:19桁, 3:ゼロ出庫でロケが?????)
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fUpdatePackCP(ByVal pstrKey As String, ByVal pstrKey2 As String, Optional ByVal intZeroOK As Integer = 0) As Integer
        'Dim wstrKey(2), wstrKeyValue(2) As String
        'Dim wstrNewSerial, wstrSeed As String

        'fUpdatePackCP = -1
        'With gclsDB.Records(pstrKey)
        '    wstrKey(0) = "ItemCode" : wstrKeyValue(0) = .Item("ItemCode")
        '    wstrKey(1) = "ItemInCode" : wstrKeyValue(1) = .Item("ItemInCode")
        '    wstrKey(2) = "PlanSerial" : wstrKeyValue(2) = .Item("PlanSerial")
        '    wstrSeed = .Item("TempSerial")
        'End With
        'Try
        '    BtLib.Transaction.BeginConCurrent()
        '    '// DB更新
        '    With gclsDB
        '        If intZeroOK = 0 Or intZeroOK = 2 Then
        '            .Setcolumn = "PickFlag,SerialNo,PackQtyJ,ScanDate,ScanTime,UserNo"
        '            .SetData = "3" & "," & gclsDB.Records(pstrKey2).Item("SerialNo") & "," & gclsDB.Records(pstrKey).Item("BunkatuJ") & "," & fgetDefaultDate() & "," & fgetDefaultTime() & "," & gstrctKDHT.strUserNo
        '        ElseIf (intZeroOK = 1 Or intZeroOK = 3) Then '0件出庫
        '            'PlanSerialを変更　SerialNoにもコピー
        '            If intZeroOK = 1 Then
        '                wstrNewSerial = fGetNewSerialNo(wstrSeed).PadLeft(6, "0")
        '                .Setcolumn = "PickFlag,SerialNo,PlanSerial,PackQtyJ,PairLctn,StockLctn,ScanDate,ScanTime,UserNo"
        '                .SetData = "3" & "," & wstrNewSerial & "," & wstrNewSerial & "," & "000000" & "," & "?????" & "," & "?????" & "," & fgetDefaultDate() & "," & fgetDefaultTime() & "," & gstrctKDHT.strUserNo
        '            Else
        '                'SerialNoにコピー
        '                .Setcolumn = "PickFlag,SerialNo,PackQtyJ,PairLctn,StockLctn,ScanDate,ScanTime,UserNo"
        '                .SetData = "3" & "," & wstrKeyValue(2) & "," & "000000" & "," & "?????" & "," & "?????" & "," & fgetDefaultDate() & "," & fgetDefaultTime() & "," & gstrctKDHT.strUserNo
        '            End If
        '        End If

        '        If .fUpdRecords(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY06, wstrKey, wstrKeyValue) = -1 Then
        '            BtLib.Transaction.Abort()
        '            sErrLog(gAppName, "fUpdatePackCP", gclsDB.ErrMsg)
        '            Exit Function
        '        End If

        '    End With
        '    BtLib.Transaction.End()

        '    fUpdatePackCP = 0
        'Catch ex As Exception
        '    sErrLog(gAppName, "fUpdatePackCP", ex.ToString)
        '    BtLib.Transaction.Abort()
        'End Try
    End Function

    Public Function fUpdatePackPlan()

        Dim rtn As Integer
        Dim wstrKeyCJ(6), wstrKeyValueCJ(6) As String
        Dim wstrKey(2), wstrKeyValue(2) As String
        Const KEY01 = "UPD_PKPLN"

        fUpdatePackPlan = -1

        Try

            wstrKeyCJ(0) = "ItemGr"
            wstrKeyCJ(1) = "ItemCode"
            wstrKeyCJ(2) = "SortLctn1"
            wstrKeyCJ(3) = "SortLctn2"
            wstrKeyCJ(4) = "SortLctn3"
            wstrKeyCJ(5) = "ItemInCode"
            wstrKeyCJ(6) = "TempSerial"
            With gstrctKDPP
                wstrKeyValueCJ(0) = RTrim(.strItemGr)
                wstrKeyValueCJ(1) = Space(30)
                wstrKeyValueCJ(2) = Space(5)
                wstrKeyValueCJ(3) = Space(5)
                wstrKeyValueCJ(4) = Space(5)
                wstrKeyValueCJ(5) = Space(30)
                wstrKeyValueCJ(6) = Space(6)
            End With


            rtn = fOpenPackCJ(G_CONST_KEY_PACKCJKEY03, KEY01, wstrKeyCJ, wstrKeyValueCJ)

            If rtn = 9 Then
                'gclsDB.fCloseRecord(KEY01)
                Exit Function
            ElseIf rtn <> 0 Then
                'gclsDB.fCloseRecord(KEY01)
                Exit Function
            End If

            If rtn = 0 Then

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

                If tmpStrCJ.Count > 0 Then

                    Do

                        values = tmpStr(i)

                        Dim result As String = Nothing

                        If values.TryGetValue("ItemGr", result) Then
                            sItemGr = RTrim(result)
                        End If

                        If wstrKeyValueCJ(0) = RTrim(sItemGr) Then

                            If fUpdatePackPlan2(KEY01) <> 0 Then
                                'gclsDB.fCloseRecord(KEY01)
                                Exit Function
                            End If

                        Else
                            Exit Do
                        End If


                        i = i + 1

                        If tmpStr.Count = i Then
                            Exit Do
                        End If

                    Loop

                End If


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

                If tmpStrCP.Count > 0 Then

                    Do

                        values = tmpStrCP(i)

                        Dim result As String = Nothing
                        If values.TryGetValue("ItemGr", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sItemGr = result
                        End If

                        If wstrKeyValueCJ(0) = RTrim(sItemGr) Then

                            If fUpdatePackPlan2(KEY01) <> 0 Then
                                'gclsDB.fCloseRecord(KEY01)
                                Exit Function
                            End If

                        Else
                            Exit Do
                        End If


                        i = i + 1

                        If tmpStr.Count = i Then
                            Exit Do
                        End If

                    Loop

                End If
            End If

            'gclsDB.fCloseRecord(KEY01)
            fUpdatePackPlan = 0
            Exit Function

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


                'With gclsDB.Records(KEY01)
                '    Do
                '        If wstrKeyValueCJ(0) = RTrim(.Item("ItemGr")) Then

                '            If fUpdatePackPlan2(KEY01) <> 0 Then
                '                gclsDB.fCloseRecord(KEY01)
                '                Exit Function
                '            End If

                '        Else
                '            Exit Do
                '        End If

                '        If gclsDB.Records(KEY01).Read(BtLib.Operation.GetNext) <> 0 Then
                '            Exit Do
                '        End If

                '    Loop
                'End With
        '    End If

        '    gclsDB.fCloseRecord(KEY01)
        '    fUpdatePackPlan = 0
        '    Exit Function

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

    End Function

    '*******************************************************************************
    '* 機能     : PACKPLAN更新制御
    '* 引数     : なし
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fUpdatePackPlan2(ByVal pstrKey As String) As Integer
        Dim wstrKeyPP(12), wstrValuePP(12) As String
        Dim wintRet As Integer
        Dim wstrWhere As String
        Const PKPLN01 = "PKPLN01"

        fUpdatePackPlan2 = -1
        Try

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sProductDate As String = ""
            Dim sShift As String = ""
            Dim sLine As String = ""
            Dim sItemCode As String = ""
            Dim sItemInID As String = ""
            Dim sItemInCode As String = ""
            Dim sScanDate As String = ""
            Dim sScanTime As String = ""
            Dim sStockLctn As String = ""
            Dim sSerialNo As String = ""
            Dim sItemID As String = ""

            If tmpStrCP.Count > 0 Then
                values = tmpStr(0)
                Dim result As String = Nothing
                If values.TryGetValue("ProductDate", result) Then
                    sProductDate = RTrim(result)
                End If
                If values.TryGetValue("Shift", result) Then
                    sShift = RTrim(result)
                End If
                If values.TryGetValue("Line", result) Then
                    sLine = RTrim(result)
                End If
                If values.TryGetValue("ItemCode", result) Then
                    sItemCode = RTrim(result)
                End If
                If values.TryGetValue("ItemInID", result) Then
                    sItemInID = RTrim(result)
                End If
                If values.TryGetValue("ItemInCode", result) Then
                    sItemInCode = RTrim(result)
                End If
                If values.TryGetValue("ScanDate", result) Then
                    sScanDate = RTrim(result)
                End If
                If values.TryGetValue("ScanTime", result) Then
                    sScanTime = RTrim(result)
                End If
                If values.TryGetValue("StockLctn", result) Then
                    sStockLctn = RTrim(result)
                End If
                If values.TryGetValue("SerialNo", result) Then
                    sSerialNo = RTrim(result)
                End If
                If values.TryGetValue("ItemID", result) Then
                    sItemID = RTrim(result)
                End If

                wstrKeyPP(0) = "PicsType" : wstrValuePP(0) = gstrctKDHT.strPackType
                wstrKeyPP(1) = "Cstmid" : wstrValuePP(1) = gstrctKDHT.strCstmid
                wstrKeyPP(2) = "CstmCode" : wstrValuePP(2) = gstrctKDHT.strCstmCode
                wstrKeyPP(3) = "CenterCode" : wstrValuePP(3) = gstrctKDPP.strCenterCode
                wstrKeyPP(4) = "Date" : wstrValuePP(4) = RTrim(sProductDate).PadRight(8, " ") & RTrim(sShift).PadRight(1, " ")
                wstrKeyPP(5) = "Line" : wstrValuePP(5) = RTrim(sLine)
                wstrKeyPP(6) = "Aic" : wstrValuePP(6) = gstrctPPDisp.strAic
                wstrKeyPP(7) = "CaseNo" : wstrValuePP(7) = gstrctPPDisp.strCaseNo
                '>>> DEL ST  2006.06.23  >>> 
                'wstrKeyPP(8) = "CartonNo" : wstrValuePP(8) = Mid(RTrim(sItemCode), 21, 5)
                '<<< DEL END 2006.06.23  <<<
                '>>> ADD ST 2006.06.23  >>>
                If RTrim(sItemID) = "C" Then  'SPM処理時
                    wstrKeyPP(8) = "CartonNo" : wstrValuePP(8) = Mid(RTrim(sItemCode), 21, 5)
                Else 'SUBSPM処理時
                    wstrKeyPP(8) = "CartonNo" : wstrValuePP(8) = "00000"
                End If
                '<<< ADD END 2006.06.23 <<<
                wstrKeyPP(9) = "ItemID" : wstrValuePP(9) = RTrim(sItemInID)
                wstrKeyPP(10) = "ItemCode" : wstrValuePP(10) = RTrim(sItemInCode)
                wstrKeyPP(11) = "SerialNo" : wstrValuePP(11) = Space(6)
                wstrKeyPP(12) = "TempSerial" : wstrValuePP(12) = Space(6)


            End If


            '// 更新ｷｰ設定
            'With gclsDB.Records(pstrKey)
            '    wstrKeyPP(0) = "PicsType" : wstrValuePP(0) = gstrctKDHT.strPackType
            '    wstrKeyPP(1) = "Cstmid" : wstrValuePP(1) = gstrctKDHT.strCstmid
            '    wstrKeyPP(2) = "CstmCode" : wstrValuePP(2) = gstrctKDHT.strCstmCode
            '    wstrKeyPP(3) = "CenterCode" : wstrValuePP(3) = gstrctKDPP.strCenterCode
            '    wstrKeyPP(4) = "Date" : wstrValuePP(4) = RTrim(.Item("ProductDate")).PadRight(8, " ") & RTrim(.Item("Shift")).PadRight(1, " ")
            '    wstrKeyPP(5) = "Line" : wstrValuePP(5) = RTrim(.Item("Line"))
            '    wstrKeyPP(6) = "Aic" : wstrValuePP(6) = gstrctPPDisp.strAic
            '    wstrKeyPP(7) = "CaseNo" : wstrValuePP(7) = gstrctPPDisp.strCaseNo
            '    '>>> DEL ST  2006.06.23  >>> 
            '    'wstrKeyPP(8) = "CartonNo" : wstrValuePP(8) = Mid(RTrim(.Item("ItemCode")), 21, 5)
            '    '<<< DEL END 2006.06.23  <<<
            '    '>>> ADD ST 2006.06.23  >>>
            '    If RTrim(.Item("ItemID")) = "C" Then  'SPM処理時
            '        wstrKeyPP(8) = "CartonNo" : wstrValuePP(8) = Mid(RTrim(.Item("ItemCode")), 21, 5)
            '    Else 'SUBSPM処理時
            '        wstrKeyPP(8) = "CartonNo" : wstrValuePP(8) = "00000"
            '    End If
            '    '<<< ADD END 2006.06.23 <<<
            '    wstrKeyPP(9) = "ItemID" : wstrValuePP(9) = RTrim(.Item("ItemInID"))
            '    wstrKeyPP(10) = "ItemCode" : wstrValuePP(10) = RTrim(.Item("ItemInCode"))
            '    wstrKeyPP(11) = "SerialNo" : wstrValuePP(11) = Space(6)
            '    wstrKeyPP(12) = "TempSerial" : wstrValuePP(12) = Space(6)

            'End With

            wstrWhere = ""
            wstrWhere = wstrKeyPP(0) & " = '" & wstrValuePP(0) & "'"
            wstrWhere &= " and " & wstrKeyPP(1) & " = '" & wstrValuePP(1) & "'"
            wstrWhere &= " and " & wstrKeyPP(2) & " = '" & wstrValuePP(2) & "'"
            wstrWhere &= " and " & wstrKeyPP(3) & " = '" & wstrValuePP(3) & "'"
            wstrWhere &= " and " & wstrKeyPP(4) & " = '" & wstrValuePP(4) & "'"
            wstrWhere &= " and " & wstrKeyPP(5) & " = '" & wstrValuePP(5) & "'"
            wstrWhere &= " and " & wstrKeyPP(6) & " = '" & wstrValuePP(6) & "'"
            wstrWhere &= " and " & wstrKeyPP(7) & " = '" & wstrValuePP(7) & "'"
            wstrWhere &= " and " & wstrKeyPP(8) & " = '" & wstrValuePP(8) & "'"
            wstrWhere &= " and " & wstrKeyPP(9) & " = '" & wstrValuePP(9) & "'"
            wstrWhere &= " and " & wstrKeyPP(10) & " = '" & wstrValuePP(10) & "'"
            wstrWhere &= " and " & wstrKeyPP(11) & " = '" & wstrValuePP(11) & "'"
            wstrWhere &= " and " & wstrKeyPP(12) & " = '" & wstrValuePP(12) & "'"

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

            values = New Dictionary(Of String, String)
            Dim sPicsType As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""
            Dim sCenterCode As String = ""
            Dim sDate As String = ""
            sLine = ""
            Dim sAic As String = ""
            Dim sCaseNo As String = ""
            Dim sCartonNo As String = ""
            sItemID = ""
            sItemCode = ""
            Dim sStatus As String = ""
            sSerialNo = ""
            Dim sTempSerial As String = ""

            Dim i As Integer = 0

            If tmpStr.Count > 0 Then

                values = tmpStr(0)

                Dim result As String = Nothing
                If values.TryGetValue("PicsType", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sPicsType = result
                End If
                If values.TryGetValue("Cstmid", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sCstmid = result
                End If
                If values.TryGetValue("CstmCode", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sCstmCode = result
                End If
                If values.TryGetValue("CenterCode", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sCenterCode = result
                End If
                If values.TryGetValue("Date", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sDate = result
                End If
                If values.TryGetValue("Line", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sLine = result
                End If

                If values.TryGetValue("Aic", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sAic = result
                End If
                If values.TryGetValue("CaseNo", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sCaseNo = result
                End If
                If values.TryGetValue("CartonNo", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sCartonNo = result
                End If
                If values.TryGetValue("ItemID", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sItemID = result
                End If
                If values.TryGetValue("ItemCode", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sItemCode = result
                End If

                If wstrValuePP(0) = RTrim(sPicsType) And wstrValuePP(1) = RTrim(sCstmid) And _
                    wstrValuePP(2) = RTrim(sCstmCode) And wstrValuePP(3) = RTrim(sCenterCode) And _
                    wstrValuePP(4) = RTrim(sDate) And wstrValuePP(5) = RTrim(sLine) And _
                    wstrValuePP(6) = RTrim(sAic) And wstrValuePP(7) = RTrim(sCaseNo) And _
                    wstrValuePP(8) = RTrim(sCartonNo) And wstrValuePP(9) = RTrim(sItemID) And _
                    wstrValuePP(10) = RTrim(sItemCode) Then

                    Do
                        values = tmpStr(i)

                        If values.TryGetValue("Status", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sStatus = result
                        End If
                        If values.TryGetValue("SerialNo", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sSerialNo = result
                        End If
                        If values.TryGetValue("TempSerial", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sTempSerial = result
                        End If

                        If RTrim(sStatus) < "30" Then '未出庫対象を更新
                            wstrValuePP(11) = RTrim(sSerialNo)
                            wstrValuePP(12) = RTrim(sTempSerial)

                            wstrWhere = ""
                            wstrWhere = wstrKeyPP(0) & " = '" & wstrValuePP(0) & "'"
                            wstrWhere &= " and " & wstrKeyPP(1) & " = '" & wstrValuePP(1) & "'"
                            wstrWhere &= " and " & wstrKeyPP(2) & " = '" & wstrValuePP(2) & "'"
                            wstrWhere &= " and " & wstrKeyPP(3) & " = '" & wstrValuePP(3) & "'"
                            wstrWhere &= " and " & wstrKeyPP(4) & " = '" & wstrValuePP(4) & "'"
                            wstrWhere &= " and " & wstrKeyPP(5) & " = '" & wstrValuePP(5) & "'"
                            wstrWhere &= " and " & wstrKeyPP(6) & " = '" & wstrValuePP(6) & "'"
                            wstrWhere &= " and " & wstrKeyPP(7) & " = '" & wstrValuePP(7) & "'"
                            wstrWhere &= " and " & wstrKeyPP(8) & " = '" & wstrValuePP(8) & "'"
                            wstrWhere &= " and " & wstrKeyPP(9) & " = '" & wstrValuePP(9) & "'"
                            wstrWhere &= " and " & wstrKeyPP(10) & " = '" & wstrValuePP(10) & "'"
                            wstrWhere &= " and " & wstrKeyPP(11) & " = '" & wstrValuePP(11) & "'"
                            wstrWhere &= " and " & wstrKeyPP(12) & " = '" & wstrValuePP(12) & "'"

                            affected_rows = dbClient.Execute("UPDATE " + G_CONST_TBL_PACKPLAN + " SET Status='" _
                                                         + "30" _
                                                         + "' , PickDate='" _
                                                         + sScanDate _
                                                         + "' , PickTime='" _
                                                         + sScanTime _
                                                         + "' , PickEmp='" _
                                                         + gstrctKDHT.strUserNo _
                                                         + "' , PickLctn1='" _
                                                         + sStockLctn _
                                                         + "' , SerialNo='" _
                                                         + sSerialNo _
                                                         + "' WHERE " + wstrWhere)


                            If affected_rows = 0 Then
                                sErrLog(gAppName, "fUpdatePackPlan2", "Error")
                            End If


                        End If

                        i = i + 1

                        If tmpStr.Count = i Then
                            Exit Do
                        End If
                    Loop

                End If

            End If

            fUpdatePackPlan2 = 0
            Exit Function
        Catch ex As Exception
            sErrLog(gAppName, "fUpDatePackPlan2", ex.ToString)
        End Try



        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, PKPLN01, wstrKeyPP, wstrValuePP, BtLib.Operation.GetGreaterOrEqual)
        'If wintRet <> 0 Then
        '    gclsDB.fCloseRecord(PKPLN01)
        'End If
        'With gclsDB.Records(PKPLN01)
        '    If wstrValuePP(0) = RTrim(.Item("PicsType")) And wstrValuePP(1) = RTrim(.Item("Cstmid")) And _
        '        wstrValuePP(2) = RTrim(.Item("CstmCode")) And wstrValuePP(3) = RTrim(.Item("CenterCode")) And _
        '        wstrValuePP(4) = RTrim(.Item("Date")) And wstrValuePP(5) = RTrim(.Item("Line")) And _
        '        wstrValuePP(6) = RTrim(.Item("Aic")) And wstrValuePP(7) = RTrim(.Item("CaseNo")) And _
        '        wstrValuePP(8) = RTrim(.Item("CartonNo")) And wstrValuePP(9) = RTrim(.Item("ItemID")) And _
        '        wstrValuePP(10) = RTrim(.Item("ItemCode")) Then
        '        Do
        '            If RTrim(.Item("Status")) < "30" Then '未出庫対象を更新
        '                wstrValuePP(11) = RTrim(.Item("SerialNo"))
        '                wstrValuePP(12) = RTrim(.Item("TempSerial"))
        '                '// DB更新
        '                With gclsDB
        '                    .Setcolumn = "Status,PickDate,PickTime,PickEmp,PickLctn1,SerialNo"
        '                    .SetData = "30," & .Records(pstrKey).Item("ScanDate") & "," & .Records(pstrKey).Item("ScanTime") & "," _
        '                      & gstrctKDHT.strUserNo & "," & .Records(pstrKey).Item("StockLctn") & "," & .Records(pstrKey).Item("SerialNo")

        '                    If .fUpdRecords(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, wstrKeyPP, wstrValuePP) = -1 Then
        '                        sErrLog(gAppName, "fUpdatePackPlan2", gclsDB.ErrMsg)
        '                        .fCloseRecord(PKPLN01)
        '                        Exit Function
        '                    End If
        '                    Exit Do
        '                End With
        '            End If
        '            If .Read(BtLib.Operation.GetNext) <> 0 Then
        '                'レコードがなくなれば終了する
        '                Exit Do
        '            End If
        '        Loop
        '    End If
        'End With
        'gclsDB.fCloseRecord(PKPLN01)
        'fUpdatePackPlan2 = 0
        'Exit Function
        'Catch ex As Exception
        '    sErrLog(gAppName, "fUpDatePackPlan2", ex.ToString)
        'End Try
    End Function

    'Public Function fUpdatePackPlan()

    '    Dim rtn As Integer
    '    Dim wstrKeyCJ(6), wstrKeyValueCJ(6) As String
    '    Dim wstrKey(2), wstrKeyValue(2) As String
    '    Const KEY01 = "UPD_PKPLN"

    '    fUpdatePackPlan = -1

    '    Try

    '        wstrKeyCJ(0) = "ItemGr"
    '        wstrKeyCJ(1) = "ItemCode"
    '        wstrKeyCJ(2) = "SortLctn1"
    '        wstrKeyCJ(3) = "SortLctn2"
    '        wstrKeyCJ(4) = "SortLctn3"
    '        wstrKeyCJ(5) = "ItemInCode"
    '        wstrKeyCJ(6) = "TempSerial"
    '        With gstrctKDPP
    '            wstrKeyValueCJ(0) = RTrim(.strItemGr)
    '            wstrKeyValueCJ(1) = Space(30)
    '            wstrKeyValueCJ(2) = Space(5)
    '            wstrKeyValueCJ(3) = Space(5)
    '            wstrKeyValueCJ(4) = Space(5)
    '            wstrKeyValueCJ(5) = Space(30)
    '            wstrKeyValueCJ(6) = Space(6)
    '        End With

    '        rtn = fOpenPackCJ(G_CONST_KEY_PACKCJKEY03, KEY01, wstrKeyCJ, wstrKeyValueCJ)

    '        If rtn = 9 Then
    '            gclsDB.fCloseRecord(KEY01)
    '            Exit Function
    '        ElseIf rtn <> 0 Then
    '            gclsDB.fCloseRecord(KEY01)
    '            rtn = -1
    '            Exit Function
    '        End If

    '        If rtn = 0 Then
    '            With gclsDB.Records(KEY01)
    '                'BtLib.Transaction.BeginConCurrent()
    '                Do
    '                    If wstrKeyValueCJ(0) = RTrim(.Item("ItemGr")) Then

    '                        If fUpdatePackPlan2(KEY01) <> 0 Then
    '                            'BtLib.Transaction.Abort()
    '                            gclsDB.fCloseRecord(KEY01)
    '                            rtn = -1
    '                            Exit Function
    '                        End If

    '                    Else
    '                        Exit Do
    '                    End If

    '                    If gclsDB.Records(KEY01).Read(BtLib.Operation.GetNext) <> 0 Then
    '                        Exit Do
    '                    End If

    '                Loop
    '                'BtLib.Transaction.End()
    '            End With
    '        End If

    '        gclsDB.fCloseRecord(KEY01)
    '        rtn = -1
    '        fUpdatePackPlan = 0
    '        Exit Function

    '    Catch ex As Exception
    '        If rtn <> -1 Then gclsDB.fCloseRecord(KEY01)
    '        sErrLog(gAppName, "fUpdatePackPlan", ex.ToString)
    '    End Try

    'End Function

    ''*******************************************************************************
    ''* 機能     : PACKPLAN更新2
    ''* 引数     : 無し
    ''* 戻り値   : 0:OK -1:ERROR
    ''* 備考     : なし
    ''*******************************************************************************
    'Public Function fUpdatePackPlan2(ByVal pstrKey As String) As Integer
    '    Dim wstrKeyPP(12), wstrValuePP(12) As String
    '    Dim wintRet As Integer = -1
    '    Const PKPLN01 = "PKPLN01"

    '    fUpdatePackPlan2 = -1
    '    Try
    '        '// 更新ｷｰ設定
    '        With gclsDB.Records(pstrKey)
    '            wstrKeyPP(0) = "PicsType" : wstrValuePP(0) = gstrctKDHT.strPackType
    '            wstrKeyPP(1) = "Cstmid" : wstrValuePP(1) = gstrctKDHT.strCstmid
    '            wstrKeyPP(2) = "CstmCode" : wstrValuePP(2) = gstrctKDHT.strCstmCode
    '            wstrKeyPP(3) = "CenterCode" : wstrValuePP(3) = gstrctKDPP.strCenterCode
    '            wstrKeyPP(4) = "Date" : wstrValuePP(4) = RTrim(.Item("ProductDate")).PadRight(8, " ") & RTrim(.Item("Shift")).PadRight(1, " ")
    '            wstrKeyPP(5) = "Line" : wstrValuePP(5) = RTrim(.Item("Line"))
    '            wstrKeyPP(6) = "Aic" : wstrValuePP(6) = gstrctPPDisp.strAic
    '            wstrKeyPP(7) = "CaseNo" : wstrValuePP(7) = gstrctPPDisp.strCaseNo
    '            If RTrim(.Item("ItemID")) = "C" Then  'SPM処理時
    '                wstrKeyPP(8) = "CartonNo" : wstrValuePP(8) = Mid(RTrim(.Item("ItemCode")), 21, 5)
    '            Else 'SUBSPM処理時
    '                wstrKeyPP(8) = "CartonNo" : wstrValuePP(8) = "00000"
    '            End If
    '            wstrKeyPP(9) = "ItemID" : wstrValuePP(9) = RTrim(.Item("ItemInID"))
    '            wstrKeyPP(10) = "ItemCode" : wstrValuePP(10) = RTrim(.Item("ItemInCode"))
    '            wstrKeyPP(11) = "SerialNo" : wstrValuePP(11) = Space(6)
    '            wstrKeyPP(12) = "TempSerial" : wstrValuePP(12) = Space(6)

    '        End With
    '        wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, PKPLN01, wstrKeyPP, wstrValuePP, BtLib.Operation.GetGreaterOrEqual)
    '        If wintRet = -1 Then
    '            Exit Function
    '        ElseIf wintRet = 0 Then
    '            'Do
    '            With gclsDB.Records(PKPLN01)
    '                If wstrValuePP(0) = RTrim(.Item("PicsType")) And wstrValuePP(1) = RTrim(.Item("Cstmid")) And _
    '                    wstrValuePP(2) = RTrim(.Item("CstmCode")) And wstrValuePP(3) = RTrim(.Item("CenterCode")) And _
    '                    wstrValuePP(4) = RTrim(.Item("Date")) And wstrValuePP(5) = RTrim(.Item("Line")) And _
    '                    wstrValuePP(6) = RTrim(.Item("Aic")) And wstrValuePP(7) = RTrim(.Item("CaseNo")) And _
    '                    wstrValuePP(8) = RTrim(.Item("CartonNo")) And wstrValuePP(9) = RTrim(.Item("ItemID")) And _
    '                    wstrValuePP(10) = RTrim(.Item("ItemCode")) Then
    '                    Do
    '                        If RTrim(.Item("Status")) < "30" Then '未出庫対象を更新
    '                            wstrValuePP(11) = RTrim(.Item("SerialNo"))
    '                            wstrValuePP(12) = RTrim(.Item("TempSerial"))
    '                            '// DB更新
    '                            With gclsDB
    '                                .Setcolumn = "Status,PickDate,PickTime,PickEmp,PickLctn1,SerialNo"
    '                                .SetData = "30," & .Records(pstrKey).Item("ScanDate") & "," & .Records(pstrKey).Item("ScanTime") & "," _
    '                                  & gstrctKDHT.strUserNo & "," & .Records(pstrKey).Item("StockLctn") & "," & .Records(pstrKey).Item("SerialNo")

    '                                If .fUpdRecords(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, wstrKeyPP, wstrValuePP) = -1 Then
    '                                    fUpdatePackPlan2 = -1
    '                                    sErrLog(gAppName, "fUpdatePackPlan2", gclsDB.ErrMsg)
    '                                    .fCloseRecord(PKPLN01)
    '                                    wintRet = -1
    '                                    Exit Function
    '                                End If
    '                                fUpdatePackPlan2 = 0
    '                                Exit Do
    '                            End With
    '                        End If
    '                        If .Read(BtLib.Operation.GetNext) <> 0 Then
    '                            'レコードがなくなれば終了する
    '                            Exit Do
    '                        End If
    '                    Loop
    '                End If
    '            End With
    '            'Loop
    '        End If
    '    Catch ex As Exception
    '        If wintRet <> -1 Then gclsDB.fCloseRecord(PKPLN01)
    '        sErrLog(gAppName, "fUpDatePackPlan2", ex.ToString)
    '    Finally
    '        If wintRet <> -1 Then gclsDB.fCloseRecord(PKPLN01)
    '    End Try
    'End Function

    '/*
    '|| 関数名：fSortPKCP
    '|| 概要  ：
    '*/
    Public Function fSortPKCP(ByVal pstrInput As String)

        Dim rtn As Integer
        Dim wstrKey(6) As String
        Dim wstrKeyValue(6) As String
        Dim wstrLctn1 As String = ""
        Dim wstrLctn2 As String = ""
        Dim wstrLctn3 As String = ""
        Dim wstrWhere As String

        fSortPKCP = -1

        Try

            '// ﾄﾗﾝｻﾞｸｼｮﾝ開始
            'BtLib.Transaction.BeginConCurrent()

            wstrKey(0) = "ItemGr"
            wstrKey(1) = "ItemCode"
            wstrKey(2) = "SortLctn1"
            wstrKey(3) = "SortLctn2"
            wstrKey(4) = "SortLctn3"
            wstrKey(5) = "ItemInCode"
            wstrKey(6) = "TempSerial"
            wstrKeyValue(0) = gstrctKDPP.strItemGr
            wstrKeyValue(1) = Space(30)
            wstrKeyValue(2) = Space(5)
            wstrKeyValue(3) = Space(5)
            wstrKeyValue(4) = Space(5)
            wstrKeyValue(5) = Space(30)
            wstrKeyValue(6) = 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) & "'"

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemGr As String = ""
            Dim sItemCode As String = ""
            Dim sSortLctn1 As String = ""
            Dim sSortLctn2 As String = ""
            Dim sSortLctn3 As String = ""
            Dim sItemInCode As String = ""
            Dim sTempSerial As String = ""
            Dim sStockLctn As String = ""
            Dim sPairLctn As String = ""

            Dim i As Integer = 0

            If tmpStr.Count > 0 Then

                Do

                    values = tmpStr(i)

                    Dim result As String = Nothing
                    If values.TryGetValue("ItemGr", result) Then
                        sItemGr = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("SortLctn1", result) Then
                        sSortLctn1 = RTrim(result)
                    End If
                    If values.TryGetValue("SortLctn2", result) Then
                        sSortLctn2 = RTrim(result)
                    End If
                    If values.TryGetValue("SortLctn3", result) Then
                        sSortLctn3 = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If
                    If values.TryGetValue("TempSerial", result) Then
                        sTempSerial = RTrim(result)
                    End If
                    If values.TryGetValue("StockLctn", result) Then
                        sStockLctn = RTrim(result)
                    End If
                    If values.TryGetValue("PairLctn", result) Then
                        sPairLctn = RTrim(result)
                    End If


                    If wstrKeyValue(0) = RTrim(sItemGr) Then

                        wstrKeyValue(1) = RTrim(sItemCode)
                        wstrKeyValue(2) = RTrim(sSortLctn1)
                        wstrKeyValue(3) = RTrim(sSortLctn2)
                        wstrKeyValue(4) = RTrim(sSortLctn3)
                        wstrKeyValue(5) = RTrim(sItemInCode)
                        wstrKeyValue(6) = RTrim(sTempSerial)

                        Select Case pstrInput

                            Case G_CONST_SORT_ASCEND
                                wstrLctn1 = RTrim(sStockLctn)
                                wstrLctn2 = Space(5)
                                wstrLctn3 = Space(6)
                            Case G_CONST_SORT_DESCEND
                                wstrLctn1 = RTrim(Mid(sPairLctn, 1, 2))
                                wstrLctn2 = RTrim(sStockLctn)
                                wstrLctn3 = Space(6)
                            Case G_CONST_SORT_PASCEND
                                wstrLctn1 = RTrim(sPairLctn)
                                wstrLctn2 = RTrim(sStockLctn)
                                wstrLctn3 = Space(6)
                            Case G_CONST_SORT_PDESCEND
                                wstrLctn1 = RTrim(Mid(sPairLctn, 1, 2))
                                wstrLctn2 = RTrim(sPairLctn)
                                wstrLctn3 = sStockLctn
                        End Select

                        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) & "'"

                        affected_rows = dbClient.Execute("UPDATE " + G_CONST_TBL_PACKCP + " SET SortLctn1='" _
                                                                 + wstrLctn1 _
                                                                 + "' , SortLctn2='" _
                                                                 + wstrLctn2 _
                                                                 + "' , SortLctn3='" _
                                                                 + wstrLctn3 _
                                                                 + "' WHERE " + wstrWhere)


                        If affected_rows = 0 Then
                            Exit Function
                        End If


                    Else
                        Exit Do
                    End If



                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If

                Loop


            Else

                Exit Function


            End If


            fSortPKCP = 0
            Exit Function

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



        'rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY03, "PKCP01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'If rtn = 9 Then
        '    fSortPKCP = -2
        '    gclsDB.fCloseRecord("PKCP01")
        '    BtLib.Transaction.Abort()
        '    Exit Function
        'ElseIf rtn <> 0 Then
        '    gclsDB.fCloseRecord("PKCP01")
        '    BtLib.Transaction.Abort()
        '    Exit Function
        'End If

        'If rtn = 0 Then
        '    Do
        '        With gclsDB.Records("PKCP01")
        '            If wstrKeyValue(0) = RTrim(.Item("ItemGr")) Then

        '                wstrKeyValue(1) = RTrim(.Item("ItemCode"))
        '                wstrKeyValue(2) = RTrim(.Item("SortLctn1"))
        '                wstrKeyValue(3) = RTrim(.Item("SortLctn2"))
        '                wstrKeyValue(4) = RTrim(.Item("SortLctn3"))
        '                wstrKeyValue(5) = RTrim(.Item("ItemInCode"))
        '                wstrKeyValue(6) = RTrim(.Item("TempSerial"))

        '                Select Case pstrInput

        '                    Case G_CONST_SORT_ASCEND
        '                        wstrLctn1 = RTrim(.Item("StockLctn"))
        '                        wstrLctn2 = Space(5)
        '                        wstrLctn3 = Space(6)
        '                    Case G_CONST_SORT_DESCEND
        '                        wstrLctn1 = RTrim(Mid(.Item("PairLctn"), 1, 2))
        '                        wstrLctn2 = RTrim(.Item("StockLctn"))
        '                        wstrLctn3 = Space(6)
        '                    Case G_CONST_SORT_PASCEND
        '                        wstrLctn1 = RTrim(.Item("PairLctn"))
        '                        wstrLctn2 = RTrim(.Item("StockLctn"))
        '                        wstrLctn3 = Space(6)
        '                    Case G_CONST_SORT_PDESCEND
        '                        wstrLctn1 = RTrim(Mid(.Item("PairLctn"), 1, 2))
        '                        wstrLctn2 = RTrim(.Item("PairLctn"))
        '                        wstrLctn3 = .Item("StockLctn")
        '                End Select

        '                '// DB更新
        '                With gclsDB
        '                    .Setcolumn = "SortLctn1,SortLctn2,SortLctn3"
        '                    .SetData = wstrLctn1 & "," & wstrLctn2 & "," & wstrLctn3

        '                    If .fUpdRecords(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY03, wstrKey, wstrKeyValue) = -1 Then
        '                        gclsDB.fCloseRecord("PKCP01")
        '                        BtLib.Transaction.Abort()
        '                        Exit Function
        '                    End If
        '                End With

        '            Else
        '                Exit Do
        '            End If

        '        End With

        '        '次レコードを取得する
        '        If gclsDB.Records("PKCP01").Read(BtLib.Operation.GetNext) <> 0 Then
        '            'レコードがなくなれば終了する
        '            Exit Do
        '        End If
        '    Loop
        'End If

        'gclsDB.fCloseRecord("PKCP01")

        'BtLib.Transaction.End()

        'fSortPKCP = 0
        'Exit Function

        'Catch ex As Exception
        '    BtLib.Transaction.Abort()
        '    sErrLog(gAppName, "fSortPKCP", ex.ToString)
        'End Try

    End Function

    '*******************************************************************************
    '* 機能     : PACKCP取得処理(大物出庫専用)
    '* 引数     : 検索方向(G_CONST_DIR_GOFORWARD, G_CONST_DIR_GOBACKWARD)
    '* 戻り値   : -1:NG　-2:0件  0:1件以上
    '* 備考     : PicsFlagが3以外の未処理のみ対象
    '*******************************************************************************
    Public Function fSrchPackCP4Ohmono(Optional ByVal pintDirection As Integer = 0) As Integer
        'Dim rtn As Integer
        'Dim wintCnt As Integer
        'Dim wstrKey(6) As String
        'Dim wstrKeyValue(6) As String
        'Dim wstrLctnItemCode As String
        'Dim wstrItemInCodeDisp As String
        'Dim wstrWork As String
        'Dim wstrPrevCrtnNo As String
        'Dim bFound As Boolean

        'fSrchPackCP4Ohmono = -1

        'wstrPrevCrtnNo = gstrctPPDisp.strCrtnNo

        'wstrKey(0) = "ItemGr"
        'wstrKey(1) = "ItemCode"
        'wstrKey(2) = "SortLctn1"
        'wstrKey(3) = "SortLctn2"
        'wstrKey(4) = "SortLctn3"
        'wstrKey(5) = "ItemInCode"
        'wstrKey(6) = "TempSerial"

        'bFound = False
        'Try
        '    'ItemGrとItemCodeでサーチ
        '    Do Until bFound
        '        With gstrctKDPP
        '            wstrKeyValue(0) = .strItemGr
        '            wstrKeyValue(1) = Mid(.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
        '            wstrKeyValue(2) = Space(5)
        '            wstrKeyValue(3) = Space(5)
        '            wstrKeyValue(4) = Space(5)
        '            wstrKeyValue(5) = Space(30)
        '            wstrKeyValue(6) = Space(6)
        '        End With

        '        rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY03, "PKCP01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        '        If rtn = 9 Then
        '            gclsDB.fCloseRecord("PKCP01")
        '            Exit Do
        '        ElseIf rtn <> 0 Then
        '            fSrchPackCP4Ohmono = -1
        '            gclsDB.fCloseRecord("PKCP01")
        '            Exit Function
        '        ElseIf rtn = 0 Then
        '            wintCnt = 0
        '            With gclsDB.Records("PKCP01")
        '                Do Until bFound
        '                    If wstrKeyValue(0) = RTrim(.Item("ItemGr")) And wstrKeyValue(1) = RTrim(.Item("ItemCode")) Then
        '                        '未処理部品のみ検索
        '                        If RTrim(.Item("PickFlag")) = "1" Or RTrim(.Item("PickFlag")) = "0" Then
        '                            If wintCnt = gstrctKDPP.intIndex Then
        '                                With gstrctPPDisp
        '                                    .strItemCode = RTrim(gclsDB.Records("PKCP01").Item("ItemCode"))
        '                                    .strCrtnNo = Mid(RTrim(gclsDB.Records("PKCP01").Item("ItemCode")), 21, 5)
        '                                End With
        '                                With gstrctPPDispPart
        '                                    wstrWork = gclsDB.Records("PKCP01").Item("StockLctn")
        '                                    wstrLctnItemCode = wstrWork.PadRight(5, " ")
        '                                    .strLocation = RTrim(gclsDB.Records("PKCP01").Item("StockLctn"))
        '                                    .strLocation1 = RTrim(Mid(gclsDB.Records("PKCP01").Item("StockLctn"), 1, 2))
        '                                    .strLocation2 = RTrim(Mid(gclsDB.Records("PKCP01").Item("StockLctn"), 3))
        '                                    .strID = RTrim(gclsDB.Records("PKCP01").Item("ItemID"))
        '                                    .strItemCode = RTrim(gclsDB.Records("PKCP01").Item("ItemCode"))
        '                                    .strItemInID = RTrim(gclsDB.Records("PKCP01").Item("ItemInID"))
        '                                    .strItemInCode = RTrim(gclsDB.Records("PKCP01").Item("ItemInCode"))
        '                                    wstrLctnItemCode &= .strItemInCode

        '                                    '表示用部品番号の編集
        '                                    wstrItemInCodeDisp = RTrim(gclsDB.Records("PKCP01").Item("ItemInCodeDisp"))
        '                                    .strPartNoDisp = Mid(wstrItemInCodeDisp, 1, 12)

        '                                    .strCL = RTrim(Mid(gclsDB.Records("PKCP01").Item("ItemInCode"), 11, 2))
        '                                    .strZ = RTrim(Mid(gclsDB.Records("PKCP01").Item("ItemInCode"), 13, 1))
        '                                    .strSerial = RTrim(gclsDB.Records("PKCP01").Item("PlanSerial"))
        '                                    .strPackQty = RTrim(gclsDB.Records("PKCP01").Item("BunkatuJ"))
        '                                    bFound = True
        '                                End With
        '                            End If
        '                            wintCnt += 1
        '                        End If

        '                    Else
        '                        Exit Do
        '                    End If

        '                    If .Read(BtLib.Operation.GetNext) <> 0 Then
        '                        'レコードがなくなれば終了する
        '                        Exit Do
        '                    End If
        '                Loop
        '            End With
        '        End If
        '        gclsDB.fCloseRecord("PKCP01")

        '        If Not bFound Then
        '            'If FORWARD Then
        '            If pintDirection = G_CONST_DIR_GOFORWARD And (gstrctPPDisp.strCrtnNo < Mid(gstrctKDPP.strItemGr, 26, 5)) Then
        '                gstrctPPDisp.strCrtnNo = CStr(CInt(gstrctPPDisp.strCrtnNo) + 1).PadLeft(5, "0")
        '                gstrctKDPP.intIndex = 0
        '            ElseIf pintDirection = G_CONST_DIR_GOBACKWARD And (gstrctPPDisp.strCrtnNo > Mid(gstrctKDPP.strItemGr, 21, 5)) Then
        '                gstrctPPDisp.strCrtnNo = CStr(CInt(gstrctPPDisp.strCrtnNo) - 1).PadLeft(5, "0")
        '                gstrctKDPP.intIndex = 0
        '            Else
        '                Exit Do
        '            End If
        '        Else
        '            Exit Do
        '        End If
        '    Loop

        '    If bFound Then
        '        If gstrctPPDisp.strCrtnNo <> wstrPrevCrtnNo Then
        '            gstrctPPDispPart.bNextCarton = True
        '        End If
        '        fSrchPackCP4Ohmono = 0
        '        Exit Function
        '    End If

        '    'ItemGrで再チェック
        '    With gstrctKDPP
        '        wstrKeyValue(0) = .strItemGr
        '        If pintDirection = 2 Then
        '            wstrKeyValue(1) = Mid(.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
        '        Else
        '            wstrKeyValue(1) = Space(30)
        '        End If
        '        wstrKeyValue(2) = Space(5)
        '        wstrKeyValue(3) = Space(5)
        '        wstrKeyValue(4) = Space(5)
        '        wstrKeyValue(5) = Space(30)
        '        wstrKeyValue(6) = Space(6)
        '    End With

        '    gstrctKDPP.intIndex = 0
        '    rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY03, "PKCP01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        '    If rtn = 9 Then
        '        gclsDB.fCloseRecord("PKCP01")
        '        fSrchPackCP4Ohmono = -2
        '        Exit Function
        '    ElseIf rtn <> 0 Then
        '        fSrchPackCP4Ohmono = -1
        '        gclsDB.fCloseRecord("PKCP01")
        '        Exit Function
        '    ElseIf rtn = 0 Then
        '        With gclsDB.Records("PKCP01")
        '            Do Until bFound
        '                If (pintDirection <> 2 And wstrKeyValue(0) = RTrim(.Item("ItemGr"))) Or _
        '                      (wstrKeyValue(0) = RTrim(.Item("ItemGr")) And wstrKeyValue(1) = RTrim(.Item("ItemCode"))) Then
        '                    If .Item("PickFlag") = "1" Or .Item("PickFlag") = "0" Then
        '                        With gstrctPPDisp
        '                            .strItemCode = RTrim(gclsDB.Records("PKCP01").Item("ItemCode"))
        '                            .strCrtnNo = Mid(RTrim(gclsDB.Records("PKCP01").Item("ItemCode")), 21, 5)
        '                        End With
        '                        With gstrctPPDispPart
        '                            wstrWork = gclsDB.Records("PKCP01").Item("StockLctn")
        '                            wstrLctnItemCode = wstrWork.PadRight(5, " ")
        '                            .strLocation = RTrim(gclsDB.Records("PKCP01").Item("StockLctn"))
        '                            .strLocation1 = RTrim(Mid(gclsDB.Records("PKCP01").Item("StockLctn"), 1, 2))
        '                            .strLocation2 = RTrim(Mid(gclsDB.Records("PKCP01").Item("StockLctn"), 3))
        '                            .strID = RTrim(gclsDB.Records("PKCP01").Item("ItemID"))
        '                            .strItemCode = RTrim(gclsDB.Records("PKCP01").Item("ItemCode"))
        '                            .strItemInID = RTrim(gclsDB.Records("PKCP01").Item("ItemInID"))
        '                            .strItemInCode = RTrim(gclsDB.Records("PKCP01").Item("ItemInCode"))
        '                            wstrLctnItemCode &= .strItemInCode

        '                            '表示用部品番号の編集
        '                            wstrItemInCodeDisp = RTrim(gclsDB.Records("PKCP01").Item("ItemInCodeDisp"))
        '                            .strPartNoDisp = Mid(wstrItemInCodeDisp, 1, 12)

        '                            .strCL = RTrim(Mid(gclsDB.Records("PKCP01").Item("ItemInCode"), 11, 2))
        '                            .strZ = RTrim(Mid(gclsDB.Records("PKCP01").Item("ItemInCode"), 13, 1))
        '                            .strSerial = RTrim(gclsDB.Records("PKCP01").Item("PlanSerial"))
        '                            .strPackQty = RTrim(gclsDB.Records("PKCP01").Item("BunkatuJ"))
        '                        End With
        '                        bFound = True
        '                    End If
        '                Else
        '                    Exit Do
        '                End If

        '                If .Read(BtLib.Operation.GetNext) <> 0 Then
        '                    'レコードがなくなれば終了する
        '                    Exit Do
        '                End If
        '            Loop
        '        End With
        '    End If

        '    gclsDB.fCloseRecord("PKCP01")
        '    If bFound Then
        '        If gstrctPPDisp.strCrtnNo <> wstrPrevCrtnNo Then
        '            gstrctPPDispPart.bNextCarton = True
        '        End If
        '        fSrchPackCP4Ohmono = 0
        '    Else
        '        fSrchPackCP4Ohmono = -2
        '    End If

        '    Exit Function

        'Catch ex As Exception
        '    sErrLog(gAppName, "fSrchPackCP4ohMono", ex.ToString)
        'End Try
    End Function
    '*******************************************************************************
    '* 機能     : 現品票ログデータ取得処理(大物出庫専用)
    '* 引数     : 取得用PACKCPキー
    '* 戻り値   : -1:NG　0:OK
    '* 備考     : 
    '*******************************************************************************
    Public Function fGetGHData(ByVal pstrKey As String, ByRef pstrData As String) As Integer
        'Dim wstrKey(2), wstrKeyValue(2) As String

        'fGetGHData = -1

        'Try
        '    With gclsDB.Records(pstrKey)
        '        pstrData = CStr(.Item("HandyNo")).PadRight(8, " ") & CStr(.Item("PicsType")).PadRight(2, " ") & CStr(.Item("Cstmid")).PadRight(1, " ") & CStr(.Item("CstmCode")).PadRight(8, " ") & CStr(.Item("TrSectionId")).PadRight(1, " ") & CStr(.Item("TrSection")).PadRight(8, " ") & CStr(.Item("PickFlag")).PadRight(1, " ")
        '        pstrData += CStr(.Item("WKSumDate")).PadRight(8, " ") & CStr(.Item("ProductDate")).PadRight(8, " ") & CStr(.Item("Shift")).PadRight(1, " ") & CStr(.Item("Line")).PadRight(2, " ") & CStr(.Item("PackNo")).PadRight(6, " ") & CStr(.Item("ItemID")).PadRight(1, " ") & CStr(.Item("ItemGr")).PadRight(30, " ") & CStr(.Item("ItemCode")).PadRight(30, " ")
        '        pstrData += CStr(.Item("ItemMCode")).PadRight(10, " ") & CStr(.Item("ItemCodeDisp")).PadRight(30, " ") & CStr(.Item("ItemInID")).PadRight(1, " ") & CStr(.Item("ItemInCode")).PadRight(30, " ") & CStr(.Item("ItemInCodeDisp")).PadRight(30, " ")
        '        pstrData += CStr(.Item("PackQtyP")).PadRight(5, " ") & CStr(.Item("PackQtyJ")).PadRight(5, " ") & CStr(.Item("CaseQty")).PadRight(5, " ") & CStr(.Item("CenterCode")).PadRight(5, " ") & CStr(.Item("Bhk")).PadRight(3, " ") & CStr(.Item("SortLctn1")).PadRight(5, " ") & CStr(.Item("SortLctn2")).PadRight(5, " ") & CStr(.Item("SortLctn3")).PadRight(5, " ")
        '        pstrData += CStr(.Item("DisplayLctn")).PadRight(5, " ") & CStr(.Item("PairLctn")).PadRight(5, " ") & CStr(.Item("StockLctn")).PadRight(5, " ") & CStr(.Item("PlanSerial")).PadRight(6, " ") & CStr(.Item("SerialNo")).PadRight(6, " ") & CStr(.Item("TempSerial")).PadRight(6, " ")
        '        pstrData += CStr(.Item("ScanDate")).PadRight(8, " ") & CStr(.Item("ScanTime")).PadRight(6, " ") & CStr(.Item("UserNo")).PadRight(6, " ") & CStr(.Item("StartDate")).PadRight(8, " ") & CStr(.Item("StartTime")).PadRight(6, " ") & CStr(.Item("EndDate")).PadRight(8, " ") & CStr(.Item("EndTime")).PadRight(6, " ")
        '        pstrData += CStr(.Item("PartID")).PadRight(2, " ") & CStr(.Item("HosoYou")).PadRight(2, " ") & CStr(.Item("HosoTan")).PadRight(5, " ") & CStr(.Item("HosoZai")).PadRight(3, " ") & CStr(.Item("Inz")).PadRight(5, " ") & CStr(.Item("SetDaisu")).PadRight(3, " ")
        '        pstrData += CStr(.Item("PalLctn")).PadRight(7, " ") & CStr(.Item("OffDate")).PadRight(4, " ") & CStr(.Item("OffTime")).PadRight(4, " ") & CStr(.Item("S6030")).PadRight(5, " ") & CStr(.Item("PartName")).PadRight(30, " ") & CStr(.Item("BunkatuJ")).PadRight(5, " ") & Space(102)
        '    End With

        '    fGetGHData = 0

        'Catch ex As Exception
        '    sErrLog(gAppName, "fGetGHData", ex.ToString)
        'End Try
    End Function
    '*******************************************************************************
    '* 機能     : PACKCPデリバリー判定処理
    '* 引数     : 取得用PACKCPキー
    '* 戻り値   : -1:NG　0:OK
    '* 備考     : 
    '*******************************************************************************
    Public Function fCheckDelivery(Optional ByVal pintCheck As Integer = 0) As Integer
        Dim wstrKey(6), wstrKeyValue(6) As String
        Dim wstrKey2(6), wstrKeyValue2(6) As String
        Dim wstrKBN As String
        Dim wintRet As Integer = -1
        Dim wstrWhere As String
        fCheckDelivery = -1
        wstrKey(0) = "ItemGr"
        wstrKey(1) = "ItemCode"
        wstrKey(2) = "SortLctn1"
        wstrKey(3) = "SortLctn2"
        wstrKey(4) = "SortLctn3"
        wstrKey(5) = "ItemInCode"
        wstrKey(6) = "TempSerial"
        With gstrctKDPP
            wstrKeyValue(0) = .strItemGr
            wstrKeyValue(1) = Mid(.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
            wstrKeyValue(2) = Space(5)
            wstrKeyValue(3) = Space(5)
            wstrKeyValue(4) = Space(5)
            wstrKeyValue(5) = Space(30)
            wstrKeyValue(6) = Space(6)
        End With
        Try

            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) & "'"

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemGr As String = ""
            Dim sItemCode As String = ""
            Dim sItemInID As String = ""
            Dim sItemInCode As String = ""
            Dim i As Integer = 0

            If tmpStr.Count > 0 Then

                Do
                    values = tmpStr(i)

                    Dim result As String = Nothing
                    If values.TryGetValue("ItemGr", result) Then
                        sItemGr = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInID", result) Then
                        sItemInID = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If


                    If RTrim(sItemGr) = wstrKeyValue(0) AndAlso RTrim(sItemCode) = wstrKeyValue(1) Then
                        If RTrim(sItemInID) = "D" Then
                            fCheckDelivery = 1
                            Exit Function
                        Else
                            If pintCheck = 1 Then
                                If fSearchPartM(gstrctKDPP.strBhk, RTrim(sItemInCode), wstrKBN) <> 1 Then Exit Function
                                If wstrKBN = "D" Then
                                    fCheckDelivery = 1
                                    Exit Function
                                End If
                            End If
                        End If
                    Else
                        fCheckDelivery = 0
                        Exit Function
                    End If



                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If


                Loop

            Else

                Exit Function

            End If

        Catch ex As Exception
            fCheckDelivery = -1
            sErrLog(gAppName, "fCheckDelivery", ex.ToString)
        Finally
            'If wintRet <> -1 Then gclsDB.fCloseRecord("PKCP01")
        End Try




        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY03, "PKCP01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'Select Case wintRet
        '    Case 0
        '        fCheckDelivery = 0
        '        Do
        '            With gclsDB.Records("PKCP01")
        '                If RTrim(.Item("ItemGr")) = wstrKeyValue(0) AndAlso RTrim(.Item("ItemCode")) = wstrKeyValue(1) Then
        '                    If RTrim(.Item("ItemInID")) = "D" Then
        '                        fCheckDelivery = 1
        '                        Exit Function
        '                    Else
        '                        If pintCheck = 1 Then
        '                            If fSearchPartM(gstrctKDPP.strBhk, RTrim(.Item("ItemInCode")), wstrKBN) <> 1 Then Exit Function
        '                            If wstrKBN = "D" Then
        '                                fCheckDelivery = 1
        '                                Exit Function
        '                            End If
        '                        End If
        '                    End If
        '                Else
        '                    fCheckDelivery = 0
        '                    Exit Function
        '                End If
        '                If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Function
        '            End With
        '        Loop
        '    Case 9
        '        fCheckDelivery = 0
        '    Case Else
        '        Exit Function
        'End Select
        'Catch ex As Exception
        '    fCheckDelivery = -1
        '    sErrLog(gAppName, "fCheckDelivery", ex.ToString)
        'Finally
        '    If wintRet <> -1 Then gclsDB.fCloseRecord("PKCP01")
        'End Try
    End Function

    '*******************************************************************************
    '* 機能     : PACKCPデリバリー判定処理(STOCK P用の更新)
    '* 引数     : 取得用PACKCPキー
    '* 戻り値   : -1:NG　0:OK
    '* 備考     : 
    '*******************************************************************************
    Public Function fUpdateStock2(ByVal pstrKey As String, ByVal pstrKey2 As String) As Integer


    End Function
End Module
