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

namespace OsaGateway
{
    public partial class PinRequest : Form
    {
        public delegate void BlackDelegate();

        public string pinSet;

        public PinRequest()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int pin;
            if(textBox1.Text.Length == 4 && int.TryParse(textBox1.Text, out pin))
            {
                this.pinSet = textBox1.Text;
                if (base.InvokeRequired)
                {
                    this.EndInvoke(this.BeginInvoke(new BlackDelegate(SetPin)));
                }
                else
                {
                    SetPin();
                }
                this.Hide();
                this.Close();
            }
            else
            {
                textBox1.BackColor = Color.Orange;
            }
        }

        private void SetPin()
        {
            Program.Pin = pinSet;
        }
    }
}
