using System;
using System.IO;
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.Threading;

namespace Temperature_chamber02
{
    /// <summary>
    /// Interaction logic for Export.xaml
    /// </summary>
    public partial class Export : Window
    {
        public Export()
        {
            InitializeComponent();
        }

        private void btn_uloz_Click(object sender, RoutedEventArgs e)
        {
            string data_to_write;
            DateTime datumCas = DateTime.Now;
            string datum = datumCas.ToString();
            data_to_write = ("Záznam Temperature Chamber Interface měření \n");
            data_to_write += ("Datum a čas pořízení: ");
            data_to_write += datum;
            data_to_write += (" \n\n");
            data_to_write += ("Pozice Nastavena Zmerena\n");

            for (int i = 0; i < data.tep_pozice_historie; i++)
            {
                data_to_write += i.ToString();
                data_to_write += (" ");
                data_to_write += data.tep_nastavena[i].ToString("F1");
                data_to_write += (" ");
                data_to_write += data.tep_zmerena[i].ToString("F1");
                data_to_write += ("\n");
            }
            data_to_write += ("\n---Konec záznamu---\n");

            if (txt_cesta.Text.Contains(":\\"))
            {
                try
                {
                    if (!File.Exists(txt_cesta.Text))
                    {
                        
                        File.WriteAllText(txt_cesta.Text, data_to_write);
                    }
                    else
                    {
                        MessageBox.Show("Soubor jiz existuje");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Chyba pri ulozeni");
                }
            }
            else
            {
                MessageBox.Show("Chybná cesta");
            }

            
        }

        private void btn_ok_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
