﻿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 Bt
Imports Bt.ScanLib
'Imports KDPL1000.BtScanLib
Imports BTClientLib
Imports System.IO
Imports System.Reflection
Imports Newtonsoft
Imports Microsoft.WindowsCE.Forms
Imports BtScan2

Public Class frm1070
    Inherits System.Windows.Forms.Form
    Private btScanLib As BtScanLib
    Private scanHandler As Boolean = False
    'Private dbClient As BtrieveDbClient
    Private tmpStr As List(Of Dictionary(Of String, String))
    Private affected_rows As Integer

#Region " Windows tH[€ fUCiลถฌณ๊ฝR[h "

    Public Sub New()
        MyBase.New()

        ' ฑฬฤัoตอ Windows tH[€ fUCiล•K—vลทB
        InitializeComponent()

        ' InitializeComponent() ฤัoตฬใษ๚ป๐’วมตทB

    End Sub

    ' Form อAR“|[l“g๊——ษใ—๐ภsท้ฝ฿ษ dispose ๐I[o[ChตทB
    'Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    '    If disposing Then
    '        If Not (components Is Nothing) Then
    '            components.Dispose()
    '        End If
    '    End If
    '    MyBase.Dispose(disposing)
    'End Sub

    ' Windows tH[€ fUCiล•K—vลทB
    'Private components As System.ComponentModel.IContainer

    '  : ศบฬvV[WอAWindows tH[€ fUCiล•K—vลทB
    'Windows tH[€ fUCi๐gมฤ•ฯXตฤญพณขB  
    ' R[h GfB^๐gมฤ•ฯXตศขลญพณขB
    'Friend WithEvents WarpFrame1 As WarpControl.WarpFrame
    'Friend WithEvents WarpBox1 As WarpControl.WarpBox
    'Friend WithEvents wfName As WarpControl.WarpField
    'Friend WithEvents WarpHWBcr1 As WarpControl.WarpHWBcr
    'Friend WithEvents wfPallete As WarpControl.WarpField
    'Friend WithEvents wfPC As WarpControl.WarpField
    'Friend WithEvents wfChk1 As WarpControl.WarpField
    'Friend WithEvents wfChk2 As WarpControl.WarpField
    'Friend WithEvents wfChk3 As WarpControl.WarpField
    'Friend WithEvents wfKey As WarpControl.WarpField
    'Friend WithEvents wfLine As WarpControl.WarpField
    'Friend WithEvents wfSeq As WarpControl.WarpField
    'Friend WithEvents wfCase As WarpControl.WarpField
    'Friend WithEvents wfLine2 As WarpControl.WarpField
    'Friend WithEvents WarpField1 As WarpControl.WarpField
    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame()
    '    Me.WarpField1 = New WarpControl.WarpField()
    '    Me.wfLine2 = New WarpControl.WarpField()
    '    Me.wfCase = New WarpControl.WarpField()
    '    Me.wfSeq = New WarpControl.WarpField()
    '    Me.wfLine = New WarpControl.WarpField()
    '    Me.wfChk3 = New WarpControl.WarpField()
    '    Me.wfChk2 = New WarpControl.WarpField()
    '    Me.wfChk1 = New WarpControl.WarpField()
    '    Me.wfPC = New WarpControl.WarpField()
    '    Me.wfPallete = New WarpControl.WarpField()
    '    Me.wfName = New WarpControl.WarpField()
    '    Me.WarpBox1 = New WarpControl.WarpBox()
    '    Me.wfKey = New WarpControl.WarpField()
    '    Me.WarpHWBcr1 = New WarpControl.WarpHWBcr()
    '    Me.WarpFrame1.SuspendLayout()
    '    Me.SuspendLayout()
    '
    'WarpFrame1
    '
    'Me.WarpFrame1.Controls.Add(Me.WarpField1)
    'Me.WarpFrame1.Controls.Add(Me.wfLine2)
    'Me.WarpFrame1.Controls.Add(Me.wfCase)
    'Me.WarpFrame1.Controls.Add(Me.wfSeq)
    'Me.WarpFrame1.Controls.Add(Me.wfLine)
    'Me.WarpFrame1.Controls.Add(Me.wfChk3)
    'Me.WarpFrame1.Controls.Add(Me.wfChk2)
    'Me.WarpFrame1.Controls.Add(Me.wfChk1)
    'Me.WarpFrame1.Controls.Add(Me.wfPC)
    'Me.WarpFrame1.Controls.Add(Me.wfPallete)
    'Me.WarpFrame1.Controls.Add(Me.wfName)
    'Me.WarpFrame1.Controls.Add(Me.WarpBox1)
    'Me.WarpFrame1.Controls.Add(Me.wfKey)
    'Me.WarpFrame1.Font = New System.Drawing.Font("MS UI Gothic", 9.0!)
    'Me.WarpFrame1.Location = New System.Drawing.Point(0, 0)
    'Me.WarpFrame1.Name = "WarpFrame1"
    'Me.WarpFrame1.Size = New System.Drawing.Size(240, 296)
    'Me.WarpFrame1.TabIndex = 1
    'Me.WarpFrame1.Text = "WarpFrame1"
    'Me.WarpFrame1.UseMacro = False
    'Me.WarpFrame1.UseMacroFileName = ""
    '
    'WarpField1
    '
    'Me.WarpField1.DecimalPointPosition = CType(0, Short)
    'Me.WarpField1.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.WarpField1.Format = ""
    'Me.WarpField1.Length = CType(1, Short)
    'Me.WarpField1.Location = New System.Drawing.Point(43, 0)
    'Me.WarpField1.MacroBcr = ""
    'Me.WarpField1.MacroIn = ""
    'Me.WarpField1.MacroKey = ""
    'Me.WarpField1.MacroOut = ""
    'Me.WarpField1.Name = "WarpField1"
    'Me.WarpField1.Size = New System.Drawing.Size(18, 36)
    'Me.WarpField1.TabIndex = CType(13, Short)
    'Me.WarpField1.Text = "-"
    '
    'wfLine2
    '
    'Me.wfLine2.DecimalPointPosition = CType(0, Short)
    'Me.wfLine2.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfLine2.Format = ""
    'Me.wfLine2.Length = CType(2, Short)
    'Me.wfLine2.Location = New System.Drawing.Point(69, 0)
    'Me.wfLine2.MacroBcr = ""
    'Me.wfLine2.MacroIn = ""
    'Me.wfLine2.MacroKey = ""
    'Me.wfLine2.MacroOut = ""
    'Me.wfLine2.Name = "wfLine2"
    'Me.wfLine2.Size = New System.Drawing.Size(36, 36)
    'Me.wfLine2.TabIndex = CType(12, Short)
    'Me.wfLine2.Text = "XX"
    '
    'wfCase
    '
    'Me.wfCase.DecimalPointPosition = CType(0, Short)
    'Me.wfCase.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfCase.FontSize = WarpControl.FontSizes.Small2
    'Me.wfCase.Format = ""
    'Me.wfCase.Length = CType(16, Short)
    'Me.wfCase.Location = New System.Drawing.Point(43, 103)
    'Me.wfCase.MacroBcr = ""
    'Me.wfCase.MacroIn = ""
    'Me.wfCase.MacroKey = ""
    'Me.wfCase.MacroOut = ""
    'Me.wfCase.Name = "wfCase"
    'Me.wfCase.Size = New System.Drawing.Size(192, 24)
    'Me.wfCase.TabIndex = CType(11, Short)
    'Me.wfCase.Text = "KD Card/Case Lbl"
    '
    'wfSeq
    '
    'Me.wfSeq.DecimalPointPosition = CType(0, Short)
    'Me.wfSeq.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfSeq.Format = ""
    'Me.wfSeq.InputMode.Right = True
    'Me.wfSeq.Length = CType(3, Short)
    'Me.wfSeq.Location = New System.Drawing.Point(139, 1)
    'Me.wfSeq.MacroBcr = ""
    'Me.wfSeq.MacroIn = ""
    'Me.wfSeq.MacroKey = ""
    'Me.wfSeq.MacroOut = ""
    'Me.wfSeq.Name = "wfSeq"
    'Me.wfSeq.Size = New System.Drawing.Size(54, 36)
    'Me.wfSeq.TabIndex = CType(10, Short)
    'Me.wfSeq.Text = "999"
    '
    'wfLine
    '
    'Me.wfLine.DecimalPointPosition = CType(0, Short)
    'Me.wfLine.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfLine.Format = ""
    'Me.wfLine.Length = CType(2, Short)
    'Me.wfLine.Location = New System.Drawing.Point(1, 1)
    'Me.wfLine.MacroBcr = ""
    'Me.wfLine.MacroIn = ""
    'Me.wfLine.MacroKey = ""
    'Me.wfLine.MacroOut = ""
    'Me.wfLine.Name = "wfLine"
    'Me.wfLine.Size = New System.Drawing.Size(36, 36)
    'Me.wfLine.TabIndex = CType(9, Short)
    'Me.wfLine.Text = "XX"
    '
    'wfChk3
    '
    'Me.wfChk3.DecimalPointPosition = CType(0, Short)
    'Me.wfChk3.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfChk3.Format = ""
    'Me.wfChk3.Length = CType(2, Short)
    'Me.wfChk3.Location = New System.Drawing.Point(0, 144)
    'Me.wfChk3.MacroBcr = ""
    'Me.wfChk3.MacroIn = ""
    'Me.wfChk3.MacroKey = ""
    'Me.wfChk3.MacroOut = ""
    'Me.wfChk3.Name = "wfChk3"
    'Me.wfChk3.Size = New System.Drawing.Size(36, 36)
    'Me.wfChk3.TabIndex = CType(7, Short)
    '
    'wfChk2
    '
    'Me.wfChk2.DecimalPointPosition = CType(0, Short)
    'Me.wfChk2.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfChk2.Format = ""
    'Me.wfChk2.Length = CType(2, Short)
    'Me.wfChk2.Location = New System.Drawing.Point(0, 99)
    'Me.wfChk2.MacroBcr = ""
    'Me.wfChk2.MacroIn = ""
    'Me.wfChk2.MacroKey = ""
    'Me.wfChk2.MacroOut = ""
    'Me.wfChk2.Name = "wfChk2"
    'Me.wfChk2.Size = New System.Drawing.Size(36, 36)
    'Me.wfChk2.TabIndex = CType(6, Short)
    '
    'wfChk1
    '
    'Me.wfChk1.DecimalPointPosition = CType(0, Short)
    'Me.wfChk1.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfChk1.Format = ""
    'Me.wfChk1.Length = CType(2, Short)
    'Me.wfChk1.Location = New System.Drawing.Point(0, 52)
    'Me.wfChk1.MacroBcr = ""
    'Me.wfChk1.MacroIn = ""
    'Me.wfChk1.MacroKey = ""
    'Me.wfChk1.MacroOut = ""
    'Me.wfChk1.Name = "wfChk1"
    'Me.wfChk1.Size = New System.Drawing.Size(36, 36)
    'Me.wfChk1.TabIndex = CType(5, Short)
    '
    'wfPC
    '
    'Me.wfPC.DecimalPointPosition = CType(0, Short)
    'Me.wfPC.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfPC.FontSize = WarpControl.FontSizes.Small
    'Me.wfPC.Format = ""
    'Me.wfPC.Length = CType(11, Short)
    'Me.wfPC.Location = New System.Drawing.Point(46, 148)
    'Me.wfPC.MacroBcr = ""
    'Me.wfPC.MacroIn = ""
    'Me.wfPC.MacroKey = ""
    'Me.wfPC.MacroOut = ""
    'Me.wfPC.Name = "wfPC"
    'Me.wfPC.Size = New System.Drawing.Size(165, 30)
    'Me.wfPC.TabIndex = CType(4, Short)
    'Me.wfPC.Text = "Part/Carton"
    '
    'wfPallete
    '
    'Me.wfPallete.DecimalPointPosition = CType(0, Short)
    'Me.wfPallete.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfPallete.FontSize = WarpControl.FontSizes.Small
    'Me.wfPallete.Format = ""
    'Me.wfPallete.Length = CType(7, Short)
    'Me.wfPallete.Location = New System.Drawing.Point(45, 55)
    'Me.wfPallete.MacroBcr = ""
    'Me.wfPallete.MacroIn = ""
    'Me.wfPallete.MacroKey = ""
    'Me.wfPallete.MacroOut = ""
    'Me.wfPallete.Name = "wfPallete"
    'Me.wfPallete.Size = New System.Drawing.Size(105, 30)
    'Me.wfPallete.TabIndex = CType(2, Short)
    'Me.wfPallete.Text = "Pallete"
    '
    'wfName
    '
    'Me.wfName.DecimalPointPosition = CType(0, Short)
    'Me.wfName.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfName.FontSize = WarpControl.FontSizes.Small2
    'Me.wfName.Format = ""
    'Me.wfName.Length = CType(20, Short)
    'Me.wfName.Location = New System.Drawing.Point(0, 216)
    'Me.wfName.MacroBcr = ""
    'Me.wfName.MacroIn = ""
    'Me.wfName.MacroKey = ""
    'Me.wfName.MacroOut = ""
    'Me.wfName.Name = "wfName"
    'Me.wfName.Size = New System.Drawing.Size(240, 24)
    'Me.wfName.TabIndex = CType(1, Short)
    '
    'WarpBox1
    '
    'Me.WarpBox1.BoxType = WarpControl.BoxTypes.Box
    'Me.WarpBox1.DrawMode = WarpControl.DrawModes.Paint
    'Me.WarpBox1.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.WarpBox1.ForeColor = CType(15, Short)
    'Me.WarpBox1.Image = "C:\H081-0005.jpg"
    'Me.WarpBox1.Location = New System.Drawing.Point(0, 192)
    'Me.WarpBox1.Name = "WarpBox1"
    'Me.WarpBox1.Size = New System.Drawing.Size(240, 24)
    'Me.WarpBox1.TabIndex = 0
    'Me.WarpBox1.Text = "Echo System"
    '
    'wfKey
    '
    'Me.wfKey.BcrFlag = True
    'Me.wfKey.DecimalPointPosition = CType(0, Short)
    'Me.wfKey.Font = New System.Drawing.Font("Lucida Console", 8.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfKey.FontSize = WarpControl.FontSizes.Small4
    'Me.wfKey.Format = ""
    'Me.wfKey.InputMode.Secret = True
    'Me.wfKey.Length = CType(1, Short)
    'Me.wfKey.Location = New System.Drawing.Point(216, 192)
    'Me.wfKey.MacroBcr = ""
    'Me.wfKey.MacroIn = ""
    'Me.wfKey.MacroKey = ""
    'Me.wfKey.MacroOut = ""
    'Me.wfKey.Name = "wfKey"
    'Me.wfKey.Size = New System.Drawing.Size(6, 12)
    'Me.wfKey.TabIndex = CType(8, Short)
    '
    'WarpHWBcr1
    '
    'Me.WarpHWBcr1.CheckCode.Code39 = True
    'Me.WarpHWBcr1.CheckCode.PostalCode = True
    'Me.WarpHWBcr1.Decode.Code39 = True
    'Me.WarpHWBcr1.DiscreteFirstLen = CType(0, Short)
    'Me.WarpHWBcr1.DiscreteSecondLen = CType(0, Short)
    'Me.WarpHWBcr1.InterleavedFirstLen = CType(0, Short)
    'Me.WarpHWBcr1.InterleavedSecondLen = CType(0, Short)
    '
    'frm1070
    '
    'Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
    'Me.ClientSize = New System.Drawing.Size(240, 296)
    'Me.Controls.Add(Me.WarpFrame1)
    'Me.Font = New System.Drawing.Font("MS UI Gothic", 9.0!)
    'Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
    'Me.Name = "frm1070"
    'Me.Text = "Form1"
    'Me.WarpFrame1.ResumeLayout(False)
    'Me.ResumeLayout(False)

    'End Sub

#End Region
    Public Enum M1070_STATUS As Integer
        INIT = 0
        NOTCD = 1
        DONE = 2
        CHKEND = 3
    End Enum

    Public mint1070status As Integer

    Private Sub frm1070_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Select Case e.KeyCode.ToString()
            Case "Return"
                Exit Sub
            Case "F1"
            Case "F2"
                gintStatus = PL_STATUS.QUIT
                Me.Close()
                Exit Sub
        End Select
    End Sub

    Private Sub frm1070_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        '// Case QVGA -> resolution to 1/2
        If System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width = 240 Then
            Call resolution.VGAtoQVGA(Me)
        End If

        Dim wstrImage As String
        Dim rtn As Integer

        Try
            mint1070status = M1070_STATUS.INIT

            't[€ฬI[v“
            'rtn = WarpFrame1.Open
            'If (rtn <> 0) Then
            '    Err.Raise(vbObjectError + 1, gAppName, "WarpError")
            'End If

#If Not Debug Then
            If gstrctKDPL.bNextDscnOnly Then
                'sSetImgFName(G_CONST_MID_H1075, WarpBox1)
                'KDนฐฝฬบ’i๐ฝทฌ
            Else
                'sSetImgFName(G_CONST_MID_H1070, WarpBox1)
            End If
#End If
            sDisp1070()
            ' tH[€EC“ ภs
            sMain()

            ' t[€ฬN[Y
            'rtn = WarpFrame1.Close()
            'If (rtn <> 0) Then
            '    Err.Raise(vbObjectError + 1, gAppName, "WarpError")
            'End If

            ' tH[€EN[Y
            'Me.Close()

            Exit Sub


        Catch ex As Exception

        End Try

    End Sub

    '/*
    '|| ึ”–ผFsDisp1070
    '|| T—v  F1070ๆ–ส•\ฆ
    '*/
    Private Sub sDisp1070()
        With gstrctAicCase
            'wfLine.Puts(.Line)
            'wfLine2.Puts(.KasoLine)
            'wfSeq.Puts(CInt(.PackSeq))

            wfLine.Text = .Line
            wfLine2.Text = .KasoLine
            wfSeq.Text = CInt(.PackSeq)

        End With
        'ๆ–ส•\ฆ•ถ—๑อ’่”’่`๐CommonษฤsมฤขทB
        sReversCheckedLBL(gstrctKDPL.intCheckFlag)
        Select Case gstrctKDPL.intCheckLbl
            Case 1
                'wfChk1.Puts(G_CONST_CHKARRW)

                wfChk1.Text = G_CONST_CHKARRW
            Case 2
                'wfChk2.Puts(G_CONST_CHKARRW)

                wfChk2.Text = G_CONST_CHKARRW
            Case 3
                'wfChk3.Puts(G_CONST_CHKARRW)

                wfChk3.Text = G_CONST_CHKARRW
            Case Else
                'wfChk1.Puts("")
                'wfChk2.Puts("")
                'wfChk3.Puts("")

                wfChk1.Text = ""
                wfChk2.Text = ""
                wfChk3.Text = ""
        End Select
        'wfName.Puts(gstrctKDHT.strUserName)

        wfName.Text = gstrctKDHT.strUserName

    End Sub

    Private Sub btScanLib_OnScan(ByVal result As String)
        Dim buf As String = result
        Dim rtn As Integer

        If Not (Mid(buf, 2, 1) = "A" AndAlso Mid(buf, 2).Length = 16) Then   'นฐฝือูษมชฏธรผฏฤ–ณต
            'มชฏธรจผฏฤ
            If (Not fCheckCode(buf)) Then
                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
#If Not Debug Then
                                    fFnc_WrpMsg("E", G_CONST_MID_E1E70)
#End If
                Exit Sub
            End If
        Else
            buf = Mid(buf, 2)
        End If

        '“—อ—
        rtn = fProcInput(RTrim(buf))

        If rtn = 0 Then
            Select Case mint1070status
                Case M1070_STATUS.INIT

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    gintStatus = PL_STATUS.PALETTESCN
                    Me.Close()
                    Exit Sub

                Case M1070_STATUS.NOTCD             '‘ฮสฐบฐฤศO๐ฝทฌ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    gintStatus = PL_STATUS.SUSPEND2
                    Me.Close()
                    Exit Sub

                Case M1070_STATUS.DONE              'ณํษQฦลซฝ

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    gintStatus = PL_STATUS.FINALCHK
                    Me.Close()
                    Exit Sub

                Case M1070_STATUS.CHKEND            'มชฏธฎ—น
                    If gstrctKDHT.bLinkFlag Then fClearJisseki() '“NtOษๆ่ภัํ

                    RemoveHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
                    btScanLib.Disable()

                    gintStatus = PL_STATUS.PALETTESCN
                    If fClearSKey() = -1 Then
                        'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
                        MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                    End If
                    Me.Close()
                    Exit Sub
            End Select

        Else

            'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
            MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

        End If


    End Sub

    ' t[€EC“
    Public Sub sMain()

        '        Dim WKey As Short
        '        Dim buf As String
        '        Dim rtn As Integer

        '        Try

        '            ' t[€ฬ—๐ฑฑษLqตทB
        '            Do While (True)

        '                ' R[h“—อ
        '                WKey = WarpFrame1.Input(wfKey)

        '                If WKey = WKY_ENT Then

        '                    'fSakusei2()

        '                ElseIf WKey = WKY_BCR Then

        '                    'สฐบฐฤ“—อฬๆ“พ
        '                    rtn = WarpHWBcr1.Get(buf)
        '                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.OK)
        '                    If (rtn <> 0) Then
        '                        Err.Raise(vbObjectError + 1, gAppName, "WarpError")
        '                    End If

        '                    If Not (Mid(buf, 2, 1) = "A" AndAlso Mid(buf, 2).Length = 16) Then   'นฐฝือูษมชฏธรผฏฤ–ณต
        '                        'มชฏธรจผฏฤ
        '                        If (Not fCheckCode(buf)) Then
        '                            sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '#If Not Debug Then
        '                            fFnc_WrpMsg("E", G_CONST_MID_E1E70)
        '#End If
        '                            Exit Do
        '                        End If
        '                    Else
        '                        buf = Mid(buf, 2)
        '                    End If

        '                    '“—อ—
        '                    rtn = fProcInput(RTrim(buf))

        '                    If rtn = 0 Then
        '                        Select Case mint1070status
        '                            Case M1070_STATUS.INIT
        '                                gintStatus = PL_STATUS.PALETTESCN

        '                            Case M1070_STATUS.NOTCD             '‘ฮสฐบฐฤศO๐ฝทฌ
        '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                                gintStatus = PL_STATUS.SUSPEND2
        '                                Exit Do

        '                            Case M1070_STATUS.DONE              'ณํษQฦลซฝ
        '                                gintStatus = PL_STATUS.FINALCHK
        '                                Exit Do

        '                            Case M1070_STATUS.CHKEND            'มชฏธฎ—น
        '                                If gstrctKDHT.bLinkFlag Then fClearJisseki() '“NtOษๆ่ภัํ
        '                                gintStatus = PL_STATUS.PALETTESCN
        '                                If fClearSKey() = -1 Then
        '                                    f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                                End If
        '                                Exit Do

        '                        End Select

        '                    Else

        '                        f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
        '                        Exit Do
        '                    End If

        '                ElseIf WKey = WKY_F1 Then


        '                ElseIf WKey = WKY_F2 Then


        '                ElseIf WKey = WKY_ERROR Then

        '                    f0.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, G_CONST_EM_WARP, MWA_DB_WARNING, MWA_DB_OK)

        '                End If

        '            Loop

        '            Exit Sub

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

    End Sub
    '/*
    '|| ึ”–ผFfProcInput
    '|| T—v  F“—อ—
    '*/
    Private Function fProcInput(ByVal pstrInput As String) As Integer
        Dim wstrctAicCase As STRCT_KEY_AICCASE
        Dim wintScnFlg As Integer
        Dim wstrKey(7), wstrKeyValue(7) As String
        Dim tmp As String
        Dim rtn As Integer
        Dim wintPartsFlag As Integer
        Dim bIsFreeChkFlg As Boolean = False  'KDนฐฝ๘ๆ่•[บ’i—ฬ๐ฬืธ
        fProcInput = -1

        Try

            If gstrctKDPL.bNextDscnOnly Then        'KDนฐฝ๘ๆ่•[บ’iฬ“วๆ่ย”\๓‘ิ
                If pstrInput.StartsWith("D") Then   'KDนฐฝ๘ๆ่•[บ’i—
                    If pstrInput.Length = 16 Then
                        sDecodeDLabel2CaseNo(gstrctKDPL.strCaseNoByKDlbl, pstrInput)
                        gstrctKDPL.intCheckLbl = 2
                        bIsFreeChkFlg = True
                        wintScnFlg = G_CONST_CASELBL
                        'wfChk1.Puts("")
                        'wfChk2.Puts(G_CONST_CHKARRW)
                        'wfChk3.Puts("")

                        wfChk1.Text = ""
                        wfChk2.Text = G_CONST_CHKARRW
                        wfChk3.Text = ""
                    Else
                        mint1070status = M1070_STATUS.NOTCD
                        fProcInput = 0
                        Exit Function
                    End If
                Else
                    mint1070status = M1070_STATUS.NOTCD
                    fProcInput = 0
                    Exit Function
                End If
            Else
                If pstrInput.StartsWith("A") Then
                    If pstrInput.Length = 31 Then 'ซ•๏‘ไ”ยือูฝทฌ
                        sDecodeScanData2AicCase(wstrctAicCase, pstrInput)
                        wintScnFlg = G_CONST_PLTLBL
                        gstrctKDPL.intCheckLbl = 1
                        'wfChk1.Puts(G_CONST_CHKARRW)
                        'wfChk2.Puts("")
                        'wfChk3.Puts("")
                        wfChk1.Text = G_CONST_CHKARRW
                        wfChk2.Text = ""
                        wfChk3.Text = ""
                    ElseIf pstrInput.Length = 16 OrElse pstrInput.Length = 21 Then
                        'นฐฝือูฝทฌ
                        sDecodeCaseLbl2MscCaseNo(wstrctAicCase, pstrInput)
                        gstrctKDPL.intCheckLbl = 2
                        wintScnFlg = G_CONST_CASELBL
                        'wfChk1.Puts("")
                        'wfChk2.Puts(G_CONST_CHKARRW)
                        'wfChk3.Puts("")
                        wfChk1.Text = ""
                        wfChk2.Text = G_CONST_CHKARRW
                        wfChk3.Text = ""
                    End If
                ElseIf pstrInput.StartsWith("K") Then 'KDP[X๘ๆ่•[ใ’i—
                    If pstrInput.Length = 18 Then
                        sDecodeKLabel2Msc(gstrctKDPL.strMscByKDlbl, pstrInput)
                        gstrctKDPL.bNextDscnOnly = True
                        bIsFreeChkFlg = False
                        gstrctKDPL.intCheckLbl = 2
                        wintScnFlg = G_CONST_CASELBL
                        'wfChk1.Puts("")
                        'wfChk2.Puts(G_CONST_CHKARRW)
                        'wfChk3.Puts("")
                        wfChk1.Text = ""
                        wfChk2.Text = G_CONST_CHKARRW
                        wfChk3.Text = ""
                    Else
                        mint1070status = M1070_STATUS.NOTCD
                        fProcInput = 0
                        Exit Function
                    End If

                ElseIf pstrInput.StartsWith("C") OrElse pstrInput.StartsWith("B") Then
                    'wfChk1.Puts("")
                    'wfChk2.Puts("")
                    'wfChk3.Puts(G_CONST_CHKARRW)
                    wfChk1.Text = ""
                    wfChk2.Text = ""
                    wfChk3.Text = G_CONST_CHKARRW
                    wstrctAicCase.AicCaseNo = Mid(pstrInput, 2, 20)
                    wintScnFlg = G_CONST_CPLBL
                    gstrctKDPL.intCheckLbl = 3
                ElseIf pstrInput.StartsWith("P") Then
                    If pstrInput.Length = 25 Then
                        wintPartsFlag = 1
                    ElseIf pstrInput.Length = 19 Then
                        wintPartsFlag = 2
                    Else
                        wintPartsFlag = -1
                        mint1070status = M1070_STATUS.NOTCD
                        fProcInput = 0
                        Exit Function
                    End If
                    'wfChk1.Puts("")
                    'wfChk2.Puts("")
                    'wfChk3.Puts(G_CONST_CHKARRW)
                    wfChk1.Text = ""
                    wfChk2.Text = ""
                    wfChk3.Text = G_CONST_CHKARRW
                    gstrctKDPL.intCheckLbl = 3
                    tmp = Mid(pstrInput, 1, 1) & fBackDispItem(Mid(pstrInput, 2, 10), True) & Mid(pstrInput, 12)
                    pstrInput = tmp

                    wstrKey(0) = "PaletteID"
                    wstrKey(1) = "ItemGr"
                    wstrKey(2) = "ItemInID"
                    wstrKey(3) = "ItemInCode"
                    wstrKey(4) = "ItemCode"
                    wstrKey(5) = "ItemID"
                    wstrKey(6) = "SerialNo"
                    wstrKey(7) = "TempSerial"
                    With gstrctAicCase
                        wstrKeyValue(0) = "A"
                        wstrKeyValue(1) = .AicCaseNo & .YYYYMMDD & Space(2)
                        wstrKeyValue(2) = "P"
                        wstrKeyValue(3) = Mid(pstrInput, 2, 13).PadRight(30)
                        wstrKeyValue(4) = .AicCaseNo & "00000" & Space(5)
                        wstrKeyValue(5) = "C"
                        If wintPartsFlag = 1 Then
                            wstrKeyValue(6) = Mid(pstrInput, 20, 6)
                        ElseIf wintPartsFlag = 2 Then
                            wstrKeyValue(6) = Space(6)
                        End If
                        wstrKeyValue(7) = Space(6)
                    End With
                    rtn = fSearchPackAJ(wstrKey, wstrKeyValue)
                    If rtn = 1 Then
                        wstrctAicCase.AicCaseNo = Mid(wstrKeyValue(1), 1, 20)
                        wintScnFlg = G_CONST_CPLBL
                    Else
                        mint1070status = M1070_STATUS.NOTCD
                        fProcInput = 0
                        Exit Function
                    End If
                Else
                    mint1070status = M1070_STATUS.NOTCD
                    fProcInput = 0
                    Exit Function
                End If
            End If
            'AicCaseNoล”ไrB’AตP[Xxฬ๊อMsc CaseNoล”ไr
            If gstrctAicCase.AicCaseNo = wstrctAicCase.AicCaseNo OrElse _
               (wintScnFlg = G_CONST_CASELBL AndAlso gstrctAicCase.Msc = wstrctAicCase.Msc AndAlso _
                Mid(gstrctAicCase.AicCaseNo, 14, 7) = wstrctAicCase.CaseNo) OrElse _
                (gstrctKDPL.bNextDscnOnly AndAlso bIsFreeChkFlg = False AndAlso wintScnFlg = G_CONST_CASELBL AndAlso _
                gstrctAicCase.Msc = gstrctKDPL.strMscByKDlbl) OrElse _
                (gstrctKDPL.bNextDscnOnly AndAlso bIsFreeChkFlg AndAlso wintScnFlg = G_CONST_CASELBL AndAlso _
                 gstrctAicCase.Msc = gstrctKDPL.strMscByKDlbl AndAlso Mid(gstrctAicCase.AicCaseNo, 14, 7) = gstrctKDPL.strCaseNoByKDlbl) Then
                Select Case wintScnFlg
                    Case G_CONST_PLTLBL

                        gstrctKDPL.intCheckFlag = gstrctKDPL.intCheckFlag Or G_CONST_PLTLBL

                    Case G_CONST_CASELBL

                        If bIsFreeChkFlg Then
                            gstrctKDPL.bNextDscnOnly = False 'KDนฐฝ๘ๆ่•[บ’i—ฬืธ๐
                        End If
                        gstrctKDPL.intCheckFlag = gstrctKDPL.intCheckFlag Or G_CONST_CASELBL

                    Case G_CONST_CPLBL

                        gstrctKDPL.intCheckFlag = gstrctKDPL.intCheckFlag Or G_CONST_CPLBL

                End Select

                sReversCheckedLBL(gstrctKDPL.intCheckFlag)

                If gstrctKDPL.intCheckFlag = G_CONST_ALLOK Then
                    If gstrctKDPL.bNextDscnOnly Then 'KDนฐฝ๘ๆ่•[บ’i“ว—ึ
                        mint1070status = M1070_STATUS.DONE
                    Else
                        With gstrctKDPL
                            .intCheckFlag = G_CONST_INIT
                            .intCheckLbl = 0
                            .bNextDscnOnly = False
                            .strMscByKDlbl = ""
                            .strCaseNoByKDlbl = ""
                        End With

                        mint1070status = M1070_STATUS.CHKEND
                    End If
                Else
                    mint1070status = M1070_STATUS.DONE
                End If
                fProcInput = 0
            Else
                mint1070status = M1070_STATUS.NOTCD
                fProcInput = 0
            End If

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

    '*******************************************************************************
    '* @”\     : นฐฝือูรบฐฤ—
    '* ๘”     : 1.AICCASE—pทฐ๎•๑\‘ข‘ฬ 2.ฝทฌรฐภ
    '* –฿่’l   : ศต
    '* ”๕l     : ศต
    '*******************************************************************************
    Private Sub sDecodeCaseLbl2MscCaseNo(ByRef pstrctAicCase As STRCT_KEY_AICCASE, ByVal pstrScnData As String)
        pstrctAicCase.Msc = Mid(pstrScnData, 2, 7)
        If pstrScnData.Length = 16 Then
            pstrctAicCase.CaseNo = Mid(pstrScnData, 10, 7)
        ElseIf pstrScnData.Length = 21 Then
            pstrctAicCase.CaseNo = Mid(pstrScnData, 15, 7)
        End If
    End Sub
    '*******************************************************************************
    '* @”\     : KDนฐฝ๘ๆ่ถฐฤใ’iรบฐฤ—
    '* ๘”     : 1.AICCASE—pทฐ๎•๑\‘ข‘ฬ 2.ฝทฌรฐภ
    '* –฿่’l   : ศต
    '* ”๕l     : ศต
    '*******************************************************************************
    Private Sub sDecodeKLabel2Msc(ByRef pstrMsc As String, ByVal pstrScnData As String)
        pstrMsc = Mid(pstrScnData, 6, 7)
    End Sub
    '*******************************************************************************
    '* @”\     : KDนฐฝ๘ๆ่ถฐฤบ’iรบฐฤ—
    '* ๘”     : 1.AICCASE—pทฐ๎•๑\‘ข‘ฬ 2.ฝทฌรฐภ
    '* –฿่’l   : ศต
    '* ”๕l     : ศต
    '*******************************************************************************
    Private Sub sDecodeDLabel2CaseNo(ByRef pstrAicCase As String, ByVal pstrScnData As String)
        pstrAicCase = Mid(pstrScnData, 2, 7)
    End Sub
    '*******************************************************************************
    '* @”\     : ฝทฌฯือูฬ”ฝ“]•\ฆ
    '* ๘”     : ฝทฌณ๊ฝือู
    '* –฿่’l   : ศต
    '* ”๕l     : ศต
    '*******************************************************************************
    Private Sub sReversCheckedLBL(ByVal intChkFlg As Integer)
        Dim arryAtrb() As Integer = {G_CONST_PLTLBL, G_CONST_CASELBL, G_CONST_CPLBL} 'ฝทฌ‘ฮ•จ’่`
        Dim i As Integer
        Dim wintMaxCnt As Integer

        'ๆ–ส•\ฆ•ถ—๑อ’่`๐CommonษฤsมฤขทB
        If intChkFlg = G_CONST_INIT Then
            'wfPallete.SetAtr(MWA_ATR_NOM, MWA_ATR_NOM)
            'wfPallete.Puts(G_CONST_PALETTE)
            'wfCase.SetAtr(MWA_ATR_NOM, MWA_ATR_NOM)
            'wfCase.Puts(G_CONST_CASE)
            'wfPC.SetAtr(MWA_ATR_NOM, MWA_ATR_NOM)
            'wfPC.Puts(G_CONST_PCLBL)

            wfPallete.Text = G_CONST_PALETTE
            wfCase.Text = G_CONST_CASE
            wfPC.Text = G_CONST_PCLBL
            Exit Sub
        End If
        'ฝทฌ‘ฮ—v‘f”•ชมชฏธ
        wintMaxCnt = arryAtrb.Length - 1
        For i = 0 To wintMaxCnt
            Select Case (intChkFlg And arryAtrb(i))
                Case G_CONST_PLTLBL
                    'wfPallete.SetAtr(MWA_ATR_REV, MWA_ATR_REV)
                    'wfPallete.Puts(G_CONST_PALETTE)
                    wfPallete.Text = G_CONST_PALETTE
                Case G_CONST_CASELBL
                    'wfCase.SetAtr(MWA_ATR_REV, MWA_ATR_REV)
                    'wfCase.Puts(G_CONST_CASE)
                    wfCase.Text = G_CONST_CASE
                Case G_CONST_CPLBL
                    'wfPC.SetAtr(MWA_ATR_REV, MWA_ATR_REV)
                    'wfPC.Puts(G_CONST_PCLBL)
                    wfPC.Text = G_CONST_PCLBL
            End Select
        Next
    End Sub

    Private Sub frm1070_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        ' Enable BTScanLib
        If Not scanHandler Then
            btScanLib = btScanLib.getInstance()
            AddHandler btScanLib.OnScan, AddressOf btScanLib_OnScan
            scanHandler = True
            btScanLib.Debug = False
            btScanLib.Enable()
        End If
    End Sub
End Class
