﻿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 BTClientLib
Imports System.IO
Imports System.Reflection
Imports Newtonsoft
Imports Microsoft.WindowsCE.Forms

Public Class frm1025
    Inherits System.Windows.Forms.Form
    '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 WarpHWBcr1 As WarpControl.WarpHWBcr
    'Friend WithEvents wfCaseNo As WarpControl.WarpField
    'Friend WithEvents wfTrm As WarpControl.WarpField
    'Friend WithEvents wfPNT As WarpControl.WarpField
    'Friend WithEvents wfMSC As WarpControl.WarpField
    'Friend WithEvents wfName As WarpControl.WarpField
    'Friend WithEvents WarpBox1 As WarpControl.WarpBox
    'Friend WithEvents wfKey As WarpControl.WarpField
    'Friend WithEvents WarpFrame1 As WarpControl.WarpFrame
    'Friend WithEvents wfLine As WarpControl.WarpField
    'Friend WithEvents wfSeq As WarpControl.WarpField
    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpHWBcr1 = New WarpControl.WarpHWBcr()
    '    Me.wfCaseNo = New WarpControl.WarpField()
    '    Me.wfTrm = New WarpControl.WarpField()
    '    Me.wfPNT = New WarpControl.WarpField()
    '    Me.wfMSC = New WarpControl.WarpField()
    '    Me.wfName = New WarpControl.WarpField()
    '    Me.WarpBox1 = New WarpControl.WarpBox()
    '    Me.wfKey = New WarpControl.WarpField()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame()
    '    Me.wfSeq = New WarpControl.WarpField()
    '    Me.wfLine = New WarpControl.WarpField()
    '    Me.WarpFrame1.SuspendLayout()
    '    Me.SuspendLayout()
    '
    '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)
    '
    'wfCaseNo
    '
    'Me.wfCaseNo.DecimalPointPosition = CType(0, Short)
    'Me.wfCaseNo.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfCaseNo.FontSize = WarpControl.FontSizes.Small
    'Me.wfCaseNo.Format = ""
    'Me.wfCaseNo.Length = CType(9, Short)
    'Me.wfCaseNo.Location = New System.Drawing.Point(0, 73)
    'Me.wfCaseNo.MacroBcr = ""
    'Me.wfCaseNo.MacroIn = ""
    'Me.wfCaseNo.MacroKey = ""
    'Me.wfCaseNo.MacroOut = ""
    'Me.wfCaseNo.Name = "wfCaseNo"
    'Me.wfCaseNo.Size = New System.Drawing.Size(135, 30)
    'Me.wfCaseNo.TabIndex = CType(56, Short)
    'Me.wfCaseNo.Text = "XXX-XX-XX"
    '
    'wfTrm
    '
    'Me.wfTrm.DecimalPointPosition = CType(0, Short)
    'Me.wfTrm.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfTrm.FontSize = WarpControl.FontSizes.Small
    'Me.wfTrm.Format = ""
    'Me.wfTrm.Length = CType(3, Short)
    'Me.wfTrm.Location = New System.Drawing.Point(192, 36)
    'Me.wfTrm.MacroBcr = ""
    'Me.wfTrm.MacroIn = ""
    'Me.wfTrm.MacroKey = ""
    'Me.wfTrm.MacroOut = ""
    'Me.wfTrm.Name = "wfTrm"
    'Me.wfTrm.Size = New System.Drawing.Size(45, 30)
    'Me.wfTrm.TabIndex = CType(55, Short)
    'Me.wfTrm.Text = "XXX"
    '
    'wfPNT
    '
    'Me.wfPNT.DecimalPointPosition = CType(0, Short)
    'Me.wfPNT.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfPNT.FontSize = WarpControl.FontSizes.Small
    'Me.wfPNT.Format = ""
    'Me.wfPNT.Length = CType(3, Short)
    'Me.wfPNT.Location = New System.Drawing.Point(129, 36)
    'Me.wfPNT.MacroBcr = ""
    'Me.wfPNT.MacroIn = ""
    'Me.wfPNT.MacroKey = ""
    'Me.wfPNT.MacroOut = ""
    'Me.wfPNT.Name = "wfPNT"
    'Me.wfPNT.Size = New System.Drawing.Size(45, 30)
    'Me.wfPNT.TabIndex = CType(54, Short)
    'Me.wfPNT.Text = "XXX"
    '
    'wfMSC
    '
    'Me.wfMSC.DecimalPointPosition = CType(0, Short)
    'Me.wfMSC.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfMSC.FontSize = WarpControl.FontSizes.Small
    'Me.wfMSC.Format = ""
    'Me.wfMSC.Length = CType(8, Short)
    'Me.wfMSC.Location = New System.Drawing.Point(0, 37)
    'Me.wfMSC.MacroBcr = ""
    'Me.wfMSC.MacroIn = ""
    'Me.wfMSC.MacroKey = ""
    'Me.wfMSC.MacroOut = ""
    'Me.wfMSC.Name = "wfMSC"
    'Me.wfMSC.Size = New System.Drawing.Size(120, 30)
    'Me.wfMSC.TabIndex = CType(53, Short)
    'Me.wfMSC.Text = "XXXX-XXX"
    '
    '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(1, Short)
    '
    'WarpBox1
    '
    'Me.WarpBox1.BoxType = WarpControl.BoxTypes.Box
    'Me.WarpBox1.DrawMode = WarpControl.DrawModes.Line
    '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 = ""
    'Me.WarpBox1.Location = New System.Drawing.Point(0, 108)
    'Me.WarpBox1.Name = "WarpBox1"
    'Me.WarpBox1.Size = New System.Drawing.Size(240, 96)
    'Me.WarpBox1.TabIndex = 0
    '
    '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.ForeColor = CType(15, Short)
    'Me.wfKey.Format = ""
    'Me.wfKey.InputMode.Secret = True
    'Me.wfKey.Length = CType(1, Short)
    'Me.wfKey.Location = New System.Drawing.Point(180, 73)
    '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(45, Short)
    '
    'WarpFrame1
    '
    'Me.WarpFrame1.Controls.Add(Me.WarpBox1)
    'Me.WarpFrame1.Controls.Add(Me.wfSeq)
    'Me.WarpFrame1.Controls.Add(Me.wfLine)
    'Me.WarpFrame1.Controls.Add(Me.wfCaseNo)
    'Me.WarpFrame1.Controls.Add(Me.wfTrm)
    'Me.WarpFrame1.Controls.Add(Me.wfPNT)
    'Me.WarpFrame1.Controls.Add(Me.wfMSC)
    'Me.WarpFrame1.Controls.Add(Me.wfName)
    'Me.WarpFrame1.Controls.Add(Me.wfKey)
    '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 = ""
    '
    'wfSeq
    '
    'Me.wfSeq.DecimalPointPosition = CType(0, Short)
    'Me.wfSeq.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfSeq.FontSize = WarpControl.FontSizes.Small
    'Me.wfSeq.Format = ""
    'Me.wfSeq.Length = CType(3, Short)
    'Me.wfSeq.Location = New System.Drawing.Point(94, 3)
    'Me.wfSeq.MacroBcr = ""
    'Me.wfSeq.MacroIn = ""
    'Me.wfSeq.MacroKey = ""
    'Me.wfSeq.MacroOut = ""
    'Me.wfSeq.Name = "wfSeq"
    'Me.wfSeq.Size = New System.Drawing.Size(45, 30)
    'Me.wfSeq.TabIndex = CType(58, Short)
    'Me.wfSeq.Text = "999"
    '
    'wfLine
    '
    'Me.wfLine.DecimalPointPosition = CType(0, Short)
    'Me.wfLine.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    'Me.wfLine.FontSize = WarpControl.FontSizes.Small
    'Me.wfLine.Format = ""
    'Me.wfLine.Length = CType(2, Short)
    'Me.wfLine.Location = New System.Drawing.Point(13, 3)
    'Me.wfLine.MacroBcr = ""
    'Me.wfLine.MacroIn = ""
    'Me.wfLine.MacroKey = ""
    'Me.wfLine.MacroOut = ""
    'Me.wfLine.Name = "wfLine"
    'Me.wfLine.Size = New System.Drawing.Size(30, 30)
    'Me.wfLine.TabIndex = CType(57, Short)
    'Me.wfLine.Text = "XX"
    '
    'frm1025
    '
    '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 = "frm1025"
    'Me.Text = "Form1"
    'Me.WarpFrame1.ResumeLayout(False)
    'Me.ResumeLayout(False)

    'End Sub

#End Region

    Public Enum M1025_STATUS As Integer
        INIT = 0
        DONE = 1
        PALTOVER = 2
    End Enum

    Public mint1025status As Integer


    Private Sub frm1025_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 = 0

        Try
            mint1025status = M1025_STATUS.INIT

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

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

    End Sub

    '/*
    '|| ึ”–ผFsDisp1025
    '|| T—v  F1025ๆ–ส•\ฆ
    '*/
    Private Sub sDisp1025()
        With gstrctAicCase
            'wfLine.Puts(.Line)
            'wfSeq.Puts(CInt(.PackSeq))
            'wfMSC.Puts(.Msc_Disp)
            'wfPNT.Puts(.Pnt)
            'wfTrm.Puts(.Trm)
            'wfCaseNo.Puts(.CaseNo)

            wfLine.Text = .Line
            wfSeq.Text = CInt(.PackSeq)
            wfMSC.Text = .Msc_Disp
            wfPNT.Text = .Pnt
            wfTrm.Text = .Trm
            wfCaseNo.Text = .CaseNo

        End With

        'wfName.Puts(gstrctKDHT.strUserName)

        wfName.Text = gstrctKDHT.strUserName
    End Sub

    ' t[€EC“
    Public Sub sMain()

        '        Dim WKey As Short
        '        Dim buf As String
        '        Dim rtn As Integer
        '        Dim stat As Integer

        '        Try

        '            ' t[€ฬ—๐ฑฑษLqตทB
        '            Do While (True)

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

        '                If WKey = WKY_ENT Then
        '                    'ๆ–สฤ•\ฆ
        '                    gstrctPLDispHead.initialize()
        '                    gstrctPLDispData.initialize()
        '                    'pbg”มZ
        '                    BtLib.Transaction.BeginConCurrent()
        '                    rtn = fUpdPaletteQty(1)
        '                    If rtn = -1 Then
        '                        BtLib.Transaction.Abort()
        '                        f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                        Exit Sub
        '                    ElseIf rtn = 0 Then
        '                        BtLib.Transaction.Abort()
        '                        sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
        '#If Not Debug Then
        '                                fFnc_WrpMsg("E", G_CONST_MID_E1E19)
        '#End If
        '                        gintStatus = PL_STATUS.PALETTESCN
        '                        Exit Do
        '                    End If

        '                    'rtn = fSearchPackAP2("1")
        '                    rtn = fSearchPackAP3("1")
        '                    If rtn = 1 Then
        '                        If fSetPlan("3") <> 1 Then
        '                            BtLib.Transaction.Abort()
        '                            f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                            Exit Sub
        '                        End If
        '                        gstrctKDPL.strSearchKey = gstrctAicCase.KeyData
        '                        'HTCTRLษ—f[^๐’วม
        '                        rtn = fUpdateHTCTRL4PL()
        '                        If rtn = -1 Then
        '                            BtLib.Transaction.Abort()
        '                            f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                            Exit Sub
        '                        End If
        '                        BtLib.Transaction.End()
        '                        fMakeCommandFile(G_CONST_PROCESS_PAL_DSP, G_CONST_SPEECH_NOTPRES)
        '                        gintStatus = PL_STATUS.PCSCAN
        '                        Exit Do
        '                    ElseIf rtn <> 0 Then
        '                        BtLib.Transaction.Abort()
        '                        f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                    End If
        '                ElseIf WKey = WKY_F1 Then
        '                    gintStatus = PL_STATUS.PALETTESCN
        '                    rtn = fClearSKey()
        '                    If rtn <> 0 Then
        '                        f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(RTrim(gclsDB.BtriveStatus), RTrim(gclsDB.ErrFile)), MWA_DB_WARNING, MWA_DB_OK)
        '                    End If
        '                    Exit Do

        '                ElseIf WKey = WKY_BCR 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_F2 Then
        '                    'gintStatus = PL_STATUS.ENTKEY
        '                    'Exit Do
        '                End If

        '            Loop

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

    Private Sub frm1025_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Dim WKey As Short
        Dim buf As String
        Dim rtn As Integer
        Dim stat As Integer

        Select Case e.KeyCode.ToString()
            Case "Return"
                'ๆ–สฤ•\ฆ
                gstrctPLDispHead.initialize()
                gstrctPLDispData.initialize()
                'pbg”มZ
                'BtLib.Transaction.BeginConCurrent()
                rtn = fUpdPaletteQty(1)
                If rtn = -1 Then
                    'BtLib.Transaction.Abort()
                    '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)

                    Exit Sub
                ElseIf rtn = 0 Then
                    'BtLib.Transaction.Abort()
                    sBeepSound(modPublicHT.BEEP_TYPE.A, modPublicHT.BEEP_SELECTION.NG)
#If Not Debug Then
                                fFnc_WrpMsg("E", G_CONST_MID_E1E19)
#End If
                    gintStatus = PL_STATUS.PALETTESCN
                    Me.Close()
                    Exit Sub
                End If

                'rtn = fSearchPackAP2("1")
                rtn = fSearchPackAP3("1")
                If rtn = 1 Then
                    If fSetPlan("3") <> 1 Then
                        'BtLib.Transaction.Abort()
                        '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)

                        Exit Sub
                    End If
                    gstrctKDPL.strSearchKey = gstrctAicCase.KeyData
                    'HTCTRLษ—f[^๐’วม
                    rtn = fUpdateHTCTRL4PL()
                    If rtn = -1 Then
                        'BtLib.Transaction.Abort()
                        '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)

                        Exit Sub
                    End If
                    'BtLib.Transaction.End()
                    fMakeCommandFile(G_CONST_PROCESS_PAL_DSP, G_CONST_SPEECH_NOTPRES)
                    gintStatus = PL_STATUS.PCSCAN
                    Me.Close()
                ElseIf rtn <> 0 Then
                    'BtLib.Transaction.Abort()
                    '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

                Exit Sub
            Case "F1"
            Case "F2"
                
                Exit Sub
        End Select
    End Sub

    Private Sub frm1025_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        
    End Sub
End Class


