using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO.Ports;
using System.Threading;
using System.Windows.Threading;

namespace Temperature_chamber02
{

    
    /// <summary>
    /// Interaction logic for Setup_okno.xaml
    /// </summary>
    public partial class Setup_okno : Window
    {
        
        





        public Setup_okno()
        {
            InitializeComponent();

            string[] portNames = SerialPort.GetPortNames();
            
            if (portNames.Length <= 0)
            {
                MessageBox.Show("Počítač neobsahuje žádné sériové porty!");
            }
            else
            {
                foreach (string port in portNames)
                {
                    comboBox_porty.Items.Add(port);
                }
            }








            DispatcherTimer timer3_aktualizace = new DispatcherTimer();
            timer3_aktualizace.Interval = TimeSpan.FromMilliseconds(1);
            timer3_aktualizace.Tick += timer3_aktualizace_tick;
            timer3_aktualizace.Start();




        }

        private void timer3_aktualizace_tick(object sender, EventArgs e)
        {
            switch (cb_select.Text)
            {
                case "USB":
                    {
                        txt_serial_Port.Visibility = Visibility.Visible;
                        txt_Baudrate.Visibility = Visibility.Visible;
                        Baudrate.Visibility = Visibility.Visible;
                        comboBox_porty.Visibility = Visibility.Visible;
                        IP_adresa.Visibility = Visibility.Hidden;
                        txt_IP_inf.Visibility = Visibility.Hidden;
                        txt_Port.Visibility = Visibility.Hidden;
                        UDP_Port.Visibility = Visibility.Hidden;
                        break;
                    }
                case "Ethernet":
                    {
                        IP_adresa.Visibility = Visibility.Visible;
                        txt_IP_inf.Visibility = Visibility.Visible;
                        txt_Port.Visibility = Visibility.Visible;
                        UDP_Port.Visibility = Visibility.Visible;
                        txt_serial_Port.Visibility = Visibility.Hidden;
                        txt_Baudrate.Visibility = Visibility.Hidden;
                        Baudrate.Visibility = Visibility.Hidden;
                        comboBox_porty.Visibility = Visibility.Hidden;
                        break;
                    }
            }

        }

        private void btn_set_ok_Click(object sender, RoutedEventArgs e)
        {
            data.globalni.Komunikace = cb_select.Text;
            data.globalni.IP_adresa = IP_adresa.Text;
            data.globalni.UDP_Port = UDP_Port.Text;
            data.globalni.Serial_port = comboBox_porty.Text;
            data.globalni.Baudrate = Baudrate.Text;
                        
            this.Close();

        }




    }
}
