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

Module modPublicPL000

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

    Public Structure ITEMINCODE_STR

        Public astrItemInCode() As String
        Public intIndex As Integer


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

        Public Sub ProcItem(ByVal strItemInCode As String)

            Dim i As Integer
            Dim flag As Boolean

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

        End Sub
    End Structure


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

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

        fGetCountry = -1

        Try

            Dim fileloc As String = "Setting.ini"

            Dim appPath As String = fgetAppPath() ' Assuming fgetAppPath() retrieves the application directory
            Dim filePath As String = Path.Combine(appPath, fileloc)

            Dim i As Integer = 0
            Dim strIP As String = "192.168.1.1"
            Dim intPort As Integer = 11433
            Dim strDatabase As String = "demodata"

            If File.Exists(filePath) Then

                Dim sr As StreamReader = New StreamReader(filePath)
                Dim s As String = sr.ReadToEnd()
                Dim words As String() = s.Split(New Char() {","c})

                Dim word As String

                For Each word In words

                    If i = 0 Then
                        strIP = word
                    ElseIf i = 1 Then

                        If IsNumeric(word) Then
                            intPort = Convert.ToInt32(word)
                        End If

                    ElseIf i = 2 Then
                        strDatabase = word
                    End If

                    i = i + 1

                Next

            End If

            dbClient = New BtrieveDbClient(strIP, intPort, strDatabase)


            'BtLib.Transaction.BeginConCurrent()

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

            'gstrctKDHT.strHdNo = "HT002"

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

            'MessageBox.Show(G_CONST_TBL_HTCTRL + " | " + wstrWhere)

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

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


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

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

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

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

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

                    wstrCount = "001"
                    wstrKeyFlg = "0"

                End If

            Else
                wstrCount = "001"
                wstrKeyFlg = "1"

                'Exit Function

            End If

            gstrctKDHT.strCountry = "001"
            Select Case wstrKeyFlg

                Case "0"        '更新ﾃﾞｰﾀ

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

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

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


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

                    affected_rows = dbClient.Execute(sSQL)




                Case "1"        '新規ﾃﾞｰﾀ

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

                    affected_rows = dbClient.Execute(sSQL)

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

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

                    'End If

            End Select

            'BtLib.Transaction.End()

            fGetCountry = 0

            Exit Function

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





        'wintCnt = gclsDB.fGetData(G_CONST_TBL_HTCTRL, G_CONST_KEY_HTCTRLKEY00, wstrWhere, "HTCTRL1")

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

        '    With gclsDB.Extended("HTCTRL1")

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

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

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

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

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

        '        End If
        '    End With

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

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

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

        'End If

        'gclsDB.fCloseRecord("HTCTRL1")

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

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

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

        '        wstrKey(0) = "HTNumber"
        '        wstrKeyValue(0) = gstrctKDHT.strHdNo
        '        If gclsDB.fUpdRecords(G_CONST_TBL_HTCTRL, G_CONST_KEY_HTCTRLKEY00, wstrKey, wstrKeyValue) = -1 Then
        '            BtLib.Transaction.Abort()

        '        End If

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

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

        '        End If

        'End Select

        'BtLib.Transaction.End()

        'fGetCountry = 0

        'Exit Function

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

    End Function


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

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

        fGetTitle = -1

        Try

            'BtLib.Transaction.BeginConCurrent()

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

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

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

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

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

                gstrctKDHT.strTitle = sTitle

            Else
                fGetTitle = -2

                Exit Function

            End If

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

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

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

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

            affected_rows = dbClient.Execute(sSQL)




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

            'End If

            'BtLib.Transaction.End()

            fGetTitle = 0

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




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

        'If wintCnt > 0 Then

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


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

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

        'End If

        'gclsDB.fCloseRecord("TITLE1")

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

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

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

        'End If

        'BtLib.Transaction.End()

        'fGetTitle = 0

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

    End Function


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

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

        fGetEmplName = -1

        Try

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

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

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

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

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

                gstrctKDHT.strUserName = sEmplName

            Else
                Exit Function

            End If

            fGetEmplName = 0

            Exit Function

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



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

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

        'ElseIf wintCnt = 0 Then

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

        'ElseIf wintCnt = -1 Then

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

        'End If

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

        'Exit Function

        'Catch ex As Exception
        '    sErrLog(gAppName, "fGetEmplName", ex.ToString)
        'End Try
    End Function
    '/*
    '|| 関数名： 
    '|| 概要  ：SPMからCartonTypeを読み込む
    '*/
    Public Function fGetCartonType(ByVal wstrDBName As String, ByRef pstrCartonType As String) As Integer

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

        Try
            fGetCartonType = -1

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

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

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



            Else
                Exit Function

            End If


            'With gclsDB.Records(wstrDBName)

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

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

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

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

            If tmpStr.Count > 0 Then
                values1 = tmpStr(0)
                Dim result As String = Nothing
                If values1.TryGetValue("CartonType", result) Then
                    sCartonType = RTrim(result)
                End If

                pstrCartonType = RTrim(sCartonType)

            Else
                Exit Function

            End If

            fGetCartonType = 0
            Exit Function

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


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

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

        '    End With

        'fGetCartonType = 0
        'Exit Function

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

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

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

        Try
            fGetKasoLine = -1

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sPicsType As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""
            Dim sLine As String = ""
            Dim sProductDate As String = ""
            Dim sShift As String = ""
            Dim sItemCode As String = ""

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


            Else
                Exit Function

            End If



            'With gclsDB.Records(wstrDBName)


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


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

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

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

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

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

            Else
                Exit Function

            End If

            fGetKasoLine = 0
            Exit Function

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




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

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

        '    End With

        'fGetKasoLine = 0
        'Exit Function

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

    End Function
    '/*
    '|| 関数名：fUpdPalleteQty
    '|| 概要  ：パレット数を更新
    '*/
    Public Function fUpdPaletteQty(ByVal intFlg As Integer) As Integer
        Dim wstrKey(2), wstrKeyValue(2) As String
        Dim ret As Integer
        Dim wstrWorkQty As String
        Dim wintQty As Integer
        Dim sSQL As String
        Dim wstrWhere As String
        fUpdPaletteQty = -1
        wstrKey(0) = "CenterCode"
        wstrKey(1) = "SectionID"
        wstrKey(2) = "Section"
        wstrKeyValue(0) = gstrctKDPL.strCenterCode
        wstrKeyValue(1) = gstrctKDPL.strSectionID
        wstrKeyValue(2) = gstrctKDPL.strSection

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

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

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

            If tmpStr.Count > 0 Then
                Try
                    values = tmpStr(0)

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

                    wstrWorkQty = sSeq

                    If IsNumeric(wstrWorkQty) Then
                        wintQty = CInt(wstrWorkQty)
                    Else
                        wintQty = 0
                    End If

                    If intFlg = 1 Then '加算
                        If wintQty >= G_CONST_MAX_PALT Then
                            fUpdPaletteQty = 0
                            Exit Function
                        Else
                            wintQty += 1
                        End If
                    ElseIf intFlg = 0 Then  '減算
                        If wintQty <= 0 Then
                            wintQty = 0
                        Else
                            wintQty -= 1
                        End If
                    End If

                    sSQL = "UPDATE " + G_CONST_TBL_SECTION + " SET Seq='" _
                                                             + CStr(wintQty).PadLeft(6, "0") _
                                                             + "' WHERE " + wstrWhere

                    affected_rows = dbClient.Execute(sSQL)

                Catch ex As Exception
                    Exit Function
                End Try

            Else
                Exit Function
            End If

            fUpdPaletteQty = 1
        Catch ex As Exception
            sErrLog(gAppName, "fUpdPaletteQty", ex.ToString)
        End Try


        'ret = gclsDB.fOpenRecord(G_CONST_TBL_SECTION, G_CONST_KEY_SECTIONKEY00, "SEC00", wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)
        'If ret = -1 Then
        '    Exit Function
        'ElseIf ret <> 0 Then
        '    gclsDB.fCloseRecord("SEC00")
        '    Exit Function
        'End If
        'wstrWorkQty = gclsDB.Records("SEC00").Item("Seq")
        'gclsDB.fCloseRecord("SEC00")
        'If IsNumeric(wstrWorkQty) Then
        '    wintQty = CInt(wstrWorkQty)
        'Else
        '    wintQty = 0
        'End If
        'If intFlg = 1 Then '加算
        '    If wintQty >= G_CONST_MAX_PALT Then
        '        fUpdPaletteQty = 0
        '        Exit Function
        '    Else
        '        wintQty += 1
        '    End If
        'ElseIf intFlg = 0 Then  '減算
        '    If wintQty <= 0 Then
        '        wintQty = 0
        '    Else
        '        wintQty -= 1
        '    End If
        'End If
        'With gclsDB
        '    .Setcolumn = "Seq"
        '    .SetData = CStr(wintQty).PadLeft(6, "0")
        '    .fUpdRecords(G_CONST_TBL_SECTION, G_CONST_KEY_SECTIONKEY00, wstrKey, wstrKeyValue)
        'End With

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

    '/*
    '|| 関数名：fSrchHTCTRL
    '|| 概要  ：SrchKeyを検索
    '*/
    Public Function fSrchHTCTRL(ByVal pstrSrchKey As String) As Integer
        Dim wstrKey(1), wstrKeyValue(1) As String
        Dim wintRet As Integer
        Dim wstrWhere As String
        fSrchHTCTRL = -1
        Try
            wstrKey(0) = "SearchKey"
            wstrKey(1) = "HTNumber"
            wstrKeyValue(0) = pstrSrchKey
            wstrKeyValue(1) = Space(8)

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

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

            Dim values As Dictionary(Of String, String) = New Dictionary(Of String, String)
            Dim sSearchKey As String = ""
            Dim i As Integer = 0

            If tmpStr.Count > 0 Then

                Do

                    values = tmpStr(i)

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

                    If RTrim(wstrKeyValue(0)) = RTrim(sSearchKey) Then
                        fSrchHTCTRL = 1
                        Exit Do


                    End If

                    i = i + 1

                    If tmpStr.Count = i Then
                        fSrchHTCTRL = 0
                        Exit Do
                    End If


                Loop



            End If



            'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_HTCTRL, G_CONST_KEY_HTCTRLKEY00, "HTCTRL01", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)

            'If wintRet = -1 Then
            '    Exit Function
            'ElseIf wintRet <> 0 Then
            '    fSrchHTCTRL = 0
            'Else
            '    Do

            '        With gclsDB.Records("HTCTRL01")
            '            If RTrim(wstrKeyValue(0)) = RTrim(.Item("SearchKey")) Then
            '                fSrchHTCTRL = 1
            '                Exit Do
            '            Else
            '                If .Read(BtLib.Operation.GetNext) <> 0 Then
            '                    fSrchHTCTRL = 0
            '                    Exit Do
            '                End If
            '            End If
            '        End With
            '    Loop
            'End If
            'gclsDB.fCloseRecord("HTCTRL01")
        Catch ex As Exception
            sErrLog(gAppName, "fSrchHTCTRL", ex.ToString)
        End Try
    End Function

End Module
