using Microsoft.VisualBasic;
using PackingControlSystem.lib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace PackingControlSystem
{
    public partial class frmScanQR2 : Form
    {
        string strWet = string.Empty;

        public frmScanQR2(string Wet)
        {
            InitializeComponent();
            strWet = Wet;
        }

        private void frmScanQR2_Load(object sender, EventArgs e)
        {
            frmPacking.strScanWet = string.Empty;
            txtScanQR2.Text = string.Empty;
            txtScanQR2.Focus();
        }

        private void txtScanQR2_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            // Check if User Presses Enter
            if (e.KeyCode == System.Windows.Forms.Keys.Return)
            {

                if (txtScanQR2.Text.Trim().Length < 4)
                {
                    MessageBox.Show(this, "Format QR Code ไม่ถูกต้อง รบกวนสแกนใหม่อีกครั้ง",
                                           "WKCS", MessageBoxButtons.OK,
                                           MessageBoxIcon.Warning,
                                           MessageBoxDefaultButton.Button1, 0);
                    txtScanQR2.Text = string.Empty;
                    txtScanQR2.Focus();
                    return;

                }

                txtScanQR2.Text = txtScanQR2.Text.ToUpper();

                if (strWet == txtScanQR2.Text.Trim().Substring(0, 4))
                {
                    frmPacking.strScanWet = txtScanQR2.Text.Trim();
                    this.Close();
                }
                else
                {
                    MessageBox.Show(this, "QR Code ไม่ถูกต้อง รบกวนสแกนใหม่อีกครั้ง",
                                           "WKCS", MessageBoxButtons.OK,
                                           MessageBoxIcon.Warning,
                                           MessageBoxDefaultButton.Button1, 0);

                    txtScanQR2.Text = string.Empty;
                    txtScanQR2.Focus();

                }

            }
        }

        private void txtScanQR2_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            frmPacking.strScanWet = string.Empty;
            this.Close();
        }
    }
}
