Imports System
Imports System.Linq
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports BTClientLib
Imports System.IO
Imports System.Reflection
Imports Newtonsoft
Imports Microsoft.WindowsCE.Forms

Module modPublicPL070
    Private Structure STRCT_PPLN_REC
        Public strPicsType As String
        Public strCstmid As String
        Public strCstmCode As String
        Public strCenterCode As String
        Public strDate As String
        Public strLine As String
        Public strAic As String
        Public strCaseNo As String
        Public strCartonNo As String
        Public strItemID As String
        Public strItemCode As String
        Public strSerialNo As String
        Public strTempSerial As String
        Public strPickUser As String
        Public strPickDate As String
        Public strPickTime As String
        Public strStockLctn As String
    End Structure
    Private dbClient As BtrieveDbClient
    Private tmpStr As List(Of Dictionary(Of String, String))
    Private affected_rows As Integer
    Private tmpStr_KEYCJ00 As List(Of Dictionary(Of String, String))
    Private tmpStr_KEY00 As List(Of Dictionary(Of String, String))



    Public Function fClearJisseki() As Integer

        Dim wstrKey(6), wstrKeyValue(6) As String
        Dim wstrKey2(2), wstrKeyValue2(2) As String
        Dim wstrKey3(12), wstrKeyValue3(12) As String
        Dim wintRet As Integer = -1
        Dim wintRet2 As Integer = -1
        Dim wintRet3 As Integer = -1
        Dim wintFlag As Integer
        Dim wstrctPPLN_REC() As STRCT_PPLN_REC
        Dim wintRecCount As Integer = 0
        Dim wbReadAJ As Boolean = False
        Dim wstrWhere As String
        Dim sSql As String = ""
        Dim rowCount As Integer = 0
        Dim rowCount1 As Integer = 0
        Dim rowCount2 As Integer = 0
        fClearJisseki = -1
        wstrKey(0) = "PaletteID" : wstrKeyValue(0) = "A"
        wstrKey(1) = "ItemGr" : wstrKeyValue(1) = gstrctAicCase.AicCaseNo & gstrctAicCase.YYYYMMDD
        wstrKey(2) = "ItemID" : wstrKeyValue(2) = Space(1)
        wstrKey(3) = "ItemCode" : wstrKeyValue(3) = Space(30)
        wstrKey(4) = "ItemInID" : wstrKeyValue(4) = Space(1)
        wstrKey(5) = "ItemInCode" : wstrKeyValue(5) = Space(30)
        wstrKey(6) = "TempSerial" : wstrKeyValue(6) = Space(6)

        'BtLib.Transaction.BeginConCurrent()
        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_PACKAJ + " WHERE " + wstrWhere)

            tmpStr_KEY00 = tmpStr

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sPaletteID As String = ""
            Dim sItemGr As String = ""
            Dim sItemCode As String = ""
            Dim sItemID As String = ""
            Dim sItemInID As String = ""
            Dim sItemInCode As String = ""
            Dim sTempSerial As String = ""
            Dim sProductDate As String = ""
            Dim sShift As String = ""
            Dim sLine As String = ""
            Dim i As Integer = 0

            rowCount = tmpStr.Count

            If tmpStr.Count > 0 Then
                fClearJisseki = 0
                wstrKey2(0) = "ItemCode"
                wstrKey2(1) = "ItemInCode"
                wstrKey2(2) = "TempSerial"
                wstrKey3(0) = "PicsType" : wstrKeyValue3(0) = gstrctKDHT.strPackType
                wstrKey3(1) = "Cstmid" : wstrKeyValue3(1) = gstrctKDHT.strCstmid
                wstrKey3(2) = "CstmCode" : wstrKeyValue3(2) = gstrctKDHT.strCstmCode
                wstrKey3(3) = "CenterCode" : wstrKeyValue3(3) = gstrctKDPL.strCenterCode
                wstrKey3(4) = "Date"
                wstrKey3(5) = "Line"
                wstrKey3(6) = "Aic"
                wstrKey3(7) = "CaseNo"
                wstrKey3(8) = "CartonNo"
                wstrKey3(9) = "ItemID"
                wstrKey3(10) = "ItemCode"
                wstrKey3(11) = "SerialNo"
                wstrKey3(12) = "TempSerial"


                Do

                    values = tmpStr(i)

                    Dim result As String = Nothing
                    If values.TryGetValue("PaletteID", result) Then
                        sPaletteID = RTrim(result)
                    End If
                    If values.TryGetValue("ItemGr", result) Then
                        sItemGr = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("ItemID", result) Then
                        sItemID = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInID", result) Then
                        sItemInID = RTrim(result)
                    End If
                    If values.TryGetValue("ItemInCode", result) Then
                        sItemInCode = RTrim(result)
                    End If
                    If values.TryGetValue("TempSerial", result) Then
                        sTempSerial = 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("Line", result) Then
                        sLine = RTrim(result)
                    End If


                    If RTrim(sPaletteID) = "A" AndAlso RTrim(sItemGr) = wstrKeyValue(1) Then
                        If wstrKeyValue2(0) <> RTrim(sItemCode) Then
                            If wintRet2 <> -1 Then
                                wintRet2 = -1
                            End If
                        End If
                        wstrKeyValue2(0) = RTrim(sItemCode)
                        If Mid(RTrim(sItemCode), 21, 5) = "00000" OrElse RTrim(sItemID) = "B" Then '部品
                            wstrKeyValue2(1) = RTrim(sItemInCode)
                            wstrKeyValue2(2) = Space(6)
                            wintFlag = 0
                        Else 'カートン
                            wstrKeyValue2(1) = Space(30)
                            wstrKeyValue2(2) = Space(6)
                            wintFlag = 1
                        End If
                        If wintFlag <> 0 AndAlso wintRet2 <> -1 Then
                            If wintRet2 <> -1 Then
                                wintRet2 = -1
                            End If
                        End If

                        If wintRet2 = -1 Then

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

                            Dim values1 As Dictionary(Of String, String) = New Dictionary(Of String, String)
                            Dim sPaletteID1 As String = ""
                            Dim sItemGr1 As String = ""
                            Dim sItemCode1 As String = ""
                            Dim sItemID1 As String = ""
                            Dim sItemInID1 As String = ""
                            Dim sItemInCode1 As String = ""
                            Dim sTempSerial1 As String = ""
                            Dim sPicsType1 As String = ""
                            Dim sCstmid1 As String = ""
                            Dim sCstmCode1 As String = ""
                            Dim sCenterCode1 As String = ""
                            Dim sProductDate1 As String = ""
                            Dim sShift1 As String = ""
                            Dim sLine1 As String = ""
                            Dim sScanDate1 As String = ""
                            Dim sScanTime1 As String = ""
                            Dim sUserNo1 As String = ""
                            Dim sStockLctn1 As String = ""
                            Dim sSerialNo1 As String = ""
                            Dim sCarryOutSectioniId1 As String = ""
                            Dim sCarryOutSection1 As String = ""
                            Dim i1 As Integer = 0

                            rowCount1 = tmpStr.Count

                            If tmpStr.Count > 0 Then

                                Do
                                    values = tmpStr(i)

                                    Dim result1 As String = Nothing
                                    If values.TryGetValue("PaletteID", result1) Then
                                        sPaletteID1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("ItemGr", result1) Then
                                        sItemGr1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("ItemCode", result1) Then
                                        sItemCode1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("ItemID", result1) Then
                                        sItemID1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("ItemInID", result1) Then
                                        sItemInID1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("ItemInCode", result1) Then
                                        sItemInCode1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("TempSerial", result1) Then
                                        sTempSerial1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("PicsType", result1) Then
                                        sPicsType1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("Cstmid", result1) Then
                                        sCstmid1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("CstmCode", result1) Then
                                        sCstmCode1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("CenterCode", result1) Then
                                        sCenterCode1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("ProductDate", result1) Then
                                        sProductDate1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("Shift", result1) Then
                                        sShift1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("Line", result1) Then
                                        sLine1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("ScanDate", result1) Then
                                        sScanDate1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("ScanTime", result1) Then
                                        sScanTime1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("UserNo", result1) Then
                                        sUserNo1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("StockLctn", result1) Then
                                        sStockLctn1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("SerialNo", result1) Then
                                        sSerialNo1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("CarryOutSectioniId", result1) Then
                                        sCarryOutSectioniId1 = RTrim(result1)
                                    End If
                                    If values.TryGetValue("CarryOutSection", result1) Then
                                        sCarryOutSection1 = RTrim(result1)
                                    End If




                                    If Mid(RTrim(sItemCode1), 21, 5) = "00000" OrElse RTrim(sItemID1) = "B" Then '部品
                                        If wintFlag = 0 Then '部品
                                            If fSearchStock("KEYCJ00") = 1 Then

                                                Do

                                                    If RTrim(sItemID) = RTrim(sItemID1) AndAlso _
                                                                   RTrim(sItemCode) = RTrim(sItemCode1) AndAlso _
                                                                   RTrim(sItemInID) = RTrim(sItemInID1) AndAlso _
                                                                   RTrim(sItemInCode) = RTrim(sItemInCode1) Then
                                                        'PackPlan再ｵｰﾌﾟﾝ処理
                                                        If Mid(RTrim(sItemCode1), 21, 5) <> wstrKeyValue3(8) Then
                                                            If wintRet3 <> -1 Then
                                                                'gclsDB.fCloseRecord("PKPLN00")
                                                                wintRet3 = -1
                                                            End If
                                                            wstrKeyValue3(4) = RTrim(sProductDate).PadRight(8, " ") & RTrim(sShift).PadRight(1, " ")
                                                            wstrKeyValue3(5) = sLine
                                                            wstrKeyValue3(6) = Mid(gstrctAicCase.AicCaseNo, 1, 13)
                                                            wstrKeyValue3(7) = Replace(gstrctAicCase.CaseNo, "-", "")
                                                            If sItemID = "C" Then
                                                                wstrKeyValue3(8) = Mid(sItemCode, 21, 5)
                                                            ElseIf sItemID = "B" Then
                                                                wstrKeyValue3(8) = "00000"
                                                            End If
                                                            wstrKeyValue3(9) = RTrim(sItemInID)
                                                            wstrKeyValue3(10) = RTrim(sItemInCode)
                                                            wstrKeyValue3(11) = Space(6)
                                                            wstrKeyValue3(12) = Space(6)

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

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

                                                            Dim values2 As Dictionary(Of String, String) = New Dictionary(Of String, String)
                                                            Dim sPicsType2 As String = ""
                                                            Dim sCstmid2 As String = ""
                                                            Dim sCstmCode2 As String = ""
                                                            Dim sCenterCode2 As String = ""
                                                            Dim sDate2 As String = ""
                                                            Dim sLine2 As String = ""
                                                            Dim sAic2 As String = ""
                                                            Dim sCaseNo2 As String = ""
                                                            Dim sCartonNo2 As String = ""
                                                            Dim sItemID2 As String = ""
                                                            Dim sItemCode2 As String = ""
                                                            Dim sSerialNo2 As String = ""
                                                            Dim sTempSerial2 As String = ""
                                                            Dim sStatus2 As String = ""
                                                            Dim i2 As Integer = 0

                                                            rowCount2 = tmpStr.Count

                                                            If tmpStr.Count > 0 Then

                                                                Do
                                                                    values = tmpStr(i)

                                                                    Dim result2 As String = Nothing
                                                                    If values.TryGetValue("PicsType", result) Then
                                                                        sPicsType2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("Cstmid", result) Then
                                                                        sCstmid2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("CstmCode", result) Then
                                                                        sCstmCode2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("CenterCode", result) Then
                                                                        sCenterCode2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("Date", result) Then
                                                                        sDate2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("Line", result) Then
                                                                        sLine2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("Aic", result) Then
                                                                        sAic2 = RTrim(result)
                                                                    End If

                                                                    If values.TryGetValue("CaseNo", result) Then
                                                                        sCaseNo2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("CartonNo", result) Then
                                                                        sCartonNo2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("ItemID", result) Then
                                                                        sItemID2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("ItemCode", result) Then
                                                                        sItemCode2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("SerialNo", result) Then
                                                                        sSerialNo2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("TempSerial", result) Then
                                                                        sTempSerial2 = RTrim(result)
                                                                    End If
                                                                    If values.TryGetValue("Status", result) Then
                                                                        sStatus2 = RTrim(result)
                                                                    End If

                                                                    If Mid(RTrim(sItemCode), 21, 5) = "00000" OrElse RTrim(sItemID) = "B" Then '部品
                                                                        If wintFlag = 0 Then '部品
                                                                            If fSearchStock("KEYCJ00") = 1 Then
                                                                                'Do
                                                                                If RTrim(sItemID) = RTrim(sItemID1) AndAlso _
                                                                                   RTrim(sItemCode) = RTrim(sItemCode1) AndAlso _
                                                                                   RTrim(sItemInID) = RTrim(sItemInID1) AndAlso _
                                                                                   RTrim(sItemInCode) = RTrim(sItemInCode1) Then
                                                                                    'PackPlan再ｵｰﾌﾟﾝ処理
                                                                                    If Mid(RTrim(sItemCode1), 21, 5) <> wstrKeyValue3(8) Then
                                                                                        If wintRet3 <> -1 Then
                                                                                            'gclsDB.fCloseRecord("PKPLN00")
                                                                                            wintRet3 = -1
                                                                                        End If
                                                                                        wstrKeyValue3(4) = RTrim(sProductDate).PadRight(8, " ") & RTrim(sShift).PadRight(1, " ")
                                                                                        wstrKeyValue3(5) = sLine
                                                                                        wstrKeyValue3(6) = Mid(gstrctAicCase.AicCaseNo, 1, 13)
                                                                                        wstrKeyValue3(7) = Replace(gstrctAicCase.CaseNo, "-", "")
                                                                                        If sItemID = "C" Then
                                                                                            wstrKeyValue3(8) = Mid(sItemCode, 21, 5)
                                                                                        ElseIf sItemID = "B" Then
                                                                                            wstrKeyValue3(8) = "00000"
                                                                                        End If
                                                                                        wstrKeyValue3(9) = RTrim(sItemInID)
                                                                                        wstrKeyValue3(10) = RTrim(sItemInCode)
                                                                                        wstrKeyValue3(11) = Space(6)
                                                                                        wstrKeyValue3(12) = Space(6)

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

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

                                                                                        If tmpStr.Count = 0 Then
                                                                                            wintRet3 = -1
                                                                                        End If

                                                                                        'wintRet3 = gclsDB.fOpenRecord(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, "PKPLN00", wstrKey3, wstrKeyValue3, BtLib.Operation.GetGreaterOrEqual)
                                                                                    End If
                                                                                    wstrKeyValue3(0) = RTrim(sPicsType1)
                                                                                    wstrKeyValue3(1) = RTrim(sCstmid1)
                                                                                    wstrKeyValue3(2) = RTrim(sCstmCode1)
                                                                                    wstrKeyValue3(3) = RTrim(sCenterCode1)
                                                                                    wstrKeyValue3(4) = RTrim(sProductDate1).PadRight(8, " ") & RTrim(sShift1).PadRight(1, " ")
                                                                                    wstrKeyValue3(5) = RTrim(sLine1)
                                                                                    wstrKeyValue3(6) = Mid(gstrctAicCase.AicCaseNo, 1, 13)
                                                                                    wstrKeyValue3(7) = Replace(gstrctAicCase.CaseNo, "-", "")
                                                                                    If RTrim(sItemID) = "C" Then
                                                                                        wstrKeyValue3(8) = Mid(sItemCode1, 21, 5)
                                                                                    ElseIf sItemID = "B" Then
                                                                                        wstrKeyValue3(8) = "00000"
                                                                                    End If
                                                                                    wstrKeyValue3(9) = RTrim(sItemInID1)
                                                                                    wstrKeyValue3(10) = RTrim(sItemInCode1)
                                                                                    'PackCJとPackPlanの突合せ
                                                                                    If RTrim(sPicsType2) = wstrKeyValue3(0) AndAlso _
                                                                                       RTrim(sCstmid2) = wstrKeyValue3(1) AndAlso _
                                                                                       RTrim(sCstmCode2) = wstrKeyValue3(2) AndAlso _
                                                                                       RTrim(sCenterCode2) = wstrKeyValue3(3) AndAlso _
                                                                                       RTrim(sDate2) = wstrKeyValue3(4) AndAlso _
                                                                                       RTrim(sLine2) = wstrKeyValue3(5) AndAlso _
                                                                                       RTrim(sAic2) = wstrKeyValue3(6) AndAlso _
                                                                                       RTrim(sCaseNo2) = wstrKeyValue3(7) AndAlso _
                                                                                       RTrim(sCartonNo2) = wstrKeyValue3(8) AndAlso _
                                                                                       RTrim(sItemID2) = wstrKeyValue3(9) AndAlso _
                                                                                       RTrim(sItemCode2) = wstrKeyValue3(10) Then
                                                                                        wstrKeyValue3(11) = RTrim(sSerialNo2)
                                                                                        wstrKeyValue3(12) = RTrim(sTempSerial2)
                                                                                        If RTrim(sStatus2) < "30" Then

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

                                                                                            sSql = "UPDATE " + G_CONST_TBL_PACKPLAN + " SET Status='" _
                                                                                                                            + "30" _
                                                                                                                            + "' , PickDate='" _
                                                                                                                            + sScanDate1 _
                                                                                                                            + "' , PickTime='" _
                                                                                                                            + sScanTime1 _
                                                                                                                            + "' , PickEmp='" _
                                                                                                                            + sUserNo1 _
                                                                                                                            + "' , PickLctn1='" _
                                                                                                                            + sStockLctn1 _
                                                                                                                            + "' , SerialNo='" _
                                                                                                                            + sSerialNo1 _
                                                                                                                            + "' , PalDate='" _
                                                                                                                            + sScanDate1 _
                                                                                                                            + "' , PalTime='" _
                                                                                                                            + sScanTime1 _
                                                                                                                            + "' , PalEmp='" _
                                                                                                                            + sUserNo1 _
                                                                                                                            + "' , SectionIDPal='" _
                                                                                                                            + sCarryOutSectioniId1 _
                                                                                                                            + "' , SectionCodePal='" _
                                                                                                                            + sCarryOutSection1 _
                                                                                                                            + "' WHERE " + wstrWhere




                                                                                            'With gclsDB
                                                                                            '    .Setcolumn = "Status,PickDate,PickTime,PickEmp,PickLctn1,SerialNo,PalDate,PalTime,PalEmp,SectionIDPal,SectionCodePal"
                                                                                            '    .SetData = "30," & .Records("KEYCJ00").Item("ScanDate") & "," & .Records("KEYCJ00").Item("ScanTime") & "," _
                                                                                            '      & .Records("KEYCJ00").Item("UserNo") & "," & .Records("KEYCJ00").Item("StockLctn") & "," & .Records("KEYCJ00").Item("SerialNo") & "," _
                                                                                            '      & .Records("KEY00").Item("ScanDate") & "," & .Records("KEY00").Item("ScanTime") & "," & .Records("KEY00").Item("UserNo") & "," _
                                                                                            '      & .Records("KEY00").Item("CarryOutSectioniId") & "," & .Records("KEY00").Item("CarryOutSection")
                                                                                            'End With
                                                                                        Else

                                                                                            sSql = "UPDATE " + G_CONST_TBL_PACKPLAN + " SET PalDate='" _
                                                                                                                            + sScanDate1 _
                                                                                                                            + "' , PalTime='" _
                                                                                                                            + sScanTime1 _
                                                                                                                            + "' , PalEmp='" _
                                                                                                                            + sUserNo1 _
                                                                                                                            + "' , SectionIDPal='" _
                                                                                                                            + sCarryOutSectioniId1 _
                                                                                                                            + "' , SectionCodePal='" _
                                                                                                                            + sCarryOutSection1 _
                                                                                                                            + "' WHERE " + wstrWhere


                                                                                            'With gclsDB
                                                                                            '    .Setcolumn = "PalDate,PalTime,PalEmp,SectionIDPal,SectionCodePal"
                                                                                            '    .SetData = .Records("KEY00").Item("ScanDate") & "," & .Records("KEY00").Item("ScanTime") & "," & .Records("KEY00").Item("UserNo") & "," _
                                                                                            '            & .Records("KEY00").Item("CarryOutSectionId") & "," & .Records("KEY00").Item("CarryOutSection")
                                                                                            'End With
                                                                                        End If

                                                                                        affected_rows = dbClient.Execute(sSql)


                                                                                        If affected_rows = 0 Then
                                                                                            fClearJisseki = -1
                                                                                            Exit Function
                                                                                        End If


                                                                                        'If gclsDB.fUpdRecords(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, wstrKey3, wstrKeyValue3) <> 0 Then
                                                                                        '    fClearJisseki = -1
                                                                                        '    Exit Function
                                                                                        'End If

                                                                                        wstrKeyValue2(1) = RTrim(sItemInCode1)
                                                                                        wstrKeyValue2(2) = RTrim(sTempSerial1)

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

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


                                                                                        If affected_rows = 0 Then
                                                                                            fClearJisseki = -1
                                                                                            Exit Function
                                                                                        End If



                                                                                        'PACKCJ削除処理
                                                                                        'wstrKeyValue2(1) = RTrim(gclsDB.Records("KEYCJ00").Item("ItemInCode"))
                                                                                        'wstrKeyValue2(2) = RTrim(gclsDB.Records("KEYCJ00").Item("TempSerial"))
                                                                                        'If gclsDB.fDleRecords(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, wstrKey2, wstrKeyValue2) <> 0 Then
                                                                                        '    fClearJisseki = -1
                                                                                        '    Exit Function
                                                                                        'End If
                                                                                        'If gclsDB.Records("KEYCJ00").Read(BtLib.Operation.GetNext) <> 0 Then
                                                                                        '    Exit Function
                                                                                        'End If
                                                                                        If sItemID = "B" Then '比較のためｶｰﾄﾝを復帰
                                                                                            wstrKeyValue3(8) = Mid(sItemCode, 21, 5)
                                                                                        End If
                                                                                        'If gclsDB.Records("PKPLN00").Read(BtLib.Operation.GetNext) <> 0 Then
                                                                                        '    Exit Function
                                                                                        'End If
                                                                                        wbReadAJ = True
                                                                                        Exit Do
                                                                                    Else
                                                                                        If sItemID = "B" Then '比較のためｶｰﾄﾝを復帰
                                                                                            wstrKeyValue3(8) = Mid(sItemCode, 21, 5)
                                                                                        End If
                                                                                        'If gclsDB.Records("PKPLN00").Read(BtLib.Operation.GetNext) <> 0 Then
                                                                                        '    Exit Function
                                                                                        'End If
                                                                                    End If
                                                                                Else
                                                                                    Exit Do
                                                                                End If
                                                                                'Loop



                                                                            End If
                                                                        End If

                                                                    Else

                                                                        If wintFlag = 0 Then  '再オープン
                                                                            wstrKeyValue2(0) = RTrim(sItemCode)
                                                                            wstrKeyValue2(1) = Space(30)
                                                                            wstrKeyValue2(2) = Space(6)
                                                                            wintFlag = 1
                                                                            If wintRet2 <> -1 Then
                                                                                'gclsDB.fCloseRecord("KEYCJ00")
                                                                                wintRet2 = -1
                                                                            End If

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

                                                                            tmpStr_KEYCJ00 = tmpStr

                                                                            If tmpStr.Count = 0 Then
                                                                                fClearJisseki = 0
                                                                                Exit Do
                                                                            End If



                                                                            'wintRet2 = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, "KEYCJ00", wstrKey2, wstrKeyValue2, BtLib.Operation.GetGreaterOrEqual)
                                                                            'If wintRet2 = -1 Then
                                                                            '    Exit Function
                                                                            'ElseIf wintRet2 <> 0 Then
                                                                            '    fClearJisseki = 0
                                                                            '    Exit Do
                                                                            'End If
                                                                        End If
                                                                        If RTrim(sItemCode) = RTrim(sItemCode1) Then '同一ｶｰﾄﾝ
                                                                            Select Case fSearchStock("KEYCJ00")
                                                                                Case 1
                                                                                    'PACKPLANの更新
                                                                                    ReDim Preserve wstrctPPLN_REC(wintRecCount)
                                                                                    'With gclsDB.Records("KEYCJ00")
                                                                                    wstrctPPLN_REC(wintRecCount).strPicsType = gstrctKDHT.strPackType
                                                                                    wstrctPPLN_REC(wintRecCount).strCstmid = gstrctKDHT.strCstmid
                                                                                    wstrctPPLN_REC(wintRecCount).strCstmCode = gstrctKDHT.strCstmCode
                                                                                    wstrctPPLN_REC(wintRecCount).strCenterCode = gstrctKDPL.strCenterCode
                                                                                    wstrctPPLN_REC(wintRecCount).strDate = RTrim(sProductDate1).PadRight(8, " ") & RTrim(sShift1).PadRight(1, " ")
                                                                                    wstrctPPLN_REC(wintRecCount).strLine = sLine1
                                                                                    wstrctPPLN_REC(wintRecCount).strAic = Mid(gstrctAicCase.AicCaseNo, 1, 13)
                                                                                    wstrctPPLN_REC(wintRecCount).strCaseNo = Replace(gstrctAicCase.CaseNo, "-", "")
                                                                                    If sItemID1 = "C" Then
                                                                                        wstrctPPLN_REC(wintRecCount).strCartonNo = Mid(sItemCode, 21, 5)
                                                                                    Else
                                                                                        wstrctPPLN_REC(wintRecCount).strCartonNo = "00000"
                                                                                    End If
                                                                                    wstrctPPLN_REC(wintRecCount).strItemID = RTrim(sItemInID1)
                                                                                    wstrctPPLN_REC(wintRecCount).strItemCode = RTrim(sItemInCode1)
                                                                                    wstrctPPLN_REC(wintRecCount).strSerialNo = sSerialNo1
                                                                                    wstrctPPLN_REC(wintRecCount).strTempSerial = sTempSerial
                                                                                    wstrctPPLN_REC(wintRecCount).strStockLctn = sStockLctn1
                                                                                    wstrctPPLN_REC(wintRecCount).strPickUser = sUserNo1
                                                                                    wstrctPPLN_REC(wintRecCount).strPickDate = sScanDate1
                                                                                    wstrctPPLN_REC(wintRecCount).strPickTime = sScanTime1

                                                                                    wstrKeyValue2(1) = RTrim(sItemInCode1)
                                                                                    wstrKeyValue2(2) = RTrim(sTempSerial1)
                                                                                    'End With

                                                                                    'If gclsDB.fDleRecords(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, wstrKey2, wstrKeyValue2) <> 0 Then
                                                                                    '    fClearJisseki = -1
                                                                                    '    Exit Function
                                                                                    'End If
                                                                                    wintRecCount += 1
                                                                                Case -1
                                                                                    Exit Function
                                                                            End Select
                                                                        Else
                                                                            If wintRecCount > 0 Then
                                                                                If wintRet3 <> -1 Then
                                                                                    'gclsDB.fCloseRecord("PKPLN00")
                                                                                    wintRet3 = -1
                                                                                End If
                                                                                fSearchPackPlan("KEY00", "KEYCJ00", wstrKeyValue2, wintRecCount, wstrctPPLN_REC)
                                                                                Exit Do 'データ更新後、次データ取得へ
                                                                            End If
                                                                        End If

                                                                        'If gclsDB.Records("KEYCJ00").Read(BtLib.Operation.GetNext) <> 0 Then
                                                                        '    If wintRecCount > 0 Then
                                                                        '        If wintRet3 <> -1 Then
                                                                        '            gclsDB.fCloseRecord("PKPLN00")
                                                                        '            wintRet3 = -1
                                                                        '        End If
                                                                        '        If fSearchPackPlan("KEY00", "KEYCJ00", wstrKeyValue2, wintRecCount, wstrctPPLN_REC) <> 1 Then
                                                                        '            fClearJisseki = -1
                                                                        '            Exit Function
                                                                        '        End If
                                                                        '    End If
                                                                        '    Exit Do 'CJの次データ取得後、AJの次レコードへ
                                                                        'End If




                                                                    End If
                                                                    If wbReadAJ Then Exit Do



                                                                    'End If

                                                                    i2 = i2 + 1

                                                                    If rowCount2 = i2 Then
                                                                        Exit Do
                                                                    End If

                                                                Loop



                                                            End If


                                                            'wintRet3 = gclsDB.fOpenRecord(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, "PKPLN00", wstrKey3, wstrKeyValue3, BtLib.Operation.GetGreaterOrEqual)
                                                        End If





                                                    End If



                                                Loop

                                            End If
                                        End If
                                    End If

                                    i1 = i1 + 1

                                    If rowCount1 = i1 Then
                                        Exit Do
                                    End If

                                Loop



                            End If



                            'wintRet2 = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, "KEYCJ00", wstrKey2, wstrKeyValue2, BtLib.Operation.GetGreaterOrEqual)
                        End If


                    End If

                    i = i + 1

                    If rowCount = i Then
                        Exit Do
                    End If

                Loop
            End If



        Catch ex As Exception
            fClearJisseki = -1
            sErrLog(gAppName, "fClearJisseki", ex.ToString)
        Finally

        End Try




        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKAJ, G_CONST_KEY_PACKAJKEY00, "KEY00", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'Select Case wintRet
        '    Case -1
        '        Exit Function
        '    Case 0
        '        fClearJisseki = 0
        '        wstrKey2(0) = "ItemCode"
        '        wstrKey2(1) = "ItemInCode"
        '        wstrKey2(2) = "TempSerial"
        '        wstrKey3(0) = "PicsType" : wstrKeyValue3(0) = gstrctKDHT.strPackType
        '        wstrKey3(1) = "Cstmid" : wstrKeyValue3(1) = gstrctKDHT.strCstmid
        '        wstrKey3(2) = "CstmCode" : wstrKeyValue3(2) = gstrctKDHT.strCstmCode
        '        wstrKey3(3) = "CenterCode" : wstrKeyValue3(3) = gstrctKDPL.strCenterCode
        '        wstrKey3(4) = "Date"
        '        wstrKey3(5) = "Line"
        '        wstrKey3(6) = "Aic"
        '        wstrKey3(7) = "CaseNo"
        '        wstrKey3(8) = "CartonNo"
        '        wstrKey3(9) = "ItemID"
        '        wstrKey3(10) = "ItemCode"
        '        wstrKey3(11) = "SerialNo"
        '        wstrKey3(12) = "TempSerial"
        '        Try
        '            Do
        '                With gclsDB.Records("KEY00")
        '                    If RTrim(.Item("PaletteID")) = "A" AndAlso RTrim(.Item("ItemGr")) = wstrKeyValue(1) Then
        '                        If wstrKeyValue2(0) <> RTrim(.Item("ItemCode")) Then
        '                            If wintRet2 <> -1 Then
        '                                gclsDB.fCloseRecord("KEYCJ00")
        '                                wintRet2 = -1
        '                            End If
        '                        End If
        '                        wstrKeyValue2(0) = RTrim(.Item("ItemCode"))
        '                        If Mid(RTrim(.Item("ItemCode")), 21, 5) = "00000" OrElse RTrim(.Item("ItemID")) = "B" Then '部品
        '                            wstrKeyValue2(1) = RTrim(.Item("ItemInCode"))
        '                            wstrKeyValue2(2) = Space(6)
        '                            wintFlag = 0
        '                        Else 'カートン
        '                            wstrKeyValue2(1) = Space(30)
        '                            wstrKeyValue2(2) = Space(6)
        '                            wintFlag = 1
        '                        End If

        '                        If wintFlag <> 0 AndAlso wintRet2 <> -1 Then
        '                            If wintRet2 <> -1 Then
        '                                gclsDB.fCloseRecord("KEYCJ00")
        '                                wintRet2 = -1
        '                            End If
        '                        End If
        '                        If wintRet2 = -1 Then
        '                            wintRet2 = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, "KEYCJ00", wstrKey2, wstrKeyValue2, BtLib.Operation.GetGreaterOrEqual)
        '                        End If
        '                        Select Case wintRet2
        '                            Case 0
        '                                Do

        '                                    If Mid(RTrim(.Item("ItemCode")), 21, 5) = "00000" OrElse RTrim(.Item("ItemID")) = "B" Then '部品
        '                                        If wintFlag = 0 Then '部品
        '                                            If fSearchStock("KEYCJ00") = 1 Then
        '                                                Do
        '                                                    If RTrim(.Item("ItemID")) = RTrim(gclsDB.Records("KEYCJ00").Item("ItemID")) AndAlso _
        '                                                       RTrim(.Item("ItemCode")) = RTrim(gclsDB.Records("KEYCJ00").Item("ItemCode")) AndAlso _
        '                                                       RTrim(.Item("ItemInID")) = RTrim(gclsDB.Records("KEYCJ00").Item("ItemInID")) AndAlso _
        '                                                       RTrim(.Item("ItemInCode")) = RTrim(gclsDB.Records("KEYCJ00").Item("ItemInCode")) Then
        '                                                        'PackPlan再ｵｰﾌﾟﾝ処理
        '                                                        If Mid(RTrim(gclsDB.Records("KEYCJ00").Item("ItemCode")), 21, 5) <> wstrKeyValue3(8) Then
        '                                                            If wintRet3 <> -1 Then
        '                                                                gclsDB.fCloseRecord("PKPLN00")
        '                                                                wintRet3 = -1
        '                                                            End If
        '                                                            wstrKeyValue3(4) = RTrim(.Item("ProductDate")).PadRight(8, " ") & RTrim(.Item("Shift")).PadRight(1, " ")
        '                                                            wstrKeyValue3(5) = .Item("Line")
        '                                                            wstrKeyValue3(6) = Mid(gstrctAicCase.AicCaseNo, 1, 13)
        '                                                            wstrKeyValue3(7) = Replace(gstrctAicCase.CaseNo, "-", "")
        '                                                            If .Item("ItemID") = "C" Then
        '                                                                wstrKeyValue3(8) = Mid(.Item("ItemCode"), 21, 5)
        '                                                            ElseIf .Item("ItemID") = "B" Then
        '                                                                wstrKeyValue3(8) = "00000"
        '                                                            End If
        '                                                            wstrKeyValue3(9) = RTrim(.Item("ItemInID"))
        '                                                            wstrKeyValue3(10) = RTrim(.Item("ItemInCode"))
        '                                                            wstrKeyValue3(11) = Space(6)
        '                                                            wstrKeyValue3(12) = Space(6)
        '                                                            wintRet3 = gclsDB.fOpenRecord(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, "PKPLN00", wstrKey3, wstrKeyValue3, BtLib.Operation.GetGreaterOrEqual)
        '                                                        End If
        '                                                        wstrKeyValue3(0) = RTrim(gclsDB.Records("KEYCJ00").Item("PicsType"))
        '                                                        wstrKeyValue3(1) = RTrim(gclsDB.Records("KEYCJ00").Item("Cstmid"))
        '                                                        wstrKeyValue3(2) = RTrim(gclsDB.Records("KEYCJ00").Item("CstmCode"))
        '                                                        wstrKeyValue3(3) = RTrim(gclsDB.Records("KEYCJ00").Item("CenterCode"))
        '                                                        wstrKeyValue3(4) = RTrim(gclsDB.Records("KEYCJ00").Item("ProductDate")).PadRight(8, " ") & RTrim(gclsDB.Records("KEYCJ00").Item("Shift")).PadRight(1, " ")
        '                                                        wstrKeyValue3(5) = RTrim(gclsDB.Records("KEYCJ00").Item("Line"))
        '                                                        wstrKeyValue3(6) = Mid(gstrctAicCase.AicCaseNo, 1, 13)
        '                                                        wstrKeyValue3(7) = Replace(gstrctAicCase.CaseNo, "-", "")
        '                                                        If RTrim(.Item("ItemID")) = "C" Then
        '                                                            wstrKeyValue3(8) = Mid(gclsDB.Records("KEYCJ00").Item("ItemCode"), 21, 5)
        '                                                        ElseIf .Item("ItemID") = "B" Then
        '                                                            wstrKeyValue3(8) = "00000"
        '                                                        End If
        '                                                        wstrKeyValue3(9) = RTrim(gclsDB.Records("KEYCJ00").Item("ItemInID"))
        '                                                        wstrKeyValue3(10) = RTrim(gclsDB.Records("KEYCJ00").Item("ItemInCode"))
        '                                                        'PackCJとPackPlanの突合せ
        '                                                        If RTrim(gclsDB.Records("PKPLN00").Item("PicsType")) = wstrKeyValue3(0) AndAlso _
        '                                                           RTrim(gclsDB.Records("PKPLN00").Item("Cstmid")) = wstrKeyValue3(1) AndAlso _
        '                                                           RTrim(gclsDB.Records("PKPLN00").Item("CstmCode")) = wstrKeyValue3(2) AndAlso _
        '                                                           RTrim(gclsDB.Records("PKPLN00").Item("CenterCode")) = wstrKeyValue3(3) AndAlso _
        '                                                           RTrim(gclsDB.Records("PKPLN00").Item("Date")) = wstrKeyValue3(4) AndAlso _
        '                                                           RTrim(gclsDB.Records("PKPLN00").Item("Line")) = wstrKeyValue3(5) AndAlso _
        '                                                           RTrim(gclsDB.Records("PKPLN00").Item("Aic")) = wstrKeyValue3(6) AndAlso _
        '                                                           RTrim(gclsDB.Records("PKPLN00").Item("CaseNo")) = wstrKeyValue3(7) AndAlso _
        '                                                           RTrim(gclsDB.Records("PKPLN00").Item("CartonNo")) = wstrKeyValue3(8) AndAlso _
        '                                                           RTrim(gclsDB.Records("PKPLN00").Item("ItemID")) = wstrKeyValue3(9) AndAlso _
        '                                                           RTrim(gclsDB.Records("PKPLN00").Item("ItemCode")) = wstrKeyValue3(10) Then
        '                                                            wstrKeyValue3(11) = RTrim(gclsDB.Records("PKPLN00").Item("SerialNo"))
        '                                                            wstrKeyValue3(12) = RTrim(gclsDB.Records("PKPLN00").Item("TempSerial"))
        '                                                            If RTrim(gclsDB.Records("PKPLN00").Item("Status")) < "30" Then
        '                                                                With gclsDB
        '                                                                    .Setcolumn = "Status,PickDate,PickTime,PickEmp,PickLctn1,SerialNo,PalDate,PalTime,PalEmp,SectionIDPal,SectionCodePal"
        '                                                                    .SetData = "30," & .Records("KEYCJ00").Item("ScanDate") & "," & .Records("KEYCJ00").Item("ScanTime") & "," _
        '                                                                      & .Records("KEYCJ00").Item("UserNo") & "," & .Records("KEYCJ00").Item("StockLctn") & "," & .Records("KEYCJ00").Item("SerialNo") & "," _
        '                                                                      & .Records("KEY00").Item("ScanDate") & "," & .Records("KEY00").Item("ScanTime") & "," & .Records("KEY00").Item("UserNo") & "," _
        '                                                                      & .Records("KEY00").Item("CarryOutSectioniId") & "," & .Records("KEY00").Item("CarryOutSection")
        '                                                                End With
        '                                                            Else
        '                                                                With gclsDB
        '                                                                    .Setcolumn = "PalDate,PalTime,PalEmp,SectionIDPal,SectionCodePal"
        '                                                                    .SetData = .Records("KEY00").Item("ScanDate") & "," & .Records("KEY00").Item("ScanTime") & "," & .Records("KEY00").Item("UserNo") & "," _
        '                                                                            & .Records("KEY00").Item("CarryOutSectionId") & "," & .Records("KEY00").Item("CarryOutSection")
        '                                                                End With
        '                                                            End If
        '                                                            If gclsDB.fUpdRecords(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, wstrKey3, wstrKeyValue3) <> 0 Then
        '                                                                fClearJisseki = -1
        '                                                                Exit Function
        '                                                            End If
        '                                                            'PACKCJ削除処理
        '                                                            wstrKeyValue2(1) = RTrim(gclsDB.Records("KEYCJ00").Item("ItemInCode"))
        '                                                            wstrKeyValue2(2) = RTrim(gclsDB.Records("KEYCJ00").Item("TempSerial"))
        '                                                            If gclsDB.fDleRecords(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, wstrKey2, wstrKeyValue2) <> 0 Then
        '                                                                fClearJisseki = -1
        '                                                                Exit Function
        '                                                            End If
        '                                                            If gclsDB.Records("KEYCJ00").Read(BtLib.Operation.GetNext) <> 0 Then
        '                                                                Exit Function
        '                                                            End If
        '                                                            If .Item("ItemID") = "B" Then '比較のためｶｰﾄﾝを復帰
        '                                                                wstrKeyValue3(8) = Mid(.Item("ItemCode"), 21, 5)
        '                                                            End If
        '                                                            If gclsDB.Records("PKPLN00").Read(BtLib.Operation.GetNext) <> 0 Then
        '                                                                Exit Function
        '                                                            End If
        '                                                            wbReadAJ = True
        '                                                            Exit Do
        '                                                        Else
        '                                                            If .Item("ItemID") = "B" Then '比較のためｶｰﾄﾝを復帰
        '                                                                wstrKeyValue3(8) = Mid(.Item("ItemCode"), 21, 5)
        '                                                            End If
        '                                                            If gclsDB.Records("PKPLN00").Read(BtLib.Operation.GetNext) <> 0 Then
        '                                                                Exit Function
        '                                                            End If
        '                                                        End If
        '                                                    Else
        '                                                        Exit Do
        '                                                    End If
        '                                                Loop
        '                                            End If
        '                                        End If
        '                                    Else 'カートン
        '                                        If wintFlag = 0 Then  '再オープン
        '                                            wstrKeyValue2(0) = RTrim(.Item("ItemCode"))
        '                                            wstrKeyValue2(1) = Space(30)
        '                                            wstrKeyValue2(2) = Space(6)
        '                                            wintFlag = 1
        '                                            If wintRet2 <> -1 Then
        '                                                gclsDB.fCloseRecord("KEYCJ00")
        '                                                wintRet2 = -1
        '                                            End If
        '                                            wintRet2 = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, "KEYCJ00", wstrKey2, wstrKeyValue2, BtLib.Operation.GetGreaterOrEqual)
        '                                            If wintRet2 = -1 Then
        '                                                Exit Function
        '                                            ElseIf wintRet2 <> 0 Then
        '                                                fClearJisseki = 0
        '                                                Exit Do
        '                                            End If
        '                                        End If
        '                                        If RTrim(.Item("ItemCode")) = RTrim(gclsDB.Records("KEYCJ00").Item("ItemCode")) Then '同一ｶｰﾄﾝ
        '                                            Select Case fSearchStock("KEYCJ00")
        '                                                Case 1
        '                                                    'PACKPLANの更新
        '                                                    ReDim Preserve wstrctPPLN_REC(wintRecCount)
        '                                                    With gclsDB.Records("KEYCJ00")
        '                                                        wstrctPPLN_REC(wintRecCount).strPicsType = gstrctKDHT.strPackType
        '                                                        wstrctPPLN_REC(wintRecCount).strCstmid = gstrctKDHT.strCstmid
        '                                                        wstrctPPLN_REC(wintRecCount).strCstmCode = gstrctKDHT.strCstmCode
        '                                                        wstrctPPLN_REC(wintRecCount).strCenterCode = gstrctKDPL.strCenterCode
        '                                                        wstrctPPLN_REC(wintRecCount).strDate = RTrim(.Item("ProductDate")).PadRight(8, " ") & RTrim(.Item("Shift")).PadRight(1, " ")
        '                                                        wstrctPPLN_REC(wintRecCount).strLine = .Item("Line")
        '                                                        wstrctPPLN_REC(wintRecCount).strAic = Mid(gstrctAicCase.AicCaseNo, 1, 13)
        '                                                        wstrctPPLN_REC(wintRecCount).strCaseNo = Replace(gstrctAicCase.CaseNo, "-", "")
        '                                                        If .Item("ItemID") = "C" Then
        '                                                            wstrctPPLN_REC(wintRecCount).strCartonNo = Mid(.Item("ItemCode"), 21, 5)
        '                                                        Else
        '                                                            wstrctPPLN_REC(wintRecCount).strCartonNo = "00000"
        '                                                        End If
        '                                                        wstrctPPLN_REC(wintRecCount).strItemID = RTrim(.Item("ItemInID"))
        '                                                        wstrctPPLN_REC(wintRecCount).strItemCode = RTrim(.Item("ItemInCode"))
        '                                                        wstrctPPLN_REC(wintRecCount).strSerialNo = .Item("SerialNo")
        '                                                        wstrctPPLN_REC(wintRecCount).strTempSerial = .Item("TempSerial")
        '                                                        wstrctPPLN_REC(wintRecCount).strStockLctn = .Item("StockLctn")
        '                                                        wstrctPPLN_REC(wintRecCount).strPickUser = .Item("UserNo")
        '                                                        wstrctPPLN_REC(wintRecCount).strPickDate = .Item("ScanDate")
        '                                                        wstrctPPLN_REC(wintRecCount).strPickTime = .Item("ScanTime")

        '                                                        wstrKeyValue2(1) = RTrim(.Item("ItemInCode"))
        '                                                        wstrKeyValue2(2) = RTrim(.Item("TempSerial"))
        '                                                    End With

        '                                                    'If gclsDB.fDleRecords(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, wstrKey2, wstrKeyValue2) <> 0 Then
        '                                                    '    fClearJisseki = -1
        '                                                    '    Exit Function
        '                                                    'End If
        '                                                    wintRecCount += 1
        '                                                Case -1
        '                                                    Exit Function
        '                                            End Select
        '                                        Else
        '                                            If wintRecCount > 0 Then
        '                                                If wintRet3 <> -1 Then
        '                                                    gclsDB.fCloseRecord("PKPLN00")
        '                                                    wintRet3 = -1
        '                                                End If
        '                                                fSearchPackPlan("KEY00", "KEYCJ00", wstrKeyValue2, wintRecCount, wstrctPPLN_REC)
        '                                                Exit Do 'データ更新後、次データ取得へ
        '                                            End If
        '                                        End If

        '                                        If gclsDB.Records("KEYCJ00").Read(BtLib.Operation.GetNext) <> 0 Then
        '                                            If wintRecCount > 0 Then
        '                                                If wintRet3 <> -1 Then
        '                                                    gclsDB.fCloseRecord("PKPLN00")
        '                                                    wintRet3 = -1
        '                                                End If
        '                                                If fSearchPackPlan("KEY00", "KEYCJ00", wstrKeyValue2, wintRecCount, wstrctPPLN_REC) <> 1 Then
        '                                                    fClearJisseki = -1
        '                                                    Exit Function
        '                                                End If
        '                                            End If
        '                                            Exit Do 'CJの次データ取得後、AJの次レコードへ
        '                                        End If

        '                                    End If
        '                                    If wbReadAJ Then Exit Do
        '                                Loop
        '                        End Select

        '                    Else
        '                        Exit Function
        '                    End If
        '                    If .Read(BtLib.Operation.GetNext) <> 0 Then
        '                        Exit Function
        '                    End If
        '                    If wbReadAJ Then wbReadAJ = False
        '                End With

        '            Loop
        '        Catch ex As Exception
        '            fClearJisseki = -1
        '            Throw ex
        '        Finally
        '            If fClearJisseki = -1 Then
        '                BtLib.Transaction.Abort()
        '            Else
        '                BtLib.Transaction.End()
        '            End If
        '        End Try

        '    Case Else
        '        fClearJisseki = 0
        '        Exit Function
        'End Select

        'Catch ex As Exception
        '    fClearJisseki = -1
        '    sErrLog(gAppName, "fClearJisseki", ex.ToString)
        'Finally
        '    If wintRet <> -1 Then gclsDB.fCloseRecord("KEY00")
        '    If wintRet2 <> -1 Then gclsDB.fCloseRecord("KEYCJ00")
        '    If wintRet3 <> -1 Then gclsDB.fCloseRecord("PKPLN00")
        'End Try
    End Function

    Private Function fSearchPackCJ(ByVal pstrKeyCJ As String, Optional ByVal pintSrchSw As Integer = 0) As Integer
        'Dim wstrKey(2), wstrKeyValue(2) As String
        'Dim wstrKey2(12), wstrKeyValue2(12) As String
        'Dim wintRet As Integer = -1
        'Dim wintRet2 As Integer = -1
        'fSearchPackCJ = -1
        'wstrKey(0) = "ItemCode"
        'wstrKey(1) = "ItemInCode"
        'wstrKey(2) = "TempSerial"

        'Try
        '    With gclsDB.Records(pstrKeyCJ)
        '        wstrKeyValue(0) = RTrim(.Item("ItemCode"))
        '        If pintSrchSw = 0 Then '部品
        '            wstrKeyValue(1) = RTrim(.Item("ItemInCode"))
        '            wstrKeyValue(2) = Space(6)
        '            'wstrKeyValue(2) = RTrim(.Item("TempSerial"))
        '            wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, "KEYCJ00", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        '            Select Case wintRet
        '                Case -1
        '                    Exit Function
        '                Case 0
        '                    If RTrim(.Item("ItemCode")) = wstrKeyValue(1) Then
        '                        Do
        '                            If fSearchStock("KEYCJ00") = 1 Then
        '                                wstrKey2(0) = "PicsType" : wstrKeyValue2(0) = gstrctKDHT.strPackType
        '                                wstrKey2(1) = "Cstmid" : wstrKeyValue2(1) = gstrctKDHT.strCstmid
        '                                wstrKey2(2) = "CstmCode" : wstrKeyValue2(2) = gstrctKDHT.strCstmCode
        '                                wstrKey2(3) = "CenterCode" : wstrKeyValue2(3) = gstrctKDPL.strCenterCode
        '                                wstrKey2(4) = "Date" : wstrKeyValue2(4) = RTrim(.Item("ProductDate")).PadRight(8, " ") & RTrim(.Item("Shift")).PadRight(1, " ")
        '                                wstrKey2(5) = "Line" : wstrKeyValue2(5) = .Item("Line")
        '                                wstrKey2(6) = "Aic" : wstrKeyValue2(6) = Mid(gstrctAicCase.AicCaseNo, 1, 13)
        '                                wstrKey2(7) = "CaseNo" : wstrKeyValue2(7) = gstrctAicCase.CaseNo
        '                                wstrKey2(8) = "CartonNo"
        '                                If .Item("ItemID") = "C" Then
        '                                    wstrKeyValue2(8) = Mid(.Item("ItemCode"), 21, 5)
        '                                ElseIf .Item("ItemID") = "B" Then
        '                                    wstrKeyValue2(8) = "00000"
        '                                End If
        '                                wstrKey(9) = "ItemID" : wstrKeyValue2(9) = RTrim(.Item("ItemInID"))
        '                                wstrKey(10) = "ItemCode" : wstrKeyValue2(10) = RTrim(.Item("ItemInCode"))
        '                                wstrKey(11) = "SerialNo" : wstrKeyValue2(11) = Space(6)
        '                                wstrKey(12) = "TempSerial" : wstrKeyValue2(12) = Space(6)
        '                                'PACKPLANの更新
        '                                wintRet2 = gclsDB.fOpenRecord(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, "PKPLN00", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        '                                Select Case wintRet2
        '                                    Case 0
        '                                        Do
        '                                            With gclsDB.Records("PKPLN00")
        '                                                If RTrim(.Item("PicsType")) = wstrKeyValue2(0) AndAlso RTrim(.Item("Cstmid")) = wstrKeyValue2(1) AndAlso _
        '                                                   RTrim(.Item("CstmCode")) = wstrKeyValue2(2) AndAlso RTrim(.Item("CenterCode")) = wstrKeyValue2(3) AndAlso _
        '                                                   RTrim(.Item("Date")) = wstrKeyValue2(4) AndAlso RTrim(.Item("Line")) = wstrKeyValue2(5) AndAlso _
        '                                                   RTrim(.Item("Aic")) = wstrKeyValue2(6) AndAlso RTrim(.Item("CaseNo")) = wstrKeyValue2(7) AndAlso _
        '                                                   RTrim(.Item("CartonNo")) = wstrKeyValue2(8) AndAlso RTrim(.Item("ItemID")) = wstrKeyValue2(9) AndAlso _
        '                                                   RTrim(.Item("ItemCode")) = wstrKeyValue2(10) Then
        '                                                    If RTrim(.Item("Status")) < "30 then" Then
        '                                                        Dim wstrSerialNo As String
        '                                                        wstrKeyValue(11) = .Item("SerialNo")
        '                                                        wstrKeyValue(12) = .Item("TempSerial")
        '                                                        '// DB更新
        '                                                        With gclsDB
        '                                                            If RTrim(.Records("KEYCJ00").Item("PackQtyJ")).PadLeft(5, "0") = "00000" Then
        '                                                                wstrSerialNo = "00000"
        '                                                            Else
        '                                                                wstrSerialNo = RTrim(.Records("KEYCJ00").Item("SerialNo")).PadLeft(5, "0")
        '                                                            End If
        '                                                            .Setcolumn = "Status,PickDate,PickTime,PickEmp,PickLctn1,SerialNo,PalDate,PalTime,PalEmp"
        '                                                            .SetData = "30," & .Records("KEYCJ00").Item("ScanDate") & "," & .Records("KEYCJ00").Item("ScanTime") & "," _
        '                                                              & .Records("KEYCJ00").Item("UserNo") & "," & .Records("KEYCJ00").Item("StockLctn") & "," & wstrSerialNo
        '                                                            If .fUpdRecords(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, wstrKey, wstrKeyValue) = -1 Then
        '                                                                fSearchPackCJ = -1
        '                                                                sErrLog(gAppName, "fSearchPackCJ", gclsDB.ErrMsg)
        '                                                                Exit Function
        '                                                            End If
        '                                                        End With
        '                                                        fSearchPackCJ = 1
        '                                                        Exit Function
        '                                                    Else
        '                                                        If fSearchPackCJ = -1 Then fSearchPackCJ = 0
        '                                                        Exit Function
        '                                                    End If
        '                                                    If .Read(BtLib.Operation.GetNext) <> 0 Then
        '                                                        Exit Do
        '                                                    End If
        '                                                End If
        '                                            End With
        '                                        Loop
        '                                    Case -1
        '                                    Case Else
        '                                        Exit Function
        '                                End Select

        '                            End If
        '                        Loop
        '                    Else
        '                        Exit Function
        '                    End If
        '                Case Else
        '                    fSearchPackCJ = 0
        '                    Exit Function
        '            End Select
        '        Else 'カートン
        '            wstrKeyValue(1) = Space(30)
        '            wstrKeyValue(2) = Space(6)
        '            wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, "KEYCJ00", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        '            Select Case wintRet
        '                Case -1
        '                    Exit Function
        '                Case 0
        '                    Do

        '                        With gclsDB.Records("KEYCJ00")
        '                            If RTrim(.Item("ItemCode")) = wstrKeyValue(0) Then
        '                                Select Case fSearchStock("KEYCJ00")
        '                                    Case -1
        '                                        fSearchPackCJ = -1
        '                                        Exit Function
        '                                    Case 1
        '                                        'PACKPLANの更新
        '                                        fUpdPackPlan("KEYCJ00")
        '                                        wstrKeyValue(1) = RTrim(.Item("ItemInCode"))
        '                                        wstrKeyValue(2) = RTrim(.Item("TempSerial"))
        '                                        If gclsDB.fDleRecords(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, wstrKey, wstrKeyValue) <> 0 Then
        '                                            Exit Function
        '                                        End If
        '                                End Select
        '                                If .Read(BtLib.Operation.GetNext) <> 0 Then Exit Do
        '                            Else
        '                                Exit Do
        '                            End If
        '                        End With
        '                    Loop
        '                Case Else
        '                    fSearchPackCJ = 0
        '                    Exit Function
        '            End Select
        '        End If
        '    End With

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

    Private Function fSearchStock(ByVal pstrKeyStk As String) As Integer
        Dim wstrKey(7), wstrKeyValue(7) As String
        Dim wintRet As Integer = -1
        Dim wstrWhere As String
        fSearchStock = -1
        With gstrctKDHT
            wstrKey(0) = "PicsType" : wstrKeyValue(0) = .strPackType
            wstrKey(1) = "Cstmid" : wstrKeyValue(1) = .strCstmid
            wstrKey(2) = "CstmCode" : wstrKeyValue(2) = .strCstmCode
        End With
        With gstrctKDPL
            wstrKey(3) = "CenterCode" : wstrKeyValue(3) = .strCenterCode
            wstrKey(4) = "Bhk" : wstrKeyValue(4) = .strBhk
        End With
        wstrKey(5) = "Itemid" : wstrKeyValue(5) = "P"
        wstrKey(6) = "ItemCode"
        wstrKey(7) = "SerialNo"

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

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

        If tmpStr.Count > 0 Then

            values = tmpStr(0)

            wstrKeyValue(6) = RTrim(sItemInCode)
            wstrKeyValue(7) = RTrim(sSerialNo)

        End If


        'With gclsDB.Records(pstrKeyStk)
        '    wstrKeyValue(6) = RTrim(.Item("ItemInCode"))
        '    wstrKeyValue(7) = RTrim(.Item("SerialNo"))
        'End With

        Try

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

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

            Dim values1 As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sZaikoStatus As String = ""
            Dim sSql As String = ""

            If tmpStr.Count > 0 Then

                values1 = tmpStr(0)

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

                If sZaikoStatus = "7" Then

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


                    If affected_rows = 0 Then
                        Exit Function
                    End If

                Else

                    sSql = "UPDATE " + G_CONST_TBL_STOCK + " SET ZaikoStatus='" _
                            + "9" _
                            + "' WHERE " + wstrWhere

                    affected_rows = dbClient.Execute(sSql)

                    If affected_rows = 0 Then
                        Exit Function
                    End If

                End If

                fSearchStock = 1

            Else

                fSearchStock = 0

            End If



            'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, "STK00", wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)
            'Select Case wintRet
            '    Case -1
            '        Exit Function
            '    Case 0
            '        If gclsDB.Records("STK00").Item("ZaikoStatus") = "7" Then
            '            If gclsDB.fDleRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, wstrKey, wstrKeyValue) <> 0 Then
            '                Exit Function
            '            End If
            '        Else
            '            gclsDB.Setcolumn = "ZaikoStatus"
            '            gclsDB.SetData = "9"
            '            If gclsDB.fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, wstrKey, wstrKeyValue) <> 0 Then
            '                Exit Function
            '            End If
            '        End If
            '        fSearchStock = 1
            '    Case Else
            '        fSearchStock = 0
            'End Select
        Catch ex As Exception
            fSearchStock = -1
            sErrLog(gAppName, "fSearchStock", ex.ToString)
        Finally
            'If wintRet <> -1 Then gclsDB.fCloseRecord("STK00")
        End Try
    End Function
    Private Function fUpdPackPlan(ByVal pstrKey As String) As Integer
        'Dim wstrKey(12), wstrKeyValue(12) As String
        'Dim wintRet As Integer = -1
        'fUpdPackPlan = -1
        'Try
        '    With gclsDB.Records(pstrKey)
        '        wstrKey(0) = "PicsType" : wstrKeyValue(0) = gstrctKDHT.strPackType
        '        wstrKey(1) = "Cstmid" : wstrKeyValue(1) = gstrctKDHT.strCstmid
        '        wstrKey(2) = "CstmCode" : wstrKeyValue(2) = gstrctKDHT.strCstmCode
        '        wstrKey(3) = "CenterCode" : wstrKeyValue(3) = gstrctKDPL.strCenterCode
        '        wstrKey(4) = "Date" : wstrKeyValue(4) = RTrim(.Item("ProductDate")).PadRight(8, " ") & RTrim(.Item("Shift")).PadRight(1, " ")
        '        wstrKey(5) = "Line" : wstrKeyValue(5) = .Item("Line")
        '        wstrKey(6) = "Aic" : wstrKeyValue(6) = Mid(gstrctAicCase.AicCaseNo, 1, 13)
        '        wstrKey(7) = "CaseNo" : wstrKeyValue(7) = gstrctAicCase.CaseNo
        '        wstrKey(8) = "CartonNo"
        '        If .Item("ItemID") = "C" Then
        '            wstrKeyValue(8) = Mid(.Item("ItemCode"), 21, 5)
        '        ElseIf .Item("ItemID") = "B" Then
        '            wstrKeyValue(8) = "00000"
        '        End If
        '        wstrKey(9) = "ItemID" : wstrKeyValue(9) = RTrim(.Item("ItemInID"))
        '        wstrKey(10) = "ItemCode" : wstrKeyValue(10) = RTrim(.Item("ItemInCode"))
        '        wstrKey(11) = "SerialNo" : wstrKeyValue(11) = Space(6)
        '        wstrKey(12) = "TempSerial" : wstrKeyValue(12) = Space(6)
        '        'wstrKey(11) = "SerialNo" : wstrKeyValue(11) = .Item("SerialNo")
        '        'wstrKey(12) = "TempSerial" : wstrKeyValue(12) = .Item("TempSerial")
        '    End With
        '    wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY03, "PKPLN00", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        '    Select Case wintRet
        '        Case -1
        '            Exit Function
        '        Case 0
        '            Do
        '                With gclsDB.Records("PKPLN00")
        '                    If RTrim(.Item("PicsType")) = wstrKeyValue(0) AndAlso RTrim(.Item("Cstmid")) = wstrKeyValue(1) AndAlso RTrim(.Item("CstmCode")) = wstrKeyValue(2) AndAlso _
        '                       RTrim(.Item("CenterCode")) = wstrKeyValue(3) AndAlso RTrim(.Item("Date")) = wstrKeyValue(4) AndAlso RTrim(.Item("Line")) = wstrKeyValue(5) AndAlso _
        '                       RTrim(.Item("Aic")) = wstrKeyValue(6) AndAlso RTrim(.Item("CaseNo")) = wstrKeyValue(7) AndAlso RTrim(.Item("CartonNo")) = wstrKeyValue(8) AndAlso _
        '                       RTrim(.Item("ItemID")) = wstrKeyValue(9) AndAlso RTrim(.Item("ItemCode")) = wstrKeyValue(10) Then
        '                        If RTrim(.Item("Status")) < "30 then" Then
        '                            Dim wstrSerialNo As String
        '                            wstrKeyValue(11) = .Item("SerialNo")
        '                            wstrKeyValue(12) = .Item("TempSerial")
        '                            '// DB更新
        '                            With gclsDB
        '                                If RTrim(.Records(pstrKey).Item("PackQtyJ")).PadLeft(5, "0") = "00000" Then
        '                                    wstrSerialNo = "00000"
        '                                Else
        '                                    wstrSerialNo = RTrim(.Records(pstrKey).Item("SerialNo")).PadLeft(5, "0")
        '                                End If
        '                                .Setcolumn = "Status,PickDate,PickTime,PickEmp,PickLctn1,SerialNo"
        '                                .SetData = "30," & .Records(pstrKey).Item("ScanDate") & "," & .Records(pstrKey).Item("ScanTime") & "," _
        '                                  & .Records(pstrKey).Item("UserNo") & "," & .Records(pstrKey).Item("StockLctn") & "," & wstrSerialNo
        '                                If .fUpdRecords(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, wstrKey, wstrKeyValue) = -1 Then
        '                                    fUpdPackPlan = -1
        '                                    sErrLog(gAppName, "fUpdPackPlan", gclsDB.ErrMsg)
        '                                    Exit Function
        '                                End If
        '                            End With
        '                            fUpdPackPlan = 1
        '                            Exit Function
        '                        Else
        '                            fUpdPackPlan = 0
        '                            Exit Function
        '                        End If
        '                        If .Read(BtLib.Operation.GetNext) <> 0 Then
        '                            If fUpdPackPlan = -1 Then
        '                                fUpdPackPlan = 0
        '                            End If
        '                        End If

        '                    Else
        '                        fUpdPackPlan = 0
        '                        Exit Function
        '                    End If
        '                End With
        '            Loop
        '    End Select

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

    Private Function fSearchPackPlan(ByVal pstrApKey As String, ByVal pstrCJKey As String, ByRef pstrCJKeyValue() As String, ByRef pintRecCount As Integer, ByRef pstrctPPLN_REC() As STRCT_PPLN_REC) As Integer
        Dim wstrKey(12), wstrKeyValue(12) As String
        Dim wstrKey2(2) As String
        Dim i As Integer
        Dim wintRet As Integer = -1
        Dim wstrWhere As String
        Dim sSQL As String

        fSearchPackPlan = -1
        wstrKey(0) = "PicsType"
        wstrKey(1) = "Cstmid"
        wstrKey(2) = "CstmCode"
        wstrKey(3) = "CenterCode"
        wstrKey(4) = "Date"
        wstrKey(5) = "Line"
        wstrKey(6) = "Aic"
        wstrKey(7) = "CaseNo"
        wstrKey(8) = "CartonNo"
        wstrKey(9) = "ItemID"
        wstrKey(10) = "ItemCode"
        wstrKey(11) = "SerialNo"
        wstrKey(12) = "TempSerial"
        wstrKeyValue(0) = pstrctPPLN_REC(0).strPicsType
        wstrKeyValue(1) = pstrctPPLN_REC(0).strCstmid
        wstrKeyValue(2) = pstrctPPLN_REC(0).strCstmCode
        wstrKeyValue(3) = pstrctPPLN_REC(0).strCenterCode
        wstrKeyValue(4) = pstrctPPLN_REC(0).strDate
        wstrKeyValue(5) = pstrctPPLN_REC(0).strLine
        wstrKeyValue(6) = pstrctPPLN_REC(0).strAic
        wstrKeyValue(7) = pstrctPPLN_REC(0).strCaseNo
        wstrKeyValue(8) = pstrctPPLN_REC(0).strCartonNo
        wstrKeyValue(9) = Space(1)
        wstrKeyValue(10) = Space(30)
        wstrKeyValue(11) = Space(6)
        wstrKeyValue(12) = Space(6)
        wstrKey2(0) = "ItemCode"
        wstrKey2(1) = "ItemInCode"
        wstrKey2(2) = "TempSerial"


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

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sPicsType As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""
            Dim sCenterCode As String = ""
            Dim sDate As String = ""
            Dim sLine As String = ""
            Dim sAic As String = ""
            Dim sCaseNo As String = ""
            Dim sCartonNo As String = ""
            Dim sItemID As String = ""
            Dim sItemCode As String = ""
            Dim sSerialNo As String = ""
            Dim sTempSerial As String = ""
            Dim sStatus As String = ""
            Dim i1 As Integer = 0

            If tmpStr.Count > 0 Then

                Do

                    values = tmpStr(i1)

                    Dim result As String = Nothing
                    If values.TryGetValue("PicsType", result) Then
                        sPicsType = RTrim(result)
                    End If
                    If values.TryGetValue("Cstmid", result) Then
                        sCstmid = RTrim(result)
                    End If
                    If values.TryGetValue("CstmCode", result) Then
                        sCstmCode = RTrim(result)
                    End If
                    If values.TryGetValue("CenterCode", result) Then
                        sCenterCode = RTrim(result)
                    End If
                    If values.TryGetValue("Date", result) Then
                        sDate = RTrim(result)
                    End If
                    If values.TryGetValue("Line", result) Then
                        sLine = RTrim(result)
                    End If
                    If values.TryGetValue("Aic", result) Then
                        sAic = RTrim(result)
                    End If
                    If values.TryGetValue("CaseNo", result) Then
                        sCaseNo = RTrim(result)
                    End If
                    If values.TryGetValue("CartonNo", result) Then
                        sCartonNo = RTrim(result)
                    End If
                    If values.TryGetValue("ItemID", result) Then
                        sItemID = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("SerialNo", result) Then
                        sSerialNo = RTrim(result)
                    End If
                    If values.TryGetValue("TempSerial", result) Then
                        sTempSerial = RTrim(result)
                    End If
                    If values.TryGetValue("Status", result) Then
                        sStatus = RTrim(result)
                    End If

                    If sPicsType = pstrctPPLN_REC(i).strPicsType AndAlso sCstmid = pstrctPPLN_REC(i).strCstmid AndAlso _
                       sCstmCode = pstrctPPLN_REC(i).strCstmCode AndAlso sCenterCode = pstrctPPLN_REC(i).strCenterCode AndAlso _
                       sDate = pstrctPPLN_REC(i).strDate AndAlso sLine = pstrctPPLN_REC(i).strLine AndAlso _
                       sAic = pstrctPPLN_REC(i).strAic AndAlso sCaseNo = pstrctPPLN_REC(i).strCaseNo AndAlso _
                       sCartonNo = pstrctPPLN_REC(i).strCartonNo AndAlso sItemID = pstrctPPLN_REC(i).strItemID AndAlso _
                       sItemCode = pstrctPPLN_REC(i).strItemCode Then
                        wstrKeyValue(0) = pstrctPPLN_REC(i).strPicsType
                        wstrKeyValue(1) = pstrctPPLN_REC(i).strCstmid
                        wstrKeyValue(2) = pstrctPPLN_REC(i).strCstmCode
                        wstrKeyValue(3) = pstrctPPLN_REC(i).strCenterCode
                        wstrKeyValue(4) = pstrctPPLN_REC(i).strDate
                        wstrKeyValue(5) = pstrctPPLN_REC(i).strLine
                        wstrKeyValue(6) = pstrctPPLN_REC(i).strAic
                        wstrKeyValue(7) = pstrctPPLN_REC(i).strCaseNo
                        wstrKeyValue(8) = pstrctPPLN_REC(i).strCartonNo
                        wstrKeyValue(9) = pstrctPPLN_REC(i).strItemID
                        wstrKeyValue(10) = pstrctPPLN_REC(i).strItemCode
                        wstrKeyValue(11) = sSerialNo
                        wstrKeyValue(12) = sTempSerial

                        Dim values1 As Dictionary(Of String, String) = New Dictionary(Of String, String)
                        Dim sScanDate As String = ""
                        Dim sScanTime As String = ""

                        values1 = tmpStr_KEYCJ00(0)
                        Dim result1 As String = Nothing
                        If values1.TryGetValue("ScanDate", result1) Then
                            sScanDate = RTrim(result1)
                        End If
                        If values1.TryGetValue("ScanTime", result1) Then
                            sScanTime = RTrim(result1)
                        End If

                        Dim values2 As Dictionary(Of String, String) = New Dictionary(Of String, String)
                        Dim sScanDate2 As String = ""
                        Dim sScanTime2 As String = ""
                        Dim sUserNo2 As String = ""
                        Dim sCarryOutSectioniId2 As String = ""
                        Dim sCarryOutSection2 As String = ""

                        values2 = tmpStr_KEY00(0)
                        Dim result2 As String = Nothing
                        If values2.TryGetValue("ScanDate", result2) Then
                            sScanDate2 = RTrim(result2)
                        End If
                        If values2.TryGetValue("ScanTime", result2) Then
                            sScanTime2 = RTrim(result2)
                        End If
                        If values2.TryGetValue("UserNo", result2) Then
                            sUserNo2 = RTrim(result2)
                        End If
                        If values2.TryGetValue("CarryOutSectioniId", result2) Then
                            sCarryOutSectioniId2 = RTrim(result2)
                        End If
                        If values2.TryGetValue("CarryOutSection", result2) Then
                            sCarryOutSection2 = RTrim(result2)
                        End If


                        If RTrim(sStatus) < "30" Then


                            '.Setcolumn = "Status,PickDate,PickTime,PickEmp,PickLctn1,SerialNo,PalDate,PalTime,PalEmp,SectionIDPal,SectionCodePal"
                            '.SetData = "30," & .Records(pstrCJKey).Item("ScanDate") & "," & .Records(pstrCJKey).Item("ScanTime") & "," _
                            '  & pstrctPPLN_REC(i).strPickUser & "," & pstrctPPLN_REC(i).strStockLctn & "," & pstrctPPLN_REC(i).strSerialNo & "," _
                            '  & .Records(pstrApKey).Item("ScanDate") & "," & .Records(pstrApKey).Item("ScanTime") & "," & .Records(pstrApKey).Item("UserNo") & "," _
                            '  & .Records(pstrApKey).Item("CarryOutSectioniId") & "," & .Records(pstrApKey).Item("CarryOutSection")



                            sSQL = "UPDATE " + G_CONST_TBL_PACKPLAN + " SET Status='" _
                                                                 + "30" _
                                                                 + "' , PickDate='" _
                                                                 + sScanDate _
                                                                 + "' , PickTime='" _
                                                                 + sScanTime _
                                                                 + "' , PickEmp='" _
                                                                 + pstrctPPLN_REC(i).strPickUser _
                                                                 + "' , PickLctn1='" _
                                                                 + pstrctPPLN_REC(i).strStockLctn _
                                                                 + "' , SerialNo='" _
                                                                 + pstrctPPLN_REC(i).strSerialNo _
                                                                 + "' , PalDate='" _
                                                                 + sScanDate2 _
                                                                 + "' , PalTime='" _
                                                                 + sScanTime2 _
                                                                 + "' , PalEmp='" _
                                                                 + sUserNo2 _
                                                                 + "' , SectionIDPal='" _
                                                                 + sCarryOutSectioniId2 _
                                                                 + "' , SectionCodePal='" _
                                                                 + sCarryOutSection2 _
                                                                 + "' WHERE " + wstrWhere




                        Else

                            '.Setcolumn = "PalDate,PalTime,PalEmp,SectionIDPal,SectionCodePal"
                            '.SetData = .Records(pstrApKey).Item("ScanDate") & "," & .Records(pstrApKey).Item("ScanTime") & "," & .Records(pstrApKey).Item("UserNo") & "," _
                            '        & .Records(pstrApKey).Item("CarryOutSectionId") & "," & .Records(pstrApKey).Item("CarryOutSection")


                            sSQL = "UPDATE " + G_CONST_TBL_PACKPLAN + " SET PickDate='" _
                                                                 + sScanDate2 _
                                                                 + "' , PickTime='" _
                                                                 + sScanTime2 _
                                                                 + "' , PickEmp='" _
                                                                 + sUserNo2 _
                                                                 + "' , SectionIDPal='" _
                                                                 + sCarryOutSectioniId2 _
                                                                 + "' , SectionCodePal='" _
                                                                 + sCarryOutSection2 _
                                                                 + "' WHERE " + wstrWhere


                        End If

                        affected_rows = dbClient.Execute(sSQL)


                        If affected_rows = 0 Then
                            fSearchPackPlan = -1
                            Exit Function
                        End If
                        pstrCJKeyValue(1) = pstrctPPLN_REC(i).strItemCode
                        pstrCJKeyValue(2) = pstrctPPLN_REC(i).strTempSerial

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

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


                        If affected_rows = 0 Then
                            fSearchPackPlan = -1
                            Exit Function
                        End If


                    End If

                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If

                Loop
                pintRecCount = 0
                pstrctPPLN_REC = Nothing
                If wintRet <> -1 Then
                    wintRet = -1
                End If

                fSearchPackPlan = 1


            End If

        Catch ex As Exception
        Finally
        End Try


        '    wintRet = gclsDB.fOpenRecord(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, "PKPLN00", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        '    Try
        '        If wintRet = -1 Then Exit Function
        '        For i = 0 To pintRecCount - 1
        '            If gclsDB.Records("PKPLN00").Item("PicsType") = pstrctPPLN_REC(i).strPicsType AndAlso gclsDB.Records("PKPLN00").Item("Cstmid") = pstrctPPLN_REC(i).strCstmid AndAlso _
        '               gclsDB.Records("PKPLN00").Item("CstmCode") = pstrctPPLN_REC(i).strCstmCode AndAlso gclsDB.Records("PKPLN00").Item("CenterCode") = pstrctPPLN_REC(i).strCenterCode AndAlso _
        '               gclsDB.Records("PKPLN00").Item("Date") = pstrctPPLN_REC(i).strDate AndAlso gclsDB.Records("PKPLN00").Item("Line") = pstrctPPLN_REC(i).strLine AndAlso _
        '               gclsDB.Records("PKPLN00").Item("Aic") = pstrctPPLN_REC(i).strAic AndAlso gclsDB.Records("PKPLN00").Item("CaseNo") = pstrctPPLN_REC(i).strCaseNo AndAlso _
        '               gclsDB.Records("PKPLN00").Item("CartonNo") = pstrctPPLN_REC(i).strCartonNo AndAlso gclsDB.Records("PKPLN00").Item("ItemID") = pstrctPPLN_REC(i).strItemID AndAlso _
        '               gclsDB.Records("PKPLN00").Item("ItemCode") = pstrctPPLN_REC(i).strItemCode Then
        '                wstrKeyValue(0) = pstrctPPLN_REC(i).strPicsType
        '                wstrKeyValue(1) = pstrctPPLN_REC(i).strCstmid
        '                wstrKeyValue(2) = pstrctPPLN_REC(i).strCstmCode
        '                wstrKeyValue(3) = pstrctPPLN_REC(i).strCenterCode
        '                wstrKeyValue(4) = pstrctPPLN_REC(i).strDate
        '                wstrKeyValue(5) = pstrctPPLN_REC(i).strLine
        '                wstrKeyValue(6) = pstrctPPLN_REC(i).strAic
        '                wstrKeyValue(7) = pstrctPPLN_REC(i).strCaseNo
        '                wstrKeyValue(8) = pstrctPPLN_REC(i).strCartonNo
        '                wstrKeyValue(9) = pstrctPPLN_REC(i).strItemID
        '                wstrKeyValue(10) = pstrctPPLN_REC(i).strItemCode
        '                wstrKeyValue(11) = gclsDB.Records("PKPLN00").Item("SerialNo")
        '                wstrKeyValue(12) = gclsDB.Records("PKPLN00").Item("TempSerial")
        '                If RTrim(gclsDB.Records("PKPLN00").Item("Status")) < "30" Then
        '                    With gclsDB
        '                        .Setcolumn = "Status,PickDate,PickTime,PickEmp,PickLctn1,SerialNo,PalDate,PalTime,PalEmp,SectionIDPal,SectionCodePal"
        '                        .SetData = "30," & .Records(pstrCJKey).Item("ScanDate") & "," & .Records(pstrCJKey).Item("ScanTime") & "," _
        '                          & pstrctPPLN_REC(i).strPickUser & "," & pstrctPPLN_REC(i).strStockLctn & "," & pstrctPPLN_REC(i).strSerialNo & "," _
        '                          & .Records(pstrApKey).Item("ScanDate") & "," & .Records(pstrApKey).Item("ScanTime") & "," & .Records(pstrApKey).Item("UserNo") & "," _
        '                          & .Records(pstrApKey).Item("CarryOutSectioniId") & "," & .Records(pstrApKey).Item("CarryOutSection")
        '                    End With
        '                Else
        '                    With gclsDB
        '                        .Setcolumn = "PalDate,PalTime,PalEmp,SectionIDPal,SectionCodePal"
        '                        .SetData = .Records(pstrApKey).Item("ScanDate") & "," & .Records(pstrApKey).Item("ScanTime") & "," & .Records(pstrApKey).Item("UserNo") & "," _
        '                                & .Records(pstrApKey).Item("CarryOutSectionId") & "," & .Records(pstrApKey).Item("CarryOutSection")
        '                    End With
        '                End If
        '                If gclsDB.fUpdRecords(G_CONST_TBL_PACKPLAN, G_CONST_KEY_PACKPLANKEY06, wstrKey, wstrKeyValue) <> 0 Then
        '                    fSearchPackPlan = -1
        '                    Exit Function
        '                End If
        '                pstrCJKeyValue(1) = pstrctPPLN_REC(i).strItemCode
        '                pstrCJKeyValue(2) = pstrctPPLN_REC(i).strTempSerial

        '                If gclsDB.fDleRecords(G_CONST_TBL_PACKCJ, G_CONST_KEY_PACKCJKEY07, wstrKey2, pstrCJKeyValue) <> 0 Then
        '                    fSearchPackPlan = -1
        '                    Exit Function
        '                End If
        '            End If
        '            gclsDB.Records("PKPLN00").Read(BtLib.Operation.GetNext)
        '        Next
        '        pintRecCount = 0
        '        pstrctPPLN_REC = Nothing
        '        If wintRet <> -1 Then
        '            gclsDB.fCloseRecord("PKPLN00")
        '            wintRet = -1
        '        End If
        '        'Exit Do

        '        fSearchPackPlan = 1
        '    Catch ex As Exception
        '    Finally
        '        If wintRet <> -1 Then gclsDB.fCloseRecord("PKPLN00")
        '    End Try
    End Function


End Module
