
'*******************************************************************************
'* 作成者   : 株式会社エコー・システム 
'* 作成日   : 2004/10/02
'* 概要     : PICS2004 共通処理
'* 更新履歴 : 
'* ﾊﾞｰｼﾞｮﾝ  : 1.0
'*******************************************************************************
Imports System
Imports System.Linq
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports BTClientLib
Imports System.IO
Imports System.Reflection
Imports Newtonsoft

Module modPublicE

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

    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************
    '
    'E45
    '
    '
    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************

    '/*
    '|| 関数名：fSearchStock
    '|| 概要  ：
    '*/
    Public Function fSearchStock() As Integer

        Dim wintRet As Integer
        Dim wstrLocation As String
        Dim wstrSerial As String

        fSearchStock = -1

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

        wintRet = fResetStock(wstrLocation, wstrSerial)
        If wintRet = -1 Then
            'BtLib.Transaction.Abort()
            Exit Function
        ElseIf wintRet = -2 Then
            'BtLib.Transaction.End()
            fSearchStock = -2
            Exit Function
        End If

        wintRet = fSetPKCP(wstrLocation, wstrSerial)
        If wintRet = -1 Then
            'BtLib.Transaction.Abort()
            Exit Function
        Else
            fSearchStock = 0
        End If

        '// ﾄﾗﾝｻﾞｸｼｮﾝ完了
        'BtLib.Transaction.End()

        gstrctPPDispPart.strLocation = wstrLocation
        gstrctPPDispPart.strLocation1 = Mid(wstrLocation, 1, 2)
        gstrctPPDispPart.strLocation2 = Mid(wstrLocation, 3, 3)
        gstrctPPDispPart.strSerial = wstrSerial
        gstrctPPDispPart.bLocked = True

    End Function


    '/*
    '|| 関数名：fResetStock
    '|| 概要  ：
    '*/
    Public Function fResetStock(ByRef pstrLocation As String, ByRef pstrSerial As String) As Integer

        Dim rtn As Integer
        Dim bFound As Boolean
        Dim wstrKey(2) As String
        Dim wstrKeyValue(2) As String
        Dim wstrKey2(9) As String
        Dim wstrKeyValue2(9) As String
        Dim wstrKey3(12) As String
        Dim wstrKeyValue3(12) As String
        Dim wstrLocation As String
        Dim wstrQty As String
        Dim wstrNewLocation As String
        Dim wstrNewSerial As String
        Dim wstrNewStockDate As String
        Dim wstrNewStockTime As String
        Dim sSQL As String
        Dim wstrWhere As String

        fResetStock = -1
        Try

            '// PKCPから検索条件を取得
            With gstrctPPDispPart
                wstrKey(0) = "ItemCode" : wstrKeyValue(0) = .strItemCode
                wstrKey(1) = "ItemInCode" : wstrKeyValue(1) = .strItemInCode
                wstrKey(2) = "PlanSerial" : wstrKeyValue(2) = .strSerial
            End With

            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_PACKAP + " WHERE " + wstrWhere)

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemCode As String = ""
            Dim sItemInCode As String = ""
            Dim sPlanSerial As String = ""
            Dim sPicsType As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""
            Dim sCenterCode As String = ""
            Dim sBhk As String = ""

            Dim sStockLctn As String = ""
            Dim sItemInID As String = ""
            Dim sBunkatuJ As String = ""
            Dim sItemMCode As String = ""

            If tmpStr.Count > 0 Then

                values = tmpStr(0)

                Dim result As String = Nothing
                If values.TryGetValue("ItemCode", result) Then
                    sItemCode = RTrim(result)
                End If
                If values.TryGetValue("ItemInCode", result) Then
                    sItemInCode = RTrim(result)
                End If
                If values.TryGetValue("PlanSerial", result) Then
                    sPlanSerial = 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("CenterCode", result) Then
                    sCenterCode = RTrim(result)
                End If
                If values.TryGetValue("Bhk", result) Then
                    sBhk = RTrim(result)
                End If

                If values.TryGetValue("StockLctn", result) Then
                    sStockLctn = 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("StockLctn", result) Then
                    sStockLctn = RTrim(result)
                End If
                If values.TryGetValue("BunkatuJ", result) Then
                    sBunkatuJ = RTrim(result)
                End If
                If values.TryGetValue("ItemMCode", result) Then
                    sItemMCode = RTrim(result)
                End If


                If wstrKeyValue(0) = RTrim(sItemCode) And _
                   wstrKeyValue(1) = RTrim(sItemInCode) And _
                   wstrKeyValue(2) = RTrim(sPlanSerial) Then

                    wstrKeyValue2(0) = RTrim(sPicsType)
                    wstrKeyValue2(1) = RTrim(sCstmid)
                    wstrKeyValue2(2) = RTrim(sCstmCode)
                    wstrKeyValue2(3) = RTrim(sCenterCode)
                    wstrKeyValue2(4) = RTrim(sBhk)
                    wstrKeyValue2(5) = RTrim(sStockLctn)
                    wstrKeyValue2(6) = RTrim(sItemInID)
                    wstrKeyValue2(7) = RTrim(sItemInCode)
                    wstrKeyValue2(8) = Space(5)
                    wstrKeyValue2(9) = Space(6)
                    wstrLocation = RTrim(sStockLctn)
                    wstrQty = RTrim(sBunkatuJ)

                    wstrKeyValue3(0) = RTrim(sPicsType)
                    wstrKeyValue3(1) = RTrim(sCstmid)
                    wstrKeyValue3(2) = RTrim(sCstmCode)
                    wstrKeyValue3(3) = RTrim(sCenterCode)
                    wstrKeyValue3(4) = RTrim(sBhk)
                    wstrKeyValue3(5) = RTrim(sItemInID)
                    wstrKeyValue3(6) = RTrim(sItemInCode)
                    wstrKeyValue3(7) = "3"
                    wstrKeyValue3(8) = RTrim(sBunkatuJ)
                    wstrKeyValue3(9) = RTrim(sItemMCode)
                    wstrKeyValue3(10) = Space(8)
                    wstrKeyValue3(11) = Space(4)
                    wstrKeyValue3(12) = Space(6)

                Else
                    'gclsDB.fCloseRecord("PKCP01")
                    Exit Function
                End If


            Else

                Exit Function

            End If


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

            wstrWhere = ""
            wstrWhere = wstrKey2(0) & " = '" & wstrKeyValue(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) & "'"
            wstrWhere &= " and " & wstrKey2(8) & " = '" & wstrKeyValue2(8) & "'"
            wstrWhere &= " and " & wstrKey2(9) & " = '" & wstrKeyValue2(9) & "'"

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


            values = New Dictionary(Of String, String)
            sPicsType = ""
            sCstmid = ""
            sCstmCode = ""
            sCenterCode = ""
            sBhk = ""

            Dim sLocation As String = ""
            Dim sItemid As String = ""
            sItemCode = ""
            Dim sQty As String = ""
            Dim ssQty As String = ""
            Dim sSerialNo As String = ""
            Dim sZaikoStatus As String = ""
            Dim i As Integer = 0

            bFound = False

            If tmpStr.Count > 0 Then

                Do

                    values = tmpStr(i)

                    Dim result As String = Nothing
                    
                    If values.TryGetValue("PicsType", result) Then
                        sPicsType = RTrim(result)
                    End If
                    If values.TryGetValue("Cstmid", result) Then
                        sCstmid = RTrim(result)
                    End If
                    If values.TryGetValue("CstmCode", result) Then
                        sCstmCode = RTrim(result)
                    End If
                    If values.TryGetValue("CenterCode", result) Then
                        sCenterCode = RTrim(result)
                    End If
                    If values.TryGetValue("Bhk", result) Then
                        sBhk = RTrim(result)
                    End If

                    If values.TryGetValue("Location", result) Then
                        sLocation = RTrim(result)
                    End If
                    If values.TryGetValue("Itemid", result) Then
                        sItemid = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("Qty", result) Then
                        ssQty = RTrim(result)
                    End If
                    If values.TryGetValue("SerialNo", result) Then
                        sSerialNo = RTrim(result)
                    End If
                    If values.TryGetValue("ZaikoStatus", 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(sLocation) And _
                           wstrKeyValue2(6) = RTrim(sItemid) And _
                           wstrKeyValue2(7) = RTrim(sItemCode) Then

                        wstrKeyValue2(8) = RTrim(sQty)
                        wstrKeyValue2(9) = RTrim(sSerialNo)

                        If G_CONST_ST_STOCK_INSTOCK = RTrim(sZaikoStatus) Or G_CONST_ST_STOCK_RESERVED1 = RTrim(sZaikoStatus) Or G_CONST_ST_STOCK_RESERVED2 = RTrim(sZaikoStatus) Then

                            wstrWhere = ""
                            wstrWhere = wstrKey2(0) & " = '" & wstrKeyValue(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) & "'"
                            wstrWhere &= " and " & wstrKey2(8) & " = '" & wstrKeyValue2(8) & "'"
                            wstrWhere &= " and " & wstrKey2(9) & " = '" & wstrKeyValue2(9) & "'"

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

                            affected_rows = dbClient.Execute(sSQL)


                            If affected_rows = 0 Then
                                Exit Function
                            End If


                        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

            wstrKey3(0) = "PicsType"
            wstrKey3(1) = "Cstmid"
            wstrKey3(2) = "CstmCode"
            wstrKey3(3) = "CenterCode"
            wstrKey3(4) = "Bhk"
            wstrKey3(5) = "Itemid"
            wstrKey3(6) = "ItemCode"
            wstrKey3(7) = "ZaikoStatus"
            wstrKey3(8) = "Qty"
            wstrKey3(9) = "CartonType"
            wstrKey3(10) = "StockDate"
            wstrKey3(11) = "StockTime"
            wstrKey3(12) = "SerialNo"

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

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


            values = New Dictionary(Of String, String)
            sPicsType = ""
            sCstmid = ""
            sCstmCode = ""
            sCenterCode = ""
            sBhk = ""

            sLocation = ""
            sItemid = ""
            sItemCode = ""
            sQty = ""
            sSerialNo = ""
            sZaikoStatus = ""

            Dim sCartonType As String = ""
            Dim sStockDate As String = ""
            Dim sStockTime As String = ""

            i = 0

            bFound = False

            If tmpStr.Count > 0 Then

                Do



                    values = tmpStr(i)

                    Dim result As String = Nothing

                    If values.TryGetValue("PicsType", result) Then
                        sPicsType = RTrim(result)
                    End If
                    If values.TryGetValue("Cstmid", result) Then
                        sCstmid = RTrim(result)
                    End If
                    If values.TryGetValue("CstmCode", result) Then
                        sCstmCode = RTrim(result)
                    End If
                    If values.TryGetValue("CenterCode", result) Then
                        sCenterCode = RTrim(result)
                    End If
                    If values.TryGetValue("Bhk", result) Then
                        sBhk = RTrim(result)
                    End If

                    If values.TryGetValue("Location", result) Then
                        sLocation = RTrim(result)
                    End If
                    If values.TryGetValue("Itemid", result) Then
                        sItemid = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("Qty", result) Then
                        ssQty = RTrim(result)
                    End If
                    If values.TryGetValue("SerialNo", result) Then
                        sSerialNo = RTrim(result)
                    End If
                    If values.TryGetValue("ZaikoStatus", result) Then
                        sZaikoStatus = RTrim(result)
                    End If

                    If values.TryGetValue("CartonType", result) Then
                        sCartonType = RTrim(result)
                    End If
                    If values.TryGetValue("StockDate", result) Then
                        sStockDate = RTrim(result)
                    End If
                    If values.TryGetValue("StockTime", result) Then
                        sStockTime = RTrim(result)
                    End If


                    If wstrKeyValue3(0) = RTrim(sPicsType) And _
                               wstrKeyValue3(1) = RTrim(sCstmid) And _
                               wstrKeyValue3(2) = RTrim(sCstmCode) And _
                               wstrKeyValue3(3) = RTrim(sCenterCode) And _
                               wstrKeyValue3(4) = RTrim(sBhk) And _
                               wstrKeyValue3(5) = RTrim(sItemid) And _
                               wstrKeyValue3(6) = RTrim(sItemCode) And _
                               wstrKeyValue3(7) = RTrim(sZaikoStatus) And _
                               wstrKeyValue3(8) = RTrim(sQty) And _
                               wstrKeyValue3(9) = RTrim(sCartonType) Then

                        wstrKeyValue3(10) = RTrim(sStockDate)
                        wstrKeyValue3(11) = RTrim(sStockTime)
                        wstrKeyValue3(12) = RTrim(sSerialNo)

                        If wstrLocation <> RTrim(sLocation) And G_CONST_ST_STOCK_INSTOCK = RTrim(sZaikoStatus) Then

                            wstrNewLocation = RTrim(sLocation)
                            wstrNewSerial = RTrim(sSerialNo)
                            wstrNewStockDate = RTrim(sStockDate)
                            wstrNewStockTime = RTrim(sStockTime)
                            bFound = True
                            Exit Do

                        End If

                    Else
                        Exit Do
                    End If

                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If

                Loop

            End If

            If bFound Then

                wstrKeyValue3(10) = wstrNewStockDate
                wstrKeyValue3(11) = wstrNewStockTime
                wstrKeyValue3(12) = wstrNewSerial

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

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

                affected_rows = dbClient.Execute(sSQL)


                If affected_rows = 0 Then
                    Exit Function
                End If


                pstrLocation = wstrNewLocation
                pstrSerial = wstrNewSerial

                fResetStock = 0
            Else
                fResetStock = -2
            End If

            Exit Function

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



            'rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY06, "PKCP01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)

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

            'With gclsDB.Records("PKCP01")

            '    If wstrKeyValue(0) = RTrim(.Item("ItemCode")) And _
            '       wstrKeyValue(1) = RTrim(.Item("ItemInCode")) And _
            '       wstrKeyValue(2) = RTrim(.Item("PlanSerial")) Then

            '        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("StockLctn"))
            '        wstrKeyValue2(6) = RTrim(.Item("ItemInID"))
            '        wstrKeyValue2(7) = RTrim(.Item("ItemInCode"))
            '        wstrKeyValue2(8) = Space(5)
            '        wstrKeyValue2(9) = Space(6)
            '        wstrLocation = RTrim(.Item("StockLctn"))
            '        wstrQty = RTrim(.Item("BunkatuJ"))

            '        wstrKeyValue3(0) = RTrim(.Item("PicsType"))
            '        wstrKeyValue3(1) = RTrim(.Item("Cstmid"))
            '        wstrKeyValue3(2) = RTrim(.Item("CstmCode"))
            '        wstrKeyValue3(3) = RTrim(.Item("CenterCode"))
            '        wstrKeyValue3(4) = RTrim(.Item("Bhk"))
            '        wstrKeyValue3(5) = RTrim(.Item("ItemInID"))
            '        wstrKeyValue3(6) = RTrim(.Item("ItemInCode"))
            '        wstrKeyValue3(7) = "3"
            '        wstrKeyValue3(8) = RTrim(.Item("BunkatuJ"))
            '        wstrKeyValue3(9) = RTrim(.Item("ItemMCode"))
            '        wstrKeyValue3(10) = Space(8)
            '        wstrKeyValue3(11) = Space(4)
            '        wstrKeyValue3(12) = Space(6)

            '    Else
            '        gclsDB.fCloseRecord("PKCP01")
            '        Exit Function
            '    End If

            'End With

            'gclsDB.fCloseRecord("PKCP01")

            '// そのロケーションの在庫のステータス更新
            'wstrKey2(0) = "PicsType"
            'wstrKey2(1) = "Cstmid"
            'wstrKey2(2) = "CstmCode"
            'wstrKey2(3) = "CenterCode"
            'wstrKey2(4) = "Bhk"
            'wstrKey2(5) = "Location"
            'wstrKey2(6) = "Itemid"
            'wstrKey2(7) = "ItemCode"
            'wstrKey2(8) = "Qty"
            'wstrKey2(9) = "SerialNo"

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

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

            'bFound = False
            'If rtn = 0 Then
            '    Do
            '        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("Location")) And _
            '               wstrKeyValue2(6) = RTrim(.Item("Itemid")) And _
            '               wstrKeyValue2(7) = RTrim(.Item("ItemCode")) Then

            '                wstrKeyValue2(8) = RTrim(.Item("Qty"))
            '                wstrKeyValue2(9) = RTrim(.Item("SerialNo"))

            '                If G_CONST_ST_STOCK_INSTOCK = RTrim(.Item("ZaikoStatus")) Or G_CONST_ST_STOCK_RESERVED1 = RTrim(.Item("ZaikoStatus")) Or G_CONST_ST_STOCK_RESERVED2 = RTrim(.Item("ZaikoStatus")) Then
            '                    '// DB更新
            '                    With gclsDB
            '                        .Setcolumn = "ZaikoStatus"
            '                        .SetData = G_CONST_ST_STOCK_MISSING

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

            '            Else
            '                Exit Do
            '            End If

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

            '        End With
            '    Loop
            'End If

            'gclsDB.fCloseRecord("STOCK1")

            '// 代替のストックの検索
            'wstrKey3(0) = "PicsType"
            'wstrKey3(1) = "Cstmid"
            'wstrKey3(2) = "CstmCode"
            'wstrKey3(3) = "CenterCode"
            'wstrKey3(4) = "Bhk"
            'wstrKey3(5) = "Itemid"
            'wstrKey3(6) = "ItemCode"
            'wstrKey3(7) = "ZaikoStatus"
            'wstrKey3(8) = "Qty"
            'wstrKey3(9) = "CartonType"
            'wstrKey3(10) = "StockDate"
            'wstrKey3(11) = "StockTime"
            'wstrKey3(12) = "SerialNo"

            'rtn = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY06, "STOCK1", wstrKey3, wstrKeyValue3, BtLib.Operation.GetGreaterOrEqual)

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

            'bFound = False
            'If rtn = 0 Then
            '    Do
            '        With gclsDB.Records("STOCK1")
            '            If wstrKeyValue3(0) = RTrim(.Item("PicsType")) And _
            '               wstrKeyValue3(1) = RTrim(.Item("Cstmid")) And _
            '               wstrKeyValue3(2) = RTrim(.Item("CstmCode")) And _
            '               wstrKeyValue3(3) = RTrim(.Item("CenterCode")) And _
            '               wstrKeyValue3(4) = RTrim(.Item("Bhk")) And _
            '               wstrKeyValue3(5) = RTrim(.Item("Itemid")) And _
            '               wstrKeyValue3(6) = RTrim(.Item("ItemCode")) And _
            '               wstrKeyValue3(7) = RTrim(.Item("ZaikoStatus")) And _
            '               wstrKeyValue3(8) = RTrim(.Item("Qty")) And _
            '               wstrKeyValue3(9) = RTrim(.Item("CartonType")) Then

            '                wstrKeyValue3(10) = RTrim(.Item("StockDate"))
            '                wstrKeyValue3(11) = RTrim(.Item("StockTime"))
            '                wstrKeyValue3(12) = RTrim(.Item("SerialNo"))

            '                If wstrLocation <> RTrim(.Item("Location")) And G_CONST_ST_STOCK_INSTOCK = RTrim(.Item("ZaikoStatus")) Then

            '                    wstrNewLocation = RTrim(.Item("Location"))
            '                    wstrNewSerial = RTrim(.Item("SerialNo"))
            '                    wstrNewStockDate = RTrim(.Item("StockDate"))
            '                    wstrNewStockTime = RTrim(.Item("StockTime"))
            '                    bFound = True
            '                    Exit Do

            '                End If

            '            Else
            '                Exit Do
            '            End If

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

            '        End With
            '    Loop
            'End If

            'gclsDB.fCloseRecord("STOCK1")

            '// 代替のストックの更新
        '    If bFound Then

        '        wstrKeyValue3(10) = wstrNewStockDate
        '        wstrKeyValue3(11) = wstrNewStockTime
        '        wstrKeyValue3(12) = wstrNewSerial
        '        With gclsDB
        '            .Setcolumn = "ZaikoStatus"
        '            .SetData = G_CONST_ST_STOCK_RESERVED2

        '            If .fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY06, wstrKey3, wstrKeyValue3) = -1 Then
        '                Exit Function
        '            End If
        '        End With

        '        pstrLocation = wstrNewLocation
        '        pstrSerial = wstrNewSerial

        '        fResetStock = 0
        '    Else
        '        fResetStock = -2
        '    End If

        '    Exit Function

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

    End Function

    '/*
    '|| 関数名：fSetPKCP
    '|| 概要  ：
    '*/
    Public Function fSetPKCP(ByVal pstrLocation As String, ByVal pstrSerial As String) As Integer

        Dim rtn As Integer
        Dim wstrKey(2) As String
        Dim wstrKeyValue(2) As String
        Dim wstrLocation As String
        Dim wstrWhere As String
        Dim sSQL As String

        Try

            fSetPKCP = -1

            '// PKCPから検索条件を取得
            With gstrctPPDispPart
                wstrKey(0) = "ItemCode" : wstrKeyValue(0) = .strItemCode
                wstrKey(1) = "ItemInCode" : wstrKeyValue(1) = .strItemInCode
                wstrKey(2) = "PlanSerial" : wstrKeyValue(2) = .strSerial
                wstrLocation = .strLocation
            End With

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

            sSQL = "UPDATE " + G_CONST_TBL_PACKCP + " SET StockLctn='" _
                                                             + pstrLocation _
                                                             + "' , PlanSerial='" _
                                                             + pstrSerial _
                                                             + "' WHERE " + wstrWhere


            affected_rows = dbClient.Execute(sSQL)


            If affected_rows = 0 Then
                Exit Function
            End If

            'With gclsDB
            '    .Setcolumn = "StockLctn,PlanSerial"
            '    .SetData = pstrLocation & "," & pstrSerial

            '    If .fUpdRecords(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY06, wstrKey, wstrKeyValue) = -1 Then
            '        Exit Function
            '    End If
            'End With

            gstrctPPDisp.fSetQty(gstrctPPDisp.strCrtnNo & wstrLocation & gstrctPPDispPart.strItemInCode, (0 - CInt(gstrctPPDispPart.strPackQty)))
            gstrctPPDisp.fSetPkg(gstrctPPDisp.strCrtnNo & wstrLocation & gstrctPPDispPart.strItemInCode, -1)
            gstrctPPDisp.fSetQty(gstrctPPDisp.strCrtnNo & pstrLocation & gstrctPPDispPart.strItemInCode, CInt(gstrctPPDispPart.strPackQty))
            gstrctPPDisp.fSetPkg(gstrctPPDisp.strCrtnNo & pstrLocation & gstrctPPDispPart.strItemInCode, 1)

            fSetPKCP = 0

            Exit Function

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

    End Function


    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************
    '
    'E50
    '
    '
    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************

    '/*
    '|| 関数名：fNotPack
    '|| 概要  ：
    '*/
    Public Function fNotPack()

        Dim rtn As Integer
        Dim wintCnt As Integer
        Dim wstrKey(6) As String
        Dim wstrKeyValue(6) As String
        Dim wstrKey2(7) As String
        Dim wstrKeyValue2(7) As String
        Dim wstrWhere As String
        Dim sSQL As String

        fNotPack = -1

        Try

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

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

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

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemGr As String = ""
            Dim sItemCode As String = ""
            Dim sSortLctn1 As String = ""
            Dim sSortLctn2 As String = ""
            Dim sSortLctn3 As String = ""
            Dim sItemInCode As String = ""
            Dim sTempSerial As String = ""
            Dim sPicsType As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""
            Dim sCenterCode As String = ""
            Dim sBhk As String = ""
            Dim sItemInID 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("SortLctn1", result) Then
                        sSortLctn1 = RTrim(result)
                    End If
                    If values.TryGetValue("SortLctn2", result) Then
                        sSortLctn2 = RTrim(result)
                    End If
                    If values.TryGetValue("SortLctn3", result) Then
                        sSortLctn3 = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If
                    If values.TryGetValue("TempSerial", result) Then
                        sTempSerial = RTrim(result)
                    End If

                    If values.TryGetValue("PicsType", result) Then
                        sPicsType = RTrim(result)
                    End If
                    If values.TryGetValue("Cstmid", result) Then
                        sCstmid = RTrim(result)
                    End If
                    If values.TryGetValue("CstmCode", result) Then
                        sCstmCode = RTrim(result)
                    End If
                    If values.TryGetValue("CenterCode", result) Then
                        sCenterCode = RTrim(result)
                    End If
                    If values.TryGetValue("Bhk", result) Then
                        sBhk = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInID", result) Then
                        sItemInID = 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 wstrKeyValue(0) = RTrim(sItemGr) Then

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

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

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

                        affected_rows = dbClient.Execute(sSQL)


                        If affected_rows = 0 Then
                            Exit Function
                        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)
                        wstrKeyValue2(7) = RTrim(sPlanSerial)

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

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


                        If tmpStr1.Count > 0 Then

                            values = tmpStr1(0)

                            result = Nothing
                            Dim sItemid As String = Nothing
                            Dim sSerialNo As String = Nothing
                            Dim sZaikoStatus As String = Nothing

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

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

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

                                    affected_rows = dbClient.Execute(sSQL)

                                ElseIf G_CONST_ST_STOCK_PICKED = sZaikoStatus Then

                                    rtn = fFreeZaikoStatus("STOCK1")
                                    If rtn = -1 Then
                                        'gclsDB.fCloseRecord("PKCP01")
                                        'gclsDB.fCloseRecord("STOCK1")
                                        'BtLib.Transaction.Abort()
                                        Exit Function
                                    ElseIf rtn = -2 Then
                                        fNotPack = -2
                                    End If

                                End If
                            End If


                        Else


                            Exit Function

                        End If


                    Else
                        Exit Do
                    End If


                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If

                Loop

            Else

                Exit Function

            End If

            If fNotPack = -1 Then fNotPack = 0
            'fNotPack = 0
            Exit Function

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



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

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

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

            '                '// PACKCPレコードのステータスを保管部品なしに
            '                With gclsDB
            '                    .Setcolumn = "PickFlag,PairLctn,StockLctn,PlanSerial"
            '                    .SetData = G_CONST_ST_PKCP_NOSTOCK & ",?????,?????" & "," & fGetNewSerialNo(.Records("PKCP01").Item("TempSerial")).PadLeft(6, "0")

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

            '                '//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"))
            '                wstrKeyValue2(7) = RTrim(.Item("PlanSerial"))

            '                rtn = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, "STOCK1", wstrKey2, wstrKeyValue2, BtLib.Operation.GetGreaterOrEqual)
            '                Select Case rtn
            '                    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
            '                                            gclsDB.fCloseRecord("PKCP01")
            '                                            gclsDB.fCloseRecord("STOCK1")
            '                                            BtLib.Transaction.Abort()
            '                                            Exit Function
            '                                        End If
            '                                    End With

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

            '                                    rtn = fFreeZaikoStatus("STOCK1")
            '                                    If rtn = -1 Then
            '                                        gclsDB.fCloseRecord("PKCP01")
            '                                        gclsDB.fCloseRecord("STOCK1")
            '                                        BtLib.Transaction.Abort()
            '                                        Exit Function
            '                                    ElseIf rtn = -2 Then
            '                                        fNotPack = -2
            '                                    End If

            '                                End If
            '                            End If
            '                        End With
            '                    Case 9
            '                        fNotPack = -2
            '                    Case Else
            '                        gclsDB.fCloseRecord("PKCP01")
            '                        gclsDB.fCloseRecord("STOCK1")
            '                        BtLib.Transaction.Abort()
            '                        Exit Function
            '                End Select
            '                gclsDB.fCloseRecord("STOCK1")
            '            Else
            '                Exit Do
            '            End If

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

            '        End With
            '    Loop
            'End If

            'gclsDB.fCloseRecord("PKCP01")

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

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

    End Function

    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************
    '
    'E55
    '
    '
    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************

    '/*
    '|| 関数名：fPicsAllCancel
    '|| 概要  ：
    '*/
    Public Function fPicsAllCancel()

        Dim iRet As Integer
        Dim wstrKey(6) As String
        Dim wstrKeyValue(6) As String
        Const KEY01 = "DEL01"
        Const KEY02 = "DEL02"
        Dim wstrWhere As String

        fPicsAllCancel = -1

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

        With gstrctKDPP
            wstrKeyValue(0) = .strItemGr
            wstrKeyValue(1) = Space(30)
            wstrKeyValue(2) = Space(5)
            wstrKeyValue(3) = Space(5)
            wstrKeyValue(4) = Space(5)
            wstrKeyValue(5) = Space(30)
            wstrKeyValue(6) = Space(6)
        End With

        Try

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

            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 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 wstrKeyValue(0) = RTrim(sItemGr) Then
                        iRet = fDeletePackCP(KEY01, wstrWhere)
                    Else
                        Exit Do
                    End If


                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If

                Loop



            End If

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

            values = New Dictionary(Of String, String)
            sItemGr = ""
            i = 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 wstrKeyValue(0) = RTrim(sItemGr) Then
                        iRet = fDeletePackCJ(KEY02, wstrWhere)
                    Else
                        Exit Do
                    End If

                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If


                Loop


            End If

            fPicsAllCancel = 0

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



        'iRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY03, KEY01, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'If iRet = -1 Then
        '    BtLib.Transaction.Abort()
        '    sErrLog(gAppName, "fPicsAllCancel", gclsDB.ErrMsg)
        '    Exit Function
        'End If
        'If iRet = 0 Then
        '    Do
        '        If wstrKeyValue(0) = RTrim(gclsDB.Records(KEY01).Item("ItemGr")) Then
        '            iRet = fDeletePackCP(KEY01)
        '        Else
        '            Exit Do
        '        End If

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

        'iRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY03, KEY02, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'If iRet = -1 Then
        '    BtLib.Transaction.Abort()
        '    sErrLog(gAppName, "fPicsAllCancel", gclsDB.ErrMsg)
        '    Exit Function
        'End If
        'If iRet = 0 Then
        '    Do
        '        If wstrKeyValue(0) = RTrim(gclsDB.Records(KEY02).Item("ItemGr")) Then
        '            iRet = fDeletePackCJ(KEY02)
        '        Else
        '            Exit Do
        '        End If

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

        ''// ﾄﾗﾝｻﾞｸｼｮﾝ終了
        'BtLib.Transaction.End()

        'fPicsAllCancel = 0

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

    End Function

    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************
    '
    'E65
    '
    '
    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************
    '/*
    '|| 関数名：fZeroPicked
    '|| 概要  ：出荷数ゼロ完了
    '*/
    Public Function fZeroPicked()

        Dim wstrPKcpKey(2) As String
        Dim wstrPKcpKeyValue(2) As String
        Dim wstrStkKey(7) As String
        Dim wstrStkKeyValue(7) As String
        Dim wstrLctnPartNo As String
        Dim rtn2 As Integer
        Const KEY01 = "UPD01"
        Const KEY02 = "UPD02"
        Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)

        fZeroPicked = -1

        Try


            '実績更新処理

            '予約シリアル検索用
            With gstrctPPDispPart
                wstrPKcpKey(0) = "ItemCode" : wstrPKcpKeyValue(0) = .strItemCode
                wstrPKcpKey(1) = "ItemInCode" : wstrPKcpKeyValue(1) = .strItemInCode
                wstrPKcpKey(2) = "PlanSerial" : wstrPKcpKeyValue(2) = .strSerial
            End With

            rtn2 = fOpenPackCP(G_CONST_KEY_PACKCPKEY06, KEY01, wstrPKcpKey, wstrPKcpKeyValue)
            If rtn2 <> 0 Then
                'DBエラー
                'gclsDB.fCloseRecord(KEY01)
                Exit Function
            End If

            If gstrctPPDispPart.strLocation = "?????" Then

                If fUpdProc(KEY01, KEY02, 3) <> 0 Then
                    '更新失敗
                    'gclsDB.fCloseRecord(KEY01)
                    Exit Function
                End If

            Else

                Dim values1 As Dictionary(Of String, String) = New Dictionary(Of String, String)
                Dim sPicsType As String = ""
                Dim sCstmid As String = ""
                Dim sCstmCode As String = ""
                Dim sCenterCode As String = ""
                Dim sBhk As String = ""
                Dim sItemInID As String = ""
                Dim sItemInCode1 As String = ""
                Dim sPlanSerial As String = ""

                If tmpStrCP.Count > 0 Then

                    values1 = tmpStrCP(0)

                    Dim result As String = Nothing
                    If values1.TryGetValue("PicsType", result) Then
                        sPicsType = RTrim(result)
                    End If
                    If values1.TryGetValue("Cstmid", result) Then
                        sCstmid = RTrim(result)
                    End If
                    If values1.TryGetValue("CstmCode", result) Then
                        sCstmCode = RTrim(result)
                    End If
                    If values1.TryGetValue("CenterCode", result) Then
                        sCenterCode = RTrim(result)
                    End If
                    If values1.TryGetValue("Bhk", result) Then
                        sBhk = RTrim(result)
                    End If
                    If values1.TryGetValue("ItemInID", result) Then
                        sItemInID = RTrim(result)
                    End If
                    If values1.TryGetValue("ItemInCode", result) Then
                        sItemInCode1 = RTrim(result)
                    End If
                    If values1.TryGetValue("PlanSerial", result) Then
                        sPlanSerial = RTrim(result)
                    End If

                    wstrStkKey(0) = "PicsType" : wstrStkKeyValue(0) = RTrim(sPicsType)
                    wstrStkKey(1) = "Cstmid" : wstrStkKeyValue(1) = RTrim(sCstmid)
                    wstrStkKey(2) = "CstmCode" : wstrStkKeyValue(2) = RTrim(sCstmCode)
                    wstrStkKey(3) = "CenterCode" : wstrStkKeyValue(3) = RTrim(sCenterCode)
                    wstrStkKey(4) = "Bhk" : wstrStkKeyValue(4) = RTrim(sBhk)
                    wstrStkKey(5) = "Itemid" : wstrStkKeyValue(5) = RTrim(sItemInID)
                    wstrStkKey(6) = "ItemCode" : wstrStkKeyValue(6) = RTrim(sItemInCode1)
                    wstrStkKey(7) = "SerialNo" : wstrStkKeyValue(7) = RTrim(sPlanSerial)


                    rtn2 = fOpenStock(G_CONST_KEY_STOCKKEY00, KEY02, wstrStkKey, wstrStkKeyValue, 0)


                    If rtn2 <> 0 Then
                        'DBエラー
                        'gclsDB.fCloseRecord(KEY01)
                        Exit Function
                    End If

                    If fUpdProc(KEY01, KEY02, 1) <> 0 Then
                        '更新失敗
                        'gclsDB.fCloseRecord(KEY01)
                        Exit Function
                    End If
                    'gclsDB.fCloseRecord(KEY02)


                End If

            End If

            values = New Dictionary(Of String, String)
            Dim sStockLctn As String = ""
            Dim sItemInCode As String = ""
            Dim sPackQtyJ As String = ""

            If tmpStrCP.Count > 0 Then

                values = tmpStrCP(0)

                Dim result As String = Nothing
                If values.TryGetValue("StockLctn", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sStockLctn = result
                End If
                If values.TryGetValue("ItemInCode", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sItemInCode = result
                End If
                If values.TryGetValue("PackQtyJ", result) Then
                    'Console.WriteLine("RESULT: {0}", result)
                    sPackQtyJ = result
                End If

                wstrLctnPartNo = gstrctPPDisp.strCrtnNo & sStockLctn & sItemInCode
                gstrctPPDisp.fSetQty(wstrLctnPartNo, sPackQtyJ, 1)
                gstrctPPDisp.fSetPkg(wstrLctnPartNo, 1, 1)

                gstrctPPDisp.intNumOfScanned += 1

                fZeroPicked = 0

            End If

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


            ''予約STOCK検索用
            'With gclsDB.Records(KEY01)
            '    wstrStkKey(0) = "PicsType" : wstrStkKeyValue(0) = RTrim(.Item("PicsType"))
            '    wstrStkKey(1) = "Cstmid" : wstrStkKeyValue(1) = RTrim(.Item("Cstmid"))
            '    wstrStkKey(2) = "CstmCode" : wstrStkKeyValue(2) = RTrim(.Item("CstmCode"))
            '    wstrStkKey(3) = "CenterCode" : wstrStkKeyValue(3) = RTrim(.Item("CenterCode"))
            '    wstrStkKey(4) = "Bhk" : wstrStkKeyValue(4) = RTrim(.Item("Bhk"))
            '    wstrStkKey(5) = "Itemid" : wstrStkKeyValue(5) = RTrim(.Item("ItemInID"))
            '    wstrStkKey(6) = "ItemCode" : wstrStkKeyValue(6) = RTrim(.Item("ItemInCode"))
            '    wstrStkKey(7) = "SerialNo" : wstrStkKeyValue(7) = RTrim(.Item("PlanSerial"))

            'End With

            'rtn2 = fOpenStock(G_CONST_KEY_STOCKKEY00, KEY02, wstrStkKey, wstrStkKeyValue, 0)

            'If rtn2 <> 0 Then
            '    'DBエラー
            '    gclsDB.fCloseRecord(KEY01)
            '    Exit Function
            'End If

            'If fUpdProc(KEY01, KEY02, 1) <> 0 Then
            '    '更新失敗
            '    gclsDB.fCloseRecord(KEY01)
            '    Exit Function
            'End If
            'gclsDB.fCloseRecord(KEY02)

            'End If

        '    With gclsDB.Records(KEY01)
        '        wstrLctnPartNo = gstrctPPDisp.strCrtnNo & .Item("StockLctn") & .Item("ItemInCode")
        '        gstrctPPDisp.fSetQty(wstrLctnPartNo, .Item("PackQtyJ"), 1)
        '        gstrctPPDisp.fSetPkg(wstrLctnPartNo, 1, 1)
        '    End With
        '    gstrctPPDisp.intNumOfScanned += 1

        '    gclsDB.fCloseRecord(KEY01)
        '    fZeroPicked = 0

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

    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************
    '
    'E75
    '
    '
    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************

    '/*
    '|| 関数名：fInvalidatePKCP
    '|| 概要  ：
    '*/
    Public Function fInvalidatePKCP() As Integer

        Dim rtn As Integer
        Dim wstrKey(2) As String
        Dim wstrKeyValue(2) As String
        Dim wstrLocation As String
        Dim sSQL As String
        Dim wstrWhere As String

        Try

            fInvalidatePKCP = -1

            '// PKCPから検索条件を取得
            With gstrctPPDispPart
                wstrKey(0) = "ItemCode" : wstrKeyValue(0) = .strItemCode
                wstrKey(1) = "ItemInCode" : wstrKeyValue(1) = .strItemInCode
                wstrKey(2) = "PlanSerial" : wstrKeyValue(2) = .strSerial
                wstrLocation = .strLocation
            End With

            'BtLib.Transaction.BeginConCurrent()

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


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


            affected_rows = dbClient.Execute(sSQL)


            If affected_rows = 0 Then
                Exit Function
            End If



            'With gclsDB
            '    .Setcolumn = "PickFlag,PairLctn,StockLctn,PlanSerial"
            '    .SetData = "0,?????,?????" & "," & fGetNewSerialNo(wstrKeyValue(2)).PadLeft(6, "0")
            '    If .fUpdRecords(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY06, wstrKey, wstrKeyValue) = -1 Then
            '        Exit Function
            '    End If
            'End With

            'BtLib.Transaction.End()

            gstrctPPDisp.fSetQty(gstrctPPDisp.strCrtnNo & wstrLocation & gstrctPPDispPart.strItemInCode, (0 - CInt(gstrctPPDispPart.strPackQty)))
            gstrctPPDisp.fSetPkg(gstrctPPDisp.strCrtnNo & wstrLocation & gstrctPPDispPart.strItemInCode, -1)
            gstrctPPDisp.fSetQty(gstrctPPDisp.strCrtnNo & "?????" & gstrctPPDispPart.strItemInCode, CInt(gstrctPPDispPart.strPackQty))
            gstrctPPDisp.fSetPkg(gstrctPPDisp.strCrtnNo & "?????" & gstrctPPDispPart.strItemInCode, 1)

            fInvalidatePKCP = 0

            Exit Function

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

    End Function

    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************
    '
    'E80
    '
    '
    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************


    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************
    '
    'E95
    '
    '
    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************

    '/*
    '|| 関数名：fResetSection
    '|| 概要　：Sectionのｱｸｾｽ区分をL -> F へ復帰
    '*/
    Public Function fResetSection()
        'Dim wstrKey(2) As String
        'Dim wstrKeyValue(2) As String
        'Dim wintRet As Integer
        'Dim wstrAccess As String

        ''検索キー設定
        'wstrKey(0) = "CenterCode"
        'wstrKey(1) = "SectionID"
        'wstrKey(2) = "Section"
        'wstrKeyValue(0) = gstrctKDPP.strCenterCode
        'wstrKeyValue(1) = gstrctKDPP.strSectionID
        'wstrKeyValue(2) = gstrctKDPP.strSection

        'fResetSection = -1

        'Try

        '    wintRet = gclsDB.fOpenRecord(G_CONST_TBL_SECTION, G_CONST_KEY_SECTIONKEY00, "SEC1", wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)
        '    If wintRet = -1 Then
        '        gclsDB.fCloseRecord("SEC1")
        '        Exit Function
        '    End If

        '    wstrAccess = gclsDB.Records("SEC1").Item("Access")
        '    gclsDB.fCloseRecord("SEC1")

        '    If wstrAccess <> M_CONST_LOCK_L Then Exit Function

        '    '更新対象列名
        '    gclsDB.Setcolumn = ("Access")
        '    '更新データ
        '    gclsDB.SetData = (M_CONST_LOCK_F)

        '    'アンロック
        '    wintRet = gclsDB.fUpdRecords(G_CONST_TBL_SECTION, G_CONST_KEY_SECTIONKEY00, wstrKey, wstrKeyValue)
        '    If wintRet = -1 Then
        '        gclsDB.fCloseRecord("SEC1")
        '        Exit Function
        '    End If

        '    fResetSection = 0

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

End Module
