﻿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


Public Class frm5000
    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 WarpCtrl1 As WarpControl.WarpCtrl
    'Friend WithEvents WarpFrame1 As WarpControl.WarpFrame
    'Friend WithEvents WarpBox1 As WarpControl.WarpBox
    'Friend WithEvents WarpHWBcr1 As WarpControl.WarpHWBcr
    'Friend WithEvents wfName As WarpControl.WarpField
    'Friend WithEvents WarpField1 As WarpControl.WarpField
    '<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    '    Me.WarpCtrl1 = New WarpControl.WarpCtrl()
    '    Me.WarpFrame1 = New WarpControl.WarpFrame()
    '    Me.WarpField1 = New WarpControl.WarpField()
    '    Me.wfName = New WarpControl.WarpField()
    '    Me.WarpBox1 = New WarpControl.WarpBox()
    '    Me.WarpHWBcr1 = New WarpControl.WarpHWBcr()
    '    Me.WarpFrame1.SuspendLayout()
    '    Me.SuspendLayout()
    '    '
    '    'WarpCtrl1
    '    '
    '    Me.WarpCtrl1.Location = New System.Drawing.Point(0, 0)
    '    Me.WarpCtrl1.MachineType = WarpControl.MachineLists.finpad700f
    '    Me.WarpCtrl1.Name = "WarpCtrl1"
    '    Me.WarpCtrl1.Size = New System.Drawing.Size(50, 50)
    '    Me.WarpCtrl1.TabIndex = 0
    '    Me.WarpCtrl1.Text = "WarpCtrl1"
    '    '
    '    'WarpFrame1
    '    '
    '    Me.WarpFrame1.Controls.Add(Me.WarpField1)
    '    Me.WarpFrame1.Controls.Add(Me.wfName)
    '    Me.WarpFrame1.Controls.Add(Me.WarpBox1)
    '    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 = ""
    '    '
    '    'WarpField1
    '    '
    '    Me.WarpField1.DecimalPointPosition = CType(0, Short)
    '    Me.WarpField1.Font = New System.Drawing.Font("lr SVbN", 33.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.WarpField1.Format = ""
    '    Me.WarpField1.Length = CType(8, Short)
    '    Me.WarpField1.Location = New System.Drawing.Point(204, 156)
    '    Me.WarpField1.MacroBcr = ""
    '    Me.WarpField1.MacroIn = ""
    '    Me.WarpField1.MacroKey = ""
    '    Me.WarpField1.MacroOut = ""
    '    Me.WarpField1.Name = "WarpField1"
    '    Me.WarpField1.Size = New System.Drawing.Size(144, 36)
    '    Me.WarpField1.TabIndex = CType(3, Short)
    '    '
    '    'wfName
    '    '
    '    Me.wfName.BcrFlag = True
    '    Me.wfName.DecimalPointPosition = CType(0, Short)
    '    Me.wfName.Font = New System.Drawing.Font("lr SVbN", 28.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)
    '    Me.wfName.FontSize = WarpControl.FontSizes.Small
    '    Me.wfName.Format = ""
    '    Me.wfName.Length = CType(12, Short)
    '    Me.wfName.Location = New System.Drawing.Point(48, 204)
    '    Me.wfName.MacroBcr = ""
    '    Me.wfName.MacroIn = ""
    '    Me.wfName.MacroKey = ""
    '    Me.wfName.MacroOut = ""
    '    Me.wfName.Name = "wfName"
    '    Me.wfName.Size = New System.Drawing.Size(180, 30)
    '    Me.wfName.TabIndex = CType(2, 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, 60)
    '    Me.WarpBox1.Name = "WarpBox1"
    '    Me.WarpBox1.Size = New System.Drawing.Size(240, 24)
    '    Me.WarpBox1.TabIndex = 0
    '    '
    '    '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)
    '    '
    '    'frm5000
    '    '
    '    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
    '    Me.ClientSize = New System.Drawing.Size(240, 296)
    '    Me.Controls.Add(Me.WarpFrame1)
    '    Me.Controls.Add(Me.WarpCtrl1)
    '    Me.Font = New System.Drawing.Font("MS UI Gothic", 9.0!)
    '    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
    '    Me.Name = "frm5000"
    '    Me.Text = "Form1"
    '    Me.WarpFrame1.ResumeLayout(False)
    '    Me.ResumeLayout(False)

    'End Sub

#End Region
    Private Sub frm5000_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
        Dim si As New MWA_STARTUP
        Dim rtn2 As Integer


        Try

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

            'WarpCtrl1.GetStartupInfo(si)

            gstrctKDHT.strHdNo = si.term_dev      ' ’[––IDl“พ

            rtn = fGetCountry()
            If (rtn <> 0) Then
                'WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, MWA_DB_WARNING, MWA_DB_OK)
                'WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
                MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                gintStatus = TR_STATUS.QUIT
                Me.Close()
                Exit Sub
            End If

            rtn = fGetTitle()
            If (rtn = -2) Then
                fFnc_WrpMsg("E", G_CONST_MID_E5E03)
                gintStatus = TR_STATUS.QUIT
                Me.Close()
                Exit Sub
            ElseIf (rtn <> 0) Then
                'WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, MWA_DB_WARNING, MWA_DB_OK)
                'WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
                MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

                gintStatus = TR_STATUS.QUIT
                Me.Close()
                Exit Sub
            End If

            If (Not gstrctKDHT.strUserNo Is Nothing) Then
                rtn = fGetEmplName(gstrctKDHT.strUserNo)
                If (rtn = 0) Then
                    If gstrctKDPP.strSearchKey <> "" Then
                        rtn = fMakeRecovery2()
                        If rtn = 0 Then
                            gstrctKDPP.intIndex = 0
                            gstrctPPDisp.strCrtnNo = Mid(gstrctKDPP.strSearchKey, 21, 5)
                            rtn2 = fSearchPackCP()
                            If rtn2 = -1 Then
                                'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, MWA_DB_WARNING, MWA_DB_OK)
                                'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
                                MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)


                                gintStatus = TR_STATUS.CLABEL
                                Me.Close()
                                Exit Sub
                            ElseIf rtn2 = -2 Then
                                gintStatus = TR_STATUS.CLABEL
                                Me.Close()
                                Exit Sub
                            Else
                                Select Case fCheckDelivery(1)
                                    Case 0 'fo[–ณต
                                        gstrctPPDispPart.bNextCarton = False
                                        gintStatus = TR_STATUS.PART
                                        Me.Close()
                                        Exit Sub
                                    Case 1 'fo[ ่
                                        If fMakeRecovery4Deliv() = 0 Then
                                            rtn = fSearchPackCP4Delv()
                                            If rtn = -1 Then Exit Sub
                                            gintStatus = TR_STATUS.PART2
                                            Me.Close()
                                            Exit Sub
                                        Else
                                            gintStatus = TR_STATUS.CLABEL
                                            Me.Close()
                                            Exit Sub
                                        End If
                                    Case Else
                                        'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
                                        MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)


                                        gstrctKDPP.intIndex -= 1
                                End Select
                            End If




                            'If rtn2 = -1 Then
                            '    'f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, MWA_DB_WARNING, MWA_DB_OK)
                            '    f0.WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
                            '    gintStatus = TR_STATUS.CLABEL
                            '    Exit Sub
                            'ElseIf rtn2 = -2 Then '•AใAf[^ช‘ถตศข๊อ๓—ึ
                            '    gintStatus = TR_STATUS.PRINT
                            '    Exit Sub
                            'Else
                            '    gstrctPPDispPart.bNextCarton = False
                            '    gintStatus = TR_STATUS.PART
                            'End If
                        Else
                            gintStatus = TR_STATUS.CLABEL
                            Me.Close()
                            Exit Sub
                        End If
                    Else
                        '###(2017/01/26 T. SHIMOKUBO)### UPD_ST [—v–]‘ฮ]
                        'gintStatus = TR_STATUS.CLABEL
                        gintStatus = TR_STATUS.NAME
                        Me.Close()
                        Exit Sub
                        '###(2017/01/26 T. SHIMOKUBO)### UPD_ED [—v–]‘ฮ]
                    End If
                ElseIf (rtn = -1) Then
                    'WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EM_DB, MWA_DB_WARNING, MWA_DB_OK)
                    'WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
                    MessageBox.Show(G_CONST_EM_DB, G_CONST_EMT_DB, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)


                    gintStatus = TR_STATUS.QUIT
                    Me.Close()
                    Exit Sub
                ElseIf (rtn = -2) Then
                    gintStatus = TR_STATUS.NAME
                    Me.Close()
                    Exit Sub
                End If
            Else
                gintStatus = TR_STATUS.NAME
                Me.Close()
                Exit Sub
            End If

#If Not Debug Then
            'sSetImgFName(G_CONST_MID_H0000, WarpBox1)
#End If

            ' tH[€EC“ ภs
            'sMain()

            Exit Sub

        Catch ex As Exception
            gintStatus = TR_STATUS.QUIT
            sErrLog(gAppName, "frm5000_Load", ex.ToString)
            Me.Close()
            Exit Sub
        End Try

    End Sub

    '<StructLayout(LayoutKind.Sequential, pack:=4)> _
    Public Structure MWA_STARTUP
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=17)> _
        Public term_dev As String

        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=17)> _
        Public proc_dev As String

        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4097)> _
        Public proc_path As String
    End Structure

    ' 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(WarpField1)


        '        If WKey = WKY_ENT Then

        '            gintStatus = TR_STATUS.NAME
        '            Exit Do

        '        ElseIf WKey = WKY_F1 Then


        '        ElseIf WKey = WKY_F2 Then

        '            gintStatus = TR_STATUS.QUIT
        '            Exit Do

        '        ElseIf WKey = WKY_ERROR Then

        '            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
        '    gintStatus = TR_STATUS.QUIT
        '    sErrLog(gAppName, "sMain", ex.ToString)
        'End Try

    End Sub

    Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frm5000))
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
        Me.PictureBox1.Location = New System.Drawing.Point(0, 24)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(475, 27)
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        '
        'frm5000
        '
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit
        Me.BackColor = System.Drawing.Color.White
        Me.ClientSize = New System.Drawing.Size(478, 615)
        Me.Controls.Add(Me.PictureBox1)
        Me.Name = "frm5000"
        Me.ResumeLayout(False)

    End Sub

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