﻿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 frm1010
    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 wfName As WarpControl.WarpField
    'Friend WithEvents wfLocation As WarpControl.WarpField
    'Friend WithEvents WarpField2 As WarpControl.WarpField
    'Friend WithEvents wfPut As WarpControl.WarpField
    'Friend WithEvents wfTitle As WarpControl.WarpField

    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame()
    '    Me.wfTitle = New WarpControl.WarpField()
    '    Me.wfPut = New WarpControl.WarpField()
    '    Me.WarpField2 = 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.wfTitle)
    '    Me.WarpFrame1.Controls.Add(Me.wfPut)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField2)
    '    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 = ""
    '    '
    '    'wfTitle
    '    '
    '    Me.wfTitle.BcrFlag = True
    '    Me.wfTitle.DecimalPointPosition = CType(0, Short)
    '    Me.wfTitle.Font = New System.Drawing.Font("lr SVbN", 22.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfTitle.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfTitle.Format = ""
    '    Me.wfTitle.InputAttribute.Reverse = True
    '    Me.wfTitle.InputMode.Clear = True
    '    Me.wfTitle.Length = CType(12, Short)
    '    Me.wfTitle.Location = New System.Drawing.Point(60, 0)
    '    Me.wfTitle.MacroBcr = ""
    '    Me.wfTitle.MacroIn = ""
    '    Me.wfTitle.MacroKey = ""
    '    Me.wfTitle.MacroOut = ""
    '    Me.wfTitle.Name = "wfTitle"
    '    Me.wfTitle.Size = New System.Drawing.Size(144, 24)
    '    Me.wfTitle.TabIndex = CType(26, Short)
    '    '
    '    '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", 28.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfPut.FontSize = WarpControl.FontSizes.Small
    '    Me.wfPut.Format = ""
    '    Me.wfPut.Length = CType(5, Short)
    '    Me.wfPut.Location = New System.Drawing.Point(159, 144)
    '    Me.wfPut.MacroBcr = ""
    '    Me.wfPut.MacroIn = ""
    '    Me.wfPut.MacroKey = ""
    '    Me.wfPut.MacroOut = ""
    '    Me.wfPut.Name = "wfPut"
    '    Me.wfPut.Size = New System.Drawing.Size(75, 30)
    '    Me.wfPut.TabIndex = CType(25, Short)
    '    Me.wfPut.Text = "ZZZZ9"
    '    '
    '    'WarpField2
    '    '
    '    Me.WarpField2.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField2.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField2.FontSize = WarpControl.FontSizes.Small
    '    Me.WarpField2.Format = ""
    '    Me.WarpField2.Length = CType(10, Short)
    '    Me.WarpField2.Location = New System.Drawing.Point(7, 144)
    '    Me.WarpField2.MacroBcr = ""
    '    Me.WarpField2.MacroIn = ""
    '    Me.WarpField2.MacroKey = ""
    '    Me.WarpField2.MacroOut = ""
    '    Me.WarpField2.Name = "WarpField2"
    '    Me.WarpField2.Size = New System.Drawing.Size(150, 30)
    '    Me.WarpField2.TabIndex = CType(10, Short)
    '    Me.WarpField2.Text = "Rack 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.InputMode.Clear = True
    '    Me.wfLocation.Length = CType(8, Short)
    '    Me.wfLocation.Location = New System.Drawing.Point(36, 72)
    '    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(9, 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(12, 36)
    '    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(8, 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, 96)
    '    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)
    '    '
    '    'frm1010
    '    '
    '    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 = "frm1010"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region

    Public Enum M1010_STATUS As Integer
        INIT = 0
        SHUTDOWN = 1
        MENUBACK = 2
        NOTCODE = 3
        NOTPUT = 4
        NOTFILE = 5
        DONE = 6
    End Enum

    Public mint1010status As Integer

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

            mint1010status = M1010_STATUS.INIT

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

            'sSetImgFName(G_CONST_MID_H1010, WarpBox1)

            sDisp1010()

            ' 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, "frm1010_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_E1E15)
            Exit Sub
        End If

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

        If rtn = 0 Then
            Select Case mint1010status
                Case M1010_STATUS.INIT


                Case M1010_STATUS.SHUTDOWN          'HTCTRL.ExeName๐มตฤI—น
                    sFinishApp()
                    gintStatus = PART_STATUS.QUIT
                    Me.Close()
                    Exit Sub
                Case M1010_STATUS.MENUBACK          'าฦญฐสฏธ

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

                    gintStatus = PART_STATUS.NAME
                    Me.Close()
                    Exit Sub
                Case M1010_STATUS.NOTCODE              'w’่บฐฤศOศฬลดืฐาฏพฐผ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E1E15)
                    Exit Sub
                Case M1010_STATUS.NOTPUT              '๓—ชcมฤข้ฬลดืฐาฏพฐผ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E1E20)
                    Exit Sub
                Case M1010_STATUS.NOTFILE              'ฬงฒู‘ซ—ชลซศฉมฝฝ฿ดืฐาฏพฐผ
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
                    fFnc_WrpMsg("E", G_CONST_MID_E1E35)
                    Exit Sub
                Case M1010_STATUS.DONE              'ณํษQฦลซฝ

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

                    gintStatus = PART_STATUS.PART
                    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_E1E15)

        '                Exit Do
        '            End If

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

        '            If rtn = 0 Then
        '                Select Case mint1010status
        '                    Case M1010_STATUS.INIT


        '                    Case M1010_STATUS.SHUTDOWN          'HTCTRL.ExeName๐มตฤI—น
        '                        sFinishApp()
        '                        gintStatus = PART_STATUS.QUIT

        '                    Case M1010_STATUS.MENUBACK          'าฦญฐสฏธ
        '                        gintStatus = PART_STATUS.NAME

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

        '                    Case M1010_STATUS.NOTPUT              '๓—ชcมฤข้ฬลดืฐาฏพฐผ
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                        fFnc_WrpMsg("E", G_CONST_MID_E1E20)

        '                    Case M1010_STATUS.NOTFILE              'ฬงฒู‘ซ—ชลซศฉมฝฝ฿ดืฐาฏพฐผ
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '                        fFnc_WrpMsg("E", G_CONST_MID_E1E35)

        '                    Case M1010_STATUS.DONE              'ณํษQฦลซฝ
        '                        gintStatus = PART_STATUS.PART

        '                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

    '/*
    '|| ึ”–ผFsDisp1010
    '|| T—v  F1010ๆ–ส•\ฆ
    '*/
    Private Sub sDisp1010()
        Dim rut As String
        rut = gstrctS1000.lngCntRack

        'wfLocation.Clr()
        'wfName.Puts(gstrctKDHT.strUserName)
        'wfTitle.Puts(gstrctKDHT.strTitle)
        'wfPut.Puts(rut.PadLeft(5))

        'wfName.Text = gstrctKDHT.strUserName
        wfTitle.Text = gstrctKDHT.strTitle
        wfPut.Text = rut.PadLeft(5)

    End Sub


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

        Dim rtn As Integer
        Dim wintCnt As Integer
        Dim wintCnt1 As Integer
        Dim wstrIPAddress As String
        Dim wstrFilePath As String
        Dim wintrtn As Integer

        fProcInput = -1

        Try

            If RTrim(pstrInput) = "OCMENUBACK" Then             'OCMENUBACKศ็ฮ
                If gstrctS1000.lngCntRack <> 0 Then
                    mint1010status = M1010_STATUS.NOTPUT
                    fProcInput = 0
                    Exit Function
                End If
                mint1010status = M1010_STATUS.MENUBACK
                fProcInput = 0
                Exit Function

            ElseIf RTrim(pstrInput) = "OCSHUTDOWN" Then         'OCSHUTDOWNศ็ฮ
                mint1010status = M1010_STATUS.SHUTDOWN
                fProcInput = 0
                Exit Function

            ElseIf pstrInput.StartsWith("T") Then
                rtn = pstrInput.Length
                If rtn <> 9 Then                    '9…ศOศ็ฮ
                    mint1010status = M1010_STATUS.NOTCODE
                    fProcInput = 0
                    Exit Function
                End If
                gstrctS1000.strBhk = pstrInput.Substring(1, 3)
                gstrctS1000.strLocation = pstrInput.Substring(4)
                mint1010status = M1010_STATUS.DONE
                fProcInput = 0

            ElseIf pstrInput.StartsWith("OP") Then

                If gstrctS1000.lngCntRack <> 0 Then
                    'ฬงฒูo—อ
                    wintCnt = sOutputLavel(fgetAppPath() & "DATA\" & OUTPUT_ALLOUT_TXT)
                    If wintCnt = -2 Then
                        mint1010status = M1010_STATUS.NOTFILE
                        fProcInput = 0
                        Exit Function
                    ElseIf wintCnt = -1 Then
                        Exit Function
                    End If

                    If pstrInput <> "OP999999999999" Then    '๓—pฬงฒูo—อ

                        'If sOutputHT(fgetAppPath() & "DATA\" & gstrctKDHT.strHdNo & OUTPUT_HT_TXT) = True Then
                        If sOutputHT(fgetAppPath() & "FTP\" & Mid(pstrInput, 3) & gstrctKDHT.strHdNo & OUTPUT_HT_TXT) = True Then

                        End If

                        '''wstrIPAddress = Mid(pstrInput, 3, 3) & "." & Mid(pstrInput, 6, 3) & "." & Mid(pstrInput, 9, 3) & "." & Mid(pstrInput, 12, 3)
                        '''wstrFilePath = fgetAppPath() & "DATA\" & gstrctKDHT.strHdNo & OUTPUT_HT_TXT
                        '''wintrtn = (fFTPUpload(wstrIPAddress, wstrFilePath))
                        '''If wintrtn = -1 Then
                        '''    'G[—
                        '''    mint1010status = M1010_STATUS.NOTFILE
                        '''    fProcInput = 0
                        '''    Exit Function
                        '''End If
                    End If
                    'If fCheckOpenFile(3, fgetAppPath() & "DATA\" & gstrctKDHT.strHdNo & OUTPUT_HT_TXT) = True Then
                    ' If fCheckOpenFile(3, fgetAppPath() & "FTP\" & Mid(pstrInput, 3) & gstrctKDHT.strHdNo & OUTPUT_HT_TXT) = True Then
                    gstrctS1000.lngCnt = 0
                    gstrctS1000.lngCntRack = 0
                    Erase gstrctS1000.strRecord
                    'End If

                End If
                fProcInput = 0

            Else
                mint1010status = M1010_STATUS.NOTCODE 'w’่ศOฬบฐฤศ็ฮ
                fProcInput = 0
                Exit Function

            End If

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

        End Try

    End Function

    '*******************************************************************************
    '* @”\     : ๓—pษOt@Cษ“fซoตทiSTOCK_ALL—pj
    '* ๘”     : pstrPath     String@t@CpX
    '          
    '* –฿่’l   : True False
    '* ”๕l     : ศต
    '*******************************************************************************
    Public Function sOutputLavel(ByVal pstrPath As String) As Integer

        Dim wstrRecord As String
        Dim wstrFileName As String
        Dim wintFileNum As Integer
        Dim i, z As Integer

        sOutputLavel = -1

        'wintFileNum = FreeFile() ' t[ฬt@Ci“o[๐ๆ“พ

        Try
            ' Open the file in append mode
            Using writer As StreamWriter = New StreamWriter(pstrPath, True)
                ' Write the record to the file
                'For i = 0 To pstrParam.Length - 1
                '    writer.WriteLine(pstrFileName)
                'Next
                i = 0
                Do While i <= gstrctS1000.lngCnt - 1
                    wstrRecord = gstrctS1000.strRecord(i)

                    'PrintLine(wintFileNum, wstrRecord) 'Oฬ‘ซoต

                    writer.WriteLine(wstrRecord)

                    i += 1
                Loop
            End Using
        Catch ex As Exception
            ' Handle any potential exceptions here
            MessageBox.Show("An error occurred while writing to the HTERRLOG.TXT file: " & ex.Message)
        End Try




        'wstrFileName = Trim(pstrPath)
        'If wstrFileName = "" Then wstrFileName = ""
        'z = 0
        'Do
        '    Try
        '        ' o—อt@CฬI[v“
        '        FileOpen(wintFileNum, wstrFileName, OpenMode.Append, OpenAccess.Write, OpenShare.LockWrite)
        '        Exit Do
        '    Catch ex As Exception
        '    End Try

        '    If z = 10 Then
        '        sOutputLavel = -2
        '        Exit Function
        '    End If
        '    z += 1
        '    System.Threading.Thread.Sleep(1000)
        'Loop

        'i = 0
        'Do While i <= gstrctS1000.lngCnt - 1
        '    wstrRecord = gstrctS1000.strRecord(i)

        '    PrintLine(wintFileNum, wstrRecord) 'Oฬ‘ซoต

        '    i += 1
        'Loop


        'FileClose(wintFileNum) ' o—อt@CฬN[Y

        sOutputLavel = 0
        Exit Function


    End Function

    '*******************************************************************************
    '* @”\     : ๓—pษOt@Cษ“fซoตทiHT‘—M—pj
    '* ๘”     : pstrPath     String@t@CpX
    '           
    '* –฿่’l   : True False
    '* ”๕l     : ศต
    '*******************************************************************************
    Public Function sOutputHT(ByVal pstrPath As String) As Boolean

        Dim wstrRecord As String
        Dim wstrFileName As String
        Dim wintFileNum As Integer
        Dim i As Integer

        sOutputHT = False

        'wintFileNum = FreeFile() ' t[ฬt@Ci“o[๐ๆ“พ
        wstrFileName = Trim(pstrPath)
        If wstrFileName = "" Then wstrFileName = ""

        sQtySimple()

        Try
            ' Open the file in append mode
            Using writer As StreamWriter = New StreamWriter(pstrPath, True)
                ' Write the record to the file
                'For i = 0 To pstrParam.Length - 1
                '    writer.WriteLine(pstrFileName)
                'Next
                i = 0
                Do While i <= gstrctS1000.lngCnt - 1
                    If gstrctS1000.strRecord(i) <> "" Then

                        wstrRecord = Mid(gstrctS1000.strRecord(i), 1, 45)
                        wstrRecord &= sItemCodeSimple(i)
                        wstrRecord &= gstrctKDHT.strUserNo
                        wstrRecord &= fgetDefaultDate()        'ผฝรั“๚•t

                        'PrintLine(wintFileNum, wstrRecord) 'Oฬ‘ซoต
                        writer.WriteLine(wstrRecord)
                    End If
                    i += 1
                Loop


            End Using

            sOutputHT = True
            Exit Function

        Catch ex As Exception


            MessageBox.Show(G_CONST_EM_FILEIO, G_CONST_EMT_FILEIO, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)


        End Try





        ' o—อt@CฬI[v“
        'FileOpen(wintFileNum, wstrFileName, OpenMode.Append)

        'sQtySimple()

        'Try
        '    i = 0
        '    Do While i <= gstrctS1000.lngCnt - 1
        '        If gstrctS1000.strRecord(i) <> "" Then

        '            wstrRecord = Mid(gstrctS1000.strRecord(i), 1, 45)
        '            wstrRecord &= sItemCodeSimple(i)
        '            wstrRecord &= gstrctKDHT.strUserNo
        '            wstrRecord &= fgetDefaultDate()        'ผฝรั“๚•t

        '            PrintLine(wintFileNum, wstrRecord) 'Oฬ‘ซoต
        '        End If
        '        i += 1
        '    Loop

        '    FileClose(wintFileNum) ' o—อt@CฬN[Y

        '    sOutputHT = True
        '    Exit Function

        'Catch ex As Exception
        '    f0.WarpCtrl1.MessageBox(G_CONST_EMT_FILEIO, G_CONST_EM_FILEIO, MWA_DB_WARNING, MWA_DB_OK)
        'End Try
    End Function

    '*******************************************************************************
    '* @”\     : “ฏACe€๐JE“gตAฦ฿้
    '* ๘”     : 
    '           
    '* –฿่’l   : ศต
    '* ”๕l     : ศต
    '*******************************************************************************
    Public Sub sQtySimple()
        Dim i, z As Integer
        Dim wstrRecode() As String

        ReDim Preserve wstrRecode(gstrctS1000.lngCnt)

        i = 0
        Do While i <= gstrctS1000.lngCnt - 1
            wstrRecode(i) = Mid(gstrctS1000.strRecord(i), 1, 12)
            wstrRecode(i) &= Mid(gstrctS1000.strRecord(i), 14, 41)
            i += 1
        Loop

        i = 0
        Do While i <= gstrctS1000.lngCnt - 1
            If wstrRecode(i) <> "" Then
                z = i + 1
                Do While z <= gstrctS1000.lngCnt - 1

                    If wstrRecode(i) = wstrRecode(z) Then
                        wstrRecode(z) = ""
                        gstrctS1000.strRecord(z) = ""
                    End If
                    z += 1
                Loop
            End If
            i += 1
        Loop
    End Sub

    '*******************************************************************************
    '* @”\     : Ju๐๐ม—p
    '* ๘”     : 
    '           
    '* –฿่’l   : ศต
    '* ”๕l     : ศต
    '*******************************************************************************
    Public Function sItemCodeSimple(ByVal i As Integer) As String
        Dim z As Integer
        Dim wstrRecodI As String
        Dim wstrRecode() As String
        Dim wlngCnt, wlngQty, wlngQty1 As Long

        ReDim Preserve wstrRecode(gstrctS1000.lngCnt)
        wlngCnt = 0
        wlngQty = 0

        wstrRecodI = Mid(gstrctS1000.strRecord(i), 1, 12)
        wstrRecodI &= Mid(gstrctS1000.strRecord(i), 14, 30)

        z = 0
        Do While z <= gstrctS1000.lngCnt - 1
            If gstrctS1000.strRecord(z) = "" Then
                wstrRecode(z) = ""
            Else
                wstrRecode(z) = Mid(gstrctS1000.strRecord(z), 1, 12)
                wstrRecode(z) &= Mid(gstrctS1000.strRecord(z), 14, 30)
            End If
            z += 1
        Loop

        z = 0
        Do While z <= gstrctS1000.lngCnt - 1
            If wstrRecode(z) <> "" Then
                If i <> z Then
                    If wstrRecodI = wstrRecode(z) Then
                        wlngQty = CLng(Mid(gstrctS1000.strRecord(z), 44, 5))
                        wstrRecode(z) = ""
                        gstrctS1000.strRecord(z) = ""
                        wlngCnt += wlngQty
                    End If
                Else
                    wlngQty1 = CLng(Mid(gstrctS1000.strRecord(i), 44, 5))
                End If
            End If

            z += 1
        Loop

        sItemCodeSimple = fstrZeroput(5, CStr(wlngCnt + wlngQty1))

    End Function

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