Imports System.Text

'*******************************************************************************
'* 作成者   : 株式会社エコー・システム 
'* 作成日   : 2004/10/02
'* 概要     : PICS2004 共通処理
'* 更新履歴 : 
'* ﾊﾞｰｼﾞｮﾝ  : 1.0
'*******************************************************************************

Imports WarpControl
Imports WarpControl.WarpApi2

Module modPublicE


    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************
    '
    '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

        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

            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

        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

            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

        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)

            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"

        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()

            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"

        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

                '予約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

        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()

            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
