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;
using System.Threading;
using GatewayCommon;
using System.Runtime.InteropServices;

namespace OsaGateway
{
    public partial class Connect : Form
    {
        public Connect()
        {
            InitializeComponent();
            comboBox1.SelectedItem = Connection.LoadPort();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (comboBox1.SelectedItem != null && comboBox1.SelectedItem.ToString().Contains("COM"))
            {
                Program.gateway = new GatewayControl(comboBox1.SelectedItem.ToString());
                if (Program.gateway.IsAlive)
                {
                    Connection.SavePort(comboBox1.SelectedItem.ToString());
                    this.Hide();
                    this.Close();
                }
                else
                {
                    label2.Visible = true;
                    Program.gateway = null;
                }
            }
            else
            {
                comboBox1.BackColor = Color.Orange;
            }

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.Close();
        }
    }
}
