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

namespace Setup
{
    /// <summary>
    /// Formulář pro zadání cílové IP adresy pro navázání komunikace s modulem
    /// </summary>
    public partial class EnterIp : Form
    {
        /// <summary>
        /// Vytvoří instanci formuláře
        /// </summary>
        public EnterIp()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Hdonota IP adresy
        /// </summary>
        public IPAddress Value { get; private set; }

        /// <summary>
        /// Indikuje možnost uzavřít formulář
        /// </summary>
        private bool closable = false;

        /// <summary>
        /// Obsluha tlačítka [OK]
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                this.Value = IPAddress.Parse(textBox1.Text.Trim());
                Settings.Default.ipDialog = this.Value.ToString();
                Settings.Default.Save();
                closable = true;
                this.Close();
            }
            catch
            {
                closable = false;
            }
        }

        /// <summary>
        /// bsluha události uzavření formuláře [x]
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EnterIp_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!closable)
            {
                //_vetoClosing = false;
                e.Cancel = true;
            }
        }

        /// <summary>
        /// Obsluha tlačítka [CANCEL]
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            closable = true;
            this.Close();
        }
    }
}
