using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace HT_SKT_Stock
{
    public partial class FrmInputQty : Form
    {
        private String startQty;

        public FrmInputQty(String Qty)
        {
            InitializeComponent();

            startQty = Qty;

            txtQty.Text = Qty;

            txtQty.Focus();

            txtQty.SelectAll();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            
        }

        private void FrmInputQty_Load(object sender, EventArgs e)
        {
            if (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width == 240)
            {
                resolution.ScreenSize.VGAtoQVGA(this);
            }

            // フォームの最大化・最小化ボタン非表示
            this.MaximizeBox = !this.MaximizeBox;
            this.MinimizeBox = !this.MinimizeBox;

            lblError.Visible = false;
            
        }

        public bool IsNumeric(string value)
        {
            return value.All(char.IsNumber);
        }

        private void txtQty_KeyDown(object sender, KeyEventArgs e)
        {

            if (e.KeyCode == Keys.Enter)
            {
                FrmLogin.strQty = txtQty.Text;

                if (txtQty.Text.Trim() == string.Empty)
                {
                    FrmLogin.strQty = startQty;
                }

                string source = txtQty.Text;
                int count = 0;
                foreach (char c in source)
                    if (c == '.') count++;

                if (count > 1)
                {
                    lblError.Visible = true;
                    return;
                }

                this.Close();
            }
            else if (e.KeyCode.ToString() == "Back")
            {
                if (txtQty.Text.Length > 0)
                {
                    txtQty.Text = txtQty.Text.Substring(0, txtQty.Text.Length - 1);
                    txtQty.Focus();
                    txtQty.SelectionStart = txtQty.Text.Length;
                }
                
            }
           
        }

        private void txtQty_KeyPress(object sender, KeyPressEventArgs e)
        {


            if ((!IsNumeric(e.KeyChar.ToString())) && (e.KeyChar.ToString() != ".")) 
            {
                e.Handled = true;
            }

                       
        }

        private void btnOK_Click_1(object sender, EventArgs e)
        {
            FrmLogin.strQty = txtQty.Text;

            if (txtQty.Text.Trim() == string.Empty)
            {
                FrmLogin.strQty = startQty;
            }

            string source = txtQty.Text;
            int count = 0;
            foreach (char c in source)
                if (c == '.') count++;

            if (count > 1)
            {
                lblError.Visible = true;
                return;
            }

            this.Close();
        }

    }
}