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 modPublic000

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

    Public Structure ITEMINCODE_STR

        Public astrItemInCode() As String
        Public intIndex As Integer

        Public Sub initialize()
            Erase astrItemInCode
            intIndex = -1
        End Sub

        Public Sub ProcItem(ByVal strItemInCode As String)

            Dim i As Integer
            Dim flag As Boolean

            If intIndex = -1 Then
                ReDim astrItemInCode(0)
                astrItemInCode(0) = strItemInCode
                intIndex = 1
            Else
                For i = 0 To intIndex - 1
                    If astrItemInCode(i) = strItemInCode Then
                        Exit Sub
                    End If
                Next
                ReDim Preserve astrItemInCode(intIndex)
                astrItemInCode(intIndex) = strItemInCode
                intIndex += 1
            End If

        End Sub
    End Structure

    '/*
    '|| 関数名：fGetCountry
    '|| 概要  ：国コード取得
    '*/
    Public Function fGetCountry() As Integer

        '端末ID確認＆国ｺｰﾄﾞ入力
        Dim wintCnt As Integer
        Dim wstrWhere As String
        Dim wstrCount As String
        Dim wstrUserNo As String
        Dim wstrKeyFlg As String
        Dim wstrKey(0) As String, wstrKeyValue(0) As String
        Dim sSQL As String

        fGetCountry = -1

        Try

            'BtLib.Transaction.BeginConCurrent()

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

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sCountry As String = ""
            Dim sEmplCode As String = ""
            Dim sSectionID As String = ""
            Dim sSection As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""
            Dim sPackType As String = ""
            Dim sS6030 As String = ""
            Dim sSearchKey As String = ""


            If tmpStr.Count > 0 Then
                values = tmpStr(0)
                Dim result As String = Nothing
                If values.TryGetValue("Country", result) Then
                    sCountry = RTrim(result)
                    Console.WriteLine("RESULT: {0}", result)
                End If
                If values.TryGetValue("EmplCode", result) Then
                    sEmplCode = RTrim(result)
                    Console.WriteLine("RESULT: {0}", result)
                End If
                If values.TryGetValue("SectionID", result) Then
                    sSectionID = RTrim(result)
                    Console.WriteLine("RESULT: {0}", result)
                End If
                If values.TryGetValue("Section", result) Then
                    sSection = RTrim(result)
                    Console.WriteLine("RESULT: {0}", result)
                End If
                If values.TryGetValue("Cstmid", result) Then
                    sCstmid = RTrim(result)
                    Console.WriteLine("RESULT: {0}", result)
                End If
                If values.TryGetValue("CstmCode", result) Then
                    sCstmCode = RTrim(result)
                    Console.WriteLine("RESULT: {0}", result)
                End If
                If values.TryGetValue("PackType", result) Then
                    sPackType = RTrim(result)
                    Console.WriteLine("RESULT: {0}", result)
                End If
                If values.TryGetValue("S6030", result) Then
                    sS6030 = RTrim(result)
                    Console.WriteLine("RESULT: {0}", result)
                End If
                If values.TryGetValue("SearchKey", result) Then
                    sSearchKey = RTrim(result)
                    Console.WriteLine("RESULT: {0}", result)
                End If

                wstrCount = fstrZeroput(3, sCountry)    '前Zero埋め
                wstrUserNo = sEmplCode
                gstrctKDHT.strSectionID = sSectionID
                gstrctKDHT.strSection = sSection
                gstrctKDHT.strCstmid = sCstmid
                gstrctKDHT.strCstmCode = sCstmCode
                gstrctKDHT.strPackType = sPackType
                gstrctKDHT.strS6030 = sS6030
                'gstrctKDPL.initialize()
                gstrctKDPL.strSectionID = RTrim(sSectionID)
                gstrctKDPL.strSection = RTrim(sSection)
                gstrctKDPL.strSearchKey = RTrim(sSearchKey)

                If wstrCount <> "000" Then        '国ｺｰﾄﾞが入力されている

                    gstrctKDHT.strCountry = wstrCount
                    gstrctKDHT.strUserNo = wstrUserNo
                    fGetCountry = 0
                    Exit Function

                ElseIf wstrCount = "000" Then     '国ｺｰﾄﾞが入力されていなければ"001"を入力する

                    wstrCount = "001"
                    wstrKeyFlg = "0"

                End If


            Else

                wstrCount = "001"
                wstrKeyFlg = "1"


            End If

            gstrctKDHT.strCountry = "001"

            Select Case wstrKeyFlg

                Case "0"        '更新ﾃﾞｰﾀ

                    'gclsDB.Setcolumn = ("Country")          '登録/更新対象列名
                    'gclsDB.SetData = (gstrctKDHT.strCountry)      '登録/更新データ

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

                    wstrWhere = ""
                    wstrWhere = wstrKey(0) & " = '" & wstrKeyValue(0) & "'"


                    sSQL = "UPDATE " + G_CONST_TBL_HTCTRL + " SET Country='" _
                                                         + gstrctKDHT.strCountry _
                                                         + "' WHERE " + wstrWhere

                    affected_rows = dbClient.Execute(sSQL)




                Case "1"        '新規ﾃﾞｰﾀ

                    sSQL = "INSERT INTO " & G_CONST_TBL_HTCTRL & " (HTNumber,Country) VALUES ('" _
                            & gstrctKDHT.strHdNo & "','" & gstrctKDHT.strCountry & "')"

                    affected_rows = dbClient.Execute(sSQL)

                    'gclsDB.Setcolumn = ("HTNumber,Country")          '登録/更新対象列名
                    'gclsDB.SetData = (gstrctKDHT.strHdNo & "," & gstrctKDHT.strCountry)      '登録/更新データ

                    'If gclsDB.fInsRecord(G_CONST_TBL_HTCTRL) = -1 Then
                    '    BtLib.Transaction.Abort()

                    'End If

            End Select


            fGetCountry = 0

            Exit Function

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



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

        'If wintCnt > 0 Then             'ﾃﾞｰﾀがあれば国ｺｰﾄﾞを検索

        '    With gclsDB.Extended("HTCTRL1")

        '        wstrCount = fstrZeroput(3, .Item("Country"))    '前Zero埋め
        '        wstrUserNo = .Item("EmplCode")
        '        gstrctKDHT.strSectionID = .Item("SectionID")
        '        gstrctKDHT.strSection = .Item("Section")
        '        gstrctKDHT.strCstmid = .Item("Cstmid")
        '        gstrctKDHT.strCstmCode = .Item("CstmCode")
        '        gstrctKDHT.strPackType = .Item("PackType")
        '        gstrctKDHT.strS6030 = .Item("S6030")
        '        'gstrctKDPP.initialize()
        '        gstrctKDPP.strSectionID = RTrim(.Item("SectionID"))
        '        gstrctKDPP.strSection = RTrim(.Item("Section"))
        '        gstrctKDPP.strSearchKey = RTrim(.Item("SearchKey"))

        '        If wstrCount <> "000" Then        '国ｺｰﾄﾞが入力されている

        '            gstrctKDHT.strCountry = wstrCount
        '            gstrctKDHT.strUserNo = wstrUserNo
        '            gclsDB.fCloseRecord("HTCTRL1")
        '            fGetCountry = 0
        '            Exit Function

        '        ElseIf wstrCount = "000" Then     '国ｺｰﾄﾞが入力されていなければ"001"を入力する

        '            wstrCount = "001"
        '            wstrKeyFlg = "0"

        '        End If
        '    End With

        'ElseIf wintCnt = 0 Then       'ﾃﾞｰﾀがなければ端末番号・国ｺｰﾄﾞ("001")を追加する

        '    With gclsDB.Extended("HTCTRL1")
        '        wstrCount = "001"
        '        wstrKeyFlg = "1"
        '    End With

        'ElseIf wintCnt = -1 Then
        '    gclsDB.fCloseRecord("HTCTRL1")
        '    Exit Function

        'End If

        'gclsDB.fCloseRecord("HTCTRL1")

        ''更新ﾃﾞｰﾀ、新規ﾃﾞｰﾀをDBに登録
        'gstrctKDHT.strCountry = "001"
        'Select Case wstrKeyFlg

        '    Case "0"        '更新ﾃﾞｰﾀ

        '        gclsDB.Setcolumn = ("Country")          '登録/更新対象列名
        '        gclsDB.SetData = (gstrctKDHT.strCountry)      '登録/更新データ

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

        '        End If

        '    Case "1"        '新規ﾃﾞｰﾀ
        '        gclsDB.Setcolumn = ("HTNumber,Country")          '登録/更新対象列名
        '        gclsDB.SetData = (gstrctKDHT.strHdNo & "," & gstrctKDHT.strCountry)      '登録/更新データ

        '        If gclsDB.fInsRecord(G_CONST_TBL_HTCTRL) = -1 Then
        '            BtLib.Transaction.Abort()

        '        End If

        'End Select

        'BtLib.Transaction.End()

        'fGetCountry = 0

        'Exit Function

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

    End Function


    '/*
    '|| 関数名：fGetTitle
    '|| 概要  ：タイトルコード取得
    '*/
    Public Function fGetTitle() As Integer

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

        fGetTitle = -1

        Try

            'BtLib.Transaction.BeginConCurrent()

            'wstrWhere = ""
            'wstrWhere = "@Country = " & gstrctKDHT.strCountry
            'wstrWhere &= " & @PrgID = " & gstrctKDHT.strPrgID


            wstrWhere = ""
            wstrWhere = "Country" & " = '" & gstrctKDHT.strCountry & "'"
            wstrWhere &= " and " & "PrgID" & " = '" & gstrctKDHT.strPrgID & "'"

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

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

            If tmpStr.Count > 0 Then
                values = tmpStr(0)
                Dim result As String = Nothing
                If values.TryGetValue("Title", result) Then
                    sTitle = RTrim(result)
                End If

                gstrctKDHT.strTitle = sTitle

            Else
                fGetTitle = -2

                Exit Function

            End If

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

            wstrWhere = ""
            wstrWhere = wstrKey(0) & " = '" & wstrKeyValue(0) & "'"

            sSQL = "UPDATE " + G_CONST_TBL_HTCTRL + " SET ExeName='" _
                                                         + gstrctKDHT.strPrgID _
                                                         + "' WHERE " + wstrWhere

            affected_rows = dbClient.Execute(sSQL)


            fGetTitle = 0

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




        'wintCnt = gclsDB.fGetData(G_CONST_TBL_HTTITLE, G_CONST_KEY_HTTITLEKEY00, wstrWhere, "TITLE1")

        'If wintCnt > 0 Then

        '    gstrctKDHT.strTitle = gclsDB.Extended("TITLE1").Item("Title")


        'ElseIf wintCnt = 0 Then
        '    gclsDB.fCloseRecord("TITLE1")
        '    fGetTitle = -2
        '    Exit Function

        'ElseIf wintCnt = -1 Then
        '    gclsDB.fCloseRecord("TITLE1")
        '    Exit Function

        'End If

        'gclsDB.fCloseRecord("TITLE1")

        'gclsDB.Setcolumn = ("ExeName")              '登録/更新対象列名
        'gclsDB.SetData = (gstrctKDHT.strPrgID)     '登録/更新データ

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

        'End If

        'BtLib.Transaction.End()

        'fGetTitle = 0

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

    End Function


    '/*
    '|| 関数名：fGetEmplName
    '|| 概要  ：作業者名取得
    '*/
    Public Function fGetEmplName(ByVal pstrUserNo As String) As Integer

        Dim rtn As Integer
        Dim wstrWhere As String
        Dim wintCnt As Integer

        fGetEmplName = -1

        Try

            '検索を開始します
            'wstrWhere = ""
            'wstrWhere = "@EmplCode = " & pstrUserNo

            wstrWhere = ""
            wstrWhere = "EmplCode" & " = '" & pstrUserNo & "'"

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

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

            If tmpStr.Count > 0 Then

                values = tmpStr(0)

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

                gstrctKDHT.strUserName = sEmplName

            Else

                fGetEmplName = -2
                Exit Function

            End If

            fGetEmplName = 0

            Exit Function

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




        'wintCnt = gclsDB.fGetData(G_CONST_TBL_PICSUSER, G_CONST_KEY_PICSUSERKEY00, wstrWhere, "USER1")
        'If wintCnt > 0 Then

        '    gstrctKDHT.strUserName = gclsDB.Extended("USER1").Item("EmplName")

        'ElseIf wintCnt = 0 Then

        '    fGetEmplName = -2
        '    gclsDB.fCloseRecord("USER1")
        '    Exit Function

        'ElseIf wintCnt = -1 Then

        '    gclsDB.fCloseRecord("USER1")
        '    Exit Function

        'End If

        'gclsDB.fCloseRecord("USER1")
        'fGetEmplName = 0

        'Exit Function

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

    End Function

    '/*
    '|| 関数名：fMakeRecovery
    '|| 概要  ：リカバリ処理
    '*/
    Public Function fMakeRecovery() As Integer

        Dim rtn As Integer
        Dim flag As Boolean
        Dim wstrKey(6) As String
        Dim wstrKeyValue(6) As String
        Dim wstrKey2(2) As String
        Dim wstrKeyValue2(2) As String
        Dim wstrTmp As String
        Dim wstrctItemInCode As ITEMINCODE_STR
        Dim wstrWhere As String

        fMakeRecovery = -1
        wstrctItemInCode.initialize()

        Try

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


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

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemGr As String = ""
            Dim sWKSumDate As String = ""
            Dim sPackNo As String = ""
            Dim sCenterCode As String = ""
            Dim sBhk As String = ""
            Dim sItemCode As String = ""
            Dim sStockLctn As String = ""
            Dim sItemInCode As String = ""
            Dim sBunkatuJ As String = ""
            Dim i As String = 0
            flag = False

            If tmpStr.Count = 0 Then

                Exit Function

            Else

                Do

                    values = tmpStr(i)
                    Dim result As String = Nothing
                    If values.TryGetValue("ItemGr", result) Then
                        sItemGr = RTrim(result)
                    End If
                    If values.TryGetValue("WKSumDate", result) Then
                        sWKSumDate = RTrim(result)
                    End If
                    If values.TryGetValue("PackNo", result) Then
                        sPackNo = RTrim(result)
                    End If
                    If values.TryGetValue("CenterCode", result) Then
                        sCenterCode = RTrim(result)
                    End If
                    If values.TryGetValue("Bhk", result) Then
                        sBhk = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("StockLctn", result) Then
                        sStockLctn = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If
                    If values.TryGetValue("sBunkatuJ", result) Then
                        sBunkatuJ = RTrim(result)
                    End If
                    If values.TryGetValue("PackNo", result) Then
                        sPackNo = RTrim(result)
                    End If
                    If values.TryGetValue("PackNo", result) Then
                        sPackNo = RTrim(result)
                    End If

                    If wstrKeyValue(0) = RTrim(sItemGr) Then
                        If Not flag Then
                            gstrctAicCase.YYYYMMDD = RTrim(sWKSumDate)
                            gstrctKDPP.strItemGr = RTrim(sItemGr)
                            gstrctPPDisp.strAic = Mid(RTrim(sItemGr), 1, 13)
                            gstrctPPDisp.strMsc = Mid(RTrim(sItemGr), 1, 7)
                            gstrctPPDisp.strPNT = Mid(RTrim(sItemGr), 8, 3)
                            gstrctPPDisp.strTRM = Mid(RTrim(sItemGr), 11, 3)
                            gstrctPPDisp.strCaseNo = Mid(RTrim(sItemGr), 14, 7)
                            gstrctPPDisp.strCrtnFrom = Mid(RTrim(sItemGr), 21, 5)
                            gstrctPPDisp.strCrtnTo = Mid(RTrim(sItemGr), 26, 5)
                            gstrctPPDisp.strCrtnNo = Mid(RTrim(sItemGr), 21, 5)
                            gstrctPPDisp.strSeq = RTrim(sPackNo)
                            gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
                            gstrctKDPP.strCenterCode = RTrim(sCenterCode)
                            gstrctKDPP.strBhk = RTrim(sBhk)

                            If rtn = 0 Then rtn = fGetKasoLine("PKCPRE1", wstrTmp)
                            gstrctPPDisp.strLine = wstrTmp
                            If rtn = 0 Then rtn = fGetCartonType("PKCPRE1", wstrTmp)
                            If rtn = 0 Then gstrctPPDisp.strCrtnType = wstrTmp
                            If rtn <> 0 Then
                                Exit Function
                            End If
                        End If

                        gstrctPPDisp.strItemCode = RTrim(sItemCode)
                        gstrctPPDisp.intNumOfPkg += 1
                        gstrctPPDisp.fSetQty(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), RTrim(sBunkatuJ))
                        gstrctPPDisp.fSetPkg(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), 1)
                        wstrctItemInCode.ProcItem(RTrim(sItemCode))
                        flag = True
                    Else
                        If flag Then
                            Exit Do
                        Else
                            'gclsDB.fCloseRecord("PKCPRE1")
                            Exit Function
                        End If
                    End If

                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If

                Loop

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

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

            If tmpStr.Count = 0 Then
                Exit Function


            Else

                Do

                    values = tmpStr(i)
                    Dim result As String = Nothing
                    If values.TryGetValue("ItemGr", result) Then
                        sItemGr = RTrim(result)
                    End If
                    If values.TryGetValue("WKSumDate", result) Then
                        sWKSumDate = RTrim(result)
                    End If
                    If values.TryGetValue("PackNo", result) Then
                        sPackNo = RTrim(result)
                    End If
                    If values.TryGetValue("CenterCode", result) Then
                        sCenterCode = RTrim(result)
                    End If
                    If values.TryGetValue("Bhk", result) Then
                        sBhk = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("StockLctn", result) Then
                        sStockLctn = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If
                    If values.TryGetValue("sBunkatuJ", result) Then
                        sBunkatuJ = RTrim(result)
                    End If
                    If values.TryGetValue("PackNo", result) Then
                        sPackNo = RTrim(result)
                    End If
                    If values.TryGetValue("PackNo", result) Then
                        sPackNo = RTrim(result)
                    End If

                    If wstrKeyValue(0) = RTrim(sItemGr) Then
                        gstrctPPDisp.strItemCode = RTrim(sItemCode)
                        gstrctPPDisp.intNumOfPkg += 1
                        gstrctPPDisp.fSetQty(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), RTrim(sBunkatuJ))
                        gstrctPPDisp.fSetPkg(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), 1)

                        gstrctPPDisp.intNumOfScanned += 1
                        gstrctPPDisp.fSetQty(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), RTrim(sBunkatuJ), 1)
                        gstrctPPDisp.fSetPkg(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), 1, 1)
                        gstrctPPDispPart.bLocked = False
                        wstrctItemInCode.ProcItem(RTrim(sItemInCode))
                        If Not flag Then
                            gstrctKDPP.strItemGr = RTrim(sItemGr)
                            gstrctKDPP.strCenterCode = RTrim(sCenterCode)
                            gstrctKDPP.strBhk = RTrim(sBhk)

                            gstrctPPDisp.strAic = Mid(RTrim(sItemGr), 1, 13)
                            gstrctPPDisp.strMsc = Mid(RTrim(sItemGr), 1, 7)
                            gstrctPPDisp.strPNT = Mid(RTrim(sItemGr), 8, 3)
                            gstrctPPDisp.strTRM = Mid(RTrim(sItemGr), 11, 3)
                            gstrctPPDisp.strCaseNo = Mid(RTrim(sItemGr), 14, 7)
                            gstrctPPDisp.strCrtnFrom = Mid(RTrim(sItemGr), 21, 5)
                            gstrctPPDisp.strCrtnTo = Mid(RTrim(sItemGr), 26, 5)
                            gstrctPPDisp.strCrtnNo = Mid(RTrim(sItemGr), 21, 5)
                            gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
                            gstrctPPDisp.strSeq = RTrim(sPackNo)




                        End If
                    Else
                        Exit Do
                    End If

                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If


                Loop



            End If


            gstrctPPDisp.intNumOfItem = wstrctItemInCode.intIndex

            wstrKey2(0) = "CenterCode"
            wstrKey2(1) = "SectionID"
            wstrKey2(2) = "Section"
            wstrKeyValue2(0) = gstrctKDPP.strCenterCode
            wstrKeyValue2(1) = gstrctKDPP.strSectionID
            wstrKeyValue2(2) = gstrctKDPP.strSection


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

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

            If tmpStr.Count > 0 Then

                values = tmpStr(0)
                Dim result As String = Nothing
                If values.TryGetValue("SectionName", result) Then
                    sSectionName = RTrim(result)
                End If

                gstrctKDPP.strSectionName = RTrim(sSectionName)


            Else

                gstrctKDPP.strSectionName = " "
                Exit Function

            End If

            fMakeRecovery = 0

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





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

        'If rtn <> 0 Then
        '    'DBｴﾗｰの場合のみ-1を返しその他はPACKCJのﾁｪｯｸへ
        '    If rtn = -1 Then
        '        gclsDB.fCloseRecord("PKCPRE1")
        '        Exit Function
        '    End If
        'End If

        'flag = False
        'If rtn = 0 Then
        '    Do
        '        With gclsDB.Records("PKCPRE1")

        '            If wstrKeyValue(0) = RTrim(.Item("ItemGr")) Then
        '                If Not flag Then
        '                    gstrctAicCase.YYYYMMDD = RTrim(.Item("WKSumDate"))
        '                    gstrctKDPP.strItemGr = RTrim(.Item("ItemGr"))
        '                    gstrctPPDisp.strAic = Mid(RTrim(.Item("ItemGr")), 1, 13)
        '                    gstrctPPDisp.strMsc = Mid(RTrim(.Item("ItemGr")), 1, 7)
        '                    gstrctPPDisp.strPNT = Mid(RTrim(.Item("ItemGr")), 8, 3)
        '                    gstrctPPDisp.strTRM = Mid(RTrim(.Item("ItemGr")), 11, 3)
        '                    gstrctPPDisp.strCaseNo = Mid(RTrim(.Item("ItemGr")), 14, 7)
        '                    gstrctPPDisp.strCrtnFrom = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                    gstrctPPDisp.strCrtnTo = Mid(RTrim(.Item("ItemGr")), 26, 5)
        '                    gstrctPPDisp.strCrtnNo = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                    gstrctPPDisp.strSeq = RTrim(.Item("PackNo"))
        '                    gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
        '                    gstrctKDPP.strCenterCode = RTrim(.Item("CenterCode"))
        '                    gstrctKDPP.strBhk = RTrim(.Item("Bhk"))

        '                    If rtn = 0 Then rtn = fGetKasoLine("PKCPRE1", wstrTmp)
        '                    gstrctPPDisp.strLine = wstrTmp
        '                    If rtn = 0 Then rtn = fGetCartonType("PKCPRE1", wstrTmp)
        '                    If rtn = 0 Then gstrctPPDisp.strCrtnType = wstrTmp
        '                    If rtn <> 0 Then
        '                        gclsDB.fCloseRecord("PKCPRE1")
        '                        Exit Function
        '                    End If
        '                End If

        '                gstrctPPDisp.strItemCode = RTrim(.Item("ItemCode"))
        '                gstrctPPDisp.intNumOfPkg += 1
        '                gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")))
        '                gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1)
        '                wstrctItemInCode.ProcItem(RTrim(.Item("ItemInCode")))
        '                flag = True
        '            Else
        '                If flag Then
        '                    Exit Do
        '                Else
        '                    gclsDB.fCloseRecord("PKCPRE1")
        '                    Exit Function
        '                End If
        '            End If

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

        '        End With
        '    Loop
        'End If

        'gclsDB.fCloseRecord("PKCPRE1")

        'rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY03, "PKCJRE1", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)

        'If rtn <> 0 Then
        '    If rtn = -1 Then
        '        gclsDB.fCloseRecord("PKCJRE1")
        '        Exit Function
        '    End If
        'End If

        'If rtn = 0 Then
        '    Do
        '        With gclsDB.Records("PKCJRE1")

        '            If wstrKeyValue(0) = RTrim(.Item("ItemGr")) Then
        '                gstrctPPDisp.strItemCode = RTrim(.Item("ItemCode"))
        '                gstrctPPDisp.intNumOfPkg += 1
        '                gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")))
        '                gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1)

        '                gstrctPPDisp.intNumOfScanned += 1
        '                gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")), 1)
        '                gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1, 1)
        '                gstrctPPDispPart.bLocked = False
        '                wstrctItemInCode.ProcItem(RTrim(.Item("ItemInCode")))
        '                If Not flag Then
        '                    gstrctKDPP.strItemGr = RTrim(.Item("ItemGr"))
        '                    gstrctKDPP.strCenterCode = RTrim(.Item("CenterCode"))
        '                    gstrctKDPP.strBhk = RTrim(.Item("Bhk"))

        '                    gstrctPPDisp.strAic = Mid(RTrim(.Item("ItemGr")), 1, 13)
        '                    gstrctPPDisp.strMsc = Mid(RTrim(.Item("ItemGr")), 1, 7)
        '                    gstrctPPDisp.strPNT = Mid(RTrim(.Item("ItemGr")), 8, 3)
        '                    gstrctPPDisp.strTRM = Mid(RTrim(.Item("ItemGr")), 11, 3)
        '                    gstrctPPDisp.strCaseNo = Mid(RTrim(.Item("ItemGr")), 14, 7)
        '                    gstrctPPDisp.strCrtnFrom = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                    gstrctPPDisp.strCrtnTo = Mid(RTrim(.Item("ItemGr")), 26, 5)
        '                    gstrctPPDisp.strCrtnNo = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                    gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
        '                    gstrctPPDisp.strSeq = RTrim(.Item("PackNo"))


        '                End If
        '            Else
        '                Exit Do
        '            End If

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

        '        End With
        '    Loop
        'End If

        'gstrctPPDisp.intNumOfItem = wstrctItemInCode.intIndex

        'gclsDB.fCloseRecord("PKCJRE1")

        'wstrKey2(0) = "CenterCode"
        'wstrKey2(1) = "SectionID"
        'wstrKey2(2) = "Section"
        'wstrKeyValue2(0) = gstrctKDPP.strCenterCode
        'wstrKeyValue2(1) = gstrctKDPP.strSectionID
        'wstrKeyValue2(2) = gstrctKDPP.strSection

        'rtn = gclsDB.fOpenRecord(G_CONST_TBL_SECTION, G_CONST_KEY_SECTIONKEY00, "SECRE1", wstrKey2, wstrKeyValue2, BtLib.Operation.GetEqual)

        'If rtn <> 0 Then
        '    gstrctKDPP.strSectionName = " "
        '    gclsDB.fCloseRecord("SECRE1")
        '    Exit Function
        'End If

        'If rtn = 0 Then
        '    gstrctKDPP.strSectionName = RTrim(gclsDB.Records("SECRE1").Item("SectionName"))
        'End If

        'gclsDB.fCloseRecord("SECRE1")

        'fMakeRecovery = 0

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

    End Function

    '/*
    '|| 関数名：fMakeRecovery2
    '|| 概要  ：リカバリ処理
    '*/
    Public Function fMakeRecovery2() As Integer

        'Dim rtn As Integer
        'Dim flag As Boolean
        'Dim wstrKey(2) As String
        'Dim wstrKeyValue(2) As String
        'Dim wstrTmp As String
        'Dim wstrctItemInCode As ITEMINCODE_STR

        'fMakeRecovery2 = -1
        'wstrctItemInCode.initialize()

        'Try

        '    wstrKey(0) = "ItemCode"
        '    wstrKey(1) = "ItemInCode"
        '    wstrKey(2) = "PlanSerial"
        '    wstrKeyValue(0) = gstrctKDPP.strSearchKey
        '    wstrKeyValue(1) = Space(30)
        '    wstrKeyValue(2) = Space(6)

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

        '    If rtn <> 0 Then
        '        'DBｴﾗｰの場合のみ-1を返しその他はPACKCJのﾁｪｯｸへ
        '        If rtn = -1 Then
        '            gclsDB.fCloseRecord("PKCPRE1")
        '            Exit Function
        '        End If
        '    End If

        '    flag = False
        '    If rtn = 0 Then
        '        Do
        '            With gclsDB.Records("PKCPRE1")

        '                If wstrKeyValue(0) = RTrim(.Item("ItemCode")) Then
        '                    If Not flag Then
        '                        gstrctKDPP.strItemGr = RTrim(.Item("ItemGr"))
        '                        gstrctPPDisp.strAic = Mid(RTrim(.Item("ItemGr")), 1, 13)
        '                        gstrctPPDisp.strMsc = Mid(RTrim(.Item("ItemGr")), 1, 7)
        '                        gstrctPPDisp.strPNT = Mid(RTrim(.Item("ItemGr")), 8, 3)
        '                        gstrctPPDisp.strTRM = Mid(RTrim(.Item("ItemGr")), 11, 3)
        '                        gstrctPPDisp.strCaseNo = Mid(RTrim(.Item("ItemGr")), 14, 7)
        '                        gstrctPPDisp.strCrtnFrom = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                        gstrctPPDisp.strCrtnTo = Mid(RTrim(.Item("ItemGr")), 26, 5)
        '                        gstrctPPDisp.strSeq = RTrim(.Item("PackNo"))
        '                        gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
        '                        gstrctKDPP.strCenterCode = RTrim(.Item("CenterCode"))
        '                        gstrctKDPP.strBhk = RTrim(.Item("Bhk"))

        '                        If rtn = 0 Then rtn = fGetKasoLine("PKCPRE1", wstrTmp)
        '                        gstrctPPDisp.strLine = wstrTmp
        '                        If rtn = 0 Then rtn = fGetCartonType("PKCPRE1", wstrTmp)
        '                        If rtn = 0 Then gstrctPPDisp.strCrtnType = wstrTmp
        '                        If rtn <> 0 Then
        '                            gclsDB.fCloseRecord("PKCPRE1")
        '                            Exit Function
        '                        End If
        '                    End If

        '                    gstrctPPDisp.strItemCode = RTrim(.Item("ItemCode"))
        '                    gstrctPPDisp.intNumOfPkg += 1
        '                    gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")))
        '                    gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1)
        '                    wstrctItemInCode.ProcItem(RTrim(.Item("ItemInCode")))
        '                    flag = True
        '                Else
        '                    If flag Then
        '                        Exit Do
        '                    Else
        '                        gclsDB.fCloseRecord("PKCPRE1")
        '                        Exit Function
        '                    End If
        '                End If

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

        '            End With
        '        Loop
        '    End If

        '    gclsDB.fCloseRecord("PKCPRE1")

        '    rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY06, "PKCJRE1", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)

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

        '    If rtn = 0 Then
        '        Do
        '            With gclsDB.Records("PKCJRE1")

        '                If wstrKeyValue(0) = RTrim(.Item("ItemCode")) Then
        '                    gstrctPPDisp.strItemCode = RTrim(.Item("ItemCode"))
        '                    gstrctPPDisp.intNumOfPkg += 1
        '                    gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")))
        '                    gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1)

        '                    gstrctPPDisp.intNumOfScanned += 1
        '                    gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")), 1)
        '                    gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1, 1)
        '                    gstrctPPDispPart.bLocked = False
        '                    wstrctItemInCode.ProcItem(RTrim(.Item("ItemInCode")))
        '                    If Not flag Then
        '                        gstrctKDPP.strItemGr = RTrim(.Item("ItemGr"))
        '                        gstrctKDPP.strCenterCode = RTrim(.Item("CenterCode"))
        '                        gstrctKDPP.strBhk = RTrim(.Item("Bhk"))

        '                        gstrctPPDisp.strAic = Mid(RTrim(.Item("ItemGr")), 1, 13)
        '                        gstrctPPDisp.strMsc = Mid(RTrim(.Item("ItemGr")), 1, 7)
        '                        gstrctPPDisp.strPNT = Mid(RTrim(.Item("ItemGr")), 8, 3)
        '                        gstrctPPDisp.strTRM = Mid(RTrim(.Item("ItemGr")), 11, 3)
        '                        gstrctPPDisp.strCaseNo = Mid(RTrim(.Item("ItemGr")), 14, 7)
        '                        gstrctPPDisp.strCrtnFrom = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                        gstrctPPDisp.strCrtnTo = Mid(RTrim(.Item("ItemGr")), 26, 5)
        '                        gstrctPPDisp.strCrtnNo = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                        gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
        '                        gstrctPPDisp.strSeq = RTrim(.Item("PackNo"))


        '                    End If
        '                Else
        '                    Exit Do
        '                End If

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

        '            End With
        '        Loop
        '    End If

        '    gstrctPPDisp.intNumOfItem = wstrctItemInCode.intIndex

        '    gclsDB.fCloseRecord("PKCJRE1")

        '    fMakeRecovery2 = 0

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

    End Function

    '/*
    '|| 関数名：fMakeRecovery4Ohmono
    '|| 概要  ：リカバリ処理
    '*/
    Public Function fMakeRecovery4Ohmono() As Integer

        'Dim rtn As Integer
        'Dim flag As Boolean
        'Dim wstrKey(6) As String
        'Dim wstrKeyValue(6) As String
        'Dim wstrKey2(2) As String
        'Dim wstrKeyValue2(2) As String
        'Dim wstrTmp As String
        'Dim wstrctItemInCode As ITEMINCODE_STR

        'fMakeRecovery4Ohmono = -1
        'wstrctItemInCode.initialize()

        'Try

        '    wstrKey(0) = "ItemGr"
        '    wstrKey(1) = "ItemCode"
        '    wstrKey(2) = "SortLctn1"
        '    wstrKey(3) = "SortLctn2"
        '    wstrKey(4) = "SortLctn3"
        '    wstrKey(5) = "ItemInCode"
        '    wstrKey(6) = "TempSerial"
        '    wstrKeyValue(0) = gstrctKDPP.strSearchKey
        '    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, "PKCPRE1", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)

        '    If rtn <> 0 Then
        '        gclsDB.fCloseRecord("PKCPRE1")
        '        Exit Function
        '    End If

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

        '                    If Not flag Then
        '                        gstrctKDPP.strItemGr = RTrim(.Item("ItemGr"))
        '                        gstrctPPDisp.strAic = Mid(RTrim(.Item("ItemGr")), 1, 13)
        '                        gstrctPPDisp.strMsc = Mid(RTrim(.Item("ItemGr")), 1, 7)
        '                        gstrctPPDisp.strPNT = Mid(RTrim(.Item("ItemGr")), 8, 3)
        '                        gstrctPPDisp.strTRM = Mid(RTrim(.Item("ItemGr")), 11, 3)
        '                        gstrctPPDisp.strCaseNo = Mid(RTrim(.Item("ItemGr")), 14, 7)
        '                        gstrctPPDisp.strCrtnFrom = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                        gstrctPPDisp.strCrtnTo = Mid(RTrim(.Item("ItemGr")), 26, 5)
        '                        gstrctPPDisp.strCrtnNo = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                        gstrctPPDisp.strSeq = RTrim(.Item("PackNo"))
        '                        gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
        '                        gstrctKDPP.strCenterCode = RTrim(.Item("CenterCode"))
        '                        gstrctKDPP.strBhk = RTrim(.Item("Bhk"))

        '                        If rtn = 0 Then rtn = fGetKasoLine("PKCPRE1", wstrTmp)
        '                        gstrctPPDisp.strLine = wstrTmp
        '                        If rtn = 0 Then rtn = fGetCartonType("PKCPRE1", wstrTmp)
        '                        If rtn = 0 Then gstrctPPDisp.strCrtnType = wstrTmp
        '                        If rtn <> 0 Then
        '                            gclsDB.fCloseRecord("PKCPRE1")
        '                            Exit Function
        '                        End If
        '                        flag = True
        '                    End If

        '                    If G_CONST_ST_PKCP_NOSTOCK = RTrim(.Item("PickFlag")) Or G_CONST_ST_PKCP_INSTOCK = RTrim(.Item("PickFlag")) Then
        '                        gstrctPPDisp.strItemCode = RTrim(.Item("ItemCode"))
        '                        gstrctPPDisp.intNumOfPkg += 1
        '                        gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")))
        '                        gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1)
        '                        wstrctItemInCode.ProcItem(RTrim(.Item("ItemInCode")))
        '                    ElseIf G_CONST_ST_PKCP_PICKED = RTrim(.Item("PickFlag")) Then
        '                        gstrctPPDisp.strItemCode = RTrim(.Item("ItemCode"))
        '                        gstrctPPDisp.intNumOfPkg += 1
        '                        gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")))
        '                        gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1)

        '                        gstrctPPDisp.intNumOfScanned += 1
        '                        gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")), 1)
        '                        gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1, 1)
        '                        gstrctPPDispPart.bLocked = False
        '                        wstrctItemInCode.ProcItem(RTrim(.Item("ItemInCode")))
        '                    End If

        '                Else
        '                    If flag Then
        '                        Exit Do
        '                    Else
        '                        gclsDB.fCloseRecord("PKCPRE1")
        '                        Exit Function
        '                    End If
        '                End If

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

        '            End With
        '        Loop
        '    End If

        '    gclsDB.fCloseRecord("PKCPRE1")

        '    gstrctPPDisp.intNumOfItem = wstrctItemInCode.intIndex

        '    wstrKey2(0) = "CenterCode"
        '    wstrKey2(1) = "SectionID"
        '    wstrKey2(2) = "Section"
        '    wstrKeyValue2(0) = gstrctKDPP.strCenterCode
        '    wstrKeyValue2(1) = gstrctKDPP.strSectionID
        '    wstrKeyValue2(2) = gstrctKDPP.strSection

        '    rtn = gclsDB.fOpenRecord(G_CONST_TBL_SECTION, G_CONST_KEY_SECTIONKEY00, "SECRE1", wstrKey2, wstrKeyValue2, BtLib.Operation.GetEqual)

        '    If rtn <> 0 Then
        '        gstrctKDPP.strSectionName = " "
        '        gclsDB.fCloseRecord("SECRE1")
        '        Exit Function
        '    End If

        '    If rtn = 0 Then
        '        gstrctKDPP.strSectionName = RTrim(gclsDB.Records("SECRE1").Item("SectionName"))
        '    End If

        '    gclsDB.fCloseRecord("SECRE1")

        '    fMakeRecovery4Ohmono = 0

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

    End Function


    '/*
    '|| 関数名：fMakeRecovery4Ohmono2
    '|| 概要  ：リカバリ処理
    '*/
    Public Function fMakeRecovery4Ohmono2() As Integer

        Dim rtn As Integer
        Dim flag As Boolean
        Dim wstrKey(2) As String
        Dim wstrKeyValue(2) As String
        Dim wstrTmp As String
        Dim wstrctItemInCode As ITEMINCODE_STR
        Dim wstrWhere As String

        fMakeRecovery4Ohmono2 = -1
        wstrctItemInCode.initialize()

        Try

            wstrKey(0) = "ItemCode"
            wstrKey(1) = "ItemInCode"
            wstrKey(2) = "PlanSerial"
            wstrKeyValue(0) = gstrctKDPP.strSearchKey
            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_PACKCP + " WHERE " + wstrWhere)

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemCode As String = ""
            Dim sItemGr As String = ""
            Dim sPackNo As String = ""
            Dim sCenterCode As String = ""
            Dim sBhk As String = ""
            Dim sPickFlag As String = ""

            Dim sItemInCode As String = ""
            Dim sStockLctn As String = ""
            Dim sBunkatuJ As String = ""

            Dim i As Integer = 0

            If tmpStr.Count > 0 Then

                Do

                    values = tmpStr(i)

                    Dim result As String = Nothing
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("ItemGr", result) Then
                        sItemGr = RTrim(result)
                    End If
                    If values.TryGetValue("PackNo", result) Then
                        ssPackNo = RTrim(result)
                    End If
                    If values.TryGetValue("CenterCode", result) Then
                        sCenterCode = RTrim(result)
                    End If
                    If values.TryGetValue("Bhk", result) Then
                        sBhk = RTrim(result)
                    End If
                    If values.TryGetValue("PickFlag", result) Then
                        sPickFlag = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If
                    If values.TryGetValue("StockLctn", result) Then
                        sStockLctn = RTrim(result)
                    End If
                    If values.TryGetValue("BunkatuJ", result) Then
                        sBunkatuJ = RTrim(result)
                    End If


                    If wstrKeyValue(0) = RTrim(sItemCode) Then

                        If Not flag Then
                            gstrctKDPP.strItemGr = RTrim(sItemGr)
                            gstrctPPDisp.strAic = Mid(RTrim(sItemGr), 1, 13)
                            gstrctPPDisp.strMsc = Mid(RTrim(sItemGr), 1, 7)
                            gstrctPPDisp.strPNT = Mid(RTrim(sItemGr), 8, 3)
                            gstrctPPDisp.strTRM = Mid(RTrim(sItemGr), 11, 3)
                            gstrctPPDisp.strCaseNo = Mid(RTrim(sItemGr), 14, 7)
                            gstrctPPDisp.strCrtnFrom = Mid(RTrim(sItemGr), 21, 5)
                            gstrctPPDisp.strCrtnTo = Mid(RTrim(sItemGr), 26, 5)
                            gstrctPPDisp.strSeq = RTrim(sPackNo)
                            gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
                            gstrctKDPP.strCenterCode = RTrim(sCenterCode)
                            gstrctKDPP.strBhk = RTrim(sBhk)

                            If rtn = 0 Then rtn = fGetKasoLine("PKCPRE1", wstrTmp)
                            gstrctPPDisp.strLine = wstrTmp
                            If rtn = 0 Then rtn = fGetCartonType("PKCPRE1", wstrTmp)
                            If rtn = 0 Then gstrctPPDisp.strCrtnType = wstrTmp
                            If rtn <> 0 Then
                                'gclsDB.fCloseRecord("PKCPRE1")
                                Exit Function
                            End If
                            flag = True
                        End If

                        If G_CONST_ST_PKCP_NOSTOCK = RTrim(sPickFlag) Or G_CONST_ST_PKCP_INSTOCK = RTrim(sPickFlag) Then
                            gstrctPPDisp.strItemCode = RTrim(sItemCode)
                            gstrctPPDisp.intNumOfPkg += 1
                            gstrctPPDisp.fSetQty(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), RTrim(sBunkatuJ))
                            gstrctPPDisp.fSetPkg(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), 1)
                            wstrctItemInCode.ProcItem(RTrim(sItemInCode))
                        ElseIf G_CONST_ST_PKCP_PICKED = RTrim(sPickFlag) Then
                            gstrctPPDisp.strItemCode = RTrim(sItemCode)
                            gstrctPPDisp.intNumOfPkg += 1
                            gstrctPPDisp.fSetQty(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), RTrim(sBunkatuJ))
                            gstrctPPDisp.fSetPkg(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), 1)

                            gstrctPPDisp.intNumOfScanned += 1
                            gstrctPPDisp.fSetQty(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), RTrim(sBunkatuJ), 1)
                            gstrctPPDisp.fSetPkg(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), 1, 1)
                            gstrctPPDispPart.bLocked = False
                            wstrctItemInCode.ProcItem(RTrim(sItemInCode))
                        End If

                    Else
                        If flag Then
                            Exit Do
                        Else
                            'gclsDB.fCloseRecord("PKCPRE1")
                            Exit Function
                        End If
                    End If


                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If




                Loop


            End If


            gstrctPPDisp.intNumOfItem = wstrctItemInCode.intIndex

            fMakeRecovery4Ohmono2 = 0

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


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

        'If rtn <> 0 Then
        '    gclsDB.fCloseRecord("PKCPRE1")
        '    Exit Function
        'End If

        'flag = False
        'If rtn = 0 Then
        '    Do
        '        With gclsDB.Records("PKCPRE1")
        '            If wstrKeyValue(0) = RTrim(.Item("ItemCode")) Then

        '                If Not flag Then
        '                    gstrctKDPP.strItemGr = RTrim(.Item("ItemGr"))
        '                    gstrctPPDisp.strAic = Mid(RTrim(.Item("ItemGr")), 1, 13)
        '                    gstrctPPDisp.strMsc = Mid(RTrim(.Item("ItemGr")), 1, 7)
        '                    gstrctPPDisp.strPNT = Mid(RTrim(.Item("ItemGr")), 8, 3)
        '                    gstrctPPDisp.strTRM = Mid(RTrim(.Item("ItemGr")), 11, 3)
        '                    gstrctPPDisp.strCaseNo = Mid(RTrim(.Item("ItemGr")), 14, 7)
        '                    gstrctPPDisp.strCrtnFrom = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                    gstrctPPDisp.strCrtnTo = Mid(RTrim(.Item("ItemGr")), 26, 5)
        '                    gstrctPPDisp.strSeq = RTrim(.Item("PackNo"))
        '                    gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
        '                    gstrctKDPP.strCenterCode = RTrim(.Item("CenterCode"))
        '                    gstrctKDPP.strBhk = RTrim(.Item("Bhk"))

        '                    If rtn = 0 Then rtn = fGetKasoLine("PKCPRE1", wstrTmp)
        '                    gstrctPPDisp.strLine = wstrTmp
        '                    If rtn = 0 Then rtn = fGetCartonType("PKCPRE1", wstrTmp)
        '                    If rtn = 0 Then gstrctPPDisp.strCrtnType = wstrTmp
        '                    If rtn <> 0 Then
        '                        gclsDB.fCloseRecord("PKCPRE1")
        '                        Exit Function
        '                    End If
        '                    flag = True
        '                End If

        '                If G_CONST_ST_PKCP_NOSTOCK = RTrim(.Item("PickFlag")) Or G_CONST_ST_PKCP_INSTOCK = RTrim(.Item("PickFlag")) Then
        '                    gstrctPPDisp.strItemCode = RTrim(.Item("ItemCode"))
        '                    gstrctPPDisp.intNumOfPkg += 1
        '                    gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")))
        '                    gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1)
        '                    wstrctItemInCode.ProcItem(RTrim(.Item("ItemInCode")))
        '                ElseIf G_CONST_ST_PKCP_PICKED = RTrim(.Item("PickFlag")) Then
        '                    gstrctPPDisp.strItemCode = RTrim(.Item("ItemCode"))
        '                    gstrctPPDisp.intNumOfPkg += 1
        '                    gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")))
        '                    gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1)

        '                    gstrctPPDisp.intNumOfScanned += 1
        '                    gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")), 1)
        '                    gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1, 1)
        '                    gstrctPPDispPart.bLocked = False
        '                    wstrctItemInCode.ProcItem(RTrim(.Item("ItemInCode")))
        '                End If

        '            Else
        '                If flag Then
        '                    Exit Do
        '                Else
        '                    gclsDB.fCloseRecord("PKCPRE1")
        '                    Exit Function
        '                End If
        '            End If

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

        '        End With
        '    Loop
        'End If

        'gclsDB.fCloseRecord("PKCPRE1")

        '    gstrctPPDisp.intNumOfItem = wstrctItemInCode.intIndex

        '    fMakeRecovery4Ohmono2 = 0

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

    End Function

    '/*
    '|| 関数名：fMakeRecovery4Deliv
    '|| 概要  ：リカバリ処理(デリバリ)
    '*/
    Public Function fMakeRecovery4Deliv() As Integer
        Dim wstrKey(6), wstrKeyValue(6) As String
        Dim wstrKey2(2), wstrKeyValue2(2) As String
        Dim wintRet As Integer = -1
        Dim wintRet2 As Integer = -1
        Dim wstrTmp As String
        Dim wstrRestCnt As String
        Dim flag As Boolean = False
        Dim wstrWhere As String

        Dim KEYCP1 As String = "KEYCP1"
        Dim KEYSEC1 As String = "KEYSEC1"

        fMakeRecovery4Deliv = -1
        'wstrKey(0) = "ItemCode"
        'wstrKey(1) = "ItemInCode"
        'wstrKey(2) = "TempSerial"

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

        Try

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

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

            tmpStr_PKCPRE1 = tmpStr

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sItemGr As String = ""
            Dim sWKSumDate As String = ""
            Dim sPackNo As String = ""
            Dim sCenterCode As String = ""
            Dim sItemInID As String = ""
            Dim sBhk As String = ""
            Dim sSortLctn3 As String = ""
            Dim sItemCode As String = ""
            Dim sStockLctn As String = ""
            Dim sItemInCode As String = ""
            Dim sBunkatuJ As String = ""
            Dim sPackQtyP As String = ""
            Dim sPackQtyJ As String = ""

            Dim i As Integer = 0

            If tmpStr.Count > 0 Then

                Do

                    values = tmpStr(i)

                    Dim result As String = Nothing
                    If values.TryGetValue("ItemGr", result) Then
                        sItemGr = RTrim(result)
                    End If
                    If values.TryGetValue("WKSumDate", result) Then
                        sWKSumDate = RTrim(result)
                    End If
                    If values.TryGetValue("PackNo", result) Then
                        sPackNo = RTrim(result)
                    End If
                    If values.TryGetValue("CenterCode", result) Then
                        sCenterCode = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInID", result) Then
                        sItemInID = RTrim(result)
                    End If
                    If values.TryGetValue("Bhk", result) Then
                        sBhk = RTrim(result)
                    End If
                    If values.TryGetValue("SortLctn3", result) Then
                        sSortLctn3 = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If

                    If values.TryGetValue("StockLctn", result) Then
                        sStockLctn = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If
                    If values.TryGetValue("BunkatuJ", result) Then
                        sBunkatuJ = RTrim(result)
                    End If
                    If values.TryGetValue("PackQtyP", result) Then
                        sPackQtyP = RTrim(result)
                    End If
                    If values.TryGetValue("PackQtyJ", result) Then
                        sPackQtyJ = RTrim(result)
                    End If
                  

                    If RTrim(sItemGr) = wstrKeyValue(0) Then
                        If Not flag Then
                            gstrctAicCase.YYYYMMDD = RTrim(sWKSumDate)
                            gstrctKDPP.strItemGr = RTrim(sItemGr)
                            gstrctPPDisp.strAic = Mid(RTrim(sItemGr), 1, 13)
                            gstrctPPDisp.strMsc = Mid(RTrim(sItemGr), 1, 7)
                            gstrctPPDisp.strPNT = Mid(RTrim(sItemGr), 8, 3)
                            gstrctPPDisp.strTRM = Mid(RTrim(sItemGr), 11, 3)
                            gstrctPPDisp.strCaseNo = Mid(RTrim(sItemGr), 14, 7)
                            gstrctPPDisp.strCrtnFrom = Mid(RTrim(sItemGr), 21, 5)
                            gstrctPPDisp.strCrtnTo = Mid(RTrim(sItemGr), 26, 5)
                            gstrctPPDisp.strCrtnNo = Mid(RTrim(sItemGr), 21, 5)
                            gstrctPPDisp.strSeq = RTrim(sPackNo)
                            gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
                            gstrctKDPP.strCenterCode = RTrim(sCenterCode)
                            gstrctKDPP.strBhk = RTrim(sBhk)
                            If fGetKasoLine(KEYCP1, wstrTmp) = 0 Then
                                gstrctPPDisp.strLine = wstrTmp
                            Else
                                Exit Function
                            End If
                        End If
                        'if sItemInID = "D" then gstrctPPdisp.sSortLctn3
                        gstrctPPDisp.strItemCode = RTrim(sItemCode)
                        gstrctPPDisp.intNumOfPkg += 1
                        'gstrctPPDisp.fSetQty(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), RTrim(sBunkatuJ))
                        gstrctPPDisp.fSetQty2(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), RTrim(sPackQtyP), 2)
                        gstrctPPDisp.fSetQty2(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), RTrim(sPackQtyJ), 1)
                        'gstrctPPDisp.fSetPkg(Mid(RTrim(sItemCode), 21, 5) & RTrim(sStockLctn) & RTrim(sItemInCode), 1)
                        'wstrctItemInCode.ProcItem(RTrim(sItemInCode))
                        flag = True
                        fMakeRecovery4Deliv = 0
                    Else
                        Exit Function
                    End If


                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If

                Loop

            Else
                fMakeRecovery4Deliv = -1
                Exit Function

            End If

            wstrKey2(0) = "CenterCode"
            wstrKey2(1) = "SectionID"
            wstrKey2(2) = "Section"
            wstrKeyValue2(0) = gstrctKDPP.strCenterCode
            wstrKeyValue2(1) = gstrctKDPP.strSectionID
            wstrKeyValue2(2) = gstrctKDPP.strSection

            wstrWhere = ""
            wstrWhere = wstrKey2(0) & " = '" & wstrKeyValue2(0) & "'"
            wstrWhere &= " and " & wstrKey2(1) & " = '" & wstrKeyValue2(1) & "'"
            wstrWhere &= " and " & wstrKey2(2) & " = '" & wstrKeyValue2(2) & "'"

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

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

            If tmpStr.Count > 0 Then

                values = tmpStr(0)

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

                gstrctKDPP.strSectionName = RTrim(sSectionName)

            Else
                fMakeRecovery4Deliv = -1
                Exit Function

            End If

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


        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCP, G_CONST_KEY_PACKCPKEY03, KEYCP1, wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'Select Case wintRet
        '    Case 0
        '        Do
        '            With gclsDB.Records(KEYCP1)
        '                If RTrim(.Item("ItemGr")) = wstrKeyValue(0) Then
        '                    If Not flag Then
        '                        gstrctAicCase.YYYYMMDD = RTrim(.Item("WKSumDate"))
        '                        gstrctKDPP.strItemGr = RTrim(.Item("ItemGr"))
        '                        gstrctPPDisp.strAic = Mid(RTrim(.Item("ItemGr")), 1, 13)
        '                        gstrctPPDisp.strMsc = Mid(RTrim(.Item("ItemGr")), 1, 7)
        '                        gstrctPPDisp.strPNT = Mid(RTrim(.Item("ItemGr")), 8, 3)
        '                        gstrctPPDisp.strTRM = Mid(RTrim(.Item("ItemGr")), 11, 3)
        '                        gstrctPPDisp.strCaseNo = Mid(RTrim(.Item("ItemGr")), 14, 7)
        '                        gstrctPPDisp.strCrtnFrom = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                        gstrctPPDisp.strCrtnTo = Mid(RTrim(.Item("ItemGr")), 26, 5)
        '                        gstrctPPDisp.strCrtnNo = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                        gstrctPPDisp.strSeq = RTrim(.Item("PackNo"))
        '                        gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
        '                        gstrctKDPP.strCenterCode = RTrim(.Item("CenterCode"))
        '                        gstrctKDPP.strBhk = RTrim(.Item("Bhk"))
        '                        If fGetKasoLine(KEYCP1, wstrTmp) = 0 Then
        '                            gstrctPPDisp.strLine = wstrTmp
        '                        Else
        '                            Exit Function
        '                        End If
        '                    End If
        '                    'if .Item("ItemInID") = "D" then gstrctPPdisp..Item("SortLctn3")
        '                    gstrctPPDisp.strItemCode = RTrim(.Item("ItemCode"))
        '                    gstrctPPDisp.intNumOfPkg += 1
        '                    'gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")))
        '                    gstrctPPDisp.fSetQty2(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("PackQtyP")), 2)
        '                    gstrctPPDisp.fSetQty2(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("PackQtyJ")), 1)
        '                    'gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1)
        '                    'wstrctItemInCode.ProcItem(RTrim(.Item("ItemInCode")))
        '                    flag = True
        '                    fMakeRecovery4Deliv = 0
        '                Else
        '                    Exit Function
        '                End If
        '                '次レコードを取得する
        '                If .Read(BtLib.Operation.GetNext) <> 0 Then
        '                    'レコードがなくなれば終了する
        '                    Exit Do
        '                End If
        '            End With
        '        Loop
        '    Case 9
        '        fMakeRecovery4Deliv = 1
        '    Case Else
        '        fMakeRecovery4Deliv = -1
        '        Exit Function
        'End Select


        'wstrKey2(0) = "CenterCode"
        'wstrKey2(1) = "SectionID"
        'wstrKey2(2) = "Section"
        'wstrKeyValue2(0) = gstrctKDPP.strCenterCode
        'wstrKeyValue2(1) = gstrctKDPP.strSectionID
        'wstrKeyValue2(2) = gstrctKDPP.strSection

        'wintRet2 = gclsDB.fOpenRecord(G_CONST_TBL_SECTION, G_CONST_KEY_SECTIONKEY00, KEYSEC1, wstrKey2, wstrKeyValue2, BtLib.Operation.GetEqual)

        'If wintRet2 = 0 Then
        '    gstrctKDPP.strSectionName = RTrim(gclsDB.Records(KEYSEC1).Item("SectionName"))
        'ElseIf wintRet2 <> -1 Then
        '    gstrctKDPP.strSectionName = " "
        '    If fMakeRecovery4Deliv <> 0 Then fMakeRecovery4Deliv = 1
        'Else
        '    fMakeRecovery4Deliv = -1
        '    Exit Function
        'End If





        'Dim rtn As Integer
        'Dim flag As Boolean
        'Dim wstrKey(6) As String
        'Dim wstrKeyValue(6) As String
        'Dim wstrKey2(2) As String
        'Dim wstrKeyValue2(2) As String
        'Dim wstrTmp As String
        'Dim wstrctItemInCode As ITEMINCODE_STR


        'fMakeRecovery = -1
        'wstrctItemInCode.initialize()

        'Try

        '    wstrKey(0) = "ItemGr"
        '    wstrKey(1) = "ItemCode"
        '    wstrKey(2) = "SortLctn1"
        '    wstrKey(3) = "SortLctn2"
        '    wstrKey(4) = "SortLctn3"
        '    wstrKey(5) = "ItemInCode"
        '    wstrKey(6) = "TempSerial"
        '    wstrKeyValue(0) = gstrctKDPP.strSearchKey
        '    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, "PKCPRE1", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)

        '    If rtn <> 0 Then
        '        'DBｴﾗｰの場合のみ-1を返しその他はPACKCJのﾁｪｯｸへ
        '        If rtn = -1 Then
        '            gclsDB.fCloseRecord("PKCPRE1")
        '            Exit Function
        '        End If
        '    End If

        '    flag = False
        '    If rtn = 0 Then
        '        Do
        '            With gclsDB.Records("PKCPRE1")

        '                If wstrKeyValue(0) = RTrim(.Item("ItemGr")) Then
        '                    If Not flag Then
        '                        gstrctAicCase.YYYYMMDD = RTrim(.Item("WKSumDate"))
        '                        gstrctKDPP.strItemGr = RTrim(.Item("ItemGr"))
        '                        gstrctPPDisp.strAic = Mid(RTrim(.Item("ItemGr")), 1, 13)
        '                        gstrctPPDisp.strMsc = Mid(RTrim(.Item("ItemGr")), 1, 7)
        '                        gstrctPPDisp.strPNT = Mid(RTrim(.Item("ItemGr")), 8, 3)
        '                        gstrctPPDisp.strTRM = Mid(RTrim(.Item("ItemGr")), 11, 3)
        '                        gstrctPPDisp.strCaseNo = Mid(RTrim(.Item("ItemGr")), 14, 7)
        '                        gstrctPPDisp.strCrtnFrom = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                        gstrctPPDisp.strCrtnTo = Mid(RTrim(.Item("ItemGr")), 26, 5)
        '                        gstrctPPDisp.strCrtnNo = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                        gstrctPPDisp.strSeq = RTrim(.Item("PackNo"))
        '                        gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
        '                        gstrctKDPP.strCenterCode = RTrim(.Item("CenterCode"))
        '                        gstrctKDPP.strBhk = RTrim(.Item("Bhk"))

        '                        If rtn = 0 Then rtn = fGetKasoLine("PKCPRE1", wstrTmp)
        '                        gstrctPPDisp.strLine = wstrTmp
        '                        If rtn = 0 Then rtn = fGetCartonType("PKCPRE1", wstrTmp)
        '                        If rtn = 0 Then gstrctPPDisp.strCrtnType = wstrTmp
        '                        If rtn <> 0 Then
        '                            gclsDB.fCloseRecord("PKCPRE1")
        '                            Exit Function
        '                        End If
        '                    End If

        '                    gstrctPPDisp.strItemCode = RTrim(.Item("ItemCode"))
        '                    gstrctPPDisp.intNumOfPkg += 1
        '                    gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")))
        '                    gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1)
        '                    wstrctItemInCode.ProcItem(RTrim(.Item("ItemInCode")))
        '                    flag = True
        '                Else
        '                    If flag Then
        '                        Exit Do
        '                    Else
        '                        gclsDB.fCloseRecord("PKCPRE1")
        '                        Exit Function
        '                    End If
        '                End If

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

        '            End With
        '        Loop
        '    End If

        '    gclsDB.fCloseRecord("PKCPRE1")

        '    rtn = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY03, "PKCJRE1", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)

        '    If rtn <> 0 Then
        '        If rtn = -1 Then
        '            gclsDB.fCloseRecord("PKCJRE1")
        '            Exit Function
        '        End If
        '    End If

        '    If rtn = 0 Then
        '        Do
        '            With gclsDB.Records("PKCJRE1")

        '                If wstrKeyValue(0) = RTrim(.Item("ItemGr")) Then
        '                    gstrctPPDisp.strItemCode = RTrim(.Item("ItemCode"))
        '                    gstrctPPDisp.intNumOfPkg += 1
        '                    gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")))
        '                    gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1)

        '                    gstrctPPDisp.intNumOfScanned += 1
        '                    gstrctPPDisp.fSetQty(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), RTrim(.Item("BunkatuJ")), 1)
        '                    gstrctPPDisp.fSetPkg(Mid(RTrim(.Item("ItemCode")), 21, 5) & RTrim(.Item("StockLctn")) & RTrim(.Item("ItemInCode")), 1, 1)
        '                    gstrctPPDispPart.bLocked = False
        '                    wstrctItemInCode.ProcItem(RTrim(.Item("ItemInCode")))
        '                    If Not flag Then
        '                        gstrctKDPP.strItemGr = RTrim(.Item("ItemGr"))
        '                        gstrctKDPP.strCenterCode = RTrim(.Item("CenterCode"))
        '                        gstrctKDPP.strBhk = RTrim(.Item("Bhk"))

        '                        gstrctPPDisp.strAic = Mid(RTrim(.Item("ItemGr")), 1, 13)
        '                        gstrctPPDisp.strMsc = Mid(RTrim(.Item("ItemGr")), 1, 7)
        '                        gstrctPPDisp.strPNT = Mid(RTrim(.Item("ItemGr")), 8, 3)
        '                        gstrctPPDisp.strTRM = Mid(RTrim(.Item("ItemGr")), 11, 3)
        '                        gstrctPPDisp.strCaseNo = Mid(RTrim(.Item("ItemGr")), 14, 7)
        '                        gstrctPPDisp.strCrtnFrom = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                        gstrctPPDisp.strCrtnTo = Mid(RTrim(.Item("ItemGr")), 26, 5)
        '                        gstrctPPDisp.strCrtnNo = Mid(RTrim(.Item("ItemGr")), 21, 5)
        '                        gstrctPPDisp.intNumOfCase = CInt((CLng(gstrctPPDisp.strCrtnTo) - CLng(gstrctPPDisp.strCrtnFrom)) + 1)
        '                        gstrctPPDisp.strSeq = RTrim(.Item("PackNo"))


        '                    End If
        '                Else
        '                    Exit Do
        '                End If

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

        '            End With
        '        Loop
        '    End If

        '    gstrctPPDisp.intNumOfItem = wstrctItemInCode.intIndex

        '    gclsDB.fCloseRecord("PKCJRE1")

        '    wstrKey2(0) = "CenterCode"
        '    wstrKey2(1) = "SectionID"
        '    wstrKey2(2) = "Section"
        '    wstrKeyValue2(0) = gstrctKDPP.strCenterCode
        '    wstrKeyValue2(1) = gstrctKDPP.strSectionID
        '    wstrKeyValue2(2) = gstrctKDPP.strSection

        '    rtn = gclsDB.fOpenRecord(G_CONST_TBL_SECTION, G_CONST_KEY_SECTIONKEY00, "SECRE1", wstrKey2, wstrKeyValue2, BtLib.Operation.GetEqual)

        '    If rtn <> 0 Then
        '        gstrctKDPP.strSectionName = " "
        '        gclsDB.fCloseRecord("SECRE1")
        '        Exit Function
        '    End If

        '    If rtn = 0 Then
        '        gstrctKDPP.strSectionName = RTrim(gclsDB.Records("SECRE1").Item("SectionName"))
        '    End If

        '    gclsDB.fCloseRecord("SECRE1")



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



    '/*
    '|| 関数名： 
    '|| 概要  ：PLANからKasoLineを読み込む
    '*/
    Public Function fGetKasoLine(ByVal wstrDBName As String, ByRef pstrKasoLine As String) As Integer

        Dim wintRet As Integer
        Dim wstrKey(10) As String
        Dim wstrKeyValue(10) As String
        Dim wstrWhere As String

        Try
            fGetKasoLine = -1

            'With gclsDB.Records(wstrDBName)

            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 sLine As String = ""
            Dim sProductDate As String = ""
            Dim sShift As String = ""
            Dim sItemCode As String = ""


            If tmpStr_PKCPRE1.Count > 0 Then

                values = tmpStr(0)

                Dim result As String = Nothing
                If values.TryGetValue("PicsType", result) Then
                    sPicsType = RTrim(result)
                End If
                If values.TryGetValue("Cstmid", result) Then
                    sCstmid = RTrim(result)
                End If
                If values.TryGetValue("CstmCode", result) Then
                    sCstmCode = RTrim(result)
                End If
                If values.TryGetValue("Line", result) Then
                    sLine = RTrim(result)
                End If
                If values.TryGetValue("ProductDate", result) Then
                    sProductDate = RTrim(result)
                End If
                If values.TryGetValue("Shift", result) Then
                    sShift = RTrim(result)
                End If
                If values.TryGetValue("ItemCode", result) Then
                    sItemCode = RTrim(result)
                End If



            End If




            '検索キー設定
            wstrKey(0) = "PicsType"
            wstrKey(1) = "CstmId"
            wstrKey(2) = "CstmCode"
            wstrKey(3) = "Line"
            wstrKey(4) = "YYYYMMDDS"
            wstrKey(5) = "Msc"
            wstrKey(6) = "Pnt"
            wstrKey(7) = "Trm"
            wstrKey(8) = "Lot"
            wstrKey(9) = "Gr"
            wstrKey(10) = "Seq"
            wstrKeyValue(0) = sPicsType
            wstrKeyValue(1) = sCstmid
            wstrKeyValue(2) = sCstmCode
            wstrKeyValue(3) = sLine
            wstrKeyValue(4) = sProductDate & sShift
            wstrKeyValue(5) = Mid(sItemCode, 1, 7)
            wstrKeyValue(6) = Mid(sItemCode, 8, 3)
            wstrKeyValue(7) = Mid(sItemCode, 11, 3)
            wstrKeyValue(8) = Mid(sItemCode, 14, 3)
            wstrKeyValue(9) = Mid(sItemCode, 17, 2)
            wstrKeyValue(10) = Mid(sItemCode, 19, 2)

            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) & "'"
            wstrWhere &= " and " & wstrKey(10) & " = '" & wstrKeyValue(10) & "'"

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

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

            If tmpStr.Count > 0 Then

                values = tmpStr(0)

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

                pstrKasoLine = RTrim(sKasoLine).PadRight(2, " ")

            End If



            '検索処理
            '    wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PLAN, G_CONST_KEY_PLANKEY02, "PLN2", wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)
            '    If wintRet <> 0 Then
            '        'DBエラーの場合
            '        gclsDB.fCloseRecord("PLN2")
            '        Exit Function
            '    End If

            '    If wintRet = 0 Then
            '        'Keyがある場合
            '        pstrKasoLine = RTrim(gclsDB.Records("PLN2").Item("KasoLine")).PadRight(2, " ")
            '    End If
            '    gclsDB.fCloseRecord("PLN2")

            'End With

            fGetKasoLine = 0
            Exit Function

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

    End Function

    '/*
    '|| 関数名： 
    '|| 概要  ：SPMからCartonTypeを読み込む
    '*/
    Public Function fGetCartonType(ByVal wstrDBName As String, ByRef pstrCartonType As String) As Integer

        Dim wintRet As Integer
        Dim wstrKey(11) As String
        Dim wstrKeyValue(11) As String
        Dim wstrWhere As String

        Try
            fGetCartonType = -1

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sWKSumDate As String = ""
            Dim sPicsType As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""
            Dim sItemInCode As String = ""
            Dim sPartID As String = ""
            Dim sItemCode As String = ""


            If tmpStr_PKCPRE1.Count > 0 Then

                values = tmpStr(0)

                Dim result As String = Nothing
                If values.TryGetValue("PicsType", result) Then
                    sPicsType = RTrim(result)
                End If
                If values.TryGetValue("Cstmid", result) Then
                    sCstmid = RTrim(result)
                End If
                If values.TryGetValue("CstmCode", result) Then
                    sCstmCode = RTrim(result)
                End If
                If values.TryGetValue("ItemInCode", result) Then
                    sItemInCode = RTrim(result)
                End If
                If values.TryGetValue("PartID", result) Then
                    sPartID = RTrim(result)
                End If
                If values.TryGetValue("ItemCode", result) Then
                    sItemCode = RTrim(result)
                End If



            End If



            'With gclsDB.Records(wstrDBName)

            '検索キー設定
            wstrKey(0) = "YYYYMMDD"
            wstrKey(1) = "PicsType"
            wstrKey(2) = "CstmId"
            wstrKey(3) = "CstmCode"
            wstrKey(4) = "Msc"
            wstrKey(5) = "Pnt"
            wstrKey(6) = "Trm"
            wstrKey(7) = "Gr"
            wstrKey(8) = "PartNo"
            wstrKey(9) = "PartCL"
            wstrKey(10) = "PartZnc"
            wstrKey(11) = "PartID"
            wstrKeyValue(0) = RTrim(sWKSumDate)
            wstrKeyValue(1) = RTrim(sPicsType)
            wstrKeyValue(2) = RTrim(sCstmid)
            wstrKeyValue(3) = RTrim(sCstmCode)
            wstrKeyValue(4) = RTrim(Mid(sItemCode, 1, 7))
            wstrKeyValue(5) = RTrim(Mid(sItemCode, 8, 3))
            wstrKeyValue(6) = RTrim(Mid(sItemCode, 11, 3))
            wstrKeyValue(7) = RTrim(Mid(sItemCode, 17, 2))
            wstrKeyValue(8) = RTrim(Mid(sItemInCode, 1, 10))
            wstrKeyValue(9) = RTrim(Mid(sItemInCode, 11, 2))
            wstrKeyValue(10) = RTrim(Mid(sItemInCode, 13, 1))
            wstrKeyValue(11) = RTrim(sPartID)

            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) & "'"
            wstrWhere &= " and " & wstrKey(10) & " = '" & wstrKeyValue(10) & "'"
            wstrWhere &= " and " & wstrKey(11) & " = '" & wstrKeyValue(11) & "'"


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

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

            If tmpStr.Count > 0 Then

                values = tmpStr(0)

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

                pstrCartonType = RTrim(sCartonType)

            Else

                Exit Function


            End If

            fGetCartonType = 0
            Exit Function

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



        '検索処理
        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_SPM, G_CONST_KEY_SPMKEY00, "SPM1", wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)
        'If wintRet <> 0 Then
        '    'DBエラーの場合
        '    gclsDB.fCloseRecord("SPM1")
        '    Exit Function
        'End If

        'If wintRet = 0 Then
        '    'Keyがある場合
        '    pstrCartonType = RTrim(gclsDB.Records("SPM1").Item("CartonType"))
        'End If
        'gclsDB.fCloseRecord("SPM1")

        ''End With

        'fGetCartonType = 0
        'Exit Function

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

    End Function

End Module
