Module modPublic027
    Private mintLabelCount As Integer
    Private Structure M_STRUCT_KEY
        Dim PicsType As String
        Dim Cstmid As String
        Dim CstmCode As String
        Dim CenterCode As String
        Dim Bhk As String
        Dim ItemID As String
        Dim ItemCode As String
    End Structure
    Private mstructKey As M_STRUCT_KEY      '検索Key構造体
    '*******************************************************************************
    '* 機能     : PACKCP NOTPACK処理（デリバリー対応）
    '* 引数     : 
    '*          : 
    '* 戻り値   : -1:NG　-2:0件  0:1件以上 1:区分"D"
    '* 備考     : なし
    '*******************************************************************************
    Public Function fNotPackForDelv(ByVal pstrKey) As Integer
        Dim wstrKey(2), wstrKeyValue(2) As String
        Dim wstrKey2(7), wstrKeyValue2(7) As String
        Dim wintRet As Integer = -1
        fNotPackForDelv = -1

        wstrKey(0) = "ItemCode"
        wstrKey(1) = "ItemInCode"
        wstrKey(2) = "TempSerial"
        Try

            Dim values1 As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemInID As String = ""
            Dim sItemCode As String = ""
            Dim sItemInCode As String = ""
            Dim sTempSerial As String = ""

            Dim sPicsType As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""
            Dim sCenterCode As String = ""
            Dim sBhk As String = ""
            Dim sPickFlag As String = ""
            Dim sSerialNo As String = ""
            Dim sZaikoStatus As String = ""

            Dim sSQL As String = ""


            If tmpStr_PKCP1.Count > 0 Then

                values1 = tmpStr_PKCP1(0)
                Dim result As String = Nothing
                If values1.TryGetValue("ItemInID", result) Then
                    sItemInID = RTrim(result)
                End If
                If values1.TryGetValue("ItemCode", result) Then
                    sItemCode = RTrim(result)
                End If
                If values1.TryGetValue("ItemInCode", result) Then
                    sItemInCode = RTrim(result)
                End If
                If values1.TryGetValue("TempSerial", result) Then
                    sTempSerial = RTrim(result)
                End If

                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("sCenterCode", result) Then
                    sCenterCode = RTrim(result)
                End If
                If values1.TryGetValue("sBhk", result) Then
                    sBhk = RTrim(result)
                End If
                If values1.TryGetValue("PickFlag", result) Then
                    sPickFlag = RTrim(result)
                End If
                If values1.TryGetValue("SerialNo", result) Then
                    sSerialNo = RTrim(result)
                End If
                If values1.TryGetValue("sZaikoStatus", result) Then
                    sZaikoStatus = RTrim(result)
                End If

                If RTrim(sItemInIDs) = "P" Then
                    wstrKeyValue(0) = RTrim(sItemCodes)
                    wstrKeyValue(1) = RTrim(sItemInCodes)
                    wstrKeyValue(2) = RTrim(sTempSerials)
                    '// PACKCPレコードのステータスを保管部品なしに
                    'With gclsDB

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



                    '.Setcolumn = "PickFlag,PairLctn,StockLctn,PlanSerial"
                    If IsNumeric(Mid(wstrKeyValue(2), 1, 1)) Then
                        '.SetData = G_CONST_ST_PKCP_NOSTOCK & ",?????,?????" & "," & fGetNewSerialNo(sTempSerials).PadLeft(6, "0")

                        sSQL = "UPDATE " + G_CONST_TBL_PACKCP + " SET PickFlag='" _
                                                             + pstrLock _
                                                             + "' , PairLctn='" _
                                                             + "?????" _
                                                             + "' , StockLctn='" _
                                                             + "?????" _
                                                             + "' , PlanSerial='" _
                                                             + fGetNewSerialNo(sTempSerials).PadLeft(6, "0") _
                                                             + "' WHERE " + wstrWhere

                    Else
                        '.SetData = G_CONST_ST_PKCP_NOSTOCK & ",?????,?????" & "," & fGetNewSerialNo(Mid(sTempSerials, 2)).PadLeft(6, "0")

                        sSQL = "UPDATE " + G_CONST_TBL_PACKCP + " SET PickFlag='" _
                                                             + pstrLock _
                                                             + "' , PairLctn='" _
                                                             + "?????" _
                                                             + "' , StockLctn='" _
                                                             + "?????" _
                                                             + "' , PlanSerial='" _
                                                             + fGetNewSerialNo(Mid(sTempSerials, 2)).PadLeft(6, "0") _
                                                             + "' WHERE " + wstrWhere


                    End If

                    affected_rows = dbClient.Execute(sSQL)


                    If affected_rows = 0 Then
                        Exit Function
                    End If


                  
                End If


                wstrKey2(0) = "PicsType"
                wstrKey2(1) = "Cstmid"
                wstrKey2(2) = "CstmCode"
                wstrKey2(3) = "CenterCode"
                wstrKey2(4) = "Bhk"
                wstrKey2(5) = "Itemid"
                wstrKey2(6) = "ItemCode"
                wstrKey2(7) = "SerialNo"

                wstrKeyValue2(0) = RTrim(sPicsType)
                wstrKeyValue2(1) = RTrim(sCstmid)
                wstrKeyValue2(2) = RTrim(sCstmCode)
                wstrKeyValue2(3) = RTrim(sCenterCode)
                wstrKeyValue2(4) = RTrim(sBhk)
                wstrKeyValue2(5) = RTrim(sItemInID)
                wstrKeyValue2(6) = RTrim(sItemInCode)


                If sItemInID") = "D" AndAlso sPickFlag") = "1" Then
                    wstrKeyValue2(7) = RTrim(sSerialNo"))

                    wstrWhere = ""
                    wstrWhere = wstrKey2(0) & " = '" & wstrKeyValue2(0) & "'"
                    wstrWhere &= " and " & wstrKey2(1) & " = '" & wstrKeyValue2(1) & "'"
                    wstrWhere &= " and " & wstrKey2(2) & " = '" & wstrKeyValue2(2) & "'"
                    wstrWhere &= " and " & wstrKey2(3) & " = '" & wstrKeyValue2(3) & "'"
                    wstrWhere &= " and " & wstrKey2(4) & " = '" & wstrKeyValue2(4) & "'"
                    wstrWhere &= " and " & wstrKey2(5) & " = '" & wstrKeyValue2(5) & "'"
                    wstrWhere &= " and " & wstrKey2(6) & " = '" & wstrKeyValue2(6) & "'"
                    wstrWhere &= " and " & wstrKey2(7) & " = '" & wstrKeyValue2(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 sZaikoStatus As String = ""

                    If tmpStr.Count > 0 Then

                        values = tmpStr(0)

                        Dim result As String = Nothing
                        If values.TryGetValue("ZaikoStatus", result) Then
                            sZaikoStatus = RTrim(result)
                        End If

                        If G_CONST_ST_STOCK_PICKED = sZaikoStatus Then

                            sSQL = "UPDATE " + G_CONST_TBL_STOCK + " SET ZaikoStatus='" _
                                                             + G_CONST_ST_STOCK_INSTOCK _
                                                             + "' WHERE " + wstrWhere


                            affected_rows = dbClient.Execute(sSQL)

                        End If

                    Else
                        Exit Function


                    End If

                Else

                    wstrKeyValue2(7) = RTrim(.Item("PlanSerial"))

                    wstrWhere = ""
                    wstrWhere = wstrKey2(0) & " = '" & wstrKeyValue2(0) & "'"
                    wstrWhere &= " and " & wstrKey2(1) & " = '" & wstrKeyValue2(1) & "'"
                    wstrWhere &= " and " & wstrKey2(2) & " = '" & wstrKeyValue2(2) & "'"
                    wstrWhere &= " and " & wstrKey2(3) & " = '" & wstrKeyValue2(3) & "'"
                    wstrWhere &= " and " & wstrKey2(4) & " = '" & wstrKeyValue2(4) & "'"
                    wstrWhere &= " and " & wstrKey2(5) & " = '" & wstrKeyValue2(5) & "'"
                    wstrWhere &= " and " & wstrKey2(6) & " = '" & wstrKeyValue2(6) & "'"
                    wstrWhere &= " and " & wstrKey2(7) & " = '" & wstrKeyValue2(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 sItemid As String = ""

                    If tmpStr.Count > 0 Then

                        values = tmpStr(0)


                        Dim result As String = Nothing
                        If values1.TryGetValue("ItemInID", result) Then
                            sItemInID = RTrim(result)
                        End If
                        If values1.TryGetValue("ItemCode", result) Then
                            sItemCode = RTrim(result)
                        End If
                        If values1.TryGetValue("ItemInCode", result) Then
                            sItemInCode = RTrim(result)
                        End If
                        If values1.TryGetValue("Itemid", result) Then
                            sItemid = RTrim(result)
                        End If

                        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("sCenterCode", result) Then
                            sCenterCode = RTrim(result)
                        End If
                        If values1.TryGetValue("sBhk", result) Then
                            sBhk = RTrim(result)
                        End If
                        If values1.TryGetValue("PickFlag", result) Then
                            sPickFlag = RTrim(result)
                        End If
                        If values1.TryGetValue("SerialNo", result) Then
                            sSerialNo = RTrim(result)
                        End If
                        If values1.TryGetValue("sZaikoStatus", result) Then
                            sZaikoStatus = RTrim(result)
                        End If

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

                            If G_CONST_ST_STOCK_RESERVED2 = RTrim(sZaikoStatus) Then

                                sSQL = "UPDATE " + G_CONST_TBL_STOCK + " SET ZaikoStatus='" _
                                                         + G_CONST_ST_STOCK_INSTOCK _
                                                         + "' WHERE " + wstrWhere

                                affected_rows = dbClient.Execute(sSQL)

                                If affected_rows = 0 Then
                                    Exit Function
                                End If

                                '//STOCKレコードがすでに他の作業者によって出庫完了となっている場合は、他の出庫予約してあるSTOCKレコードを入庫完了に戻す
                            ElseIf G_CONST_ST_STOCK_PICKED = sZaikoStatus Then

                                wintRet = fFreeZaikoStatus("STOCK1")
                                If wintRet = -1 Then
                                    Exit Function
                                ElseIf wintRet = -2 Then
                                    fNotPackForDelv = -2
                                End If

                            End If
                        End If


                    Else
                        Exit Function

                    End If

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




        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, "STOCK1", wstrKey2, wstrKeyValue2, BtLib.Operation.GetEqual)
        'Select Case wintRet
        '    Case 0
        '        With gclsDB.Records("STOCK1")
        '            If G_CONST_ST_STOCK_PICKED = .Item("ZaikoStatus") Then

        '                '// DB更新
        '                With gclsDB
        '                    .Setcolumn = "ZaikoStatus"
        '                    .SetData = G_CONST_ST_STOCK_INSTOCK

        '                    If .fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, wstrKey2, wstrKeyValue2) = -1 Then
        '                        Exit Function
        '                    End If
        '                End With

        '                '// ロケーション戻し


        '            End If
        '        End With
        '    Case 4
        '        fNotPackForDelv = -2
        '    Case Else
        '        Exit Function
        'End Select

        'Else
        'wstrKeyValue2(7) = RTrim(.Item("PlanSerial"))
        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, "STOCK1", wstrKey2, wstrKeyValue2, BtLib.Operation.GetGreaterOrEqual)
        'Select Case wintRet
        '    Case 0
        '        With gclsDB.Records("STOCK1")
        '            If wstrKeyValue2(0) = RTrim(.Item("PicsType")) And _
        '               wstrKeyValue2(1) = RTrim(.Item("Cstmid")) And _
        '               wstrKeyValue2(2) = RTrim(.Item("CstmCode")) And _
        '               wstrKeyValue2(3) = RTrim(.Item("CenterCode")) And _
        '               wstrKeyValue2(4) = RTrim(.Item("Bhk")) And _
        '               wstrKeyValue2(5) = RTrim(.Item("Itemid")) And _
        '               wstrKeyValue2(6) = RTrim(.Item("ItemCode")) And _
        '               wstrKeyValue2(7) = RTrim(.Item("SerialNo")) Then

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

        '                    '// DB更新
        '                    With gclsDB
        '                        .Setcolumn = "ZaikoStatus"
        '                        .SetData = G_CONST_ST_STOCK_INSTOCK

        '                        If .fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, wstrKey2, wstrKeyValue2) = -1 Then
        '                            Exit Function
        '                        End If
        '                    End With

        '                    '//STOCKレコードがすでに他の作業者によって出庫完了となっている場合は、他の出庫予約してあるSTOCKレコードを入庫完了に戻す
        '                ElseIf G_CONST_ST_STOCK_PICKED = .Item("ZaikoStatus") Then

        '                    wintRet = fFreeZaikoStatus("STOCK1")
        '                    If wintRet = -1 Then
        '                        Exit Function
        '                    ElseIf wintRet = -2 Then
        '                        fNotPackForDelv = -2
        '                    End If

        '                End If
        '            End If
        '        End With
        '    Case 9
        '        fNotPackForDelv = -2
        '    Case Else
        '        Exit Function
        'End Select
        'End If




        'End If



        'With gclsDB.Records(pstrKey)
        'If RTrim(.Item("ItemInID")) = "P" Then
        '    wstrKeyValue(0) = RTrim(.Item("ItemCode"))
        '    wstrKeyValue(1) = RTrim(.Item("ItemInCode"))
        '    wstrKeyValue(2) = RTrim(.Item("TempSerial"))
        '    '// PACKCPレコードのステータスを保管部品なしに
        '    With gclsDB

        '        .Setcolumn = "PickFlag,PairLctn,StockLctn,PlanSerial"
        '        If IsNumeric(Mid(wstrKeyValue(2), 1, 1)) Then
        '            .SetData = G_CONST_ST_PKCP_NOSTOCK & ",?????,?????" & "," & fGetNewSerialNo(.Records(pstrKey).Item("TempSerial")).PadLeft(6, "0")
        '        Else
        '            .SetData = G_CONST_ST_PKCP_NOSTOCK & ",?????,?????" & "," & fGetNewSerialNo(Mid(.Records(pstrKey).Item("TempSerial"), 2)).PadLeft(6, "0")
        '        End If

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

        '在庫の開放処理
        '//STOCKレコードのステータスを入庫完了に戻す
        'wstrKey2(0) = "PicsType"
        'wstrKey2(1) = "Cstmid"
        'wstrKey2(2) = "CstmCode"
        'wstrKey2(3) = "CenterCode"
        'wstrKey2(4) = "Bhk"
        'wstrKey2(5) = "Itemid"
        'wstrKey2(6) = "ItemCode"
        'wstrKey2(7) = "SerialNo"

        'wstrKeyValue2(0) = RTrim(.Item("PicsType"))
        'wstrKeyValue2(1) = RTrim(.Item("Cstmid"))
        'wstrKeyValue2(2) = RTrim(.Item("CstmCode"))
        'wstrKeyValue2(3) = RTrim(.Item("CenterCode"))
        'wstrKeyValue2(4) = RTrim(.Item("Bhk"))
        'wstrKeyValue2(5) = RTrim(.Item("ItemInID"))
        'wstrKeyValue2(6) = RTrim(.Item("ItemInCode"))

        '    If .Item("ItemInID") = "D" AndAlso .Item("PickFlag") = "1" Then
        '        wstrKeyValue2(7) = RTrim(.Item("SerialNo"))
        '        wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, "STOCK1", wstrKey2, wstrKeyValue2, BtLib.Operation.GetEqual)
        '        Select Case wintRet
        '            Case 0
        '                With gclsDB.Records("STOCK1")
        '                    If G_CONST_ST_STOCK_PICKED = .Item("ZaikoStatus") Then

        '                        '// DB更新
        '                        With gclsDB
        '                            .Setcolumn = "ZaikoStatus"
        '                            .SetData = G_CONST_ST_STOCK_INSTOCK

        '                            If .fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, wstrKey2, wstrKeyValue2) = -1 Then
        '                                Exit Function
        '                            End If
        '                        End With

        '                        '// ロケーション戻し


        '                    End If
        '                End With
        '            Case 4
        '                fNotPackForDelv = -2
        '            Case Else
        '                Exit Function
        '        End Select

        '    Else
        '        wstrKeyValue2(7) = RTrim(.Item("PlanSerial"))
        '        wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, "STOCK1", wstrKey2, wstrKeyValue2, BtLib.Operation.GetGreaterOrEqual)
        '        Select Case wintRet
        '            Case 0
        '                With gclsDB.Records("STOCK1")
        '                    If wstrKeyValue2(0) = RTrim(.Item("PicsType")) And _
        '                       wstrKeyValue2(1) = RTrim(.Item("Cstmid")) And _
        '                       wstrKeyValue2(2) = RTrim(.Item("CstmCode")) And _
        '                       wstrKeyValue2(3) = RTrim(.Item("CenterCode")) And _
        '                       wstrKeyValue2(4) = RTrim(.Item("Bhk")) And _
        '                       wstrKeyValue2(5) = RTrim(.Item("Itemid")) And _
        '                       wstrKeyValue2(6) = RTrim(.Item("ItemCode")) And _
        '                       wstrKeyValue2(7) = RTrim(.Item("SerialNo")) Then

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

        '                            '// DB更新
        '                            With gclsDB
        '                                .Setcolumn = "ZaikoStatus"
        '                                .SetData = G_CONST_ST_STOCK_INSTOCK

        '                                If .fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, wstrKey2, wstrKeyValue2) = -1 Then
        '                                    Exit Function
        '                                End If
        '                            End With

        '                            '//STOCKレコードがすでに他の作業者によって出庫完了となっている場合は、他の出庫予約してあるSTOCKレコードを入庫完了に戻す
        '                        ElseIf G_CONST_ST_STOCK_PICKED = .Item("ZaikoStatus") Then

        '                            wintRet = fFreeZaikoStatus("STOCK1")
        '                            If wintRet = -1 Then
        '                                Exit Function
        '                            ElseIf wintRet = -2 Then
        '                                fNotPackForDelv = -2
        '                            End If

        '                        End If
        '                    End If
        '                End With
        '            Case 9
        '                fNotPackForDelv = -2
        '            Case Else
        '                Exit Function
        '        End Select
        '    End If

        'End With
        'fNotPackForDelv = 0
        'Catch ex As Exception
        '    sErrLog(gAppName, "fNotPackForDelv", ex.ToString)
        'Finally
        '    If wintRet <> -1 Then gclsDB.fCloseRecord("STOCK1")
        'End Try
    End Function

    '*******************************************************************************
    '* 機能     : 支障処理（デリバリー用）
    '* 引数     : 部品番号
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fItemNotPack(ByVal pstrItemInCode As String) As Integer
        Dim wstrKey(2), wstrKeyValue(2) As String
        Dim wintRet As Integer = -1
        Dim M_KEY_CP01 As String = "PKCP01"
        Dim wstrWhere As String
        fItemNotPack = -1
        wstrKey(0) = "ItemCode" : wstrKeyValue(0) = Mid(gstrctKDPP.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
        wstrKey(1) = "ItemInCode" : wstrKeyValue(1) = pstrItemInCode
        wstrKey(2) = "PlanSerial" : wstrKeyValue(2) = Space(6)

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

        Try

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

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

            If tmpStr.Count > 0 Then

                Do
                    values = tmpStr(i)

                    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("ItemInID", result) Then
                        sItemInID = RTrim(result)
                    End If


                    If RTrim(sItemCode) = wstrKeyValue(0) AndAlso RTrim(sItemInCode) = wstrKeyValue(1) Then
                        If fNotPackForDelv(M_KEY_CP01) = -1 Then Exit Function
                        If RTrim(sItemInID) = "D" Then
                            fDeletePackCP(M_KEY_CP01, wstrWhere)
                        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

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






        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY07, M_KEY_CP01, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'Try
        '    Select Case wintRet
        '        Case 0
        '            Do
        '                With gclsDB.Records(M_KEY_CP01)
        '                    If RTrim(.Item("ItemCode")) = wstrKeyValue(0) AndAlso RTrim(.Item("ItemInCode")) = wstrKeyValue(1) Then
        '                        If fNotPackForDelv(M_KEY_CP01) = -1 Then Exit Function
        '                        If RTrim(.Item("ItemInID")) = "D" Then
        '                            fDeletePackCP(M_KEY_CP01)
        '                        End If
        '                    Else
        '                        'Exit Do
        '                    End If
        '                    If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do
        '                End With
        '            Loop
        '            fItemNotPack = 0
        '        Case 9
        '            Exit Function
        '        Case Else
        '            Exit Function
        '    End Select
        'Catch ex As Exception
        '    sErrLog(gAppName, "fItemNotPack", ex.ToString)
        'Finally
        '    If wintRet <> -1 Then gclsDB.fCloseRecord(M_KEY_CP01)
        'End Try
    End Function

    '*******************************************************************************
    '* 機能     : 支障処理(デリバリー用）
    '* 引数     : なし
    '*          : 
    '* 戻り値   : -1:NG　0:OK
    '* 備考     : なし
    '*******************************************************************************
    Public Function fItemNotPack() As Integer
        Dim wstrKey(5), wstrKeyValue(5) As String
        Dim wintRet As Integer = -1
        Dim M_KEY_CP01 As String = "PKCP01"
        fItemNotPack = -1
        wstrKey(0) = "ItemCode" : wstrKeyValue(0) = Mid(gstrctKDPP.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
        wstrKey(1) = "ItemInCode" : wstrKeyValue(1) = Space(30)
        wstrKey(2) = "ItemInID" : wstrKeyValue(2) = Space(1)
        wstrKey(3) = "StockLctn" : wstrKeyValue(3) = Space(5)
        wstrKey(4) = "PlanSerial" : wstrKeyValue(4) = Space(6)
        wstrKey(5) = "SerialNo" : wstrKeyValue(5) = Space(6)
        wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY07, M_KEY_CP01, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        Try
            Select Case wintRet
                Case 0
                    Do
                        With gclsDB.Records(M_KEY_CP01)
                            If RTrim(.Item("ItemCode")) = wstrKeyValue(0) Then
                                If fNotPackForDelv(M_KEY_CP01) = -1 Then Exit Function
                                If RTrim(.Item("ItemInID")) = "D" Then
                                    fDeletePackCP(M_KEY_CP01)
                                End If
                            Else
                                'Exit Do
                            End If
                            If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do
                        End With
                    Loop
                    fItemNotPack = 0
                Case 9
                    Exit Function
                Case Else
                    Exit Function
            End Select
        Catch ex As Exception
            sErrLog(gAppName, "fItemNotPack() Ver.2", ex.ToString)
        Finally
            If wintRet <> -1 Then gclsDB.fCloseRecord(M_KEY_CP01)
        End Try
    End Function

    '*******************************************************************************
    '* 機能     : PACKCP取得処理
    '* 引数     : 1.部品番号 2.検索条件（指定部品番号以上:0 含まない:1)
    '*          : 
    '* 戻り値   : -1:NG　-2:0件  0:1件以上 1:区分"D"
    '* 備考     : なし
    '*******************************************************************************
    Public Function fSearchPackCP4Delv(Optional ByVal pstrItemCode As String = "", Optional ByVal pintGreater As Integer = 0, Optional ByVal pintDirection As Integer = 0)
        Dim rtn As Integer = -1
        Dim wintCnt As Integer
        Dim wintSubCnt As Integer
        Dim wstrKey(5) As String
        Dim wstrKeyValue(5) As String
        Dim wstrLctnItemCode As String
        Dim wstrItemInCodeDisp As String
        Dim wstrWork As String
        Dim wstrPrevCrtnNo As String
        Dim bFound As Boolean
        Dim wstrItemInCodeTemp As String
        Dim wstrItemInCodeLctn As String
        Dim wstrItemID As String
        Dim wstrTotalScnQty As String
        Dim M_KEY_CP01 As String = "PKCP01"

        fSearchPackCP4Delv = -1

        wstrPrevCrtnNo = gstrctPPDisp.strCrtnNo

        wstrKey(0) = "ItemCode"
        wstrKey(1) = "ItemInCode"
        wstrKey(2) = "ItemInID"
        wstrKey(3) = "StockLctn"
        wstrKey(4) = "PlanSerial"
        wstrKey(5) = "SerialNo"

        wintCnt = 1
        bFound = False
        Try
            With gstrctKDPP
                wstrKeyValue(0) = Mid(.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
                If pstrItemCode = "" Then
                    wstrKeyValue(1) = Space(30)
                Else
                    wstrKeyValue(1) = pstrItemCode
                End If
                wstrKeyValue(2) = Space(1)
                wstrKeyValue(3) = Space(5)
                wstrKeyValue(4) = Space(6)
                wstrKeyValue(5) = Space(6)
            End With
            'If rtn <> -1 Then gclsDB.fCloseRecord(M_KEY_CP01)

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

            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 sPickFlag As String = ""
            Dim sItemInCode As String = ""
            Dim sStockLctn As String = ""
            Dim sPackQtyP As String = ""
            Dim sTempSerial As String = ""
            Dim sItemID As String = ""
            Dim sItemInCodeDisp As String = ""
            Dim sPlanSerial 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("PickFlag", result) Then
                        sPickFlag = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If
                    If values.TryGetValue("StockLctn", result) Then
                        sStockLctn = RTrim(result)
                    End If
                    If values.TryGetValue("PackQtyP", result) Then
                        sPackQtyP = RTrim(result)
                    End If
                    If values.TryGetValue("TempSerial", result) Then
                        sTempSerial = RTrim(result)
                    End If
                    If values.TryGetValue("ItemID", result) Then
                        sItemID = 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 RTrim(sItemGr) = gstrctKDPP.strItemGr AndAlso RTrim(sItemCode) = wstrKeyValue(0) Then
                        If RTrim(sItemInID) = "D" Then
                            'gstrctKDPP.intIndex += 1
                            If RTrim(sPickFlag) = "D" Then
                                If pstrItemCode <> "" Then 'ダイレクト検索
                                    If pstrItemCode = RTrim(sItemInCode) Then
                                        wstrItemInCodeTemp = RTrim(sItemInCode)
                                        wstrItemInCodeLctn = RTrim(sStockLctn)
                                        gstrctPPDispPart.strPackQty = RTrim(sPackQtyP)
                                    Else
                                        wstrItemInCodeTemp = RTrim(sItemInCode)
                                        wstrItemInCodeLctn = RTrim(sStockLctn)
                                        gstrctPPDispPart.strPackQty = RTrim(sPackQtyP)
                                    End If
                                Else 'シーケンシャル検索
                                    If wstrItemInCodeTemp = "" Then
                                        wstrItemInCodeTemp = RTrim(sItemInCode)
                                        wstrItemInCodeLctn = RTrim(sStockLctn)
                                        'wstrTotalScnQty = RTrim(sPackQtyP)
                                        gstrctPPDispPart.strPackQty = RTrim(sPackQtyP)
                                    Else
                                        If wstrItemInCodeTemp = RTrim(sItemInCode) Then

                                        End If
                                    End If
                                End If
                            End If
                        ElseIf RTrim(sItemInID) = "P" Then
                            'gstrctKDPP.intIndex += 1
                            If wstrItemInCodeTemp = "" Then
                                '通常P部品
                                fSearchPackCP4Delv = -2
                            Else
                                If pintGreater = 0 OrElse (pintGreater = 1 AndAlso wstrItemInCodeTemp <> RTrim(sItemInCode)) Then
                                    If wstrItemInCodeTemp = RTrim(sItemInCode) Then
                                        '表示データをセットして画面処理へ
                                        With gstrctPPDisp
                                            .strItemCode = RTrim(sItemCode)
                                            .strCrtnNo = Mid(RTrim(sItemCode), 21, 5)
                                        End With
                                        With gstrctPPDispPart
                                            .strSerial = RTrim(sTempSerial)
                                            .strLocation = wstrItemInCodeLctn
                                            .strLocation1 = RTrim(Mid(wstrItemInCodeLctn, 1, 2))
                                            .strLocation2 = RTrim(Mid(wstrItemInCodeLctn, 3))
                                            .strPLocation = RTrim(sStockLctn)
                                            .strPLocation1 = RTrim(Mid(sStockLctn, 1, 2))
                                            .strPLocation2 = RTrim(Mid(sStockLctn, 3))
                                            .strID = RTrim(sItemID)
                                            .strItemCode = RTrim(sItemCode)
                                            .strItemInID = "D" 'Dをセット
                                            .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)
                                            fSearchPackCP4Delv = 0
                                            bFound = True
                                        End With
                                    Else
                                        'Pデータ無いのでエラーへ
                                    End If
                                End If
                            End If
                        Else

                        End If

                    End If

                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If

                    wintCnt += 1
                Loop


            Else

                Exit Function

            End If

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




            'rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY10, M_KEY_CP01, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
            'Select Case rtn
            '    Case 0
            '        'ItemInID="D"と同じ部品を取得
            '        Do Until bFound
            '            With gclsDB.Records(M_KEY_CP01)
            '                If RTrim(.Item("ItemGr")) = gstrctKDPP.strItemGr AndAlso RTrim(.Item("ItemCode")) = wstrKeyValue(0) Then
            '                    If RTrim(.Item("ItemInID")) = "D" Then
            '                        'gstrctKDPP.intIndex += 1
            '                        If RTrim(.Item("PickFlag")) = "D" Then
            '                            If pstrItemCode <> "" Then 'ダイレクト検索
            '                                If pstrItemCode = RTrim("ItemInCode") Then
            '                                    wstrItemInCodeTemp = RTrim(.Item("ItemInCode"))
            '                                    wstrItemInCodeLctn = RTrim(.Item("StockLctn"))
            '                                    gstrctPPDispPart.strPackQty = RTrim(.Item("PackQtyP"))
            '                                Else
            '                                    wstrItemInCodeTemp = RTrim(.Item("ItemInCode"))
            '                                    wstrItemInCodeLctn = RTrim(.Item("StockLctn"))
            '                                    gstrctPPDispPart.strPackQty = RTrim(.Item("PackQtyP"))
            '                                End If
            '                            Else 'シーケンシャル検索
            '                                If wstrItemInCodeTemp = "" Then
            '                                    wstrItemInCodeTemp = RTrim(.Item("ItemInCode"))
            '                                    wstrItemInCodeLctn = RTrim(.Item("StockLctn"))
            '                                    'wstrTotalScnQty = RTrim(.Item("PackQtyP"))
            '                                    gstrctPPDispPart.strPackQty = RTrim(.Item("PackQtyP"))
            '                                Else
            '                                    If wstrItemInCodeTemp = RTrim(.Item("ItemInCode")) Then

            '                                    End If
            '                                End If
            '                            End If
            '                        End If
            '                    ElseIf RTrim(.Item("ItemInID")) = "P" Then
            '                        'gstrctKDPP.intIndex += 1
            '                        If wstrItemInCodeTemp = "" Then
            '                            '通常P部品
            '                            fSearchPackCP4Delv = -2
            '                        Else
            '                            If pintGreater = 0 OrElse (pintGreater = 1 AndAlso wstrItemInCodeTemp <> RTrim(.Item("ItemInCode"))) Then
            '                                If wstrItemInCodeTemp = RTrim(.Item("ItemInCode")) Then
            '                                    '表示データをセットして画面処理へ
            '                                    With gstrctPPDisp
            '                                        .strItemCode = RTrim(gclsDB.Records(M_KEY_CP01).Item("ItemCode"))
            '                                        .strCrtnNo = Mid(RTrim(gclsDB.Records(M_KEY_CP01).Item("ItemCode")), 21, 5)
            '                                    End With
            '                                    With gstrctPPDispPart
            '                                        .strSerial = RTrim(gclsDB.Records(M_KEY_CP01).Item("TempSerial"))
            '                                        .strLocation = wstrItemInCodeLctn
            '                                        .strLocation1 = RTrim(Mid(wstrItemInCodeLctn, 1, 2))
            '                                        .strLocation2 = RTrim(Mid(wstrItemInCodeLctn, 3))
            '                                        .strPLocation = RTrim(gclsDB.Records(M_KEY_CP01).Item("StockLctn"))
            '                                        .strPLocation1 = RTrim(Mid(gclsDB.Records(M_KEY_CP01).Item("StockLctn"), 1, 2))
            '                                        .strPLocation2 = RTrim(Mid(gclsDB.Records(M_KEY_CP01).Item("StockLctn"), 3))
            '                                        .strID = RTrim(gclsDB.Records(M_KEY_CP01).Item("ItemID"))
            '                                        .strItemCode = RTrim(gclsDB.Records(M_KEY_CP01).Item("ItemCode"))
            '                                        .strItemInID = "D" 'Dをセット
            '                                        .strItemInCode = RTrim(gclsDB.Records(M_KEY_CP01).Item("ItemInCode"))
            '                                        wstrLctnItemCode &= .strItemInCode

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

            '                                        .strCL = RTrim(Mid(gclsDB.Records(M_KEY_CP01).Item("ItemInCode"), 11, 2))
            '                                        .strZ = RTrim(Mid(gclsDB.Records(M_KEY_CP01).Item("ItemInCode"), 13, 1))
            '                                        .strSerial = RTrim(gclsDB.Records(M_KEY_CP01).Item("PlanSerial"))
            '                                        '.strPackQty = RTrim(gclsDB.Records(M_KEY_CP01).Item("BunkatuJ"))
            '                                        fSearchPackCP4Delv = 0
            '                                        bFound = True
            '                                    End With
            '                                Else
            '                                    'Pデータ無いのでエラーへ
            '                                End If
            '                            End If
            '                        End If
            '                    Else

            '                    End If
            '                Else
            '                    If fSearchPackCP4Delv = -1 Then fSearchPackCP4Delv = -2
            '                    Exit Function
            '                End If
            '                If .Read(BtLib.Operation.GetNext) <> 0 Then
            '                    Exit Do
            '                End If
            '                wintCnt += 1
            '            End With
            '        Loop
            '    Case 9
            '        fSearchPackCP4Delv = -3
            '    Case Else
            '        Exit Function
            'End Select

        'Catch ex As Exception
        '    sErrLog(gAppName, "fSearchPackCP4Delv", ex.ToString)
        'Finally
        '    If rtn <> -1 Then gclsDB.fCloseRecord(M_KEY_CP01)
        'End Try
    End Function
    '*******************************************************************************
    '* 機能     : PACKCP取得処理
    '* 引数     : 1.部品番号 2.検索条件（指定部品番号以上:0 含まない:1)
    '*          : 
    '* 戻り値   : -1:NG　-2:0件  0:1件以上 1:区分"D"
    '* 備考     : なし
    '*******************************************************************************
    Public Function fUpdPackCP(ByVal pstrKey1 As String, ByVal pstrKey2 As String, ByVal pstrScanSerial As String, ByVal pintRestCnt As Integer, ByRef pstrDelvLctn As String) As Integer
        Dim wstrKey(2), wstrKeyValue(2) As String
        Dim wIntRet As Integer
        Dim wstrLctn As String
        Dim wstrTempSerial As String
        Dim wstrScnDate, wstrScnTime, wstrScnNo As String
        fUpdPackCP = -1
        'スキャンフラグをD->1へ更新
        '// PACKCPデータの退避

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

        If tmpStrCP.Count > 0 Then

            values = tmpStr(0)

            Dim result As String = Nothing
            If values.TryGetValue("ItemCode", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sItemCode = result
            End If
            If values.TryGetValue("ItemInCode", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sItemInCode = result
            End If
            If values.TryGetValue("TempSerial", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sTempSerial = result
            End If
            If values.TryGetValue("SortLctn3", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sSortLctn3 = result
            End If
            If values.TryGetValue("StockLctn", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sStockLctn = result
            End If


        End If


        'With gclsDB.Records(pstrKey1)
        wstrKey(0) = "ItemCode" : wstrKeyValue(0) = sItemCode
        wstrKey(1) = "ItemInCode" : wstrKeyValue(1) = sItemInCode
        wstrKey(2) = "TempSerial" : wstrKeyValue(2) = Space(6)
        wstrTempSerial = RTrim(sTempSerial)
        If RTrim(sSortLctn3) = "" Then
            wstrLctn = RTrim(sStockLctn)
        Else
            wstrLctn = ""
        End If
        'End With




        'With gclsDB.Records(pstrKey1)
        '    wstrKey(0) = "ItemCode" : wstrKeyValue(0) = .Item("ItemCode")
        '    wstrKey(1) = "ItemInCode" : wstrKeyValue(1) = .Item("ItemInCode")
        '    wstrKey(2) = "TempSerial" : wstrKeyValue(2) = Space(6)
        '    wstrTempSerial = RTrim(.Item("TempSerial"))
        '    If RTrim(.Item("SortLctn3")) = "" Then
        '        wstrLctn = RTrim(.Item("StockLctn"))
        '    Else
        '        wstrLctn = ""
        '    End If
        'End With
        'gclsDB.fCloseRecord(pstrKey1)

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

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

        values = New Dictionary(Of String, String)
        sItemCode = ""
        sItemInCode = ""
        Dim sItemInID As String = ""
        sTempSerial = ""
        sSortLctn3 = ""
        Dim sSql As String = ""

        Dim i As Integer = 0

        If tmpStr.Count > 0 Then

            Do

                values = tmpStr(i)

                Dim result As String = Nothing
                If values.TryGetValue("ItemCode", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sItemCode = result
                End If
                If values.TryGetValue("ItemInCode", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sItemInCode = result
                End If
                If values.TryGetValue("ItemInID", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sItemInID = result
                End If
                If values.TryGetValue("TempSerial", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sTempSerial = result
                End If
                If values.TryGetValue("SortLctn3", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sSortLctn3 = result
                End If

                If RTrim(sItemCode) = RTrim(wstrKeyValue(0)) AndAlso RTrim(sItemInCode) = RTrim(wstrKeyValue(1)) Then
                    If RTrim(sItemInID) = "D" Then
                        If RTrim(sTempSerial) = wstrTempSerial Then
                            wstrScnDate = fgetDefaultDate()
                            wstrScnTime = fgetDefaultTime()
                            wstrScnNo = gstrctKDHT.strUserNo

                            sSql = "UPDATE " + G_CONST_TBL_PACKCP _
                                            + " SET PickFlag='" + "1" _
                                            + "' SerialNo='" + pstrScanSerial _
                                            + "' PackQtyJ='" + CStr(pintRestCnt).PadLeft(5, "0") _
                                            + "' SortLctn3='" + wstrLctn _
                                            + "' ScanDate='" + wstrScnDate _
                                            + "' ScanTime='" + wstrScnTime _
                                            + "' UserNo='" + wstrScnNo _
                                            + "' WHERE "


                            'gclsDB.Setcolumn = "PickFlag,SerialNo,PackQtyJ,SortLctn3,ScanDate,ScanTime,UserNo"
                            'gclsDB.SetData = "1," & pstrScanSerial & "," & CStr(pintRestCnt).PadLeft(5, "0") & "," & wstrLctn & "," & wstrScnDate & "," & wstrScnTime & "," & wstrScnNo
                        Else

                            sSql = "UPDATE " + G_CONST_TBL_PACKCP _
                                            + " SET SortLctn3='" + wstrLctn _
                                            + "' WHERE "

                            'gclsDB.Setcolumn = "SortLctn3"
                            'gclsDB.SetData = wstrLctn
                        End If
                        If wstrLctn = "" Then
                            pstrDelvLctn = RTrim(sSortLctn3)
                        Else
                            pstrDelvLctn = wstrLctn
                        End If
                        wstrKeyValue(2) = sTempSerial

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

                        sSql = sSql + wstrWhere

                        affected_rows = dbClient.Execute(sSql)

                        'gclsDB.fUpdRecords(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY07, wstrKey, wstrKeyValue)
                    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

        wstrKeyValue(2) = wstrTempSerial

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

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

        tmpStrCP = tmpStr

        If tmpStr.Count = 0 Then

            Exit Function

        End If

        wIntRet = fUpdateStock(pstrKey1, pstrKey2, 0, False)
        If wIntRet = -1 Then Exit Function
        'ロケ更新
        wIntRet = fUpdateLocation(pstrKey1, pstrKey2, 1, False, wstrTempSerial, True)
        If wIntRet = -1 Then Exit Function


        fUpdPackCP = 1





        'wIntRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY07, pstrKey1, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'Select Case wIntRet
        '    Case 0
        '        Do
        '            With gclsDB.Records(pstrKey1)
        '                If RTrim(.Item("ItemCode")) = RTrim(wstrKeyValue(0)) AndAlso RTrim(.Item("ItemInCode")) = RTrim(wstrKeyValue(1)) Then
        '                    If RTrim(.Item("ItemInID")) = "D" Then
        '                        If RTrim(.Item("TempSerial")) = wstrTempSerial Then
        '                            wstrScnDate = fgetDefaultDate()
        '                            wstrScnTime = fgetDefaultTime()
        '                            wstrScnNo = gstrctKDHT.strUserNo

        '                            gclsDB.Setcolumn = "PickFlag,SerialNo,PackQtyJ,SortLctn3,ScanDate,ScanTime,UserNo"
        '                            gclsDB.SetData = "1," & pstrScanSerial & "," & CStr(pintRestCnt).PadLeft(5, "0") & "," & wstrLctn & "," & wstrScnDate & "," & wstrScnTime & "," & wstrScnNo
        '                        Else
        '                            gclsDB.Setcolumn = "SortLctn3"
        '                            gclsDB.SetData = wstrLctn
        '                        End If
        '                        If wstrLctn = "" Then
        '                            pstrDelvLctn = RTrim(.Item("SortLctn3"))
        '                        Else
        '                            pstrDelvLctn = wstrLctn
        '                        End If
        '                        wstrKeyValue(2) = .Item("TempSerial")
        '                        gclsDB.fUpdRecords(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY07, wstrKey, wstrKeyValue)
        '                    End If
        '                Else
        '                    Exit Do
        '                End If
        '                If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do
        '            End With
        '        Loop

        '    Case Else
        '        Exit Function
        'End Select
        'gclsDB.fCloseRecord(pstrKey1)
        'wstrKeyValue(2) = wstrTempSerial
        'wIntRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY07, pstrKey1, wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)

        'If wIntRet <> 0 Then Exit Function
        ''// STOCK更新
        'wIntRet = fUpdateStock(pstrKey1, pstrKey2, 0, False)
        'If wIntRet = -1 Then Exit Function
        ''ロケ更新
        'wIntRet = fUpdateLocation(pstrKey1, pstrKey2, 1, False, wstrTempSerial, True)
        'If wIntRet = -1 Then Exit Function




        'fUpdPackCP = 1
    End Function

    '*******************************************************************************
    '* 機能     : PACKCJ書き込み
    '* 引数     : 1:キー
    '*            2:ゼロ完了OKフラグ( 0: 通常出荷、1: ゼロ完了)
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fMakePackCJ2(ByVal pstrKey As String, ByRef pstrScnSerial As String) 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
        Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)

        fMakePackCJ2 = -1

        Try

            If tmpStrCP.Count > 0 Then

                values = tmpStrCP(0)
                Dim result As String = Nothing
                Dim sBunkatuJ As String = Nothing
                Dim sStockLctn As String = Nothing
                Dim sItemInCode As String = Nothing
                Dim sPlanSerial As String = Nothing
                Dim sHosoYou As String = Nothing
                Dim sHosoZai As String = Nothing
                Dim sHandyNo As String = Nothing
                Dim sPicsType As String = Nothing
                Dim sCstmid As String = Nothing
                Dim sCstmCode As String = Nothing

                Dim sTrSectionId As String = Nothing
                Dim sTrSection As String = Nothing
                Dim sWKSumDate As String = Nothing
                Dim sProductDate As String = Nothing
                Dim sShift As String = Nothing
                Dim sLine As String = Nothing
                Dim sPackNo As String = Nothing
                Dim sItemID As String = Nothing
                Dim sItemGr As String = Nothing
                Dim sItemCode As String = Nothing
                Dim sItemMCode As String = Nothing
                Dim sItemCodeDisp As String = Nothing

                Dim sItemInID As String = Nothing
                sItemInCode = Nothing
                Dim sItemInCodeDisp As String = Nothing
                Dim sPackQtyP As String = Nothing
                Dim sCaseQty As String = Nothing
                Dim sCenterCode As String = Nothing
                Dim sBhk As String = Nothing
                Dim sSortLctn1 As String = Nothing
                Dim sSortLctn2 As String = Nothing
                Dim sSortLctn3 As String = Nothing
                Dim sDisplayLctn As String = Nothing
                Dim sPairLctn As String = Nothing

                sPlanSerial = Nothing
                Dim sTempSerial As String = Nothing
                Dim sPartID As String = Nothing
                sHosoYou = Nothing
                Dim sHosoTan As String = Nothing
                sHosoZai = Nothing
                Dim sInz As String = Nothing
                Dim sSetDaisu As String = Nothing
                Dim sPalLctn As String = Nothing
                Dim sOffDate As String = Nothing
                Dim sOffTime As String = Nothing
                Dim sS6030 As String = Nothing

                Dim sPartName As String = Nothing
                sBunkatuJ = 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("ItemInCode", result) Then
                    sItemInCode = RTrim(result)
                End If
                If values.TryGetValue("PlanSerial", result) Then
                    sPlanSerial = RTrim(result)
                End If
                If values.TryGetValue("HosoYou", result) Then
                    sHosoYou = RTrim(result)
                End If
                If values.TryGetValue("HosoZai", result) Then
                    sHosoZai = 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)
                    ssProductDate = sProductDate
                End If
                If values.TryGetValue("Shift", result) Then
                    sShift = RTrim(result)
                    ssShift = sShift
                End If
                If values.TryGetValue("Line", result) Then
                    sLine = RTrim(result)
                End If
                If values.TryGetValue("PackNo", result) Then
                    sPackNo = RTrim(result)
                    ssPackNo = sPackNo
                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("ItemCodeDisp", result) Then
                    sItemCodeDisp = 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("PackQtyP", result) Then
                    sPackQtyP = RTrim(result)
                End If
                If values.TryGetValue("CaseQty", result) Then
                    sCaseQty = 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("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("DisplayLctn", result) Then
                    sDisplayLctn = RTrim(result)
                End If
                If values.TryGetValue("PairLctn", result) Then
                    sPairLctn = 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("BunkatuJ", result) Then
                    sBunkatuJ = RTrim(result)
                    ssBunkatuJ = sBunkatuJ
                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("sartName", result) Then
                    sPartName = RTrim(result)
                End If

                wstrQty = sBunkatuJ
                wstrSerial = gstrctPPDispPart.strSerial
                wstrPickFlag = "7"
                wstrStockLctn = sStockLctn
                wstrScnDate = fgetDefaultDate()
                wstrScnTime = fgetDefaultTime()
                wstrScnNo = gstrctKDHT.strUserNo

                gstrctDelvLabelData.strItemCode = RTrim(Mid(sItemInCode, 1, 13)).PadRight(13, " ")
                gstrctDelvLabelData.strPLoctn = wstrStockLctn
                gstrctDelvLabelData.strPSerial = RTrim(sPlanSerial).PadLeft(6, "0")
                gstrctDelvLabelData.strPQty = wstrQty.PadLeft(5, "0")
                gstrctDelvLabelData.strPHosoYou = RTrim(sHosoYou).PadRight(2, " ")
                gstrctDelvLabelData.strPHosoZai = RTrim(sHosoZai).PadRight(3, " ")
                gstrctDelvLabelData.strPCartonType = gstrctPPDisp.strCrtnType.PadRight(3, " ")

                '// 追加ﾃﾞｰﾀ生成
                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(31) = "PlanSerial" : wstrKeyValue(31) = sPlanSerial
                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)



            End If

            Dim sqlInsert As String = ""

            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, "fMakePackAJ", gclsDB.ErrMsg)
                Exit Function
            End If



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

            fMakePackCJ2 = 0
            Exit Function

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






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

        '        wstrQty = .Item("BunkatuJ")
        '        wstrSerial = gstrctPPDispPart.strSerial
        '        wstrPickFlag = "7"
        '        wstrStockLctn = .Item("StockLctn")
        '        wstrScnDate = fgetDefaultDate()
        '        wstrScnTime = fgetDefaultTime()
        '        wstrScnNo = gstrctKDHT.strUserNo

        '        gstrctDelvLabelData.strItemCode = RTrim(Mid(.Item("ItemInCode"), 1, 13)).PadRight(13, " ")
        '        gstrctDelvLabelData.strPLoctn = wstrStockLctn
        '        gstrctDelvLabelData.strPSerial = RTrim(.Item("PlanSerial")).PadLeft(6, "0")
        '        gstrctDelvLabelData.strPQty = wstrQty.PadLeft(5, "0")
        '        gstrctDelvLabelData.strPHosoYou = RTrim(.Item("HosoYou")).PadRight(2, " ")
        '        gstrctDelvLabelData.strPHosoZai = RTrim(.Item("HosoZai")).PadRight(3, " ")
        '        gstrctDelvLabelData.strPCartonType = gstrctPPDisp.strCrtnType.PadRight(3, " ")

        '        '// 追加ﾃﾞｰﾀ生成
        '        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(31) = "PlanSerial" : wstrKeyValue(31) = .Item("PlanSerial")
        '        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, "fMakePackCJ2", gclsDB.ErrMsg)
        '            Exit Function
        '        End If
        '    End With
        '    pstrScnSerial = wstrSerial

        '    fMakePackCJ2 = 0
        '    Exit Function

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

    End Function
    '*******************************************************************************
    '* 機能     : デリバリー更新処理
    '* 引数     : 1.PACKCPキー 2.STOCKキー 3.更新フラグ,4.実在庫シリアル
    '*          : 
    '* 戻り値   : -1:NG　0:0件 
    '* 備考     : なし
    '*******************************************************************************
    Public Function fUpdProc3(ByVal pstrKey As String, ByVal pstrKey2 As String, ByVal pbDUpdFlag As Boolean, ByVal pstrPStockSerial As String) As Integer
        Dim wIntRet As Integer
        Dim wstrKey(2) As String
        Dim wstrKeyValue(2) As String
        Dim wstrKey2(2) As String
        Dim wstrKeyValue2(2) As String
        Const KEY03 = "UPD_KEY03"
        fUpdProc3 = -1
        'CP削除
        With gclsDB.Records(pstrKey)
            wstrKey(0) = "ItemCode" : wstrKeyValue(0) = .Item("ItemCode")
            wstrKey(1) = "ItemInCode" : wstrKeyValue(1) = .Item("ItemInCode")
            wstrKey(2) = "TempSerial" : wstrKeyValue(2) = Space(6)
        End With

        gclsDB.fCloseRecord(pstrKey)
        wIntRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY07, pstrKey, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        If wIntRet = 0 Then
            Do
                With gclsDB.Records(pstrKey)
                    If RTrim(.Item("ItemCode")) = wstrKeyValue(0) AndAlso RTrim(.Item("ItemInCode")) = wstrKeyValue(1) Then
                        'ID="D"で7のStockを削除
                        If RTrim(.Item("ItemInID")) = "D" Then
                            If fDeleteStock(pstrKey) = -1 Then Exit Function
                            '###(2008/04/22 T. SHIMOKUBO)### UPD_ST [入庫中ﾛｹｰｼｮﾝが空きﾛｹになる不具合対応]
                            'If fResetAkiKbn(pstrKey) = -1 Then Exit Function
                            If fResetAkiKbn(pstrKey, pbDUpdFlag) = -1 Then Exit Function
                            '###(2008/04/22 T. SHIMOKUBO)### UPD_ED [入庫中ﾛｹｰｼｮﾝが空きﾛｹになる不具合対応]
                            'If gclsDB.Records(pstrKey2).Delete <> 0 Then Exit Function
                        Else
                            If fUpdateStock2(pstrKey, pstrPStockSerial) = -1 Then Exit Function
                        End If
                        wIntRet = fDeletePackCP(pstrKey)
                    Else
                        Exit Do
                    End If
                    If .Read(BtLib.Operation.GetNext) <> 0 Then
                        Exit Do
                    End If
                End With
            Loop
        End If
        'デリバリー在庫の更新
        If pbDUpdFlag Then wIntRet = fSetStock(pstrKey2)
        If wIntRet <> 0 Then Exit Function

        fUpdProc3 = 0
    End Function

    '*******************************************************************************
    '* 機能     : 空き区分の復帰
    '* 引数     : キー
    '*          : デリバリー在庫の追加ﾌﾗｸﾞ
    '* 戻り値   : -1:NG　0:Not Found 1:OK
    '* 備考     : なし
    '*******************************************************************************
    '###(2008/04/22 T. SHIMOKUBO)### UPD_ST [入庫中ﾛｹｰｼｮﾝが空きﾛｹになる不具合対応]
    'Private Function fResetAkiKbn(ByVal pstrKey) As Integer
    '一応今回不具合が出たﾃﾞﾘﾊﾞﾘｰ処理時のみの条件で修正
    Private Function fResetAkiKbn(ByVal pstrKey As String, ByVal pbDUpdFlag As Boolean) As Integer
        '###(2008/04/22 T. SHIMOKUBO)### UPD_ED [入庫中ﾛｹｰｼｮﾝが空きﾛｹになる不具合対応]
        Dim wstrKey(3), wstrKeyValue(3) As String
        Dim wintRet As Integer = -1
        Dim KEY01 As String = "KEYLOC1"
        fResetAkiKbn = -1
        wstrKey(0) = "CenterCode"
        wstrKey(1) = "Bhk"
        wstrKey(2) = "Location"
        wstrKey(3) = "Product"
        With gclsDB.Records(pstrKey)
            wstrKeyValue(0) = RTrim(.Item("CenterCode"))
            wstrKeyValue(1) = RTrim(.Item("Bhk"))
            wstrKeyValue(2) = RTrim(.Item("StockLctn"))
            wstrKeyValue(3) = Space(6)
        End With

        Try

            wintRet = gclsDB.fOpenRecord(G_CONST_TBL_LOCATION, G_CONST_KEY_LOCATIONKEY00, KEY01, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
            Select Case wintRet
                Case 0
                    Do
                        With gclsDB.Records(KEY01)
                            If RTrim(.Item(wstrKey(0))) = wstrKeyValue(0) AndAlso RTrim(.Item(wstrKey(1))) = wstrKeyValue(1) AndAlso RTrim(.Item(wstrKey(2))) = wstrKeyValue(2) Then
                                wstrKeyValue(3) = RTrim(.Item(wstrKey(3)))

                                '###(2008/04/22 T. SHIMOKUBO)### ADD_ST [入庫中ﾛｹｰｼｮﾝが空きﾛｹになる不具合対応]
                                'ﾃﾞﾘﾊﾞﾘｰ登録有り、ﾛｹｰｼｮﾝ数量が0より大きい場合は空きにしない
                                Dim wstrQty As String
                                wstrQty = Trim(.Item("Qty")).PadLeft(6, "0")
                                If pbDUpdFlag AndAlso IsNumeric(wstrQty) AndAlso CLng(wstrQty) > 0 Then
                                    fResetAkiKbn = 1
                                    Exit Function
                                End If
                                '###(2008/04/22 T. SHIMOKUBO)### ADD_ED [入庫中ﾛｹｰｼｮﾝが空きﾛｹになる不具合対応]

                                gclsDB.Setcolumn = "AkiKB"
                                gclsDB.SetData = "0"
                                If gclsDB.fUpdRecords(G_CONST_TBL_LOCATION, G_CONST_KEY_LOCATIONKEY00, wstrKey, wstrKeyValue) <> 0 Then
                                    Exit Function
                                End If
                                fResetAkiKbn = 1
                                Exit Function
                            End If
                            If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do
                        End With
                    Loop
                Case 9
                    fResetAkiKbn = 0
                Case Else
                    Exit Function
            End Select
            If fResetAkiKbn = -1 Then fResetAkiKbn = 0
        Catch ex As Exception
            fResetAkiKbn = -1
            sErrLog(gAppName, "fResetAkiKbn", ex.ToString)
        Finally
            If wintRet <> -1 Then gclsDB.fCloseRecord(KEY01)
        End Try
    End Function

    Public Function fMakeDelvSerial(ByRef pstrSerial As String) As Boolean
        fMakeDelvSerial = False
        With mstructKey
            .PicsType = gstrctKDHT.strPackType
            .Cstmid = gstrctKDHT.strCstmid
            .CstmCode = gstrctKDHT.strCstmCode
            .CenterCode = gstrctKDPP.strCenterCode
            .Bhk = gstrctKDPP.strBhk
            .ItemID = "W"
            .ItemCode = gstrctPPDispPart.strItemInCode
        End With
        If Not fGetSerialNoMain(1, pstrSerial) Then Exit Function
        fMakeDelvSerial = True
    End Function


    '== ↓シリアル番号の採番処理 ===================================================

    '*******************************************************************************
    '* 機能     : シリアル番号の採番
    '* 引数     : pintLabelCount       Integer      デリバリーラベルの枚数
    '* 戻り値   : Boolean　True:OK False:NG
    '* 備考     : なし
    '*******************************************************************************
    Public Function fGetSerialNoMain(ByVal pintLabelCount As Integer, ByRef pstrSerialNo As String) As Boolean
        Dim wstrSerialFrom As String        'ｼﾘｱﾙFrom
        Dim wstrSerialTo As String          'ｼﾘｱﾙTo

        fGetSerialNoMain = False

        'ラベル枚数の取得
        mintLabelCount = pintLabelCount

        '部品番号ｼﾘｱﾙ番号の取得
        If Not wfGetSerial(wstrSerialFrom, wstrSerialTo) Then Exit Function

        '※シリアルFrom 〜 To を各ラベルに割り当てていく
        '***********************************************
        Dim i As Integer
        Dim SerialNo As String

        SerialNo = wstrSerialFrom

        For i = 0 To mintLabelCount - 1
            'ﾃﾞﾘﾊﾞﾘｰﾗﾍﾞﾙのｼﾘｱﾙ変数 = SerialNo
            SerialNo = CStr(CInt(SerialNo) + 1).PadLeft(6, "0")
            If SerialNo = "999999" Then SerialNo = "000001"
        Next
        '***********************************************

        pstrSerialNo = SerialNo
        fGetSerialNoMain = True
    End Function

    '*******************************************************************************
    '* 機能     : シリアル番号の取得
    '* 引数     : pstrSerialFrom       String      シリアルFrom
    '*          : pstrSerialTo         String      シリアルTo
    '* 戻り値   : Boolean　True:OK False:NG
    '* 備考     : なし
    '*******************************************************************************
    Private Function wfGetSerial(ByRef pstrSerialFrom As String, ByRef pstrSerialTo As String) As Boolean
        Dim wstrGetData As String

        wfGetSerial = False

        'PSERIAL検索処理
        If Not wfSearchPserial(wstrGetData) Then Exit Function

        'SerialFrom取得
        pstrSerialFrom = wfSerialFrom(wstrGetData)

        'SerialTo取得
        pstrSerialTo = wfSerialTo(pstrSerialFrom)

        'PSERIAL削除
        If wstrGetData <> "" Then
            'PSERIALが取得出来た場合のみ
            If Not wfDelPserial() Then Exit Function
        End If

        'PSERIAL登録処理
        If Not wfInsPserial(pstrSerialTo) Then Exit Function

        wfGetSerial = True
    End Function

    '*******************************************************************************
    '* 機能     : シリアルFromの取得
    '* 引数     : pstrGetData       String      PSERIALから取得したシリアルNo
    '* 戻り値   : String　シリアルFrom
    '* 備考     : なし
    '*******************************************************************************
    Private Function wfSerialFrom(ByVal pstrGetData As String) As String
        Dim wstrSerialFrom As String

        'シリアルFrom取得
        If pstrGetData <> "" Then
            'PSERIALあり
            If pstrGetData >= "999998" Then
                '"999998"を超えたら"000001"へ戻る
                wstrSerialFrom = "000001"
            Else
                '1加算
                wstrSerialFrom = CStr(CLng(pstrGetData) + 1).PadLeft(6, "0")
            End If
        Else
            'PSERIALなし
            wstrSerialFrom = "000001"
        End If

        'シリアルFrom
        wfSerialFrom = wstrSerialFrom
    End Function

    '*******************************************************************************
    '* 機能     : シリアルToの取得
    '* 引数     : pstrSerialFrom       String      シリアルFrom
    '* 戻り値   : String　シリアルTo
    '* 備考     : なし
    '*******************************************************************************
    Private Function wfSerialTo(ByVal pstrSerialFrom As String) As String
        Dim wintSerialTo As Integer

        'シリアルToの設定 (ｼﾘｱﾙFrom + ﾗﾍﾞﾙ枚数)
        wintSerialTo = CInt(pstrSerialFrom) + mintLabelCount - 1

        'シリアルNoが 999998 を超えたら 000001 に戻る
        If wintSerialTo > 999998 Then wintSerialTo -= 999998

        'シリアルTo
        wfSerialTo = CStr(wintSerialTo).PadLeft(6, "0")
    End Function

    '*******************************************************************************
    '* 機能     : PSERIAL検索/登録 条件定義
    '* 引数     : pstrKey         String      検索フィールド名
    '*          : pstrKeyValue    String      検索パラメータ
    '* 戻り値   : 
    '* 備考     : なし
    '*******************************************************************************
    Private Sub wsSetPserialKey(ByRef pstrKey() As String, ByRef pstrKeyValue() As String)

        '検索/登録 条件を作成
        With mstructKey
            pstrKey(0) = "PicsType"
            pstrKey(1) = "Cstmid"
            pstrKey(2) = "CstmCode"
            pstrKey(3) = "CenterCode"
            pstrKey(4) = "Bhk"
            pstrKey(5) = "ItemID"
            pstrKey(6) = "ItemCode"
            pstrKeyValue(0) = .PicsType
            pstrKeyValue(1) = .Cstmid
            pstrKeyValue(2) = .CstmCode
            pstrKeyValue(3) = .CenterCode
            pstrKeyValue(4) = .Bhk
            pstrKeyValue(5) = .ItemID
            pstrKeyValue(6) = .ItemCode
        End With
    End Sub

    '*******************************************************************************
    '* 機能     : PSERIAL検索処理
    '* 引数     : pstrSerialNo    String      取得シリアル番号
    '* 戻り値   : Boolean　True:OK False:NG
    '* 備考     : なし
    '*******************************************************************************
    Private Function wfSearchPserial(ByRef pstrSerialNo As String) As Boolean
        Dim wintRet As Integer
        Dim wstrSerial As String
        Dim wstrKey(6) As String
        Dim wstrKeyValue(6) As String

        wfSearchPserial = False

        '検索条件を作成
        Call wsSetPserialKey(wstrKey, wstrKeyValue)

        'データ検索
        wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PSERIAL, G_CONST_KEY_PSERIALKEY00, "PSL0", wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)
        If wintRet = -1 Then
            'DB接続エラーの場合
            ' DBエラー処理 *********************************************************************************
            Exit Function
        End If

        'SerialNo取得
        If wintRet = 0 Then
            'データあり
            pstrSerialNo = RTrim(gclsDB.Records("PSL0").Item("SerialNo")).PadLeft(6, "0")
        Else
            'データなし
            pstrSerialNo = ""
        End If

        'テーブルクローズ
        gclsDB.fCloseRecord("PSL0")

        wfSearchPserial = True

    End Function

    '*******************************************************************************
    '* 機能     : PSERIAL登録処理
    '* 引数     : pstrSerialTo    String      シリアルTo
    '* 戻り値   : Boolean　True:OK False:NG
    '* 備考     : なし
    '*******************************************************************************
    Private Function wfInsPserial(ByVal pstrSerialTo As String) As Boolean
        Dim wstrKey(8) As String
        Dim wstrKeyValue(8) As String

        wfInsPserial = False

        '登録値を作成
        Call wsSetPserialKey(wstrKey, wstrKeyValue)
        wstrKey(7) = "SerialNo"
        wstrKey(8) = "Filler"
        wstrKeyValue(7) = pstrSerialTo
        wstrKeyValue(8) = Space(8)

        '登録
        If gclsDB.fInsRecord(G_CONST_TBL_PSERIAL, wstrKey, wstrKeyValue) = -1 Then
            '登録失敗
            ' DBエラー処理 *********************************************************************************
            Exit Function
        End If

        wfInsPserial = True
    End Function

    '*******************************************************************************
    '* 機能     : PSERIAL削除処理
    '* 引数     : 
    '* 戻り値   : Boolean　True:OK False:NG
    '* 備考     : なし
    '*******************************************************************************
    Private Function wfDelPserial() As Boolean
        Dim wstrKey(6) As String
        Dim wstrKeyValue(6) As String

        wfDelPserial = False

        '削除条件を作成
        Call wsSetPserialKey(wstrKey, wstrKeyValue)

        'DELETE
        If gclsDB.fDleRecords(G_CONST_TBL_PSERIAL, G_CONST_KEY_PSERIALKEY00, wstrKey, wstrKeyValue) = -1 Then
            '削除失敗
            ' DBエラー処理 *********************************************************************************
            Exit Function
        End If

        wfDelPserial = True
    End Function
    '*******************************************************************************
    '* 機能     : デリバリー在庫追加処理
    '* 引数     : 1.Stockのインデックス
    '*          : 
    '* 戻り値   : -1:NG 0:OK
    '* 備考     : なし
    '*******************************************************************************
    Private Function fSetStock(ByVal pstrKey As String) As Integer
        Dim wstrKey(19), wstrKeyValue(19) As String
        fSetStock = -1
        Try
            With gclsDB.Records(pstrKey)
                wstrKey(0) = "PicsType" : wstrKeyValue(0) = .Item(wstrKey(0))
                wstrKey(1) = "Cstmid" : wstrKeyValue(1) = .Item(wstrKey(1))
                wstrKey(2) = "CstmCode" : wstrKeyValue(2) = .Item(wstrKey(2))
                wstrKey(3) = "CenterCode" : wstrKeyValue(3) = .Item(wstrKey(3))
                wstrKey(4) = "Bhk" : wstrKeyValue(4) = .Item(wstrKey(4))
                wstrKey(5) = "Location" : wstrKeyValue(5) = gstrctDelvLabelData.strDLoctn
                wstrKey(6) = "SerialNo" : wstrKeyValue(6) = gstrctDelvLabelData.strDSerial
                wstrKey(7) = "SerialID" : wstrKeyValue(7) = .Item(wstrKey(7))
                wstrKey(8) = "Filler1" : wstrKeyValue(8) = .Item(wstrKey(8))
                wstrKey(9) = "Itemid" : wstrKeyValue(9) = .Item(wstrKey(9))
                wstrKey(10) = "ItemCode" : wstrKeyValue(10) = .Item(wstrKey(10))
                wstrKey(11) = "DispItemCode" : wstrKeyValue(11) = .Item(wstrKey(11))
                wstrKey(12) = "Qty" : wstrKeyValue(12) = gstrctDelvLabelData.strDQty
                wstrKey(13) = "ItemWeight" : wstrKeyValue(13) = .Item(wstrKey(13))
                wstrKey(14) = "ZaikoStatus" : wstrKeyValue(14) = G_CONST_ST_STOCK_INSTOCK
                wstrKey(15) = "StockDate" : wstrKeyValue(15) = .Item(wstrKey(15))
                wstrKey(16) = "StockTime" : wstrKeyValue(16) = .Item(wstrKey(16))
                wstrKey(17) = "StockEmp" : wstrKeyValue(17) = .Item(wstrKey(17))
                wstrKey(18) = "CartonType" : wstrKeyValue(18) = .Item(wstrKey(18))
                wstrKey(19) = "Filler2" : wstrKeyValue(19) = .Item(wstrKey(19))
            End With

            '登録処理
            If gclsDB.fInsRecord(G_CONST_TBL_STOCK, wstrKey, wstrKeyValue) = -1 Then
                '登録失敗
                Exit Function
            End If
            fSetStock = 0
        Catch ex As Exception
            sErrLog(gAppName, "fSetStock", ex.ToString)
        End Try
    End Function

    '*******************************************************************************
    '* 機能     : デリバリー在庫削除処理
    '* 引数     : 1.Stockのインデックス
    '*          : 
    '* 戻り値   : -1:NG 0:Not Found 1:OK
    '* 備考     : なし
    '*******************************************************************************
    Private Function fDeleteStock(ByVal pstrKey As String) As Integer
        Dim wstrKey(9), wstrKeyValue(9) As String
        Dim wintRet As Integer = -1
        Dim wintRet2 As Integer = -1
        Dim STOCK_KEY = "STOCK01"
        fDeleteStock = -1
        Try
            With gclsDB.Records(pstrKey)
                If RTrim(.Item("ItemInID")) = "D" Then
                    wstrKey(0) = "PicsType" : wstrKeyValue(0) = RTrim(.Item("PicsType"))
                    wstrKey(1) = "Cstmid" : wstrKeyValue(1) = RTrim(.Item("Cstmid"))
                    wstrKey(2) = "CstmCode" : wstrKeyValue(2) = RTrim(.Item("CstmCode"))
                    wstrKey(3) = "CenterCode" : wstrKeyValue(3) = RTrim(.Item("CenterCode"))
                    wstrKey(4) = "Bhk" : wstrKeyValue(4) = RTrim(.Item("Bhk"))
                    wstrKey(5) = "Location" : wstrKeyValue(5) = RTrim(.Item("StockLctn"))
                    wstrKey(6) = "Itemid" : wstrKeyValue(6) = RTrim(.Item("ItemInID"))
                    wstrKey(7) = "ItemCode" : wstrKeyValue(7) = RTrim(.Item("ItemInCode"))
                    wstrKey(8) = "Qty" : wstrKeyValue(8) = RTrim(.Item("BunkatuJ"))
                    wstrKey(9) = "SerialNo" : wstrKeyValue(9) = RTrim(.Item("SerialNo"))
                    'wstrKey(9) = "SerialNo" : wstrKeyValue(9) = RTrim(.Item("PlanSerial"))
                    wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY01, STOCK_KEY, wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)

                    If wintRet = 0 Then
                        If gclsDB.Records(STOCK_KEY).Item("ZaikoStatus") = "7" Then
                            If gclsDB.Records(STOCK_KEY).Delete() <> 0 Then
                                Exit Function
                            End If
                        Else 'とりあえずEにステータス変更
                            gclsDB.Setcolumn = "ZaikoStatus"
                            gclsDB.SetData = "E"
                            If gclsDB.fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY01, wstrKey, wstrKeyValue) <> 0 Then
                                Exit Function
                            End If
                        End If
                        fDeleteStock = 1
                    ElseIf wintRet = 4 Then
                        fDeleteStock = 0
                        Exit Function
                    Else
                        Exit Function
                    End If
                End If
            End With

        Catch ex As Exception
            sErrLog(gAppName, "fDeleteStock", ex.ToString)
        Finally
            If wintRet <> -1 Then gclsDB.fCloseRecord(STOCK_KEY)
        End Try
    End Function

    '*******************************************************************************
    '* 機能     : 在庫の更新処理
    '* 引数     : 1.PACKCPのインデックス,2.シリアル
    '*          : 
    '* 戻り値   : -1:NG 0:OK
    '* 備考     : なし
    '*******************************************************************************
    Private Function fUpdateStock2(ByVal pstrKey As String, ByVal pstrSerial As String) As Integer
        Dim wstrKey(9), wstrKeyValue(9) As String
        Dim wstrCrntStat As String
        Dim wintRet As Integer = -1
        Dim STOCK_KEY = "STOCK01"
        fUpdateStock2 = -1
        Try
            With gclsDB.Records(pstrKey)
                If RTrim(.Item("ItemInID")) = "P" Then
                    wstrKey(0) = "PicsType" : wstrKeyValue(0) = RTrim(.Item("PicsType"))
                    wstrKey(1) = "Cstmid" : wstrKeyValue(1) = RTrim(.Item("Cstmid"))
                    wstrKey(2) = "CstmCode" : wstrKeyValue(2) = RTrim(.Item("CstmCode"))
                    wstrKey(3) = "CenterCode" : wstrKeyValue(3) = RTrim(.Item("CenterCode"))
                    wstrKey(4) = "Bhk" : wstrKeyValue(4) = RTrim(.Item("Bhk"))
                    wstrKey(5) = "Location" : wstrKeyValue(5) = RTrim(.Item("StockLctn"))
                    wstrKey(6) = "Itemid" : wstrKeyValue(6) = RTrim(.Item("ItemInID"))
                    wstrKey(7) = "ItemCode" : wstrKeyValue(7) = RTrim(.Item("ItemInCode"))
                    wstrKey(8) = "Qty" : wstrKeyValue(8) = RTrim(.Item("BunkatuJ"))
                    '
                    wstrKey(9) = "SerialNo" : wstrKeyValue(9) = pstrSerial
                    'wstrKey(9) = "SerialNo" : wstrKeyValue(9) = RTrim(.Item("SerialNo"))
                    wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY01, STOCK_KEY, wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)
                    If wintRet = 0 Then
                        If fGetStockStatus(wstrCrntStat, pstrKey, 1) <> 0 Then
                            Exit Function
                        End If

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

                    ElseIf wintRet = 4 Then
                        fUpdateStock2 = 0
                        Exit Function
                    Else
                        Exit Function
                    End If
                End If
            End With
            fUpdateStock2 = 0

        Catch ex As Exception
            sErrLog(gAppName, "fDeleteStock", ex.ToString)
        Finally
            If wintRet <> -1 Then gclsDB.fCloseRecord(STOCK_KEY)
        End Try
    End Function
    '*******************************************************************************
    '* 機能     : 対象フラグでのPACKCPの検索処理
    '* 引数     : 1.ItemGr,2.検索対象のPickFlag
    '*          : 
    '* 戻り値   : -1:NG 0:Not Found 1:OK
    '* 備考     : なし
    '*******************************************************************************
    Public Function fCheckPackCP(ByVal pstrItemGr As String, Optional ByVal pstrFlag As String = "1") As Integer
        Dim wstrKey(6), wstrKeyValue(6) As String
        Dim wintRet As Integer = -1
        Dim M_KEY_CP01 As String = "KEYCP01"
        fCheckPackCP = -1
        wstrKey(0) = "ItemGr" : wstrKeyValue(0) = pstrItemGr
        wstrKey(1) = "ItemCode" : wstrKeyValue(1) = Mid(pstrItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
        wstrKey(2) = "SortLctn1" : wstrKeyValue(2) = Space(5)
        wstrKey(3) = "SortLctn2" : wstrKeyValue(3) = Space(5)
        wstrKey(4) = "SortLctn3" : wstrKeyValue(4) = Space(5)
        wstrKey(5) = "ItemInCode" : wstrKeyValue(5) = Space(30)
        wstrKey(6) = "TempSerial" : wstrKeyValue(6) = Space(6)

        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 sPickFlag 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("PickFlag", result) Then
                        sPickFlag = RTrim(result)
                    End If


                    If RTrim(sItemGr) = RTrim(wstrKeyValue(0)) AndAlso RTrim(sItemCode) = RTrim(wstrKeyValue(1)) Then
                        If RTrim(sPickFlag) = pstrFlag Then
                            If fCheckPackCP = -1 Then fCheckPackCP = 1
                        Else
                            fCheckPackCP = 0
                        End If
                    Else
                        If fCheckPackCP = -1 Then fCheckPackCP = 0
                        Exit Do
                    End If




                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If


                Loop

            Else

                Exit Function

            End If

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






        '    wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY03, M_KEY_CP01, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        '    Select Case wintRet
        '        Case 0
        '            Do
        '                With gclsDB.Records(M_KEY_CP01)
        '                    If RTrim(.Item("ItemGr")) = RTrim(wstrKeyValue(0)) AndAlso RTrim(.Item("ItemCode")) = RTrim(wstrKeyValue(1)) Then
        '                        If RTrim(.Item("PickFlag")) = pstrFlag Then
        '                            If fCheckPackCP = -1 Then fCheckPackCP = 1
        '                        Else
        '                            fCheckPackCP = 0
        '                        End If
        '                    Else
        '                        If fCheckPackCP = -1 Then fCheckPackCP = 0
        '                        Exit Do
        '                    End If
        '                    If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Function
        '                End With
        '            Loop
        '        Case 9
        '            fCheckPackCP = 0
        '            Exit Function
        '        Case Else
        '            Exit Function
        '    End Select

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

    '*******************************************************************************
    '* 機能     : ロケーションの開放処理
    '* 引数     : 1.開放対象のロケーション
    '*          : 
    '* 戻り値   : -1:NG 0:OK
    '* 備考     : なし
    '*******************************************************************************
    Public Function fReleaseLctn(ByVal pstrLctn As String) As Integer
        Dim wstrKey(3), wstrKeyValue(3) As String
        Dim wintRet As Integer = -1
        Dim wintRet2 As Integer = -1
        Dim wbReleaseFlg As Boolean = False
        Dim KEY01 As String = "KEY1"
        fReleaseLctn = -1
        wstrKey(0) = "CenterCode" : wstrKeyValue(0) = gstrctKDPP.strCenterCode
        wstrKey(1) = "Bhk" : wstrKeyValue(1) = gstrctKDPP.strBhk
        wstrKey(2) = "Location" : wstrKeyValue(2) = pstrLctn
        wstrKey(3) = "Product" : wstrKeyValue(3) = Space(6)
        Try
            wintRet = gclsDB.fOpenRecord(G_CONST_TBL_LOCATION, G_CONST_KEY_LOCATIONKEY00, KEY01, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
            Select Case wintRet
                Case 0
                    Do
                        With gclsDB.Records(KEY01)
                            If RTrim(.Item("CenterCode")) = RTrim(wstrKeyValue(0)) AndAlso RTrim(.Item("Bhk")) = RTrim(wstrKeyValue(1)) AndAlso RTrim(.Item("Location")) = RTrim(wstrKeyValue(2)) Then
                                wstrKeyValue(3) = RTrim(.Item("Product"))
                                If CInt(RTrim(.Item("Qty"))) = 0 Then
                                    wbReleaseFlg = True
                                End If
                                Exit Do
                            Else
                                Exit Function
                            End If
                            If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Function
                        End With
                    Loop
                Case Else
                    Exit Function
            End Select
            If wbReleaseFlg Then
                gclsDB.Setcolumn = "AkiKB"
                gclsDB.SetData = "0"
                wintRet2 = gclsDB.fUpdRecords(G_CONST_TBL_LOCATION, G_CONST_KEY_LOCATIONKEY00, wstrKey, wstrKeyValue)
                If wintRet2 <> 0 Then
                    sErrLog(gAppName, "fReleaseLctn", gclsDB.ErrMsg)
                    Exit Function
                End If
            End If

            fReleaseLctn = 0
        Catch ex As Exception
            sErrLog(gAppName, "fReleaseLctn", ex.ToString)
        Finally
            If wintRet <> -1 Then gclsDB.fCloseRecord(KEY01)
        End Try
    End Function
End Module
