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


Module modPublicKDPP

    Private dbClient As BtrieveDbClient
    Private tmpStr As List(Of Dictionary(Of String, String))
    Private affected_rows As Integer
    Public tmpStrSTOCK As List(Of Dictionary(Of String, String))
    Public tmpStrCP As List(Of Dictionary(Of String, String))
    Public tmpStrCJ As List(Of Dictionary(Of String, String))

    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************
    '
    '共通関数
    '
    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************


    '*******************************************************************************
    '   概要  ：作業終了時にHTCTRLのSearchKeyをクリア
    '   ﾊﾟﾗﾒｰﾀ：
    '   戻り値：
    '*******************************************************************************

    Public Function fClearSKey()

        Dim rtn As Integer
        Dim wintCnt As Integer
        Dim wstrWhere As String
        Dim wstrKey(0) As String, wstrKeyValue(0) As String

        Try

            fClearSKey = -1

            'BtLib.Transaction.BeginConCurrent()

            wstrWhere = ""
            wstrWhere = "HTNumber = '" & gstrctKDHT.strHdNo & "'"

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

            If tmpStr.Count > 0 Then

            Else
                Exit Function

            End If


            'wstrWhere = "@HTNumber = " & gstrctKDHT.strHdNo
            'wintCnt = gclsDB.fGetData(G_CONST_TBL_HTCTRL, G_CONST_KEY_HTCTRLKEY00, wstrWhere, "CTRL2")

            'If wintCnt > 0 Then
            '    gclsDB.fCloseRecord("CTRL2")
            'Else
            '    gclsDB.fCloseRecord("CTRL2")
            '    'BtLib.Transaction.Abort()
            '    Exit Function
            'End If


            affected_rows = dbClient.Execute("UPDATE " + G_CONST_TBL_HTCTRL + " SET SearchKey='" _
                                                                 + Space(50) _
                                                                 + "' WHERE " + wstrWhere)



            If affected_rows = 0 Then
                Exit Function
            End If

            fClearSKey = 0
            Exit Function

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



        'gclsDB.Setcolumn = ("SearchKey")                 '登録/更新対象列名
        'gclsDB.SetData = Space(50)                       '登録/更新データ

        'wstrKey(0) = "HTNumber"
        'wstrKeyValue(0) = gstrctKDHT.strHdNo

        'If gclsDB.fUpdRecords(G_CONST_TBL_HTCTRL, G_CONST_KEY_HTCTRLKEY00, wstrKey, wstrKeyValue) = -1 Then
        '    BtLib.Transaction.Abort()
        '    Exit Function
        'End If

        'BtLib.Transaction.End()
        'fClearSKey = 0
        'Exit Function

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

    End Function

    '*******************************************************************************
    '* 機能     : PACKCPオープン処理
    '* 引数     : 1.インデックス, 1.キー, 2.検索キー, 3.検索キー値
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fOpenPackCP(ByVal pstrIndx As String, ByVal pstrKey As String, ByVal Keys() As String, ByVal KeyValues() As String, Optional ByVal pbFlg As Boolean = False) As Integer

        Dim wintRet As Integer
        Dim wstrSerial As String
        Dim wstrWhere As String

        fOpenPackCP = -1

        Try
            wstrWhere = ""


            For index As Integer = 1 To Keys.Length

                If index = 1 Then
                    wstrWhere = Keys(index - 1) & " = '" & KeyValues(index - 1) & "'"
                Else
                    wstrWhere = wstrWhere & " and " & Keys(index - 1) & " = '" & KeyValues(index - 1) & "'"
                End If


            Next

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


            tmpStrCP = tmpStr


            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 i As Integer = 0

            If tmpStr.Count > 0 Then

                Do

                    values = tmpStr(i)

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

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

                        fOpenPackCP = 0
                        Exit Function

                    End If



                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If


                Loop



            End If

            Exit Function

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



        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, pstrIndx, pstrKey, Keys, KeyValues, BtLib.Operation.GetGreaterOrEqual)
        'If wintRet = 9 Then
        '    gclsDB.fCloseRecord(pstrKey)
        '    Exit Function
        'ElseIf wintRet <> 0 Then
        '    gclsDB.fCloseRecord(pstrKey)
        '    Exit Function
        'End If

        'If wintRet = 0 Then
        '    With gclsDB.Records(pstrKey)
        '        If pbFlg Then
        '            Do
        '                If KeyValues(0) = RTrim(.Item("ItemCode")) And _
        '                   KeyValues(1) = RTrim(.Item("ItemInCode")) And _
        '                   KeyValues(2) = RTrim(.Item("PlanSerial")) Then

        '                    fOpenPackCP = 0
        '                    Exit Function

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

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

        '                fOpenPackCP = 0
        '                Exit Function

        '            End If
        '        End If
        '    End With
        'End If

        'gclsDB.fCloseRecord(pstrKey)
        'Exit Function

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

    End Function

    '*******************************************************************************
    '* 機能     : PACKCJオープン処理
    '* 引数     : 1.インデックス, 1.キー, 2.検索キー, 3.検索キー値
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fOpenPackCJ(ByVal pstrIndx As String, ByVal pstrKey As String, ByVal Keys() As String, ByVal KeyValues() As String) As Integer
        Dim wintRet As Integer
        Dim wstrWhere As String
        fOpenPackCJ = -1
        Try

            wstrWhere = ""


            For index As Integer = 1 To Keys.Length

                If index = 1 Then
                    wstrWhere = Keys(index - 1) & " = '" & KeyValues(index - 1) & "'"
                Else
                    wstrWhere = wstrWhere & " and " & Keys(index - 1) & " = '" & KeyValues(index - 1) & "'"
                End If


            Next

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

            tmpStrCJ = tmpStr

            If tmpStr.Count > 0 Then

            Else
                Exit Function
            End If


            'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, pstrIndx, pstrKey, Keys, KeyValues, BtLib.Operation.GetGreaterOrEqual)
            'If wintRet = -1 Then
            '    gclsDB.fCloseRecord(pstrIndx)
            '    Exit Function
            'ElseIf wintRet <> 0 Then
            '    gclsDB.fCloseRecord(pstrIndx)
            '    Exit Function
            'End If

            fOpenPackCJ = 0

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

    End Function
    '*******************************************************************************
    '* 機能     : STOCKオープン処理
    '* 引数     : 1.インデックス, 1.キー, 2.検索キー, 3.検索キー値
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fOpenStock(ByVal pstrIndx As String, ByVal pstrKey As String, ByVal Keys() As String, ByVal KeyValues() As String, Optional ByVal pintFlag As Integer = 0) As Integer

        Dim wintRet As Integer
        Dim wstrSerial As String
        Dim wstrWhere As String

        fOpenStock = -1

        Try

            '//pintFlag: 0:通常ケース（25桁部品ラベルからのSTOCK検索）, 2:19桁部品ラベル対応（任意のSerialNoのものを選択）
            If pintFlag = 2 Then
                KeyValues(7) = Space(6)
            End If

            wstrWhere = ""


            For index As Integer = 1 To Keys.Length

                If index = 1 Then
                    wstrWhere = Keys(index - 1) & " = '" & KeyValues(index - 1) & "'"
                Else
                    wstrWhere = wstrWhere & " and " & Keys(index - 1) & " = '" & KeyValues(index - 1) & "'"
                End If


            Next

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

            tmpStrSTOCK = tmpStr

            Dim values 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 sItemid As String = ""
            Dim sItemCode As String = ""
            Dim sSerialNo As String = ""
            Dim sLocation As String = ""
            Dim sQty As String = ""
            Dim sZaikoStatus As String = ""

            Dim i As Integer = 0

            If tmpStr.Count > 0 Then
                If pintFlag = 0 Then

                    values = tmpStr(0)

                    Dim result As String = Nothing
                    If values.TryGetValue("PicsType", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sPicsType = result
                    End If
                    If values.TryGetValue("Cstmid", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sCstmid = result
                    End If
                    If values.TryGetValue("CstmCode", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sCstmCode = result
                    End If
                    If values.TryGetValue("CenterCode", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sCenterCode = result
                    End If
                    If values.TryGetValue("Bhk", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sBhk = result
                    End If
                    If values.TryGetValue("Itemid", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sItemid = result
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sItemCode = result
                    End If
                    If values.TryGetValue("SerialNo", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sSerialNo = result
                    End If
                    If values.TryGetValue("Location", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sLocation = result
                    End If
                    If values.TryGetValue("Qty", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sQty = result
                    End If
                    If values.TryGetValue("ZaikoStatus", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sZaikoStatus = result
                    End If

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

                        fOpenStock = 0
                        Exit Function
                    End If

                Else
                    Do

                        values = tmpStr(i)

                        Dim result As String = Nothing
                        If values.TryGetValue("PicsType", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sPicsType = result
                        End If
                        If values.TryGetValue("Cstmid", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sCstmid = result
                        End If
                        If values.TryGetValue("CstmCode", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sCstmCode = result
                        End If
                        If values.TryGetValue("CenterCode", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sCenterCode = result
                        End If
                        If values.TryGetValue("Bhk", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sBhk = result
                        End If
                        If values.TryGetValue("Itemid", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sItemid = result
                        End If
                        If values.TryGetValue("ItemCode", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sItemCode = result
                        End If
                        If values.TryGetValue("SerialNo", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sSerialNo = result
                        End If
                        If values.TryGetValue("Location", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sLocation = result
                        End If
                        If values.TryGetValue("Qty", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sQty = result
                        End If
                        If values.TryGetValue("ZaikoStatus", result) Then
                            'Console.WriteLine("RESULT: {0}", result)
                            sZaikoStatus = result
                        End If


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

                            If gstrctPPDispPart.strLocation = RTrim(sLocation) And _
                               gstrctPPDispPart.strPackQty = RTrim(sQty) And _
                               G_CONST_ST_STOCK_RESERVED2 = RTrim(sZaikoStatus) Then
                                fOpenStock = 0
                                Exit Function
                            End If

                        Else
                            Exit Do
                        End If


                        i = i + 1

                        If tmpStr.Count = i Then
                            Exit Do
                        End If

                    Loop
                    fOpenStock = -2
                    Exit Function

                End If



            Else
                Exit Function
            End If


            Exit Function

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




        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, pstrIndx, pstrKey, Keys, KeyValues, BtLib.Operation.GetGreaterOrEqual)

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

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

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

        '                fOpenStock = 0
        '                Exit Function
        '            End If
        '        Else
        '            Do

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

        '                    If gstrctPPDispPart.strLocation = RTrim(.Item("Location")) And _
        '                       gstrctPPDispPart.strPackQty = RTrim(.Item("Qty")) And _
        '                       G_CONST_ST_STOCK_RESERVED2 = RTrim(.Item("ZaikoStatus")) Then
        '                        fOpenStock = 0
        '                        Exit Function
        '                    End If

        '                Else
        '                    Exit Do
        '                End If

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

        '            Loop
        '            fOpenStock = -2
        '            gclsDB.fCloseRecord(pstrKey)
        '            Exit Function

        '        End If

        '    End With
        'End If

        'gclsDB.fCloseRecord(pstrKey)
        'Exit Function

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

    End Function

    '*******************************************************************************
    '* 機能     : PACKCP消し込み
    '* 引数     : 無し
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fDeletePackCP(ByVal pstrKey As String, ByVal wstrWhere As String) As Integer

        fDeletePackCP = -1

        Try

            affected_rows = dbClient.Execute("DELETE FROM " & G_CONST_TBL_PACKCP & " WHERE " + wstrWhere)


            '// 現在ﾚｺｰﾄﾞを削除
            'With gclsDB.Records(pstrKey)
            '    .Delete()

            'End With

            fDeletePackCP = 0

        Catch ex As Exception
            sErrLog(gAppName, "fDeletePackCP", ex.ToString)

        End Try

    End Function
    '*******************************************************************************
    '* 機能     : PACKCJ消し込み
    '* 引数     : 無し
    '* 戻り値   : 0:OK -1:ERROR
    '* 備考     : なし
    '*******************************************************************************
    Public Function fDeletePackCJ(ByVal pstrKey As String, ByVal wstrWhere As String) As Integer

        fDeletePackCJ = -1

        Try

            affected_rows = dbClient.Execute("DELETE FROM " & G_CONST_TBL_PACKCJ & " WHERE " & wstrWhere)


            If affected_rows = 0 Then
                Exit Function
            End If

            '// 現在ﾚｺｰﾄﾞを削除
            'With gclsDB.Records(pstrKey)
            '    .Delete()

            'End With

        Catch ex As Exception
            sErrLog(gAppName, "fDeletePackCJ", ex.ToString)

        End Try

    End Function

    '/*
    '|| 関数名 : fFreeZaikoStatus
    '|| 概要　 : 在庫ステータスの解放
    '||          （ステータス５を３）
    '|| 引数　 : 1.在庫ステータス
    '||          2.検索キー
    '|| 戻り値 : 0:OK -1:NG -2:Not Found
    '*/
    Public Function fFreeZaikoStatus(ByVal pstrKey As String, Optional ByVal pintFlag As Integer = 0) As Integer

        Dim wstrKey(9) As String
        Dim wstrKeyValue(9) As String
        Dim wintRet As Integer
        Const STK_KEY01 = "STOCK"
        Dim wstrWhere As String
        Dim i As Integer = 0
        Dim sSQL As String

        fFreeZaikoStatus = -1

        Dim values 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 sLocation As String = ""
        Dim sItemid As String = ""
        Dim sItemCode As String = ""
        Dim sQty As String = ""
        Dim sSerialNo As String = ""

        If tmpStrSTOCK.Count > 0 Then

            values = tmpStrSTOCK(0)

            Dim result As String = Nothing
            If values.TryGetValue("SerialNo", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sSerialNo = result
            End If
            If values.TryGetValue("PicsType", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sPicsType = result
            End If
            If values.TryGetValue("Cstmid", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sCstmid = result
            End If
            If values.TryGetValue("CstmCode", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sCstmCode = result
            End If
            If values.TryGetValue("CenterCode", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sCenterCode = result
            End If
            If values.TryGetValue("Bhk", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sBhk = result
            End If
            If values.TryGetValue("Location", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sLocation = result
            End If
            If values.TryGetValue("Itemid", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sItemid = result
            End If
            If values.TryGetValue("ItemCode", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sItemCode = result
            End If
            If values.TryGetValue("Qty", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sQty = result
            End If
            If values.TryGetValue("SerialNo", result) Then
                'Console.WriteLine("RESULT: {0}", result)
                sSerialNo = result
            End If


        End If

        '検索キーの設定
        'With gclsDB.Records(pstrKey)
        wstrKey(0) = "PicsType"
        wstrKey(1) = "Cstmid"
        wstrKey(2) = "CstmCode"
        wstrKey(3) = "CenterCode"
        wstrKey(4) = "Bhk"
        wstrKey(5) = "Location"
        wstrKey(6) = "Itemid"
        wstrKey(7) = "ItemCode"
        wstrKey(8) = "Qty"
        wstrKey(9) = "SerialNo"

        wstrKeyValue(0) = RTrim(sPicsType)
        wstrKeyValue(1) = RTrim(sCstmid)
        wstrKeyValue(2) = RTrim(sCstmCode)
        wstrKeyValue(3) = RTrim(sCenterCode)
        wstrKeyValue(4) = RTrim(sBhk)
        wstrKeyValue(5) = RTrim(sLocation)
        wstrKeyValue(6) = RTrim(sItemid)
        wstrKeyValue(7) = RTrim(sItemCode)
        wstrKeyValue(8) = RTrim(sQty)
        wstrKeyValue(9) = Space(6)
        'End With

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

            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 = ""
            Dim sZaikoStatus As String = ""
            sSerialNo = ""



            If tmpStr.Count = 0 Then

                Exit Function

            Else

                Do
                    values = tmpStr(i)

                    Dim result As String = Nothing
                    If values.TryGetValue("PicsType", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sPicsType = result
                    End If
                    If values.TryGetValue("Cstmid", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sCstmid = result
                    End If
                    If values.TryGetValue("CstmCode", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sCstmCode = result
                    End If
                    If values.TryGetValue("CenterCode", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sCenterCode = result
                    End If
                    If values.TryGetValue("Bhk", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sBhk = result
                    End If
                    If values.TryGetValue("Location", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sLocation = result
                    End If
                    If values.TryGetValue("Itemid", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sItemid = result
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sItemCode = result
                    End If
                    If values.TryGetValue("Qty", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sQty = result
                    End If
                    If values.TryGetValue("ZaikoStatus", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sZaikoStatus = result
                    End If
                    If values.TryGetValue("SerialNo", result) Then
                        'Console.WriteLine("RESULT: {0}", result)
                        sSerialNo = result
                    End If


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

                        If G_CONST_ST_STOCK_RESERVED2 = RTrim(sZaikoStatus) Then

                            wstrKeyValue(9) = RTrim(sSerialNo)

                            Dim sSetData As String = ""
                            'With gclsDB
                            '    .Setcolumn = "ZaikoStatus"
                            If pintFlag = 0 Then
                                '.SetData = G_CONST_ST_STOCK_INSTOCK
                                sSetData = G_CONST_ST_STOCK_INSTOCK
                            Else
                                '.SetData = G_CONST_ST_STOCK_PICKED
                                sSetData = G_CONST_ST_STOCK_PICKED
                            End If


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


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

                            affected_rows = dbClient.Execute(sSQL)



                            If affected_rows = 0 Then
                                Exit Function
                            End If



                            'If .fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY01, wstrKey, wstrKeyValue) = -1 Then
                            '    gclsDB.fCloseRecord("STK_KEY01")
                            '    Exit Function
                            'End If
                            'End With


                        End If

                    Else

                        Exit Do


                    End If


                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If

                Loop
            End If

            'gclsDB.fCloseRecord(STK_KEY01)
            '//エラー：対象STOCK　NOTFOUND
            Exit Function

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




        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY01, STK_KEY01, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'If wintRet = 9 Then
        '    fFreeZaikoStatus = -2
        '    gclsDB.fCloseRecord(STK_KEY01)
        '    Exit Function
        'ElseIf wintRet <> 0 Then
        '    gclsDB.fCloseRecord(STK_KEY01)
        '    Exit Function
        'End If

        'If wintRet = 0 Then
        '    Do
        '        With gclsDB.Records(STK_KEY01)
        '            If wstrKeyValue(0) = RTrim(.Item("PicsType")) And _
        '               wstrKeyValue(1) = RTrim(.Item("Cstmid")) And _
        '               wstrKeyValue(2) = RTrim(.Item("CstmCode")) And _
        '               wstrKeyValue(3) = RTrim(.Item("CenterCode")) And _
        '               wstrKeyValue(4) = RTrim(.Item("Bhk")) And _
        '               wstrKeyValue(5) = RTrim(.Item("Location")) And _
        '               wstrKeyValue(6) = RTrim(.Item("Itemid")) And _
        '               wstrKeyValue(7) = RTrim(.Item("ItemCode")) And _
        '               wstrKeyValue(8) = RTrim(.Item("Qty")) Then

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

        '                    wstrKeyValue(9) = RTrim(.Item("SerialNo"))

        '                    '// DB更新
        '                    With gclsDB
        '                        .Setcolumn = "ZaikoStatus"
        '                        If pintFlag = 0 Then
        '                            .SetData = G_CONST_ST_STOCK_INSTOCK
        '                        Else
        '                            .SetData = G_CONST_ST_STOCK_PICKED
        '                        End If

        '                        If .fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY01, wstrKey, wstrKeyValue) = -1 Then
        '                            gclsDB.fCloseRecord("STK_KEY01")
        '                            Exit Function
        '                        End If
        '                    End With

        '                    gclsDB.fCloseRecord(STK_KEY01)
        '                    fFreeZaikoStatus = 0
        '                    Exit Function

        '                End If

        '            Else
        '                Exit Do
        '            End If

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

        '        End With
        '    Loop
        'End If

        'gclsDB.fCloseRecord(STK_KEY01)
        ''//エラー：対象STOCK　NOTFOUND
        'Exit Function

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

    End Function


    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************
    '
    '再チェック
    '035〜045
    '
    '*******************************************************************************
    '*******************************************************************************
    '*******************************************************************************

    '/*
    '|| 関数名：fDemotePackCJ
    '|| 概要  ：PackCJレコードステータス変更（再チェック用）
    '*/
    Public Function fDemotePackCJ(ByRef pintCnt As Integer) As Integer

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

        fDemotePackCJ = -1

        Try

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

            wstrKey(0) = "ItemCode"
            wstrKey(1) = "ItemInCode"
            wstrKey(2) = "PlanSerial"
            wstrKeyValue(0) = Mid(gstrctKDPP.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
            wstrKeyValue(1) = Space(30)
            wstrKeyValue(2) = Space(5)

            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_PACKCJ + " 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 sPackQtyJ As String = ""
            Dim i As String = 0

            If tmpStr.Count = 0 Then

                Exit Function

            Else

                Do

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

                    If wstrKeyValue(0) = RTrim(sItemCode) Then

                        wintCnt += 1
                        wstrKeyValue(1) = RTrim(sItemInCode)
                        wstrKeyValue(2) = RTrim(sPlanSerial)


                        sSQL = "UPDATE " + G_CONST_TBL_PACKCJ + " SET PickFlag='" _
                                                         + G_CONST_ST_PKCJ_CHECK _
                                                         + "' WHERE " + wstrWhere

                        affected_rows = dbClient.Execute(sSQL)


                        If affected_rows = 0 Then
                            Exit Function
                        End If


                        gstrctPPDisp.fSetQty(RTrim(sItemInCode), RTrim(sPackQtyJ))
                        gstrctPPDisp.fSetPkg(RTrim(sItemInCode), 1)
                    Else
                        Exit Do
                    End If


                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If


                Loop

            End If

            pintCnt = wintCnt
            fDemotePackCJ = 0
            Exit Function

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



        'rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY06, "PKCJ01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'If rtn = 9 Then
        '    fDemotePackCJ = -2
        '    gclsDB.fCloseRecord("PKCJ01")
        '    BtLib.Transaction.Abort()
        '    Exit Function
        'ElseIf rtn <> 0 Then
        '    gclsDB.fCloseRecord("PKCJ01")
        '    BtLib.Transaction.Abort()
        '    Exit Function
        'End If

        'Erase gstrctPPDisp.arryPARTInf
        'Erase gstrctPPDisp.arryPARTInf2
        'wintCnt = 0
        'If rtn = 0 Then
        '    Do
        '        With gclsDB.Records("PKCJ01")
        '            If wstrKeyValue(0) = RTrim(.Item("ItemCode")) Then

        '                wintCnt += 1
        '                wstrKeyValue(1) = RTrim(.Item("ItemInCode"))
        '                wstrKeyValue(2) = RTrim(.Item("PlanSerial"))

        '                '// DB更新
        '                With gclsDB
        '                    .Setcolumn = "PickFlag"
        '                    .SetData = G_CONST_ST_PKCJ_CHECK

        '                    If .fUpdRecords(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY06, wstrKey, wstrKeyValue) = -1 Then
        '                        gclsDB.fCloseRecord("PKCJ01")
        '                        BtLib.Transaction.Abort()
        '                        Exit Function
        '                    End If
        '                End With

        '                gstrctPPDisp.fSetQty(RTrim(.Item("ItemInCode")), RTrim(.Item("PackQtyJ")))
        '                gstrctPPDisp.fSetPkg(RTrim(.Item("ItemInCode")), 1)
        '            Else
        '                Exit Do
        '            End If

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

        '        End With
        '    Loop
        'End If

        'gclsDB.fCloseRecord("PKCJ01")

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

        'pintCnt = wintCnt
        'fDemotePackCJ = 0
        'Exit Function

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

    '/*
    '|| 関数名：fProcData4SRetry
    '|| 概要  ：スキャンリトライ入力処理
    '|| 戻り値: 0(正常): -1(DBｴﾗｰ): -2(ﾃﾞｰﾀ無し): -3(ﾀﾞﾌﾞﾙｽｷｬﾝ)
    '*/
    Public Function fProcData4SRetry(ByVal pstrInput As String, ByRef pintCnt As Integer)
        Dim wstrItemCode As String
        Dim wstrItemInCodeDisp As String
        Dim wstrSerialNo As String
        Dim wstrLocPart As String
        Dim wstrPlanQty As String
        Dim bFound As Boolean
        Dim rtn As Integer
        Dim wintCnt As Integer
        Dim wstrKey(2) As String
        Dim wstrKeyValue(2) As String
        Dim wstrWhere As String

        fProcData4SRetry = -1

        Try

            wstrItemCode = RTrim(Mid(pstrInput, 2, 13))
            If pstrInput.Length() = G_CONST_LLEN_PRT1 Then
                wstrSerialNo = "999999"
            Else
                wstrSerialNo = RTrim(Mid(pstrInput, 20, 6))
            End If

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

            wstrKey(0) = "ItemCode"
            wstrKey(1) = "ItemInCode"
            wstrKey(2) = "PlanSerial"
            wstrKeyValue(0) = Mid(gstrctKDPP.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
            wstrKeyValue(1) = Space(30)
            wstrKeyValue(2) = Space(6)

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemCode As String = ""
            Dim sItemInCode As String = ""
            Dim sSerialNo As String = ""
            Dim sPickFlag As String = ""
            Dim sStockLctn As String = ""
            Dim sItemInCodeDisp As String = ""
            Dim sPackQtyJ As String = ""
            Dim sPlanSerial As String = ""
            Dim i As Integer = 0

            bFound = False
            wintCnt = 0
            If tmpStr.Count > 0 Then

                Do

                    values = tmpStr(i)

                    Dim result As String = Nothing
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If
                    If values.TryGetValue("SerialNo", result) Then
                        sSerialNo = RTrim(result)
                    End If
                    If values.TryGetValue("PickFlag", result) Then
                        sPickFlag = RTrim(result)
                    End If
                    If values.TryGetValue("StockLctn", result) Then
                        sStockLctn = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCodeDisp", result) Then
                        sItemInCodeDisp = RTrim(result)
                    End If
                    If values.TryGetValue("PackQtyJ", result) Then
                        sPackQtyJ = RTrim(result)
                    End If
                    If values.TryGetValue("PlanSerial", result) Then
                        sPlanSerial = RTrim(result)
                    End If


                    If wstrKeyValue(0) = RTrim(sItemCode) Then

                        If wstrItemCode = RTrim(sItemInCode) And _
                           (wstrSerialNo = RTrim(sSerialNo) Or _
                           (Not bFound And wstrSerialNo = "999999" And G_CONST_ST_PKCJ_CHECK = RTrim(sPickFlag))) Then

                            If G_CONST_ST_PKCJ_PACKED = RTrim(sPickFlag) And wstrSerialNo <> "999999" Then
                                'gclsDB.fCloseRecord("PKCJ01
                                fProcData4SRetry = -3
                                Exit Function
                            End If

                            '表示用データの取得
                            With gstrctPPDispPart
                                .initialize()
                                .strLocation1 = RTrim(Mid(sStockLctn, 1, 2))
                                .strLocation2 = RTrim(Mid(sStockLctn, 3))
                                '画面表示用部品番号の取得
                                .strItemInCode = RTrim(sItemInCode)
                                wstrItemInCodeDisp = RTrim(sItemInCodeDisp)
                                .strPartNoDisp = RTrim(Mid(wstrItemInCodeDisp, 1, 12))
                                .strCL = RTrim(Mid(wstrItemCode, 11, 2))
                                .strZ = RTrim(Mid(wstrItemCode, 13, 1))
                                'wstrLocPart = RTrim(gclsDB.Records("PKCJ01").Item("StockLctn"))
                                'wstrLocPart = wstrLocPart.PadRight(5, " ")
                                'wstrLocPart = gstrctPPDisp.strCrtnNo & gstrctPPDisp.strCrtnNo & wstrLocPart & RTrim(gclsDB.Records("PKCJ01").Item("ItemInCode"))
                                wstrLocPart = .strItemInCode
                                'gstrctPPDisp.fSetQty(wstrLocPart, RTrim(gclsDB.Records("PKCJ01").Item("PackQtyJ")), 1)
                                'gstrctPPDisp.fSetPkg(wstrLocPart, 1, 1)
                                wstrPlanQty = RTrim(sPackQtyJ)
                            End With

                            wstrKeyValue(1) = RTrim(sItemInCode)
                            wstrKeyValue(2) = RTrim(sPlanSerial)

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


                            affected_rows = dbClient.Execute("UPDATE " + G_CONST_TBL_PACKCJ + " SET PickFlag='" _
                                                                + G_CONST_ST_PKCJ_PACKED _
                                                                + "' WHERE " + wstrWhere)


                            If affected_rows = 0 Then
                                Exit Function
                            End If

                            '// DB更新
                            'With gclsDB
                            '    .Setcolumn = "PickFlag"
                            '    .SetData = G_CONST_ST_PKCJ_PACKED

                            '    If .fUpdRecords(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY06, wstrKey, wstrKeyValue) = -1 Then
                            '        'gclsDB.fCloseRecord("PKCJ01")
                            '        'BtLib.Transaction.Abort()
                            '        Exit Function
                            '    End If
                            'End With
                            bFound = True

                            'Exit Do

                        End If

                        If RTrim(sPickFlag) = G_CONST_ST_PKCJ_PACKED Then
                            wintCnt += 1
                        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 Not bFound Then
                fProcData4SRetry = -2
                Exit Function
            End If

            gstrctPPDisp.fSetQty(wstrLocPart, wstrPlanQty, 1)
            gstrctPPDisp.fSetPkg(wstrLocPart, 1, 1)
            pintCnt = wintCnt + 1

            fProcData4SRetry = 0
            Exit Function

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


            'rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY06, "PKCJ01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
            'If rtn = 9 Then
            '    fProcData4SRetry = -2
            '    'gclsDB.fCloseRecord("PKCJ01")
            '    'BtLib.Transaction.Abort()
            '    Exit Function
            'ElseIf rtn <> 0 Then
            '    'gclsDB.fCloseRecord("PKCJ01")
            '    'BtLib.Transaction.Abort()
            '    Exit Function
            'End If

            'bFound = False
            'wintCnt = 0
        '    If rtn = 0 Then
        '        Do
        '            With gclsDB.Records("PKCJ01")
        '                If wstrKeyValue(0) = RTrim(.Item("ItemCode")) Then

        '                    If wstrItemCode = RTrim(.Item("ItemInCode")) And _
        '                       (wstrSerialNo = RTrim(.Item("SerialNo")) Or _
        '                       (Not bFound And wstrSerialNo = "999999" And G_CONST_ST_PKCJ_CHECK = RTrim(.Item("PickFlag")))) Then

        '                        If G_CONST_ST_PKCJ_PACKED = RTrim(.Item("PickFlag")) And wstrSerialNo <> "999999" Then
        '                            gclsDB.fCloseRecord("PKCJ01")
        '                            fProcData4SRetry = -3
        '                            Exit Function
        '                        End If

        '                        '表示用データの取得
        '                        With gstrctPPDispPart
        '                            .initialize()
        '                            .strLocation1 = RTrim(Mid(gclsDB.Records("PKCJ01").Item("StockLctn"), 1, 2))
        '                            .strLocation2 = RTrim(Mid(gclsDB.Records("PKCJ01").Item("StockLctn"), 3))
        '                            '画面表示用部品番号の取得
        '                            .strItemInCode = RTrim(gclsDB.Records("PKCJ01").Item("ItemInCode"))
        '                            wstrItemInCodeDisp = RTrim(gclsDB.Records("PKCJ01").Item("ItemInCodeDisp"))
        '                            .strPartNoDisp = RTrim(Mid(wstrItemInCodeDisp, 1, 12))
        '                            .strCL = RTrim(Mid(wstrItemCode, 11, 2))
        '                            .strZ = RTrim(Mid(wstrItemCode, 13, 1))
        '                            'wstrLocPart = RTrim(gclsDB.Records("PKCJ01").Item("StockLctn"))
        '                            'wstrLocPart = wstrLocPart.PadRight(5, " ")
        '                            'wstrLocPart = gstrctPPDisp.strCrtnNo & gstrctPPDisp.strCrtnNo & wstrLocPart & RTrim(gclsDB.Records("PKCJ01").Item("ItemInCode"))
        '                            wstrLocPart = .strItemInCode
        '                            'gstrctPPDisp.fSetQty(wstrLocPart, RTrim(gclsDB.Records("PKCJ01").Item("PackQtyJ")), 1)
        '                            'gstrctPPDisp.fSetPkg(wstrLocPart, 1, 1)
        '                            wstrPlanQty = RTrim(gclsDB.Records("PKCJ01").Item("PackQtyJ"))
        '                        End With

        '                        wstrKeyValue(1) = RTrim(.Item("ItemInCode"))
        '                        wstrKeyValue(2) = RTrim(.Item("PlanSerial"))


        '                        '// DB更新
        '                        With gclsDB
        '                            .Setcolumn = "PickFlag"
        '                            .SetData = G_CONST_ST_PKCJ_PACKED

        '                            If .fUpdRecords(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY06, wstrKey, wstrKeyValue) = -1 Then
        '                                gclsDB.fCloseRecord("PKCJ01")
        '                                BtLib.Transaction.Abort()
        '                                Exit Function
        '                            End If
        '                        End With
        '                        bFound = True

        '                        'Exit Do

        '                    End If

        '                    If RTrim(.Item("PickFlag")) = G_CONST_ST_PKCJ_PACKED Then
        '                        wintCnt += 1
        '                    End If

        '                Else
        '                    Exit Do
        '                End If

        '            End With

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

        '    End If

        '    gclsDB.fCloseRecord("PKCJ01")

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

        '    If Not bFound Then
        '        fProcData4SRetry = -2
        '        Exit Function
        '    End If

        '    gstrctPPDisp.fSetQty(wstrLocPart, wstrPlanQty, 1)
        '    gstrctPPDisp.fSetPkg(wstrLocPart, 1, 1)
        '    pintCnt = wintCnt + 1

        '    fProcData4SRetry = 0
        '    Exit Function

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

    End Function


    '/*
    '|| 関数名：fProcData4SRetry2
    '|| 概要  ：スキャンリトライ入力処理（リスト用）
    '|| 戻り値: 0(正常): -1(DBｴﾗｰ): -2(ﾃﾞｰﾀ無し): -3(ﾀﾞﾌﾞﾙｽｷｬﾝ)　 
    '*/
    Public Function fProcData4SRetry2(ByVal pstrInput As String, ByRef pintCnt As Integer)
        Dim wstrItemCode As String
        Dim wstrItemCode2 As String
        Dim wstrSerialNo As String
        Dim wstrItemInCodeDisp As String
        Dim bTry As Boolean
        Dim bFound As Boolean
        Dim rtn As Integer
        Dim wintCnt As Integer
        Dim wstrKey(2) As String
        Dim wstrKeyValue(2) As String
        Dim wstrWhere As String

        fProcData4SRetry2 = -1

        Try

            If pstrInput <> "NOUPDATE" And pstrInput <> "ZEROOK" Then

                bTry = True
                wstrItemCode = RTrim(Mid(pstrInput, 2, 13))
                If pstrInput.Length() = G_CONST_LLEN_PRT1 Then
                    wstrSerialNo = "999999"
                Else
                    wstrSerialNo = RTrim(Mid(pstrInput, 20, 6))
                End If

            Else
                bTry = False
            End If

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

            wstrKey(0) = "ItemCode"
            wstrKey(1) = "ItemInCode"
            wstrKey(2) = "PlanSerial"
            wstrKeyValue(0) = Mid(gstrctKDPP.strItemGr, 1, 20) & gstrctPPDisp.strCrtnNo
            wstrKeyValue(1) = Space(30)
            wstrKeyValue(2) = Space(6)

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemCode As String = ""
            Dim sPackQtyJ As String = ""
            Dim sStockLctn As String = ""
            Dim sPickFlag As String = ""
            Dim sItemInCode As String = ""
            Dim sItemInID As String = ""
            Dim sPlanSerial As String = ""
            Dim sSerialNo As String = ""
            Dim sItemInCodeDisp As String = ""
            Dim i As Integer = 0

            Erase gastrctPPDispPart
            ReDim gastrctPPDispPart(4)
            wintCnt = 0

            If tmpStr.Count > 0 Then

                Do
                    values = tmpStr(i)

                    Dim result As String = Nothing
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("PackQtyJ", result) Then
                        sPackQtyJ = RTrim(result)
                    End If
                    If values.TryGetValue("StockLctn", result) Then
                        sStockLctn = RTrim(result)
                    End If
                    If values.TryGetValue("PickFlag", result) Then
                        sPickFlag = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInID", result) Then
                        sItemInID = RTrim(result)
                    End If
                    If values.TryGetValue("PlanSerial", result) Then
                        sPlanSerial = RTrim(result)
                    End If
                    If values.TryGetValue("SerialNo", result) Then
                        sSerialNo = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCodeDisp", result) Then
                        sItemInCodeDisp = RTrim(result)
                    End If


                    If wstrKeyValue(0) = RTrim(sItemCode) Then

                        If Not bFound And pstrInput = "ZEROOK" And _
                           "00000" = RTrim(sPackQtyJ) And _
                           "?????" = RTrim(sStockLctn) And _
                           G_CONST_ST_PKCJ_CHECK = RTrim(sPickFlag) Then

                            wstrKeyValue(1) = RTrim(sItemInCode)
                            wstrKeyValue(2) = RTrim(sPlanSerial)

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

                            affected_rows = dbClient.Execute("UPDATE " + G_CONST_TBL_PACKCJ + " SET PickFlag='" _
                                                                 + G_CONST_ST_PKCJ_PACKED _
                                                                 + "' WHERE " + wstrWhere)


                            If affected_rows = 0 Then

                                Exit Function

                            End If

                            bFound = True


                        ElseIf bTry And wstrItemCode = RTrim(sItemInCode) And _
                           (wstrSerialNo = RTrim(sSerialNo) Or _
                           (Not bFound And wstrSerialNo = "999999" And G_CONST_ST_PKCJ_CHECK = RTrim(sPickFlag))) Then

                            If G_CONST_ST_PKCJ_PACKED = RTrim(sPickFlag) And wstrSerialNo <> "999999" Then
                                'gclsDB.fCloseRecord("PKCJ01
                                'fProcData4SRetry2 = -3
                                Exit Function
                            End If

                            wstrKeyValue(1) = RTrim(sItemInCode)
                            wstrKeyValue(2) = RTrim(sPlanSerial)

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

                            affected_rows = dbClient.Execute("UPDATE " + G_CONST_TBL_PACKCJ + " SET PickFlag='" _
                                                                 + G_CONST_ST_PKCJ_PACKED _
                                                                 + "' WHERE " + wstrWhere)

                          
                            bFound = True

                        ElseIf G_CONST_ST_PKCJ_CHECK = RTrim(sPickFlag) Then

                            '表示用データの取得
                            With gastrctPPDispPart(wintCnt)
                                .initialize()
                                .strID = RTrim(sItemInID)
                                '表示用部品番号の編集
                                wstrItemInCodeDisp = RTrim(sItemInCodeDisp)
                                .strPartNoDisp = Mid(wstrItemInCodeDisp, 1, 12)
                                wstrItemCode2 = RTrim(Mid(sItemInCode, 1, 10))
                                .strCL = Mid(wstrItemCode2, 11, 2)
                                .strZ = Mid(wstrItemCode2, 13, 1)
                                .strSerial = RTrim(sSerialNo)
                            End With

                            wintCnt += 1

                        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 Not bFound And pstrInput <> "NOUPDATE" Then
                fProcData4SRetry2 = -2
                Exit Function
            End If
            pintCnt = wintCnt

            fProcData4SRetry2 = 0
            Exit Function

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



            'rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY06, "PKCJ01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
            'If rtn = 9 Then
            '    fProcData4SRetry2 = -2
            '    gclsDB.fCloseRecord("PKCJ01")
            '    BtLib.Transaction.Abort()
            '    Exit Function
            'ElseIf rtn <> 0 Then
            '    gclsDB.fCloseRecord("PKCJ01")
            '    BtLib.Transaction.Abort()
            '    Exit Function
            'End If

            'Erase gastrctPPDispPart
            'ReDim gastrctPPDispPart(4)
            'wintCnt = 0
            'If rtn = 0 Then
            '    Do
            '        With gclsDB.Records("PKCJ01")
            '            If wstrKeyValue(0) = RTrim(.Item("ItemCode")) Then

            '                If Not bFound And pstrInput = "ZEROOK" And _
            '                   "00000" = RTrim(.Item("PackQtyJ")) And _
            '                   "?????" = RTrim(.Item("StockLctn")) And _
            '                   G_CONST_ST_PKCJ_CHECK = RTrim(.Item("PickFlag")) Then

            '                    wstrKeyValue(1) = RTrim(.Item("ItemInCode"))
            '                    wstrKeyValue(2) = RTrim(.Item("PlanSerial"))

            '                    '// DB更新
            '                    With gclsDB
            '                        .Setcolumn = "PickFlag"
            '                        .SetData = G_CONST_ST_PKCJ_PACKED

            '                        If .fUpdRecords(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY06, wstrKey, wstrKeyValue) = -1 Then
            '                            gclsDB.fCloseRecord("PKCJ01")
            '                            BtLib.Transaction.Abort()
            '                            Exit Function
            '                        End If
            '                    End With
            '                    bFound = True
            '                ElseIf bTry And wstrItemCode = RTrim(.Item("ItemInCode")) And _
            '                   (wstrSerialNo = RTrim(.Item("SerialNo")) Or _
            '                   (Not bFound And wstrSerialNo = "999999" And G_CONST_ST_PKCJ_CHECK = RTrim(.Item("PickFlag")))) Then

            '                    If G_CONST_ST_PKCJ_PACKED = RTrim(.Item("PickFlag")) And wstrSerialNo <> "999999" Then
            '                        gclsDB.fCloseRecord("PKCJ01")
            '                        fProcData4SRetry2 = -3
            '                        Exit Function
            '                    End If

            '                    wstrKeyValue(1) = RTrim(.Item("ItemInCode"))
            '                    wstrKeyValue(2) = RTrim(.Item("PlanSerial"))

            '                    '// DB更新
            '                    With gclsDB
            '                        .Setcolumn = "PickFlag"
            '                        .SetData = G_CONST_ST_PKCJ_PACKED

            '                        If .fUpdRecords(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY06, wstrKey, wstrKeyValue) = -1 Then
            '                            gclsDB.fCloseRecord("PKCJ01")
            '                            BtLib.Transaction.Abort()
            '                            Exit Function
            '                        End If
            '                    End With
            '                    bFound = True

            '                ElseIf G_CONST_ST_PKCJ_CHECK = RTrim(.Item("PickFlag")) Then

            '                    '表示用データの取得
            '                    With gastrctPPDispPart(wintCnt)
            '                        .initialize()
            '                        .strID = RTrim((gclsDB.Records("PKCJ01").Item("ItemInID")))
            '                        '表示用部品番号の編集
            '                        wstrItemInCodeDisp = RTrim(gclsDB.Records("PKCJ01").Item("ItemInCodeDisp"))
            '                        .strPartNoDisp = Mid(wstrItemInCodeDisp, 1, 12)
            '                        wstrItemCode2 = RTrim(Mid(gclsDB.Records("PKCJ01").Item("ItemInCode"), 1, 10))
            '                        .strCL = Mid(wstrItemCode2, 11, 2)
            '                        .strZ = Mid(wstrItemCode2, 13, 1)
            '                        .strSerial = RTrim(gclsDB.Records("PKCJ01").Item("SerialNo"))
            '                    End With

            '                    wintCnt += 1

            '                End If

            '            Else
            '                Exit Do
            '            End If

            '        End With

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

            'gclsDB.fCloseRecord("PKCJ01")

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

        '    If Not bFound And pstrInput <> "NOUPDATE" Then
        '        fProcData4SRetry2 = -2
        '        Exit Function
        '    End If
        '    pintCnt = wintCnt

        '    fProcData4SRetry2 = 0
        '    Exit Function

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

    End Function

    '/*
    '|| 関数名：fSearchPackCP
    '|| 概要  ：PACKCPをItemCodeで検索する
    '|| 引数　：1.ItemCode
    '||         2.キー
    '|| 戻り値：-1(NG)  -2:0件 0:1件以上
    '*/
    Public Function fSearchPackCP2(ByVal pstrItemCode As String, ByVal pstrKey As String, ByVal pstrTable As List(Of Dictionary(Of String, String))) As Integer
        fSearchPackCP2 = -1

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

            Dim i As String = 0

            If pstrTable.Count > 0 Then

                Do

                    values = pstrTable(i)
                    Dim result As String = Nothing
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If

                    If RTrim(pstrItemCode) = RTrim(sItemCode) Then
                        fSearchPackCP2 = 0
                        Exit Function
                    End If


                    i = i + 1

                    If pstrTable.Count = i Then
                        Exit Do
                    End If

                Loop

                fSearchPackCP2 = -2

            End If


            'With gclsDB.Records(pstrKey)
            '    Do
            '        If RTrim(pstrItemCode) = RTrim(.Item("ItemCode")) Then
            '            fSearchPackCP2 = 0
            '            Exit Function
            '        End If
            '        If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do
            '    Loop
            '    fSearchPackCP2 = -2
            'End With

        Catch ex As Exception
            sErrLog(gAppName, "fSearchPackCP2", ex.ToString)
        End Try
    End Function
    '/*
    '|| 関数名：fGetPrintKind（大物出庫用)
    '|| 概要  ：PACKCPをPickFlag=0 or PickFlag = 3のItemCodeで検索して
    '||         支障ﾗﾍﾞﾙまたはｺﾝﾃﾝﾂﾘｽﾄの判定をする
    '|| 引数　：1.ItemCode
    '||         2.キー
    '|| 戻り値：-1(NG)  -2(支障ﾗﾍﾞﾙ) 0:(ｺﾝﾃﾝﾂﾘｽﾄ)
    '*/
    Public Function fGetPrintKind(ByVal pstrItemCode As String, ByVal pstrKey As String) As Integer
        Dim wintAllCnt As Integer
        Dim wintICnt As Integer
        Dim wintCCnt As Integer
        fGetPrintKind = -1
        wintAllCnt = 0
        wintICnt = 0
        wintCCnt = 0
        Try
            'With gclsDB.Records(pstrKey)
            '    Do
            '        If RTrim(pstrItemCode) = RTrim(.Item("ItemCode")) Then
            '            wintAllCnt += 1
            '            If RTrim(.Item("PickFlag")) = "0" Then   'NotPacked
            '                wintICnt += 1
            '            ElseIf RTrim(.Item("PickFlag")) = "3" Then 'Packed
            '                wintCCnt += 1
            '            End If
            '        Else
            '            Exit Do
            '        End If
            '        If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do
            '    Loop
            '    If (wintAllCnt = wintICnt) Then '支障ﾗﾍﾞﾙ
            '        fGetPrintKind = -2
            '        Exit Function
            '    ElseIf (wintAllCnt = wintCCnt) Then 'ｺﾝﾃﾝﾂﾘｽﾄ
            '        fGetPrintKind = 0
            '        Exit Function
            '    End If
            'End With

        Catch ex As Exception
            sErrLog(gAppName, "fGetPrintKind", ex.ToString)
        End Try
    End Function
    '/*
    '|| 関数名：fSearchPackCJ
    '|| 概要  ：PACKCJをItemCodeで検索する
    '|| 引数　：ItemCode
    '|| 戻り値：-1(NG)   -2:0件  0:1件以上
    '*/
    Public Function fSearchPackCJ(ByVal pstrItemCode As String, ByVal pstrKey As String, ByVal pstrTable As List(Of Dictionary(Of String, String))) As Integer
        Dim i As Integer
        Dim rtn As Integer
        Dim wstrKey(2), wstrKeyValue(2) As String
        fSearchPackCJ = -1

        Try

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

            i = 0

            If pstrTable.Count > 0 Then

                Do

                    values = pstrTable(i)
                    Dim result As String = Nothing
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If

                    If RTrim(pstrItemCode) = RTrim(sItemCode) Then
                        fSearchPackCJ = 0
                        Exit Function
                    End If

                    i = i + 1

                    If pstrTable.Count = i Then
                        Exit Do
                    End If

                Loop

                fSearchPackCJ = -2

            End If



            'With gclsDB.Records(pstrKey)
            '    Do
            '        If RTrim(pstrItemCode) = RTrim(.Item("ItemCode")) Then
            '            fSearchPackCJ = 0
            '            Exit Function
            '        End If
            '        If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do
            '    Loop
            '    fSearchPackCJ = -2
            'End With

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

    End Function
    '/*
    '|| 関数名：fEditErrorInfo
    '|| 概要  ：Btrieveのｽﾃｰﾀｽとﾌｧｲﾙを編集して表示する
    '|| 引数　：1.ｽﾃｰﾀｽ　
    '||         2.Btrieveﾌｧｲﾙ名
    '|| 戻り値：ｴﾗｰﾒｯｾｰｼﾞ
    '*/
    Public Function fEditErrorInfo(ByVal pstrErrorCode As String, ByVal pstrErrorFile As String) As String
        fEditErrorInfo = pstrErrorCode.PadRight(14) + pstrErrorFile.PadRight(14) + G_CONST_EM_DB
    End Function

End Module

