﻿Imports System
Imports System.Linq
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports Microsoft.WindowsCE.Forms
Imports System.Runtime.InteropServices
Imports Bt
Imports Bt.ScanLib
'Imports KDPA4000.BtScanLib
Imports BTClientLib
Imports System.IO
Imports System.Reflection
Imports Newtonsoft
Imports BtScan2

Public Class frm4015
    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 WarpCtrl1 As WarpControl.WarpCtrl
    'Friend WithEvents WarpHWBcr1 As WarpControl.WarpHWBcr
    'Friend WithEvents WarpBox1 As WarpControl.WarpBox
    'Friend WithEvents wfKey As WarpControl.WarpField
    'Friend WithEvents WarpFrame1 As WarpControl.WarpFrame
    'Friend WithEvents WarpField3 As WarpControl.WarpField
    'Friend WithEvents WarpField5 As WarpControl.WarpField
    'Friend WithEvents WarpField7 As WarpControl.WarpField
    'Friend WithEvents WarpField8 As WarpControl.WarpField
    'Friend WithEvents WarpField11 As WarpControl.WarpField
    'Friend WithEvents wfName As WarpControl.WarpField
    'Friend WithEvents wfLocation As WarpControl.WarpField
    'Friend WithEvents wfPart As WarpControl.WarpField
    'Friend WithEvents wfCL As WarpControl.WarpField
    'Friend WithEvents wfZnc As WarpControl.WarpField
    'Friend WithEvents wfPut As WarpControl.WarpField

    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame()
    '    Me.wfPut = New WarpControl.WarpField()
    '    Me.WarpField11 = New WarpControl.WarpField()
    '    Me.wfZnc = New WarpControl.WarpField()
    '    Me.wfCL = New WarpControl.WarpField()
    '    Me.WarpField8 = New WarpControl.WarpField()
    '    Me.WarpField7 = New WarpControl.WarpField()
    '    Me.wfPart = New WarpControl.WarpField()
    '    Me.WarpField5 = New WarpControl.WarpField()
    '    Me.wfLocation = New WarpControl.WarpField()
    '    Me.WarpField3 = New WarpControl.WarpField()
    '    Me.wfKey = New WarpControl.WarpField()
    '    Me.WarpBox1 = New WarpControl.WarpBox()
    '    Me.wfName = New WarpControl.WarpField()
    '    Me.WarpHWBcr1 = New WarpControl.WarpHWBcr()
    '    Me.WarpFrame1.SuspendLayout()
    '    Me.SuspendLayout()
    '    '
    '    'WarpFrame1
    '    '
    '    Me.WarpFrame1.Controls.Add(Me.wfPut)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField11)
    '    Me.WarpFrame1.Controls.Add(Me.wfZnc)
    '    Me.WarpFrame1.Controls.Add(Me.wfCL)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField8)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField7)
    '    Me.WarpFrame1.Controls.Add(Me.wfPart)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField5)
    '    Me.WarpFrame1.Controls.Add(Me.wfLocation)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField3)
    '    Me.WarpFrame1.Controls.Add(Me.wfKey)
    '    Me.WarpFrame1.Controls.Add(Me.WarpBox1)
    '    Me.WarpFrame1.Controls.Add(Me.wfName)
    '    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 = ""
    '    '
    '    'wfPut
    '    '
    '    Me.wfPut.DecimalPointPosition = CType(0, Short)
    '    Me.wfPut.DisplayAttribute.Bold = True
    '    Me.wfPut.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfPut.Format = ""
    '    Me.wfPut.Length = CType(5, Short)
    '    Me.wfPut.Location = New System.Drawing.Point(144, 156)
    '    Me.wfPut.MacroBcr = ""
    '    Me.wfPut.MacroIn = ""
    '    Me.wfPut.MacroKey = ""
    '    Me.wfPut.MacroOut = ""
    '    Me.wfPut.Name = "wfPut"
    '    Me.wfPut.Size = New System.Drawing.Size(90, 36)
    '    Me.wfPut.TabIndex = CType(14, Short)
    '    Me.wfPut.Text = "ZZZZ9"
    '    '
    '    'WarpField11
    '    '
    '    Me.WarpField11.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField11.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField11.FontSize = WarpControl.FontSizes.Small
    '    Me.WarpField11.Format = ""
    '    Me.WarpField11.Length = CType(8, Short)
    '    Me.WarpField11.Location = New System.Drawing.Point(0, 156)
    '    Me.WarpField11.MacroBcr = ""
    '    Me.WarpField11.MacroIn = ""
    '    Me.WarpField11.MacroKey = ""
    '    Me.WarpField11.MacroOut = ""
    '    Me.WarpField11.Name = "WarpField11"
    '    Me.WarpField11.Size = New System.Drawing.Size(120, 30)
    '    Me.WarpField11.TabIndex = CType(13, Short)
    '    Me.WarpField11.Text = "Put away"
    '    '
    '    'wfZnc
    '    '
    '    Me.wfZnc.DecimalPointPosition = CType(0, Short)
    '    Me.wfZnc.DisplayAttribute.Bold = True
    '    Me.wfZnc.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfZnc.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfZnc.Format = ""
    '    Me.wfZnc.InputAttribute.Bold = True
    '    Me.wfZnc.Length = CType(1, Short)
    '    Me.wfZnc.Location = New System.Drawing.Point(204, 117)
    '    Me.wfZnc.MacroBcr = ""
    '    Me.wfZnc.MacroIn = ""
    '    Me.wfZnc.MacroKey = ""
    '    Me.wfZnc.MacroOut = ""
    '    Me.wfZnc.Name = "wfZnc"
    '    Me.wfZnc.Size = New System.Drawing.Size(12, 24)
    '    Me.wfZnc.TabIndex = CType(12, Short)
    '    Me.wfZnc.Text = "X"
    '    '
    '    'wfCL
    '    '
    '    Me.wfCL.DecimalPointPosition = CType(0, Short)
    '    Me.wfCL.DisplayAttribute.Bold = True
    '    Me.wfCL.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfCL.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfCL.Format = ""
    '    Me.wfCL.InputAttribute.Bold = True
    '    Me.wfCL.Length = CType(2, Short)
    '    Me.wfCL.Location = New System.Drawing.Point(156, 117)
    '    Me.wfCL.MacroBcr = ""
    '    Me.wfCL.MacroIn = ""
    '    Me.wfCL.MacroKey = ""
    '    Me.wfCL.MacroOut = ""
    '    Me.wfCL.Name = "wfCL"
    '    Me.wfCL.Size = New System.Drawing.Size(24, 24)
    '    Me.wfCL.TabIndex = CType(11, Short)
    '    Me.wfCL.Text = "XX"
    '    '
    '    'WarpField8
    '    '
    '    Me.WarpField8.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField8.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField8.FontSize = WarpControl.FontSizes.Small
    '    Me.WarpField8.Format = ""
    '    Me.WarpField8.Length = CType(3, Short)
    '    Me.WarpField8.Location = New System.Drawing.Point(192, 84)
    '    Me.WarpField8.MacroBcr = ""
    '    Me.WarpField8.MacroIn = ""
    '    Me.WarpField8.MacroKey = ""
    '    Me.WarpField8.MacroOut = ""
    '    Me.WarpField8.Name = "WarpField8"
    '    Me.WarpField8.Size = New System.Drawing.Size(45, 30)
    '    Me.WarpField8.TabIndex = CType(10, Short)
    '    Me.WarpField8.Text = "Znc"
    '    '
    '    'WarpField7
    '    '
    '    Me.WarpField7.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField7.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField7.FontSize = WarpControl.FontSizes.Small
    '    Me.WarpField7.Format = ""
    '    Me.WarpField7.Length = CType(2, Short)
    '    Me.WarpField7.Location = New System.Drawing.Point(156, 84)
    '    Me.WarpField7.MacroBcr = ""
    '    Me.WarpField7.MacroIn = ""
    '    Me.WarpField7.MacroKey = ""
    '    Me.WarpField7.MacroOut = ""
    '    Me.WarpField7.Name = "WarpField7"
    '    Me.WarpField7.Size = New System.Drawing.Size(30, 30)
    '    Me.WarpField7.TabIndex = CType(9, Short)
    '    Me.WarpField7.Text = "CL"
    '    '
    '    'wfPart
    '    '
    '    Me.wfPart.DecimalPointPosition = CType(0, Short)
    '    Me.wfPart.DisplayAttribute.Bold = True
    '    Me.wfPart.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfPart.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfPart.Format = ""
    '    Me.wfPart.InputAttribute.Bold = True
    '    Me.wfPart.InputMode.Clear = True
    '    Me.wfPart.Length = CType(12, Short)
    '    Me.wfPart.Location = New System.Drawing.Point(0, 117)
    '    Me.wfPart.MacroBcr = ""
    '    Me.wfPart.MacroIn = ""
    '    Me.wfPart.MacroKey = ""
    '    Me.wfPart.MacroOut = ""
    '    Me.wfPart.Name = "wfPart"
    '    Me.wfPart.Size = New System.Drawing.Size(144, 24)
    '    Me.wfPart.TabIndex = CType(8, Short)
    '    Me.wfPart.Text = "XXXX-XX-XXXX"
    '    '
    '    'WarpField5
    '    '
    '    Me.WarpField5.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField5.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField5.FontSize = WarpControl.FontSizes.Small
    '    Me.WarpField5.Format = ""
    '    Me.WarpField5.Length = CType(7, Short)
    '    Me.WarpField5.Location = New System.Drawing.Point(0, 84)
    '    Me.WarpField5.MacroBcr = ""
    '    Me.WarpField5.MacroIn = ""
    '    Me.WarpField5.MacroKey = ""
    '    Me.WarpField5.MacroOut = ""
    '    Me.WarpField5.Name = "WarpField5"
    '    Me.WarpField5.Size = New System.Drawing.Size(105, 30)
    '    Me.WarpField5.TabIndex = CType(7, Short)
    '    Me.WarpField5.Text = "Part-No"
    '    '
    '    'wfLocation
    '    '
    '    Me.wfLocation.DecimalPointPosition = CType(0, Short)
    '    Me.wfLocation.DisplayAttribute.Bold = True
    '    Me.wfLocation.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfLocation.Format = ""
    '    Me.wfLocation.Length = CType(8, Short)
    '    Me.wfLocation.Location = New System.Drawing.Point(24, 39)
    '    Me.wfLocation.MacroBcr = ""
    '    Me.wfLocation.MacroIn = ""
    '    Me.wfLocation.MacroKey = ""
    '    Me.wfLocation.MacroOut = ""
    '    Me.wfLocation.Name = "wfLocation"
    '    Me.wfLocation.Size = New System.Drawing.Size(144, 36)
    '    Me.wfLocation.TabIndex = CType(6, Short)
    '    Me.wfLocation.Text = "X - XXXX"
    '    '
    '    'WarpField3
    '    '
    '    Me.WarpField3.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField3.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField3.FontSize = WarpControl.FontSizes.Small
    '    Me.WarpField3.Format = ""
    '    Me.WarpField3.Length = CType(8, Short)
    '    Me.WarpField3.Location = New System.Drawing.Point(0, 0)
    '    Me.WarpField3.MacroBcr = ""
    '    Me.WarpField3.MacroIn = ""
    '    Me.WarpField3.MacroKey = ""
    '    Me.WarpField3.MacroOut = ""
    '    Me.WarpField3.Name = "WarpField3"
    '    Me.WarpField3.Size = New System.Drawing.Size(120, 30)
    '    Me.WarpField3.TabIndex = CType(5, Short)
    '    Me.WarpField3.Text = "Location"
    '    '
    '    'wfKey
    '    '
    '    Me.wfKey.BcrFlag = True
    '    Me.wfKey.DecimalPointPosition = CType(0, Short)
    '    Me.wfKey.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfKey.Format = ""
    '    Me.wfKey.InputMode.Secret = True
    '    Me.wfKey.Length = CType(1, Short)
    '    Me.wfKey.Location = New System.Drawing.Point(216, 13)
    '    Me.wfKey.MacroBcr = ""
    '    Me.wfKey.MacroIn = ""
    '    Me.wfKey.MacroKey = ""
    '    Me.wfKey.MacroOut = ""
    '    Me.wfKey.Name = "wfKey"
    '    Me.wfKey.Size = New System.Drawing.Size(18, 36)
    '    Me.wfKey.TabIndex = CType(4, 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-0015.jpg"
    '    Me.WarpBox1.Location = New System.Drawing.Point(0, 208)
    '    Me.WarpBox1.Name = "WarpBox1"
    '    Me.WarpBox1.Size = New System.Drawing.Size(240, 25)
    '    Me.WarpBox1.TabIndex = 3
    '    '
    '    '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, 234)
    '    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(2, Short)
    '    '
    '    'WarpHWBcr1
    '    '
    '    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)
    '    '
    '    'frm4015
    '    '
    '    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 = "frm4015"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region

    Public Enum M4015_STATUS As Integer
        INIT = 0
        CANCEL = 1
        MENUBACK = 2
        NA = 3
        LOCMATCHED = 4
        LOCUNMATCHED = 5
        SECOND = 6
        NOTEXIST = 7
        DONE = 8
    End Enum

    Public mint4015status As Integer

    Public mintCnt As Integer
    Private gstrScanItem() As String

    Public mhtScanPart As New Hashtable

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

    Private Sub frm4015_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

            mint4015status = M4015_STATUS.INIT
            mintCnt = 0
            mhtScanPart.Clear()
            Erase gstrScanItem

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

#If Not Debug Then
            'sSetImgFName(G_CONST_MID_H4015, WarpBox1)
#End If

            sDisp4015()

            ' 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
            gintStatus = FREE_STATUS.QUIT
            sErrLog(gAppName, "frm4015_Load", ex.ToString)
            Me.Close()
        End Try

    End Sub

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

        If (Not fCheckCode(buf)) Then
            sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
#If Not Debug Then
                        fFnc_WrpMsg("E", G_CONST_MID_E4E50)
#End If
            rtn = 0
            mint4015status = M4015_STATUS.INIT
        Else

            '“—อ—
            rtn = fProcInput(buf)
        End If

        If rtn = 0 Then
            Select Case mint4015status
                Case M4015_STATUS.INIT



                Case M4015_STATUS.CANCEL            'ทฌพู

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

                    gintStatus = FREE_STATUS.LOCATION
                    Me.Close()
                    Exit Sub
                    'BtLib.Transaction.Abort()

                Case M4015_STATUS.NA                'T,P,ZศOศฬลดืฐาฏพฐผ
                    'sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    sOutputLog(gstrctPicsIni.strOutput_KDPA, "KDPA4E50", G_CONST_BC_PART, buf)
#If Not Debug Then
                                fFnc_WrpMsg("E", G_CONST_MID_E4E50)
#End If
                Case M4015_STATUS.LOCMATCHED        '

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

                    'BtLib.Transaction.End()
                    gintStatus = FREE_STATUS.LOCATION
                    Me.Close()
                    Exit Sub

                Case M4015_STATUS.LOCUNMATCHED      '
                    'sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    sOutputLog(gstrctPicsIni.strOutput_KDPA, "KDPA4E40", gstrctP4000.strLctnStart, gstrctP4000.strLctnM)
#If Not Debug Then
                                fFnc_WrpMsg("E", G_CONST_MID_E4E40)
#End If
                Case M4015_STATUS.SECOND
                    'sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
#If Not Debug Then
                                fFnc_WrpMsg("E", G_CONST_MID_E4E42)
#End If

                Case M4015_STATUS.NOTEXIST          '
                    'sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
#If Not Debug Then
                                fFnc_WrpMsg("E", G_CONST_MID_E4E33)
#End If

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

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

                    sUpdateScreen(buf)

            End Select

        Else
            'BtLib.Transaction.Abort()
            'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, 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

        '            'BtLib.Transaction.BeginConCurrent()

        '            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 fCheckCode(buf)) Then
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '#If Not Debug Then
        '                        fFnc_WrpMsg("E", G_CONST_MID_E4E50)
        '#End If
        '                        rtn = 0
        '                        mint4015status = M4015_STATUS.INIT
        '                    Else

        '                        '“—อ—
        '                        rtn = fProcInput(buf)
        '                    End If

        '                    If rtn = 0 Then
        '                        Select Case mint4015status
        '                            Case M4015_STATUS.INIT



        '                            Case M4015_STATUS.CANCEL            'ทฌพู

        '                                gintStatus = FREE_STATUS.LOCATION
        '                                'BtLib.Transaction.Abort()
        '                                Exit Do

        '                            Case M4015_STATUS.NA                'T,P,ZศOศฬลดืฐาฏพฐผ
        '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                                sOutputLog(gstrctPicsIni.strOutput_KDPA, "KDPA4E50", G_CONST_BC_PART, buf)
        '#If Not Debug Then
        '                                fFnc_WrpMsg("E", G_CONST_MID_E4E50)
        '#End If
        '                            Case M4015_STATUS.LOCMATCHED        '

        '                                'BtLib.Transaction.End()
        '                                gintStatus = FREE_STATUS.LOCATION
        '                                Exit Do

        '                            Case M4015_STATUS.LOCUNMATCHED      '
        '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                                sOutputLog(gstrctPicsIni.strOutput_KDPA, "KDPA4E40", gstrctP4000.strLctnStart, gstrctP4000.strLctnM)
        '#If Not Debug Then
        '                                fFnc_WrpMsg("E", G_CONST_MID_E4E40)
        '#End If
        '                            Case M4015_STATUS.SECOND
        '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '#If Not Debug Then
        '                                fFnc_WrpMsg("E", G_CONST_MID_E4E42)
        '#End If

        '                            Case M4015_STATUS.NOTEXIST          '
        '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '#If Not Debug Then
        '                                fFnc_WrpMsg("E", G_CONST_MID_E4E33)
        '#End If

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

        '                                sUpdateScreen(buf)

        '                        End Select

        '                    Else
        '                        'BtLib.Transaction.Abort()
        '                        f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, 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
        '            'gintStatus = FREE_STATUS.QUIT
        '            sErrLog(gAppName, "sMain", ex.ToString)
        '        End Try

    End Sub

    '/*
    '|| ึ”–ผFsDisp4015
    '|| T—v  F4015ๆ–ส•\ฆ
    '*/
    Private Sub sDisp4015()

        'wfPart.Clr()
        'wfCL.Clr()
        'wfZnc.Clr()
        'wfPut.Puts(mintCnt)
        'wfName.Puts(gstrctKDHT.strUserName)
        'wfLocation.Puts(fstrDivision(2, gstrctP4000.strLctnStart))

        wfPart.Text = ""
        wfCL.Text = ""
        wfZnc.Text = ""
        wfPut.Text = mintCnt
        wfName.Text = gstrctKDHT.strUserName
        wfLocation.Text = fstrDivision(2, gstrctP4000.strLctnStart)

    End Sub

    '/*
    '|| ึ”–ผFsUpdateScreen
    '|| T—v  F4015ๆ–ส•\ฆ
    '*/
    Private Sub sUpdateScreen(ByVal buf As String)

        'wfPut.Puts(mintCnt)
        'wfPart.Puts(fstrDivision(7, fstrDivision(4, Mid(buf, 2, 10))))
        'wfCL.Puts(Mid(buf, 12, 2))
        'wfZnc.Puts(Mid(buf, 14, 1))

        wfPut.Text = mintCnt
        wfPart.Text = fstrDivision(7, fstrDivision(4, Mid(buf, 2, 10)))
        wfCL.Text = Mid(buf, 12, 2)
        wfZnc.Text = Mid(buf, 14, 1)

    End Sub

    '/*
    '|| ึ”–ผFfProcInput
    '|| T—v  F“—อ—
    '*/
    Private Function fProcInput(ByVal pstrInput As String) As Integer

        Dim rtn As Integer
        Dim wintRet As Integer
        Dim wstrKey(7) As String
        Dim wstrKeyValue(7) As String
        Dim wstrItemID As String
        Dim wstrItemCode As String
        Dim wstrSerialNo As String
        Dim tmp As String '•\ฆ—pบฐฤ๐“เ•”บฐฤษ•ฯท
        Dim i As Integer
        Dim wstrWhere As String

        fProcInput = -1

        Try

            If RTrim(pstrInput) = "OCCANCEL" Then             'OCCANCELศ็ฮ

                mint4015status = M4015_STATUS.CANCEL
                fProcInput = 0
                Exit Function

            ElseIf pstrInput.StartsWith("T") Then        'ๆ“ชชTศ็ฮ

                gstrctP4000.strLctnM = Mid(pstrInput, 5)
                If gstrctP4000.strLctnStart = Mid(pstrInput, 5) Then                    '9…ศOศ็ฮ

                    '0ศ็Iํ้
                    If mintCnt = 0 Then
                        mint4015status = M4015_STATUS.LOCMATCHED
                        fProcInput = 0
                        Exit Function
                    End If

                    'XV—

                    'BtLib.Transaction.BeginConCurrent()

                    i = 0
                    Do
                        If i > mintCnt - 1 Then
                            Exit Do
                        End If

                        rtn = fUpdateStock(gstrScanItem(i))

                        If (rtn = -1) Then
                            'BtLib.Transaction.Abort()
                            Exit Function
                        ElseIf (rtn = -2) Then
                            'BtLib.Transaction.Abort()
                            fProcInput = 0
                            Exit Function
                        End If

                        i += 1
                    Loop

                    'BtLib.Transaction.End()

                    mint4015status = M4015_STATUS.LOCMATCHED
                    fProcInput = 0
                    Exit Function
                Else
                    mint4015status = M4015_STATUS.LOCUNMATCHED
                    fProcInput = 0
                    Exit Function
                End If
                '>>> DEL 2006.04.22 ST >>> 
                'ElseIf pstrInput.StartsWith("P") Or pstrInput.StartsWith("Z") Then        'ๆ“ชชP,Zศ็ฮ

                '    If mhtScanPart.Item(pstrInput) Then
                '        mint4015status = M4015_STATUS.SECOND
                '        fProcInput = 0
                '        Exit Function
                '    ElseIf pstrInput.Length() = G_CONST_LLEN_PRT1 Then
                '        wstrSerialNo = "999998"
                '    ElseIf pstrInput.Length() = G_CONST_LLEN_PRT2 Then
                '        wstrSerialNo = Mid(pstrInput, 20)
                '    Else
                '        mint4015status = M4015_STATUS.NA
                '        fProcInput = 0
                '        Exit Function
                '    End If

                '    'wstrItemID = Mid(pstrInput, 1, 1)
                '    'wstrItemCode = Mid(pstrInput, 2, 13)

                '    '2005/03/07@•\ฆ—pบฐฤ๐“เ•”บฐฤษ•ฯท
                '    wstrItemID = Mid(pstrInput, 1, 1)
                '    tmp = Mid(pstrInput, 2, 13)
                '    wstrItemCode = fBackDispItem(tmp, True)
                '<<< DEL 2006.04.22 END <<<
                '>>> ADD 2006.04.22 ST >>>
            ElseIf pstrInput.StartsWith("Z") Then         'ๆ“ชชP,Zศ็ฮ

                If mhtScanPart.Item(pstrInput) Then
                    mint4015status = M4015_STATUS.SECOND
                    fProcInput = 0
                    Exit Function
                ElseIf pstrInput.Length() = G_CONST_LLEN_PRT1 Then
                    wstrSerialNo = "999998"
                ElseIf pstrInput.Length() = G_CONST_LLEN_PRT2 Then
                    wstrSerialNo = Mid(pstrInput, 20)
                Else
                    mint4015status = M4015_STATUS.NA
                    fProcInput = 0
                    Exit Function
                End If

                'wstrItemID = Mid(pstrInput, 1, 1)
                'wstrItemCode = Mid(pstrInput, 2, 13)

                '2005/03/07@•\ฆ—pบฐฤ๐“เ•”บฐฤษ•ฯท
                wstrItemID = Mid(pstrInput, 1, 1)
                tmp = Mid(pstrInput, 2, 13)
                wstrItemCode = fBackDispItem(tmp, True)
                '>>> ADD 2006.04.22 END >>>
            Else

                mint4015status = M4015_STATUS.NA
                fProcInput = 0
                Exit Function

            End If

            '๕๐Jnตท
            wstrKey(0) = "PicsType"
            wstrKey(1) = "Cstmid"
            wstrKey(2) = "CstmCode"
            wstrKey(3) = "CenterCode"
            wstrKey(4) = "Bhk"
            wstrKey(5) = "Itemid"
            wstrKey(6) = "ItemCode"
            wstrKey(7) = "SerialNo"
            wstrKeyValue(0) = gstrctKDHT.strPackType
            wstrKeyValue(1) = gstrctKDHT.strCstmid
            wstrKeyValue(2) = gstrctKDHT.strCstmCode
            wstrKeyValue(3) = gstrctP4000.strCenterCode
            wstrKeyValue(4) = gstrctP4000.strBhk
            wstrKeyValue(5) = wstrItemID
            wstrKeyValue(6) = wstrItemCode
            wstrKeyValue(7) = wstrSerialNo

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


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

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

            If tmpStr.Count > 0 Then

                values = tmpStr(0)

                Dim result As String = Nothing
                Dim sPicsType As String = Nothing
                Dim sCstmid As String = Nothing
                Dim sCstmCode As String = Nothing
                Dim sCenterCode As String = Nothing
                Dim sBhk As String = Nothing
                Dim sLocation As String = Nothing
                Dim sItemid As String = Nothing
                Dim sItemCode As String = Nothing
                Dim sZaikoStatus As String = Nothing
                Dim sSerialNo 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("Bhk", result) Then
                    sBhk = RTrim(result)
                End If
                If values.TryGetValue("Location", result) Then
                    sLocation = 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("ZaikoStatus", result) Then
                    sZaikoStatus = RTrim(result)
                End If
                If values.TryGetValue("SerialNo", result) Then
                    sSerialNo = RTrim(result)
                End If

                If (RTrim(gstrctKDHT.strPackType) = RTrim(sPicsType) And _
                        RTrim(gstrctKDHT.strCstmid) = RTrim(sCstmid) And _
                        RTrim(gstrctKDHT.strCstmCode) = RTrim(sCstmCode) And _
                        RTrim(gstrctP4000.strCenterCode) = RTrim(sCenterCode) And _
                        RTrim(gstrctP4000.strBhk) = RTrim(sBhk) And _
                        RTrim(wstrItemID) = RTrim(sItemid) And _
                        RTrim(wstrItemCode) = RTrim(sItemCode) And _
                        RTrim(wstrSerialNo) = RTrim(sSerialNo)) Then

                Else

                    mint4015status = M4015_STATUS.NOTEXIST
                    fProcInput = 0
                    Exit Function

                End If

            Else

                mint4015status = M4015_STATUS.NOTEXIST
                fProcInput = 0
                Exit Function


            End If

            mintCnt += 1

            ReDim Preserve gstrScanItem(mintCnt - 1)
            gstrScanItem(mintCnt - 1) = pstrInput

            mhtScanPart.Add(pstrInput, True)
            mint4015status = M4015_STATUS.DONE

            fProcInput = 0


        Catch ex As Exception
            'gintStatus = FREE_STATUS.QUIT
            sErrLog(gAppName, "fProcInput", ex.ToString)

        End Try




        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, "STOCK1", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)

        'If wintRet = 0 Then

        '    With gclsDB.Records("STOCK1")
        '        If (RTrim(gstrctKDHT.strPackType) = RTrim(.Item("PicsType")) And _
        '            RTrim(gstrctKDHT.strCstmid) = RTrim(.Item("Cstmid")) And _
        '            RTrim(gstrctKDHT.strCstmCode) = RTrim(.Item("CstmCode")) And _
        '            RTrim(gstrctP4000.strCenterCode) = RTrim(.Item("CenterCode")) And _
        '            RTrim(gstrctP4000.strBhk) = RTrim(.Item("Bhk")) And _
        '            RTrim(wstrItemID) = RTrim(.Item("Itemid")) And _
        '            RTrim(wstrItemCode) = RTrim(.Item("ItemCode")) And _
        '            RTrim(wstrSerialNo) = RTrim(.Item("SerialNo"))) Then

        '        Else

        '            mint4015status = M4015_STATUS.NOTEXIST
        '            gclsDB.fCloseRecord("STOCK1")
        '            fProcInput = 0
        '            Exit Function

        '        End If
        '    End With

        'ElseIf wintRet = 9 Then

        '    mint4015status = M4015_STATUS.NOTEXIST
        '    gclsDB.fCloseRecord("STOCK1")
        '    fProcInput = 0
        '    Exit Function

        'Else

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

        'End If

        'gclsDB.fCloseRecord("STOCK1")

        'mintCnt += 1

        'ReDim Preserve gstrScanItem(mintCnt - 1)
        'gstrScanItem(mintCnt - 1) = pstrInput

        'mhtScanPart.Add(pstrInput, True)
        'mint4015status = M4015_STATUS.DONE

        'fProcInput = 0


        'Catch ex As Exception
        '    'gintStatus = FREE_STATUS.QUIT
        '    sErrLog(gAppName, "fProcInput", ex.ToString)

        'End Try


    End Function



    '/*
    '|| ึ”–ผFfUpdateStock
    '|| T—v  FSTOCKXV—
    '*/
    Private Function fUpdateStock(ByVal wstrInput As String) As Integer

        Dim rtn As Integer
        Dim wintRet As Integer
        Dim wstrKey(7) As String
        Dim wstrKeyValue(7) As String
        Dim wstrItemCode As String
        Dim tmp As String
        Dim wstrWhere As String
        fUpdateStock = -1

        Try

            tmp = Mid(wstrInput, 2, 13)
            wstrItemCode = fBackDispItem(tmp, True)

            'XV—
            wstrKey(0) = "PicsType"
            wstrKey(1) = "Cstmid"
            wstrKey(2) = "CstmCode"
            wstrKey(3) = "CenterCode"
            wstrKey(4) = "Bhk"
            wstrKey(5) = "Itemid"
            wstrKey(6) = "ItemCode"
            wstrKey(7) = "SerialNo"
            wstrKeyValue(0) = gstrctKDHT.strPackType
            wstrKeyValue(1) = gstrctKDHT.strCstmid
            wstrKeyValue(2) = gstrctKDHT.strCstmCode
            wstrKeyValue(3) = gstrctP4000.strCenterCode
            wstrKeyValue(4) = gstrctP4000.strBhk
            wstrKeyValue(5) = Mid(wstrInput, 1, 1)
            wstrKeyValue(6) = wstrItemCode

            If Mid(wstrInput, 20, 6) = Nothing Then
                wstrKeyValue(7) = "999998"
            Else
                wstrKeyValue(7) = Mid(wstrInput, 20, 6)
            End If


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


            affected_rows = dbClient.Execute("UPDATE " + G_CONST_TBL_STOCK _
                                            + " SET Location='" + gstrctP4000.strLctnStart _
                                            + "' ZaikoStatus='" + "3" _
                                            + "' StockDate='" + fgetDefaultDate() _
                                            + "' StockTime='" + Mid(fgetDefaultTime(), 1, 4) _
                                            + "' StockEmp='" + gstrctKDHT.strUserNo _
                                            + "' WHERE " + wstrWhere)


            If affected_rows = 0 Then
                Exit Function
            End If


            'gclsDB.Setcolumn = ("Location,ZaikoStatus,StockDate,StockTime,StockEmp")          '“o^/XV‘ฮ—๑–ผ
            'gclsDB.SetData = (gstrctP4000.strLctnStart & "," & "3," & fgetDefaultDate() & "," & Mid(fgetDefaultTime(), 1, 4) & "," & gstrctKDHT.strUserNo) '“o^/XVf[^


            'If gclsDB.fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, wstrKey, wstrKeyValue) = -1 Then
            '    Exit Function

            'End If

            fUpdateStock = 0

        Catch ex As Exception

            sErrLog(gAppName, "fUpdateStock", ex.ToString)

        End Try

    End Function


    Private Sub frm4015_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
