﻿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 KDST5000.BtScanLib
Imports BTClientLib
Imports System.IO
Imports System.Reflection
Imports BtScan2

Public Class frm5015
    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 wfName As WarpControl.WarpField
    'Friend WithEvents wfLocation As WarpControl.WarpField
    'Friend WithEvents WarpField11 As WarpControl.WarpField
    'Friend WithEvents wfPut1 As WarpControl.WarpField
    'Friend WithEvents wfPartNo As WarpControl.WarpField
    'Friend WithEvents wfCL As WarpControl.WarpField
    'Friend WithEvents wfZnc As WarpControl.WarpField
    'Friend WithEvents WarpField2 As WarpControl.WarpField
    'Friend WithEvents wfPut2 As WarpControl.WarpField

    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame()
    '    Me.wfPut2 = New WarpControl.WarpField()
    '    Me.WarpField2 = New WarpControl.WarpField()
    '    Me.wfZnc = New WarpControl.WarpField()
    '    Me.wfCL = New WarpControl.WarpField()
    '    Me.wfPartNo = New WarpControl.WarpField()
    '    Me.WarpField11 = New WarpControl.WarpField()
    '    Me.wfPut1 = New WarpControl.WarpField()
    '    Me.WarpField8 = New WarpControl.WarpField()
    '    Me.WarpField7 = 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.wfPut2)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField2)
    '    Me.WarpFrame1.Controls.Add(Me.wfZnc)
    '    Me.WarpFrame1.Controls.Add(Me.wfCL)
    '    Me.WarpFrame1.Controls.Add(Me.wfPartNo)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField11)
    '    Me.WarpFrame1.Controls.Add(Me.wfPut1)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField8)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField7)
    '    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 = ""
    '    '
    '    'wfPut2
    '    '
    '    Me.wfPut2.DecimalPointPosition = CType(0, Short)
    '    Me.wfPut2.DisplayAttribute.Bold = True
    '    Me.wfPut2.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfPut2.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfPut2.Format = ""
    '    Me.wfPut2.Length = CType(4, Short)
    '    Me.wfPut2.Location = New System.Drawing.Point(187, 144)
    '    Me.wfPut2.MacroBcr = ""
    '    Me.wfPut2.MacroIn = ""
    '    Me.wfPut2.MacroKey = ""
    '    Me.wfPut2.MacroOut = ""
    '    Me.wfPut2.Name = "wfPut2"
    '    Me.wfPut2.Size = New System.Drawing.Size(48, 24)
    '    Me.wfPut2.TabIndex = CType(23, Short)
    '    Me.wfPut2.Text = "ZZZZ"
    '    '
    '    'WarpField2
    '    '
    '    Me.WarpField2.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField2.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField2.FontSize = WarpControl.FontSizes.Small2
    '    Me.WarpField2.Format = ""
    '    Me.WarpField2.Length = CType(8, Short)
    '    Me.WarpField2.Location = New System.Drawing.Point(84, 144)
    '    Me.WarpField2.MacroBcr = ""
    '    Me.WarpField2.MacroIn = ""
    '    Me.WarpField2.MacroKey = ""
    '    Me.WarpField2.MacroOut = ""
    '    Me.WarpField2.Name = "WarpField2"
    '    Me.WarpField2.Size = New System.Drawing.Size(96, 24)
    '    Me.WarpField2.TabIndex = CType(22, Short)
    '    Me.WarpField2.Text = "#ofMinus"
    '    '
    '    'wfZnc
    '    '
    '    Me.wfZnc.DecimalPointPosition = CType(0, Short)
    '    Me.wfZnc.DisplayAttribute.Bold = True
    '    Me.wfZnc.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfZnc.FontSize = WarpControl.FontSizes.Small
    '    Me.wfZnc.Format = ""
    '    Me.wfZnc.Length = CType(1, Short)
    '    Me.wfZnc.Location = New System.Drawing.Point(43, 120)
    '    Me.wfZnc.MacroBcr = ""
    '    Me.wfZnc.MacroIn = ""
    '    Me.wfZnc.MacroKey = ""
    '    Me.wfZnc.MacroOut = ""
    '    Me.wfZnc.Name = "wfZnc"
    '    Me.wfZnc.Size = New System.Drawing.Size(15, 30)
    '    Me.wfZnc.TabIndex = CType(21, Short)
    '    '
    '    'wfCL
    '    '
    '    Me.wfCL.DecimalPointPosition = CType(0, Short)
    '    Me.wfCL.DisplayAttribute.Bold = True
    '    Me.wfCL.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfCL.FontSize = WarpControl.FontSizes.Small
    '    Me.wfCL.Format = ""
    '    Me.wfCL.Length = CType(2, Short)
    '    Me.wfCL.Location = New System.Drawing.Point(3, 121)
    '    Me.wfCL.MacroBcr = ""
    '    Me.wfCL.MacroIn = ""
    '    Me.wfCL.MacroKey = ""
    '    Me.wfCL.MacroOut = ""
    '    Me.wfCL.Name = "wfCL"
    '    Me.wfCL.Size = New System.Drawing.Size(30, 30)
    '    Me.wfCL.TabIndex = CType(20, Short)
    '    '
    '    'wfPartNo
    '    '
    '    Me.wfPartNo.DecimalPointPosition = CType(0, Short)
    '    Me.wfPartNo.DisplayAttribute.Bold = True
    '    Me.wfPartNo.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfPartNo.FontSize = WarpControl.FontSizes.Small
    '    Me.wfPartNo.Format = ""
    '    Me.wfPartNo.Length = CType(12, Short)
    '    Me.wfPartNo.Location = New System.Drawing.Point(12, 55)
    '    Me.wfPartNo.MacroBcr = ""
    '    Me.wfPartNo.MacroIn = ""
    '    Me.wfPartNo.MacroKey = ""
    '    Me.wfPartNo.MacroOut = ""
    '    Me.wfPartNo.Name = "wfPartNo"
    '    Me.wfPartNo.Size = New System.Drawing.Size(180, 30)
    '    Me.wfPartNo.TabIndex = CType(19, Short)
    '    '
    '    'WarpField11
    '    '
    '    Me.WarpField11.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField11.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField11.FontSize = WarpControl.FontSizes.Small2
    '    Me.WarpField11.Format = ""
    '    Me.WarpField11.Length = CType(7, Short)
    '    Me.WarpField11.Location = New System.Drawing.Point(97, 120)
    '    Me.WarpField11.MacroBcr = ""
    '    Me.WarpField11.MacroIn = ""
    '    Me.WarpField11.MacroKey = ""
    '    Me.WarpField11.MacroOut = ""
    '    Me.WarpField11.Name = "WarpField11"
    '    Me.WarpField11.Size = New System.Drawing.Size(84, 24)
    '    Me.WarpField11.TabIndex = CType(18, Short)
    '    Me.WarpField11.Text = "#ofScan"
    '    '
    '    'wfPut1
    '    '
    '    Me.wfPut1.DecimalPointPosition = CType(0, Short)
    '    Me.wfPut1.DisplayAttribute.Bold = True
    '    Me.wfPut1.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfPut1.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfPut1.Format = ""
    '    Me.wfPut1.Length = CType(4, Short)
    '    Me.wfPut1.Location = New System.Drawing.Point(187, 120)
    '    Me.wfPut1.MacroBcr = ""
    '    Me.wfPut1.MacroIn = ""
    '    Me.wfPut1.MacroKey = ""
    '    Me.wfPut1.MacroOut = ""
    '    Me.wfPut1.Name = "wfPut1"
    '    Me.wfPut1.Size = New System.Drawing.Size(48, 24)
    '    Me.wfPut1.TabIndex = CType(14, Short)
    '    Me.wfPut1.Text = "ZZZZ"
    '    '
    '    '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(42, 90)
    '    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(4, 90)
    '    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"
    '    '
    '    '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, 24)
    '    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", 22.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfLocation.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfLocation.Format = ""
    '    Me.wfLocation.Length = CType(6, Short)
    '    Me.wfLocation.Location = New System.Drawing.Point(132, 0)
    '    Me.wfLocation.MacroBcr = ""
    '    Me.wfLocation.MacroIn = ""
    '    Me.wfLocation.MacroKey = ""
    '    Me.wfLocation.MacroOut = ""
    '    Me.wfLocation.Name = "wfLocation"
    '    Me.wfLocation.Size = New System.Drawing.Size(72, 24)
    '    Me.wfLocation.TabIndex = CType(6, Short)
    '    Me.wfLocation.Text = "XX-XXX"
    '    '
    '    'WarpField3
    '    '
    '    Me.WarpField3.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField3.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField3.FontSize = WarpControl.FontSizes.Small2
    '    Me.WarpField3.Format = ""
    '    Me.WarpField3.Length = CType(8, Short)
    '    Me.WarpField3.Location = New System.Drawing.Point(24, 0)
    '    Me.WarpField3.MacroBcr = ""
    '    Me.WarpField3.MacroIn = ""
    '    Me.WarpField3.MacroKey = ""
    '    Me.WarpField3.MacroOut = ""
    '    Me.WarpField3.Name = "WarpField3"
    '    Me.WarpField3.Size = New System.Drawing.Size(96, 24)
    '    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", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfKey.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfKey.Format = ""
    '    Me.wfKey.InputMode.Secret = True
    '    Me.wfKey.Length = CType(1, Short)
    '    Me.wfKey.Location = New System.Drawing.Point(228, 0)
    '    Me.wfKey.MacroBcr = ""
    '    Me.wfKey.MacroIn = ""
    '    Me.wfKey.MacroKey = ""
    '    Me.wfKey.MacroOut = ""
    '    Me.wfKey.Name = "wfKey"
    '    Me.wfKey.Size = New System.Drawing.Size(12, 24)
    '    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, 192)
    '    Me.WarpBox1.Name = "WarpBox1"
    '    Me.WarpBox1.Size = New System.Drawing.Size(240, 24)
    '    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, 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(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)
    '    '
    '    'frm5015
    '    '
    '    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 = "frm5015"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region
    Public Enum M5015_STATUS As Integer
        INIT = 0
        NOTCODE = 1
        LOCATION = 2
        FINISHLOCA = 3
        NOTLOCA = 4
        DONE = 5
    End Enum
    Public mint5015status As Integer

    '•”•ix๎•๑
    Structure PART
        Dim strItemID As String
        Dim strItemCode As String
        Dim strPartNo As String
        Dim strSerial As String
        Dim strCL As String
        Dim strZnc As String
        Dim strQty As String
    End Structure

    Private Sub frm5015_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 = LOCA_STATUS.QUIT
                Me.Close()
                Exit Sub
        End Select
    End Sub


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

            ' 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_H5015, WarpBox1)
#End If

            sDisp5015()

            ' 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
            sErrLog(gAppName, "frm5015_Load", ex.ToString)
        End Try

    End Sub

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

        If (Not fCheckCode(buf)) Then
            sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
#If Not Debug Then
                        fFnc_WrpMsg("E", G_CONST_MID_E5E20)
#End If
            Exit Sub
        End If

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

        If rtn = 0 Then

            Select Case mint5015status
                Case M5015_STATUS.LOCATION

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

                    gintStatus = LOCA_STATUS.LOCATION
                    Me.Close()
                    'BtLib.Transaction.Abort()
                    Exit Sub
                Case M5015_STATUS.DONE
                    'ฝทฌ—‘ฑs

                Case M5015_STATUS.FINISHLOCA

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

                    gintStatus = LOCA_STATUS.LOCATION
                    Me.Close()
                    'BtLib.Transaction.End()
                    Exit Sub
                Case M5015_STATUS.NOTCODE
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E5E20)
                    Exit Sub
                Case M5015_STATUS.NOTLOCA
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E5E15)
                    Exit Sub
            End Select

        ElseIf rtn = -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



    End Sub

    ' t[€EC“
    Public Sub sMain()

        Dim WKey As Short
        Dim buf As String
        Dim rtn As Integer
        Dim wintCnt, wintCnt2 As Integer

        Try

            'BtLib.Transaction.BeginConCurrent()
            fResetStock("7")
            fUpdLocationQty("0")
            sDisp5015()
            ' t[€ฬ—๐ฑฑษLqตทB
            '            Do While (True)

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

            '                If WKey = WKY_ENT Then

            '                ElseIf WKey = WKY_F1 Then   'Q1ทฐลLocationษ–฿้

            '                ElseIf WKey = WKY_F2 Then


            '                ElseIf WKey = WKY_PGUP Then


            '                ElseIf WKey = WKY_PGDOWN Then

            '                ElseIf WKey = WKY_ERROR Then

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

            '                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_E5E20)
            '#End If
            '                        Exit Do
            '                    End If

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

            '                    If rtn = 0 Then

            '                        Select Case mint5015status
            '                            Case M5015_STATUS.LOCATION
            '                                gintStatus = LOCA_STATUS.LOCATION
            '                                BtLib.Transaction.Abort()
            '                                Exit Sub
            '                            Case M5015_STATUS.DONE
            '                                'ฝทฌ—‘ฑs

            '                            Case M5015_STATUS.FINISHLOCA
            '                                gintStatus = LOCA_STATUS.LOCATION
            '                                BtLib.Transaction.End()
            '                                Exit Sub
            '                            Case M5015_STATUS.NOTCODE
            '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
            '                                fFnc_WrpMsg("E", G_CONST_MID_E5E20)
            '                            Case M5015_STATUS.NOTLOCA
            '                                sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
            '                                fFnc_WrpMsg("E", G_CONST_MID_E5E15)
            '                        End Select

            '                    ElseIf rtn = -1 Then

            '                        f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)

            '                    End If


            '                End If
            '            Loop

            Exit Sub

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

    '/*
    '|| ึ”–ผFsDisp5015
    '|| T—v  F5015ๆ–ส•\ฆ
    '*/
    Private Sub sDisp5015()
        Dim rtn, rtn1 As String

        rtn = gstrctS5000.lngCntnumber
        rtn1 = gstrctS5000.lngMCntnumber
        wfPut1.Text = rtn.PadLeft(4)
        wfPut2.Text = rtn1.PadLeft(4)
        wfPartNo.Text = gstrctS5000.strPartNo
        wfCL.Text = gstrctS5000.strCL
        wfZnc.Text = gstrctS5000.strZnc
        wfName.Text = gstrctKDHT.strUserName
        wfLocation.Text = fstrDivision(2, gstrctS5000.strLocation)

    End Sub
    '/*
    '|| ึ”–ผFfProcInput
    '|| T—v  F“—อ—
    '*/
    Private Function fProcInput(ByVal pstrInput As String) As Integer
        Dim tmp As String
        Dim rtn As Integer
        Dim rtn2 As Integer
        fProcInput = -1

        If pstrInput.StartsWith("P") Then '•”•ix
            tmp = Mid(pstrInput, 1, 1) & fBackDispItem(Mid(pstrInput, 2, 10), True) & Mid(pstrInput, 12)
            pstrInput = tmp
            If fUpdateStock("3", pstrInput) <> -1 Then
                mint5015status = M5015_STATUS.DONE
                sDisp5015()
            Else
                Exit Function
            End If

        ElseIf pstrInput.StartsWith("T") AndAlso pstrInput.Length = 9 Then 'นฐผฎือู

            If Mid(pstrInput, 5) = gstrctS5000.strLocation Then
                If gstrctS5000.lngCntnumber = 0 Then
                    rtn = fFnc_WrpMsg("E", G_CONST_MID_E5E25, "ND", 2)
                    If rtn = "WKY_ENT" Then
                        If gstrctS5000.lngMCntnumber = 0 Then
                            '๓ซๆ•ช๐—งฤ้
                            rtn2 = fUpdLocationQty("000000", "0")
                            If rtn2 <> 1 Then
                                Exit Function
                            End If
                            mint5015status = M5015_STATUS.FINISHLOCA
                            fProcInput = 0
                            Exit Function
                        Else
                            'ฯฒลฝ•”•i ่
                            rtn = fFnc_WrpMsg("E", G_CONST_MID_E5E30, "ND", 2)
                            If rtn <> "WKY_ENT" Then
                                mint5015status = M5015_STATUS.DONE
                                fProcInput = 0
                                Exit Function
                            End If
                        End If
                    Else
                        mint5015status = M5015_STATUS.DONE
                        fProcInput = 0
                        Exit Function
                    End If
                End If
                rtn2 = fUpdLocationQty(CStr(gstrctS5000.lngCntnumber + gstrctS5000.lngMCntnumber).PadLeft(6, "0"))
                If rtn2 <> 1 Then
                    Exit Function
                End If
                mint5015status = M5015_STATUS.FINISHLOCA
            Else
                mint5015status = M5015_STATUS.NOTLOCA
            End If

        ElseIf pstrInput = "OCMENUBACK" Then

            mint5015status = M5015_STATUS.LOCATION

        Else

            mint5015status = M5015_STATUS.NOTCODE

        End If

        fProcInput = 0
    End Function

    '/*
    '|| ึ”–ผFfUpdateStock
    '|| T—v  Fฝทฌตฝ•”•iฬSTOCKฬฬืธ๐w’่StatusลXV
    '|| ๘”@F1.Xe[^X,2.ฝทฌรฐภ
    '|| –฿่’lF-1(NG),1(OK),0(XVย”\รฐภ–ณต)   
    '*/
    Private Function fUpdateStock(ByVal status As String, ByVal pstrInput As String) As Integer
        Dim wstrKey(7) As String
        Dim wstrKeyValue(7) As String
        Dim wstrctPart As PART
        Dim rtn As Integer
        Dim wstrWhere As String
        Dim sSQL As String
        Const STOCK_KEY = "STOCK1"
        fUpdateStock = -1
        Try
            sDecodeParts(wstrctPart, pstrInput)
            wstrKey(0) = "PicsType" : wstrKeyValue(0) = gstrctKDHT.strPackType
            wstrKey(1) = "Cstmid" : wstrKeyValue(1) = gstrctKDHT.strCstmid
            wstrKey(2) = "CstmCode" : wstrKeyValue(2) = gstrctKDHT.strCstmCode
            wstrKey(3) = "CenterCode" : wstrKeyValue(3) = gstrctS5000.strCenterCode
            wstrKey(4) = "Bhk" : wstrKeyValue(4) = gstrctS5000.strBhk
            wstrKey(5) = "Itemid" : wstrKeyValue(5) = wstrctPart.strItemID
            wstrKey(6) = "ItemCode" : wstrKeyValue(6) = wstrctPart.strItemCode
            wstrKey(7) = "SerialNo" : wstrKeyValue(7) = wstrctPart.strSerial

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

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

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


            If tmpStr.Count > 0 Then

                values1 = tmpStr(0)

                Dim result As String = Nothing
                Dim sZaikoStatus As String = Nothing
                Dim sLocation As String = Nothing

                If values1.TryGetValue("ZaikoStatus", result) Then
                    sZaikoStatus = RTrim(result)
                End If

                If values1.TryGetValue("Location", result) Then
                    sLocation = RTrim(result)
                End If

                If RTrim(sZaikoStatus) <> "M" Then
                    If RTrim(sZaikoStatus) = "7" OrElse RTrim(sZaikoStatus) = "E" OrElse gstrctS5000.strLocation <> RTrim(sLocation) Then

                        sSQL = "UPDATE " + G_CONST_TBL_STOCK _
                                        + " SET ZaikoStatus='" + status _
                                        + "' Location='" + gstrctS5000.strLocation _
                                        + "' WHERE " + wstrWhere

                        affected_rows = dbClient.Execute(sSQL)


                        If affected_rows = 0 Then
                            sErrLog(gAppName, "fUpdateStock", "Error")
                            Exit Function
                        End If

                        'gclsDB.Setcolumn = "ZaikoStatus,Location"
                        'gclsDB.SetData = status & "," & gstrctS5000.strLocation
                        'rtn = gclsDB.fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, wstrKey, wstrKeyValue)
                        'If rtn <> 0 Then
                        '    sErrLog(gAppName, "fUpdateStock", gclsDB.ErrMsg)
                        '    gclsDB.fCloseRecord(STOCK_KEY)
                        '    Exit Function
                        'End If
                        gstrctS5000.lngCntnumber += 1
                        gstrctS5000.strPartNo = fDispItemChg(modConst.DispItemChg.ToMazda, wstrctPart.strPartNo)
                        gstrctS5000.strZnc = wstrctPart.strZnc
                        gstrctS5000.strCL = wstrctPart.strCL
                        If gstrctS5000.lngCntnumber = 1 Then
                            gstrctS5000.strItemId = wstrctPart.strItemID
                            gstrctS5000.strItemCode = wstrctPart.strItemCode
                        End If
                        fUpdateStock = 1
                    Else
                        fUpdateStock = 0
                    End If
                Else
                    fUpdateStock = 0
                End If


            End If

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



        'rtn = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, STOCK_KEY, wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)
        'If rtn = -1 Then
        '    Exit Function
        'ElseIf rtn = 0 Then
        '    With gclsDB.Records(STOCK_KEY)
        '        If RTrim(.Item("ZaikoStatus")) <> "M" Then
        '            If RTrim(.Item("ZaikoStatus")) = "7" OrElse RTrim(.Item("ZaikoStatus")) = "E" OrElse gstrctS5000.strLocation <> RTrim(.Item("Location")) Then
        '                gclsDB.Setcolumn = "ZaikoStatus,Location"
        '                gclsDB.SetData = status & "," & gstrctS5000.strLocation
        '                rtn = gclsDB.fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, wstrKey, wstrKeyValue)
        '                If rtn <> 0 Then
        '                    sErrLog(gAppName, "fUpdateStock", gclsDB.ErrMsg)
        '                    gclsDB.fCloseRecord(STOCK_KEY)
        '                    Exit Function
        '                End If
        '                gstrctS5000.lngCntnumber += 1
        '                gstrctS5000.strPartNo = fDispItemChg(modConst.DispItemChg.ToMazda, wstrctPart.strPartNo)
        '                gstrctS5000.strZnc = wstrctPart.strZnc
        '                gstrctS5000.strCL = wstrctPart.strCL
        '                If gstrctS5000.lngCntnumber = 1 Then
        '                    gstrctS5000.strItemId = wstrctPart.strItemID
        '                    gstrctS5000.strItemCode = wstrctPart.strItemCode
        '                End If
        '                fUpdateStock = 1
        '            Else
        '                fUpdateStock = 0
        '            End If
        '        Else
        '            fUpdateStock = 0
        '        End If
        '    End With
        'End If
        'gclsDB.fCloseRecord(STOCK_KEY)
        'Catch ex As Exception
        '    sErrLog(gAppName, "fUpdateStock", ex.ToString)
        'End Try
    End Function
    '/*
    '|| ึ”–ผFfResetStock
    '|| T—v  FSTOCKฬฬืธ๐w’่StatusลXV
    '|| ๘”@F1.Xe[^X
    '|| –฿่’lF-1(NG),1(OK),0(XVย”\รฐภ–ณต)   
    '*/
    Private Function fResetStock(ByVal Status As String) As Integer
        Dim wstrKey(7) As String
        Dim wstrKeyValue(7) As String
        Dim wintRet As Integer
        Dim wstrWhere As String
        fResetStock = -1
        wstrKey(0) = "PicsType" : wstrKeyValue(0) = gstrctKDHT.strPackType
        wstrKey(1) = "Cstmid" : wstrKeyValue(1) = gstrctKDHT.strCstmid
        wstrKey(2) = "CstmCode" : wstrKeyValue(2) = gstrctKDHT.strCstmCode
        wstrKey(3) = "CenterCode" : wstrKeyValue(3) = gstrctS5000.strCenterCode
        wstrKey(4) = "Bhk" : wstrKeyValue(4) = gstrctS5000.strBhk
        wstrKey(5) = "Location" : wstrKeyValue(5) = gstrctS5000.strLocation
        wstrKey(6) = "ItemCode" : wstrKeyValue(6) = Space(30)
        wstrKey(7) = "SerialNo" : wstrKeyValue(7) = Space(6)
        Try

            wstrWhere = ""
            wstrWhere = wstrKey(0) & " = '" & wstrKeyValue(0) & "'"
            wstrWhere &= " and " & wstrKey(1) & " = '" & wstrKeyValue(1) & "'"
            wstrWhere &= " and " & wstrKey(2) & " = '" & wstrKeyValue(2) & "'"
            wstrWhere &= " and " & wstrKey(3) & " = '" & wstrKeyValue(3) & "'"
            wstrWhere &= " and " & wstrKey(4) & " = '" & wstrKeyValue(4) & "'"
            wstrWhere &= " and " & wstrKey(5) & " = '" & wstrKeyValue(5) & "'"
            wstrWhere &= " and " & wstrKey(6) & " = '" & wstrKeyValue(6) & "'"
            wstrWhere &= " and " & 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)
            Dim sPicsType As String = ""
            Dim sCstmid As String = ""
            Dim sCstmCode As String = ""
            Dim sCenterCode As String = ""
            Dim sBhk As String = ""
            Dim sLocation As String = ""
            Dim sZaikoStatus As String = ""
            Dim sItemCode As String = ""
            Dim sSerialNo As String = ""

            Dim i As Integer = 0

            If tmpStr.Count > 0 Then

                fResetStock = 0

                Do

                    values = tmpStr(i)

                    Dim result As String = Nothing
                    If values.TryGetValue("PicsType", result) Then
                        sPicsType = RTrim(result)
                    End If
                    If values.TryGetValue("Cstmid", result) Then
                        sCstmid = RTrim(result)
                    End If
                    If values.TryGetValue("CstmCode", result) Then
                        sCstmCode = RTrim(result)
                    End If
                    If values.TryGetValue("CenterCode", result) Then
                        sCenterCode = RTrim(result)
                    End If
                    If values.TryGetValue("Bhk", result) Then
                        sBhk = RTrim(result)
                    End If
                    If values.TryGetValue("Location", result) Then
                        sLocation = RTrim(result)
                    End If
                    If values.TryGetValue("ZaikoStatus", result) Then
                        sZaikoStatus = RTrim(result)
                    End If
                    If values.TryGetValue("ItemCode", result) Then
                        sItemCode = RTrim(result)
                    End If
                    If values.TryGetValue("SerialNo", result) Then
                        sSerialNo = RTrim(result)
                    End If

                    If wstrKeyValue(0) = RTrim(sPicsType) AndAlso wstrKeyValue(1) = RTrim(sCstmid) AndAlso _
                           wstrKeyValue(2) = RTrim(sCstmCode) AndAlso wstrKeyValue(3) = RTrim(sCenterCode) AndAlso _
                           wstrKeyValue(4) = RTrim(sBhk) AndAlso wstrKeyValue(5) = RTrim(sLocation) Then
                        If RTrim(sZaikoStatus) = "M" Then  'ฯฒลฝอถณฤฬลXV—–ณต!
                            gstrctS5000.lngMCntnumber += 1
                        ElseIf RTrim(sZaikoStatus) <> "E" Then
                            wstrKeyValue(6) = RTrim(sItemCode)
                            wstrKeyValue(7) = RTrim(sSerialNo)

                            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 ZaikoStatus='" + Status _
                                                           + "' WHERE " + wstrWhere)


                            If affected_rows = 0 Then
                                Exit Function
                            End If

                        End If
                        fResetStock = 1

                    Else
                        Exit Do
                    End If




                    i = i + 1

                    If tmpStr.Count = i Then
                        Exit Do
                    End If


                Loop


            Else
                fResetStock = 0

            End If

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



        'wintRet = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY04, "STOCK1", wstrKey, wstrKeyValue, BtLib.Operation.GetGreaterOrEqual)
        'If wintRet = -1 Then
        '    Exit Function
        'ElseIf wintRet = 0 Then
        '    fResetStock = 0
        '    Do
        '        With gclsDB.Records("STOCK1")
        '            If wstrKeyValue(0) = RTrim(.Item("PicsType")) AndAlso wstrKeyValue(1) = RTrim(.Item("Cstmid")) AndAlso _
        '               wstrKeyValue(2) = RTrim(.Item("CstmCode")) AndAlso wstrKeyValue(3) = RTrim(.Item("CenterCode")) AndAlso _
        '               wstrKeyValue(4) = RTrim(.Item("Bhk")) AndAlso wstrKeyValue(5) = RTrim(.Item("Location")) Then
        '                If RTrim(.Item("ZaikoStatus")) = "M" Then  'ฯฒลฝอถณฤฬลXV—–ณต!
        '                    gstrctS5000.lngMCntnumber += 1
        '                ElseIf RTrim(.Item("ZaikoStatus")) <> "E" Then
        '                    wstrKeyValue(6) = RTrim(.Item("ItemCode"))
        '                    wstrKeyValue(7) = RTrim(.Item("SerialNo"))
        '                    gclsDB.Setcolumn = "ZaikoStatus"
        '                    gclsDB.SetData = Status
        '                    wintRet = gclsDB.fUpdRecords(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY04, wstrKey, wstrKeyValue)
        '                    If wintRet <> 0 Then
        '                        gclsDB.fCloseRecord("STOCK1")
        '                        Exit Function
        '                    End If
        '                End If
        '                fResetStock = 1
        '                If .Read(BtLib.Operation.GetNext) <> 0 Then
        '                    Exit Do
        '                End If
        '            Else
        '                Exit Do
        '            End If
        '        End With
        '    Loop
        'Else
        '    fResetStock = 0
        'End If
        'gclsDB.fCloseRecord("STOCK1")
        'Catch ex As Exception
        '    sErrLog(gAppName, "fResetStock", ex.ToString)
        'End Try
    End Function
    '/*
    '|| ึ”–ผFfUpdLocationQty
    '|| T—v  Fนฐผฎฬ”—สฦ ซๆ•ช๐XV
    '|| ๘”@F1.•ว”—ส,2.๓ซๆ•ชฬืธ 0:๓ซๆ•ช(0),1:๓ซๆ•ช(1)
    '|| –฿่’lF-1(NG),1(OK)   
    '*/
    Private Function fUpdLocationQty(ByVal pstrQty As String, Optional ByVal pstrAkiKbn As String = "1") As Integer
        Dim wstrKey(3) As String
        Dim wstrKeyValue(3) As String
        Dim wintRet As Integer
        Dim wstrWhere As String
        Dim sSql As String
        fUpdLocationQty = -1
        Try
            wstrKey(0) = "CenterCode" : wstrKeyValue(0) = gstrctS5000.strCenterCode
            wstrKey(1) = "Bhk" : wstrKeyValue(1) = gstrctS5000.strBhk
            wstrKey(2) = "Location" : wstrKeyValue(2) = gstrctS5000.strLocation
            'wstrKey(3) = "Product" : wstrKeyValue(3) = "999999"
            wstrKey(3) = "Product" : wstrKeyValue(3) = "200603"

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


            'With gclsDB
            If pstrAkiKbn = "1" Then
                '.Setcolumn = "Qty,AkiKB,ItemID,ItemCode,DispItemCode"
                '.SetData = pstrQty & "," & "1" & "," & gstrctS5000.strItemId & "," & gstrctS5000.strItemCode & "," & fDispItemChg(DispItemChg.ToMazda, gstrctS5000.strItemCode)

                sSql = "UPDATE " + G_CONST_TBL_PACKCP + " SET Qty='" _
                                                             + pstrQty _
                                                             + "' , AkiKB='" _
                                                             + "1" _
                                                             + "' , ItemID='" _
                                                             + gstrctS5000.strItemId _
                                                             + "' , ItemCode='" _
                                                             + gstrctS5000.strItemCode _
                                                             + "' , DispItemCode='" _
                                                             + fDispItemChg(DispItemChg.ToMazda, gstrctS5000.strItemCode) _
                                                             + "' WHERE " + wstrWhere

            ElseIf pstrAkiKbn = "0" Then
                '.Setcolumn = "Qty,AkiKB,ItemCode,DispItemCode"
                '.SetData = pstrQty & "," & "0" & "," & Space(30) & "," & Space(30)

                sSql = "UPDATE " + G_CONST_TBL_PACKCP + " SET Qty='" _
                                                             + pstrQty _
                                                             + "' , AkiKB='" _
                                                             + "0" _
                                                             + "' , ItemCode='" _
                                                             + Space(30) _
                                                             + "' , DispItemCode='" _
                                                             + Space(30) _
                                                             + "' WHERE " + wstrWhere


            End If

            affected_rows = dbClient.Execute(sSql)

            If affected_rows = 0 Then
                Exit Function
            End If


            '    wintRet = .fUpdRecords(G_CONST_TBL_LOCATION, G_CONST_KEY_LOCATIONKEY00, wstrKey, wstrKeyValue)
            '    If wintRet <> 0 Then
            '        sErrLog(gAppName, "fClearLocationQty", gclsDB.ErrMsg)
            '        Exit Function
            '    End If
            'End With
            fUpdLocationQty = 1
        Catch ex As Exception
            sErrLog(gAppName, "fUpdLocationQty", ex.ToString)
        End Try
    End Function

    '/*•”•i”ิ•ช๐
    Private Sub sDecodeParts(ByRef strctParts As PART, ByVal strCode As String)
        With strctParts
            .strItemID = RTrim(Mid(strCode, 1, 1))
            .strItemCode = RTrim(Mid(strCode, 2, 13))
            .strPartNo = RTrim(Mid(strCode, 2, 10))
            .strCL = RTrim(Mid(strCode, 12, 2))
            .strZnc = RTrim(Mid(strCode, 14, 1))
            .strQty = RTrim(Mid(strCode, 15, 5))
            .strSerial = RTrim(Mid(strCode, 20, 6))
        End With
    End Sub

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







