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

Public Class frm1015
    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 wfName As WarpControl.WarpField
    'Friend WithEvents WarpField3 As WarpControl.WarpField
    'Friend WithEvents wfLocation As WarpControl.WarpField
    'Friend WithEvents WarpField11 As WarpControl.WarpField
    'Friend WithEvents wfPut As WarpControl.WarpField
    'Friend WithEvents WarpField7 As WarpControl.WarpField
    'Friend WithEvents WarpField8 As WarpControl.WarpField
    'Friend WithEvents WarpField9 As WarpControl.WarpField
    'Friend WithEvents WarpField10 As WarpControl.WarpField
    'Friend WithEvents wfSerial As WarpControl.WarpField
    'Friend WithEvents wfZnc As WarpControl.WarpField
    'Friend WithEvents wfCL As WarpControl.WarpField
    'Friend WithEvents wfPart As WarpControl.WarpField

    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame()
    '    Me.WarpField10 = New WarpControl.WarpField()
    '    Me.WarpField9 = New WarpControl.WarpField()
    '    Me.WarpField8 = New WarpControl.WarpField()
    '    Me.WarpField7 = New WarpControl.WarpField()
    '    Me.wfSerial = New WarpControl.WarpField()
    '    Me.wfZnc = New WarpControl.WarpField()
    '    Me.wfCL = New WarpControl.WarpField()
    '    Me.wfPart = New WarpControl.WarpField()
    '    Me.wfPut = New WarpControl.WarpField()
    '    Me.WarpField11 = 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.WarpField10)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField9)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField8)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField7)
    '    Me.WarpFrame1.Controls.Add(Me.wfSerial)
    '    Me.WarpFrame1.Controls.Add(Me.wfZnc)
    '    Me.WarpFrame1.Controls.Add(Me.wfCL)
    '    Me.WarpFrame1.Controls.Add(Me.wfPart)
    '    Me.WarpFrame1.Controls.Add(Me.wfPut)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField11)
    '    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 = ""
    '    '
    '    'WarpField10
    '    '
    '    Me.WarpField10.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField10.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField10.FontSize = WarpControl.FontSizes.Small2
    '    Me.WarpField10.Format = ""
    '    Me.WarpField10.Length = CType(8, Short)
    '    Me.WarpField10.Location = New System.Drawing.Point(0, 132)
    '    Me.WarpField10.MacroBcr = ""
    '    Me.WarpField10.MacroIn = ""
    '    Me.WarpField10.MacroKey = ""
    '    Me.WarpField10.MacroOut = ""
    '    Me.WarpField10.Name = "WarpField10"
    '    Me.WarpField10.Size = New System.Drawing.Size(96, 24)
    '    Me.WarpField10.TabIndex = CType(32, Short)
    '    Me.WarpField10.Text = "SerialNo"
    '    '
    '    'WarpField9
    '    '
    '    Me.WarpField9.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField9.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField9.FontSize = WarpControl.FontSizes.Small2
    '    Me.WarpField9.Format = ""
    '    Me.WarpField9.Length = CType(3, Short)
    '    Me.WarpField9.Location = New System.Drawing.Point(192, 75)
    '    Me.WarpField9.MacroBcr = ""
    '    Me.WarpField9.MacroIn = ""
    '    Me.WarpField9.MacroKey = ""
    '    Me.WarpField9.MacroOut = ""
    '    Me.WarpField9.Name = "WarpField9"
    '    Me.WarpField9.Size = New System.Drawing.Size(36, 24)
    '    Me.WarpField9.TabIndex = CType(31, Short)
    '    Me.WarpField9.Text = "Znc"
    '    '
    '    'WarpField8
    '    '
    '    Me.WarpField8.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField8.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField8.FontSize = WarpControl.FontSizes.Small2
    '    Me.WarpField8.Format = ""
    '    Me.WarpField8.Length = CType(2, Short)
    '    Me.WarpField8.Location = New System.Drawing.Point(156, 75)
    '    Me.WarpField8.MacroBcr = ""
    '    Me.WarpField8.MacroIn = ""
    '    Me.WarpField8.MacroKey = ""
    '    Me.WarpField8.MacroOut = ""
    '    Me.WarpField8.Name = "WarpField8"
    '    Me.WarpField8.Size = New System.Drawing.Size(24, 24)
    '    Me.WarpField8.TabIndex = CType(30, Short)
    '    Me.WarpField8.Text = "CL"
    '    '
    '    'WarpField7
    '    '
    '    Me.WarpField7.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField7.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField7.FontSize = WarpControl.FontSizes.Small2
    '    Me.WarpField7.Format = ""
    '    Me.WarpField7.Length = CType(7, Short)
    '    Me.WarpField7.Location = New System.Drawing.Point(0, 75)
    '    Me.WarpField7.MacroBcr = ""
    '    Me.WarpField7.MacroIn = ""
    '    Me.WarpField7.MacroKey = ""
    '    Me.WarpField7.MacroOut = ""
    '    Me.WarpField7.Name = "WarpField7"
    '    Me.WarpField7.Size = New System.Drawing.Size(84, 24)
    '    Me.WarpField7.TabIndex = CType(29, Short)
    '    Me.WarpField7.Text = "Part-No"
    '    '
    '    'wfSerial
    '    '
    '    Me.wfSerial.DecimalPointPosition = CType(0, Short)
    '    Me.wfSerial.DisplayAttribute.Bold = True
    '    Me.wfSerial.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfSerial.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfSerial.Format = ""
    '    Me.wfSerial.Length = CType(6, Short)
    '    Me.wfSerial.Location = New System.Drawing.Point(0, 156)
    '    Me.wfSerial.MacroBcr = ""
    '    Me.wfSerial.MacroIn = ""
    '    Me.wfSerial.MacroKey = ""
    '    Me.wfSerial.MacroOut = ""
    '    Me.wfSerial.Name = "wfSerial"
    '    Me.wfSerial.Size = New System.Drawing.Size(72, 24)
    '    Me.wfSerial.TabIndex = CType(28, Short)
    '    Me.wfSerial.Text = "XXXXXX"
    '    '
    '    '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.Length = CType(1, Short)
    '    Me.wfZnc.Location = New System.Drawing.Point(204, 102)
    '    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(27, 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.Length = CType(2, Short)
    '    Me.wfCL.Location = New System.Drawing.Point(156, 102)
    '    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(26, Short)
    '    Me.wfCL.Text = "XX"
    '    '
    '    '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.Length = CType(12, Short)
    '    Me.wfPart.Location = New System.Drawing.Point(0, 102)
    '    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(25, Short)
    '    Me.wfPart.Text = "XX-XXX"
    '    '
    '    'wfPut
    '    '
    '    Me.wfPut.BcrFlag = True
    '    Me.wfPut.DecimalPointPosition = CType(0, Short)
    '    Me.wfPut.DisplayAttribute.Bold = True
    '    Me.wfPut.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfPut.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfPut.Format = ""
    '    Me.wfPut.Length = CType(5, Short)
    '    Me.wfPut.Location = New System.Drawing.Point(156, 156)
    '    Me.wfPut.MacroBcr = ""
    '    Me.wfPut.MacroIn = ""
    '    Me.wfPut.MacroKey = ""
    '    Me.wfPut.MacroOut = ""
    '    Me.wfPut.Name = "wfPut"
    '    Me.wfPut.Size = New System.Drawing.Size(60, 24)
    '    Me.wfPut.TabIndex = CType(24, Short)
    '    Me.wfPut.Text = "ZZZZ9"
    '    '
    '    '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(5, Short)
    '    Me.WarpField11.Location = New System.Drawing.Point(156, 132)
    '    Me.WarpField11.MacroBcr = ""
    '    Me.WarpField11.MacroIn = ""
    '    Me.WarpField11.MacroKey = ""
    '    Me.WarpField11.MacroOut = ""
    '    Me.WarpField11.Name = "WarpField11"
    '    Me.WarpField11.Size = New System.Drawing.Size(60, 24)
    '    Me.WarpField11.TabIndex = CType(23, Short)
    '    Me.WarpField11.Text = "Total"
    '    '
    '    '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(6, Short)
    '    Me.wfLocation.Location = New System.Drawing.Point(48, 36)
    '    Me.wfLocation.MacroBcr = ""
    '    Me.wfLocation.MacroIn = ""
    '    Me.wfLocation.MacroKey = ""
    '    Me.wfLocation.MacroOut = ""
    '    Me.wfLocation.Name = "wfLocation"
    '    Me.wfLocation.Size = New System.Drawing.Size(108, 36)
    '    Me.wfLocation.TabIndex = CType(22, Short)
    '    Me.wfLocation.Text = "XX-XXX"
    '    '
    '    '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(21, 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(204, 12)
    '    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-0010.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.Decode.UPC_EAN_JAN = 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)
    '    '
    '    'frm1015
    '    '
    '    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 = "frm1015"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region

    Public Enum M1015_STATUS As Integer
        INIT = 0
        NOTCODE = 1
        DABULL = 2
        NOTLOCA = 3
        DONE = 4
    End Enum

    Public mint1015status As Integer

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



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

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

            'sSetImgFName(G_CONST_MID_H1015, WarpBox1)

            sDisp1015()

            ' 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 = PART_STATUS.QUIT
            sErrLog(gAppName, "frm1015_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

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

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

        If rtn = 0 Then
            Select Case mint1015status

                Case M1015_STATUS.INIT

                Case M1015_STATUS.NOTCODE              'w’่ศOฬบฐฤศฬลดืฐาฏพฐผ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E1E25)
                    Exit Sub

                Case M1015_STATUS.NOTLOCA       'ลฦูศ้นฐผฎ๐“ว๑พฝ฿ดืฐาฏพฐผ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E1E30)
                    Exit Sub
                Case M1015_STATUS.DABULL        'ภฬูฝทฌ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E0230)
                    Exit Sub
                Case M1015_STATUS.DONE              'ณํษQฦลซฝ

                    fendLocation()

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

                    gintStatus = PART_STATUS.LOCATION

                    Me.Close()
                    Exit Sub

            End Select

        Else

            '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
        '    Do While (True)

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

        '        If WKey = WKY_ENT Then


        '        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)
        '                fFnc_WrpMsg("E", G_CONST_MID_E1E25)

        '                Exit Do
        '            End If

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

        '            If rtn = 0 Then
        '                Select Case mint1015status

        '                    Case M1015_STATUS.INIT

        '                    Case M1015_STATUS.NOTCODE              'w’่ศOฬบฐฤศฬลดืฐาฏพฐผ
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                        fFnc_WrpMsg("E", G_CONST_MID_E1E25)


        '                    Case M1015_STATUS.NOTLOCA       'ลฦูศ้นฐผฎ๐“ว๑พฝ฿ดืฐาฏพฐผ
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                        fFnc_WrpMsg("E", G_CONST_MID_E1E30)

        '                    Case M1015_STATUS.DABULL        'ภฬูฝทฌ
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                        fFnc_WrpMsg("E", G_CONST_MID_E0230)

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

        '                        fendLocation()
        '                        gintStatus = PART_STATUS.LOCATION

        '                End Select

        '            Else

        '                f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, MWA_DB_WARNING, MWA_DB_OK)

        '            End If
        '            Exit Do

        '        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

    '/*
    '|| ึ”–ผFsDisp1015
    '|| T—v  F1015ๆ–ส•\ฆ
    '*/
    Private Sub sDisp1015()
        Dim rut As String
        rut = gstrctS1000.lngCntItem

        wfLocation.Text = fstrDivision(2, gstrctS1000.strLocation)
        '•\ฆ—pบฐฤษ•ฯท
        'wfPart.Puts(fstrDivision(7, fstrDivision(4, Mid(gstrctS1000.strItemCode, 1, 10))))

        If rut = 0 Then
            wfPart.Text = ""
        Else
            wfPart.Text = fDispItemChg(1, Mid(gstrctS1000.strItemCode, 1, 10))
        End If

        wfCL.Text = Mid(gstrctS1000.strItemCode, 11, 2)
        wfZnc.Text = Mid(gstrctS1000.strItemCode, 13, 1)
        wfSerial.Text = gstrctS1000.strSerialNo
        wfPut.Text = rut.PadLeft(5)
        'wfName.Text = gstrctKDHT.strUserName


    End Sub


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

        Dim rtn As Integer
        Dim wintCntLoca As Integer
        Dim i As Integer
        Dim tmp As String
        Dim wstrSerialNo As String

        ReDim Preserve gstrctS1000.strScanCode(gstrctS1000.lngCntItem)
        ReDim Preserve gstrctS1000.strRecord(gstrctS1000.lngCnt)
        fProcInput = -1

        Try

            If pstrInput.StartsWith("P") OrElse pstrInput.StartsWith("Z") OrElse pstrInput.StartsWith("D") Then  'ๆ“ชชP,Zศ็ฮ
                rtn = pstrInput.Length
                If rtn <> 25 And rtn <> 19 Then                    '25…ฝอ19…ศ็ฮ
                    mint1015status = M1015_STATUS.NOTCODE
                    fProcInput = 0
                    Exit Function

                Else
                    i = 0
                    Do While i <= gstrctS1000.lngCntItem
                        If gstrctS1000.strScanCode(i) = pstrInput Then   'ภฬูฝทฌ
                            mint1015status = M1015_STATUS.DABULL
                            fProcInput = 0
                            Exit Function
                        End If
                        i += 1
                    Loop

                    If rtn = 19 Then
                        wstrSerialNo = Space(6)
                    ElseIf rtn = 25 Then
                        wstrSerialNo = pstrInput.Substring(19, 6)
                    End If

                    gstrctS1000.strItemID = pstrInput.Substring(0, 1)

                    '2005/03/07 •\ฆ—pบฐฤ๐“เ•”บฐฤษ•ฯท
                    'gstrctS1000.strItemCode = pstrInput.Substring(1, 13)
                    tmp = pstrInput.Substring(1, 13)
                    gstrctS1000.strItemCode = fBackDispItem(tmp, True)

                    gstrctS1000.strQty = pstrInput.Substring(14, 5)
                    gstrctS1000.strSerialNo = wstrSerialNo

                    fProcInput = 0
                    gstrctS1000.strScanCode(gstrctS1000.lngCntItem) = pstrInput
                    gstrctS1000.lngCntItem += 1

                    fInputRecod()
                    gstrctS1000.lngCnt += 1


                    Exit Function

                End If

            ElseIf pstrInput.StartsWith("T") Then        'ๆ“ชชTศ็ฮ
                rtn = pstrInput.Length
                If rtn <> 9 Then                    '9…ศOศ็ฮ
                    mint1015status = M1015_STATUS.NOTCODE
                    fProcInput = 0
                    Exit Function
                Else

                    'นฐผฎ๐m”F
                    wintCntLoca = fProcSearchLoca(pstrInput)

                    If wintCntLoca = 0 Then
                        mint1015status = M1015_STATUS.DONE
                        fProcInput = 0
                        Exit Function

                    ElseIf wintCntLoca = -2 Then    'ลฦูศ้นฐผฎ
                        mint1015status = M1015_STATUS.NOTLOCA
                        fProcInput = 0
                        Exit Function

                    End If

                End If

            Else        'w’่บฐฤศO
                mint1015status = M1015_STATUS.NOTCODE
                fProcInput = 0
                Exit Function

            End If

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

        End Try

    End Function

    ''/*
    ''|| ึ”–ผFfProcSearchItem
    ''|| T—v  F•”•im”F—
    ''*/
    '''Private Function fProcSearchItem(ByVal pstrInput As String) As Integer


    '''    Dim wstrKey() As String
    '''    Dim wstrKeyValue() As String
    '''    Dim wintCnt As Integer

    '''    fProcSearchItem = -1
    '''    Try

    '''        gstrctS4000.strItemID = pstrInput.Substring(0, 1)
    '''        gstrctS4000.strItemCode = pstrInput.Substring(1, 13)
    '''        gstrctS4000.strSerialNo = pstrInput.Substring(19, 6)

    '''        ReDim wstrKey(7)
    '''        ReDim wstrKeyValue(7)

    '''        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) = gstrctS4000.strFromCenterCode
    '''        wstrKey(4) = "Bhk" : wstrKeyValue(4) = gstrctS4000.strFromBhk
    '''        wstrKey(5) = "Itemid" : wstrKeyValue(5) = gstrctS4000.strItemID
    '''        wstrKey(6) = "ItemCode" : wstrKeyValue(6) = gstrctS4000.strItemCode
    '''        wstrKey(7) = "SerialNo" : wstrKeyValue(7) = gstrctS4000.strSerialNo

    '''        wintCnt = gclsDB.fOpenRecord(G_CONST_TBL_STOCK, G_CONST_KEY_STOCKKEY00, "STOCK01", wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)

    '''        If wintCnt = 0 Then
    '''            With gclsDB.Records("STOCK01")
    '''                If .Item("ZaikoStatus") <> 3 Then
    '''                    gclsDB.fCloseRecord("STOCK01")
    '''                    fProcSearchItem = -2
    '''                    Exit Function
    '''                End If
    '''                If gstrctS4000.strFromLocation <> .Item("Location") Then
    '''                    gclsDB.fCloseRecord("STOCK01")
    '''                    fProcSearchItem = -2
    '''                    Exit Function
    '''                Else
    '''                    STOCKฬษฝรฐภฝ๐"2"iฺ“ฎ’jษท้
    '''                    gclsDB.Setcolumn = ("ZaikoStatus")      '“o^/XV‘ฮ—๑–ผ
    '''                    gclsDB.SetData = ("2")

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

    '''                End If

    '''            End With
    '''        ElseIf wintCnt = 4 Or wintCnt = 9 Then
    '''            gclsDB.fCloseRecord("STOCK01")
    '''            fProcSearchItem = -2
    '''        Else
    '''            gclsDB.fCloseRecord("STOCK01")
    '''        End If

    '''        gclsDB.fCloseRecord("STOCK01")
    '''        fProcSearchItem = 0

    '''    Catch ex As Exception
    '''        gclsDB.fCloseRecord("STOCK01")
    '''        sErrLog(gAppName, "fProcSearchItem", ex.ToString)

    '''    End Try

    '''End Function

    ''/*
    ''|| ึ”–ผFfProcSearchLoca
    ''|| T—v  Fนฐผฎm”F—
    ''*/
    Private Function fProcSearchLoca(ByVal pstrInput As String) As Integer

        Dim wstrLocation As String
        Dim wintCnt As Integer

        fProcSearchLoca = -1
        wstrLocation = pstrInput.Substring(4)
        If wstrLocation <> gstrctS1000.strLocation Then

            fProcSearchLoca = -2
            Exit Function

        End If
        fProcSearchLoca = 0

    End Function

    ''/*
    ''|| ึ”–ผFfendLocation
    ''|| T—v  FนฐผฎI—น—
    ''*/
    Private Sub fendLocation()
        Erase gstrctS1000.strScanCode
        gstrctS1000.lngCntItem = 0
        gstrctS1000.lngCntRack += 1
        gstrctS1000.strItemID = ""
        gstrctS1000.strItemCode = ""
        gstrctS1000.strSerialNo = ""
    End Sub

    ''/*
    ''|| ึ”–ผFfInputRecod
    ''|| T—v  FXV€–ฺ—
    ''*/
    Private Sub fInputRecod()
        With gstrctS1000
            .strRecord(gstrctS1000.lngCnt) = "T0"
            .strRecord(gstrctS1000.lngCnt) &= .strdata
            .strRecord(gstrctS1000.lngCnt) &= .strBhk.PadRight(3)
            .strRecord(gstrctS1000.lngCnt) &= .strLocation.PadRight(5)
            .strRecord(gstrctS1000.lngCnt) &= .strItemID.PadRight(1)
            .strRecord(gstrctS1000.lngCnt) &= .strItemCode.PadRight(30)
            .strRecord(gstrctS1000.lngCnt) &= .strQty.PadRight(5)
            .strRecord(gstrctS1000.lngCnt) &= .strSerialNo.PadRight(6)
            .strRecord(gstrctS1000.lngCnt) &= gstrctKDHT.strUserNo.PadRight(6)
            .strRecord(gstrctS1000.lngCnt) &= fgetDefaultDate()         'ผฝรั“๚•t
            .strRecord(gstrctS1000.lngCnt) &= fgetDefaultTime()        'ผฝรั
        End With
    End Sub


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