﻿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 frm1000
    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(1, 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(18, 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)
    '
    'frm1000
    '
    '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 = "frm1000"
    'Me.Text = "Form1"
    'Me.WarpFrame1.ResumeLayout(False)
    'Me.ResumeLayout(False)

    'End Sub

#End Region
    Private Sub frm1000_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
        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

            Dim fileloc As String = "Setting.ini"

            Dim appPath As String = fgetAppPath() ' Assuming fgetAppPath() retrieves the application directory
            Dim filePath As String = Path.Combine(appPath, fileloc)

            Dim i As Integer = 0
            Dim strIP As String = "192.168.1.1"
            Dim intPort As Integer = 11433
            Dim strDatabase As String = "demodata"

            If File.Exists(filePath) Then

                Dim sr As StreamReader = New StreamReader(filePath)
                Dim s As String = sr.ReadToEnd()
                Dim words As String() = s.Split(New Char() {","c})

                Dim word As String

                For Each word In words

                    If i = 0 Then
                        strIP = word
                    ElseIf i = 1 Then

                        If IsNumeric(word) Then
                            intPort = Convert.ToInt32(word)
                        End If

                    ElseIf i = 2 Then
                        strDatabase = word
                    End If

                    i = i + 1

                Next

            End If

            'dbClient = New BtrieveDbClient(strIP, intPort, strDatabase)

            'WarpCtrl1.GetStartupInfo(si)

            gstrctKDHT.strHdNo = si.term_dev      ' ’[––IDl“พ
            rtn = fGetCountry()

            'rtn = 0
            If (rtn <> 0) Then
                '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 = PL_STATUS.QUIT
                Me.Close()
                Exit Sub
            End If

            rtn = fGetTitle()
            If (rtn = -2) Then
                fFnc_WrpMsg("E", G_CONST_MID_E1E03)
                gintStatus = PL_STATUS.QUIT
                Me.Close()
                Exit Sub
            ElseIf (rtn <> 0) Then
                '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 = PL_STATUS.QUIT
                Me.Close()
                Exit Sub
            End If

            If (Not gstrctKDHT.strUserNo Is Nothing) Then
                rtn = fGetEmplName(gstrctKDHT.strUserNo)
                If (rtn = 0) Then
                    '###(2017/01/26 T. SHIMOKUBO)### UPD_ST [—v–]‘ฮ]
                    'gintStatus = PL_STATUS.SECTION
                    gintStatus = PL_STATUS.NAME
                    Me.Close()
                    '###(2017/01/26 T. SHIMOKUBO)### UPD_ED [—v–]‘ฮ]

                ElseIf (rtn = -1) Then

                    '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 = PL_STATUS.QUIT
                    Me.Close()
                    Exit Sub

                ElseIf (rtn = -2) Then

                    gintStatus = PL_STATUS.NAME
                    Me.Close()
                End If
            Else
                gintStatus = PL_STATUS.NAME
                Me.Close()
            End If

        Catch ex As Exception
            gintStatus = PL_STATUS.QUIT
            sErrLog(gAppName, "frm1000_Load", ex.ToString)
            Me.Close()
        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 = PL_STATUS.NAME
        '            Exit Do

        '        ElseIf WKey = WKY_F1 Then


        '        ElseIf WKey = WKY_F2 Then

        '            gintStatus = PL_STATUS.QUIT
        '            Exit Do

        '        ElseIf WKey = WKY_ERROR Then

        '            'WarpCtrl1.MessageBox(G_CONST_EMT_DB, fEditErrorInfo(gclsDB.BtriveStatus, gclsDB.ErrFile), MWA_DB_WARNING, MWA_DB_OK)
        '            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
        '    gintStatus = PL_STATUS.QUIT
        '    sErrLog(gAppName, "sMain", ex.ToString)
        'End Try

    End Sub

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