﻿
'*******************************************************************************
'* ์ฌ๏ะ : ”ฎ๏ะGR[EVXe€
'* ์ฌา   : บv• ‘s—Y
'* ์ฌ“๚   : 2010/08/09
'* T—v     : •จ•i๖๓ ฺ“ฎ
'* XV——๐ : 
'* สฐผฎ  : 1.0
'*******************************************************************************
'Imports WarpControl.WarpApi2
'Imports CommonMove.clsBTRFile
'Imports CommonMove.clsConst

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

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

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

    Public Sub New()
        MyBase.New()

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

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

    End Sub

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

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

    '  : ศบฬvV[WอAWindows tH[€ fUCiล•K—vลทB
    'Windows tH[€ fUCi๐gมฤ•ฯXตฤญพณขB  
    ' R[h GfB^๐gมฤ•ฯXตศขลญพณขB
    'Friend WithEvents WarpFrame1 As WarpControl.WarpFrame
    'Friend WithEvents WarpHWBcr1 As WarpControl.WarpHWBcr
    'Friend WithEvents wfName As WarpControl.WarpField
    'Friend WithEvents WarpField2 As WarpControl.WarpField
    'Friend WithEvents wfCount As WarpControl.WarpField
    'Friend WithEvents wfInput As WarpControl.WarpField
    'Friend WithEvents WarpBox1 As WarpControl.WarpBox

    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame
    '    Me.WarpBox1 = New WarpControl.WarpBox
    '    Me.wfInput = New WarpControl.WarpField
    '    Me.wfCount = New WarpControl.WarpField
    '    Me.WarpField2 = New WarpControl.WarpField
    '    Me.wfName = New WarpControl.WarpField
    '    Me.WarpHWBcr1 = New WarpControl.WarpHWBcr
    '    Me.WarpFrame1.SuspendLayout()
    '    Me.SuspendLayout()
    '    '
    '    'WarpFrame1
    '    '
    '    Me.WarpFrame1.BackColor = CType(3, Short)
    '    Me.WarpFrame1.Controls.Add(Me.WarpBox1)
    '    Me.WarpFrame1.Controls.Add(Me.wfInput)
    '    Me.WarpFrame1.Controls.Add(Me.wfCount)
    '    Me.WarpFrame1.Controls.Add(Me.WarpField2)
    '    Me.WarpFrame1.Controls.Add(Me.wfName)
    '    Me.WarpFrame1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
    '    Me.WarpFrame1.Location = New System.Drawing.Point(0, 0)
    '    Me.WarpFrame1.Name = "WarpFrame1"
    '    Me.WarpFrame1.Size = New System.Drawing.Size(160, 160)
    '    Me.WarpFrame1.TabIndex = 1
    '    Me.WarpFrame1.Text = "WarpFrame1"
    '    Me.WarpFrame1.UseMacro = False
    '    Me.WarpFrame1.UseMacroFileName = ""
    '    '
    '    'WarpBox1
    '    '
    '    Me.WarpBox1.BackColor = CType(3, Short)
    '    Me.WarpBox1.BoxType = WarpControl.BoxTypes.Box
    '    Me.WarpBox1.DrawMode = WarpControl.DrawModes.Paint
    '    Me.WarpBox1.Font = New System.Drawing.Font("Lucida Console", 14.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpBox1.ForeColor = CType(3, Short)
    '    Me.WarpBox1.Image = ""
    '    Me.WarpBox1.Location = New System.Drawing.Point(0, 122)
    '    Me.WarpBox1.Name = "WarpBox1"
    '    Me.WarpBox1.Size = New System.Drawing.Size(160, 17)
    '    Me.WarpBox1.TabIndex = 54
    '    Me.WarpBox1.Text = "Echo System"
    '    '
    '    'wfInput
    '    '
    '    Me.wfInput.BackColor = CType(3, Short)
    '    Me.wfInput.BcrFlag = True
    '    Me.wfInput.DecimalPointPosition = CType(0, Short)
    '    Me.wfInput.Font = New System.Drawing.Font("Lucida Console", 14.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfInput.Format = ""
    '    Me.wfInput.InputMode.Secret = True
    '    Me.wfInput.Length = CType(1, Short)
    '    Me.wfInput.Location = New System.Drawing.Point(6, 4)
    '    Me.wfInput.MacroBcr = ""
    '    Me.wfInput.MacroIn = ""
    '    Me.wfInput.MacroKey = ""
    '    Me.wfInput.MacroOut = ""
    '    Me.wfInput.Name = "wfInput"
    '    Me.wfInput.Size = New System.Drawing.Size(12, 24)
    '    Me.wfInput.TabIndex = CType(52, Short)
    '    '
    '    'wfCount
    '    '
    '    Me.wfCount.BackColor = CType(3, Short)
    '    Me.wfCount.DecimalPointPosition = CType(0, Short)
    '    Me.wfCount.Font = New System.Drawing.Font("Lucida Console", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfCount.FontSize = WarpControl.FontSizes.Small
    '    Me.wfCount.Format = ""
    '    Me.wfCount.Length = CType(3, Short)
    '    Me.wfCount.Location = New System.Drawing.Point(124, 4)
    '    Me.wfCount.MacroBcr = ""
    '    Me.wfCount.MacroIn = ""
    '    Me.wfCount.MacroKey = ""
    '    Me.wfCount.MacroOut = ""
    '    Me.wfCount.Name = "wfCount"
    '    Me.wfCount.Size = New System.Drawing.Size(30, 20)
    '    Me.wfCount.TabIndex = CType(48, Short)
    '    Me.wfCount.Text = "999"
    '    '
    '    'WarpField2
    '    '
    '    Me.WarpField2.BackColor = CType(3, Short)
    '    Me.WarpField2.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField2.Font = New System.Drawing.Font("Lucida Console", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField2.FontSize = WarpControl.FontSizes.Small2
    '    Me.WarpField2.Format = ""
    '    Me.WarpField2.Length = CType(5, Short)
    '    Me.WarpField2.Location = New System.Drawing.Point(78, 7)
    '    Me.WarpField2.MacroBcr = ""
    '    Me.WarpField2.MacroIn = ""
    '    Me.WarpField2.MacroKey = ""
    '    Me.WarpField2.MacroOut = ""
    '    Me.WarpField2.Name = "WarpField2"
    '    Me.WarpField2.Size = New System.Drawing.Size(40, 16)
    '    Me.WarpField2.TabIndex = CType(47, Short)
    '    Me.WarpField2.Text = "Scan:"
    '    '
    '    'wfName
    '    '
    '    Me.wfName.BackColor = CType(3, Short)
    '    Me.wfName.DecimalPointPosition = CType(0, Short)
    '    Me.wfName.Font = New System.Drawing.Font("Lucida Console", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfName.FontSize = WarpControl.FontSizes.Small2
    '    Me.wfName.Format = ""
    '    Me.wfName.InputAttribute.Reverse = True
    '    Me.wfName.InputMode.Clear = True
    '    Me.wfName.Length = CType(12, Short)
    '    Me.wfName.Location = New System.Drawing.Point(32, 144)
    '    Me.wfName.MacroBcr = ""
    '    Me.wfName.MacroIn = ""
    '    Me.wfName.MacroKey = ""
    '    Me.wfName.MacroOut = ""
    '    Me.wfName.Name = "wfName"
    '    Me.wfName.Size = New System.Drawing.Size(96, 16)
    '    Me.wfName.TabIndex = CType(44, Short)
    '    Me.wfName.Text = "Echo System"
    '    '
    '    '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)
    '    '
    '    'frmPMMV1020
    '    '
    '    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    '    Me.ClientSize = New System.Drawing.Size(160, 160)
    '    Me.Controls.Add(Me.WarpFrame1)
    '    Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
    '    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
    '    Me.Name = "frmPMMV1020"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region

#Region "// Param Area /////////////////////////////////////////////////////////////////////////////"

    Private mintStatus As M_STATUS              'ฝรฐภฝ๎•๑
    Private mstrIP As String = ""               'IP๎•๑

#End Region

#Region "// Enum Area ///////////////////////////////////////////////////////////////////////////"

    'ฝรฐภฝ—๑“^
    Private Enum M_STATUS As Integer
        INIT                '๚ป
        MENUBACK            'าฦญฐสฏธ
        CANCEL              'ทฌพู
        ERROR_ID            'IDดืฐ
        SCAN_OK             'OKฝทฌ
    End Enum

#End Region

#Region "// Ivent Area /////////////////////////////////////////////////////////////////////////"

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

    '*******************************************************************************
    ' T—v      : tH[€[h—
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Sub frm_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

        gstrFuncName = "frm_Load"

        Dim wstrImage As String
        Dim rtn As Integer

        Try
            '๚ฝรฐภฝ
            mintStatus = M_STATUS.INIT

            '•ฯ”๚ป
            Call gstructHtData.Initialize(gintStatus)

            'ฬฺฐัฬตฐฬ฿
            'rtn = Me.WarpFrame1.Open()
            'If (rtn <> 0) Then Err.Raise(vbObjectError + 1, gclsPub.gAppName, "WarpError")

            'ๆ–ส–ผพฏฤ (ฺ“ฎ‘ฮ๐ฝทฌ)
            'gclsPubHT.sSetImgFName(CommonMove.clsMsgID.H2060, WarpBox1)

            'ๆ–ส•\ฆ—
            Call wsDisp()

            'ฬซฐัฅาฒ ภs
            Call wsMain()

            'ฬฺฐัฬธฐฝ
            'rtn = Me.WarpFrame1.Close()
            'If (rtn <> 0) Then Err.Raise(vbObjectError + 1, gclsPub.gAppName, "WarpError")

            'ฬซฐัฅธฐฝ
            'Me.Close()

        Catch ex As Exception
            gintStatus = G_ENUM_STATUS.QUIT
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_WARNING, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
            Me.Close()
        End Try
    End Sub

#End Region

#Region "// \bh—GA /////////////////////////////////////////////////////////////////////////"

#Region "-- Main -------------------------------------------------------------------------------"

#Region "--Input Area -------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : t[€EC“—
    ' ๘”      : ศต
    ' –฿่’l    : ศต
    ' ”๕l      : ศต
    '*******************************************************************************

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

        Call wfBarcodeMain(buf)


    End Sub


    Public Sub wsMain()
        'gstrFuncName = "wsMain"

        'Dim WKey As Short

        'Try
        '    ' t[€ฬ—๐ฑฑษLqตทB
        '    Do While (True)
        '        ' R[h“—อ
        '        WKey = WarpFrame1.Input(wfInput)
        '        gclsPubHT.sBeepSound(CommonMove.clsPublicHT.BEEP_TYPE.A, CommonMove.clsPublicHT.BEEP_SELECTION.OK, gfrmMain.WarpCtrl1)

        '        Select Case WKey
        '            Case WKY_BCR
        '                '// สฐบฐฤ“—อ
        '                Call wfBarcodeMain()
        '                Exit Do

        '            Case WKY_ERROR
        '                'ดืฐาฏพฐผ•\ฆ
        '                gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, G_CONST_EM_WARP, MWA_DB_WARNING, MWA_DB_OK)
        '                Exit Do
        '        End Select
        '    Loop

        'Catch ex As Exception
        '    gintStatus = G_ENUM_STATUS.QUIT
        '    gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
        '    gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_WARNING, MWA_DB_OK)
        'End Try
    End Sub

#End Region

#Region "---- ๆ–ส•\ฆ -------------------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : ๆ–ส•\ฆ
    ' ๘”      : ศต
    ' –฿่’l    : ศต
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Sub wsDisp()
        Dim wstrType As String = ""

        '// ถณฤ
        'wfCount.Puts(gstructHtData.ITEM_COUNT.ToString.PadLeft(2))

        'ีฐปฐ–ผ
        'wfName.Puts(gclsPubHT.gstrctPPHT.strUserName)

        wfCount.Text = gstructHtData.ITEM_COUNT.ToString.PadLeft(2)
        wfName.Text = gclsPubHT.gstrctPPHT.strUserName


    End Sub

    '*******************************************************************************
    ' T—v      : ๆ–ส’่
    ' ๘”      : buf       String      สฐบฐฤ“—อ’l
    ' –฿่’l    : ศต
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Sub wsSetNextStatus()
        gstrFuncName = "wsSetNextStatus"

        Try
            'eดืฐๆ–สฬ•\ฆ
            Select Case mintStatus
                Case M_STATUS.INIT
                    '// ฉๆ–ส

                Case M_STATUS.MENUBACK
                    '// าฦญฐสฏธ

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

                    gintStatus = G_ENUM_STATUS.NAME
                    Me.Close()
                    Exit Sub
                Case M_STATUS.CANCEL
                    '// ทฌพู

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

                    gintStatus = G_ENUM_STATUS.ITEM_SCAN
                    Me.Close()
                    Exit Sub
                Case M_STATUS.ERROR_ID
                    '// •sณศสฐบฐฤลท
                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E2010, gfrmMain.WarpCtrl1)

                Case M_STATUS.SCAN_OK
                    '// ฝทฌOK

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

                    gintStatus = G_ENUM_STATUS.ITEM_FIRST
                    Me.Close()
                    Exit Sub
                    'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.I2010, gfrmMain.WarpCtrl1, CommonMove.clsPublicHT.MsgType.Type_Info, CommonMove.clsPublicHT.MsgSelect.Btn_OK)
            End Select

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Sub
        End Try
    End Sub
#End Region

#End Region

#Region "-- Barcode Area ---------------------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : Barcode Area@C“
    ' ๘”      : 
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfBarcodeMain(ByVal result As String) As Boolean
        gstrFuncName = "wfBarcodeMain"

        Dim wintRet As Integer
        Dim wstrBuf As String = result

        Try
            '// สฐบฐฤ“—อ
            'wintRet = WarpHWBcr1.Get(wstrBuf)
            'If wintRet <> 0 Then
            '    gintStatus = MainModule.G_ENUM_STATUS.QUIT
            '    Err.Raise(vbObjectError + 1, gclsPub.gAppName, "WarpError")
            '    Return False
            'End If

            '// สฐบฐฤ“เ—eมชฏธ
            If Not wfCheckBarcode(wstrBuf) Then Return False

            '// Barcode Area
            If Not wfProcInput(wstrBuf) Then Return False

            '// ๆ–ส’่
            Call wsSetNextStatus()

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : สฐบฐฤ“เ—eมชฏธ
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfCheckBarcode(ByRef pstrInput As String) As Boolean
        gstrFuncName = "wfCheckBarcode"

        Dim rtn As Integer

        Try
            '// มชฏธรจผฏฤ
            If Not gclsPubHT.fCheckCode(pstrInput) Then
                'gclsPubHT.MSG_Warp(CommonMove.clsMsgID.E2050, gfrmMain.WarpCtrl1)
                Return False
            End If

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : Barcode Area
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    '           : vblnExist     Boolean     ๕ส(True:‘ถ / False:–ข‘ถ)
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfProcInput(ByVal pstrInput As String) As Boolean
        gstrFuncName = "wfProcInput"

        Dim wblnScanOK As Boolean = False
        Dim rtn As Integer

        Try
            '// OCสฐบฐฤ
            If wfOCBarcode(pstrInput) Then Return True

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

    '*******************************************************************************
    ' T—v      : OCo[R[h—
    ' ๘”      : pstrInput     String      สฐบฐฤ“—อ•ถ
    ' –฿่’l    : Boolean       True:OCสฐบฐฤ / False:ึ
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfOCBarcode(ByVal pstrInput As String) As Boolean
        gstrFuncName = "wfOCBarcode"

        Try
            ''// OCสฐบฐฤ
            'Select Case pstrInput.TrimEnd
            '    Case CommonMove.clsConst.G_CONST_BARCD_MENUBACK
            '        '// OCMENUBACK
            '        mintStatus = M_STATUS.MENUBACK
            '        Return True

            '    Case CommonMove.clsConst.G_CONST_BARCD_CANCEL
            '        '// OCCANCEL
            '        mintStatus = M_STATUS.CANCEL
            '        Return True
            'End Select

            '// IPสฐบฐฤ
            If pstrInput.Length = 14 AndAlso pstrInput.Substring(0, 2) = clsConst.G_CONST_BARCDID_IP Then
                If Not wfOKMain(pstrInput) Then Return True
                mintStatus = M_STATUS.SCAN_OK
                Return True
            End If

            'IDดืฐ
            mintStatus = M_STATUS.ERROR_ID

            Return False

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

#End Region

#Region "-- OKฝทฌ -----------------------------------------------------------------------------"

    '*******************************************************************************
    ' T—v      : OKXL“C“
    ' ๘”      : 
    ' –฿่’l    : Boolean       —ส    (True:ณํ/False:ูํ)
    ' ”๕l      : ศต
    '*******************************************************************************
    Private Function wfOKMain(ByVal pstrInput As String) As Boolean
        gstrFuncName = "wfOKMain"

        Dim wstrMoveNo As String = ""

        Try
            '// IPๆ“พ
            mstrIP = pstrInput.Substring(2, 12)

            '// ๓wฆ๎•๑ฬงฒูo—อ
            If Not wfOutputFTPMain(mstrIP) Then Return False

            Return True

        Catch ex As Exception
            Throw ex
        End Try
    End Function

#End Region

#End Region

#Region "// ฬงฒูo—อดุฑ ////////////////////////////////////////////////////////////////////////////////"

    Private Const M_CONST_FTP_NAME As String = "FTP"
    Private Const M_CONST_DAT_NAME As String = ".DAT"

    '*******************************************************************************
    '* @”\     : FTP“]‘—๎•๑o—อ—
    '* ๘”     : IP     String      IP
    '* –฿่’l   : Boolean       True:ณํ / False:ูํ
    '* ”๕l     : ศต
    '*******************************************************************************
    Private Function wfOutputFTPMain(ByVal IP As String) As Boolean
        gstrFuncName = "wfOutputFTPMain"

        Dim wstrParam As String = ""
        Dim wstrPath As String = ""

        Try
            '// “]‘—๎•๑ถฌ
            wstrParam = wfCreateOutputParam()

            '// ฬงฒู–ผ
            wstrPath = wfCreatePrintPath(IP)

            '// ๓๎•๑ฬo—อ
            If Not wfOutputPrintParam(wstrPath, wstrParam) Then Return False

            Return True

        Catch ex As Exception
            Throw ex
        End Try
    End Function

    '*******************************************************************************
    '* @”\     : “]‘—๎•๑ถฌ
    '* ๘”     : 
    '* –฿่’l   : String        “]‘—๎•๑
    '* ”๕l     : ศต
    '*******************************************************************************
    Private Function wfCreateOutputParam() As String
        gstrFuncName = "wfCreateOutputParam"

        Dim wstbParam As New System.Text.StringBuilder

        Try
            wstbParam.Append(clsConst.G_CONST_PRINTID_MOVELIST)  'ID
            wstbParam.Append(gstructHtData.MoveNo.PadRight(13))         'ฺ“ฎ”ิ

            Return wstbParam.ToString

        Catch ex As Exception
            Throw ex
        End Try
    End Function

    '*******************************************************************************
    '* @”\     : t@C–ผถฌ
    '* ๘”     : IP            String      IPi12…j
    '* –฿่’l   : String        ฬงฒู–ผ
    '* ”๕l     : ศต
    '*******************************************************************************
    Private Function wfCreatePrintPath(ByVal IP As String) As String
        gstrFuncName = "wfCreatePrintPath"

        Dim wstrPath As String = ""
        Dim wstbFileName As New System.Text.StringBuilder

        'ฬงฒู–ผ
        wstbFileName.Append(IP)
        wstbFileName.Append(gclsPubHT.gstrctPPHT.strHdNo.PadRight(8))
        wstbFileName.Append(Now.ToString("yyyyMMddHHmmss"))
        wstbFileName.Append(M_CONST_DAT_NAME)

        'ส฿ฝ
        wstrPath = System.IO.Path.Combine(gclsPub.fgetAppPath(), M_CONST_FTP_NAME)
        wstrPath = System.IO.Path.Combine(wstrPath, wstbFileName.ToString)

        Return wstrPath
    End Function

    '*******************************************************************************
    '* @”\     : ๓๎•๑ฬo—อ
    '* ๘”     : Path          String      t@CpX
    '*          : Msg           String      bZ[W
    '* –฿่’l   : Boolean       True:ณํ / False:ูํ
    '* ”๕l     : ศต
    '*******************************************************************************
    Private Function wfOutputPrintParam(ByVal Path As String, ByVal Msg As String) As Boolean
        gstrFuncName = "wfOutputPrintParam"

        Dim wStream As System.IO.StreamWriter

        Try
            'ฬซูภช–ณฏ๊ฮฉ“ฎ์ฌ
            Dim wstrFolder As String = System.IO.Path.GetDirectoryName(Path)
            If wstrFolder <> "" AndAlso Not System.IO.File.Exists(wstrFolder) Then
                'ฬซูภฉ“ฎถฌ
                System.IO.Directory.CreateDirectory(wstrFolder)
            End If

            'UTF-8
            wStream = New System.IO.StreamWriter(Path, False, System.Text.Encoding.GetEncoding(65001))

            Try
                wStream.WriteLine(Msg)

            Catch ex As Exception
                Throw ex
            Finally
                'ฬงฒูธฐฝ
                If Not wStream Is Nothing Then wStream.Close()
            End Try

            Return True

        Catch ex As Exception
            gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
            'gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
            MessageBox.Show(ex.Message, G_CONST_EMT_WARP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

            gintStatus = MainModule.G_ENUM_STATUS.QUIT
            Me.Close()
            Exit Function
        End Try
    End Function

#End Region

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